Ajustes para Response and Device Bian
This commit is contained in:
parent
3f36666c4d
commit
f9196a9900
@ -0,0 +1,36 @@
|
||||
package com.banesco.common.domain.dto.bian.customer;
|
||||
|
||||
public class CustomerReference {
|
||||
String customerIdType;
|
||||
String customerId;
|
||||
|
||||
public CustomerReference() {
|
||||
}
|
||||
|
||||
public CustomerReference(String customerIdType, String customerId) {
|
||||
this.customerIdType = customerIdType;
|
||||
this.customerId = customerId;
|
||||
}
|
||||
|
||||
public String getCustomerIdType() {
|
||||
return customerIdType;
|
||||
}
|
||||
|
||||
public void setCustomerIdType(String customerIdType) {
|
||||
this.customerIdType = customerIdType;
|
||||
}
|
||||
|
||||
public String getCustomerId() {
|
||||
return customerId;
|
||||
}
|
||||
|
||||
public void setCustomerId(String customerId) {
|
||||
this.customerId = customerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{\"customerIdType\":\"%s\",\"customerId\":\"%s\"}"
|
||||
.formatted(customerIdType, customerId);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package com.banesco.common.domain.dto.bian.device;
|
||||
|
||||
|
||||
|
||||
public class BianDevice {
|
||||
String deviceType;
|
||||
String deviceDescription;
|
||||
String deviceIp;
|
||||
String deviceSessionReference;
|
||||
|
||||
public BianDevice() {
|
||||
|
||||
}
|
||||
|
||||
public BianDevice(String deviceType, String deviceDescription, String deviceIp, String deviceSessionReference) {
|
||||
this.deviceType = deviceType;
|
||||
this.deviceDescription = deviceDescription;
|
||||
this.deviceIp = deviceIp;
|
||||
this.deviceSessionReference = deviceSessionReference;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public String getDeviceDescription() {
|
||||
return deviceDescription;
|
||||
}
|
||||
|
||||
public void setDeviceDescription(String deviceDescription) {
|
||||
this.deviceDescription = deviceDescription;
|
||||
}
|
||||
|
||||
public String getDeviceIp() {
|
||||
return deviceIp;
|
||||
}
|
||||
|
||||
public void setDeviceIp(String deviceIp) {
|
||||
this.deviceIp = deviceIp;
|
||||
}
|
||||
|
||||
public String getDeviceSessionReference() {
|
||||
return deviceSessionReference;
|
||||
}
|
||||
|
||||
public void setDeviceSessionReference(String deviceSessionReference) {
|
||||
this.deviceSessionReference = deviceSessionReference;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "{\"deviceType\":\"%s\",\"deviceDescription\":\"%s\",\"deviceIp\":\"%s\",\"deviceSessionReference\":\"%s\"}"
|
||||
.formatted(deviceType, deviceDescription, deviceIp, deviceSessionReference);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
package com.banesco.common.domain.dto.bian.paymentCard;
|
||||
|
||||
public enum CardTypeValues {
|
||||
DebitCard,
|
||||
CreditCard
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package com.banesco.common.domain.dto.bian.response;
|
||||
|
||||
public class BaseResponse<T, K> {
|
||||
protected T statusResponse;
|
||||
|
||||
protected K dataResponse;
|
||||
|
||||
public BaseResponse() {
|
||||
}
|
||||
|
||||
public BaseResponse(T statusResponse, K dataResponse) {
|
||||
|
||||
this.statusResponse = statusResponse;
|
||||
this.dataResponse = dataResponse;
|
||||
|
||||
}
|
||||
|
||||
public T getStatusResponse() {
|
||||
return statusResponse;
|
||||
}
|
||||
|
||||
public void setStatusResponse(T statusResponse) {
|
||||
this.statusResponse = statusResponse;
|
||||
}
|
||||
|
||||
public K getDataResponse() {
|
||||
return dataResponse;
|
||||
}
|
||||
|
||||
public void setDataResponse(K statusResponse) {
|
||||
this.dataResponse = dataResponse;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.banesco.common.domain.dto.bian.response;
|
||||
|
||||
public record BianStatusResponse(String status, String statusCode, String message, String traceId) {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{\"status\":\"%s\",\"statusCode\":\"%s\",\"message\":\"%s\",\"traceId\":\"%s\"}".formatted(status, statusCode, message, traceId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.banesco.common.domain.dto.bian.response;
|
||||
|
||||
public record MetadataResponse(String timestamp, String operationId) {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{\"timestamp\":\"%s\",\"operationId\":\"%s\"}".formatted(timestamp, operationId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.banesco.common.infraestructure.config;
|
||||
|
||||
public enum DeviceTypeValues {
|
||||
Mobile,
|
||||
Tablet,
|
||||
PersonalComputer,
|
||||
SecureCardReader,
|
||||
NonSecureCardReader,
|
||||
OtherNational,
|
||||
OtherPrivate,
|
||||
Wearable,
|
||||
Vehicle,
|
||||
Embedded,
|
||||
KeyFob,
|
||||
Jewellery,
|
||||
Sticker,
|
||||
GamingDevice,
|
||||
Watch,
|
||||
Unknown
|
||||
}
|
||||
@ -1,14 +1,21 @@
|
||||
package com.banesco.common.infraestructure.helpers;
|
||||
|
||||
import com.banesco.common.domain.dto.bian.device.BianDevice;
|
||||
import com.banesco.common.domain.model.Device;
|
||||
import com.banesco.common.infraestructure.config.DeviceTypeValues;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class DeviceHelper {
|
||||
|
||||
private boolean readDeviceFromRequest;
|
||||
private final String DESKTOP = "Desktop";
|
||||
|
||||
private static final Logger logger = Logger.getLogger(DeviceHelper.class.getName());
|
||||
/**
|
||||
* Nombres de cabeceras HTTP que pueden contener la dirección IP del
|
||||
* cliente. Se revisan en orden para encontrar la IP real considerando
|
||||
@ -93,4 +100,55 @@ public class DeviceHelper {
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapea el tipo de dispositivo desde el objeto BianDevice al enum DeviceTypeValues.
|
||||
*
|
||||
* @param device
|
||||
* @return
|
||||
*/
|
||||
public static DeviceTypeValues getDeviceTypeValue(
|
||||
BianDevice device
|
||||
) {
|
||||
var deviceTypeValue = DeviceTypeValues.Unknown;
|
||||
|
||||
if (!Objects.isNull(device) && !StringHelper.isEmpty(device.getDeviceType())) {
|
||||
try {
|
||||
deviceTypeValue = DeviceTypeValues.valueOf(device.getDeviceType());
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Error Mapping Device Type: %s -> %s".formatted(device.getDeviceType(), e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
return deviceTypeValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Valida si el tipo de dispositivo es válido según el enum DeviceTypeValues.
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidDeviceType(String type) {
|
||||
|
||||
for (DeviceTypeValues deviceType : DeviceTypeValues.values()) {
|
||||
if (deviceType.name().equals(type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene una cadena con todos los tipos de dispositivos válidos.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getDeviceTypes() {
|
||||
return Stream.of(DeviceTypeValues.values()).map(Enum::name).collect(
|
||||
Collectors.joining(", ")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,11 @@
|
||||
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 com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
@ -7,12 +13,6 @@ import java.util.List;
|
||||
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;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
|
||||
public class JsonHelper {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(JsonHelper.class.getName());
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
package com.banesco.common.infraestructure.helpers;
|
||||
|
||||
import com.banesco.common.domain.dto.bian.paymentCard.CardTypeValues;
|
||||
|
||||
public class PaymentCardHelper {
|
||||
|
||||
public static boolean isValidCardType(String type) {
|
||||
for (CardTypeValues cardTypeValue : CardTypeValues.values()) {
|
||||
if (cardTypeValue.name().equals(type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,11 @@
|
||||
package com.banesco.common.infraestructure.helpers;
|
||||
|
||||
import jakarta.xml.bind.JAXBContext;
|
||||
import jakarta.xml.bind.JAXBElement;
|
||||
import jakarta.xml.bind.JAXBException;
|
||||
import jakarta.xml.bind.Marshaller;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
@ -10,13 +16,6 @@ import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import jakarta.xml.bind.JAXBContext;
|
||||
import jakarta.xml.bind.JAXBElement;
|
||||
import jakarta.xml.bind.JAXBException;
|
||||
import jakarta.xml.bind.Marshaller;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
* Clase de utilidad para trabajar con XML utilizando JAXB.
|
||||
*/
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.banesco.common.infraestructure.service;
|
||||
|
||||
import com.banesco.common.domain.dto.bian.response.BianStatusResponse;
|
||||
import com.banesco.common.domain.model.BackResponse;
|
||||
import com.banesco.common.domain.model.StatusResponse;
|
||||
import com.banesco.common.infraestructure.repository.MessageRepository;
|
||||
@ -98,4 +99,15 @@ public class MessageService {
|
||||
backResponse.getDescription().formatted(target)
|
||||
);
|
||||
}
|
||||
|
||||
public BianStatusResponse backToBianStatusResponse(String traceId, BackResponse backResponse, String target) {
|
||||
return new BianStatusResponse(
|
||||
backResponse.getHttpCode() >= 200 && backResponse.getHttpCode() < 300 ? "ok" : "error",
|
||||
backResponse.getStatusCode(),
|
||||
target == null ? backResponse.getDescription() :
|
||||
backResponse.getDescription().formatted(target),
|
||||
traceId
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user