- Adjust to Native compilation
This commit is contained in:
parent
6b4f90497a
commit
f19a38fd22
12
pom.xml
12
pom.xml
@ -18,29 +18,25 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>3.8.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>2.15.4</version>
|
<version>2.15.4</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<!--dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.13.0</version>
|
<version>3.13.0</version>
|
||||||
</dependency>
|
</dependency-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
<version>4.0.1</version>
|
<version>4.0.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -1,19 +1,8 @@
|
|||||||
package com.banesco;
|
package com.banesco;
|
||||||
|
|
||||||
import com.banesco.domain.model.BackResponse;
|
|
||||||
|
|
||||||
|
|
||||||
public class Commons {
|
public class Commons {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
BackResponse backResponse = BackResponse.builder()
|
System.out.println("Commons...");
|
||||||
.backendCode("200")
|
|
||||||
.httpCode("420")
|
|
||||||
.statusCode("420")
|
|
||||||
.description("asdasd")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
System.out.println(backResponse);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,28 +0,0 @@
|
|||||||
package com.banesco.application.exception;
|
|
||||||
|
|
||||||
import com.banesco.domain.interfaces.BaseStatusCodesEnum;
|
|
||||||
|
|
||||||
public class BanRuntimeException extends RuntimeException {
|
|
||||||
|
|
||||||
protected BaseStatusCodesEnum statusCode;
|
|
||||||
protected String fieldName;
|
|
||||||
protected String backendCode;
|
|
||||||
protected String statusDesc;
|
|
||||||
|
|
||||||
public BanRuntimeException() {
|
|
||||||
super("Internal Error");
|
|
||||||
}
|
|
||||||
|
|
||||||
public BanRuntimeException(BaseStatusCodesEnum statusCode, String fieldName) {
|
|
||||||
super(statusCode.getStatusDesc());
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
this.fieldName = fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BanRuntimeException(String backendCode, String statusDesc) {
|
|
||||||
super(statusDesc);
|
|
||||||
this.backendCode = backendCode;
|
|
||||||
this.statusDesc = statusDesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package com.banesco.application.exception;
|
|
||||||
|
|
||||||
import com.banesco.domain.interfaces.BaseStatusCodesEnum;
|
|
||||||
|
|
||||||
public class InvalidDataBanException extends BanRuntimeException {
|
|
||||||
|
|
||||||
public InvalidDataBanException(BaseStatusCodesEnum statusCode, String fieldName) {
|
|
||||||
super(statusCode, fieldName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
package com.banesco.common.application.exception;
|
||||||
|
|
||||||
|
public class BanBackendException extends RuntimeException {
|
||||||
|
|
||||||
|
protected String backendCode;
|
||||||
|
protected String backendDesc;
|
||||||
|
protected String target;
|
||||||
|
|
||||||
|
public BanBackendException(String backendCode, String backendDesc) {
|
||||||
|
super(backendDesc);
|
||||||
|
this.backendCode = backendCode;
|
||||||
|
this.backendDesc = backendDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BanBackendException(String backendCode, String backendDesc, String target) {
|
||||||
|
super(backendDesc.formatted(target) + ", Target:" + target);
|
||||||
|
this.backendCode = backendCode;
|
||||||
|
this.backendDesc = backendDesc;
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBackendCode() {
|
||||||
|
return backendCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBackendDesc() {
|
||||||
|
return backendDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTarget() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package com.banesco.common.application.exception;
|
||||||
|
|
||||||
|
import com.banesco.common.domain.interfaces.BaseStatusCodesEnum;
|
||||||
|
|
||||||
|
public class BanRuntimeException extends RuntimeException {
|
||||||
|
|
||||||
|
protected BaseStatusCodesEnum statusCode;
|
||||||
|
protected String target;
|
||||||
|
|
||||||
|
public BanRuntimeException() {
|
||||||
|
super("Internal Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
public BanRuntimeException(BaseStatusCodesEnum statusCode, String target) {
|
||||||
|
super(statusCode.getStatusDesc().formatted(target) + ", Target:" + target);
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BanRuntimeException(BaseStatusCodesEnum statusCode) {
|
||||||
|
super(statusCode.getStatusDesc());
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseStatusCodesEnum getStatusCode() {
|
||||||
|
return statusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTarget() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.banesco.domain.interfaces;
|
package com.banesco.common.domain.interfaces;
|
||||||
|
|
||||||
public interface BaseStatusCodesEnum {
|
public interface BaseStatusCodesEnum {
|
||||||
String getStatusCode();
|
String getStatusCode();
|
||||||
54
src/main/java/com/banesco/common/domain/model/ApiConfig.java
Normal file
54
src/main/java/com/banesco/common/domain/model/ApiConfig.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package com.banesco.common.domain.model;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clase de configuración para APIs. Almacena la información necesaria para
|
||||||
|
* conectarse a un servicio API externo, incluyendo URL, configuración de
|
||||||
|
* timeout y parámetros adicionales. Diseñada para ser utilizada como objeto de
|
||||||
|
* configuración en clientes de API y servicios de integración.
|
||||||
|
*/
|
||||||
|
public class ApiConfig {
|
||||||
|
|
||||||
|
String url;
|
||||||
|
ApiTimeout timeout;
|
||||||
|
Map<String, String> config;
|
||||||
|
|
||||||
|
public ApiConfig(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiConfig(String url,
|
||||||
|
ApiTimeout timeout,
|
||||||
|
Map<String, String> config) {
|
||||||
|
|
||||||
|
this.url = url;
|
||||||
|
this.timeout = timeout;
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiTimeout getTimeout() {
|
||||||
|
return timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeout(ApiTimeout timeout) {
|
||||||
|
this.timeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfig(Map<String, String> config) {
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
package com.banesco.common.domain.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clase interna que representa la configuración de tiempos de espera
|
||||||
|
* (timeout) para conexiones a APIs. Define los tiempos máximos de espera
|
||||||
|
* para establecer la conexión y para recibir una respuesta, especificados
|
||||||
|
* en milisegundos.
|
||||||
|
*/
|
||||||
|
public class ApiTimeout{
|
||||||
|
private int connect;
|
||||||
|
private int response;
|
||||||
|
|
||||||
|
public ApiTimeout() {
|
||||||
|
|
||||||
|
}
|
||||||
|
public ApiTimeout(int connect, int response) {
|
||||||
|
this.connect = connect;
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getConnect() {
|
||||||
|
return connect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnect(int connect) {
|
||||||
|
this.connect = connect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getResponse() {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResponse(int response) {
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
package com.banesco.common.domain.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clase para obtener los codigos y mensajes de salida
|
||||||
|
*/
|
||||||
|
public class BackResponse {
|
||||||
|
|
||||||
|
private String backendCode;
|
||||||
|
private int httpCode;
|
||||||
|
private String statusCode;
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
public BackResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public BackResponse(String backendCode,
|
||||||
|
int httpCode,
|
||||||
|
String statusCode,
|
||||||
|
String description) {
|
||||||
|
this.backendCode = backendCode;
|
||||||
|
this.httpCode = httpCode;
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
this.description = backendCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBackendCode() {
|
||||||
|
return backendCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHttpCode() {
|
||||||
|
return httpCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatusCode() {
|
||||||
|
return statusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackendCode(String backendCode) {
|
||||||
|
this.backendCode = backendCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHttpCode(int httpCode) {
|
||||||
|
this.httpCode = httpCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatusCode(String statusCode) {
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{\"backendCode\":\"%s\",\"httpCode\":%d,\"statusCode\":\"%s\",\"description\":\"%s\"}"
|
||||||
|
.formatted(backendCode, httpCode, statusCode, description);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
package com.banesco.common.domain.model;
|
||||||
|
|
||||||
|
|
||||||
|
public class BaseResponse {
|
||||||
|
protected StatusResponse statusResponse;
|
||||||
|
|
||||||
|
public BaseResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseResponse(StatusResponse statusResponse) {
|
||||||
|
this.statusResponse = statusResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StatusResponse getStatusResponse() {
|
||||||
|
return statusResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatusResponse(StatusResponse statusResponse) {
|
||||||
|
this.statusResponse = statusResponse;
|
||||||
|
}
|
||||||
|
}
|
||||||
50
src/main/java/com/banesco/common/domain/model/Device.java
Normal file
50
src/main/java/com/banesco/common/domain/model/Device.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package com.banesco.common.domain.model;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Device {
|
||||||
|
private String type;
|
||||||
|
private String description;
|
||||||
|
private String ipAddress;
|
||||||
|
|
||||||
|
public Device() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Device(String type, String description, String ipAddress) {
|
||||||
|
this.type = type;
|
||||||
|
this.description = description;
|
||||||
|
this.ipAddress = ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIpAddress() {
|
||||||
|
return ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIpAddress(String ipAddress) {
|
||||||
|
this.ipAddress = ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "{\"type\":\"%s\",\"ipAddress\":\"%s\",\"description\":\"%s\"}".formatted(type, ipAddress, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
package com.banesco.common.domain.model;
|
||||||
|
|
||||||
|
|
||||||
|
public class RedisParam {
|
||||||
|
private String prefix;
|
||||||
|
private long expiration;
|
||||||
|
|
||||||
|
public RedisParam() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedisParam(String prefix, long expiration) {
|
||||||
|
this.prefix = prefix;
|
||||||
|
this.expiration = expiration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrefix() {
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrefix(String prefix) {
|
||||||
|
this.prefix = prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getExpiration() {
|
||||||
|
return expiration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExpiration(long expiration) {
|
||||||
|
this.expiration = expiration;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package com.banesco.common.domain.model;
|
||||||
|
|
||||||
|
public record StatusResponse(String statusCode, String statusDesc) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{\"statusCode\":\"" + statusCode + "\",\"statusDesc\":\"" + statusDesc + "\"}";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.banesco.infraestructure.helpers;
|
package com.banesco.common.infraestructure.helpers;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8,7 +8,7 @@ package com.banesco.infraestructure.helpers;
|
|||||||
public class AccountHelper {
|
public class AccountHelper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enmascara un número de cuenta, mostrando solo los primeros 4
|
* Enmascara un número de cuenta, mostrando solo los primeros 4
|
||||||
* y últimos 4 Los dígitos intermedios son reemplazados por asteriscos para proteger la
|
* y últimos 4 Los dígitos intermedios son reemplazados por asteriscos para proteger la
|
||||||
* información sensible del cliente.
|
* información sensible del cliente.
|
||||||
*
|
*
|
||||||
@ -17,6 +17,5 @@ public class AccountHelper {
|
|||||||
*/
|
*/
|
||||||
public static String getMaskedAccountId(String clearAccountId) {
|
public static String getMaskedAccountId(String clearAccountId) {
|
||||||
return clearAccountId.substring(0, 4) + "************" + clearAccountId.substring(clearAccountId.length() - 4);
|
return clearAccountId.substring(0, 4) + "************" + clearAccountId.substring(clearAccountId.length() - 4);
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,163 @@
|
|||||||
|
package com.banesco.common.infraestructure.helpers;
|
||||||
|
|
||||||
|
import java.time.DateTimeException;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clase utilitaria para operaciones relacionadas con fechas y horas.
|
||||||
|
* Proporciona métodos para validar, comparar y calcular períodos entre fechas.
|
||||||
|
*/
|
||||||
|
public class DateHelper {
|
||||||
|
|
||||||
|
|
||||||
|
private final Logger logger = Logger.getLogger(DateHelper.class.getName());
|
||||||
|
private final ZoneId currentZone = ZoneId.of("America/Caracas");
|
||||||
|
private final DateTimeFormatter DATE_YYYY_MM_DD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
private final DateTimeFormatter TIME_HH_MM_SS = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||||
|
|
||||||
|
private static class SingletonHelper {
|
||||||
|
private static final DateHelper INSTANCE = new DateHelper();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructo private to no allow other Instances
|
||||||
|
*/
|
||||||
|
private DateHelper() {
|
||||||
|
// not public instance
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Instance Singleton
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static DateHelper getInstance() {
|
||||||
|
return SingletonHelper.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permite obtener la Fecha Hora Actual
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public LocalDateTime getCurrentDateTime() {
|
||||||
|
return LocalDateTime.now(currentZone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permite Obtener la Hora para una FechaHora, en caso de ser null se obtiene la hora actual
|
||||||
|
*
|
||||||
|
* @param now Feha Hora Local
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getTime(LocalDateTime now) {
|
||||||
|
if (now == null) {
|
||||||
|
now = LocalDateTime.now(currentZone);
|
||||||
|
}
|
||||||
|
return now.format(TIME_HH_MM_SS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permite Obtener la Fecha para una FechaHora, en caso de ser null se obtiene la fecha actual
|
||||||
|
*
|
||||||
|
* @param now Feha Hora Local
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getDate(LocalDateTime now) {
|
||||||
|
if (now == null) {
|
||||||
|
now = LocalDateTime.now(currentZone);
|
||||||
|
}
|
||||||
|
return now.format(DATE_YYYY_MM_DD);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check is Current Hour is in Hour Range passed by parameters
|
||||||
|
* if Parameters are equal then return false
|
||||||
|
*
|
||||||
|
* @param rangeHourBegin Cadena de la hora de inicio del Rango
|
||||||
|
* @param rangeHourFinish Candena de la hora de fin del Rango
|
||||||
|
* @param hourStrToCheck Hora en cadena para evaluar si se encuentra entre el rango de parametros
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isHourInRange(String rangeHourBegin, String rangeHourFinish, String hourStrToCheck) {
|
||||||
|
|
||||||
|
return isHourInRange(Integer.parseInt(rangeHourBegin.replace(":", "")),
|
||||||
|
Integer.parseInt(rangeHourFinish.replace(":", "")),
|
||||||
|
hourStrToCheck
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check is Current Hour is in Hour Range passed by parameters
|
||||||
|
* if Parameters are equal then return false
|
||||||
|
*
|
||||||
|
* @param rangeHourBegin Numero entero de la hora de inicio del Rango
|
||||||
|
* @param rangeHourFinish Numero entero de la hora de fin del Rango
|
||||||
|
* @param hourStrToCheck Hora en cadena para evaluar si se encuentra entre el rango de parametros
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isHourInRange(int rangeHourBegin, int rangeHourFinish, String hourStrToCheck) {
|
||||||
|
boolean mustValidateService = false;
|
||||||
|
|
||||||
|
if (rangeHourBegin == rangeHourFinish) {
|
||||||
|
return mustValidateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
int currentHour = Integer.parseInt(hourStrToCheck.replace(":", ""));
|
||||||
|
|
||||||
|
|
||||||
|
if (rangeHourBegin > rangeHourFinish) { // hour end is less than hour start, => then validate next day
|
||||||
|
|
||||||
|
if (currentHour <= rangeHourFinish || currentHour >= rangeHourBegin) {
|
||||||
|
mustValidateService = true;
|
||||||
|
}
|
||||||
|
} else if (currentHour >= rangeHourBegin && currentHour <= rangeHourFinish) { // Hour the same day
|
||||||
|
mustValidateService = true;
|
||||||
|
}
|
||||||
|
logger.log(Level.INFO, "La hora (%s => %d) %sesta entre %d y %d ".formatted(
|
||||||
|
hourStrToCheck,
|
||||||
|
currentHour,
|
||||||
|
(mustValidateService ? "" : "NO "),
|
||||||
|
rangeHourBegin,
|
||||||
|
rangeHourFinish));
|
||||||
|
|
||||||
|
return mustValidateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calcula el número de días entre dos fechas.
|
||||||
|
*
|
||||||
|
* @param startDate Fecha de inicio en formato ISO (yyyy-MM-dd)
|
||||||
|
* @param endDate Fecha de fin en formato ISO (yyyy-MM-dd)
|
||||||
|
* @return El número de días entre las fechas o -1 si ocurre un error al
|
||||||
|
* procesar las fechas
|
||||||
|
*/
|
||||||
|
public long daysBetweenTwoDates(String startDate, String endDate) {
|
||||||
|
try {
|
||||||
|
return ChronoUnit.DAYS.between(LocalDate.parse(startDate), LocalDate.parse(endDate));
|
||||||
|
} catch (DateTimeException dte) {
|
||||||
|
return -1L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifica si la fecha de inicio es anterior o igual a la fecha de fin.
|
||||||
|
*
|
||||||
|
* @param startDate Fecha de inicio en formato ISO (yyyy-MM-dd)
|
||||||
|
* @param endDate Fecha de fin en formato ISO (yyyy-MM-dd)
|
||||||
|
* @return true si startDate es anterior o igual a endDate, false en caso
|
||||||
|
* contrario
|
||||||
|
*/
|
||||||
|
public boolean isStartDateBeforeEndDate(String startDate, String endDate) {
|
||||||
|
return LocalDate.parse(startDate).isBefore(LocalDate.parse(endDate))
|
||||||
|
|| LocalDate.parse(startDate).isEqual(LocalDate.parse(endDate));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,96 @@
|
|||||||
|
package com.banesco.common.infraestructure.helpers;
|
||||||
|
|
||||||
|
import com.banesco.common.domain.model.Device;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
public class DeviceHelper {
|
||||||
|
|
||||||
|
private boolean readDeviceFromRequest;
|
||||||
|
private final String DESKTOP = "Desktop";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nombres de cabeceras HTTP que pueden contener la dirección IP del
|
||||||
|
* cliente. Se revisan en orden para encontrar la IP real considerando
|
||||||
|
* proxies y balanceadores.
|
||||||
|
*/
|
||||||
|
private final String[] IP_HEADER_NAMES = {
|
||||||
|
"X-Forwarded-For",
|
||||||
|
"Proxy-Client-IP",
|
||||||
|
"WL-Proxy-Client-IP",
|
||||||
|
"HTTP_X_FORWARDED_FOR",
|
||||||
|
"HTTP_X_FORWARDED",
|
||||||
|
"HTTP_X_CLUSTER_CLIENT_IP",
|
||||||
|
"HTTP_CLIENT_IP",
|
||||||
|
"HTTP_FORWARDED_FOR",
|
||||||
|
"HTTP_FORWARDED",
|
||||||
|
"HTTP_VIA",
|
||||||
|
"REMOTE_ADDR"
|
||||||
|
};
|
||||||
|
|
||||||
|
public DeviceHelper() {
|
||||||
|
// Lee la propiedad del sistema. Si no existe, asume false por defecto.
|
||||||
|
String readDeviceProperty = System.getProperty("api.server-request.read-device");
|
||||||
|
this.readDeviceFromRequest = readDeviceProperty == null ? false : Boolean.parseBoolean(readDeviceProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene la dirección IP remota del cliente a partir de la solicitud HTTP.
|
||||||
|
* Revisa varias cabeceras HTTP que podrían contener la IP real del cliente
|
||||||
|
* considerando proxies y balanceadores de carga.
|
||||||
|
*
|
||||||
|
* @param request La solicitud HTTP
|
||||||
|
* @return La dirección IP remota del cliente, o "0.0.0.0" si la solicitud
|
||||||
|
* es nula
|
||||||
|
*/
|
||||||
|
public String getRemoteIP(HttpServletRequest request) {
|
||||||
|
if (request == null) {
|
||||||
|
return "0.0.0.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String header : IP_HEADER_NAMES) {
|
||||||
|
String ipList = request.getHeader(header);
|
||||||
|
if (!StringHelper.isEmpty(ipList) && !"unknown".equalsIgnoreCase(ipList)) {
|
||||||
|
return ipList.split(",")[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return request.getRemoteAddr();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Llena la información del dispositivo remoto del cliente en el objeto
|
||||||
|
* Device. Si se configura readDeviceFromRequest como true, siempre se
|
||||||
|
* obtendrá la información del dispositivo desde la solicitud HTTP,
|
||||||
|
* independientemente de si ya existe.
|
||||||
|
*
|
||||||
|
* @param servletRequest La solicitud HTTP
|
||||||
|
* @param device El objeto Device existente a actualizar o null para crear
|
||||||
|
* uno nuevo
|
||||||
|
* @return El objeto Device con la información del cliente actualizada
|
||||||
|
*/
|
||||||
|
public Device fillRemoteDevice(HttpServletRequest servletRequest, Device device) {
|
||||||
|
if (device == null) {
|
||||||
|
device = new Device();
|
||||||
|
}
|
||||||
|
if (StringHelper.isEmpty(device.getIpAddress()) || readDeviceFromRequest) {
|
||||||
|
device.setIpAddress(getRemoteIP(servletRequest));
|
||||||
|
String userAgent = servletRequest.getHeader("user-agent");
|
||||||
|
if (userAgent == null) {
|
||||||
|
|
||||||
|
device.setType(DESKTOP);
|
||||||
|
device.setDescription(DESKTOP);
|
||||||
|
} else {
|
||||||
|
device.setDescription(userAgent);
|
||||||
|
if (userAgent.toLowerCase().contains("mobi")) {
|
||||||
|
device.setType("Mobile");
|
||||||
|
} else {
|
||||||
|
device.setType(DESKTOP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,93 @@
|
|||||||
|
package com.banesco.common.infraestructure.helpers;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class JsonHelper {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(JsonHelper.class.getName());
|
||||||
|
public static final ObjectMapper MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
|
static {
|
||||||
|
MAPPER.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||||
|
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert Object to jsonString
|
||||||
|
*
|
||||||
|
* @param object El objeto a convertir en JSON.
|
||||||
|
* @return La cadena JSON resultante o null si ocurre un error.
|
||||||
|
*/
|
||||||
|
public static String getJsonFromObject(Object object) {
|
||||||
|
if (object == null) {
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return MAPPER.writeValueAsString(object);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
logger.log(Level.SEVERE, "Error parsing objeto a JSON: {0}", e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convierte una cadena JSON en un objeto Java de la clase especificada.
|
||||||
|
*
|
||||||
|
* @param json La cadena JSON a convertir.
|
||||||
|
* @param className La clase del objeto Java resultante.
|
||||||
|
* @param <T> El tipo del objeto resultante.
|
||||||
|
* @return El objeto Java resultante, o null si ocurre un error o la cadena
|
||||||
|
* JSON está vacía.
|
||||||
|
*/
|
||||||
|
public static <T> T getObjectFromJson(String json, Class<T> className) {
|
||||||
|
if (json == null || json.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return MAPPER.readValue(json, className);
|
||||||
|
} catch (JsonProcessingException | IllegalArgumentException e) {
|
||||||
|
logger.log(Level.WARNING, "Error parsing JSON a objeto: {0}", e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> List<T> getListFromJson(String json, Class<T> className) {
|
||||||
|
if (json == null || json.isEmpty()) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return MAPPER.readValue(json,
|
||||||
|
MAPPER.getTypeFactory().constructCollectionType(List.class, className)
|
||||||
|
);
|
||||||
|
} catch (JsonProcessingException | IllegalArgumentException e) {
|
||||||
|
logger.log(Level.WARNING, "Error parsing JSON a List Object: {0}", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> List<T> getListFromInputStream(InputStream inputStream, Class<T> className) throws IOException {
|
||||||
|
if (inputStream == null) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return MAPPER.readValue(inputStream,
|
||||||
|
MAPPER.getTypeFactory().constructCollectionType(List.class, className)
|
||||||
|
);
|
||||||
|
} catch (JsonProcessingException | IllegalArgumentException e) {
|
||||||
|
logger.log(Level.WARNING, "Error parsing JSON a List Object: {0}", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,118 @@
|
|||||||
|
package com.banesco.common.infraestructure.helpers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clase utilitaria para la generación de mensajes de registro (logging).
|
||||||
|
* Facilita la creación de cadenas formateadas para registrar información de
|
||||||
|
* solicitudes y respuestas, tanto públicas como privadas, así como mensajes de
|
||||||
|
* error. Utiliza un formato estandarizado para mejorar la legibilidad y
|
||||||
|
* facilitar el análisis de los registros del sistema.
|
||||||
|
*/
|
||||||
|
public class LoggerHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construye una cadena de información para una solicitud pública.
|
||||||
|
*
|
||||||
|
* @param requestId El ID de la solicitud.
|
||||||
|
* @param request El objeto de solicitud.
|
||||||
|
* @param <T> El tipo del objeto de solicitud.
|
||||||
|
* @return Una cadena de información formateada.
|
||||||
|
*/
|
||||||
|
public static <T> String buildInfoRequest(String requestId, T request) {
|
||||||
|
return String.format("[PUB RQ: %s] [%s]", requestId, JsonHelper.getJsonFromObject(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construye una cadena de información para una solicitud pública.
|
||||||
|
*
|
||||||
|
* @param requestId El ID de la solicitud.
|
||||||
|
* @param request El request en cadena de la solicitud.
|
||||||
|
* @return Una cadena de información formateada.
|
||||||
|
*/
|
||||||
|
public static <T> String buildInfoRequest(String requestId, String request) {
|
||||||
|
return String.format("[PUB RQ: %s] [%s]", requestId, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construye una cadena de información para una respuesta pública.
|
||||||
|
*
|
||||||
|
* @param requestId El ID de la solicitud.
|
||||||
|
* @param response El objeto de respuesta.
|
||||||
|
* @param <T> El tipo del objeto de respuesta.
|
||||||
|
* @return Una cadena de información formateada.
|
||||||
|
*/
|
||||||
|
public static <T> String buildInfoResponse(String requestId, T response) {
|
||||||
|
return String.format("[PUB RS: %s] [%s]", requestId, JsonHelper.getJsonFromObject(response));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construye una cadena de información para una respuesta pública.
|
||||||
|
*
|
||||||
|
* @param requestId El ID de la solicitud.
|
||||||
|
* @param response El objeto en cadena de respuesta.
|
||||||
|
* @return Una cadena de información formateada.
|
||||||
|
*/
|
||||||
|
public static String buildInfoResponse(String requestId, String response) {
|
||||||
|
return String.format("[PUB RS: %s] [%s]", requestId, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construye una cadena de información para una solicitud privada.
|
||||||
|
*
|
||||||
|
* @param requestId El ID de la solicitud.
|
||||||
|
* @param name El nombre de la solicitud privada.
|
||||||
|
* @param request El objeto de solicitud.
|
||||||
|
* @param <T> El tipo del objeto de solicitud.
|
||||||
|
* @return Una cadena de información formateada.
|
||||||
|
*/
|
||||||
|
public static <T> String buildInfoPrivateRequest(String requestId, String name, T request) {
|
||||||
|
return String.format("[PRV RQ %s: %s] [%s]", name, requestId, JsonHelper.getJsonFromObject(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construye una cadena de información para una solicitud privada.
|
||||||
|
*
|
||||||
|
* @param requestId El ID de la solicitud.
|
||||||
|
* @param name El nombre de la solicitud privada.
|
||||||
|
* @param request El objeto en cadena de la solicitud.
|
||||||
|
* @return Una cadena de información formateada.
|
||||||
|
*/
|
||||||
|
public static String buildInfoPrivateRequest(String requestId, String name, String request) {
|
||||||
|
return String.format("[PRV RQ %s: %s] [%s]", name, requestId, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construye una cadena de información para una respuesta privada.
|
||||||
|
*
|
||||||
|
* @param requestId El ID de la solicitud.
|
||||||
|
* @param name El nombre de la respuesta privada.
|
||||||
|
* @param response El objeto de respuesta.
|
||||||
|
* @param <T> El tipo del objeto de respuesta.
|
||||||
|
* @return Una cadena de información formateada.
|
||||||
|
*/
|
||||||
|
public static <T> String buildInfoPrivateResponse(String requestId, String name, T response) {
|
||||||
|
return String.format("[PRV RS %s: %s] [%s]", name, requestId, JsonHelper.getJsonFromObject(response));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construye una cadena de información para una respuesta privada.
|
||||||
|
*
|
||||||
|
* @param requestId El ID de la solicitud.
|
||||||
|
* @param name El nombre de la respuesta privada.
|
||||||
|
* @param response El objeto en cadena de la respuesta.
|
||||||
|
* @return Una cadena de información formateada.
|
||||||
|
*/
|
||||||
|
public static String buildInfoPrivateResponse(String requestId, String name, String response) {
|
||||||
|
return String.format("[PRV RS %s: %s] [%s]", name, requestId, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construye una cadena de error.
|
||||||
|
*
|
||||||
|
* @param requestId El ID de la solicitud asociada al error.
|
||||||
|
* @param out El mensaje de error.
|
||||||
|
* @return Una cadena de error formateada.
|
||||||
|
*/
|
||||||
|
public static String buildError(String requestId, String out) {
|
||||||
|
return String.format("[ERROR %s] [%s]", requestId, out);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,81 @@
|
|||||||
|
package com.banesco.common.infraestructure.helpers;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clase utilitaria para operaciones relacionadas con solicitudes HTTP y
|
||||||
|
* generación de identificadores. Proporciona métodos para generar IDs únicos,
|
||||||
|
* obtener información del cliente y gestionar información del dispositivo.
|
||||||
|
*/
|
||||||
|
public class RequestHelper {
|
||||||
|
|
||||||
|
private final String ALPHANUMERIC_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
private final int baseCharacterLen = ALPHANUMERIC_CHARACTERS.length();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permite tener una cadena aleatoria de caracteres numericos
|
||||||
|
*
|
||||||
|
* @param len longitud de la cadena numerica a retornar
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String randomNumeric(int len) {
|
||||||
|
char[] chars = new char[len];
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
chars[i] = (char) ThreadLocalRandom.current().nextInt(48, 58); // ascii index number
|
||||||
|
}
|
||||||
|
|
||||||
|
return new String(chars);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permite tener una cadena aleatoria de caracteres alfa-numericos
|
||||||
|
*
|
||||||
|
* @param len longitud de la cadena alfa-numerica a retornar
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String randomAlphanumeric(int len) {
|
||||||
|
char[] chars = new char[len];
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
chars[i] = ALPHANUMERIC_CHARACTERS.charAt(ThreadLocalRandom.current().nextInt(baseCharacterLen));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new String(chars);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retorna Identificador de la Instancia del Request, usando como prefijo un valor predefinido
|
||||||
|
* ejemplos: P2P, REM,
|
||||||
|
* Facilita identificar el origen de los Requests
|
||||||
|
* Deberia obtenerse una vez al inicia el Request
|
||||||
|
*
|
||||||
|
* @param apiSourceId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getInstanceId(String apiSourceId) {
|
||||||
|
return (apiSourceId == null ? "INST" : apiSourceId).concat(randomAlphanumeric(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retorna un Identificador del Request, se sugiere usar el getInstanceId creada como prefijo.
|
||||||
|
* Usar uno para Cada Request que implique afectacion financiera
|
||||||
|
*
|
||||||
|
* @param instanceId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getRequestId(String instanceId) {
|
||||||
|
return instanceId.concat("REQ").concat(randomAlphanumeric(20));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permite Obtener un valor Numerico de Identificador de Transaccion
|
||||||
|
*
|
||||||
|
* @param len
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getTransactionId(int len) {
|
||||||
|
return randomNumeric(len);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,106 @@
|
|||||||
|
package com.banesco.common.infraestructure.helpers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clase utilitaria para operaciones con cadenas de texto (strings). Proporciona
|
||||||
|
* métodos para validar, manipular y formatear cadenas de texto. Incluye
|
||||||
|
* funcionalidades como verificación de tipos numéricos, validación de cadenas
|
||||||
|
* no vacías y funciones de formato como relleno de caracteres.
|
||||||
|
*/
|
||||||
|
public class StringHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifica si una cadena de texto representa un número entero.
|
||||||
|
*
|
||||||
|
* @param value La cadena de texto a verificar.
|
||||||
|
* @return true si la cadena es un número entero válido, false en caso
|
||||||
|
* contrario.
|
||||||
|
* @throws NumberFormatException Si el string no tiene el formato adeacuado
|
||||||
|
*/
|
||||||
|
public static boolean isNumeric(String value) {
|
||||||
|
if (value == null || value.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Integer.parseInt(value);
|
||||||
|
return true;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifica si una cadena de texto es nula o está vacía después de
|
||||||
|
* eliminar espacios en blanco.
|
||||||
|
*
|
||||||
|
* @param value La cadena de texto a verificar.
|
||||||
|
* @return true si la cadena está vacía, false en caso contrario.
|
||||||
|
*/
|
||||||
|
public static boolean isEmpty(String value) {
|
||||||
|
return value == null || value.trim().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rellena una cadena de texto con un carácter específico a la izquierda
|
||||||
|
* hasta alcanzar la longitud deseada.
|
||||||
|
*
|
||||||
|
* @param inputStr La cadena de texto a rellenar.
|
||||||
|
* @param strLenOut La longitud deseada de la cadena resultante.
|
||||||
|
* @param padChar El carácter de relleno.
|
||||||
|
* @return La cadena rellenada con el carácter especificado a la izquierda.
|
||||||
|
*/
|
||||||
|
public static String leftPad(String inputStr, int strLenOut, char padChar) {
|
||||||
|
if (inputStr == null) {
|
||||||
|
inputStr = ""; // Handle null input
|
||||||
|
}
|
||||||
|
int padLength = strLenOut - inputStr.length();
|
||||||
|
if (padLength <= 0) {
|
||||||
|
return inputStr; // No padding needed
|
||||||
|
}
|
||||||
|
|
||||||
|
char[] paddedString = new char[padLength];
|
||||||
|
for (int i = 0; i < padLength; i++) {
|
||||||
|
paddedString[i] = padChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new String(paddedString).concat(inputStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permite convertir nombre de propiedad separada con (,-) to CamelCase
|
||||||
|
*
|
||||||
|
* @param inputStr Cadena de texto a convertir
|
||||||
|
* @param firstUpper Flag que indica si la primera letra es Mayuscula
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String convertToCamelCase(String inputStr, boolean firstUpper) {
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
boolean capitalizeNext = firstUpper;
|
||||||
|
|
||||||
|
for (char ch : inputStr.toCharArray()) {
|
||||||
|
if (ch == '.' || ch == '-') {
|
||||||
|
capitalizeNext = true; // Next character should be capitalized
|
||||||
|
} else {
|
||||||
|
if (capitalizeNext) {
|
||||||
|
result.append(Character.toUpperCase(ch)); // Capitalize current character
|
||||||
|
capitalizeNext = false; // Reset flag
|
||||||
|
} else {
|
||||||
|
result.append(Character.toLowerCase(ch)); // Append in lowercase
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param inputStr Cadena de texto a convertir en UpperCamelCase
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String convertToUpperCamelCase(String inputStr) {
|
||||||
|
return convertToCamelCase(inputStr, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,4 +1,8 @@
|
|||||||
package com.banesco.infraestructure.repository;
|
package com.banesco.common.infraestructure.repository;
|
||||||
|
|
||||||
|
import com.banesco.common.domain.model.BackResponse;
|
||||||
|
import com.banesco.common.infraestructure.helpers.JsonHelper;
|
||||||
|
import com.banesco.common.infraestructure.helpers.StringHelper;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -9,10 +13,6 @@ import java.util.Map;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.banesco.domain.model.BackResponse;
|
|
||||||
import com.banesco.infraestructure.helpers.JsonHelper;
|
|
||||||
import com.banesco.infraestructure.helpers.StringHelper;
|
|
||||||
|
|
||||||
public class MessageRepository {
|
public class MessageRepository {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(MessageRepository.class.getName());
|
private static final Logger logger = Logger.getLogger(MessageRepository.class.getName());
|
||||||
@ -21,7 +21,6 @@ public class MessageRepository {
|
|||||||
* Respuesta de error por defecto que se utiliza cuando no se encuentra un
|
* Respuesta de error por defecto que se utiliza cuando no se encuentra un
|
||||||
* error específico.
|
* error específico.
|
||||||
*/
|
*/
|
||||||
public final BackResponse DEFAULT_ERROR = new BackResponse("CONFLICT");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapa que almacena múltiples mapas de códigos de error, donde la clave
|
* Mapa que almacena múltiples mapas de códigos de error, donde la clave
|
||||||
@ -33,14 +32,14 @@ public class MessageRepository {
|
|||||||
* Carga los mensajes de error desde un InputStream y los almacena en un
|
* Carga los mensajes de error desde un InputStream y los almacena en un
|
||||||
* mapa.
|
* mapa.
|
||||||
*
|
*
|
||||||
* @param inputStream El InputStream que contiene los datos JSON de los
|
* @param inputStream El InputStream que contiene los datos JSON de los
|
||||||
* mensajes de error.
|
* mensajes de error.
|
||||||
* @param messageFileKey La clave del archivo de mensajes, utilizada para
|
* @param messageFileKey La clave del archivo de mensajes, utilizada para
|
||||||
* almacenar el mapa en mapErrorsMultiple.
|
* almacenar el mapa en mapErrorsMultiple.
|
||||||
* @return Un mapa que contiene los códigos de error como claves y los
|
* @return Un mapa que contiene los códigos de error como claves y los
|
||||||
* objetos BackResponse como valores.
|
* objetos BackResponse como valores.
|
||||||
* @throws IOException Si ocurre un error de entrada/salida al leer el
|
* @throws IOException Si ocurre un error de entrada/salida al leer el
|
||||||
* InputStream.
|
* InputStream.
|
||||||
*/
|
*/
|
||||||
private Map<String, BackResponse> loadFile(InputStream inputStream, String messageFileKey) throws IOException {
|
private Map<String, BackResponse> loadFile(InputStream inputStream, String messageFileKey) throws IOException {
|
||||||
Map<String, BackResponse> mapStatusCodes = new HashMap<>();
|
Map<String, BackResponse> mapStatusCodes = new HashMap<>();
|
||||||
@ -56,9 +55,9 @@ public class MessageRepository {
|
|||||||
* mapa.
|
* mapa.
|
||||||
*
|
*
|
||||||
* @param messageFileKey La clave del archivo de mensajes, utilizada para
|
* @param messageFileKey La clave del archivo de mensajes, utilizada para
|
||||||
* almacenar el mapa en mapErrorsMultiple.
|
* almacenar el mapa en mapErrorsMultiple.
|
||||||
* @param jsonString La cadena JSON que contiene los datos de los mensajes
|
* @param jsonString La cadena JSON que contiene los datos de los mensajes
|
||||||
* de error.
|
* de error.
|
||||||
* @throws IOException Si ocurre un error al procesar la cadena JSON.
|
* @throws IOException Si ocurre un error al procesar la cadena JSON.
|
||||||
*/
|
*/
|
||||||
public void loadMessagesFromString(String messageFileKey, String jsonString) throws IOException {
|
public void loadMessagesFromString(String messageFileKey, String jsonString) throws IOException {
|
||||||
@ -74,13 +73,13 @@ public class MessageRepository {
|
|||||||
* específico.
|
* específico.
|
||||||
*
|
*
|
||||||
* @param responseFile El nombre del archivo de respuesta para el cual se
|
* @param responseFile El nombre del archivo de respuesta para el cual se
|
||||||
* desea obtener el mapa de errores.
|
* desea obtener el mapa de errores.
|
||||||
* @return Un mapa que contiene los códigos de error como claves y los
|
* @return Un mapa que contiene los códigos de error como claves y los
|
||||||
* objetos BackResponse como valores, o null si no se encuentra el mapa.
|
* objetos BackResponse como valores, o null si no se encuentra el mapa.
|
||||||
*/
|
*/
|
||||||
public Map<String, BackResponse> getErrorMap(String responseFile) {
|
public Map<String, BackResponse> getErrorMap(String responseFile, boolean insideProperties) {
|
||||||
Map<String, BackResponse> errorMap = mapErrorsMultiple.get(responseFile);
|
Map<String, BackResponse> errorMap = mapErrorsMultiple.get(responseFile);
|
||||||
if (errorMap != null && !errorMap.isEmpty()) {
|
if (insideProperties || (errorMap != null && !errorMap.isEmpty())) {
|
||||||
return errorMap;
|
return errorMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,19 +91,20 @@ public class MessageRepository {
|
|||||||
return loadFile(new FileInputStream("/config/".concat(fileName)), responseFile);
|
return loadFile(new FileInputStream("/config/".concat(fileName)), responseFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Si no se encuentra el archivo en /config/, intenta cargarlo desde el classpath.
|
// Si no se encuentra el archivo en /config/, intenta cargarlo desde el classpath.
|
||||||
logger.log(Level.WARNING, String.format("Path /config/%s not found. Loading local from errors-mapping/%s", fileName, fileName));
|
logger.log(Level.WARNING, "Path /config/" + fileName + " not found. Loading local from errors-mapping/" + fileName);
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
InputStream inputStream = classLoader.getResourceAsStream("errors-mapping/" + fileName);
|
InputStream inputStream = classLoader.getResourceAsStream("errors-mapping/" + fileName);
|
||||||
if (inputStream == null) {
|
if (inputStream == null) {
|
||||||
// Si no se encuentra el archivo en el classpath, registra un error y devuelve null.
|
// Si no se encuentra el archivo en el classpath, registra un error y devuelve null.
|
||||||
logger.log(Level.SEVERE, String.format("Resource errors-mapping/%s not found.", fileName));
|
logger.log(Level.SEVERE, "Resource errors-mapping/" + fileName + " not found.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return loadFile(inputStream, responseFile);
|
return loadFile(inputStream, responseFile);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Si ocurre un error al cargar el archivo desde cualquier ubicación, registra un error y devuelve null.
|
// Si ocurre un error al cargar el archivo desde cualquier ubicación, registra un error y devuelve null.
|
||||||
logger.log(Level.SEVERE, String.format("Error loading Service Messages from /config/%s and errors-mapping/%s: %s", fileName, fileName, e.getMessage()));
|
logger.log(Level.SEVERE, "Error getting Service Messages to /config/".concat(fileName) + ": " + e.getMessage());
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,8 @@
|
|||||||
package com.banesco.infraestructure.repository;
|
package com.banesco.common.infraestructure.repository;
|
||||||
|
|
||||||
|
import com.banesco.common.domain.model.ApiConfig;
|
||||||
|
import com.banesco.common.infraestructure.helpers.JsonHelper;
|
||||||
|
import com.banesco.common.infraestructure.helpers.LoggerHelper;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -13,10 +17,6 @@ import java.util.concurrent.Executors;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.banesco.infraestructure.config.ApiConfig;
|
|
||||||
import com.banesco.infraestructure.helpers.JsonHelper;
|
|
||||||
import com.banesco.infraestructure.helpers.LoggerHelper;
|
|
||||||
|
|
||||||
public class RegisterSecurityRepository {
|
public class RegisterSecurityRepository {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(RegisterSecurityRepository.class.getName());
|
private static final Logger logger = Logger.getLogger(RegisterSecurityRepository.class.getName());
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
package com.banesco.common.infraestructure.service;
|
||||||
|
|
||||||
|
import com.banesco.common.domain.model.BackResponse;
|
||||||
|
import com.banesco.common.domain.model.StatusResponse;
|
||||||
|
import com.banesco.common.infraestructure.repository.MessageRepository;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class MessageService {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(MessageService.class.getName());
|
||||||
|
private final MessageRepository messageRepository;
|
||||||
|
|
||||||
|
private final String CONFLICT = "CONFLICT";
|
||||||
|
private final BackResponse DEFAULT_ERROR = new BackResponse(
|
||||||
|
CONFLICT,
|
||||||
|
409,
|
||||||
|
CONFLICT,
|
||||||
|
CONFLICT
|
||||||
|
);
|
||||||
|
|
||||||
|
private boolean messagesInsideProperties = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor de MessageService.
|
||||||
|
*
|
||||||
|
* @param messageRepository El repositorio de mensajes que se utilizará para
|
||||||
|
* cargar y obtener mensajes de error.
|
||||||
|
*/
|
||||||
|
public MessageService(MessageRepository messageRepository) {
|
||||||
|
this.messageRepository = messageRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Carga mensajes desde una cadena JSON en el repositorio de mensajes.
|
||||||
|
*
|
||||||
|
* @param responseFileName El nombre del archivo de respuesta asociado con
|
||||||
|
* los mensajes.
|
||||||
|
* @param jsonResponse La cadena JSON que contiene los mensajes.
|
||||||
|
*/
|
||||||
|
public void loadMessageFromJson(String responseFileName, String jsonResponse) {
|
||||||
|
messagesInsideProperties = true;
|
||||||
|
try {
|
||||||
|
messageRepository.loadMessagesFromString(responseFileName, jsonResponse);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.log(Level.SEVERE, "Error loading messages from JSON: %s".formatted(ex.getMessage()), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene una respuesta de estado (BackResponse) basada en el código de
|
||||||
|
* backend y el nombre del archivo de respuesta.
|
||||||
|
*
|
||||||
|
* @param responseFileName El nombre del archivo de respuesta.
|
||||||
|
* @param backendCode El código de backend para buscar la respuesta.
|
||||||
|
* @return La respuesta de estado (BackResponse) correspondiente al código
|
||||||
|
* de backend, la respuesta por defecto si no se encuentra, o null si hay un
|
||||||
|
* error.
|
||||||
|
*/
|
||||||
|
public BackResponse geStatusResponse(String responseFileName, String backendCode) {
|
||||||
|
logger.log(Level.INFO, "Finding backendCode: \"%s\" in File: \"%s\"".formatted(backendCode, responseFileName));
|
||||||
|
Map<String, BackResponse> errors = messageRepository.getErrorMap(responseFileName, messagesInsideProperties);
|
||||||
|
|
||||||
|
if (errors == null || errors.isEmpty()) {
|
||||||
|
logger.log(Level.WARNING, "Error map for %s is empty or null.".formatted(responseFileName));
|
||||||
|
return DEFAULT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
BackResponse backResponse = null;
|
||||||
|
try {
|
||||||
|
backResponse = errors.get(backendCode);
|
||||||
|
if (backResponse == null) {
|
||||||
|
backResponse = errors.get("default");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.log(Level.WARNING, "Error code: %s not found in %s. Using default.".formatted(backendCode, responseFileName), e);
|
||||||
|
try {
|
||||||
|
backResponse = errors.get("default");
|
||||||
|
} catch (Exception e2) {
|
||||||
|
logger.log(Level.SEVERE, "Error getting default code.", e2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (backResponse == null) {
|
||||||
|
logger.log(Level.WARNING, "Error code: %s and default not found in %s.".formatted(backendCode, responseFileName));
|
||||||
|
return DEFAULT_ERROR;
|
||||||
|
}
|
||||||
|
return backResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StatusResponse backToStatusResponse(BackResponse backResponse, String target) {
|
||||||
|
return new StatusResponse(
|
||||||
|
backResponse.getStatusCode(),
|
||||||
|
target == null ? backResponse.getDescription() :
|
||||||
|
backResponse.getDescription().formatted(target)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,9 +1,8 @@
|
|||||||
package com.banesco.infraestructure.utils;
|
package com.banesco.common.infraestructure.utils;
|
||||||
|
|
||||||
import java.time.DateTimeException;
|
import java.time.DateTimeException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clase para validación de fechas con configuración flexible. Permite validar
|
* Clase para validación de fechas con configuración flexible. Permite validar
|
||||||
@ -15,13 +14,13 @@ import java.util.regex.Pattern;
|
|||||||
public class DateValidator {
|
public class DateValidator {
|
||||||
|
|
||||||
private final DateTimeFormatter dateFormatter;
|
private final DateTimeFormatter dateFormatter;
|
||||||
private final Pattern datePattern;
|
private final PatternValidator datePattern;
|
||||||
private final int minYear;
|
private final int minYear;
|
||||||
private final int maxYear;
|
private final int maxYear;
|
||||||
|
|
||||||
private DateValidator(Builder builder) {
|
private DateValidator(Builder builder) {
|
||||||
this.dateFormatter = builder.dateFormatter;
|
this.dateFormatter = builder.dateFormatter;
|
||||||
this.datePattern = Pattern.compile(builder.dateFormatRegex);
|
this.datePattern = new PatternValidator(builder.dateFormatRegex);
|
||||||
this.minYear = builder.minYear;
|
this.minYear = builder.minYear;
|
||||||
this.maxYear = builder.maxYear;
|
this.maxYear = builder.maxYear;
|
||||||
}
|
}
|
||||||
@ -59,7 +58,7 @@ public class DateValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidDateFormat(String date) {
|
public boolean isValidDateFormat(String date) {
|
||||||
return date != null && datePattern.matcher(date).matches();
|
return datePattern.isValid(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidDate(String date) {
|
public boolean isValidDate(String date) {
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package com.banesco.common.infraestructure.utils;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clase para validar Expresion regulares
|
||||||
|
*/
|
||||||
|
public class PatternValidator {
|
||||||
|
|
||||||
|
private final Pattern pattern;
|
||||||
|
|
||||||
|
public PatternValidator(String patternStr) {
|
||||||
|
pattern = Pattern.compile(patternStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PatternValidator withRegex(String patternStr) {
|
||||||
|
return new PatternValidator(patternStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates is un valor tiene formato valido.
|
||||||
|
*
|
||||||
|
* @param value the value to check.
|
||||||
|
* @return true if the value has format valid, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isValid(String value) {
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return pattern.matcher(value).matches();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,87 +0,0 @@
|
|||||||
package com.banesco.domain.model;
|
|
||||||
|
|
||||||
public class BackResponse {
|
|
||||||
private final String backendCode;
|
|
||||||
private final String httpCode;
|
|
||||||
private final String statusCode;
|
|
||||||
private final String description;
|
|
||||||
|
|
||||||
public BackResponse(String value) {
|
|
||||||
this.backendCode = value;
|
|
||||||
this.httpCode = value;
|
|
||||||
this.statusCode = value;
|
|
||||||
this.description = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BackResponse(Builder builder) {
|
|
||||||
this.backendCode = builder.backendCode;
|
|
||||||
this.httpCode = builder.httpCode;
|
|
||||||
this.statusCode = builder.statusCode;
|
|
||||||
this.description = builder.description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBackendCode() {
|
|
||||||
return backendCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHttpCode() {
|
|
||||||
return httpCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatusCode() {
|
|
||||||
return statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
private String backendCode;
|
|
||||||
private String httpCode;
|
|
||||||
private String statusCode;
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
public Builder() {}
|
|
||||||
|
|
||||||
public Builder backendCode(String backendCode) {
|
|
||||||
this.backendCode = backendCode;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder httpCode(String httpCode) {
|
|
||||||
this.httpCode = httpCode;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder statusCode(String statusCode) {
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder description(String description) {
|
|
||||||
this.description = description;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BackResponse build() {
|
|
||||||
// Validaciones de ser necesario
|
|
||||||
// if (attr == null || attr.isEmpty()) {
|
|
||||||
// throw new IllegalStateException("El atributo1 no puede estar vacío");
|
|
||||||
// }
|
|
||||||
return new BackResponse(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "BackResponse [backendCode=" + backendCode + ", httpCode=" + httpCode + ", statusCode=" + statusCode
|
|
||||||
+ ", description=" + description + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,64 +0,0 @@
|
|||||||
package com.banesco.domain.model;
|
|
||||||
|
|
||||||
public class BaseResponse<T> {
|
|
||||||
|
|
||||||
private StatusResponse statusResponse;
|
|
||||||
private T dataResponse;
|
|
||||||
|
|
||||||
public BaseResponse() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaseResponse(StatusResponse statusResponse, T dataResponse) {
|
|
||||||
this.statusResponse = statusResponse;
|
|
||||||
this.dataResponse = dataResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BaseResponse(Builder<T> builder) {
|
|
||||||
this.statusResponse = builder.statusResponse;
|
|
||||||
this.dataResponse = builder.dataResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StatusResponse getstatusResponse() {
|
|
||||||
return statusResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getdataResponse() {
|
|
||||||
return dataResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder<T> {
|
|
||||||
|
|
||||||
private StatusResponse statusResponse;
|
|
||||||
private T dataResponse;
|
|
||||||
|
|
||||||
public Builder() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder<T> statusResponse(StatusResponse statusResponse) {
|
|
||||||
this.statusResponse = statusResponse;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder<T> dataResponse(T dataResponse) {
|
|
||||||
this.dataResponse = dataResponse;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaseResponse<T> build() {
|
|
||||||
// Validaciones de ser necesario
|
|
||||||
// if (attr == null || attr.isEmpty()) {
|
|
||||||
// throw new IllegalStateException("El atributo1 no puede estar vacío");
|
|
||||||
// }
|
|
||||||
return new BaseResponse<>(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> Builder<T> builder() {
|
|
||||||
return new Builder<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "BaseResponse [statusResponse=" + statusResponse + ", dataResponse=" + dataResponse + "]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,73 +0,0 @@
|
|||||||
package com.banesco.domain.model;
|
|
||||||
|
|
||||||
|
|
||||||
public class Device {
|
|
||||||
private final String type;
|
|
||||||
private final String description;
|
|
||||||
private final String ipAddress;
|
|
||||||
|
|
||||||
private Device(Builder builder) {
|
|
||||||
this.type = builder.type;
|
|
||||||
this.description = builder.description;
|
|
||||||
this.ipAddress = builder.ipAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIpAddress() {
|
|
||||||
return ipAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
private String type;
|
|
||||||
private String description;
|
|
||||||
private String ipAddress;
|
|
||||||
|
|
||||||
public Builder() {}
|
|
||||||
|
|
||||||
public Builder type(String type) {
|
|
||||||
this.type = type;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder description(String description) {
|
|
||||||
this.description = description;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder ipAddress(String ipAddress) {
|
|
||||||
this.ipAddress = ipAddress;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Device build() {
|
|
||||||
// Validaciones de ser necesario
|
|
||||||
// if (attr == null || attr.isEmpty()) {
|
|
||||||
// throw new IllegalStateException("El atributo1 no puede estar vacío");
|
|
||||||
// }
|
|
||||||
return new Device(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("Device{");
|
|
||||||
sb.append("type=").append(type);
|
|
||||||
sb.append(", description=").append(description);
|
|
||||||
sb.append(", ipAddress=").append(ipAddress);
|
|
||||||
sb.append('}');
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,66 +0,0 @@
|
|||||||
package com.banesco.domain.model;
|
|
||||||
|
|
||||||
public class FieldValidateResult {
|
|
||||||
|
|
||||||
private String backendCode;
|
|
||||||
private String field;
|
|
||||||
|
|
||||||
public FieldValidateResult() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldValidateResult(String backendCode, String field) {
|
|
||||||
this.backendCode = backendCode;
|
|
||||||
this.field = field;
|
|
||||||
}
|
|
||||||
|
|
||||||
private FieldValidateResult(Builder builder) {
|
|
||||||
this.backendCode = builder.backendCode;
|
|
||||||
this.field = builder.field;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBackendCode() {
|
|
||||||
return backendCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getField() {
|
|
||||||
return field;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
|
|
||||||
private String backendCode;
|
|
||||||
private String field;
|
|
||||||
|
|
||||||
public Builder() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder backendCode(String backendCode) {
|
|
||||||
this.backendCode = backendCode;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder field(String field) {
|
|
||||||
this.field = field;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldValidateResult build() {
|
|
||||||
// Validaciones de ser necesario
|
|
||||||
// if (attr == null || attr.isEmpty()) {
|
|
||||||
// throw new IllegalStateException("El atributo1 no puede estar vacío");
|
|
||||||
// }
|
|
||||||
return new FieldValidateResult(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "FieldValidateResult [backendCode=" + backendCode + ", field=" + field + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,250 +0,0 @@
|
|||||||
package com.banesco.domain.model;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class RegisterSecurityRq {
|
|
||||||
private final String codBan;
|
|
||||||
private final String codMon;
|
|
||||||
private final String codEve;
|
|
||||||
private final String codEve2;
|
|
||||||
private final String login;
|
|
||||||
private final Date fecHor;
|
|
||||||
private final String nacCli;
|
|
||||||
private final Long cedRifCli;
|
|
||||||
private final String objeto;
|
|
||||||
private final Integer tipoRespuesta;
|
|
||||||
private final String msgRespuesta;
|
|
||||||
private final Integer tiempoRespuesta;
|
|
||||||
private final String codFintech;
|
|
||||||
private final String nombreFintech;
|
|
||||||
private final String tipoDispositivo;
|
|
||||||
private final String desDispositivo;
|
|
||||||
private final String ipCli;
|
|
||||||
private final String sp;
|
|
||||||
|
|
||||||
private RegisterSecurityRq(Builder builder) {
|
|
||||||
this.codBan = builder.codBan;
|
|
||||||
this.codMon = builder.codMon;
|
|
||||||
this.codEve = builder.codEve;
|
|
||||||
this.codEve2 = builder.codEve2;
|
|
||||||
this.login = builder.login;
|
|
||||||
this.fecHor = builder.fecHor;
|
|
||||||
this.nacCli = builder.nacCli;
|
|
||||||
this.cedRifCli = builder.cedRifCli;
|
|
||||||
this.objeto = builder.objeto;
|
|
||||||
this.tipoRespuesta = builder.tipoRespuesta;
|
|
||||||
this.msgRespuesta = builder.msgRespuesta;
|
|
||||||
this.tiempoRespuesta = builder.tiempoRespuesta;
|
|
||||||
this.codFintech = builder.codFintech;
|
|
||||||
this.nombreFintech = builder.nombreFintech;
|
|
||||||
this.tipoDispositivo = builder.tipoDispositivo;
|
|
||||||
this.desDispositivo = builder.desDispositivo;
|
|
||||||
this.ipCli = builder.ipCli;
|
|
||||||
this.sp = builder.sp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCodBan() {
|
|
||||||
return codBan;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCodMon() {
|
|
||||||
return codMon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCodEve() {
|
|
||||||
return codEve;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCodEve2() {
|
|
||||||
return codEve2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLogin() {
|
|
||||||
return login;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getFecHor() {
|
|
||||||
return fecHor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNacCli() {
|
|
||||||
return nacCli;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getCedRifCli() {
|
|
||||||
return cedRifCli;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getObjeto() {
|
|
||||||
return objeto;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getTipoRespuesta() {
|
|
||||||
return tipoRespuesta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMsgRespuesta() {
|
|
||||||
return msgRespuesta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getTiempoRespuesta() {
|
|
||||||
return tiempoRespuesta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCodFintech() {
|
|
||||||
return codFintech;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNombreFintech() {
|
|
||||||
return nombreFintech;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTipoDispositivo() {
|
|
||||||
return tipoDispositivo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDesDispositivo() {
|
|
||||||
return desDispositivo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIpCli() {
|
|
||||||
return ipCli;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSp() {
|
|
||||||
return sp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
private String codBan;
|
|
||||||
private String codMon;
|
|
||||||
private String codEve;
|
|
||||||
private String codEve2;
|
|
||||||
private String login;
|
|
||||||
private Date fecHor;
|
|
||||||
private String nacCli;
|
|
||||||
private Long cedRifCli;
|
|
||||||
private String objeto;
|
|
||||||
private Integer tipoRespuesta;
|
|
||||||
private String msgRespuesta;
|
|
||||||
private Integer tiempoRespuesta;
|
|
||||||
private String codFintech;
|
|
||||||
private String nombreFintech;
|
|
||||||
private String tipoDispositivo;
|
|
||||||
private String desDispositivo;
|
|
||||||
private String ipCli;
|
|
||||||
private String sp;
|
|
||||||
|
|
||||||
public Builder() {}
|
|
||||||
|
|
||||||
public Builder codBan(String codBan) {
|
|
||||||
this.codBan = codBan;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder codMon(String codMon) {
|
|
||||||
this.codMon = codMon;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder codEve(String codEve) {
|
|
||||||
this.codEve = codEve;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder codEve2(String codEve2) {
|
|
||||||
this.codEve2 = codEve2;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder login(String login) {
|
|
||||||
this.login = login;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder fecHor(Date fecHor) {
|
|
||||||
this.fecHor = fecHor;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder nacCli(String nacCli) {
|
|
||||||
this.nacCli = nacCli;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder cedRifCli(Long cedRifCli) {
|
|
||||||
this.cedRifCli = cedRifCli;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder objeto(String objeto) {
|
|
||||||
this.objeto = objeto;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder tipoRespuesta(Integer tipoRespuesta) {
|
|
||||||
this.tipoRespuesta = tipoRespuesta;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder msgRespuesta(String msgRespuesta) {
|
|
||||||
this.msgRespuesta = msgRespuesta;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder tiempoRespuesta(Integer tiempoRespuesta) {
|
|
||||||
this.tiempoRespuesta = tiempoRespuesta;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder codFintech(String codFintech) {
|
|
||||||
this.codFintech = codFintech;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder nombreFintech(String nombreFintech) {
|
|
||||||
this.nombreFintech = nombreFintech;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder tipoDispositivo(String tipoDispositivo) {
|
|
||||||
this.tipoDispositivo = tipoDispositivo;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder desDispositivo(String desDispositivo) {
|
|
||||||
this.desDispositivo = desDispositivo;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder ipCli(String ipCli) {
|
|
||||||
this.ipCli = ipCli;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder sp(String sp) {
|
|
||||||
this.sp = sp;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RegisterSecurityRq build() {
|
|
||||||
// Validaciones de ser necesario
|
|
||||||
// if (attr == null || attr.isEmpty()) {
|
|
||||||
// throw new IllegalStateException("El atributo1 no puede estar vacío");
|
|
||||||
// }
|
|
||||||
return new RegisterSecurityRq(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "RegisterSecurityRq [codBan=" + codBan + ", codMon=" + codMon + ", codEve=" + codEve + ", codEve2="
|
|
||||||
+ codEve2 + ", login=" + login + ", fecHor=" + fecHor + ", nacCli=" + nacCli + ", cedRifCli="
|
|
||||||
+ cedRifCli + ", objeto=" + objeto + ", tipoRespuesta=" + tipoRespuesta + ", msgRespuesta="
|
|
||||||
+ msgRespuesta + ", tiempoRespuesta=" + tiempoRespuesta + ", codFintech=" + codFintech
|
|
||||||
+ ", nombreFintech=" + nombreFintech + ", tipoDispositivo=" + tipoDispositivo + ", desDispositivo="
|
|
||||||
+ desDispositivo + ", ipCli=" + ipCli + ", sp=" + sp + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,223 +0,0 @@
|
|||||||
package com.banesco.domain.model;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
public class RequestBase {
|
|
||||||
|
|
||||||
@JsonProperty("MsgRqHdr")
|
|
||||||
public MsgRqHdr msgRqHdr;
|
|
||||||
|
|
||||||
public static class NetworkTrnInfo {
|
|
||||||
|
|
||||||
@JsonProperty("TransactionConsecutive")
|
|
||||||
public String transactionConsecutive;
|
|
||||||
@JsonProperty("RegisterNumber")
|
|
||||||
public String registerNumber;
|
|
||||||
@JsonProperty("OperationType")
|
|
||||||
public String operationType;
|
|
||||||
@JsonProperty("TransactionType")
|
|
||||||
public String transactionType;
|
|
||||||
@JsonProperty("TransactionCode")
|
|
||||||
public String transactionCode;
|
|
||||||
@JsonProperty("TransactionDate")
|
|
||||||
public String transactionDate;
|
|
||||||
@JsonProperty("TransactionTime")
|
|
||||||
public String transactionTime;
|
|
||||||
@JsonProperty("BankId")
|
|
||||||
public String bankId;
|
|
||||||
@JsonProperty("AgencyCode")
|
|
||||||
public String agencyCode;
|
|
||||||
@JsonProperty("ChannelId")
|
|
||||||
public String channelId;
|
|
||||||
|
|
||||||
public String getTransactionConsecutive() {
|
|
||||||
return transactionConsecutive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransactionConsecutive(String transactionConsecutive) {
|
|
||||||
this.transactionConsecutive = transactionConsecutive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRegisterNumber() {
|
|
||||||
return registerNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRegisterNumber(String registerNumber) {
|
|
||||||
this.registerNumber = registerNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOperationType() {
|
|
||||||
return operationType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperationType(String operationType) {
|
|
||||||
this.operationType = operationType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTransactionType() {
|
|
||||||
return transactionType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransactionType(String transactionType) {
|
|
||||||
this.transactionType = transactionType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTransactionCode() {
|
|
||||||
return transactionCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransactionCode(String transactionCode) {
|
|
||||||
this.transactionCode = transactionCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTransactionDate() {
|
|
||||||
return transactionDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransactionDate(String transactionDate) {
|
|
||||||
this.transactionDate = transactionDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTransactionTime() {
|
|
||||||
return transactionTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransactionTime(String transactionTime) {
|
|
||||||
this.transactionTime = transactionTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBankId() {
|
|
||||||
return bankId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBankId(String bankId) {
|
|
||||||
this.bankId = bankId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAgencyCode() {
|
|
||||||
return agencyCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAgencyCode(String agencyCode) {
|
|
||||||
this.agencyCode = agencyCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getChannelId() {
|
|
||||||
return channelId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChannelId(String channelId) {
|
|
||||||
this.channelId = channelId;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ApplicantData {
|
|
||||||
|
|
||||||
@JsonProperty("Application")
|
|
||||||
public String application;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class VBProtocol {
|
|
||||||
|
|
||||||
@JsonProperty("VBProtocolInd")
|
|
||||||
public String vBProtocolInd;
|
|
||||||
@JsonProperty("TransactionInd")
|
|
||||||
public String transactionInd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class MsgRqHdr {
|
|
||||||
|
|
||||||
@JsonProperty("MessageDate")
|
|
||||||
public String messageDate;
|
|
||||||
@JsonProperty("MessageTime")
|
|
||||||
public String messageTime;
|
|
||||||
@JsonProperty("RequestId")
|
|
||||||
public String requestId;
|
|
||||||
@JsonProperty("SourceChannelCode")
|
|
||||||
public String sourceChannelCode;
|
|
||||||
@JsonProperty("SupervisorCode")
|
|
||||||
public String supervisorCode;
|
|
||||||
@JsonProperty("OperatorCode")
|
|
||||||
public String operatorCode;
|
|
||||||
@JsonProperty("NetworkTrnInfo")
|
|
||||||
public NetworkTrnInfo networkTrnInfo;
|
|
||||||
@JsonProperty("ApplicantData")
|
|
||||||
public ApplicantData applicantData;
|
|
||||||
@JsonProperty("VBProtocol")
|
|
||||||
public VBProtocol vBProtocol;
|
|
||||||
|
|
||||||
public String getMessageDate() {
|
|
||||||
return messageDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessageDate(String messageDate) {
|
|
||||||
this.messageDate = messageDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessageTime() {
|
|
||||||
return messageTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessageTime(String messageTime) {
|
|
||||||
this.messageTime = messageTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRequestId() {
|
|
||||||
return requestId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRequestId(String requestId) {
|
|
||||||
this.requestId = requestId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSourceChannelCode() {
|
|
||||||
return sourceChannelCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSourceChannelCode(String sourceChannelCode) {
|
|
||||||
this.sourceChannelCode = sourceChannelCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSupervisorCode() {
|
|
||||||
return supervisorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSupervisorCode(String supervisorCode) {
|
|
||||||
this.supervisorCode = supervisorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOperatorCode() {
|
|
||||||
return operatorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperatorCode(String operatorCode) {
|
|
||||||
this.operatorCode = operatorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NetworkTrnInfo getNetworkTrnInfo() {
|
|
||||||
return networkTrnInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNetworkTrnInfo(NetworkTrnInfo networkTrnInfo) {
|
|
||||||
this.networkTrnInfo = networkTrnInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicantData getApplicantData() {
|
|
||||||
return applicantData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApplicantData(ApplicantData applicantData) {
|
|
||||||
this.applicantData = applicantData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public VBProtocol getvBProtocol() {
|
|
||||||
return vBProtocol;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setvBProtocol(VBProtocol vBProtocol) {
|
|
||||||
this.vBProtocol = vBProtocol;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,298 +0,0 @@
|
|||||||
package com.banesco.domain.model;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
public class ResponseBase {
|
|
||||||
|
|
||||||
@JsonProperty("MsgRsHdr")
|
|
||||||
public ArrayList<MsgRsHdr> msgRsHdr;
|
|
||||||
|
|
||||||
@JsonProperty("Status")
|
|
||||||
public ArrayList<Status> status;
|
|
||||||
|
|
||||||
public ResponseBase() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponseBase(ArrayList<MsgRsHdr> msgRsHdr, ArrayList<Status> status) {
|
|
||||||
this.msgRsHdr = msgRsHdr;
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponseBase(Builder builder) {
|
|
||||||
this.msgRsHdr = builder.msgRsHdr;
|
|
||||||
this.status = builder.status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<MsgRsHdr> getMsgRsHdr() {
|
|
||||||
return msgRsHdr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMsgRsHdr(ArrayList<MsgRsHdr> msgRsHdr) {
|
|
||||||
this.msgRsHdr = msgRsHdr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Status> getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(ArrayList<Status> status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
|
|
||||||
private ArrayList<MsgRsHdr> msgRsHdr;
|
|
||||||
private ArrayList<Status> status;
|
|
||||||
|
|
||||||
public Builder msgRsHdr(ArrayList<MsgRsHdr> msgRsHdr) {
|
|
||||||
this.msgRsHdr = msgRsHdr;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder status(ArrayList<Status> status) {
|
|
||||||
this.status = status;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponseBase build() {
|
|
||||||
return new ResponseBase(msgRsHdr, status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class MsgRsHdr {
|
|
||||||
|
|
||||||
@JsonProperty("FinalStatusRequest")
|
|
||||||
public String finalStatusRequest;
|
|
||||||
@JsonProperty("CountDataOut")
|
|
||||||
public String countDataOut;
|
|
||||||
@JsonProperty("TransactionCode")
|
|
||||||
public String transactionCode;
|
|
||||||
@JsonProperty("SupervisorCode")
|
|
||||||
public String supervisorCode;
|
|
||||||
@JsonProperty("OperationType")
|
|
||||||
public String operationType;
|
|
||||||
@JsonProperty("TransactionConsecutive")
|
|
||||||
public String transactionConsecutive;
|
|
||||||
@JsonProperty("DetailReg")
|
|
||||||
public String detailReg;
|
|
||||||
@JsonProperty("RegisterNumber")
|
|
||||||
public ArrayList<String> registerNumber;
|
|
||||||
@JsonProperty("TransactionType")
|
|
||||||
public String transactionType;
|
|
||||||
@JsonProperty("RequestId")
|
|
||||||
public String requestId;
|
|
||||||
@JsonProperty("AppName")
|
|
||||||
public String appName;
|
|
||||||
|
|
||||||
public MsgRsHdr() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFinalStatusRequest() {
|
|
||||||
return finalStatusRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFinalStatusRequest(String finalStatusRequest) {
|
|
||||||
this.finalStatusRequest = finalStatusRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCountDataOut() {
|
|
||||||
return countDataOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCountDataOut(String countDataOut) {
|
|
||||||
this.countDataOut = countDataOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTransactionCode() {
|
|
||||||
return transactionCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransactionCode(String transactionCode) {
|
|
||||||
this.transactionCode = transactionCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSupervisorCode() {
|
|
||||||
return supervisorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSupervisorCode(String supervisorCode) {
|
|
||||||
this.supervisorCode = supervisorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOperationType() {
|
|
||||||
return operationType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperationType(String operationType) {
|
|
||||||
this.operationType = operationType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTransactionConsecutive() {
|
|
||||||
return transactionConsecutive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransactionConsecutive(String transactionConsecutive) {
|
|
||||||
this.transactionConsecutive = transactionConsecutive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDetailReg() {
|
|
||||||
return detailReg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDetailReg(String detailReg) {
|
|
||||||
this.detailReg = detailReg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getRegisterNumber() {
|
|
||||||
return registerNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRegisterNumber(ArrayList<String> registerNumber) {
|
|
||||||
this.registerNumber = registerNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTransactionType() {
|
|
||||||
return transactionType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransactionType(String transactionType) {
|
|
||||||
this.transactionType = transactionType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRequestId() {
|
|
||||||
return requestId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRequestId(String requestId) {
|
|
||||||
this.requestId = requestId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAppName() {
|
|
||||||
return appName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppName(String appName) {
|
|
||||||
this.appName = appName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "MsgRsHdr [finalStatusRequest=" + finalStatusRequest + ", countDataOut=" + countDataOut
|
|
||||||
+ ", transactionCode=" + transactionCode + ", supervisorCode=" + supervisorCode + ", operationType="
|
|
||||||
+ operationType + ", transactionConsecutive=" + transactionConsecutive + ", detailReg=" + detailReg
|
|
||||||
+ ", registerNumber=" + registerNumber + ", transactionType=" + transactionType + ", requestId="
|
|
||||||
+ requestId + ", appName=" + appName + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class AdditionalStatus {
|
|
||||||
|
|
||||||
@JsonProperty("StatusCode")
|
|
||||||
public String statusCode;
|
|
||||||
@JsonProperty("StatusDesc")
|
|
||||||
public String statusDesc;
|
|
||||||
@JsonProperty("Severity")
|
|
||||||
public String severity;
|
|
||||||
|
|
||||||
public String getStatusCode() {
|
|
||||||
return statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatusCode(String statusCode) {
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatusDesc() {
|
|
||||||
return statusDesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatusDesc(String statusDesc) {
|
|
||||||
this.statusDesc = statusDesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSeverity() {
|
|
||||||
return severity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSeverity(String severity) {
|
|
||||||
this.severity = severity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "AdditionalStatus [statusCode=" + statusCode + ", statusDesc=" + statusDesc + ", severity="
|
|
||||||
+ severity + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Status {
|
|
||||||
|
|
||||||
@JsonProperty("StatusCode")
|
|
||||||
public String statusCode;
|
|
||||||
@JsonProperty("StatusDesc")
|
|
||||||
public String statusDesc;
|
|
||||||
@JsonProperty("ApplicationName")
|
|
||||||
public String applicationName;
|
|
||||||
@JsonProperty("LineNumber")
|
|
||||||
public int lineNumber;
|
|
||||||
@JsonProperty("AdditionalStatus")
|
|
||||||
public ArrayList<AdditionalStatus> additionalStatus;
|
|
||||||
|
|
||||||
public String getStatusCode() {
|
|
||||||
|
|
||||||
return statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatusCode(String statusCode) {
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatusDesc() {
|
|
||||||
return statusDesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatusDesc(String statusDesc) {
|
|
||||||
this.statusDesc = statusDesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getApplicationName() {
|
|
||||||
return applicationName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApplicationName(String applicationName) {
|
|
||||||
this.applicationName = applicationName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLineNumber() {
|
|
||||||
return lineNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLineNumber(int lineNumber) {
|
|
||||||
this.lineNumber = lineNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<AdditionalStatus> getAdditionalStatus() {
|
|
||||||
return additionalStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAdditionalStatus(ArrayList<AdditionalStatus> additionalStatus) {
|
|
||||||
this.additionalStatus = additionalStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Status [statusCode=" + statusCode + ", statusDesc=" + statusDesc + ", applicationName="
|
|
||||||
+ applicationName + ", lineNumber=" + lineNumber + ", additionalStatus=" + additionalStatus + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ResponseBase [msgRsHdr=" + msgRsHdr + ", status=" + status + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,61 +0,0 @@
|
|||||||
package com.banesco.domain.model;
|
|
||||||
|
|
||||||
|
|
||||||
public class SecurityAuth {
|
|
||||||
private final String sessionId;
|
|
||||||
private final String username;
|
|
||||||
|
|
||||||
private SecurityAuth(Builder builder) {
|
|
||||||
this.sessionId = builder.sessionId;
|
|
||||||
this.username = builder.username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSessionId() {
|
|
||||||
return sessionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
private String sessionId;
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
public Builder() {}
|
|
||||||
|
|
||||||
public Builder sessionId(String sessionId) {
|
|
||||||
this.sessionId = sessionId;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder username(String username) {
|
|
||||||
this.username = username;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SecurityAuth build() {
|
|
||||||
// Validaciones de ser necesario
|
|
||||||
// if (attr == null || attr.isEmpty()) {
|
|
||||||
// throw new IllegalStateException("El atributo1 no puede estar vacío");
|
|
||||||
// }
|
|
||||||
return new SecurityAuth(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("SecurityAuth{");
|
|
||||||
sb.append("sessionId=").append(sessionId);
|
|
||||||
sb.append(", username=").append(username);
|
|
||||||
sb.append('}');
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,55 +0,0 @@
|
|||||||
package com.banesco.domain.model;
|
|
||||||
|
|
||||||
public class StatusResponse {
|
|
||||||
private final String statusCode;
|
|
||||||
private final String statusDesc;
|
|
||||||
|
|
||||||
private StatusResponse(Builder builder) {
|
|
||||||
this.statusCode = builder.statusCode;
|
|
||||||
this.statusDesc = builder.statusDesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatusCode() {
|
|
||||||
return statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatusDesc() {
|
|
||||||
return statusDesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
private String statusCode;
|
|
||||||
private String statusDesc;
|
|
||||||
|
|
||||||
public Builder() {}
|
|
||||||
|
|
||||||
public Builder statusCode(String statusCode) {
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder statusDesc(String statusDesc) {
|
|
||||||
this.statusDesc = statusDesc;
|
|
||||||
return Builder.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StatusResponse build() {
|
|
||||||
// Validaciones de ser necesario
|
|
||||||
// if (attr == null || attr.isEmpty()) {
|
|
||||||
// throw new IllegalStateException("El atributo1 no puede estar vacío");
|
|
||||||
// }
|
|
||||||
return new StatusResponse(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "StatusResponse [statusCode=" + statusCode + ", statusDesc=" + statusDesc + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,101 +0,0 @@
|
|||||||
package com.banesco.infraestructure.config;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clase de configuración para APIs. Almacena la información necesaria para
|
|
||||||
* conectarse a un servicio API externo, incluyendo URL, path, configuración de
|
|
||||||
* timeout y parámetros adicionales. Diseñada para ser utilizada como objeto de
|
|
||||||
* configuración en clientes de API y servicios de integración.
|
|
||||||
*/
|
|
||||||
public class ApiConfig {
|
|
||||||
|
|
||||||
private String url;
|
|
||||||
private String path;
|
|
||||||
private Timeout timeout;
|
|
||||||
private Map<String, String> config;
|
|
||||||
|
|
||||||
public ApiConfig() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApiConfig(String url, String path, Timeout timeout, Map<String, String> config) {
|
|
||||||
this.url = url;
|
|
||||||
this.path = path;
|
|
||||||
this.timeout = timeout;
|
|
||||||
this.config = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPath() {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPath(String path) {
|
|
||||||
this.path = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Timeout getTimeout() {
|
|
||||||
return timeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimeout(Timeout timeout) {
|
|
||||||
this.timeout = timeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getConfig() {
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConfig(Map<String, String> config) {
|
|
||||||
this.config = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clase interna que representa la configuración de tiempos de espera
|
|
||||||
* (timeout) para conexiones a APIs. Define los tiempos máximos de espera
|
|
||||||
* para establecer la conexión y para recibir una respuesta, especificados
|
|
||||||
* en milisegundos.
|
|
||||||
*/
|
|
||||||
public static class Timeout {
|
|
||||||
|
|
||||||
private int connect = 15000;
|
|
||||||
private int response = 15000;
|
|
||||||
|
|
||||||
public Timeout() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Timeout(int connect, int response) {
|
|
||||||
this.connect = connect;
|
|
||||||
this.response = response;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnect() {
|
|
||||||
return connect;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnect(int connect) {
|
|
||||||
this.connect = connect;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getResponse() {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResponse(int response) {
|
|
||||||
this.response = response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ApiConfig [url=" + url + ", path=" + path + ", timeout=" + timeout + ", config=" + config + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
package com.banesco.infraestructure.config;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import com.banesco.domain.model.RequestBase;
|
|
||||||
import com.banesco.infraestructure.helpers.RequestHelper;
|
|
||||||
import com.banesco.infraestructure.repository.SoapHeadersRepository;
|
|
||||||
|
|
||||||
public class RestClient {
|
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(RestClient.class.getName());
|
|
||||||
|
|
||||||
private final String idGeneratorUrl;
|
|
||||||
private final RequestHelper requestHelper;
|
|
||||||
private String instanceId;
|
|
||||||
|
|
||||||
public RestClient(String headerUrl, String idGeneratorUrl, RequestHelper requestHelper) {
|
|
||||||
this.idGeneratorUrl = idGeneratorUrl;
|
|
||||||
this.requestHelper = requestHelper;
|
|
||||||
this.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
if (!idGeneratorUrl.contains("localhost")) {
|
|
||||||
logger.log(Level.INFO, "Request to getInstanceId");
|
|
||||||
this.instanceId = getInstanceId();
|
|
||||||
logger.log(Level.INFO, "Response to getInstanceId: {0}", this.instanceId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public RequestBase.MsgRqHdr getHeader(String headerName) {
|
|
||||||
return SoapHeadersRepository.getHeader(headerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRequestId() {
|
|
||||||
return requestHelper.getRequestId(instanceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInstanceId() {
|
|
||||||
return requestHelper.getInstanceId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,93 +0,0 @@
|
|||||||
package com.banesco.infraestructure.helpers;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.time.DateTimeException;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clase utilitaria para operaciones relacionadas con fechas y horas.
|
|
||||||
* Proporciona métodos para validar, comparar y calcular períodos entre fechas.
|
|
||||||
*/
|
|
||||||
public class DateHelper {
|
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(DateHelper.class.getName());
|
|
||||||
private static final String TIME_FORMAT = "HH:mm";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifica si la hora actual está dentro del rango de horas proporcionado.
|
|
||||||
* Si las horas de inicio y fin son iguales, devuelve false. Maneja
|
|
||||||
* correctamente los rangos que cruzan la medianoche.
|
|
||||||
*
|
|
||||||
* @param inputHourOne Hora de inicio en formato HH:mm
|
|
||||||
* @param inputHourTwo Hora de fin en formato HH:mm
|
|
||||||
* @return true si la hora actual está dentro del rango, false en caso
|
|
||||||
* contrario
|
|
||||||
* @throws ParseException Si ocurre un error al analizar las horas
|
|
||||||
* proporcionadas
|
|
||||||
*/
|
|
||||||
public static boolean isTimeInRange(String inputHourOne, String inputHourTwo) throws ParseException {
|
|
||||||
if (inputHourOne.equals(inputHourTwo)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
DateFormat dateFormat = new SimpleDateFormat(TIME_FORMAT);
|
|
||||||
Date now = new Date();
|
|
||||||
Date beginTime = dateFormat.parse(inputHourOne);
|
|
||||||
Date endTime = dateFormat.parse(inputHourTwo);
|
|
||||||
Date currentTime = dateFormat.parse(dateFormat.format(now));
|
|
||||||
|
|
||||||
long beginMillis = beginTime.getTime();
|
|
||||||
long endMillis = endTime.getTime();
|
|
||||||
long currentMillis = currentTime.getTime();
|
|
||||||
|
|
||||||
boolean isInRange;
|
|
||||||
|
|
||||||
if (beginMillis > endMillis) {
|
|
||||||
// Rango que cruza la medianoche
|
|
||||||
isInRange = currentMillis >= beginMillis || currentMillis <= endMillis;
|
|
||||||
} else {
|
|
||||||
// Rango dentro del mismo día
|
|
||||||
isInRange = currentMillis >= beginMillis && currentMillis <= endMillis;
|
|
||||||
}
|
|
||||||
|
|
||||||
String currentHourStr = dateFormat.format(now);
|
|
||||||
logger.log(Level.INFO, "La hora {0}{1}entre {2} y {3}", new Object[]{currentHourStr, isInRange ? " está " : " NO está ", inputHourOne, inputHourTwo});
|
|
||||||
|
|
||||||
return isInRange;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calcula el número de días entre dos fechas.
|
|
||||||
*
|
|
||||||
* @param startDate Fecha de inicio en formato ISO (yyyy-MM-dd)
|
|
||||||
* @param endDate Fecha de fin en formato ISO (yyyy-MM-dd)
|
|
||||||
* @return El número de días entre las fechas o -1 si ocurre un error al
|
|
||||||
* procesar las fechas
|
|
||||||
*/
|
|
||||||
public long daysBetweenTwoDates(String startDate, String endDate) {
|
|
||||||
try {
|
|
||||||
return ChronoUnit.DAYS.between(LocalDate.parse(startDate), LocalDate.parse(endDate));
|
|
||||||
} catch (DateTimeException dte) {
|
|
||||||
return -1L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifica si la fecha de inicio es anterior o igual a la fecha de fin.
|
|
||||||
*
|
|
||||||
* @param startDate Fecha de inicio en formato ISO (yyyy-MM-dd)
|
|
||||||
* @param endDate Fecha de fin en formato ISO (yyyy-MM-dd)
|
|
||||||
* @return true si startDate es anterior o igual a endDate, false en caso
|
|
||||||
* contrario
|
|
||||||
*/
|
|
||||||
public boolean isStartDateBeforeEndDate(String startDate, String endDate) {
|
|
||||||
return LocalDate.parse(startDate).isBefore(LocalDate.parse(endDate))
|
|
||||||
|| LocalDate.parse(startDate).isEqual(LocalDate.parse(endDate));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,62 +0,0 @@
|
|||||||
package com.banesco.infraestructure.helpers;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
|
|
||||||
public class JsonHelper {
|
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(JsonHelper.class.getName());
|
|
||||||
public static final ObjectMapper MAPPER = new ObjectMapper();
|
|
||||||
|
|
||||||
static {
|
|
||||||
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convierte un objeto Java en una cadena JSON.
|
|
||||||
*
|
|
||||||
* @param object El objeto a convertir en JSON.
|
|
||||||
* @return La cadena JSON resultante o null si ocurre un error.
|
|
||||||
* @throws JsonProcessingException si hay algún error al convertir el objeto
|
|
||||||
* a JSON
|
|
||||||
*/
|
|
||||||
public static String getJsonFromObject(Object object) {
|
|
||||||
if (object == null) {
|
|
||||||
return "null";
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return MAPPER.writeValueAsString(object);
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
logger.log(Level.SEVERE, "Error al convertir objeto a JSON: {0}", e.getMessage());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convierte una cadena JSON en un objeto Java de la clase especificada.
|
|
||||||
*
|
|
||||||
* @param json La cadena JSON a convertir.
|
|
||||||
* @param className La clase del objeto Java resultante.
|
|
||||||
* @param <T> El tipo del objeto resultante.
|
|
||||||
* @return El objeto Java resultante, o null si ocurre un error o la cadena
|
|
||||||
* JSON está vacía.
|
|
||||||
* @throws JsonProcessingException Si ocurre un error al procesar JSON.
|
|
||||||
* @throws IllegalArgumentException Si alguno de los argumentos no es
|
|
||||||
* válido.
|
|
||||||
*/
|
|
||||||
public static <T> T getObjectFromJson(String json, Class<T> className) {
|
|
||||||
if (json == null || json.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return MAPPER.readValue(json, className);
|
|
||||||
} catch (JsonProcessingException | IllegalArgumentException e) {
|
|
||||||
logger.log(Level.WARNING, "Error al convertir JSON a objeto: {0}", e.getMessage());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,72 +0,0 @@
|
|||||||
package com.banesco.infraestructure.helpers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clase utilitaria para la generación de mensajes de registro (logging).
|
|
||||||
* Facilita la creación de cadenas formateadas para registrar información de
|
|
||||||
* solicitudes y respuestas, tanto públicas como privadas, así como mensajes de
|
|
||||||
* error. Utiliza un formato estandarizado para mejorar la legibilidad y
|
|
||||||
* facilitar el análisis de los registros del sistema.
|
|
||||||
*/
|
|
||||||
public class LoggerHelper {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construye una cadena de información para una solicitud pública.
|
|
||||||
*
|
|
||||||
* @param requestId El ID de la solicitud.
|
|
||||||
* @param request El objeto de solicitud.
|
|
||||||
* @param <T> El tipo del objeto de solicitud.
|
|
||||||
* @return Una cadena de información formateada.
|
|
||||||
*/
|
|
||||||
public static <T> String buildInfoRequest(String requestId, T request) {
|
|
||||||
return String.format("[RQ PUB: %s] [%s]", requestId, JsonHelper.getJsonFromObject(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construye una cadena de información para una respuesta pública.
|
|
||||||
*
|
|
||||||
* @param requestId El ID de la solicitud.
|
|
||||||
* @param response El objeto de respuesta.
|
|
||||||
* @param <T> El tipo del objeto de respuesta.
|
|
||||||
* @return Una cadena de información formateada.
|
|
||||||
*/
|
|
||||||
public static <T> String buildInfoResponse(String requestId, T response) {
|
|
||||||
return String.format("[RS PUB: %s] [%s]", requestId, JsonHelper.getJsonFromObject(response));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construye una cadena de información para una solicitud privada.
|
|
||||||
*
|
|
||||||
* @param requestId El ID de la solicitud.
|
|
||||||
* @param name El nombre de la solicitud privada.
|
|
||||||
* @param request El objeto de solicitud.
|
|
||||||
* @param <T> El tipo del objeto de solicitud.
|
|
||||||
* @return Una cadena de información formateada.
|
|
||||||
*/
|
|
||||||
public static <T> String buildInfoPrivateRequest(String requestId, String name, T request) {
|
|
||||||
return String.format("[RQ PRV %s: %s] [%s]", name, requestId, JsonHelper.getJsonFromObject(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construye una cadena de información para una respuesta privada.
|
|
||||||
*
|
|
||||||
* @param requestId El ID de la solicitud.
|
|
||||||
* @param name El nombre de la respuesta privada.
|
|
||||||
* @param response El objeto de respuesta.
|
|
||||||
* @param <T> El tipo del objeto de respuesta.
|
|
||||||
* @return Una cadena de información formateada.
|
|
||||||
*/
|
|
||||||
public static <T> String buildInfoPrivateResponse(String requestId, String name, T response) {
|
|
||||||
return String.format("[PRV RS %s: %s] [%s]", name, requestId, JsonHelper.getJsonFromObject(response));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construye una cadena de error.
|
|
||||||
*
|
|
||||||
* @param requestId El ID de la solicitud asociada al error.
|
|
||||||
* @param out El mensaje de error.
|
|
||||||
* @return Una cadena de error formateada.
|
|
||||||
*/
|
|
||||||
public static String buildError(String requestId, String out) {
|
|
||||||
return String.format("[ERROR %s] [%s]", requestId, out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,181 +0,0 @@
|
|||||||
package com.banesco.infraestructure.helpers;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import com.banesco.domain.model.Device;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clase utilitaria para operaciones relacionadas con solicitudes HTTP y
|
|
||||||
* generación de identificadores. Proporciona métodos para generar IDs únicos,
|
|
||||||
* obtener información del cliente y gestionar información del dispositivo.
|
|
||||||
*/
|
|
||||||
public class RequestHelper {
|
|
||||||
|
|
||||||
private static boolean readDeviceFromRequest = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Nombres de cabeceras HTTP que pueden contener la dirección IP del
|
|
||||||
* cliente. Se revisan en orden para encontrar la IP real considerando
|
|
||||||
* proxies y balanceadores.
|
|
||||||
*/
|
|
||||||
private static final String[] IP_HEADER_NAMES = {
|
|
||||||
"X-Forwarded-For",
|
|
||||||
"Proxy-Client-IP",
|
|
||||||
"WL-Proxy-Client-IP",
|
|
||||||
"HTTP_X_FORWARDED_FOR",
|
|
||||||
"HTTP_X_FORWARDED",
|
|
||||||
"HTTP_X_CLUSTER_CLIENT_IP",
|
|
||||||
"HTTP_CLIENT_IP",
|
|
||||||
"HTTP_FORWARDED_FOR",
|
|
||||||
"HTTP_FORWARDED",
|
|
||||||
"HTTP_VIA",
|
|
||||||
"REMOTE_ADDR"
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor de RequestHelper. Inicializa la configuración para la lectura
|
|
||||||
* de información del dispositivo. Lee la propiedad de configuración
|
|
||||||
* 'api.server-request.read-device' del sistema.
|
|
||||||
*/
|
|
||||||
public RequestHelper() {
|
|
||||||
// Lee la propiedad del sistema. Si no existe, asume false por defecto.
|
|
||||||
String readDeviceProperty = System.getProperty("api.server-request.read-device");
|
|
||||||
this.readDeviceFromRequest = Boolean.parseBoolean(readDeviceProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Genera un ID de instancia único con un prefijo específico. Útil para
|
|
||||||
* identificar instancias del servidor o aplicación.
|
|
||||||
*
|
|
||||||
* @return Un ID de instancia con el prefijo "INST" seguido de 10 caracteres
|
|
||||||
* alfanuméricos aleatorios
|
|
||||||
*/
|
|
||||||
public static String getInstanceId() {
|
|
||||||
return "INST" + RandomStringUtils.randomAlphanumeric(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Genera un ID de solicitud único basado en el ID de instancia. Combina el
|
|
||||||
* ID de instancia con caracteres aleatorios para crear un identificador
|
|
||||||
* único.
|
|
||||||
*
|
|
||||||
* @param instanceId El ID de la instancia a incluir en el ID de solicitud
|
|
||||||
* @return Un ID de solicitud en formato [instanceId]REQ[20 caracteres
|
|
||||||
* aleatorios]
|
|
||||||
*/
|
|
||||||
public static String getRequestId(String instanceId) {
|
|
||||||
return instanceId + "REQ" + RandomStringUtils.randomAlphanumeric(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Genera un ID de solicitud único sin necesidad de proporcionar un ID de
|
|
||||||
* instancia. Crea un nuevo ID de instancia y lo utiliza para generar el ID
|
|
||||||
* de solicitud.
|
|
||||||
*
|
|
||||||
* @return Un ID de solicitud completo con instancia generada
|
|
||||||
* automáticamente
|
|
||||||
*/
|
|
||||||
public static String getRequestId() {
|
|
||||||
return getInstanceId() + "REQ" + RandomStringUtils.randomAlphanumeric(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Genera un identificador de sesión (SID) aleatorio.
|
|
||||||
*
|
|
||||||
* @return Un string de 20 caracteres alfanuméricos aleatorios
|
|
||||||
*/
|
|
||||||
public static String getSid() {
|
|
||||||
return RandomStringUtils.randomAlphanumeric(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Genera un ID de transacción numérico de 11 dígitos.
|
|
||||||
*
|
|
||||||
* @return Un string de 11 caracteres numéricos aleatorios
|
|
||||||
*/
|
|
||||||
public static String getTransactionId() {
|
|
||||||
return RandomStringUtils.randomNumeric(11);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Genera un ID de transacción numérico con el número de dígitos
|
|
||||||
* especificado.
|
|
||||||
*
|
|
||||||
* @param numDigitos El número de dígitos que debe tener el ID generado
|
|
||||||
* @return Un string de caracteres numéricos aleatorios con la longitud
|
|
||||||
* especificada
|
|
||||||
*/
|
|
||||||
public static String getTransactionId(Integer numDigitos) {
|
|
||||||
return RandomStringUtils.randomNumeric(numDigitos);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Genera una referencia Banesco alfanumérica con el número de dígitos
|
|
||||||
* especificado.
|
|
||||||
*
|
|
||||||
* @param numDigitos El número de dígitos que debe tener la referencia
|
|
||||||
* generada
|
|
||||||
* @return Un string de caracteres alfanuméricos aleatorios con la longitud
|
|
||||||
* especificada
|
|
||||||
*/
|
|
||||||
public static String getRefBanesco(Integer numDigitos) {
|
|
||||||
return RandomStringUtils.randomAlphanumeric(numDigitos);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtiene la dirección IP remota del cliente a partir de la solicitud HTTP.
|
|
||||||
* Revisa varias cabeceras HTTP que podrían contener la IP real del cliente
|
|
||||||
* considerando proxies y balanceadores de carga.
|
|
||||||
*
|
|
||||||
* @param request La solicitud HTTP
|
|
||||||
* @return La dirección IP remota del cliente, o "0.0.0.0" si la solicitud
|
|
||||||
* es nula
|
|
||||||
*/
|
|
||||||
public static String getRemoteIP(HttpServletRequest request) {
|
|
||||||
if (request == null) {
|
|
||||||
return "0.0.0.0";
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String header : IP_HEADER_NAMES) {
|
|
||||||
String ipList = request.getHeader(header);
|
|
||||||
if (StringUtils.isNotBlank(ipList) && !"unknown".equalsIgnoreCase(ipList)) {
|
|
||||||
return ipList.split(",")[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return request.getRemoteAddr();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Llena la información del dispositivo remoto del cliente en el objeto
|
|
||||||
* Device. Si se configura readDeviceFromRequest como true, siempre se
|
|
||||||
* obtendrá la información del dispositivo desde la solicitud HTTP,
|
|
||||||
* independientemente de si ya existe.
|
|
||||||
*
|
|
||||||
* @param servletRequest La solicitud HTTP
|
|
||||||
* @param device El objeto Device existente a actualizar o null para crear
|
|
||||||
* uno nuevo
|
|
||||||
* @return El objeto Device con la información del cliente actualizada
|
|
||||||
*/
|
|
||||||
public static Device fillRemoteDevice(HttpServletRequest servletRequest, Device device) {
|
|
||||||
Device.Builder deviceBuilder = (device == null) ? Device.builder() : Device.builder()
|
|
||||||
.ipAddress(device.getIpAddress())
|
|
||||||
.description(device.getDescription())
|
|
||||||
.type(device.getType());
|
|
||||||
|
|
||||||
if (device == null || StringUtils.isEmpty(device.getIpAddress()) || readDeviceFromRequest) {
|
|
||||||
String remoteIP = getRemoteIP(servletRequest);
|
|
||||||
String userAgent = servletRequest.getHeader("user-agent");
|
|
||||||
String deviceType = StringUtils.containsIgnoreCase(userAgent, "Mobi") ? "Mobile" : "Desktop";
|
|
||||||
|
|
||||||
deviceBuilder.ipAddress(remoteIP)
|
|
||||||
.description(userAgent)
|
|
||||||
.type(deviceType);
|
|
||||||
}
|
|
||||||
|
|
||||||
return deviceBuilder.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,56 +0,0 @@
|
|||||||
package com.banesco.infraestructure.helpers;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clase utilitaria para operaciones con cadenas de texto (strings). Proporciona
|
|
||||||
* métodos para validar, manipular y formatear cadenas de texto. Incluye
|
|
||||||
* funcionalidades como verificación de tipos numéricos, validación de cadenas
|
|
||||||
* no vacías y funciones de formato como relleno de caracteres.
|
|
||||||
*/
|
|
||||||
public class StringHelper {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifica si una cadena de texto representa un número entero.
|
|
||||||
*
|
|
||||||
* @param value La cadena de texto a verificar.
|
|
||||||
* @return true si la cadena es un número entero válido, false en caso
|
|
||||||
* contrario.
|
|
||||||
* @throws NumberFormatException Si el string no tiene el formato adeacuado
|
|
||||||
*/
|
|
||||||
public static boolean isNumeric(String value) {
|
|
||||||
if (value == null || value.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Integer.parseInt(value);
|
|
||||||
return true;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifica si una cadena de texto no es nula y no está vacía después de
|
|
||||||
* eliminar espacios en blanco.
|
|
||||||
*
|
|
||||||
* @param value La cadena de texto a verificar.
|
|
||||||
* @return true si la cadena no está vacía, false en caso contrario.
|
|
||||||
*/
|
|
||||||
public static boolean isNotEmpty(String value) {
|
|
||||||
return value != null && !value.trim().isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rellena una cadena de texto con un carácter específico a la izquierda
|
|
||||||
* hasta alcanzar la longitud deseada.
|
|
||||||
*
|
|
||||||
* @param numberStr La cadena de texto a rellenar.
|
|
||||||
* @param strLen La longitud deseada de la cadena resultante.
|
|
||||||
* @param c El carácter de relleno.
|
|
||||||
* @return La cadena rellenada con el carácter especificado a la izquierda.
|
|
||||||
*/
|
|
||||||
public static String leftPad(String numberStr, int strLen, Character c) {
|
|
||||||
return StringUtils.leftPad(numberStr, strLen, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
package com.banesco.infraestructure.repository;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import com.banesco.domain.model.RequestBase;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
|
|
||||||
public class SoapHeadersRepository {
|
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(MessageRepository.class.getName());
|
|
||||||
|
|
||||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
|
||||||
public static final DateTimeFormatter DATE_TIME_YYYY_MM_dd = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
||||||
public static final DateTimeFormatter DATE_TIME_HH_mm_ss = DateTimeFormatter.ofPattern("HH:mm:ss");
|
|
||||||
|
|
||||||
public static RequestBase.MsgRqHdr getHeader(String headerName) {
|
|
||||||
RequestBase.MsgRqHdr msgRqHdr = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
InputStream in = Thread.currentThread().getContextClassLoader()
|
|
||||||
.getResourceAsStream("headers/" + headerName + ".json");
|
|
||||||
msgRqHdr = OBJECT_MAPPER.readValue(Objects.requireNonNull(in), RequestBase.MsgRqHdr.class);
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.log(Level.WARNING, String.format("ERROR: Path /headers/%s", headerName));
|
|
||||||
// o lanzar una excepcion.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msgRqHdr != null) {
|
|
||||||
Timestamp dateHour = Timestamp.valueOf(LocalDateTime.now(ZoneId.of("America/Caracas")));
|
|
||||||
|
|
||||||
String date = new SimpleDateFormat("yyyy-MM-dd").format(dateHour);
|
|
||||||
String hour = new SimpleDateFormat("HH:mm:ss").format(dateHour);
|
|
||||||
|
|
||||||
msgRqHdr.setMessageTime(hour);
|
|
||||||
msgRqHdr.getNetworkTrnInfo().setTransactionDate(date);
|
|
||||||
msgRqHdr.getNetworkTrnInfo().setTransactionTime(hour);
|
|
||||||
|
|
||||||
return msgRqHdr;
|
|
||||||
} else {
|
|
||||||
return msgRqHdr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,100 +0,0 @@
|
|||||||
package com.banesco.infraestructure.service;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import com.banesco.domain.model.BackResponse;
|
|
||||||
import com.banesco.domain.model.BaseResponse;
|
|
||||||
import com.banesco.infraestructure.repository.MessageRepository;
|
|
||||||
|
|
||||||
public class MessageService<T extends BaseResponse> {
|
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(MessageService.class.getName());
|
|
||||||
private final Class<T> currentClass;
|
|
||||||
private final MessageRepository messageRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor de MessageService.
|
|
||||||
*
|
|
||||||
* @param currentClass La clase de la respuesta genérica (T) que se
|
|
||||||
* utilizará para crear instancias.
|
|
||||||
* @param messageRepository El repositorio de mensajes que se utilizará para
|
|
||||||
* cargar y obtener mensajes de error.
|
|
||||||
*/
|
|
||||||
public MessageService(Class<T> currentClass, MessageRepository messageRepository) {
|
|
||||||
this.currentClass = currentClass;
|
|
||||||
this.messageRepository = messageRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Crea una instancia de la clase genérica T.
|
|
||||||
*
|
|
||||||
* @return Una nueva instancia de T.
|
|
||||||
* @throws RuntimeException Si ocurre un error al crear la instancia.
|
|
||||||
*/
|
|
||||||
public T createInstance() {
|
|
||||||
try {
|
|
||||||
return currentClass.getDeclaredConstructor().newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.log(Level.SEVERE, "Error creating instance: " + e.getMessage(), e);
|
|
||||||
throw new RuntimeException("Error creating instance", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Carga mensajes desde una cadena JSON en el repositorio de mensajes.
|
|
||||||
*
|
|
||||||
* @param responseFileName El nombre del archivo de respuesta asociado con
|
|
||||||
* los mensajes.
|
|
||||||
* @param jsonResponse La cadena JSON que contiene los mensajes.
|
|
||||||
*/
|
|
||||||
public void loadMessageFromJson(String responseFileName, String jsonResponse) {
|
|
||||||
try {
|
|
||||||
messageRepository.loadMessagesFromString(responseFileName, jsonResponse);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.log(Level.SEVERE, String.format("Error loading messages from JSON: %s", ex.getMessage()), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtiene una respuesta de estado (BackResponse) basada en el código de
|
|
||||||
* backend y el nombre del archivo de respuesta.
|
|
||||||
*
|
|
||||||
* @param responseFileName El nombre del archivo de respuesta.
|
|
||||||
* @param backendCode El código de backend para buscar la respuesta.
|
|
||||||
* @return La respuesta de estado (BackResponse) correspondiente al código
|
|
||||||
* de backend, la respuesta por defecto si no se encuentra, o null si hay un
|
|
||||||
* error.
|
|
||||||
*/
|
|
||||||
private BackResponse geStatusResponse(String responseFileName, String backendCode) {
|
|
||||||
logger.log(Level.INFO, String.format("Finding backendCode: \"%s\" in File: \"%s\"", backendCode, responseFileName));
|
|
||||||
Map<String, BackResponse> errors = messageRepository.getErrorMap(responseFileName);
|
|
||||||
|
|
||||||
if (errors == null || errors.isEmpty()) {
|
|
||||||
logger.log(Level.WARNING, String.format("Error map for %s is empty or null.", responseFileName));
|
|
||||||
return messageRepository.DEFAULT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
BackResponse backResponse = null;
|
|
||||||
try {
|
|
||||||
backResponse = errors.get(backendCode);
|
|
||||||
if (backResponse == null) {
|
|
||||||
backResponse = errors.get("default");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.log(Level.WARNING, String.format("Error code: %s not found in %s. Using default.", backendCode, responseFileName), e);
|
|
||||||
try {
|
|
||||||
backResponse = errors.get("default");
|
|
||||||
} catch (Exception e2) {
|
|
||||||
logger.log(Level.SEVERE, "Error getting default code.", e2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (backResponse == null) {
|
|
||||||
logger.log(Level.WARNING, String.format("Error code: %s and default not found in %s.", backendCode, responseFileName));
|
|
||||||
return messageRepository.DEFAULT_ERROR;
|
|
||||||
}
|
|
||||||
return backResponse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
package com.banesco.infraestructure.utils;
|
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clase para validar números telefónicos según patrones específicos. Utiliza
|
|
||||||
* expresiones regulares para verificar que los números telefónicos cumplan con
|
|
||||||
* el formato esperado, permitiendo diferentes configuraciones según los
|
|
||||||
* requisitos regionales o de formato de la aplicación.
|
|
||||||
*/
|
|
||||||
public class PhoneNumberValidator {
|
|
||||||
|
|
||||||
private final Pattern pattern;
|
|
||||||
|
|
||||||
public PhoneNumberValidator(String phonePattern) {
|
|
||||||
pattern = Pattern.compile(phonePattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates the phone number format.
|
|
||||||
*
|
|
||||||
* @param phoneNumber the phone number to validate.
|
|
||||||
* @return true if the phone number is valid, false otherwise.
|
|
||||||
*/
|
|
||||||
public boolean isValid(String phoneNumber) {
|
|
||||||
if (phoneNumber == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return pattern.matcher(phoneNumber).matches();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,111 +0,0 @@
|
|||||||
package com.banesco.infraestructure.web;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.http.HttpClient;
|
|
||||||
import java.net.http.HttpRequest;
|
|
||||||
import java.net.http.HttpResponse;
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clase constructora para crear instancias de WebClient utilizando
|
|
||||||
* java.net.http.HttpClient
|
|
||||||
*
|
|
||||||
* @author [Tu Nombre]
|
|
||||||
*/
|
|
||||||
public class BaseWebClientBuilder {
|
|
||||||
|
|
||||||
private String baseUrl;
|
|
||||||
private Duration connectTimeout;
|
|
||||||
private Duration responseTimeout;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor para inicializar los timeouts con valores predeterminados.
|
|
||||||
*/
|
|
||||||
public BaseWebClientBuilder() {
|
|
||||||
this.connectTimeout = Duration.ofSeconds(10);
|
|
||||||
this.responseTimeout = Duration.ofSeconds(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Método estático para iniciar la construcción de un BaseWebClientBuilder.
|
|
||||||
* Permite encadenar llamadas a los métodos de configuración.
|
|
||||||
*
|
|
||||||
* @return Una nueva instancia de BaseWebClientBuilder.
|
|
||||||
*/
|
|
||||||
public static BaseWebClientBuilder builder() {
|
|
||||||
return new BaseWebClientBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configura la URL base para el WebClient.
|
|
||||||
*
|
|
||||||
* @param baseUrl La URL base a utilizar.
|
|
||||||
* @return La instancia actual de BaseWebClientBuilder para encadenar
|
|
||||||
* llamadas.
|
|
||||||
*/
|
|
||||||
public BaseWebClientBuilder baseUrl(String baseUrl) {
|
|
||||||
this.baseUrl = baseUrl;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configura el timeout de conexión.
|
|
||||||
*
|
|
||||||
* @param timeout El timeout de conexión.
|
|
||||||
* @return La instancia actual de BaseWebClientBuilder para encadenar
|
|
||||||
* llamadas.
|
|
||||||
*/
|
|
||||||
public BaseWebClientBuilder connectTimeout(Duration timeout) {
|
|
||||||
this.connectTimeout = timeout;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configura el timeout de respuesta.
|
|
||||||
*
|
|
||||||
* @param timeout El timeout de respuesta.
|
|
||||||
* @return La instancia actual de BaseWebClientBuilder para encadenar
|
|
||||||
* llamadas.
|
|
||||||
*/
|
|
||||||
public BaseWebClientBuilder responseTimeout(Duration timeout) {
|
|
||||||
this.responseTimeout = timeout;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construye y devuelve una instancia de HttpClient con la configuración
|
|
||||||
* especificada.
|
|
||||||
*
|
|
||||||
* @return Una instancia de HttpClient configurada.
|
|
||||||
*/
|
|
||||||
public HttpClient build() {
|
|
||||||
return HttpClient.newBuilder()
|
|
||||||
.connectTimeout(connectTimeout)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Realiza una petición GET utilizando el HttpClient configurado.
|
|
||||||
*
|
|
||||||
* @param httpClient El HttpClient configurado.
|
|
||||||
* @param path El path de la petición.
|
|
||||||
* @return Un CompletableFuture que emite la respuesta como String.
|
|
||||||
* @throws IOException
|
|
||||||
* @throws InterruptedException
|
|
||||||
*/
|
|
||||||
public CompletableFuture<String> get(HttpClient httpClient, String path) {
|
|
||||||
HttpRequest request = HttpRequest.newBuilder()
|
|
||||||
.uri(URI.create(baseUrl + path))
|
|
||||||
.header("Content-Type", "application/json")
|
|
||||||
.header("Accept", "application/json")
|
|
||||||
.timeout(responseTimeout)
|
|
||||||
.GET()
|
|
||||||
.build();
|
|
||||||
|
|
||||||
return httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
|
|
||||||
.thenApply(HttpResponse::body);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,38 +1,19 @@
|
|||||||
package com.banesco;
|
package com.banesco;
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for simple App.
|
* Unit test for simple App.
|
||||||
*/
|
*/
|
||||||
public class AppTest
|
public class AppTest {
|
||||||
extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Create the test case
|
* Create the test case
|
||||||
*
|
*
|
||||||
* @param testName name of the test case
|
* @param testName name of the test case
|
||||||
*/
|
*/
|
||||||
public AppTest( String testName )
|
|
||||||
{
|
public AppTest(String testName) {
|
||||||
super( testName );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the suite of tests being tested
|
|
||||||
*/
|
|
||||||
public static Test suite()
|
|
||||||
{
|
|
||||||
return new TestSuite( AppTest.class );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rigourous Test :-)
|
|
||||||
*/
|
|
||||||
public void testApp()
|
|
||||||
{
|
|
||||||
assertTrue( true );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user