update runner
This commit is contained in:
parent
9626a7d981
commit
362080a176
Binary file not shown.
@ -123,7 +123,7 @@ public class MessageHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (json == null || json.isEmpty()) {
|
if (json == null || json.isEmpty()) {
|
||||||
log.warn("No se encontró JSON de errores");
|
log.warn("No se encontro JSON de errores");
|
||||||
return createDefaultMappings();
|
return createDefaultMappings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,11 +138,11 @@ public class MessageHelper {
|
|||||||
result.put(mapping.getBackendCode(), mapping);
|
result.put(mapping.getBackendCode(), mapping);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.warn("Ignorando mapping sin backendCode válido: {}", mapping.getDescription());
|
log.warn("Ignorando mapping sin backendCode valido: {}", mapping.getDescription());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("Mappings de errores cargados exitosamente, total válidos: {}", result.size());
|
log.info("Mappings de errores cargados exitosamente, total validos: {}", result.size());
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error cargando mappings de errores: {}", e.getMessage());
|
log.error("Error cargando mappings de errores: {}", e.getMessage());
|
||||||
@ -153,7 +153,7 @@ public class MessageHelper {
|
|||||||
private String loadFromJsonFile() {
|
private String loadFromJsonFile() {
|
||||||
try (InputStream is = MessageHelper.class.getClassLoader().getResourceAsStream(ERROR_FILE_PATH)) {
|
try (InputStream is = MessageHelper.class.getClassLoader().getResourceAsStream(ERROR_FILE_PATH)) {
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
log.warn("No se encontró el archivo de errores: {}", ERROR_FILE_PATH);
|
log.warn("No se encontro el archivo de errores: {}", ERROR_FILE_PATH);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return new String(is.readAllBytes());
|
return new String(is.readAllBytes());
|
||||||
@ -184,7 +184,7 @@ public class MessageHelper {
|
|||||||
mapping.setBackendCode(SUCCESS_DEFAULT);
|
mapping.setBackendCode(SUCCESS_DEFAULT);
|
||||||
mapping.setHttpCode(200);
|
mapping.setHttpCode(200);
|
||||||
mapping.setStatusCode("200");
|
mapping.setStatusCode("200");
|
||||||
mapping.setDescription("Operación exitosa");
|
mapping.setDescription("Operacion exitosa");
|
||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,10 +3,10 @@ package com.banesco.common.application.service;
|
|||||||
import com.banesco.common.application.usecase.HttpClientUseCase;
|
import com.banesco.common.application.usecase.HttpClientUseCase;
|
||||||
import com.banesco.common.domain.exception.HttpApiResponseException;
|
import com.banesco.common.domain.exception.HttpApiResponseException;
|
||||||
import com.banesco.common.domain.exception.HttpStatusCodeException;
|
import com.banesco.common.domain.exception.HttpStatusCodeException;
|
||||||
import com.banesco.common.domain.model.ApiResponse;
|
import com.banesco.common.domain.model.*;
|
||||||
import com.banesco.common.domain.model.HttpRequest;
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JavaType;
|
import com.fasterxml.jackson.databind.JavaType;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
@ -15,6 +15,9 @@ import jakarta.ws.rs.core.MediaType;
|
|||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@ -31,43 +34,71 @@ public class HttpClientService implements HttpClientUseCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T execute(HttpRequest request) {
|
public <T> T execute(HttpRequest request) {
|
||||||
|
return executeInternal(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> ApiResponse<T> executeApiResponse(HttpRequest request) {
|
||||||
|
return executeInternal(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> ApiResponse<List<T>> executeApiResponseList(
|
||||||
|
HttpRequest request
|
||||||
|
) {
|
||||||
|
return executeInternal(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> ApiPrivateResponse<Either<T, ApiPrivateError>> executeApiPrivateResponse(
|
||||||
|
HttpRequest request
|
||||||
|
) {
|
||||||
|
return executeInternal(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> ApiPrivateResponse<Either<List<T>, ApiPrivateError>> executeApiPrivateResponseList(
|
||||||
|
HttpRequest request
|
||||||
|
) {
|
||||||
|
return executeInternal(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> T executeInternal(HttpRequest request) {
|
||||||
String finalUrl = buildFinalUrl(request);
|
String finalUrl = buildFinalUrl(request);
|
||||||
|
|
||||||
log.info("URL final: {}", finalUrl);
|
if (request.isLogRequestBody()) {
|
||||||
|
log.info("URL final: {}", finalUrl);
|
||||||
|
|
||||||
if (request.getHeaders() != null) {
|
if (request.getHeaders() != null && !request.getHeaders().isEmpty()) {
|
||||||
log.info("Headers request: {}", request.getHeaders());
|
log.info("Headers: {}", request.getHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.getQueryParams() != null) {
|
if (request.getQueryParams() != null && !request.getQueryParams().isEmpty()) {
|
||||||
log.info("Query params request: {}", request.getQueryParams());
|
log.info("Query params: {}", request.getQueryParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.getBody() != null) {
|
if (request.getBody() != null) {
|
||||||
log.info("Body request: {}", request.getBody());
|
log.info("Body: {}", request.getBody());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Client client = createClient(request.getConnectTimeout(), request.getReadTimeout())) {
|
try (Client client = createClient(request.getConnectTimeout(), request.getReadTimeout())) {
|
||||||
WebTarget target = client.target(finalUrl);
|
WebTarget target = client.target(finalUrl);
|
||||||
|
|
||||||
Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON);
|
Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
if (request.getHeaders() != null && !request.getHeaders().isEmpty()) {
|
if (request.getHeaders() != null) {
|
||||||
for (Map.Entry<String, String> entry : request.getHeaders().entrySet()) {
|
request.getHeaders().forEach(builder::header);
|
||||||
builder.header(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Response response = buildRequest(builder, request);
|
Response response = buildRequest(builder, request);
|
||||||
|
|
||||||
return handleResponse(request, response);
|
return handleResponse(request, response);
|
||||||
} catch (HttpStatusCodeException | HttpApiResponseException e) {
|
} catch (HttpStatusCodeException | HttpApiResponseException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error de conexión {}: {}", request.getMethod(), e.getMessage());
|
log.error("Error de conexion {}: {}", request.getMethod(), e.getMessage());
|
||||||
throw HttpStatusCodeException.serviceUnavailable(
|
throw HttpStatusCodeException.serviceUnavailable(
|
||||||
"503",
|
"503",
|
||||||
"Error de conexión con el servicio externo: " + e.getMessage()
|
"Error de conexion con el servicio externo: " + e.getMessage()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,18 +107,13 @@ public class HttpClientService implements HttpClientUseCase {
|
|||||||
String finalUrl = request.getUrl();
|
String finalUrl = request.getUrl();
|
||||||
|
|
||||||
if (request.getPathParams() != null && !request.getPathParams().isEmpty()) {
|
if (request.getPathParams() != null && !request.getPathParams().isEmpty()) {
|
||||||
log.debug("PathParams antes de reemplazar: {}", request.getPathParams());
|
|
||||||
log.debug("URL original: {}", finalUrl);
|
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : request.getPathParams().entrySet()) {
|
for (Map.Entry<String, String> entry : request.getPathParams().entrySet()) {
|
||||||
String placeholder = "{" + entry.getKey() + "}";
|
String placeholder = "{" + entry.getKey() + "}";
|
||||||
finalUrl = finalUrl.replace(placeholder, entry.getValue());
|
finalUrl = finalUrl.replace(placeholder, entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finalUrl = appendQueryParams(finalUrl, request.getQueryParams());
|
return appendQueryParams(finalUrl, request.getQueryParams());
|
||||||
|
|
||||||
return finalUrl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String appendQueryParams(String url, Map<String, String> queryParams) {
|
private String appendQueryParams(String url, Map<String, String> queryParams) {
|
||||||
@ -96,7 +122,6 @@ public class HttpClientService implements HttpClientUseCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder urlBuilder = new StringBuilder(url);
|
StringBuilder urlBuilder = new StringBuilder(url);
|
||||||
|
|
||||||
boolean firstParam = !url.contains("?");
|
boolean firstParam = !url.contains("?");
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : queryParams.entrySet()) {
|
for (Map.Entry<String, String> entry : queryParams.entrySet()) {
|
||||||
@ -119,11 +144,7 @@ public class HttpClientService implements HttpClientUseCase {
|
|||||||
Invocation.Builder builder,
|
Invocation.Builder builder,
|
||||||
HttpRequest request
|
HttpRequest request
|
||||||
) {
|
) {
|
||||||
log.info(
|
log.info("Metodo HTTP: {}", request.getMethod().name());
|
||||||
"Método HTTP: {}, Headers enviados: {}",
|
|
||||||
request.getMethod().name(),
|
|
||||||
request.getHeaders()
|
|
||||||
);
|
|
||||||
|
|
||||||
return switch (request.getMethod()) {
|
return switch (request.getMethod()) {
|
||||||
case GET -> builder.get();
|
case GET -> builder.get();
|
||||||
@ -133,14 +154,11 @@ public class HttpClientService implements HttpClientUseCase {
|
|||||||
case PATCH -> builder.method("PATCH", Entity.entity(request.getBody(), MediaType.APPLICATION_JSON));
|
case PATCH -> builder.method("PATCH", Entity.entity(request.getBody(), MediaType.APPLICATION_JSON));
|
||||||
case HEAD -> builder.head();
|
case HEAD -> builder.head();
|
||||||
case OPTIONS -> builder.options();
|
case OPTIONS -> builder.options();
|
||||||
default -> throw new IllegalArgumentException("Método HTTP no soportado: " + request.getMethod());
|
default -> throw new IllegalArgumentException("Metodo HTTP no soportado: " + request.getMethod());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private Client createClient(
|
private Client createClient(int connectTimeout, int readTimeout) {
|
||||||
int connectTimeout,
|
|
||||||
int readTimeout
|
|
||||||
) {
|
|
||||||
return ClientBuilder.newBuilder()
|
return ClientBuilder.newBuilder()
|
||||||
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
|
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
|
||||||
.readTimeout(readTimeout, TimeUnit.MILLISECONDS)
|
.readTimeout(readTimeout, TimeUnit.MILLISECONDS)
|
||||||
@ -157,7 +175,9 @@ public class HttpClientService implements HttpClientUseCase {
|
|||||||
try (response) {
|
try (response) {
|
||||||
String responseBody = response.readEntity(String.class);
|
String responseBody = response.readEntity(String.class);
|
||||||
|
|
||||||
log.info("Respuesta Cuerpo: {}", responseBody);
|
if (request.isLogResponseBody()) {
|
||||||
|
log.info("Respuesta Cuerpo: {}", responseBody);
|
||||||
|
}
|
||||||
|
|
||||||
if (statusCode >= 200 && statusCode < 300) {
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
if (request.getResponseType() == Void.class || request.getResponseType() == void.class) {
|
if (request.getResponseType() == Void.class || request.getResponseType() == void.class) {
|
||||||
@ -195,8 +215,7 @@ public class HttpClientService implements HttpClientUseCase {
|
|||||||
e.getMessage()
|
e.getMessage()
|
||||||
);
|
);
|
||||||
throw HttpStatusCodeException.internalServer(
|
throw HttpStatusCodeException.internalServer(
|
||||||
"500",
|
"500", "Error procesando respuesta del servicio externo: " + e.getMessage()
|
||||||
"Error procesando respuesta del servicio externo: " + e.getMessage()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,26 +224,166 @@ public class HttpClientService implements HttpClientUseCase {
|
|||||||
HttpRequest request,
|
HttpRequest request,
|
||||||
String responseBody
|
String responseBody
|
||||||
) throws JsonProcessingException {
|
) throws JsonProcessingException {
|
||||||
|
if (request.isApiPrivateResponse() && request.isEitherResponse()) {
|
||||||
|
return handleApiPrivateResponseWithEither(request, responseBody);
|
||||||
|
}
|
||||||
|
|
||||||
T result;
|
T result;
|
||||||
|
|
||||||
if (request.getResponseType() == ApiResponse.class) {
|
if (request.getResponseType() == ApiResponse.class) {
|
||||||
result = deserializeApiResponse(responseBody, request);
|
result = 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);
|
||||||
|
} else if (request.getGenericType() != null) {
|
||||||
|
JavaType javaType = objectMapper.getTypeFactory().constructParametricType(
|
||||||
|
request.getResponseType(), objectMapper.getTypeFactory().constructType(request.getGenericType())
|
||||||
|
);
|
||||||
|
result = objectMapper.readValue(responseBody, javaType);
|
||||||
} else {
|
} else {
|
||||||
result = (request.getGenericType() != null) ? objectMapper.readValue(
|
result = objectMapper.readValue(
|
||||||
responseBody,
|
responseBody, objectMapper.getTypeFactory().constructType(request.getResponseType())
|
||||||
objectMapper.getTypeFactory().constructParametricType(
|
|
||||||
request.getResponseType(),
|
|
||||||
objectMapper.getTypeFactory().constructType(request.getGenericType())
|
|
||||||
)
|
|
||||||
) : objectMapper.readValue(
|
|
||||||
responseBody,
|
|
||||||
objectMapper.getTypeFactory().constructType(request.getResponseType())
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
JsonNode detailNode = rootNode.get("detalle");
|
||||||
|
|
||||||
|
if (request.getStatusSuccess().equals(status)) {
|
||||||
|
return handleSuccessResponse(request, status, message, detailNode);
|
||||||
|
} else {
|
||||||
|
return handleErrorResponse(status, message, detailNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private <T> T handleSuccessResponse(
|
||||||
|
HttpRequest request,
|
||||||
|
String status,
|
||||||
|
String message,
|
||||||
|
JsonNode detailNode
|
||||||
|
) {
|
||||||
|
Object successData;
|
||||||
|
|
||||||
|
if (request.isListResponse()) {
|
||||||
|
successData = handleListSuccess(request, detailNode);
|
||||||
|
ApiPrivateResponse<Either<List<Object>, ApiPrivateError>> response = new ApiPrivateResponse<>();
|
||||||
|
|
||||||
|
response.setEstatus(status);
|
||||||
|
response.setMensaje(message);
|
||||||
|
response.setDetalle(Either.left((List<Object>) successData));
|
||||||
|
return (T) response;
|
||||||
|
} else {
|
||||||
|
successData = handleObjectSuccess(request, detailNode);
|
||||||
|
ApiPrivateResponse<Either<Object, ApiPrivateError>> response = new ApiPrivateResponse<>();
|
||||||
|
|
||||||
|
response.setEstatus(status);
|
||||||
|
response.setMensaje(message);
|
||||||
|
response.setDetalle(Either.left(successData));
|
||||||
|
return (T) response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object handleListSuccess(
|
||||||
|
HttpRequest request,
|
||||||
|
JsonNode detailNode
|
||||||
|
) {
|
||||||
|
Class<?> elementType = getElementTypeFromRequest(request);
|
||||||
|
JavaType listType = objectMapper.getTypeFactory().constructCollectionType(List.class, elementType);
|
||||||
|
|
||||||
|
if (detailNode != null && !detailNode.isNull()) {
|
||||||
|
return objectMapper.convertValue(detailNode, listType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object handleObjectSuccess(
|
||||||
|
HttpRequest request,
|
||||||
|
JsonNode detailNode
|
||||||
|
) {
|
||||||
|
Class<?> elementType = getElementTypeFromRequest(request);
|
||||||
|
|
||||||
|
if (detailNode != null && !detailNode.isNull()) {
|
||||||
|
return objectMapper.convertValue(detailNode, elementType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private <T> T handleErrorResponse(
|
||||||
|
String status,
|
||||||
|
String message,
|
||||||
|
JsonNode detailNode
|
||||||
|
) {
|
||||||
|
ApiPrivateError error = buildApiPrivateError(detailNode, message);
|
||||||
|
ApiPrivateResponse<Either<Object, ApiPrivateError>> response = new ApiPrivateResponse<>();
|
||||||
|
|
||||||
|
response.setEstatus(status);
|
||||||
|
response.setMensaje(message);
|
||||||
|
response.setDetalle(Either.right(error));
|
||||||
|
|
||||||
|
return (T) response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApiPrivateError buildApiPrivateError(
|
||||||
|
JsonNode detailNode,
|
||||||
|
String message
|
||||||
|
) {
|
||||||
|
if (detailNode != null && !detailNode.isNull()) {
|
||||||
|
try {
|
||||||
|
return objectMapper.convertValue(detailNode, ApiPrivateError.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Cannot map detail to ApiPrivateError, creating default error. Detail: {}", detailNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ApiPrivateError.builder()
|
||||||
|
.codError(null)
|
||||||
|
.mensajeError(message)
|
||||||
|
.constraintName(null)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Class<?> getElementTypeFromRequest(HttpRequest request) {
|
||||||
|
if (request.getGenericType() != null) {
|
||||||
|
return request.getGenericType();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.getComplexType() instanceof ParameterizedType pt) {
|
||||||
|
Type[] typeArgs = pt.getActualTypeArguments();
|
||||||
|
|
||||||
|
if (typeArgs.length > 0) {
|
||||||
|
Type firstArg = typeArgs[0];
|
||||||
|
|
||||||
|
if (firstArg instanceof ParameterizedType innerPt) {
|
||||||
|
Type[] innerArgs = innerPt.getActualTypeArguments();
|
||||||
|
|
||||||
|
if (innerArgs.length > 0 && innerArgs[0] instanceof Class<?> innerClass) {
|
||||||
|
return innerClass;
|
||||||
|
}
|
||||||
|
} else if (firstArg instanceof Class<?> elementClass) {
|
||||||
|
return elementClass;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.warn("No se pudo determinar el elementType del request, usando Object.class");
|
||||||
|
return Object.class;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <T> T deserializeApiResponse(
|
private <T> T deserializeApiResponse(
|
||||||
String responseBody,
|
String responseBody,
|
||||||
@ -243,14 +402,12 @@ public class HttpClientService implements HttpClientUseCase {
|
|||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
log.error("Error deserializando respuesta JSON: {}", e.getMessage());
|
log.error("Error deserializando respuesta JSON: {}", e.getMessage());
|
||||||
throw HttpStatusCodeException.internalServer(
|
throw HttpStatusCodeException.internalServer(
|
||||||
"500",
|
"500", "Error deserializando respuesta JSON: " + e.getMessage()
|
||||||
"Error deserializando respuesta JSON: " + e.getMessage()
|
|
||||||
);
|
);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error desconocido al deserializar respuesta: {}", e.getMessage());
|
log.error("Error desconocido al deserializar respuesta: {}", e.getMessage());
|
||||||
throw HttpStatusCodeException.internalServer(
|
throw HttpStatusCodeException.internalServer(
|
||||||
"500",
|
"500", "Error desconocido al deserializar respuesta: " + e.getMessage()
|
||||||
"Error desconocido al deserializar respuesta: " + e.getMessage()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,18 @@
|
|||||||
package com.banesco.common.application.usecase;
|
package com.banesco.common.application.usecase;
|
||||||
|
|
||||||
import com.banesco.common.domain.model.HttpRequest;
|
import com.banesco.common.domain.model.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface HttpClientUseCase {
|
public interface HttpClientUseCase {
|
||||||
|
|
||||||
<T> T execute(HttpRequest request);
|
<T> T execute(HttpRequest request);
|
||||||
|
|
||||||
|
<T> ApiResponse<T> executeApiResponse(HttpRequest request);
|
||||||
|
|
||||||
|
<T> ApiResponse<List<T>> executeApiResponseList(HttpRequest request);
|
||||||
|
|
||||||
|
<T> ApiPrivateResponse<Either<T, ApiPrivateError>> executeApiPrivateResponse(HttpRequest request);
|
||||||
|
|
||||||
|
<T> ApiPrivateResponse<Either<List<T>, ApiPrivateError>> executeApiPrivateResponseList(HttpRequest request);
|
||||||
}
|
}
|
||||||
@ -15,7 +15,7 @@ public class ApiPrivateException extends RuntimeException {
|
|||||||
String statusCode,
|
String statusCode,
|
||||||
String message
|
String message
|
||||||
) {
|
) {
|
||||||
super(message != null ? message : "Operación de negocio fallida");
|
super(message != null ? message : "Operacion de negocio fallida");
|
||||||
this.statusCode = statusCode;
|
this.statusCode = statusCode;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.banesco.common.domain.model;
|
||||||
|
|
||||||
|
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RegisterForReflection
|
||||||
|
public class ApiPrivateError {
|
||||||
|
private Long codError;
|
||||||
|
private String mensajeError;
|
||||||
|
private String constraintName;
|
||||||
|
}
|
||||||
33
src/main/java/com/banesco/common/domain/model/Either.java
Normal file
33
src/main/java/com/banesco/common/domain/model/Either.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.banesco.common.domain.model;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class Either<L, R> {
|
||||||
|
private final L left;
|
||||||
|
private final R right;
|
||||||
|
|
||||||
|
private final boolean leftFlag;
|
||||||
|
|
||||||
|
private Either(L left, R right, boolean leftFlag) {
|
||||||
|
this.left = left;
|
||||||
|
this.right = right;
|
||||||
|
this.leftFlag = leftFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <L, R> Either<L, R> left(L left) {
|
||||||
|
return new Either<>(left, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <L, R> Either<L, R> right(R right) {
|
||||||
|
return new Either<>(null, right, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLeft() {
|
||||||
|
return leftFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRight() {
|
||||||
|
return !leftFlag;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ package com.banesco.common.domain.model;
|
|||||||
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ -23,6 +24,24 @@ public class HttpRequest {
|
|||||||
|
|
||||||
private Class<?> genericType;
|
private Class<?> genericType;
|
||||||
|
|
||||||
|
private Type complexType;
|
||||||
|
|
||||||
|
private Class<?> errorType;
|
||||||
|
|
||||||
|
private String statusSuccess;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private boolean eitherResponse = false;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private boolean apiPrivateResponse = false;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private boolean apiResponse = false;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private boolean listResponse = false;
|
||||||
|
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private int connectTimeout = 5000;
|
private int connectTimeout = 5000;
|
||||||
|
|
||||||
@ -32,6 +51,172 @@ public class HttpRequest {
|
|||||||
@Builder.Default
|
@Builder.Default
|
||||||
private boolean returnFullResponse = false;
|
private boolean returnFullResponse = false;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private boolean logRequestBody = true;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private boolean logResponseBody = true;
|
||||||
|
|
||||||
|
public static <T> HttpRequest forApiResponse(
|
||||||
|
String url,
|
||||||
|
HttpMethod method,
|
||||||
|
Class<T> dataType
|
||||||
|
) {
|
||||||
|
return HttpRequest.builder()
|
||||||
|
.url(url)
|
||||||
|
.method(method)
|
||||||
|
.responseType(ApiResponse.class)
|
||||||
|
.genericType(dataType)
|
||||||
|
.apiResponse(true)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> HttpRequest forApiResponseList(
|
||||||
|
String url,
|
||||||
|
HttpMethod method,
|
||||||
|
Class<T> elementType
|
||||||
|
) {
|
||||||
|
return HttpRequest.builder()
|
||||||
|
.url(url)
|
||||||
|
.method(method)
|
||||||
|
.responseType(ApiResponse.class)
|
||||||
|
.complexType(TypeBuilder.listOf(elementType))
|
||||||
|
.apiResponse(true)
|
||||||
|
.listResponse(true)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> HttpRequest forApiPrivateResponse(
|
||||||
|
String url,
|
||||||
|
String statusSuccess,
|
||||||
|
HttpMethod method,
|
||||||
|
Class<T> successType
|
||||||
|
) {
|
||||||
|
return HttpRequest.builder()
|
||||||
|
.url(url)
|
||||||
|
.method(method)
|
||||||
|
.responseType(ApiPrivateResponse.class)
|
||||||
|
.complexType(TypeBuilder.parametricType(
|
||||||
|
Either.class,
|
||||||
|
successType,
|
||||||
|
ApiPrivateError.class
|
||||||
|
))
|
||||||
|
.apiPrivateResponse(true)
|
||||||
|
.eitherResponse(true)
|
||||||
|
.errorType(ApiPrivateError.class)
|
||||||
|
.statusSuccess(statusSuccess)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> HttpRequest forApiPrivateResponseList(
|
||||||
|
String url,
|
||||||
|
String statusSuccess,
|
||||||
|
HttpMethod method,
|
||||||
|
Class<T> elementType
|
||||||
|
) {
|
||||||
|
return HttpRequest.builder()
|
||||||
|
.url(url)
|
||||||
|
.method(method)
|
||||||
|
.responseType(ApiPrivateResponse.class)
|
||||||
|
.complexType(TypeBuilder.parametricType(
|
||||||
|
Either.class,
|
||||||
|
TypeBuilder.listOf(elementType),
|
||||||
|
ApiPrivateError.class
|
||||||
|
))
|
||||||
|
.apiPrivateResponse(true)
|
||||||
|
.eitherResponse(true)
|
||||||
|
.listResponse(true)
|
||||||
|
.errorType(ApiPrivateError.class)
|
||||||
|
.statusSuccess(statusSuccess)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> HttpRequest forDirectResponse(
|
||||||
|
String url,
|
||||||
|
HttpMethod method,
|
||||||
|
Class<T> responseType
|
||||||
|
) {
|
||||||
|
return HttpRequest.builder()
|
||||||
|
.url(url)
|
||||||
|
.method(method)
|
||||||
|
.responseType(responseType)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, U> HttpRequest forGenericResponse(
|
||||||
|
String url,
|
||||||
|
HttpMethod method,
|
||||||
|
Class<T> rawType,
|
||||||
|
Class<U> genericType
|
||||||
|
) {
|
||||||
|
return HttpRequest.builder()
|
||||||
|
.url(url)
|
||||||
|
.method(method)
|
||||||
|
.responseType(rawType)
|
||||||
|
.complexType(TypeBuilder.parametricType(rawType, genericType))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpRequest withHeaders(Map<String, String> headers) {
|
||||||
|
this.headers = headers;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpRequest withQueryParams(Map<String, String> queryParams) {
|
||||||
|
this.queryParams = queryParams;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpRequest withPathParams(Map<String, String> pathParams) {
|
||||||
|
this.pathParams = pathParams;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpRequest withBody(Object body) {
|
||||||
|
this.body = body;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpRequest withTimeout(int connectTimeout, int readTimeout) {
|
||||||
|
this.connectTimeout = connectTimeout;
|
||||||
|
this.readTimeout = readTimeout;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpRequest disableRequestLogging() {
|
||||||
|
this.logRequestBody = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpRequest disableResponseLogging() {
|
||||||
|
this.logResponseBody = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseType getExpectedResponseType() {
|
||||||
|
if (apiPrivateResponse && eitherResponse) {
|
||||||
|
return listResponse ? ResponseType.API_PRIVATE_WITH_EITHER_LIST : ResponseType.API_PRIVATE_WITH_EITHER;
|
||||||
|
} else if (apiResponse) {
|
||||||
|
return listResponse ? ResponseType.API_RESPONSE_LIST : ResponseType.API_RESPONSE;
|
||||||
|
} else if (complexType != null) {
|
||||||
|
return ResponseType.COMPLEX_TYPE;
|
||||||
|
} else if (genericType != null) {
|
||||||
|
return ResponseType.GENERIC_TYPE;
|
||||||
|
} else {
|
||||||
|
return ResponseType.DIRECT_TYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ResponseType {
|
||||||
|
API_RESPONSE,
|
||||||
|
API_RESPONSE_LIST,
|
||||||
|
API_PRIVATE_WITH_EITHER,
|
||||||
|
API_PRIVATE_WITH_EITHER_LIST,
|
||||||
|
GENERIC_TYPE,
|
||||||
|
COMPLEX_TYPE,
|
||||||
|
DIRECT_TYPE
|
||||||
|
}
|
||||||
|
|
||||||
public enum HttpMethod {
|
public enum HttpMethod {
|
||||||
GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
|
GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,67 @@
|
|||||||
|
package com.banesco.common.domain.model;
|
||||||
|
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
public class TypeBuilder {
|
||||||
|
|
||||||
|
private TypeBuilder() {}
|
||||||
|
|
||||||
|
public static Type listOf(Class<?> elementType) {
|
||||||
|
return new ParameterizedType() {
|
||||||
|
@Override
|
||||||
|
public Type[] getActualTypeArguments() {
|
||||||
|
return new Type[]{elementType};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type getRawType() {
|
||||||
|
return java.util.List.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type getOwnerType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Type parametricType(Class<?> rawType, Type... typeArguments) {
|
||||||
|
return new ParameterizedType() {
|
||||||
|
@Override
|
||||||
|
public Type[] getActualTypeArguments() {
|
||||||
|
return typeArguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type getRawType() {
|
||||||
|
return rawType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type getOwnerType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Type apiPrivateResponseWithEither(Class<?> successType, Class<?> errorType) {
|
||||||
|
Type eitherType = parametricType(Either.class, successType, errorType);
|
||||||
|
return parametricType(ApiPrivateResponse.class, eitherType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Type apiPrivateResponseWithListEither(Class<?> successType, Class<?> errorType) {
|
||||||
|
Type listType = listOf(successType);
|
||||||
|
Type eitherType = parametricType(Either.class, listType, errorType);
|
||||||
|
return parametricType(ApiPrivateResponse.class, eitherType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Type apiResponseType(Class<?> dataType) {
|
||||||
|
return parametricType(ApiResponse.class, dataType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Type apiResponseListType(Class<?> elementType) {
|
||||||
|
Type listType = listOf(elementType);
|
||||||
|
return parametricType(ApiResponse.class, listType);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -46,15 +46,15 @@ public class RestClientConfig {
|
|||||||
log.info("Configurando {}: {}", fullConfigName, json);
|
log.info("Configurando {}: {}", fullConfigName, json);
|
||||||
|
|
||||||
if (json == null || json.trim().isEmpty()) {
|
if (json == null || json.trim().isEmpty()) {
|
||||||
throw new IllegalStateException("Configuración no encontrada para: " + fullConfigName);
|
throw new IllegalStateException("Configuracion no encontrada para: " + fullConfigName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> configMap = objectMapper.readValue(json, new TypeReference<>() {});
|
Map<String, Object> configMap = objectMapper.readValue(json, new TypeReference<>() {});
|
||||||
return objectMapper.convertValue(configMap, configType);
|
return objectMapper.convertValue(configMap, configType);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new IllegalArgumentException("Formato JSON inválido para " + configName + ": " + e.getMessage(), e);
|
throw new IllegalArgumentException("Formato JSON invalido para " + configName + ": " + e.getMessage(), e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalStateException("Error cargando configuración del servicio " + configName + ": " + e.getMessage(), e);
|
throw new IllegalStateException("Error cargando configuracion del servicio " + configName + ": " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,10 +1,9 @@
|
|||||||
package com.banesco.module.payment_status.application.usecase;
|
package com.banesco.module.payment_status.application.usecase;
|
||||||
|
|
||||||
import com.banesco.module.payment_status.domain.dto.request.PaymentStatusRequest;
|
import com.banesco.module.payment_status.domain.dto.request.PaymentStatusRequest;
|
||||||
import com.banesco.common.domain.model.ApiPrivateResponse;
|
|
||||||
|
|
||||||
public interface PaymentStatusUseCase {
|
public interface PaymentStatusUseCase {
|
||||||
<T> ApiPrivateResponse<T> execute(
|
<T> T execute(
|
||||||
PaymentStatusRequest params,
|
PaymentStatusRequest params,
|
||||||
Class<T> responseType
|
Class<T> responseType
|
||||||
);
|
);
|
||||||
|
|||||||
@ -8,13 +8,11 @@ import com.banesco.common.domain.model.*;
|
|||||||
import com.banesco.common.infrastructure.config.RestClientConfig;
|
import com.banesco.common.infrastructure.config.RestClientConfig;
|
||||||
import com.banesco.module.payment_status.application.usecase.PaymentStatusUseCase;
|
import com.banesco.module.payment_status.application.usecase.PaymentStatusUseCase;
|
||||||
import com.banesco.module.payment_status.domain.dto.request.PaymentStatusRequest;
|
import com.banesco.module.payment_status.domain.dto.request.PaymentStatusRequest;
|
||||||
import com.banesco.module.payment_status.domain.model.PaymentStatus;
|
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
@ -32,57 +30,40 @@ public class PaymentStatusClient implements PaymentStatusUseCase {
|
|||||||
this.serializationHelper = serializationHelper;
|
this.serializationHelper = serializationHelper;
|
||||||
this.httpClientUseCase = httpClientUseCase;
|
this.httpClientUseCase = httpClientUseCase;
|
||||||
this.paymentStatusConfig = restClientConfig.getPaymentStatusConfig();
|
this.paymentStatusConfig = restClientConfig.getPaymentStatusConfig();
|
||||||
log.info("Configuración cargada para payment-status: {}", paymentStatusConfig);
|
log.info("Configuracion cargada para payment-status: {}", paymentStatusConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> ApiPrivateResponse<T> execute(
|
public <T> T execute(
|
||||||
PaymentStatusRequest params,
|
PaymentStatusRequest params,
|
||||||
Class<T> responseType
|
Class<T> responseType
|
||||||
) {
|
) {
|
||||||
String signatureIdentifier = serializationHelper.encodeBase64(params);
|
String signatureIdentifier = serializationHelper.encodeBase64(params);
|
||||||
HttpRequest request = HttpRequest.builder()
|
HttpRequest request = HttpRequest.forApiPrivateResponse(
|
||||||
.url(paymentStatusConfig.getUrl())
|
paymentStatusConfig.getUrl(),
|
||||||
.method(HttpRequest.HttpMethod.GET)
|
paymentStatusConfig.getStatusSuccess(),
|
||||||
.pathParams(Map.of("signatureIdentifier", signatureIdentifier))
|
HttpRequest.HttpMethod.GET,
|
||||||
.headers(Map.of("fintechId", params.getFintechId()))
|
responseType
|
||||||
.responseType(ApiPrivateResponse.class)
|
)
|
||||||
.genericType(responseType)
|
.withPathParams(Map.of("signatureIdentifier", signatureIdentifier))
|
||||||
.connectTimeout(paymentStatusConfig.getTimeout().getConnect())
|
.withHeaders(Map.of("fintechId", params.getFintechId()))
|
||||||
.readTimeout(paymentStatusConfig.getTimeout().getResponse())
|
.withTimeout(
|
||||||
.build();
|
paymentStatusConfig.getTimeout().getConnect(),
|
||||||
|
paymentStatusConfig.getTimeout().getResponse()
|
||||||
|
);
|
||||||
|
|
||||||
log.debug("Request configurado: {}", request);
|
log.debug("Request configurado: {}", request);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ApiPrivateResponse<T> response = httpClientUseCase.execute(request);
|
ApiPrivateResponse<Either<T, ApiPrivateError>> response =
|
||||||
boolean isSuccess = paymentStatusConfig.getStatusSuccess().equals(response.getEstatus());
|
httpClientUseCase.executeApiPrivateResponse(request);
|
||||||
|
Either<T, ApiPrivateError> detail = response.getDetalle();
|
||||||
log.info("Respuesta recibida: {}, estatus: {} -> {}", isSuccess, response.getEstatus(), response.getMensaje());
|
|
||||||
|
|
||||||
if (!isSuccess) {
|
|
||||||
PaymentStatus error = (PaymentStatus) response.getDetalle();
|
|
||||||
|
|
||||||
|
if(detail == null) {
|
||||||
log.error(
|
log.error(
|
||||||
"API retornó error de negocio. Código: {}, Mensaje: {}, Error Interno: {} -> {}",
|
"API retorno exitoso pero con detalle vacio. Codigo: {}, Mensaje: {}",
|
||||||
response.getEstatus(),
|
response.getEstatus(),
|
||||||
response.getMensaje(),
|
response.getMensaje()
|
||||||
error.getCodError(),
|
|
||||||
error.getMensajeError()
|
|
||||||
);
|
|
||||||
|
|
||||||
throw ApiPrivateException.builder()
|
|
||||||
.statusCode(response.getEstatus())
|
|
||||||
.message((!Objects.isNull(error.getCodError()))
|
|
||||||
? error.getCodError() + ":" + error.getMensajeError()
|
|
||||||
: "EMPTY_MESSAGE"
|
|
||||||
)
|
|
||||||
.build();
|
|
||||||
} else if(Objects.isNull(response.getDetalle())) {
|
|
||||||
log.error(
|
|
||||||
"API retornó exitoso pero con detalle vacio. Código: {}, Mensaje: {}",
|
|
||||||
response.getEstatus(),
|
|
||||||
response.getMensaje()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
throw ApiPrivateException.builder()
|
throw ApiPrivateException.builder()
|
||||||
@ -91,7 +72,27 @@ public class PaymentStatusClient implements PaymentStatusUseCase {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
if (detail.isLeft()) {
|
||||||
|
return detail.getLeft();
|
||||||
|
}
|
||||||
|
|
||||||
|
ApiPrivateError error = detail.getRight();
|
||||||
|
|
||||||
|
log.error(
|
||||||
|
"API privada retorno error. Codigo: {}, Mensaje: {}, Error Interno: {} -> {}",
|
||||||
|
response.getEstatus(),
|
||||||
|
response.getMensaje(),
|
||||||
|
error.getCodError(),
|
||||||
|
error.getMensajeError()
|
||||||
|
);
|
||||||
|
|
||||||
|
throw ApiPrivateException.builder()
|
||||||
|
.statusCode(response.getEstatus())
|
||||||
|
.message((error.getCodError() != null)
|
||||||
|
? error.getCodError() + ":" + error.getMensajeError()
|
||||||
|
: "EMPTY_MESSAGE"
|
||||||
|
)
|
||||||
|
.build();
|
||||||
} catch (ApiPrivateException e) {
|
} catch (ApiPrivateException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (HttpStatusCodeException e) {
|
} catch (HttpStatusCodeException e) {
|
||||||
|
|||||||
@ -31,22 +31,22 @@ public class ServiceIssuePaymentStatusService implements ServiceIssuePaymentStat
|
|||||||
public ApiResponse<ServiceIssuePaymentStatusResponse> execute(
|
public ApiResponse<ServiceIssuePaymentStatusResponse> execute(
|
||||||
ServiceIssuePaymentStatusRequest request
|
ServiceIssuePaymentStatusRequest request
|
||||||
) {
|
) {
|
||||||
log.info("Iniciando ejecución para el id: {}", request.getId());
|
log.info("Iniciando ejecucion para el id: {}", request.getId());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return apiPrivate(request);
|
return apiPrivate(request);
|
||||||
} catch (ApiPrivateException e) {
|
} catch (ApiPrivateException e) {
|
||||||
log.warn(
|
log.warn(
|
||||||
"Excepción de la api privada: {} -> {}",
|
"Excepcion de la api privada: {} -> {}",
|
||||||
e.getStatusCode(),
|
e.getStatusCode(),
|
||||||
e.getMessage()
|
e.getMessage()
|
||||||
);
|
);
|
||||||
throw HttpStatusCodeException.badRequest("400");
|
throw HttpStatusCodeException.badRequest("400");
|
||||||
} catch (HttpStatusCodeException e) {
|
} catch (HttpStatusCodeException e) {
|
||||||
log.error("Excepción HTTP del api privada: {} - {}", e.getStatusCode(), e.getErrorCode());
|
log.error("Excepcion HTTP del api privada: {} - {}", e.getStatusCode(), e.getErrorCode());
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Excepción genérica del api privada: {}", e.getMessage());
|
log.error("Excepcion generica del api privada: {}", e.getMessage());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package com.banesco.module.service_issue_payment_status.infrastructure.adapter;
|
package com.banesco.module.service_issue_payment_status.infrastructure.adapter;
|
||||||
|
|
||||||
import com.banesco.common.domain.exception.HttpStatusCodeException;
|
import com.banesco.common.domain.exception.HttpStatusCodeException;
|
||||||
import com.banesco.common.domain.model.ApiPrivateResponse;
|
|
||||||
import com.banesco.module.payment_status.application.usecase.PaymentStatusUseCase;
|
import com.banesco.module.payment_status.application.usecase.PaymentStatusUseCase;
|
||||||
import com.banesco.module.payment_status.domain.model.PaymentStatus;
|
import com.banesco.module.payment_status.domain.model.PaymentStatus;
|
||||||
import com.banesco.module.service_issue_payment_status.application.repository.ApiPrivateRepository;
|
import com.banesco.module.service_issue_payment_status.application.repository.ApiPrivateRepository;
|
||||||
@ -30,21 +29,16 @@ public class ApiPrivateAdapter implements ApiPrivateRepository {
|
|||||||
public ServicingIssueProcedure execute(
|
public ServicingIssueProcedure execute(
|
||||||
ServiceIssuePaymentStatusRequest request
|
ServiceIssuePaymentStatusRequest request
|
||||||
) {
|
) {
|
||||||
ApiPrivateResponse<PaymentStatus> response = paymentStatusUseCase.execute(
|
PaymentStatus response = paymentStatusUseCase.execute(
|
||||||
ServicingIssueMapper.toPaymentRequest(request), PaymentStatus.class
|
ServicingIssueMapper.toPaymentRequest(request), PaymentStatus.class
|
||||||
);
|
);
|
||||||
PaymentStatus paymentStatus = response.getDetalle();
|
|
||||||
|
|
||||||
if(Objects.isNull(paymentStatus) || Objects.isNull(paymentStatus.getId())) {
|
if(Objects.isNull(response) || Objects.isNull(response.getId())) {
|
||||||
throw HttpStatusCodeException.badRequest("400");
|
throw HttpStatusCodeException.badRequest("400");
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info(
|
log.info("Resultado de la transaccion obtenida: {}", response.getId());
|
||||||
"Resultado de la transaccion obtenida: {} del ID {}",
|
|
||||||
response.getEstatus(),
|
|
||||||
paymentStatus.getId()
|
|
||||||
);
|
|
||||||
|
|
||||||
return ServicingIssueMapper.toModel(paymentStatus);
|
return ServicingIssueMapper.toModel(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -160,9 +160,11 @@ public class ServicingIssueMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return switch (codeStatusRequest.toUpperCase()) {
|
return switch (codeStatusRequest.toUpperCase()) {
|
||||||
|
case "PENDIENTE" -> TransactionStatusType.PENDING;
|
||||||
case "EXITO", "EXITOSA", "COMPLETADO", "FINALIZADO" -> TransactionStatusType.COMPLETED;
|
case "EXITO", "EXITOSA", "COMPLETADO", "FINALIZADO" -> TransactionStatusType.COMPLETED;
|
||||||
case "APROBADO", "CONFIRMADO" -> TransactionStatusType.CONFIRMED;
|
case "APROBADO", "CONFIRMADO" -> TransactionStatusType.CONFIRMED;
|
||||||
case "EN_PROCESO", "PROCESANDO", "INICIADO" -> TransactionStatusType.INITIATED;
|
case "INICIADO" -> TransactionStatusType.INITIATED;
|
||||||
|
case "EN_PROCESO", "PROCESANDO", "EN CURSO" -> TransactionStatusType.IN_PROGRESS;
|
||||||
case "RECHAZADO", "FALLIDO" -> TransactionStatusType.REJECTED;
|
case "RECHAZADO", "FALLIDO" -> TransactionStatusType.REJECTED;
|
||||||
case "CANCELADO" -> TransactionStatusType.CANCELLED;
|
case "CANCELADO" -> TransactionStatusType.CANCELLED;
|
||||||
case "SUSPENDIDO" -> TransactionStatusType.SUSPENDED;
|
case "SUSPENDIDO" -> TransactionStatusType.SUSPENDED;
|
||||||
@ -170,7 +172,8 @@ public class ServicingIssueMapper {
|
|||||||
case "CONTABILIZADO" -> TransactionStatusType.BOOKED;
|
case "CONTABILIZADO" -> TransactionStatusType.BOOKED;
|
||||||
case "EJECUTADO" -> TransactionStatusType.EXECUTED;
|
case "EJECUTADO" -> TransactionStatusType.EXECUTED;
|
||||||
case "EXP" -> TransactionStatusType.EXPIRED;
|
case "EXP" -> TransactionStatusType.EXPIRED;
|
||||||
default -> TransactionStatusType.PENDING;
|
case "ENVIADO" -> TransactionStatusType.SENT;
|
||||||
|
default -> TransactionStatusType.DEFAULT;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,13 +45,13 @@ public class ServiceIssuePaymentStatusResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("/retrieve/{paymentStatusId}/{channelCode}/{signatureIdentifier}")
|
@Path("/retrieve/{paymentStatusId}/{channelCode}/{signatureIdentifier}")
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Recuperar información de la transaccion",
|
summary = "Recuperar informacion de la transaccion",
|
||||||
description = "Consulta de una trasanccion de pago por id de archivo"
|
description = "Consulta de una trasanccion de pago por id de archivo"
|
||||||
)
|
)
|
||||||
@APIResponses(value = {
|
@APIResponses(value = {
|
||||||
@APIResponse(
|
@APIResponse(
|
||||||
responseCode = "200",
|
responseCode = "200",
|
||||||
description = "Operación exitosa",
|
description = "Operacion exitosa",
|
||||||
content = @Content(
|
content = @Content(
|
||||||
mediaType = MediaType.APPLICATION_JSON,
|
mediaType = MediaType.APPLICATION_JSON,
|
||||||
schema = @Schema(
|
schema = @Schema(
|
||||||
@ -242,7 +242,7 @@ public class ServiceIssuePaymentStatusResource {
|
|||||||
),
|
),
|
||||||
examples = {
|
examples = {
|
||||||
@ExampleObject(
|
@ExampleObject(
|
||||||
name = "Error VRN08 - Identificación del fintechId no coincide",
|
name = "Error VRN08 - Identificacion del fintechId no coincide",
|
||||||
value = """
|
value = """
|
||||||
{
|
{
|
||||||
"data": null,
|
"data": null,
|
||||||
@ -282,7 +282,7 @@ public class ServiceIssuePaymentStatusResource {
|
|||||||
"data": null,
|
"data": null,
|
||||||
"statusResponse": {
|
"statusResponse": {
|
||||||
"statusCode": "VRN04",
|
"statusCode": "VRN04",
|
||||||
"message": "El servicio no está disponible fuera del horario operativo"
|
"message": "El servicio no esta disponible fuera del horario operativo"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
@ -294,7 +294,7 @@ public class ServiceIssuePaymentStatusResource {
|
|||||||
"data": null,
|
"data": null,
|
||||||
"statusResponse": {
|
"statusResponse": {
|
||||||
"statusCode": "VDR13",
|
"statusCode": "VDR13",
|
||||||
"message": "El servicio OSB no está disponible en este momento"
|
"message": "El servicio OSB no esta disponible en este momento"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
@ -305,11 +305,11 @@ public class ServiceIssuePaymentStatusResource {
|
|||||||
})
|
})
|
||||||
public Response retrieve(
|
public Response retrieve(
|
||||||
@PathParam("paymentStatusId")
|
@PathParam("paymentStatusId")
|
||||||
@Parameter(description = "Identificación del archivo", required = true, example = "11")
|
@Parameter(description = "Identificacion del archivo", required = true, example = "11")
|
||||||
String paymentStatusId,
|
String paymentStatusId,
|
||||||
|
|
||||||
@PathParam("channelCode")
|
@PathParam("channelCode")
|
||||||
@Parameter(description = "Código del canal (BOL, BOLE)", required = true, example = "BOLE")
|
@Parameter(description = "Codigo del canal (BOL, BOLE)", required = true, example = "BOLE")
|
||||||
String channelCode,
|
String channelCode,
|
||||||
|
|
||||||
@PathParam("signatureIdentifier")
|
@PathParam("signatureIdentifier")
|
||||||
@ -321,10 +321,10 @@ public class ServiceIssuePaymentStatusResource {
|
|||||||
String customerReferenceFintechId,
|
String customerReferenceFintechId,
|
||||||
|
|
||||||
@QueryParam("appId")
|
@QueryParam("appId")
|
||||||
@Parameter(description = "ID de la aplicación", example = "DANIAPP")
|
@Parameter(description = "ID de la aplicacion", example = "DANIAPP")
|
||||||
String appId
|
String appId
|
||||||
) {
|
) {
|
||||||
log.info("Iniciando consulta para instrucción de archivo id: {}", paymentStatusId);
|
log.info("Iniciando consulta para instruccion de archivo id: {}", paymentStatusId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return Response.ok(useCase.execute(
|
return Response.ok(useCase.execute(
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
package com.banesco.module.transaction.domain.model;
|
package com.banesco.module.transaction.domain.model;
|
||||||
|
|
||||||
public enum TransactionStatusType {
|
public enum TransactionStatusType {
|
||||||
|
DEFAULT,
|
||||||
INITIATED,
|
INITIATED,
|
||||||
|
IN_PROGRESS,
|
||||||
EXECUTED,
|
EXECUTED,
|
||||||
CANCELLED,
|
CANCELLED,
|
||||||
CONFIRMED,
|
CONFIRMED,
|
||||||
@ -12,4 +14,5 @@ public enum TransactionStatusType {
|
|||||||
BOOKED,
|
BOOKED,
|
||||||
REJECTED,
|
REJECTED,
|
||||||
EXPIRED,
|
EXPIRED,
|
||||||
|
SENT,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,6 @@ api:
|
|||||||
dom-service-issue-payment-status:
|
dom-service-issue-payment-status:
|
||||||
messages:
|
messages:
|
||||||
key: 'dom-service-issue-payment-status'
|
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 validación 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"},{"backend_code":"204","http_code":"200","status_code":"200","description":"Cliente sin productos","status":"ok"}]'
|
||||||
rest-client:
|
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"}'
|
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