diff --git a/pom.xml b/pom.xml
index 458bbb6..249af7c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -224,11 +224,43 @@
jakarta.xml.bind-api
4.0.2
+
+ org.mockito
+ mockito-core
+ 5.12.0
+ test
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 3.3.1
+
spring-boot:run
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 3.3.1
+
+ src/main/resources/checkstyle.xml
+ true
+ true
+
+ ${project.build.sourceDirectory}
+
+
+
+
+
+ check
+
+ compile
+
+
+
org.springframework.boot
spring-boot-maven-plugin
@@ -351,6 +383,28 @@
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 3.3.1
+
+ src/main/resources/checkstyle.xml
+ true
+ true
+
+
+
+
+ checkstyle-aggregate
+
+
+
+
+
+
+
diff --git a/src/main/java/com/primefactorsolutions/invoices/Application.java b/src/main/java/com/primefactorsolutions/invoices/Application.java
index 1aa8437..2eeb1b1 100644
--- a/src/main/java/com/primefactorsolutions/invoices/Application.java
+++ b/src/main/java/com/primefactorsolutions/invoices/Application.java
@@ -16,7 +16,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@Theme(value = "pfs")
public class Application implements AppShellConfigurator {
- public static void main(String[] args) {
+ public static void main(final String[] args) {
SpringApplication.run(Application.class, args);
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/beans/CabeceraDTO.java b/src/main/java/com/primefactorsolutions/invoices/beans/CabeceraDTO.java
index a0de040..9abfdac 100644
--- a/src/main/java/com/primefactorsolutions/invoices/beans/CabeceraDTO.java
+++ b/src/main/java/com/primefactorsolutions/invoices/beans/CabeceraDTO.java
@@ -17,45 +17,45 @@ public class CabeceraDTO {
@NotNull
@DecimalMin(value = "1", inclusive = true)
@DecimalMax(value = "9999999999999", inclusive = true)
- protected long nitEmisor;
- @XmlElement(required = true)
+ private long nitEmisor;
+
@NotNull
@Size(min = 1, max = 200)
- protected String razonSocialEmisor;
- @XmlElement(required = true)
+ private String razonSocialEmisor;
+
@NotNull
@Size(min = 1, max = 25)
- protected String municipio;
- @XmlElement(required = true, nillable = true)
+ private String municipio;
+
@Size(min = 1, max = 25)
- protected String telefono;
+ private String telefono;
@NotNull
@DecimalMin(value = "1", inclusive = true)
@DecimalMax(value = "9999999999", inclusive = true)
- protected long numeroFactura;
+ private long numeroFactura;
@XmlElement(required = true)
@NotNull
@Size(min = 1, max = 100)
- protected String cuf;
+ private String cuf;
@XmlElement(required = true)
@NotNull
@Size(min = 1, max = 100)
- protected String cufd;
+ private String cufd;
@NotNull
@DecimalMin(value = "0", inclusive = true)
@DecimalMax(value = "9999", inclusive = true)
- protected int codigoSucursal;
+ private int codigoSucursal;
@XmlElement(required = true)
@NotNull
@Size(min = 1, max = 500)
- protected String direccion;
+ private String direccion;
@XmlElement(required = true, type = Integer.class, nillable = true)
@DecimalMin(value = "0", inclusive = true)
@DecimalMax(value = "9999", inclusive = true)
- protected Integer codigoPuntoVenta;
+ private Integer codigoPuntoVenta;
@XmlElement(required = true, type = String.class)
@XmlJavaTypeAdapter(DateTimeXmlAdapter.class)
@XmlSchemaType(name = "dateTime")
@NotNull
- protected LocalDateTime fechaEmision;
+ private LocalDateTime fechaEmision;
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/beans/ClientDTO.java b/src/main/java/com/primefactorsolutions/invoices/beans/ClientDTO.java
index 1630408..2278f23 100644
--- a/src/main/java/com/primefactorsolutions/invoices/beans/ClientDTO.java
+++ b/src/main/java/com/primefactorsolutions/invoices/beans/ClientDTO.java
@@ -11,40 +11,40 @@ import lombok.Data;
public class ClientDTO {
@XmlElement(required = true, nillable = true)
@Size(min = 1, max = 500)
- protected String nombreRazonSocial;
+ private String nombreRazonSocial;
@NotNull
@DecimalMin(value = "1", inclusive = true)
@DecimalMax(value = "5", inclusive = true)
- protected int codigoTipoDocumentoIdentidad;
+ private int codigoTipoDocumentoIdentidad;
@XmlElement(required = true)
@NotNull
@Size(min = 1, max = 20)
- protected String numeroDocumento;
+ private String numeroDocumento;
@XmlElement(required = true, nillable = true)
@Size(max = 5)
- protected String complemento;
+ private String complemento;
@XmlElement(required = true)
@NotNull
@Size(min = 1, max = 500)
- protected String direccionComprador;
+ private String direccionComprador;
@XmlElement(required = true)
@NotNull
@Size(min = 1, max = 100)
- protected String codigoCliente;
+ private String codigoCliente;
@XmlElement(required = true)
@NotNull
@Size(min = 1, max = 500)
- protected String lugarDestino;
+ private String lugarDestino;
@NotNull
@DecimalMin(value = "1", inclusive = true)
@DecimalMax(value = "212", inclusive = true)
- protected int codigoPais;
+ private int codigoPais;
@NotNull
@DecimalMin(value = "1", inclusive = true)
@DecimalMax(value = "308", inclusive = true)
- protected int codigoMetodoPago;
+ private int codigoMetodoPago;
@XmlElement(required = true, type = Long.class, nillable = true)
@DecimalMin(value = "0", inclusive = true)
@DecimalMax(value = "9999999999999999", inclusive = true)
- protected Long numeroTarjeta;
+ private Long numeroTarjeta;
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/beans/DetalleDTO.java b/src/main/java/com/primefactorsolutions/invoices/beans/DetalleDTO.java
index 9c42fd5..dd89b68 100644
--- a/src/main/java/com/primefactorsolutions/invoices/beans/DetalleDTO.java
+++ b/src/main/java/com/primefactorsolutions/invoices/beans/DetalleDTO.java
@@ -13,38 +13,38 @@ public class DetalleDTO {
@XmlElement(required = true)
@NotNull
@Size(min = 1, max = 10)
- protected String actividadEconomica;
+ private String actividadEconomica;
@NotNull
@DecimalMin(value = "1", inclusive = true)
@DecimalMax(value = "99999999", inclusive = true)
- protected int codigoProductoSin;
+ private int codigoProductoSin;
@XmlElement(required = true)
@NotNull
@Size(min = 1, max = 50)
- protected String codigoProducto;
+ private String codigoProducto;
@XmlElement(required = true)
@NotNull
@Size(min = 1, max = 500)
- protected String descripcion;
+ private String descripcion;
@XmlElement(required = true)
@NotNull
- protected BigInteger cantidad;
+ private BigInteger cantidad;
@NotNull
@DecimalMin(value = "1", inclusive = true)
@DecimalMax(value = "200", inclusive = true)
- protected int unidadMedida;
+ private int unidadMedida;
@XmlElement(required = true)
@NotNull
@DecimalMin(value = "0", inclusive = false)
@Digits(integer = 20, fraction = 5)
- protected BigDecimal precioUnitario;
+ private BigDecimal precioUnitario;
@XmlElement(required = true, nillable = true)
@DecimalMin(value = "0", inclusive = true)
@Digits(integer = 20, fraction = 5)
- protected BigDecimal montoDescuento;
+ private BigDecimal montoDescuento;
@XmlElement(required = true)
@NotNull
@DecimalMin(value = "0", inclusive = false)
@Digits(integer = 20, fraction = 5)
- protected BigDecimal subTotal;
+ private BigDecimal subTotal;
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/beans/TotalesDTO.java b/src/main/java/com/primefactorsolutions/invoices/beans/TotalesDTO.java
index 6394dea..bb0f25c 100644
--- a/src/main/java/com/primefactorsolutions/invoices/beans/TotalesDTO.java
+++ b/src/main/java/com/primefactorsolutions/invoices/beans/TotalesDTO.java
@@ -15,20 +15,20 @@ public class TotalesDTO {
@NotNull
@DecimalMin(value = "0", inclusive = false)
@Digits(integer = 17, fraction = 2)
- protected BigDecimal montoTotal;
+ private BigDecimal montoTotal;
@XmlElement(required = true)
@NotNull
- protected BigDecimal montoTotalSujetoIva;
+ private BigDecimal montoTotalSujetoIva;
@XmlElement(required = true)
@NotNull
@DecimalMin(value = "0", inclusive = false)
@Digits(integer = 17, fraction = 2)
- protected BigDecimal montoTotalMoneda;
+ private BigDecimal montoTotalMoneda;
@XmlElement(required = true, nillable = true)
@Size(min = 1, max = 10000)
- protected String informacionAdicional;
+ private String informacionAdicional;
@XmlElement(required = true, nillable = true)
@DecimalMin(value = "0", inclusive = true)
@Digits(integer = 17, fraction = 2)
- protected BigDecimal descuentoAdicional;
+ private BigDecimal descuentoAdicional;
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/config/ApplicationReadyListener.java b/src/main/java/com/primefactorsolutions/invoices/config/ApplicationReadyListener.java
index e3c464e..7266267 100644
--- a/src/main/java/com/primefactorsolutions/invoices/config/ApplicationReadyListener.java
+++ b/src/main/java/com/primefactorsolutions/invoices/config/ApplicationReadyListener.java
@@ -23,7 +23,7 @@ public class ApplicationReadyListener implements ApplicationListener
auth.requestMatchers(
AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/images/*.png")).permitAll());
diff --git a/src/main/java/com/primefactorsolutions/invoices/model/AbstractEntity.java b/src/main/java/com/primefactorsolutions/invoices/model/AbstractEntity.java
index a25fb59..216b509 100644
--- a/src/main/java/com/primefactorsolutions/invoices/model/AbstractEntity.java
+++ b/src/main/java/com/primefactorsolutions/invoices/model/AbstractEntity.java
@@ -22,7 +22,7 @@ public abstract class AbstractEntity {
return id;
}
- public void setId(UUID id) {
+ public void setId(final UUID id) {
this.id = id;
}
@@ -39,7 +39,7 @@ public abstract class AbstractEntity {
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (!(obj instanceof AbstractEntity that)) {
return false; // null or not an AbstractEntity class
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/model/Branch.java b/src/main/java/com/primefactorsolutions/invoices/model/Branch.java
index 80c21a0..f858884 100644
--- a/src/main/java/com/primefactorsolutions/invoices/model/Branch.java
+++ b/src/main/java/com/primefactorsolutions/invoices/model/Branch.java
@@ -21,9 +21,9 @@ public class Branch extends AbstractEntity {
@NotNull
@DecimalMin(value = "0", inclusive = true)
@DecimalMax(value = "9999", inclusive = true)
- protected int codigoSucursal;
+ private int codigoSucursal;
- protected String cuis;
+ private String cuis;
- protected String description;
+ private String description;
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/model/Client.java b/src/main/java/com/primefactorsolutions/invoices/model/Client.java
index ea30b24..72984b5 100644
--- a/src/main/java/com/primefactorsolutions/invoices/model/Client.java
+++ b/src/main/java/com/primefactorsolutions/invoices/model/Client.java
@@ -37,37 +37,37 @@ public class Client extends AbstractEntity {
@XmlElement(required = true, nillable = true)
@Size(min = 1, max = 500)
@FullTextField
- protected String nombreRazonSocial;
+ private String nombreRazonSocial;
@NotNull
@DecimalMin(value = "1", inclusive = true)
@DecimalMax(value = "5", inclusive = true)
- protected int codigoTipoDocumentoIdentidad;
+ private int codigoTipoDocumentoIdentidad;
@NotNull
@Size(min = 1, max = 20)
- protected String numeroDocumento;
+ private String numeroDocumento;
@NotNull
@Size(min = 1, max = 500)
- protected String direccionComprador;
+ private String direccionComprador;
@NotNull
@Size(min = 1, max = 100)
- protected String codigoCliente;
+ private String codigoCliente;
@NotNull
@DecimalMin(value = "1", inclusive = true)
@DecimalMax(value = "212", inclusive = true)
- protected int codigoPais;
+ private int codigoPais;
@NotNull
@DecimalMin(value = "1", inclusive = true)
@DecimalMax(value = "308", inclusive = true)
- protected int codigoMetodoPago;
+ private int codigoMetodoPago;
@DecimalMin(value = "0", inclusive = true)
@DecimalMax(value = "9999999999999999", inclusive = true)
- protected Long numeroTarjeta;
+ private Long numeroTarjeta;
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/model/Company.java b/src/main/java/com/primefactorsolutions/invoices/model/Company.java
index 8b214fd..061c7c5 100644
--- a/src/main/java/com/primefactorsolutions/invoices/model/Company.java
+++ b/src/main/java/com/primefactorsolutions/invoices/model/Company.java
@@ -17,22 +17,22 @@ public class Company extends AbstractEntity {
@NotNull
@DecimalMin(value = "1", inclusive = true)
@DecimalMax(value = "9999999999999", inclusive = true)
- protected long nitEmisor;
+ private long nitEmisor;
@NotNull
@Size(min = 1, max = 200)
- protected String razonSocialEmisor;
+ private String razonSocialEmisor;
@NotNull
@Size(min = 1, max = 25)
- protected String municipio;
+ private String municipio;
@Size(min = 1, max = 25)
- protected String telefono;
+ private String telefono;
@NotNull
@Size(min = 1, max = 500)
- protected String direccion;
+ private String direccion;
@Type(JsonType.class)
@Column(columnDefinition = "json")
diff --git a/src/main/java/com/primefactorsolutions/invoices/model/Event.java b/src/main/java/com/primefactorsolutions/invoices/model/Event.java
index 1d02c5f..eadba7d 100644
--- a/src/main/java/com/primefactorsolutions/invoices/model/Event.java
+++ b/src/main/java/com/primefactorsolutions/invoices/model/Event.java
@@ -14,7 +14,7 @@ import java.util.UUID;
@Entity
@Setter
@Getter
-public class Event extends AbstractEntity{
+public class Event extends AbstractEntity {
private UUID userId;
private UUID entityId;
private Instant timestamp;
diff --git a/src/main/java/com/primefactorsolutions/invoices/model/Invoice.java b/src/main/java/com/primefactorsolutions/invoices/model/Invoice.java
index 8976bd4..ba6d0a5 100644
--- a/src/main/java/com/primefactorsolutions/invoices/model/Invoice.java
+++ b/src/main/java/com/primefactorsolutions/invoices/model/Invoice.java
@@ -6,7 +6,6 @@ import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.*;
-import jakarta.xml.bind.annotation.XmlElement;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Type;
@@ -27,10 +26,10 @@ public class Invoice extends AbstractEntity {
private InvoiceStatus status;
@NotNull
- protected LocalDateTime fechaEmision;
+ private LocalDateTime fechaEmision;
@Size(min = 1, max = 500)
- protected String nombreRazonSocial;
+ private String nombreRazonSocial;
@Type(JsonType.class)
@Column(columnDefinition = "json")
diff --git a/src/main/java/com/primefactorsolutions/invoices/model/Media.java b/src/main/java/com/primefactorsolutions/invoices/model/Media.java
index a2426e7..f029858 100644
--- a/src/main/java/com/primefactorsolutions/invoices/model/Media.java
+++ b/src/main/java/com/primefactorsolutions/invoices/model/Media.java
@@ -4,7 +4,6 @@ import io.hypersistence.utils.hibernate.type.json.JsonType;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
-import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Type;
@@ -14,7 +13,7 @@ import java.util.Map;
@Entity
@Setter
@Getter
-public class Media extends AbstractEntity{
+public class Media extends AbstractEntity {
@NotBlank
private String name;
diff --git a/src/main/java/com/primefactorsolutions/invoices/model/PointOfSale.java b/src/main/java/com/primefactorsolutions/invoices/model/PointOfSale.java
index 287efb4..cc72a5e 100644
--- a/src/main/java/com/primefactorsolutions/invoices/model/PointOfSale.java
+++ b/src/main/java/com/primefactorsolutions/invoices/model/PointOfSale.java
@@ -21,17 +21,17 @@ public class PointOfSale extends AbstractEntity {
@NotNull
@DecimalMin(value = "0", inclusive = true)
@DecimalMax(value = "9999", inclusive = true)
- protected int codigoSucursal;
+ private int codigoSucursal;
@DecimalMin(value = "0", inclusive = true)
@DecimalMax(value = "9999", inclusive = true)
- protected Integer codigoPuntoVenta;
+ private Integer codigoPuntoVenta;
- protected POSType codigoTipoPuntoVenta;
+ private POSType codigoTipoPuntoVenta;
- protected String cuis;
+ private String cuis;
- protected String description;
+ private String description;
- protected String nombrePuntoVenta;
+ private String nombrePuntoVenta;
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/model/Product.java b/src/main/java/com/primefactorsolutions/invoices/model/Product.java
index 1620549..57e5209 100644
--- a/src/main/java/com/primefactorsolutions/invoices/model/Product.java
+++ b/src/main/java/com/primefactorsolutions/invoices/model/Product.java
@@ -19,25 +19,25 @@ public class Product extends AbstractEntity {
@NotNull
@DecimalMin(value = "1", inclusive = true)
@DecimalMax(value = "99999999", inclusive = true)
- protected int codigoProductoSin;
+ private int codigoProductoSin;
@NotNull
@Size(min = 1, max = 50)
- protected String codigoProducto;
+ private String codigoProducto;
@NotNull
@Size(min = 1, max = 500)
- protected String descripcion;
+ private String descripcion;
@NotNull
@DecimalMin(value = "1", inclusive = true)
@DecimalMax(value = "200", inclusive = true)
- protected int unidadMedida;
+ private int unidadMedida;
@NotNull
@DecimalMin(value = "0", inclusive = false)
@Digits(integer = 20, fraction = 5)
- protected BigDecimal precioUnitario;
+ private BigDecimal precioUnitario;
@ManyToOne
@JoinColumn(name = "company_id")
diff --git a/src/main/java/com/primefactorsolutions/invoices/model/Task.java b/src/main/java/com/primefactorsolutions/invoices/model/Task.java
index b25619c..8d490a5 100644
--- a/src/main/java/com/primefactorsolutions/invoices/model/Task.java
+++ b/src/main/java/com/primefactorsolutions/invoices/model/Task.java
@@ -14,7 +14,7 @@ import java.util.Map;
@Entity
@Setter
@Getter
-public class Task extends AbstractEntity{
+public class Task extends AbstractEntity {
@NotBlank
private BigInteger nitEmisor;
diff --git a/src/main/java/com/primefactorsolutions/invoices/model/validators/FacturaComputarizadaComercialExportacionServicioValidator.java b/src/main/java/com/primefactorsolutions/invoices/model/validators/FacturaComputarizadaComercialExportacionServicioValidator.java
index f570761..8122969 100644
--- a/src/main/java/com/primefactorsolutions/invoices/model/validators/FacturaComputarizadaComercialExportacionServicioValidator.java
+++ b/src/main/java/com/primefactorsolutions/invoices/model/validators/FacturaComputarizadaComercialExportacionServicioValidator.java
@@ -5,10 +5,11 @@ import com.primefactorsolutions.invoices.xsd.FacturaComputarizadaComercialExport
import java.util.List;
-public class FacturaComputarizadaComercialExportacionServicioValidator implements InvoiceValidator {
+public class FacturaComputarizadaComercialExportacionServicioValidator
+ implements InvoiceValidator {
@Override
- public List validate(FacturaComputarizadaComercialExportacionServicio invoice) {
+ public List validate(final FacturaComputarizadaComercialExportacionServicio invoice) {
return Lists.newArrayList();
}
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/security/SecurityService.java b/src/main/java/com/primefactorsolutions/invoices/security/SecurityService.java
index 558913f..d2b69c2 100644
--- a/src/main/java/com/primefactorsolutions/invoices/security/SecurityService.java
+++ b/src/main/java/com/primefactorsolutions/invoices/security/SecurityService.java
@@ -11,7 +11,7 @@ public class SecurityService {
private final AuthenticationContext authenticationContext;
- public SecurityService(AuthenticationContext authenticationContext) {
+ public SecurityService(final AuthenticationContext authenticationContext) {
this.authenticationContext = authenticationContext;
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/services/ClientService.java b/src/main/java/com/primefactorsolutions/invoices/services/ClientService.java
index e24dfb7..3818a38 100644
--- a/src/main/java/com/primefactorsolutions/invoices/services/ClientService.java
+++ b/src/main/java/com/primefactorsolutions/invoices/services/ClientService.java
@@ -26,12 +26,12 @@ public class ClientService {
private final CompanyService companyService;
@Transactional
- public List findAllClients(String code) {
+ public List findAllClients(final String code) {
return findAllClients(code, PageRequest.of(0, 25));
}
@Transactional
- public List findAllClients(String code, PageRequest of) {
+ public List findAllClients(final String code, final PageRequest of) {
if (Strings.isBlank(code)) {
return clientRepository.findAll();
}
@@ -50,14 +50,14 @@ public class ClientService {
return result.hits();
}
- public void saveOrUpdateClient(Client updatedClient) {
+ public void saveOrUpdateClient(final Client updatedClient) {
updatedClient.setCompany(companyService.getCompany());
updatedClient.setStatus(Status.ACTIVE);
clientRepository.save(updatedClient);
}
- public Client getClient(UUID uuid) {
+ public Client getClient(final UUID uuid) {
return clientRepository.findById(uuid)
.orElseThrow(() -> new IllegalArgumentException("Client not found"));
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/services/ComponentBuilder.java b/src/main/java/com/primefactorsolutions/invoices/services/ComponentBuilder.java
index b73267b..52562e5 100644
--- a/src/main/java/com/primefactorsolutions/invoices/services/ComponentBuilder.java
+++ b/src/main/java/com/primefactorsolutions/invoices/services/ComponentBuilder.java
@@ -13,7 +13,7 @@ import java.util.Locale;
public class ComponentBuilder {
private final I18NProvider i18NProvider;
- public ButtonBuilder button(String text) {
+ public ButtonBuilder button(final String text) {
return ButtonBuilder.builder().i18NProvider(i18NProvider).text(text);
}
@@ -42,12 +42,12 @@ public class ComponentBuilder {
return this;
}
- public ButtonBuilder i18NProvider(I18NProvider i18NProvider) {
+ public ButtonBuilder i18NProvider(final I18NProvider i18NProvider) {
this.setI18NProvider(i18NProvider);
return this;
}
- public ButtonBuilder text(String text) {
+ public ButtonBuilder text(final String text) {
this.setText(text);
return this;
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/services/InvoiceService.java b/src/main/java/com/primefactorsolutions/invoices/services/InvoiceService.java
index 0267d10..2f6baa9 100644
--- a/src/main/java/com/primefactorsolutions/invoices/services/InvoiceService.java
+++ b/src/main/java/com/primefactorsolutions/invoices/services/InvoiceService.java
@@ -17,9 +17,11 @@ import freemarker.template.Template;
import freemarker.template.TemplateExceptionHandler;
import jakarta.transaction.Transactional;
import lombok.Data;
+import lombok.Getter;
import lombok.extern.log4j.Log4j2;
import org.apache.pdfbox.io.MemoryUsageSetting;
import org.apache.pdfbox.pdmodel.PDDocument;
+import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import java.io.*;
@@ -34,6 +36,7 @@ import java.util.TimeZone;
@Data
@Log4j2
public class InvoiceService {
+ @Getter
private final Help help;
private final InvoiceRepository invoiceRepository;
private final MediaRepository mediaRepository;
@@ -45,9 +48,9 @@ public class InvoiceService {
}
@Transactional
- public void sendInvoice(FacturaComputarizadaComercialExportacionServicio factura) {
+ public void sendInvoice(final FacturaComputarizadaComercialExportacionServicio factura) {
- try(var os = new ByteArrayOutputStream()) {
+ try (var os = new ByteArrayOutputStream()) {
writeAsPdf(factura, os);
var media = new Media();
media.setName("factura.pdf");
@@ -82,19 +85,10 @@ public class InvoiceService {
return Invoice.class.getResourceAsStream("/pfs-invoice.html");
}
- public void writeAsPdf(FacturaComputarizadaComercialExportacionServicio factura, OutputStream out) {
-
+ public void writeAsPdf(final FacturaComputarizadaComercialExportacionServicio factura, final OutputStream out) {
try {
var in = getTemplate();
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_32);
- // cfg.setDirectoryForTemplateLoading(new File("/where/you/store/templates"));
- // Recommended settings for new projects:
- cfg.setDefaultEncoding("UTF-8");
- cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
- cfg.setLogTemplateExceptions(false);
- cfg.setWrapUncheckedExceptions(true);
- cfg.setFallbackOnNullLoopVariable(false);
- cfg.setSQLDateAndTimeTimeZone(TimeZone.getDefault());
+ Configuration cfg = getConfiguration();
Reader reader = new InputStreamReader(in);
Template temp = new Template("pfs-invoice", reader, cfg);
@@ -119,7 +113,17 @@ public class InvoiceService {
}
}
- public Help getHelp() {
- return help;
+ @NotNull
+ private static Configuration getConfiguration() {
+ Configuration cfg = new Configuration(Configuration.VERSION_2_3_32);
+ // cfg.setDirectoryForTemplateLoading(new File("/where/you/store/templates"));
+ // Recommended settings for new projects:
+ cfg.setDefaultEncoding("UTF-8");
+ cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
+ cfg.setLogTemplateExceptions(false);
+ cfg.setWrapUncheckedExceptions(true);
+ cfg.setFallbackOnNullLoopVariable(false);
+ cfg.setSQLDateAndTimeTimeZone(TimeZone.getDefault());
+ return cfg;
}
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/services/MediaService.java b/src/main/java/com/primefactorsolutions/invoices/services/MediaService.java
index 0f85a52..9adb9be 100644
--- a/src/main/java/com/primefactorsolutions/invoices/services/MediaService.java
+++ b/src/main/java/com/primefactorsolutions/invoices/services/MediaService.java
@@ -12,15 +12,15 @@ import java.util.List;
public class MediaService {
private final MediaRepository mediaRepository;
- public Media findMedia(String name) {
+ public Media findMedia(final String name) {
return mediaRepository.findAll().stream().findFirst().get();
}
- public List findAllMedia(String name) {
+ public List findAllMedia(final String name) {
return mediaRepository.findByNameLike(name);
}
- public void saveMedia(Media media) {
+ public void saveMedia(final Media media) {
mediaRepository.save(media);
}
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/services/ProductService.java b/src/main/java/com/primefactorsolutions/invoices/services/ProductService.java
index d4a3526..682fcb0 100644
--- a/src/main/java/com/primefactorsolutions/invoices/services/ProductService.java
+++ b/src/main/java/com/primefactorsolutions/invoices/services/ProductService.java
@@ -15,18 +15,18 @@ public class ProductService {
private final ProductRepository productRepository;
private final CompanyService companyService;
- public List findAllProducts(String name) {
+ public List findAllProducts(final String name) {
return productRepository.findAll();
}
- public void saveOrUpdateProduct(Product product) {
+ public void saveOrUpdateProduct(final Product product) {
var company = companyService.getCompany();
product.setCompany(company);
product.setStatus(Status.ACTIVE);
productRepository.save(product);
}
- public Product getProduct(UUID uuid) {
+ public Product getProduct(final UUID uuid) {
return productRepository.findById(uuid).get();
}
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/services/UserService.java b/src/main/java/com/primefactorsolutions/invoices/services/UserService.java
index 19e4b9d..1fb56b1 100644
--- a/src/main/java/com/primefactorsolutions/invoices/services/UserService.java
+++ b/src/main/java/com/primefactorsolutions/invoices/services/UserService.java
@@ -19,15 +19,15 @@ public class UserService implements UserDetailsService {
private final UserRepository userRepository;
private final CompanyService companyService;
- public List findAllUsers(String code) {
+ public List findAllUsers(final String code) {
return userRepository.findAll();
}
- public User getUser(UUID id) {
+ public User getUser(final UUID id) {
return userRepository.findById(id).get();
}
- public void saveOrUpdateUser(User updatedUser) {
+ public void saveOrUpdateUser(final User updatedUser) {
if (updatedUser.getId() == null) {
var company = companyService.getCompany();
updatedUser.setCompany(company);
@@ -39,7 +39,7 @@ public class UserService implements UserDetailsService {
}
@Override
- public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
+ public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {
return userRepository.getByEmail(username);
}
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/utils/UiUtils.java b/src/main/java/com/primefactorsolutions/invoices/utils/UiUtils.java
index ae2ae84..c47f129 100644
--- a/src/main/java/com/primefactorsolutions/invoices/utils/UiUtils.java
+++ b/src/main/java/com/primefactorsolutions/invoices/utils/UiUtils.java
@@ -6,7 +6,7 @@ import lombok.experimental.UtilityClass;
@UtilityClass
public class UiUtils {
- public static void goTo(Component component, String location) {
+ public static void goTo(final Component component, final String location) {
component.getUI().ifPresent(ui -> ui.navigate(location));
}
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/ClientEditView.java b/src/main/java/com/primefactorsolutions/invoices/views/ClientEditView.java
index 7098e39..fba537a 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/ClientEditView.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/ClientEditView.java
@@ -30,26 +30,31 @@ import static com.primefactorsolutions.invoices.utils.UiUtils.goTo;
@PageTitle("Client | PFS Facturacion")
public class ClientEditView extends VerticalLayout implements HasUrlParameter {
- ClientService clientService;
- I18NProvider i18NProvider;
- ComponentBuilder componentBuilder;
- GenericForm clientGenericForm;
+ private final ClientService clientService;
+ private final I18NProvider i18NProvider;
+ private final ComponentBuilder componentBuilder;
+ private GenericForm clientGenericForm;
- public ClientEditView(ClientService clientService, I18NProvider i18NProvider, ComponentBuilder componentBuilder) {
+ public ClientEditView(final ClientService clientService,
+ final I18NProvider i18NProvider,
+ final ComponentBuilder componentBuilder) {
this.clientService = clientService;
this.i18NProvider = i18NProvider;
this.componentBuilder = componentBuilder;
- var client = new Client();
+ initView();
+ }
+ private void initView() {
+ var client = new Client();
this.clientGenericForm = new GenericForm<>(Client.class);
this.clientGenericForm.setBean(client);
var saveButton = this.componentBuilder.button("action.save").primary().build();
saveButton.addClickListener(c -> {
- var updatedClient = clientGenericForm.getBean();
- clientService.saveOrUpdateClient(updatedClient);
- goTo(this, "clients");
+ var updatedClient = clientGenericForm.getBean();
+ clientService.saveOrUpdateClient(updatedClient);
+ goTo(this, "clients");
});
var cancelButton = this.componentBuilder.button("action.cancel").build();
cancelButton.addClickListener(c -> goTo(this, "clients"));
@@ -61,7 +66,7 @@ public class ClientEditView extends VerticalLayout implements HasUrlParameter grid = new PagingGrid<>(Client.class);
- TextField filterText = new TextField();
- ClientService clientService;
+ private final ClientService clientService;
+ private final PagingGrid grid = new PagingGrid<>(Client.class);
+ private final TextField filterText = new TextField();
- public ClientListView(ClientService clientService) {
+ public ClientListView(final ClientService clientService) {
this.clientService = clientService;
+ initView();
+ }
+
+ private void initView() {
addClassName("pfs-list-view");
setSizeFull();
configureGrid();
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/CompanyEditView.java b/src/main/java/com/primefactorsolutions/invoices/views/CompanyEditView.java
index ad73179..66c92db 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/CompanyEditView.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/CompanyEditView.java
@@ -8,7 +8,6 @@ import com.primefactorsolutions.invoices.views.component.GenericForm;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
-import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.html.H4;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
@@ -18,14 +17,11 @@ import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll;
-import org.checkerframework.checker.units.qual.C;
import org.springframework.context.annotation.Scope;
-import org.vaadin.firitin.components.textfield.VBigDecimalField;
import org.vaadin.firitin.fields.ElementCollectionField;
import org.vaadin.firitin.fields.EnumSelect;
import java.math.BigDecimal;
-import java.util.List;
import java.util.Locale;
import static com.primefactorsolutions.invoices.utils.UiUtils.goTo;
@@ -37,21 +33,27 @@ import static com.primefactorsolutions.invoices.utils.UiUtils.goTo;
@PageTitle("Compania | PFS Facturacion")
public class CompanyEditView extends VerticalLayout {
- CompanyService companyService;
+ private CompanyService companyService;
+ private I18NProvider i18NProvider;
- public CompanyEditView(CompanyService companyService, I18NProvider i18NProvider) {
+ public CompanyEditView(final CompanyService companyService, final I18NProvider i18NProvider) {
this.companyService = companyService;
+ this.i18NProvider = i18NProvider;
+ initView();
+ }
+
+ private void initView() {
var company = this.companyService.getCompany();
var companyGenericForm = new GenericForm<>(Company.class);
companyGenericForm.setBean(company);
- String text = i18NProvider.getTranslation("action.save", Locale.of("es"));
+ String text = this.i18NProvider.getTranslation("action.save", Locale.of("es"));
var saveButton = new Button(text);
saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
saveButton.addClickListener(c -> {
- var updatedCompany = companyGenericForm.getBean();
- companyService.saveOrUpdateCompany(updatedCompany);
+ var updatedCompany = companyGenericForm.getBean();
+ this.companyService.saveOrUpdateCompany(updatedCompany);
});
var cancelButton = new Button("Cancel");
cancelButton.addClickListener(c -> goTo(this, ""));
@@ -68,19 +70,21 @@ public class CompanyEditView extends VerticalLayout {
private Component getCurrencyForm() {
- ElementCollectionField field = new ElementCollectionField<>(CurrencyPair.class, CurrencyEditor.class)
- .withEditorInstantiator(CurrencyEditor::new);
+ ElementCollectionField field =
+ new ElementCollectionField<>(CurrencyPair.class, CurrencyEditor.class)
+ .withEditorInstantiator(CurrencyEditor::new);
- var cp = new CurrencyPair(CurrencyPair.CurrencyType.BOB, CurrencyPair.CurrencyType.USD, BigDecimal.valueOf(7.0), BigDecimal.valueOf(6.97));
+ var cp = new CurrencyPair(CurrencyPair.CurrencyType.BOB, CurrencyPair.CurrencyType.USD,
+ BigDecimal.valueOf(7.0), BigDecimal.valueOf(6.97));
field.setValue(Lists.newArrayList(cp));
return field;
}
public static class CurrencyEditor {
- EnumSelect base = new EnumSelect<>(CurrencyPair.CurrencyType.class);
- EnumSelect quote = new EnumSelect<>(CurrencyPair.CurrencyType.class);
- BigDecimalField bid = new BigDecimalField();
- BigDecimalField ask = new BigDecimalField();
+ private final EnumSelect base = new EnumSelect<>(CurrencyPair.CurrencyType.class);
+ private final EnumSelect quote = new EnumSelect<>(CurrencyPair.CurrencyType.class);
+ private final BigDecimalField bid = new BigDecimalField();
+ private final BigDecimalField ask = new BigDecimalField();
}
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/CustomErrorHandler.java b/src/main/java/com/primefactorsolutions/invoices/views/CustomErrorHandler.java
index 3d44370..7e0cf96 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/CustomErrorHandler.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/CustomErrorHandler.java
@@ -1,7 +1,5 @@
package com.primefactorsolutions.invoices.views;
-
-import com.vaadin.flow.component.ScrollOptions;
import com.vaadin.flow.component.Text;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
@@ -14,22 +12,21 @@ import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.server.ErrorEvent;
import com.vaadin.flow.server.ErrorHandler;
import lombok.extern.log4j.Log4j2;
-import org.aspectj.weaver.ast.Not;
-import org.springframework.stereotype.Component;
@Log4j2
public class CustomErrorHandler implements ErrorHandler {
@Override
- public void error(ErrorEvent errorEvent) {
+ public void error(final ErrorEvent errorEvent) {
log.error("Something wrong happened", errorEvent.getThrowable());
- if(UI.getCurrent() != null) {
+ if (UI.getCurrent() != null) {
UI.getCurrent().access(() -> {
var notification = new Notification();
notification.addThemeVariants(NotificationVariant.LUMO_ERROR);
notification.setPosition(Notification.Position.TOP_CENTER);
notification.setDuration(0);
- var layout = new HorizontalLayout(new Text("An internal error has occurred." +
- "Contact support for assistance."), new CloseButton());
+ var layout = new HorizontalLayout(
+ new Text("An internal error has occurred. Contact support for assistance."),
+ new CloseButton());
layout.setAlignItems(FlexComponent.Alignment.CENTER);
notification.add(layout);
notification.open();
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/InitListener.java b/src/main/java/com/primefactorsolutions/invoices/views/InitListener.java
index d9b42e3..9132f26 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/InitListener.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/InitListener.java
@@ -1,6 +1,5 @@
package com.primefactorsolutions.invoices.views;
-
import com.vaadin.flow.server.ServiceInitEvent;
import com.vaadin.flow.server.VaadinServiceInitListener;
import com.vaadin.flow.server.VaadinSession;
@@ -12,7 +11,7 @@ import org.springframework.stereotype.Component;
public class InitListener implements VaadinServiceInitListener {
@Override
- public void serviceInit(ServiceInitEvent event) {
+ public void serviceInit(final ServiceInitEvent event) {
event.getSource().addSessionInitListener(
initEvent -> {
log.info("A new Session has been initialized!");
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/InvoiceListView.java b/src/main/java/com/primefactorsolutions/invoices/views/InvoiceListView.java
index 4e3089a..6979912 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/InvoiceListView.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/InvoiceListView.java
@@ -30,14 +30,16 @@ import java.util.List;
@Route(value = "", layout = MainLayout.class)
@PageTitle("Facturas | PFS Facturacion")
public class InvoiceListView extends VerticalLayout {
- PagingGrid grid = new PagingGrid<>(Invoice.class);
+ private final InvoiceService invoiceService;
+ private final PagingGrid grid = new PagingGrid<>(Invoice.class);
+ private final TextField filterText = new TextField();
- TextField filterText = new TextField();
-
- InvoiceService invoiceService;
-
- public InvoiceListView(InvoiceService invoiceService) {
+ public InvoiceListView(final InvoiceService invoiceService) {
this.invoiceService = invoiceService;
+ initView();
+ }
+
+ private void initView() {
addClassName("list-view");
setSizeFull();
configureGrid();
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/InvoicePdfView.java b/src/main/java/com/primefactorsolutions/invoices/views/InvoicePdfView.java
index e755f5b..e31028e 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/InvoicePdfView.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/InvoicePdfView.java
@@ -18,8 +18,14 @@ import java.io.ByteArrayInputStream;
@Route(value = "invoice-pdf", layout = MainLayout.class)
@PageTitle("Vista | PFS Facturacion")
public class InvoicePdfView extends Div {
+ private final MediaService mediaService;
- public InvoicePdfView(MediaService mediaService) {
+ public InvoicePdfView(final MediaService mediaService) {
+ this.mediaService = mediaService;
+ initView();
+ }
+
+ private void initView() {
var media = mediaService.findMedia("foo.pdf");
var content = media.getContent();
var pdfViewer = new PdfViewer();
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/LoginView.java b/src/main/java/com/primefactorsolutions/invoices/views/LoginView.java
index b967118..e70b134 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/LoginView.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/LoginView.java
@@ -16,7 +16,7 @@ public class LoginView extends VerticalLayout implements BeforeEnterObserver {
private final LoginForm login = new LoginForm();
- public LoginView(){
+ public LoginView() {
addClassName("login-view");
setSizeFull();
setAlignItems(Alignment.CENTER);
@@ -31,7 +31,7 @@ public class LoginView extends VerticalLayout implements BeforeEnterObserver {
@Override
public void beforeEnter(final BeforeEnterEvent beforeEnterEvent) {
// inform the user about an authentication error
- if(beforeEnterEvent.getLocation()
+ if (beforeEnterEvent.getLocation()
.getQueryParameters()
.getParameters()
.containsKey("error")) {
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/MainLayout.java b/src/main/java/com/primefactorsolutions/invoices/views/MainLayout.java
index c50dac0..190676a 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/MainLayout.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/MainLayout.java
@@ -15,7 +15,7 @@ import org.springframework.security.core.userdetails.UserDetails;
public class MainLayout extends AppLayout {
private final SecurityService securityService;
- public MainLayout(SecurityService securityService) {
+ public MainLayout(final SecurityService securityService) {
this.securityService = securityService;
createHeader();
createDrawer();
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/ProductEditView.java b/src/main/java/com/primefactorsolutions/invoices/views/ProductEditView.java
index 13adc62..e2ea20f 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/ProductEditView.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/ProductEditView.java
@@ -18,7 +18,6 @@ import jakarta.annotation.security.PermitAll;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.context.annotation.Scope;
-import org.vaadin.firitin.components.button.VButton;
import java.util.List;
import java.util.Locale;
@@ -33,13 +32,17 @@ import static com.primefactorsolutions.invoices.utils.UiUtils.goTo;
@PageTitle("Product | PFS Facturacion")
public class ProductEditView extends VerticalLayout implements HasUrlParameter {
- ProductService productService;
- I18NProvider i18NProvider;
- GenericForm productGenericForm;
+ private final ProductService productService;
+ private final I18NProvider i18NProvider;
+ private GenericForm productGenericForm;
- public ProductEditView(ProductService productService, I18NProvider i18NProvider) {
+ public ProductEditView(final ProductService productService, final I18NProvider i18NProvider) {
this.productService = productService;
this.i18NProvider = i18NProvider;
+ initView();
+ }
+
+ private void initView() {
var product = new Product();
this.productGenericForm = new GenericForm<>(Product.class);
@@ -49,9 +52,9 @@ public class ProductEditView extends VerticalLayout implements HasUrlParameter {
- var updatedProduct = productGenericForm.getBean();
- productService.saveOrUpdateProduct(updatedProduct);
- goTo(this, "products");
+ var updatedProduct = this.productGenericForm.getBean();
+ this.productService.saveOrUpdateProduct(updatedProduct);
+ goTo(this, "products");
});
var cancelButton = new Button("Cancel");
cancelButton.addClickListener(c -> goTo(this, "products"));
@@ -63,7 +66,7 @@ public class ProductEditView extends VerticalLayout implements HasUrlParameter grid = new PagingGrid<>(Product.class);
- TextField filterText = new TextField();
- ProductService productService;
+ private final ProductService productService;
+ private final PagingGrid grid = new PagingGrid<>(Product.class);
+ private final TextField filterText = new TextField();
- public ProductListView(ProductService productService) {
+ public ProductListView(final ProductService productService) {
this.productService = productService;
+ initView();
+ }
+
+ private void initView() {
addClassName("list-view");
setSizeFull();
configureGrid();
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/UserEditView.java b/src/main/java/com/primefactorsolutions/invoices/views/UserEditView.java
index 0df8a5f..69dd802 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/UserEditView.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/UserEditView.java
@@ -6,8 +6,6 @@ import com.primefactorsolutions.invoices.views.component.Breadcrumbs;
import com.primefactorsolutions.invoices.views.component.GenericForm;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
-import com.vaadin.flow.component.html.Anchor;
-import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.i18n.I18NProvider;
@@ -34,13 +32,17 @@ import static com.primefactorsolutions.invoices.utils.UiUtils.goTo;
@PageTitle("User | PFS Facturacion")
public class UserEditView extends VerticalLayout implements HasUrlParameter {
- UserService userService;
- I18NProvider i18NProvider;
- GenericForm userGenericForm;
+ private final UserService userService;
+ private final I18NProvider i18NProvider;
+ private GenericForm userGenericForm;
- public UserEditView(UserService userService, I18NProvider i18NProvider) {
+ public UserEditView(final UserService userService, final I18NProvider i18NProvider) {
this.userService = userService;
this.i18NProvider = i18NProvider;
+ initView();
+ }
+
+ private void initView() {
var user = new User();
this.userGenericForm = new GenericForm<>(User.class);
@@ -50,8 +52,8 @@ public class UserEditView extends VerticalLayout implements HasUrlParameter {
- var updatedUser = userGenericForm.getBean();
- userService.saveOrUpdateUser(updatedUser);
+ var updatedUser = this.userGenericForm.getBean();
+ this.userService.saveOrUpdateUser(updatedUser);
goTo(this, "users");
});
var cancelButton = new Button("Cancel");
@@ -66,7 +68,7 @@ public class UserEditView extends VerticalLayout implements HasUrlParameter grid = new PagingGrid<>(User.class);
- TextField filterText = new TextField();
- UserService userService;
+ private final PagingGrid grid = new PagingGrid<>(User.class);
+ private final TextField filterText = new TextField();
+ private final UserService userService;
- public UserListView(UserService userService) {
+ public UserListView(final UserService userService) {
this.userService = userService;
+ initView();
+ }
+
+ private void initView() {
addClassName("list-view");
setSizeFull();
configureGrid();
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/component/BigIntegerField.java b/src/main/java/com/primefactorsolutions/invoices/views/component/BigIntegerField.java
index eedc6a3..888a18d 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/component/BigIntegerField.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/component/BigIntegerField.java
@@ -43,10 +43,9 @@ public class BigIntegerField extends AbstractNumberField> listener) {
+ final ValueChangeListener super ComponentValueChangeEvent> listener) {
this();
addValueChangeListener(listener);
}
@@ -83,16 +78,14 @@ public class BigIntegerField extends AbstractNumberField> listener) {
+ public BigIntegerField(
+ final String label,
+ final ValueChangeListener super ComponentValueChangeEvent> listener) {
this(label);
addValueChangeListener(listener);
}
@@ -101,19 +94,17 @@ public class BigIntegerField extends AbstractNumberField> listener) {
+ public BigIntegerField(
+ final String label,
+ final BigInteger initialValue,
+ final ValueChangeListener super ComponentValueChangeEvent> listener) {
this(label);
setValue(initialValue);
addValueChangeListener(listener);
@@ -123,10 +114,9 @@ public class BigIntegerField extends AbstractNumberField> parts) {
+ public Breadcrumbs(final List> parts) {
var components = parts.stream()
.flatMap(p -> {
- if (p.getValue() == null) {
- return Stream.of((Component)new Span(p.getKey()), (Component)new Span(">"));
- } else {
- return Stream.of((Component)new Anchor(p.getValue(), p.getKey()), (Component)new Span(">"));
- }
- }).toList();
+ if (p.getValue() == null) {
+ return Stream.of(new Span(p.getKey()), (Component) new Span(">"));
+ } else {
+ return Stream.of(new Anchor(p.getValue(), p.getKey()), (Component) new Span(">"));
+ }
+ }).toList();
if (components.size() > 1) {
this.add(components.subList(0, components.size() - 1));
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/component/CollectionContainer.java b/src/main/java/com/primefactorsolutions/invoices/views/component/CollectionContainer.java
index ccdc93f..2bf6cb0 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/component/CollectionContainer.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/component/CollectionContainer.java
@@ -12,9 +12,9 @@ import java.util.stream.Collectors;
public class CollectionContainer extends VerticalLayout implements Bindable> {
- private List> elements = new ArrayList<>();
+ private final List> elements = new ArrayList<>();
- public CollectionContainer(Class elementClazz) {
+ public CollectionContainer(final Class elementClazz) {
Button button = new Button("Add");
button.addClickListener((ComponentEventListener>) buttonClickEvent -> {
GenericForm element = new GenericForm<>(elementClazz);
@@ -30,10 +30,10 @@ public class CollectionContainer extends VerticalLayout implements Bindable)bean).get(i));
- }
+ public void setBean(final Object bean) {
+ for (int i = 0; i < elements.size(); i++) {
+ elements.get(i).setBean(((List) bean).get(i));
+ }
}
@Override
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/component/GenericForm.java b/src/main/java/com/primefactorsolutions/invoices/views/component/GenericForm.java
index 13adb66..0c1ca84 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/component/GenericForm.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/component/GenericForm.java
@@ -33,29 +33,29 @@ import java.util.stream.Stream;
import static com.primefactorsolutions.invoices.utils.TextUtils.makeLabel;
public class GenericForm extends VerticalLayout implements Bindable {
- Binder binder;
- List>> inner2 = new ArrayList<>();
- List>> inner = new ArrayList<>();
+ private Binder binder;
+ private final List>> inner2 = new ArrayList<>();
+ private final List>> inner = new ArrayList<>();
@Getter(value = AccessLevel.PUBLIC)
- Class tClass;
+ private final Class tClass;
- boolean recursive;
+ private final boolean recursive;
- public GenericForm(Class tClass) {
+ public GenericForm(final Class tClass) {
this(tClass, false);
}
- public GenericForm(Class tClass, boolean withDetails) {
+ public GenericForm(final Class tClass, final boolean withDetails) {
this.recursive = false;
this.tClass = tClass;
this.binder = new BeanValidationBinder<>(tClass);
List content = getComponents(tClass).toList();
FormLayout formLayout = new FormLayout();
formLayout.setResponsiveSteps(
- new FormLayout.ResponsiveStep("0", 1),
- new FormLayout.ResponsiveStep("500px", 1),
- new FormLayout.ResponsiveStep("800px", 1));
+ new FormLayout.ResponsiveStep("0", 1),
+ new FormLayout.ResponsiveStep("500px", 1),
+ new FormLayout.ResponsiveStep("800px", 1));
if (withDetails) {
Details details = new Details(tClass.getName());
@@ -84,7 +84,7 @@ public class GenericForm extends VerticalLayout implements Bindable {
}
}
- public Stream getComponents(Class> clazz) {
+ public Stream getComponents(final Class> clazz) {
return Arrays.stream(clazz.getDeclaredFields())
.sorted(Comparator.comparing(Field::getName))
.flatMap(field -> {
@@ -98,14 +98,16 @@ public class GenericForm extends VerticalLayout implements Bindable {
if (field.getType().equals(String.class)) {
component = new TextField(label);
- binder.forField((TextField)component)
+ binder.forField((TextField) component)
.bind(field.getName());
- } else if (field.getType().equals(Integer.class) || field.getType().equals(Integer.TYPE)) {
+ } else if (field.getType().equals(Integer.class)
+ || field.getType().equals(Integer.TYPE)) {
final IntegerField formField = new IntegerField(label);
binder.forField(formField)
.bind(field.getName());
component = formField;
- } else if (field.getType().equals(Long.class) || field.getType().equals(Long.TYPE)) {
+ } else if (field.getType().equals(Long.class)
+ || field.getType().equals(Long.TYPE)) {
final LongField formField = new LongField(label);
binder.forField(formField)
.bind(field.getName());
@@ -115,10 +117,10 @@ public class GenericForm extends VerticalLayout implements Bindable {
binder.forField(formField)
.bind(field.getName());
component = formField;
- } else if (field.getType().equals(Double.class) ||
- field.getType().equals(Double.TYPE) ||
- field.getType().equals(Float.class) ||
- field.getType().equals(Float.TYPE)) {
+ } else if (field.getType().equals(Double.class)
+ || field.getType().equals(Double.TYPE)
+ || field.getType().equals(Float.class)
+ || field.getType().equals(Float.TYPE)) {
var formField = new NumberField(label);
binder.forField(formField)
.bind(field.getName());
@@ -155,10 +157,10 @@ public class GenericForm extends VerticalLayout implements Bindable {
@Override
@SneakyThrows
- public void setBean(Object bean) {
+ public void setBean(final Object bean) {
binder.setBean((T) bean);
- for(Pair> b: inner2) {
+ for (Pair> b : inner2) {
Object foo = tClass.getDeclaredMethod("get" + StringUtils.capitalize(b.getKey())).invoke(bean);
if (foo == null) {
foo = tClass.getDeclaredField(b.getKey()).getType().getConstructor().newInstance();
@@ -172,19 +174,17 @@ public class GenericForm extends VerticalLayout implements Bindable {
public T getBean() {
T result = binder.getBean();
- for(Pair> b: inner2) {
+ for (Pair> b : inner2) {
Object foo = b.getValue().getBean();
tClass.getDeclaredMethod("set" + StringUtils.capitalize(b.getKey()), b.getValue().getTClass())
.invoke(result, foo);
}
- for (Pair> b: inner) {
+ for (Pair> b : inner) {
List> foo = b.getValue().getBean();
tClass.getDeclaredMethod("set" + StringUtils.capitalize(b.getKey()), List.class).invoke(result, foo);
}
return result;
}
-
-
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/component/LongField.java b/src/main/java/com/primefactorsolutions/invoices/views/component/LongField.java
index 38029ff..14864ab 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/component/LongField.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/component/LongField.java
@@ -44,7 +44,7 @@ public class LongField extends AbstractNumberField
* @param label
* the text to set as the label
*/
- public LongField(String label) {
+ public LongField(final String label) {
this();
setLabel(label);
}
@@ -58,7 +58,7 @@ public class LongField extends AbstractNumberField
* @param placeholder
* the placeholder text to set
*/
- public LongField(String label, String placeholder) {
+ public LongField(final String label, final String placeholder) {
this(label);
setPlaceholder(placeholder);
}
@@ -72,7 +72,7 @@ public class LongField extends AbstractNumberField
* @see #addValueChangeListener(ValueChangeListener)
*/
public LongField(
- ValueChangeListener super ComponentValueChangeEvent> listener) {
+ final ValueChangeListener super ComponentValueChangeEvent> listener) {
this();
addValueChangeListener(listener);
}
@@ -89,8 +89,8 @@ public class LongField extends AbstractNumberField
* @see #setLabel(String)
* @see #addValueChangeListener(ValueChangeListener)
*/
- public LongField(String label,
- ValueChangeListener super ComponentValueChangeEvent> listener) {
+ public LongField(final String label,
+ final ValueChangeListener super ComponentValueChangeEvent> listener) {
this(label);
addValueChangeListener(listener);
}
@@ -110,8 +110,8 @@ public class LongField extends AbstractNumberField
* @see #setValue(Object)
* @see #addValueChangeListener(ValueChangeListener)
*/
- public LongField(String label, Long initialValue,
- ValueChangeListener super ComponentValueChangeEvent> listener) {
+ public LongField(final String label, final Long initialValue,
+ final ValueChangeListener super ComponentValueChangeEvent> listener) {
this(label);
setValue(initialValue);
addValueChangeListener(listener);
@@ -124,7 +124,7 @@ public class LongField extends AbstractNumberField
* @param min
* the min value to set
*/
- public void setMin(int min) {
+ public void setMin(final int min) {
super.setMin(min);
}
@@ -145,7 +145,7 @@ public class LongField extends AbstractNumberField
* @param max
* the max value to set
*/
- public void setMax(int max) {
+ public void setMax(final int max) {
super.setMax(max);
}
@@ -171,7 +171,7 @@ public class LongField extends AbstractNumberField
* @throws IllegalArgumentException
* if the argument is less or equal to zero.
*/
- public void setStep(int step) {
+ public void setStep(final int step) {
if (step <= 0) {
throw new IllegalArgumentException(
"The step cannot be less or equal to zero.");
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/CabeceraForm.java b/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/CabeceraForm.java
index e1e4d5d..8d6b11a 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/CabeceraForm.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/CabeceraForm.java
@@ -8,22 +8,28 @@ import com.vaadin.flow.component.textfield.IntegerField;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.BeanValidationBinder;
import com.vaadin.flow.data.binder.Binder;
+import lombok.Getter;
public class CabeceraForm extends FormLayout {
- public Binder binder;
+ @Getter
+ private Binder binder;
- LongField nitEmisor = new LongField("nitEmisor");
- TextField razonSocialEmisor = new TextField("razonSocialEmisor");
- TextField municipio = new TextField("municipio");
- TextField telefono = new TextField("telefono");
- IntegerField codigoSucursal = new IntegerField("codigoSucursal");
- TextField direccion = new TextField("direccion");
- IntegerField codigoPuntoVenta = new IntegerField("codigoPuntoVenta");
- DateTimePicker fechaEmision = new DateTimePicker("fechaEmision");
- IntegerField codigoMoneda = new IntegerField("codigoMoneda");
- BigDecimalField tipoCambio = new BigDecimalField("tipoCambio");
+ private final LongField nitEmisor = new LongField("nitEmisor");
+ private final TextField razonSocialEmisor = new TextField("razonSocialEmisor");
+ private final TextField municipio = new TextField("municipio");
+ private final TextField telefono = new TextField("telefono");
+ private final IntegerField codigoSucursal = new IntegerField("codigoSucursal");
+ private final TextField direccion = new TextField("direccion");
+ private final IntegerField codigoPuntoVenta = new IntegerField("codigoPuntoVenta");
+ private final DateTimePicker fechaEmision = new DateTimePicker("fechaEmision");
+ private final IntegerField codigoMoneda = new IntegerField("codigoMoneda");
+ private final BigDecimalField tipoCambio = new BigDecimalField("tipoCambio");
- public CabeceraForm(Class clazz) {
+ public CabeceraForm(final Class clazz) {
+ initView(clazz);
+ }
+
+ private void initView(final Class clazz) {
binder = new BeanValidationBinder<>(clazz);
binder.bindInstanceFields(this);
setResponsiveSteps(
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/ClientForm.java b/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/ClientForm.java
index a9a769d..eb151bb 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/ClientForm.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/ClientForm.java
@@ -6,21 +6,27 @@ import com.vaadin.flow.component.textfield.IntegerField;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.BeanValidationBinder;
import com.vaadin.flow.data.binder.Binder;
+import lombok.Getter;
public class ClientForm extends FormLayout {
- public Binder binder;
- TextField nombreRazonSocial = new TextField("nombreRazonSocial");
- IntegerField codigoTipoDocumentoIdentidad = new IntegerField("codigoTipoDocumentoIdentidad");
- TextField numeroDocumento = new TextField("numeroDocumento");
- TextField complemento = new TextField("complemento");
- TextField direccionComprador = new TextField("direccionComprador");
- TextField codigoCliente = new TextField("codigoCliente");
- TextField lugarDestino = new TextField("lugarDestino");
- IntegerField codigoPais = new IntegerField("codigoPais");
- IntegerField codigoMetodoPago = new IntegerField("codigoMetodoPago");
- LongField numeroTarjeta = new LongField("numeroTarjeta");
+ @Getter
+ private Binder binder;
+ private final TextField nombreRazonSocial = new TextField("nombreRazonSocial");
+ private final IntegerField codigoTipoDocumentoIdentidad = new IntegerField("codigoTipoDocumentoIdentidad");
+ private final TextField numeroDocumento = new TextField("numeroDocumento");
+ private final TextField complemento = new TextField("complemento");
+ private final TextField direccionComprador = new TextField("direccionComprador");
+ private final TextField codigoCliente = new TextField("codigoCliente");
+ private final TextField lugarDestino = new TextField("lugarDestino");
+ private final IntegerField codigoPais = new IntegerField("codigoPais");
+ private final IntegerField codigoMetodoPago = new IntegerField("codigoMetodoPago");
+ private final LongField numeroTarjeta = new LongField("numeroTarjeta");
- public ClientForm(Class clazz) {
+ public ClientForm(final Class clazz) {
+ initView(clazz);
+ }
+
+ private void initView(final Class clazz) {
binder = new BeanValidationBinder<>(clazz);
binder.bindInstanceFields(this);
setResponsiveSteps(
@@ -31,15 +37,15 @@ public class ClientForm extends FormLayout {
setColspan(direccionComprador, 5);
add(nombreRazonSocial,
- direccionComprador,
- codigoTipoDocumentoIdentidad,
- numeroDocumento,
- complemento,
- codigoCliente,
- lugarDestino,
- codigoPais,
- codigoMetodoPago,
- numeroTarjeta
+ direccionComprador,
+ codigoTipoDocumentoIdentidad,
+ numeroDocumento,
+ complemento,
+ codigoCliente,
+ lugarDestino,
+ codigoPais,
+ codigoMetodoPago,
+ numeroTarjeta
);
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/ClientInputForm.java b/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/ClientInputForm.java
index 8957270..573928e 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/ClientInputForm.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/ClientInputForm.java
@@ -7,17 +7,25 @@ import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.data.binder.BeanValidationBinder;
import com.vaadin.flow.data.binder.Binder;
+import lombok.Getter;
import org.springframework.data.domain.PageRequest;
import java.util.List;
import java.util.function.Consumer;
public class ClientInputForm extends FormLayout {
- public Binder binder;
- ComboBox queryText = new ComboBox<>("correoElectronico o telefono");
- List> listeners = Lists.newArrayList();
+ @Getter
+ private Binder binder;
+ private final ClientService clientService;
+ private final ComboBox queryText = new ComboBox<>("correoElectronico o telefono");
+ private final List> listeners = Lists.newArrayList();
- public ClientInputForm(ClientService clientService) {
+ public ClientInputForm(final ClientService clientService) {
+ this.clientService = clientService;
+ initView();
+ }
+
+ private void initView() {
binder = new BeanValidationBinder<>(Client.class);
queryText.setPlaceholder("Buscar ...");
@@ -26,7 +34,7 @@ public class ClientInputForm extends FormLayout {
query -> {
var limit = Math.min(query.getPageSize(), query.getLimit());
var page = Math.min(query.getPage(), query.getOffset());
- return clientService.findAllClients(query.getFilter().orElse(""),
+ return this.clientService.findAllClients(query.getFilter().orElse(""),
PageRequest.of(page, limit)).stream();
},
personSearchTerm -> personSearchTerm
@@ -36,7 +44,7 @@ public class ClientInputForm extends FormLayout {
add(queryText);
}
- public void addListener(Consumer listener) {
+ public void addListener(final Consumer listener) {
listeners.add(listener);
}
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/DetalleForm.java b/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/DetalleForm.java
index 927ba07..974deb9 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/DetalleForm.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/DetalleForm.java
@@ -8,23 +8,29 @@ import com.vaadin.flow.component.textfield.IntegerField;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.BeanValidationBinder;
import com.vaadin.flow.data.binder.Binder;
+import lombok.Getter;
import static com.primefactorsolutions.invoices.utils.TextUtils.makeLabel;
public class DetalleForm extends FormLayout {
- Binder binder;
+ @Getter
+ private Binder binder;
- TextField actividadEconomica = new TextField(makeLabel("actividadEconomica"));
- TextField descripcion = new TextField("descripcion");
- BigIntegerField cantidad = new BigIntegerField("cantidad");
- IntegerField unidadMedida = new IntegerField("unidadMedida");
- BigDecimalField precioUnitario = new BigDecimalField("precioUnitario");
- BigDecimalField montoDescuento = new BigDecimalField("montoDescuento");
- BigDecimalField subTotal = new BigDecimalField("subTotal");
- Hr separator = new Hr();
+ private final TextField actividadEconomica = new TextField(makeLabel("actividadEconomica"));
+ private final TextField descripcion = new TextField("descripcion");
+ private final BigIntegerField cantidad = new BigIntegerField("cantidad");
+ private final IntegerField unidadMedida = new IntegerField("unidadMedida");
+ private final BigDecimalField precioUnitario = new BigDecimalField("precioUnitario");
+ private final BigDecimalField montoDescuento = new BigDecimalField("montoDescuento");
+ private final BigDecimalField subTotal = new BigDecimalField("subTotal");
+ private final Hr separator = new Hr();
- DetalleForm(Class clazz) {
+ DetalleForm(final Class clazz) {
super();
+ initView(clazz);
+ }
+
+ private void initView(final Class clazz) {
binder = new BeanValidationBinder<>(clazz);
binder.bindInstanceFields(this);
setResponsiveSteps(
@@ -35,13 +41,13 @@ public class DetalleForm extends FormLayout {
setColspan(separator, 6);
add(descripcion,
- actividadEconomica,
- cantidad,
- unidadMedida,
- precioUnitario,
- montoDescuento,
- subTotal,
- separator
+ actividadEconomica,
+ cantidad,
+ unidadMedida,
+ precioUnitario,
+ montoDescuento,
+ subTotal,
+ separator
);
}
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/DetallesForm.java b/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/DetallesForm.java
index 570c147..a9ffb8c 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/DetallesForm.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/DetallesForm.java
@@ -13,10 +13,10 @@ import java.util.stream.Collectors;
public class DetallesForm extends VerticalLayout {
- Class clazz;
- Supplier supplier;
+ private final Class clazz;
+ private final Supplier supplier;
- public DetallesForm(Class clazz, Supplier supplier) {
+ public DetallesForm(final Class clazz, final Supplier supplier) {
this.clazz = clazz;
this.supplier = supplier;
addDetalle();
@@ -26,9 +26,9 @@ public class DetallesForm extends VerticalLayout {
var content = new VerticalLayout();
var value = supplier.get();
var detalle = new DetalleForm<>(clazz);
- detalle.binder.setBean(value);
+ detalle.getBinder().setBean(value);
- detalle.binder.addValueChangeListener(v -> {
+ detalle.getBinder().addValueChangeListener(v -> {
fireEvent(new ChangeEvent(this, true));
});
@@ -40,15 +40,13 @@ public class DetallesForm extends VerticalLayout {
add(content);
}
-
-
public List getValues() {
return getChildren()
.flatMap(d -> {
return d.getChildren()
.map(c -> {
if (c instanceof DetalleForm) {
- return ((DetalleForm) c).binder.getBean();
+ return ((DetalleForm) c).getBinder().getBean();
} else {
return null;
}
@@ -59,14 +57,14 @@ public class DetallesForm extends VerticalLayout {
}
public Registration addChangeListener(
- ComponentEventListener listener) {
+ final ComponentEventListener listener) {
return addListener(DetallesForm.ChangeEvent.class, listener);
}
public static class ChangeEvent
extends ComponentEvent> {
- public ChangeEvent(DetallesForm source,
- boolean fromClient) {
+ public ChangeEvent(final DetallesForm source,
+ final boolean fromClient) {
super(source, fromClient);
}
}
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/TotalesForm.java b/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/TotalesForm.java
index 21dc58d..fdb667f 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/TotalesForm.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/component/invoice/TotalesForm.java
@@ -5,15 +5,22 @@ import com.vaadin.flow.component.textfield.BigDecimalField;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.BeanValidationBinder;
import com.vaadin.flow.data.binder.Binder;
+import lombok.Getter;
public class TotalesForm extends FormLayout {
- public Binder binder;
- BigDecimalField montoTotal = new BigDecimalField("montoTotal");
- BigDecimalField montoTotalSujetoIva = new BigDecimalField("montoTotalSujetoIva");
- BigDecimalField montoTotalMoneda = new BigDecimalField("montoTotalMoneda");
- TextField informacionAdicional = new TextField("informacionAdicional");
- BigDecimalField descuentoAdicional = new BigDecimalField("descuentoAdicional");
- public TotalesForm(Class clazz) {
+ @Getter
+ private Binder binder;
+ private final BigDecimalField montoTotal = new BigDecimalField("montoTotal");
+ private final BigDecimalField montoTotalSujetoIva = new BigDecimalField("montoTotalSujetoIva");
+ private final BigDecimalField montoTotalMoneda = new BigDecimalField("montoTotalMoneda");
+ private final TextField informacionAdicional = new TextField("informacionAdicional");
+ private final BigDecimalField descuentoAdicional = new BigDecimalField("descuentoAdicional");
+
+ public TotalesForm(final Class clazz) {
+ initView(clazz);
+ }
+
+ private void initView(final Class clazz) {
binder = new BeanValidationBinder<>(clazz);
binder.bindInstanceFields(this);
diff --git a/src/main/java/com/primefactorsolutions/invoices/views/invoices/FacturaComputarizadaComercialExportacionesServicioEditView.java b/src/main/java/com/primefactorsolutions/invoices/views/invoices/FacturaComputarizadaComercialExportacionesServicioEditView.java
index 19c2b66..a622054 100644
--- a/src/main/java/com/primefactorsolutions/invoices/views/invoices/FacturaComputarizadaComercialExportacionesServicioEditView.java
+++ b/src/main/java/com/primefactorsolutions/invoices/views/invoices/FacturaComputarizadaComercialExportacionesServicioEditView.java
@@ -33,8 +33,6 @@ import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Scope;
import java.math.BigDecimal;
-import java.util.List;
-import java.util.stream.Stream;
import static com.primefactorsolutions.invoices.utils.TextUtils.makeLabel;
import static com.primefactorsolutions.invoices.utils.UiUtils.goTo;
@@ -45,34 +43,38 @@ import static com.primefactorsolutions.invoices.utils.UiUtils.goTo;
@Route(value = "edit-invoice", layout = MainLayout.class)
@PageTitle("Factura | Editar")
public class FacturaComputarizadaComercialExportacionesServicioEditView extends VerticalLayout {
- private final CabeceraForm cabeceraForm;
- private final ClientForm clientForm;
- private final TotalesForm totalesForm;
- private final DetallesForm detalleForm;
- private final Button save = new Button("Crear");
- private final Button close = new Button("Cancelar");
- private final Dialog dialog = new Dialog();
private final InvoiceService invoiceService;
private final ClientService clientService;
private final CompanyService companyService;
+ private final Button save = new Button("Crear");
+ private final Button close = new Button("Cancelar");
+ private final Dialog dialog = new Dialog();
+ private CabeceraForm cabeceraForm;
+ private ClientForm clientForm;
+ private TotalesForm totalesForm;
+ private DetallesForm detalleForm;
public FacturaComputarizadaComercialExportacionesServicioEditView(
- InvoiceService invoiceService,
- ClientService clientService,
- CompanyService companyService) {
+ final InvoiceService invoiceService,
+ final ClientService clientService,
+ final CompanyService companyService) {
this.invoiceService = invoiceService;
this.clientService = clientService;
this.companyService = companyService;
- var company = companyService.getCompany();
+ initView();
+ }
+
+ private void initView() {
+ var company = this.companyService.getCompany();
var cabeceraDTO = CabeceraMapper.INSTANCE.cabeceraDtoFromCompany(company);
this.cabeceraForm = new CabeceraForm<>(CabeceraDTO.class);
- this.cabeceraForm.binder.setBean(cabeceraDTO);
+ this.cabeceraForm.getBinder().setBean(cabeceraDTO);
var clientDTO = new ClientDTO();
this.clientForm = new ClientForm<>(ClientDTO.class);
- this.clientForm.binder.setBean(clientDTO);
+ this.clientForm.getBinder().setBean(clientDTO);
this.detalleForm = new DetallesForm<>(DetalleDTO.class, DetalleDTO::new);
@@ -80,7 +82,7 @@ public class FacturaComputarizadaComercialExportacionesServicioEditView extends
totalesDTO.setInformacionAdicional("Ninguno");
totalesDTO.setDescuentoAdicional(BigDecimal.valueOf(0));
this.totalesForm = new TotalesForm<>(TotalesDTO.class);
- this.totalesForm.binder.setBean(totalesDTO);
+ this.totalesForm.getBinder().setBean(totalesDTO);
var emisorDetails = getEmisorDetails(cabeceraDTO);
var clienteDetails = getClienteDetails();
@@ -111,20 +113,20 @@ public class FacturaComputarizadaComercialExportacionesServicioEditView extends
this.detalleForm.addChangeListener(c -> {
var values = this.detalleForm.getValues();
- var currentTotales = this.totalesForm.binder.getBean();
+ var currentTotales = this.totalesForm.getBinder().getBean();
var total = values.stream()
.map(DetalleDTO::getSubTotal)
.map(b -> b == null ? new BigDecimal(0) : b)
.reduce(BigDecimal::add).orElse(new BigDecimal(0));
- System.out.println(">>>>>>>>" + total);
currentTotales.setMontoTotalMoneda(total);
currentTotales.setMontoTotal((total.subtract(currentTotales.getDescuentoAdicional()))
.multiply(BigDecimal.valueOf(7.0)));
- currentTotales.setMontoTotalSujetoIva(currentTotales.getMontoTotal().subtract(currentTotales.getDescuentoAdicional()));
+ currentTotales.setMontoTotalSujetoIva(currentTotales.getMontoTotal()
+ .subtract(currentTotales.getDescuentoAdicional()));
- this.totalesForm.binder.setBean(currentTotales);
+ this.totalesForm.getBinder().setBean(currentTotales);
});
return detalleDetails;
@@ -135,7 +137,7 @@ public class FacturaComputarizadaComercialExportacionesServicioEditView extends
ClientInputForm clientInputForm = new ClientInputForm(clientService);
clientInputForm.addListener(c -> {
var selectedClientDTO = ClientMapper.INSTANCE.clientDtoFromClient(c);
- this.clientForm.binder.setBean(selectedClientDTO);
+ this.clientForm.getBinder().setBean(selectedClientDTO);
this.clientForm.setVisible(true);
});
@@ -154,7 +156,7 @@ public class FacturaComputarizadaComercialExportacionesServicioEditView extends
if (e.isOpened()) {
clienteText.setText("Cliente");
} else {
- var clienteDTO = clientForm.binder.getBean();
+ var clienteDTO = clientForm.getBinder().getBean();
clienteText.setText("Cliente (" + clienteDTO.getNombreRazonSocial() + ")");
}
});
@@ -171,7 +173,7 @@ public class FacturaComputarizadaComercialExportacionesServicioEditView extends
}
@NotNull
- private Details getEmisorDetails(CabeceraDTO cabeceraDTO) {
+ private Details getEmisorDetails(final CabeceraDTO cabeceraDTO) {
var emisorText = new Text("Emisor");
var emisorSummary = new HorizontalLayout();
emisorSummary.setSpacing(false);
@@ -204,9 +206,9 @@ public class FacturaComputarizadaComercialExportacionesServicioEditView extends
this.save.addClickListener(e -> {
var factura = new FacturaComputarizadaComercialExportacionServicio();
- var cabecera = CabeceraMapper.INSTANCE.cabeceraFromDtos(this.cabeceraForm.binder.getBean(),
- this.clientForm.binder.getBean(),
- this.totalesForm.binder.getBean());
+ var cabecera = CabeceraMapper.INSTANCE.cabeceraFromDtos(this.cabeceraForm.getBinder().getBean(),
+ this.clientForm.getBinder().getBean(),
+ this.totalesForm.getBinder().getBean());
var detalles = detalleForm.getValues().stream()
.map(DetalleMapper.INSTANCE::detalleFromDto)
.toList();
diff --git a/src/main/java/com/primefactorsolutions/invoices/xml/adapters/DateTimeXmlAdapter.java b/src/main/java/com/primefactorsolutions/invoices/xml/adapters/DateTimeXmlAdapter.java
index 90950e3..fd1d1fd 100644
--- a/src/main/java/com/primefactorsolutions/invoices/xml/adapters/DateTimeXmlAdapter.java
+++ b/src/main/java/com/primefactorsolutions/invoices/xml/adapters/DateTimeXmlAdapter.java
@@ -11,12 +11,12 @@ import java.time.ZoneOffset;
public class DateTimeXmlAdapter extends XmlAdapter {
@Override
- public String marshal(LocalDateTime v) throws Exception {
+ public String marshal(final LocalDateTime v) throws Exception {
return v.toInstant(ZoneOffset.UTC).toString();
}
@Override
- public LocalDateTime unmarshal(String v) throws Exception {
+ public LocalDateTime unmarshal(final String v) throws Exception {
return LocalDateTime.ofInstant(Instant.parse(v), ZoneId.of("UTC"));
}
}
\ No newline at end of file
diff --git a/src/main/java/com/primefactorsolutions/invoices/xml/adapters/DateXmlAdapter.java b/src/main/java/com/primefactorsolutions/invoices/xml/adapters/DateXmlAdapter.java
index 6af38a2..72f9ac2 100644
--- a/src/main/java/com/primefactorsolutions/invoices/xml/adapters/DateXmlAdapter.java
+++ b/src/main/java/com/primefactorsolutions/invoices/xml/adapters/DateXmlAdapter.java
@@ -11,14 +11,14 @@ public class DateXmlAdapter extends XmlAdapter {
private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
- public String marshal(Date v) throws Exception {
+ public String marshal(final Date v) throws Exception {
synchronized (dateFormat) {
return dateFormat.format(v);
}
}
@Override
- public Date unmarshal(String v) throws Exception {
+ public Date unmarshal(final String v) throws Exception {
synchronized (dateFormat) {
return dateFormat.parse(v);
}
diff --git a/src/main/resources/checkstyle.xml b/src/main/resources/checkstyle.xml
new file mode 100644
index 0000000..216d48d
--- /dev/null
+++ b/src/main/resources/checkstyle.xml
@@ -0,0 +1,195 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/java/com/primefactorsolutions/invoices/services/ClientServiceTest.java b/src/test/java/com/primefactorsolutions/invoices/services/ClientServiceTest.java
new file mode 100644
index 0000000..b38e103
--- /dev/null
+++ b/src/test/java/com/primefactorsolutions/invoices/services/ClientServiceTest.java
@@ -0,0 +1,22 @@
+package com.primefactorsolutions.invoices.services;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class ClientServiceTest {
+
+ @BeforeEach
+ void setUp() {
+ }
+
+ @AfterEach
+ void tearDown() {
+ }
+
+ @Test
+ void getClient() {
+ }
+}
\ No newline at end of file