Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.quarkus.runtime.annotations.RegisterForReflection;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

Expand All @@ -32,6 +33,14 @@ public class NamespaceRepresentation {
@Size(max = 250)
private String description;

@NotNull
@Valid
private SunatUrlsRepresentation webServices;

@NotNull
@Valid
private SunatCredentialsRepresentation credentials;

public String getId() {
return id;
}
Expand All @@ -56,4 +65,19 @@ public void setDescription(String description) {
this.description = description;
}

public SunatUrlsRepresentation getWebServices() {
return webServices;
}

public void setWebServices(SunatUrlsRepresentation webServices) {
this.webServices = webServices;
}

public SunatCredentialsRepresentation getCredentials() {
return credentials;
}

public void setCredentials(SunatCredentialsRepresentation credentials) {
this.credentials = credentials;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
*/
package io.github.project.openubl.xsender.idm;

import io.quarkus.runtime.annotations.RegisterForReflection;

@RegisterForReflection
public final class NamespaceRepresentationBuilder {
private String id;
private String name;
private String description;
private SunatUrlsRepresentation webServices;
private SunatCredentialsRepresentation credentials;

private NamespaceRepresentationBuilder() {
}
Expand All @@ -46,11 +45,23 @@ public NamespaceRepresentationBuilder withDescription(String description) {
return this;
}

public NamespaceRepresentationBuilder withWebServices(SunatUrlsRepresentation webServices) {
this.webServices = webServices;
return this;
}

public NamespaceRepresentationBuilder withCredentials(SunatCredentialsRepresentation credentials) {
this.credentials = credentials;
return this;
}

public NamespaceRepresentation build() {
NamespaceRepresentation namespaceRepresentation = new NamespaceRepresentation();
namespaceRepresentation.setId(id);
namespaceRepresentation.setName(name);
namespaceRepresentation.setDescription(description);
namespaceRepresentation.setWebServices(webServices);
namespaceRepresentation.setCredentials(credentials);
return namespaceRepresentation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ public enum ErrorType {
FETCH_FILE("No se pudo recuperar el archivo"),
READ_FILE("Documento no pudo ser parseado"),
UNSUPPORTED_DOCUMENT_TYPE("Tipo de documento no válido"),
COMPANY_NOT_FOUND("No se pudo encontrar una empresa para el archivo"),
SEND_FILE("No se pudo enviar el archivo a la SUNAT"),
CHECK_TICKET("No se pudo verificar el ticket en la SUNAT"),
SAVE_CRD_FILE("No se pudo guardar el CDR"),
AMQP_SCHEDULE("No se pudo programar envio"),
RETRY_CONSUMED("Reenvios agotados"),
UNKNOWN("Reenvios agotados"),
;
UNKNOWN("Reenvios agotados");

private final String message;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ public class CompanyEntity extends PanacheEntityBase {
@NotNull
@Valid
@Embedded
public SunatCredentialsEntity sunatCredentials;

@NotNull
@Valid
@Embedded
public SunatUrlsEntity sunatUrls;
public SunatEntity sunat;

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.hibernate.annotations.OnDeleteAction;

import javax.persistence.*;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.ArrayList;
Expand Down Expand Up @@ -54,16 +55,17 @@ public class NamespaceEntity extends PanacheEntityBase {
@Column(name = "created_on")
public Date createdOn;

@Version
@Column(name = "version")
public int version;
@NotNull
@Valid
@Embedded
public SunatEntity sunat;

@OnDelete(action = OnDeleteAction.CASCADE)
@OneToMany(fetch = FetchType.LAZY, mappedBy = "namespace", orphanRemoval = true)
public List<CompanyEntity> companies = new ArrayList<>();

// @OnDelete(action = OnDeleteAction.CASCADE)
// @OneToMany(fetch = FetchType.LAZY, mappedBy = "namespace", orphanRemoval = true)
// public List<UBLDocumentEntity> documents = new ArrayList<>();
@Version
@Column(name = "version")
public int version;

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import javax.validation.constraints.NotNull;

@Embeddable
public class SunatUrlsEntity {
public class SunatEntity {

@NotNull
@URL
Expand All @@ -40,4 +40,12 @@ public class SunatUrlsEntity {
@Column(name = "sunat_url_percepcion_retencion")
public String sunatUrlPercepcionRetencion;

@NotNull
@Column(name = "sunat_username")
public String sunatUsername;

@NotNull
@Column(name = "sunat_password")
public String sunatPassword;

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.github.project.openubl.xsender.keys.utils.StripSecretsUtils;
import io.github.project.openubl.xsender.models.jpa.entities.CompanyEntity;
import io.github.project.openubl.xsender.models.jpa.entities.NamespaceEntity;
import io.github.project.openubl.xsender.models.jpa.entities.SunatEntity;
import io.github.project.openubl.xsender.models.jpa.entities.UBLDocumentEntity;
import org.keycloak.common.util.MultivaluedHashMap;
import org.keycloak.representations.idm.ComponentRepresentation;
Expand All @@ -42,6 +43,14 @@ public static NamespaceRepresentation toRepresentation(NamespaceEntity entity) {
rep.setName(entity.name);
rep.setDescription(entity.description);

// URLs
SunatUrlsRepresentation sunatUrlsRep = toRepresentationUrls(entity.sunat);
rep.setWebServices(sunatUrlsRep);

// Credentials
SunatCredentialsRepresentation credentialsRep = toRepresentationCredentials(entity.sunat);
rep.setCredentials(credentialsRep);

return rep;
}

Expand All @@ -53,25 +62,35 @@ public static CompanyRepresentation toRepresentation(CompanyEntity entity) {
rep.setName(entity.name);
rep.setDescription(entity.description);

if (entity.sunatUrls != null) {
SunatUrlsRepresentation sunatUrlsRep = new SunatUrlsRepresentation();
if (entity.sunat != null) {
// URLs
SunatUrlsRepresentation sunatUrlsRep = toRepresentationUrls(entity.sunat);
rep.setWebServices(sunatUrlsRep);

sunatUrlsRep.setFactura(entity.sunatUrls.sunatUrlFactura);
sunatUrlsRep.setGuia(entity.sunatUrls.sunatUrlGuiaRemision);
sunatUrlsRep.setRetenciones(entity.sunatUrls.sunatUrlPercepcionRetencion);
}

if (entity.sunatCredentials != null) {
SunatCredentialsRepresentation credentialsRep = new SunatCredentialsRepresentation();
// Credentials
SunatCredentialsRepresentation credentialsRep = toRepresentationCredentials(entity.sunat);
rep.setCredentials(credentialsRep);

credentialsRep.setUsername(entity.sunatCredentials.sunatUsername);
}

return rep;
}

private static SunatUrlsRepresentation toRepresentationUrls(SunatEntity entity) {
SunatUrlsRepresentation sunatUrlsRep = new SunatUrlsRepresentation();

sunatUrlsRep.setFactura(entity.sunatUrlFactura);
sunatUrlsRep.setGuia(entity.sunatUrlGuiaRemision);
sunatUrlsRep.setRetenciones(entity.sunatUrlPercepcionRetencion);

return sunatUrlsRep;
}

private static SunatCredentialsRepresentation toRepresentationCredentials(SunatEntity entity) {
SunatCredentialsRepresentation credentialsRep = new SunatCredentialsRepresentation();
credentialsRep.setUsername(entity.sunatUsername);
return credentialsRep;
}

public static DocumentRepresentation toRepresentation(UBLDocumentEntity entity) {
DocumentRepresentation rep = new DocumentRepresentation();

Expand Down Expand Up @@ -127,7 +146,7 @@ public static ComponentRepresentation toRepresentationWithoutConfig(ComponentMod
return rep;
}

// public static List<ConfigPropertyRepresentation> toRepresentation(List<ProviderConfigProperty> configProperties) {
// public static List<ConfigPropertyRepresentation> toRepresentation(List<ProviderConfigProperty> configProperties) {
// List<ConfigPropertyRepresentation> propertiesRep = new LinkedList<>();
// for (ProviderConfigProperty prop : configProperties) {
// ConfigPropertyRepresentation propRep = toRepresentation(prop);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,53 @@
package io.github.project.openubl.xsender.models.utils;

import io.github.project.openubl.xsender.idm.CompanyRepresentation;
import io.github.project.openubl.xsender.idm.NamespaceRepresentation;
import io.github.project.openubl.xsender.idm.SunatCredentialsRepresentation;
import io.github.project.openubl.xsender.idm.SunatUrlsRepresentation;
import io.github.project.openubl.xsender.models.jpa.entities.CompanyEntity;
import io.github.project.openubl.xsender.models.jpa.entities.SunatCredentialsEntity;
import io.github.project.openubl.xsender.models.jpa.entities.SunatUrlsEntity;
import io.github.project.openubl.xsender.models.jpa.entities.NamespaceEntity;
import io.github.project.openubl.xsender.models.jpa.entities.SunatEntity;

public class RepresentationToEntity {

public static NamespaceEntity assign(NamespaceEntity entity, NamespaceRepresentation rep) {
if (rep.getName() != null) {
entity.name = rep.getName();
}
if (rep.getDescription() != null) {
entity.description = rep.getDescription();
}

if (rep.getWebServices() != null) {
assign(entity.sunat, rep.getWebServices());
}
if (rep.getCredentials() != null) {
assign(entity.sunat, rep.getCredentials());
}

return entity;
}

public static CompanyEntity assign(CompanyEntity entity, CompanyRepresentation rep) {
entity.ruc = rep.getRuc();
entity.name = rep.getName();
entity.description = rep.getDescription();

if (entity.sunatUrls == null) {
entity.sunatUrls = new SunatUrlsEntity();
}
if (entity.sunatCredentials == null) {
entity.sunatCredentials = new SunatCredentialsEntity();
if (entity.sunat == null) {
entity.sunat = new SunatEntity();
}

if (rep.getWebServices() != null) {
assign(entity.sunatUrls, rep.getWebServices());
assign(entity.sunat, rep.getWebServices());
}
if (rep.getCredentials() != null) {
assign(entity.sunatCredentials, rep.getCredentials());
assign(entity.sunat, rep.getCredentials());
}

return entity;
}

private static void assign(SunatUrlsEntity entity, SunatUrlsRepresentation rep) {
private static void assign(SunatEntity entity, SunatUrlsRepresentation rep) {
if (rep.getFactura() != null) {
entity.sunatUrlFactura = rep.getFactura();
}
Expand All @@ -59,7 +75,7 @@ private static void assign(SunatUrlsEntity entity, SunatUrlsRepresentation rep)
}
}

private static void assign(SunatCredentialsEntity entity, SunatCredentialsRepresentation rep) {
private static void assign(SunatEntity entity, SunatCredentialsRepresentation rep) {
if (rep.getUsername() != null) {
entity.sunatUsername = rep.getUsername();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.github.project.openubl.xsender.models.SortBean;
import io.github.project.openubl.xsender.models.jpa.NamespaceRepository;
import io.github.project.openubl.xsender.models.jpa.entities.NamespaceEntity;
import io.github.project.openubl.xsender.models.jpa.entities.SunatEntity;
import io.github.project.openubl.xsender.models.utils.EntityToRepresentation;
import io.github.project.openubl.xsender.resources.utils.ResourceUtils;
import io.github.project.openubl.xsender.security.UserIdentity;
Expand Down Expand Up @@ -72,6 +73,13 @@ public Uni<Response> createNameSpace(@NotNull @Valid NamespaceRepresentation rep
namespaceEntity.createdOn = new Date();
namespaceEntity.owner = userIdentity.getUsername();

namespaceEntity.sunat = new SunatEntity();
namespaceEntity.sunat.sunatUsername = rep.getCredentials().getUsername();
namespaceEntity.sunat.sunatPassword = rep.getCredentials().getPassword();
namespaceEntity.sunat.sunatUrlFactura = rep.getWebServices().getFactura();
namespaceEntity.sunat.sunatUrlGuiaRemision = rep.getWebServices().getGuia();
namespaceEntity.sunat.sunatUrlPercepcionRetencion = rep.getWebServices().getRetenciones();

return namespaceRepository.persist(namespaceEntity)
.chain(namespace -> defaultKeyProviders.createProviders(namespace))
.map(unused -> namespaceEntity);
Expand Down
Loading