Update channelOrigin as String
This commit is contained in:
parent
63f20d33b4
commit
d89606362c
4
pom.xml
4
pom.xml
@ -77,6 +77,10 @@
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-smallrye-health</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
||||
Binary file not shown.
@ -40,6 +40,14 @@ public class MessageHelper {
|
||||
this.errorMappings = initializeErrorMappings();
|
||||
}
|
||||
|
||||
public Response handleSuccess(Object data, String statusCode) {
|
||||
log.info(
|
||||
"Respuesta exitosa controlada: {}",
|
||||
statusCode
|
||||
);
|
||||
return buildResponse(data, statusCode);
|
||||
}
|
||||
|
||||
public Response handleException(HttpStatusCodeException exception) {
|
||||
log.error(
|
||||
"Error interno controlado: {} -> {}",
|
||||
@ -110,6 +118,25 @@ public class MessageHelper {
|
||||
.build();
|
||||
}
|
||||
|
||||
private Response buildResponse(Object data, String statusCode) {
|
||||
ErrorMapping mapping = errorMappings.getOrDefault(
|
||||
statusCode, errorMappings.getOrDefault(
|
||||
statusCode, createDefaultMapping()
|
||||
)
|
||||
);
|
||||
StatusResponse status = createError(mapping, null);
|
||||
|
||||
log.error(
|
||||
"[Success] Message {} -> {}",
|
||||
statusCode,
|
||||
status.getMessage()
|
||||
);
|
||||
|
||||
return Response.status(mapping.getHttpCode())
|
||||
.entity(new ApiResponse<>(data, status))
|
||||
.build();
|
||||
}
|
||||
|
||||
private Map<String, ErrorMapping> initializeErrorMappings() {
|
||||
try {
|
||||
String json;
|
||||
|
||||
@ -1,12 +1,17 @@
|
||||
package com.banesco.common.application.helper;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@ApplicationScoped
|
||||
@ -33,6 +38,14 @@ public class SerializationHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public String encodeStringToBase64(String text) {
|
||||
if (StringUtil.isNullOrEmpty(text)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public <T> T decodeBase64(String base64String, Class<T> clazz) {
|
||||
try {
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(base64String);
|
||||
@ -44,4 +57,116 @@ public class SerializationHelper {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String encodeSha256(String json) {
|
||||
return DigestUtils.sha256Hex(json);
|
||||
}
|
||||
|
||||
public <T> String toJsonString(T element) {
|
||||
if (element == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
try {
|
||||
return objectMapper.writeValueAsString(element);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error al convertir objeto a Json String: {}", e.getMessage());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public <T> Map<String, Object> toMap(T element) {
|
||||
return toMap(element, null);
|
||||
}
|
||||
|
||||
public <T> Map<String, Object> toMap(
|
||||
T element,
|
||||
List<String> excludedFields
|
||||
) {
|
||||
if (element == null) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
try {
|
||||
Map<String, Object> map = objectMapper.convertValue(
|
||||
element, new TypeReference<>() {}
|
||||
);
|
||||
|
||||
if (excludedFields != null && !excludedFields.isEmpty()) {
|
||||
Set<String> excludedSet = new HashSet<>(excludedFields);
|
||||
excludedSet.forEach(map::remove);
|
||||
}
|
||||
|
||||
return map;
|
||||
} catch (Exception e) {
|
||||
log.error("Error al convertir objeto a Map: {}", e.getMessage());
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
public <T> Map<String, Object> toTreeMap(T element) {
|
||||
return toTreeMap(element, null);
|
||||
}
|
||||
|
||||
public <T> Map<String, Object> toTreeMap(
|
||||
T element,
|
||||
List<String> excludedFields
|
||||
) {
|
||||
if (element == null) {
|
||||
return new TreeMap<>();
|
||||
}
|
||||
|
||||
try {
|
||||
Map<String, Object> tempMap = objectMapper.convertValue(
|
||||
element, new TypeReference<>() {}
|
||||
);
|
||||
|
||||
Map<String, Object> treeMap = new TreeMap<>(tempMap);
|
||||
|
||||
if (excludedFields != null && !excludedFields.isEmpty()) {
|
||||
Set<String> excludedSet = new HashSet<>(excludedFields);
|
||||
excludedSet.forEach(treeMap::remove);
|
||||
}
|
||||
|
||||
return treeMap;
|
||||
} catch (Exception e) {
|
||||
log.error("Error al convertir objeto a TreeMap: {}", e.getMessage());
|
||||
return new TreeMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
public String generateSignature(
|
||||
Object operation,
|
||||
String channelOrigin
|
||||
) {
|
||||
Map<String, Object> operationSortedMap = toTreeMap(operation);
|
||||
StringBuilder concatenatedValues = new StringBuilder();
|
||||
String channelBase64 = encodeStringToBase64(channelOrigin);
|
||||
|
||||
for (Object value : operationSortedMap.values()) {
|
||||
if(!Objects.isNull(value)) {
|
||||
concatenatedValues.append(value);
|
||||
}
|
||||
}
|
||||
|
||||
String finalString = concatenatedValues + channelBase64;
|
||||
|
||||
log.info("1. Operation concatenando valores: {}", concatenatedValues);
|
||||
log.info("2. Channel Origin codificado: {}", channelBase64);
|
||||
|
||||
return encodeSha256(finalString);
|
||||
}
|
||||
|
||||
public String generateSignature(
|
||||
Long id,
|
||||
String channelOrigin
|
||||
) {
|
||||
String channelBase64 = encodeStringToBase64(channelOrigin);
|
||||
String finalString = id + channelBase64;
|
||||
|
||||
log.info("1. Operation concatenando valores: {}", finalString);
|
||||
log.info("2. Channel Origin codificado: {}", channelBase64);
|
||||
|
||||
return encodeSha256(finalString);
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,6 +17,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -34,56 +36,61 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
|
||||
@Override
|
||||
public <T> T execute(HttpRequest request) {
|
||||
return executeInternal(request);
|
||||
return executeRequest(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, R> Either<T, R> executeEither(HttpRequest request) {
|
||||
return executeEitherInternal(request, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, R> Either<List<T>, R> executeEitherList(HttpRequest request) {
|
||||
return executeEitherInternal(request, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ApiResponse<T> executeApiResponse(HttpRequest request) {
|
||||
return executeInternal(request);
|
||||
return executeRequest(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ApiResponse<List<T>> executeApiResponseList(
|
||||
HttpRequest request
|
||||
) {
|
||||
return executeInternal(request);
|
||||
public <T> ApiResponse<List<T>> executeApiResponseList(HttpRequest request) {
|
||||
return executeRequest(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ApiPrivateResponse<Either<T, ApiPrivateError>> executeApiPrivateResponse(
|
||||
HttpRequest request
|
||||
) {
|
||||
return executeInternal(request);
|
||||
public <T> ApiPrivateResponse<Either<T, ApiPrivateError>> executeApiPrivateResponse(HttpRequest request) {
|
||||
return executeRequest(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ApiPrivateResponse<Either<List<T>, ApiPrivateError>> executeApiPrivateResponseList(
|
||||
HttpRequest request
|
||||
) {
|
||||
return executeInternal(request);
|
||||
public <T> ApiPrivateResponse<Either<List<T>, ApiPrivateError>> executeApiPrivateResponseList(HttpRequest request) {
|
||||
return executeRequest(request);
|
||||
}
|
||||
|
||||
private <T> T executeInternal(HttpRequest request) {
|
||||
String finalUrl = buildFinalUrl(request);
|
||||
|
||||
if (request.isLogRequestBody()) {
|
||||
log.info("URL final: {}", finalUrl);
|
||||
|
||||
if (request.getHeaders() != null && !request.getHeaders().isEmpty()) {
|
||||
log.info("Headers: {}", request.getHeaders());
|
||||
}
|
||||
|
||||
if (request.getQueryParams() != null && !request.getQueryParams().isEmpty()) {
|
||||
log.info("Query params: {}", request.getQueryParams());
|
||||
}
|
||||
|
||||
if (request.getBody() != null) {
|
||||
log.info("Body: {}", request.getBody());
|
||||
}
|
||||
}
|
||||
|
||||
private <T, R> Either<T, R> executeEitherInternal(HttpRequest request, boolean isList) {
|
||||
try (Client client = createClient(request.getConnectTimeout(), request.getReadTimeout())) {
|
||||
WebTarget target = client.target(finalUrl);
|
||||
WebTarget target = client.target(buildFinalUrl(request));
|
||||
Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON);
|
||||
|
||||
if (request.getHeaders() != null) {
|
||||
request.getHeaders().forEach(builder::header);
|
||||
}
|
||||
|
||||
Response response = buildRequest(builder, request);
|
||||
return handleEitherResponse(request, response, isList);
|
||||
|
||||
} catch (HttpStatusCodeException | HttpApiResponseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw handleConnectionError(request, e);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T executeRequest(HttpRequest request) {
|
||||
try (Client client = createClient(request.getConnectTimeout(), request.getReadTimeout())) {
|
||||
WebTarget target = client.target(buildFinalUrl(request));
|
||||
Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON);
|
||||
|
||||
if (request.getHeaders() != null) {
|
||||
@ -95,14 +102,122 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
} catch (HttpStatusCodeException | HttpApiResponseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error("Error de conexion {}: {}", request.getMethod(), e.getMessage());
|
||||
throw HttpStatusCodeException.serviceUnavailable(
|
||||
"503",
|
||||
"Error de conexion con el servicio externo: " + e.getMessage()
|
||||
);
|
||||
throw handleConnectionError(request, e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T, R> Either<T, R> handleEitherResponse(HttpRequest request, Response response, boolean isList) {
|
||||
int statusCode = response.getStatus();
|
||||
|
||||
try (response) {
|
||||
String responseBody = response.readEntity(String.class);
|
||||
logResponse(request, statusCode, responseBody);
|
||||
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
Object successData = isList
|
||||
? parseSuccessListResponse(request, responseBody)
|
||||
: parseSuccessResponse(request, responseBody);
|
||||
return Either.left((T) successData);
|
||||
} else {
|
||||
logErrorResponse(request, statusCode, responseBody);
|
||||
R errorData = tryParseErrorResponse(request, responseBody);
|
||||
|
||||
if (errorData != null) {
|
||||
return Either.right(errorData);
|
||||
}
|
||||
|
||||
throw mapHttpStatusToException(statusCode, responseBody);
|
||||
}
|
||||
} catch (HttpStatusCodeException | HttpApiResponseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw handleProcessingError(request, e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T parseSuccessResponse(HttpRequest request, String responseBody) throws JsonProcessingException {
|
||||
Type successType = extractSuccessType(request);
|
||||
|
||||
if (successType != null) {
|
||||
if (successType instanceof Class) {
|
||||
return objectMapper.readValue(responseBody, (Class<T>) successType);
|
||||
} else if (successType instanceof ParameterizedType) {
|
||||
JavaType javaType = objectMapper.getTypeFactory().constructType(successType);
|
||||
return objectMapper.readValue(responseBody, javaType);
|
||||
}
|
||||
}
|
||||
|
||||
if (request.getResponseType() != null && request.getResponseType() != Object.class) {
|
||||
return objectMapper.readValue(responseBody, objectMapper.getTypeFactory().constructType(request.getResponseType()));
|
||||
}
|
||||
|
||||
return (T) objectMapper.readValue(responseBody, Object.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> List<T> parseSuccessListResponse(HttpRequest request, String responseBody) throws JsonProcessingException {
|
||||
Type successType = extractSuccessType(request);
|
||||
|
||||
if (
|
||||
successType instanceof ParameterizedType paramType &&
|
||||
paramType.getRawType() == List.class &&
|
||||
paramType.getActualTypeArguments().length > 0
|
||||
) {
|
||||
Type elementType = paramType.getActualTypeArguments()[0];
|
||||
if (elementType instanceof Class) {
|
||||
JavaType javaType = objectMapper.getTypeFactory().constructCollectionType(
|
||||
List.class, (Class<T>) elementType
|
||||
);
|
||||
return objectMapper.readValue(responseBody, javaType);
|
||||
}
|
||||
}
|
||||
|
||||
return objectMapper.readValue(responseBody, List.class);
|
||||
}
|
||||
|
||||
private Type extractSuccessType(HttpRequest request) {
|
||||
if (
|
||||
request.getComplexType() != null &&
|
||||
request.getComplexType() instanceof ParameterizedType paramType &&
|
||||
paramType.getRawType() == Either.class &&
|
||||
paramType.getActualTypeArguments().length > 0
|
||||
) {
|
||||
return paramType.getActualTypeArguments()[0];
|
||||
}
|
||||
|
||||
if (request.getGenericType() != null) {
|
||||
return request.getGenericType();
|
||||
}
|
||||
|
||||
return request.getResponseType();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <R> R tryParseErrorResponse(HttpRequest request, String responseBody) {
|
||||
if (responseBody == null || responseBody.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (request.getErrorType() != null) {
|
||||
return (R) objectMapper.readValue(responseBody, request.getErrorType());
|
||||
}
|
||||
|
||||
if (request.getComplexType() != null && request.getComplexType() instanceof ParameterizedType paramType) {
|
||||
Type[] typeArgs = paramType.getActualTypeArguments();
|
||||
if (typeArgs.length >= 2 && typeArgs[1] instanceof Class) {
|
||||
return objectMapper.readValue(responseBody, (Class<R>) typeArgs[1]);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("No se pudo parsear la respuesta como error type: {}", e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String buildFinalUrl(HttpRequest request) {
|
||||
String finalUrl = request.getUrl();
|
||||
|
||||
@ -113,7 +228,11 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
}
|
||||
}
|
||||
|
||||
return appendQueryParams(finalUrl, request.getQueryParams());
|
||||
String url = appendQueryParams(finalUrl, request.getQueryParams());
|
||||
|
||||
log.info("Url Final: {}", url);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
private String appendQueryParams(String url, Map<String, String> queryParams) {
|
||||
@ -132,20 +251,24 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
urlBuilder.append("&");
|
||||
}
|
||||
|
||||
urlBuilder.append(entry.getKey())
|
||||
.append("=")
|
||||
.append(entry.getValue() != null ? entry.getValue() : "");
|
||||
String encodedKey = URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8);
|
||||
String encodedValue = entry.getValue() != null
|
||||
? URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)
|
||||
: "";
|
||||
|
||||
urlBuilder.append(encodedKey).append("=").append(encodedValue);
|
||||
}
|
||||
|
||||
return urlBuilder.toString();
|
||||
}
|
||||
|
||||
private Response buildRequest(
|
||||
Invocation.Builder builder,
|
||||
HttpRequest request
|
||||
) {
|
||||
private Response buildRequest(Invocation.Builder builder, HttpRequest request) {
|
||||
log.info("Metodo HTTP: {}", request.getMethod().name());
|
||||
|
||||
if(request.getBody() != null) {
|
||||
log.info("Peticion Cuerpo: {}", request.getBody());
|
||||
}
|
||||
|
||||
return switch (request.getMethod()) {
|
||||
case GET -> builder.get();
|
||||
case POST -> builder.post(Entity.entity(request.getBody(), MediaType.APPLICATION_JSON));
|
||||
@ -160,43 +283,26 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
|
||||
private Client createClient(int connectTimeout, int readTimeout) {
|
||||
return ClientBuilder.newBuilder()
|
||||
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(readTimeout, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(readTimeout, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
}
|
||||
|
||||
private <T> T handleResponse(
|
||||
HttpRequest request,
|
||||
Response response
|
||||
) {
|
||||
private <T> T handleResponse(HttpRequest request, Response response) {
|
||||
int statusCode = response.getStatus();
|
||||
log.info("Respuesta {} - Status: {}", request.getMethod(), statusCode);
|
||||
|
||||
try (response) {
|
||||
String responseBody = response.readEntity(String.class);
|
||||
|
||||
if (request.isLogResponseBody()) {
|
||||
log.info("Respuesta Cuerpo: {}", responseBody);
|
||||
}
|
||||
logResponse(request, statusCode, responseBody);
|
||||
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
if (request.getResponseType() == Void.class || request.getResponseType() == void.class) {
|
||||
return null;
|
||||
}
|
||||
|
||||
T result = responseResult(request, responseBody);
|
||||
|
||||
log.debug("Respuesta exitosa {} {}: {}", request.getMethod(), request.getUrl(), result);
|
||||
|
||||
return result;
|
||||
return responseResult(request, responseBody);
|
||||
} else {
|
||||
log.error(
|
||||
"Error HTTP {} {} - Status: {} - Body: {}",
|
||||
request.getMethod(),
|
||||
request.getUrl(),
|
||||
statusCode,
|
||||
responseBody
|
||||
);
|
||||
logErrorResponse(request, statusCode, responseBody);
|
||||
|
||||
if (isApiResponseFormat(responseBody)) {
|
||||
ApiResponse<?> apiResponse = deserializeApiResponse(responseBody, request);
|
||||
@ -208,53 +314,72 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
} catch (HttpStatusCodeException | HttpApiResponseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error(
|
||||
"Error procesando respuesta {} {}: {}",
|
||||
request.getMethod(),
|
||||
request.getUrl(),
|
||||
e.getMessage()
|
||||
);
|
||||
throw HttpStatusCodeException.internalServer(
|
||||
"500", "Error procesando respuesta del servicio externo: " + e.getMessage()
|
||||
);
|
||||
throw handleProcessingError(request, e);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T responseResult(
|
||||
HttpRequest request,
|
||||
String responseBody
|
||||
) throws JsonProcessingException {
|
||||
private void logResponse(HttpRequest request, int statusCode, String responseBody) {
|
||||
if (request.isLogResponseBody()) {
|
||||
log.info("Respuesta {} - Status: {}", request.getMethod(), statusCode);
|
||||
log.info("Respuesta Cuerpo: {}", responseBody);
|
||||
}
|
||||
}
|
||||
|
||||
private void logErrorResponse(HttpRequest request, int statusCode, String responseBody) {
|
||||
log.error(
|
||||
"Error HTTP {} {} - Status: {} - Body: {}",
|
||||
request.getMethod(),
|
||||
request.getUrl(),
|
||||
statusCode,
|
||||
responseBody
|
||||
);
|
||||
}
|
||||
|
||||
private HttpStatusCodeException handleConnectionError(HttpRequest request, Exception e) {
|
||||
log.error("Error de conexion {}: {}", request.getMethod(), e.getMessage());
|
||||
|
||||
return HttpStatusCodeException.serviceUnavailable(
|
||||
"503", "Error de conexion con el servicio externo: " + e.getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
private HttpStatusCodeException handleProcessingError(HttpRequest request, Exception e) {
|
||||
log.error(
|
||||
"Error procesando respuesta {} {}: {}",
|
||||
request.getMethod(),
|
||||
request.getUrl(),
|
||||
e.getMessage()
|
||||
);
|
||||
return HttpStatusCodeException.internalServer(
|
||||
"500", "Error procesando respuesta del servicio externo: " + e.getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
private <T> T responseResult(HttpRequest request, String responseBody) throws JsonProcessingException {
|
||||
if (request.isApiPrivateResponse() && request.isEitherResponse()) {
|
||||
return handleApiPrivateResponseWithEither(request, responseBody);
|
||||
}
|
||||
|
||||
T result;
|
||||
|
||||
if (request.getResponseType() == ApiResponse.class) {
|
||||
result = deserializeApiResponse(responseBody, request);
|
||||
return deserializeApiResponse(responseBody, request);
|
||||
} else if (request.getComplexType() != null) {
|
||||
JavaType javaType = objectMapper.getTypeFactory().constructParametricType(
|
||||
request.getResponseType(), objectMapper.getTypeFactory().constructType(request.getComplexType())
|
||||
);
|
||||
result = objectMapper.readValue(responseBody, javaType);
|
||||
return objectMapper.readValue(responseBody, javaType);
|
||||
} else if (request.getGenericType() != null) {
|
||||
JavaType javaType = objectMapper.getTypeFactory().constructParametricType(
|
||||
request.getResponseType(), objectMapper.getTypeFactory().constructType(request.getGenericType())
|
||||
);
|
||||
result = objectMapper.readValue(responseBody, javaType);
|
||||
return objectMapper.readValue(responseBody, javaType);
|
||||
} else {
|
||||
result = objectMapper.readValue(
|
||||
return objectMapper.readValue(
|
||||
responseBody, objectMapper.getTypeFactory().constructType(request.getResponseType())
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private <T> T handleApiPrivateResponseWithEither(
|
||||
HttpRequest request,
|
||||
String responseBody
|
||||
) throws JsonProcessingException {
|
||||
private <T> T handleApiPrivateResponseWithEither(HttpRequest request, String responseBody) throws JsonProcessingException {
|
||||
JsonNode rootNode = objectMapper.readTree(responseBody);
|
||||
String status = rootNode.has("estatus") ? rootNode.get("estatus").asText() : null;
|
||||
String message = rootNode.has("mensaje") ? rootNode.get("mensaje").asText() : null;
|
||||
@ -268,12 +393,7 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T handleSuccessResponse(
|
||||
HttpRequest request,
|
||||
String status,
|
||||
String message,
|
||||
JsonNode detailNode
|
||||
) {
|
||||
private <T> T handleSuccessResponse(HttpRequest request, String status, String message, JsonNode detailNode) {
|
||||
Object successData;
|
||||
|
||||
if (request.isListResponse()) {
|
||||
@ -295,10 +415,7 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
}
|
||||
}
|
||||
|
||||
private Object handleListSuccess(
|
||||
HttpRequest request,
|
||||
JsonNode detailNode
|
||||
) {
|
||||
private Object handleListSuccess(HttpRequest request, JsonNode detailNode) {
|
||||
Class<?> elementType = getElementTypeFromRequest(request);
|
||||
JavaType listType = objectMapper.getTypeFactory().constructCollectionType(List.class, elementType);
|
||||
|
||||
@ -309,10 +426,7 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private Object handleObjectSuccess(
|
||||
HttpRequest request,
|
||||
JsonNode detailNode
|
||||
) {
|
||||
private Object handleObjectSuccess(HttpRequest request, JsonNode detailNode) {
|
||||
Class<?> elementType = getElementTypeFromRequest(request);
|
||||
|
||||
if (detailNode != null && !detailNode.isNull()) {
|
||||
@ -323,11 +437,7 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T handleErrorResponse(
|
||||
String status,
|
||||
String message,
|
||||
JsonNode detailNode
|
||||
) {
|
||||
private <T> T handleErrorResponse(String status, String message, JsonNode detailNode) {
|
||||
ApiPrivateError error = buildApiPrivateError(detailNode, message);
|
||||
ApiPrivateResponse<Either<Object, ApiPrivateError>> response = new ApiPrivateResponse<>();
|
||||
|
||||
@ -338,10 +448,7 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
return (T) response;
|
||||
}
|
||||
|
||||
private ApiPrivateError buildApiPrivateError(
|
||||
JsonNode detailNode,
|
||||
String message
|
||||
) {
|
||||
private ApiPrivateError buildApiPrivateError(JsonNode detailNode, String message) {
|
||||
if (detailNode != null && !detailNode.isNull()) {
|
||||
try {
|
||||
return objectMapper.convertValue(detailNode, ApiPrivateError.class);
|
||||
@ -385,15 +492,11 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T deserializeApiResponse(
|
||||
String responseBody,
|
||||
HttpRequest request
|
||||
) {
|
||||
private <T> T deserializeApiResponse(String responseBody, HttpRequest request) {
|
||||
try {
|
||||
if (request.getGenericType() != null) {
|
||||
JavaType javaType = objectMapper.getTypeFactory().constructParametricType(
|
||||
ApiResponse.class,
|
||||
objectMapper.getTypeFactory().constructType(request.getGenericType())
|
||||
ApiResponse.class, objectMapper.getTypeFactory().constructType(request.getGenericType())
|
||||
);
|
||||
return objectMapper.readValue(responseBody, javaType);
|
||||
} else {
|
||||
@ -427,10 +530,7 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
}
|
||||
}
|
||||
|
||||
private HttpStatusCodeException mapHttpStatusToException(
|
||||
int statusCode,
|
||||
String errorBody
|
||||
) {
|
||||
private HttpStatusCodeException mapHttpStatusToException(int statusCode, String errorBody) {
|
||||
String errorCode = "HTTP_" + statusCode;
|
||||
String defaultMessage = "Error en servicio externo: HTTP " + statusCode;
|
||||
String message = errorBody != null && !errorBody.isEmpty()
|
||||
|
||||
@ -8,6 +8,10 @@ public interface HttpClientUseCase {
|
||||
|
||||
<T> T execute(HttpRequest request);
|
||||
|
||||
<T, R> Either<T, R> executeEither(HttpRequest request);
|
||||
|
||||
<T, R> Either<List<T>, R> executeEitherList(HttpRequest request);
|
||||
|
||||
<T> ApiResponse<T> executeApiResponse(HttpRequest request);
|
||||
|
||||
<T> ApiResponse<List<T>> executeApiResponseList(HttpRequest request);
|
||||
|
||||
@ -6,7 +6,9 @@ public class RequestContext {
|
||||
|
||||
private RequestContext() {}
|
||||
|
||||
private static final String REQUEST_ID = "requestId";
|
||||
public static final String REQUEST_ID = "requestId";
|
||||
public static final String DEVICE = "device";
|
||||
public static final String DEVICE_SESSION_REFERENCE = "deviceSessionReference";
|
||||
|
||||
public static String getRequestId() {
|
||||
return MDC.get(REQUEST_ID);
|
||||
|
||||
@ -6,15 +6,88 @@ import jakarta.ws.rs.container.ContainerRequestFilter;
|
||||
import jakarta.ws.rs.container.ContainerResponseContext;
|
||||
import jakarta.ws.rs.container.ContainerResponseFilter;
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@Provider
|
||||
public class RequestIdFilter implements ContainerRequestFilter, ContainerResponseFilter {
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext requestContext) {
|
||||
RequestContext.setRequestId(UUID.randomUUID().toString().substring(0, 13));
|
||||
String requestId = requestContext.getHeaderString(RequestContext.DEVICE_SESSION_REFERENCE);
|
||||
|
||||
if (isEmpty(requestId)) {
|
||||
requestId = requestContext.getUriInfo()
|
||||
.getQueryParameters()
|
||||
.getFirst(RequestContext.DEVICE_SESSION_REFERENCE);
|
||||
}
|
||||
|
||||
if (isEmpty(requestId) && hasJsonBody(requestContext)) {
|
||||
requestId = extractRequestIdFromBody(requestContext);
|
||||
}
|
||||
|
||||
if (isEmpty(requestId)) {
|
||||
requestId = UUID.randomUUID().toString().substring(0, 13);
|
||||
}
|
||||
|
||||
RequestContext.setRequestId(requestId);
|
||||
}
|
||||
|
||||
private boolean isEmpty(String value) {
|
||||
return value == null || value.trim().isEmpty();
|
||||
}
|
||||
|
||||
private boolean hasJsonBody(ContainerRequestContext context) {
|
||||
try {
|
||||
String method = context.getMethod();
|
||||
String contentType = context.getHeaderString("Content-Type");
|
||||
|
||||
return ("POST".equals(method) || "PUT".equals(method))
|
||||
&& contentType != null
|
||||
&& contentType.contains("application/json");
|
||||
} catch (Exception e) {
|
||||
log.warn("La peticion no es un POST o PUT: {}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String extractRequestIdFromBody(ContainerRequestContext context) {
|
||||
try {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
context.getEntityStream().transferTo(buffer);
|
||||
byte[] bodyBytes = buffer.toByteArray();
|
||||
|
||||
context.setEntityStream(new ByteArrayInputStream(bodyBytes));
|
||||
|
||||
String bodyString = new String(bodyBytes, StandardCharsets.UTF_8);
|
||||
io.vertx.core.json.JsonObject jsonObject = new io.vertx.core.json.JsonObject(bodyString);
|
||||
|
||||
if (jsonObject.containsKey(RequestContext.DEVICE)) {
|
||||
io.vertx.core.json.JsonObject device = jsonObject.getJsonObject(RequestContext.DEVICE);
|
||||
|
||||
if (device.containsKey(RequestContext.DEVICE_SESSION_REFERENCE)) {
|
||||
return device.getString(RequestContext.DEVICE_SESSION_REFERENCE);
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonObject.containsKey(RequestContext.REQUEST_ID)) {
|
||||
return jsonObject.getString(RequestContext.REQUEST_ID);
|
||||
}
|
||||
|
||||
if (jsonObject.containsKey(RequestContext.DEVICE_SESSION_REFERENCE)) {
|
||||
return jsonObject.getString(RequestContext.DEVICE_SESSION_REFERENCE);
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
log.error("Error extrayendo el requestId del cuerpo de la peticion: {}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -22,6 +95,10 @@ public class RequestIdFilter implements ContainerRequestFilter, ContainerRespons
|
||||
ContainerRequestContext requestContext,
|
||||
ContainerResponseContext responseContext
|
||||
) {
|
||||
RequestContext.clear();
|
||||
try {
|
||||
RequestContext.clear();
|
||||
} catch (Exception e) {
|
||||
log.error("Error limpiando el filtro: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,4 +7,5 @@ public enum BankingProductType {
|
||||
BROKERED_PRODUCT,
|
||||
TERM_DEPOSIT_PRODUCT,
|
||||
MOBILE_PAYMENT,
|
||||
NETUNO
|
||||
}
|
||||
|
||||
@ -1,14 +1,10 @@
|
||||
package com.banesco.module.instruction.domain.model;
|
||||
|
||||
import com.banesco.common.domain.exception.HttpStatusCodeException;
|
||||
import com.banesco.common.domain.model.Identifier;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Builder
|
||||
@ -19,21 +15,12 @@ import java.util.Objects;
|
||||
public class Instruction {
|
||||
private InstructionIdentification instructionIdentifier; // Request JSON: "id"
|
||||
private String instructionDescription; // Request JSON: "signature"
|
||||
private InstructionPurposeType instructionPurposeType; // Request JSON: "channelOrigin" (BOLE)
|
||||
private String instructionPurposeType; // Request JSON: "channelOrigin" (BOLE)
|
||||
|
||||
public static Instruction fromResource(
|
||||
String paymentStatusId,
|
||||
String channelCode,
|
||||
String signatureIdentifier
|
||||
String channelCode
|
||||
) {
|
||||
boolean isChannelCodeValid = (Arrays.stream(
|
||||
InstructionPurposeType.values()
|
||||
).anyMatch(type -> Objects.equals(type.name(), channelCode)));
|
||||
|
||||
if(!isChannelCodeValid) {
|
||||
throw HttpStatusCodeException.badRequest("VDE02", "channelCode");
|
||||
}
|
||||
|
||||
return Instruction.builder()
|
||||
.instructionIdentifier(
|
||||
InstructionIdentification.builder()
|
||||
@ -45,8 +32,7 @@ public class Instruction {
|
||||
.identificationType(InstructionIdentificationType.INSTRUCTION_NUMBER)
|
||||
.build()
|
||||
)
|
||||
.instructionPurposeType(InstructionPurposeType.valueOf(channelCode))
|
||||
.instructionDescription(signatureIdentifier)
|
||||
.instructionPurposeType(channelCode)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
package com.banesco.module.instruction.domain.model;
|
||||
|
||||
public enum InstructionPurposeType {
|
||||
BOLE,
|
||||
BOL,
|
||||
}
|
||||
@ -35,8 +35,4 @@ public class PaymentStatus {
|
||||
private String uuidPasskey;
|
||||
private String dateCreate;
|
||||
private String dateModify;
|
||||
|
||||
private Long codError;
|
||||
private String mensajeError;
|
||||
private String constraintName;
|
||||
}
|
||||
@ -38,7 +38,8 @@ public class PaymentStatusClient implements PaymentStatusUseCase {
|
||||
PaymentStatusRequest params,
|
||||
Class<T> responseType
|
||||
) {
|
||||
String signatureIdentifier = serializationHelper.encodeBase64(params);
|
||||
String fintechId = params.getFintechId();
|
||||
String signatureIdentifier = getSignatureIdentifier(params);
|
||||
HttpRequest request = HttpRequest.forApiPrivateResponse(
|
||||
paymentStatusConfig.getUrl(),
|
||||
paymentStatusConfig.getStatusSuccess(),
|
||||
@ -46,14 +47,12 @@ public class PaymentStatusClient implements PaymentStatusUseCase {
|
||||
responseType
|
||||
)
|
||||
.withPathParams(Map.of("signatureIdentifier", signatureIdentifier))
|
||||
.withHeaders(Map.of("fintechId", params.getFintechId()))
|
||||
.withHeaders(Map.of("fintechId", fintechId))
|
||||
.withTimeout(
|
||||
paymentStatusConfig.getTimeout().getConnect(),
|
||||
paymentStatusConfig.getTimeout().getResponse()
|
||||
);
|
||||
|
||||
log.debug("Request configurado: {}", request);
|
||||
|
||||
try {
|
||||
ApiPrivateResponse<Either<T, ApiPrivateError>> response =
|
||||
httpClientUseCase.executeApiPrivateResponse(request);
|
||||
@ -63,7 +62,7 @@ public class PaymentStatusClient implements PaymentStatusUseCase {
|
||||
log.error(
|
||||
"API retorno exitoso pero con detalle vacio. Codigo: {}, Mensaje: {}",
|
||||
response.getEstatus(),
|
||||
response.getMensaje()
|
||||
response.getMensaje()
|
||||
);
|
||||
|
||||
throw ApiPrivateException.builder()
|
||||
@ -89,8 +88,8 @@ public class PaymentStatusClient implements PaymentStatusUseCase {
|
||||
throw ApiPrivateException.builder()
|
||||
.statusCode(response.getEstatus())
|
||||
.message((error.getCodError() != null)
|
||||
? error.getCodError() + ":" + error.getMensajeError()
|
||||
: "EMPTY_MESSAGE"
|
||||
? error.getCodError() + ":" + error.getMensajeError()
|
||||
: "EMPTY_MESSAGE"
|
||||
)
|
||||
.build();
|
||||
} catch (ApiPrivateException e) {
|
||||
@ -108,4 +107,23 @@ public class PaymentStatusClient implements PaymentStatusUseCase {
|
||||
throw HttpStatusCodeException.serviceUnavailable("503");
|
||||
}
|
||||
}
|
||||
|
||||
private String getSignatureIdentifier(PaymentStatusRequest params) {
|
||||
Map<String, Object> paymentStatusRequest = serializationHelper.toMap(params);
|
||||
String signature = serializationHelper.generateSignature(
|
||||
params.getId(), params.getChannelOrigin()
|
||||
);
|
||||
|
||||
paymentStatusRequest.put("signature", signature);
|
||||
|
||||
paymentStatusRequest.remove("fintechId");
|
||||
|
||||
String signatureIdentifier = serializationHelper.encodeBase64(paymentStatusRequest);
|
||||
|
||||
log.info("3. Firma generada: {}", signature);
|
||||
log.info("4. Parametros de la solicitud: {}", paymentStatusRequest);
|
||||
log.info("5. Solicitud final: {} -> {}", paymentStatusRequest, signatureIdentifier);
|
||||
|
||||
return signatureIdentifier;
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,7 @@ import com.banesco.module.service_issue_payment_status.domain.dto.request.Servic
|
||||
import com.banesco.module.service_issue_payment_status.domain.dto.response.ServiceIssuePaymentStatusResponse;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@ -28,27 +29,32 @@ public class ServiceIssuePaymentStatusService implements ServiceIssuePaymentStat
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<ServiceIssuePaymentStatusResponse> execute(
|
||||
public Response execute(
|
||||
ServiceIssuePaymentStatusRequest request
|
||||
) {
|
||||
log.info("Iniciando ejecucion para el id: {}", request.getId());
|
||||
|
||||
Response response;
|
||||
|
||||
try {
|
||||
return apiPrivate(request);
|
||||
} catch (ApiPrivateException e) {
|
||||
log.warn(
|
||||
"Excepcion de la api privada: {} -> {}",
|
||||
e.getStatusCode(),
|
||||
e.getMessage()
|
||||
ApiResponse<ServiceIssuePaymentStatusResponse> apiResponse = apiPrivate(request);
|
||||
|
||||
response = messageHelper.handleSuccess(
|
||||
apiResponse.getData(),
|
||||
apiResponse.getStatusResponse().getStatusCode()
|
||||
);
|
||||
throw HttpStatusCodeException.badRequest("400");
|
||||
} catch (ApiPrivateException e) {
|
||||
log.warn("Excepcion de la api privada: {} -> {}", e.getStatusCode(), e.getMessage());
|
||||
response = messageHelper.handleException(HttpStatusCodeException.badRequest("400"));
|
||||
} catch (HttpStatusCodeException e) {
|
||||
log.error("Excepcion HTTP del api privada: {} - {}", e.getStatusCode(), e.getErrorCode());
|
||||
throw e;
|
||||
response = messageHelper.handleException(e);
|
||||
} catch (Exception e) {
|
||||
log.error("Excepcion generica del api privada: {}", e.getMessage());
|
||||
throw e;
|
||||
response = messageHelper.handleGenericException(e);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private ApiResponse<ServiceIssuePaymentStatusResponse> apiPrivate(
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
package com.banesco.module.service_issue_payment_status.application.usecase;
|
||||
|
||||
import com.banesco.common.domain.model.ApiResponse;
|
||||
import com.banesco.module.service_issue_payment_status.domain.dto.request.ServiceIssuePaymentStatusRequest;
|
||||
import com.banesco.module.service_issue_payment_status.domain.dto.response.ServiceIssuePaymentStatusResponse;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
public interface ServiceIssuePaymentStatusUseCase {
|
||||
ApiResponse<ServiceIssuePaymentStatusResponse> execute(
|
||||
Response execute(
|
||||
ServiceIssuePaymentStatusRequest request
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,9 +1,18 @@
|
||||
package com.banesco.module.service_issue_payment_status.domain.dto.request;
|
||||
|
||||
import com.banesco.common.domain.model.Device;
|
||||
import com.banesco.common.infrastructure.context.RequestContext;
|
||||
import com.banesco.module.instruction.domain.model.Instruction;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Builder
|
||||
@ -17,8 +26,43 @@ public class ServiceIssuePaymentStatusRequest {
|
||||
private String appId;
|
||||
@NonNull
|
||||
private Instruction procedureRequest;
|
||||
@NonNull
|
||||
private Device device;
|
||||
|
||||
@JsonIgnore
|
||||
public String getId() {
|
||||
return getProcedureRequest().getInstructionIdentifier().getIdentification().getIdentifierValue();
|
||||
return procedureRequest
|
||||
.getInstructionIdentifier()
|
||||
.getIdentification()
|
||||
.getIdentifierValue();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getChannelCode() {
|
||||
return procedureRequest
|
||||
.getInstructionPurposeType();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Map<String, String> toParams() {
|
||||
return Map.ofEntries(
|
||||
entry("paymentStatusId", Objects.toString(getId(), "")),
|
||||
entry("channelCode", Objects.toString(getChannelCode(), ""))
|
||||
);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Map<String, String> toQueryString() {
|
||||
return Map.ofEntries(
|
||||
entry("appId", Objects.toString(getAppId(), "")),
|
||||
entry("customerReferenceFintechId", Objects.toString(getCustomerReferenceFintechId(), "")),
|
||||
entry("deviceType", Objects.toString(getDevice().getDeviceType(), "")),
|
||||
entry("deviceDescription", Objects.toString(getDevice().getDeviceDescription(), "")),
|
||||
entry("deviceIp", Objects.toString(getDevice().getDeviceIp(), "")),
|
||||
entry("deviceSessionReference", (!StringUtil.isNullOrEmpty(getDevice().getDeviceSessionReference()))
|
||||
? getDevice().getDeviceSessionReference()
|
||||
: RequestContext.getRequestId()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -23,8 +23,7 @@ public class ServicingIssueMapper {
|
||||
return PaymentStatusRequest.builder()
|
||||
.fintechId(request.getCustomerReferenceFintechId())
|
||||
.id(Long.valueOf(request.getId()))
|
||||
.channelOrigin(request.getProcedureRequest().getInstructionPurposeType().name())
|
||||
.signature(request.getProcedureRequest().getInstructionDescription())
|
||||
.channelOrigin(request.getChannelCode())
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -160,19 +159,25 @@ public class ServicingIssueMapper {
|
||||
}
|
||||
|
||||
return switch (codeStatusRequest.toUpperCase()) {
|
||||
case "ACT", "ACTIVO", "ACTIVA" -> TransactionStatusType.ACTIVE;
|
||||
case "PENDIENTE" -> TransactionStatusType.PENDING;
|
||||
case "EXITO", "EXITOSA", "COMPLETADO", "FINALIZADO" -> TransactionStatusType.COMPLETED;
|
||||
case "APROBADO", "CONFIRMADO" -> TransactionStatusType.CONFIRMED;
|
||||
case "APROBADO", "APROBADA" -> TransactionStatusType.APPROVED;
|
||||
case "CONF", "CONFIRMADO", "CONFIRMADA" -> TransactionStatusType.CONFIRMED;
|
||||
case "INICIADO" -> TransactionStatusType.INITIATED;
|
||||
case "EN_PROCESO", "PROCESANDO", "EN CURSO" -> TransactionStatusType.IN_PROGRESS;
|
||||
case "RECHAZADO", "FALLIDO" -> TransactionStatusType.REJECTED;
|
||||
case "RECH", "RECHAZADO", "FALLA", "FALLIDO", "RECHAZADA", "FALLIDA" -> TransactionStatusType.REJECTED;
|
||||
case "CANCELADO" -> TransactionStatusType.CANCELLED;
|
||||
case "SUSPENDIDO" -> TransactionStatusType.SUSPENDED;
|
||||
case "NOTIFICADO" -> TransactionStatusType.NOTIFIED;
|
||||
case "CONTABILIZADO" -> TransactionStatusType.BOOKED;
|
||||
case "EJECUTADO" -> TransactionStatusType.EXECUTED;
|
||||
case "EXP" -> TransactionStatusType.EXPIRED;
|
||||
case "ENVIADO" -> TransactionStatusType.SENT;
|
||||
case "EXP", "EXPIRADO", "EXPIRADA" -> TransactionStatusType.EXPIRED;
|
||||
case "ENVIADO", "ENVIADA" -> TransactionStatusType.SENT;
|
||||
case "RECIBIDO", "RECIBIDA" -> TransactionStatusType.RECEIVED;
|
||||
case "LEIDA" -> TransactionStatusType.READ;
|
||||
case "PROG", "PROGRAMADO", "PROGRAMADA" -> TransactionStatusType.PROGRAMED;
|
||||
case "TRANSATIP" -> TransactionStatusType.ATYPICAL_TRANSACTION;
|
||||
default -> TransactionStatusType.DEFAULT;
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
package com.banesco.module.service_issue_payment_status.infrastructure.resource;
|
||||
|
||||
import com.banesco.common.application.helper.MessageHelper;
|
||||
import com.banesco.common.domain.exception.HttpStatusCodeException;
|
||||
import com.banesco.common.domain.model.ApiResponse;
|
||||
import com.banesco.common.domain.model.Device;
|
||||
import com.banesco.common.domain.model.StatusResponse;
|
||||
import com.banesco.module.instruction.domain.model.Instruction;
|
||||
import com.banesco.module.service_issue_payment_status.application.usecase.ServiceIssuePaymentStatusUseCase;
|
||||
@ -31,19 +30,16 @@ import java.util.Objects;
|
||||
public class ServiceIssuePaymentStatusResource {
|
||||
|
||||
private final ServiceIssuePaymentStatusUseCase useCase;
|
||||
private final MessageHelper messageHelper;
|
||||
|
||||
@Inject
|
||||
public ServiceIssuePaymentStatusResource(
|
||||
MessageHelper messageHelper,
|
||||
ServiceIssuePaymentStatusUseCase useCase
|
||||
) {
|
||||
this.messageHelper = messageHelper;
|
||||
this.useCase = useCase;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/retrieve/{paymentStatusId}/{channelCode}/{signatureIdentifier}")
|
||||
@Path("/retrieve/{paymentStatusId}/{channelCode}")
|
||||
@Operation(
|
||||
summary = "Recuperar informacion de la transaccion",
|
||||
description = "Consulta de una trasanccion de pago por id de archivo"
|
||||
@ -312,34 +308,48 @@ public class ServiceIssuePaymentStatusResource {
|
||||
@Parameter(description = "Codigo del canal (BOL, BOLE)", required = true, example = "BOLE")
|
||||
String channelCode,
|
||||
|
||||
@PathParam("signatureIdentifier")
|
||||
@Parameter(description = "Firma del archivo", required = true, example = "add7c6375b8659a798a998258fb049b98119ea97d8116b95e1ee00cc9ffafa84")
|
||||
String signatureIdentifier,
|
||||
|
||||
@QueryParam("customerReferenceFintechId")
|
||||
@Parameter(description = "ID de la fintech", example = "pranical-test")
|
||||
String customerReferenceFintechId,
|
||||
|
||||
@QueryParam("appId")
|
||||
@Parameter(description = "ID de la aplicacion", example = "DANIAPP")
|
||||
String appId
|
||||
String appId,
|
||||
|
||||
@QueryParam("deviceType")
|
||||
@Parameter(description = "Tipo de dispositivo", example = "Mobile")
|
||||
String deviceType,
|
||||
|
||||
@QueryParam("deviceDescription")
|
||||
@Parameter(description = "Descripcion del dispositivo", example = "Xiaomi Note 11 PRO")
|
||||
String deviceDescription,
|
||||
|
||||
@QueryParam("deviceIp")
|
||||
@Parameter(description = "Direccion IP del dispositivo", example = "127.0.0.1")
|
||||
String deviceIp,
|
||||
|
||||
@QueryParam("deviceSessionReference")
|
||||
@Parameter(description = "Referencia de la peticion del dispositivo", example = "12345678901304")
|
||||
String deviceSessionReference
|
||||
) {
|
||||
log.info("Iniciando consulta para instruccion de archivo id: {}", paymentStatusId);
|
||||
|
||||
try {
|
||||
return Response.ok(useCase.execute(
|
||||
ServiceIssuePaymentStatusRequest.builder()
|
||||
.customerReferenceFintechId(Objects.toString(customerReferenceFintechId, ""))
|
||||
.appId(Objects.toString(appId, ""))
|
||||
.procedureRequest(Instruction.fromResource(
|
||||
paymentStatusId, channelCode, signatureIdentifier
|
||||
))
|
||||
.build()
|
||||
)).build();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
return messageHelper.handleException(e);
|
||||
} catch (Exception e) {
|
||||
return messageHelper.handleGenericException(e);
|
||||
}
|
||||
return useCase.execute(
|
||||
ServiceIssuePaymentStatusRequest.builder()
|
||||
.customerReferenceFintechId(Objects.toString(customerReferenceFintechId, ""))
|
||||
.appId(Objects.toString(appId, ""))
|
||||
.procedureRequest(Instruction.fromResource(
|
||||
paymentStatusId, channelCode
|
||||
))
|
||||
.device(
|
||||
Device.builder()
|
||||
.deviceType(deviceType)
|
||||
.deviceDescription(deviceDescription)
|
||||
.deviceIp(deviceIp)
|
||||
.deviceSessionReference(deviceSessionReference)
|
||||
.build()
|
||||
)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,7 @@ public enum TransactionStatusType {
|
||||
EXECUTED,
|
||||
CANCELLED,
|
||||
CONFIRMED,
|
||||
APPROVED,
|
||||
SUSPENDED,
|
||||
PENDING,
|
||||
COMPLETED,
|
||||
@ -15,4 +16,9 @@ public enum TransactionStatusType {
|
||||
REJECTED,
|
||||
EXPIRED,
|
||||
SENT,
|
||||
RECEIVED,
|
||||
ACTIVE,
|
||||
READ,
|
||||
PROGRAMED,
|
||||
ATYPICAL_TRANSACTION,
|
||||
}
|
||||
|
||||
@ -13,6 +13,6 @@ api:
|
||||
dom-service-issue-payment-status:
|
||||
messages:
|
||||
key: 'dom-service-issue-payment-status'
|
||||
content: '[{"backendCode":"200","httpCode":200,"statusCode":"200","description":"Operacion exitosa"},{"backendCode":"R404","httpCode":404,"statusCode":"404","description":"Datos de validacion no encontrado."},{"backendCode":"503","httpCode":503,"statusCode":"503","description":"Uso interno"},{"backendCode":"422","httpCode":422,"statusCode":"422","description":"Uso interno"},{"backendCode":"500","httpCode":500,"statusCode":"500","description":"Uso interno"},{"backendCode":"100","httpCode":503,"statusCode":"503","description":"VDR13 - OSB Disponible"},{"backendCode":"OSB-382505","httpCode":503,"statusCode":"503","description":"VDR13 - OSB Disponible"},{"backendCode":"OSB-380002","httpCode":503,"statusCode":"503","description":"VDR13 - OSB Disponible"},{"backendCode":"ERROR","httpCode":400,"statusCode":"400","description":"Uso interno"},{"backendCode":"400","httpCode":400,"statusCode":"400","description":"Uso interno"},{"backendCode":"401","httpCode":401,"statusCode":"401","description":"Uso interno"},{"backendCode":"403","httpCode":403,"statusCode":"403","description":"Uso interno"},{"backendCode":"404","httpCode":404,"statusCode":"404","description":"Uso interno"},{"backendCode":"default","httpCode":409,"statusCode":"409","description":"Conflicto"},{"backendCode":"424","httpCode":424,"statusCode":"424","description":"Error de dependencia"},{"backendCode":"VDE01","httpCode":400,"statusCode":"VDE01","description":"VDE01 - Error en dato de entrada obligatorio: %s"},{"backendCode":"VDE02","httpCode":400,"statusCode":"VDE02","description":"VDE02 - Error en valor permitido para campo: %s"},{"backend_code":"204","http_code":"200","status_code":"200","description":"Cliente sin productos","status":"ok"}]'
|
||||
content: '[{"backendCode":"200","httpCode":200,"statusCode":"200","description":"Operacion exitosa"},{"backendCode":"R404","httpCode":404,"statusCode":"404","description":"Datos de validacion no encontrado."},{"backendCode":"503","httpCode":503,"statusCode":"503","description":"Uso interno"},{"backendCode":"422","httpCode":422,"statusCode":"422","description":"Uso interno"},{"backendCode":"500","httpCode":500,"statusCode":"500","description":"Uso interno"},{"backendCode":"100","httpCode":503,"statusCode":"503","description":"VDR13 - OSB Disponible"},{"backendCode":"OSB-382505","httpCode":503,"statusCode":"503","description":"VDR13 - OSB Disponible"},{"backendCode":"OSB-380002","httpCode":503,"statusCode":"503","description":"VDR13 - OSB Disponible"},{"backendCode":"ERROR","httpCode":400,"statusCode":"400","description":"Uso interno"},{"backendCode":"400","httpCode":400,"statusCode":"400","description":"Uso interno"},{"backendCode":"401","httpCode":401,"statusCode":"401","description":"Uso interno"},{"backendCode":"403","httpCode":403,"statusCode":"403","description":"Uso interno"},{"backendCode":"404","httpCode":404,"statusCode":"404","description":"Uso interno"},{"backendCode":"default","httpCode":409,"statusCode":"409","description":"Conflicto"},{"backendCode":"424","httpCode":424,"statusCode":"424","description":"Error de dependencia"},{"backendCode":"VDE01","httpCode":400,"statusCode":"VDE01","description":"VDE01 - Error en dato de entrada obligatorio: %s"},{"backendCode":"VDE02","httpCode":400,"statusCode":"VDE02","description":"VDE02 - Error en valor permitido para campo: %s"},{"backendCode":"VRN02","httpCode":"204","statusCode":"VRN02","description":"Cliente sin productos"}]'
|
||||
rest-client:
|
||||
payment-status-by-id: '{"url":"http://10.135.193.156:8080/RequestPayment/notificationRequestPayment/v1/querys/getRequestPayStatusById/{signatureIdentifier}","timeout":{"connect":10000,"response":10000},"statusSuccess":"00"}'
|
||||
Loading…
x
Reference in New Issue
Block a user