Add scripts folder

This commit is contained in:
Ramon Ramirez 2026-01-09 18:37:46 -04:00
parent 066b002aa3
commit 7371422ac5
13 changed files with 193 additions and 80 deletions

31
scripts/native/Dockerfile Normal file
View File

@ -0,0 +1,31 @@
####
# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode.
# It uses a micro base image, tuned for Quarkus native executables.
# It reduces the size of the resulting container image.
# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image.
#
# Before building the container image run:
#
# ./mvnw package -Dnative
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/rec-legal-customer-product-directory .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/rec-legal-customer-product-directory
#
###
FROM quay.io/quarkus/quarkus-micro-image:2.0
RUN mkdir -p /work
ENV TZ="America/Caracas"
ENV LANGUAGE='en_US:en'
VOLUME /tmp
COPY /file/*-runner /work/app
RUN chmod -R 775 /work
RUN ls -ltra /work/
EXPOSE 8080
WORKDIR /work/
ENTRYPOINT ["./app", "-Dquarkus.http.host=0.0.0.0"]

View File

@ -5,7 +5,7 @@ import com.banesco.common.domain.exception.InternalServerException;
import com.banesco.common.domain.model.ApiResponse; import com.banesco.common.domain.model.ApiResponse;
import com.banesco.common.domain.model.ErrorMapping; import com.banesco.common.domain.model.ErrorMapping;
import com.banesco.common.domain.model.StatusResponse; import com.banesco.common.domain.model.StatusResponse;
import com.banesco.common.infrastructure.config.ErrorMessagesConfig; import com.banesco.common.infrastructure.config.MessagesConfig;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.quarkus.runtime.annotations.RegisterForReflection; import io.quarkus.runtime.annotations.RegisterForReflection;
@ -22,9 +22,9 @@ import java.util.concurrent.ConcurrentHashMap;
@Slf4j @Slf4j
@ApplicationScoped @ApplicationScoped
@RegisterForReflection @RegisterForReflection
public class ErrorResponseHelper { public class MessageResponseHelper {
private final ErrorMessagesConfig errorMessagesConfig; private final MessagesConfig messagesConfig;
private final Map<String, ErrorMapping> errorMappings; private final Map<String, ErrorMapping> errorMappings;
private static final String ERROR_DEFAULT = "default"; private static final String ERROR_DEFAULT = "default";
private static final String SUCCESS_DEFAULT = "200"; private static final String SUCCESS_DEFAULT = "200";
@ -32,19 +32,15 @@ public class ErrorResponseHelper {
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
@Inject @Inject
public ErrorResponseHelper( public MessageResponseHelper(
ObjectMapper objectMapper, ObjectMapper objectMapper,
ErrorMessagesConfig errorMessagesConfig MessagesConfig messagesConfig
) { ) {
this.objectMapper = objectMapper; this.objectMapper = objectMapper;
this.errorMessagesConfig = errorMessagesConfig; this.messagesConfig = messagesConfig;
this.errorMappings = initializeErrorMappings(); this.errorMappings = initializeErrorMappings();
} }
// Ya no es una clase interna, ahora usa la clase del dominio
// Solo necesitas mantener la referencia al tipo
// Si ErrorMapping está en otro paquete, asegúrate de importarlo
public Response handleException(BaseApiException exception) { public Response handleException(BaseApiException exception) {
return buildErrorResponse(exception); return buildErrorResponse(exception);
} }
@ -115,7 +111,7 @@ public class ErrorResponseHelper {
String json; String json;
if (isReadingFromProps()) { if (isReadingFromProps()) {
json = errorMessagesConfig.getErrorMessagesJson(); json = messagesConfig.getErrorMessagesJson();
log.info("Cargando mensajes de errores desde properties"); log.info("Cargando mensajes de errores desde properties");
} else { } else {
json = loadFromJsonFile(); json = loadFromJsonFile();
@ -151,7 +147,7 @@ public class ErrorResponseHelper {
} }
private String loadFromJsonFile() { private String loadFromJsonFile() {
try (InputStream is = ErrorResponseHelper.class.getClassLoader().getResourceAsStream(ERROR_FILE_PATH)) { try (InputStream is = MessageResponseHelper.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 encontró el archivo de errores: {}", ERROR_FILE_PATH);
return ""; return "";
@ -189,6 +185,6 @@ public class ErrorResponseHelper {
} }
public boolean isReadingFromProps() { public boolean isReadingFromProps() {
return errorMessagesConfig.isReadFromProps(); return messagesConfig.isReadFromProps();
} }
} }

View File

@ -5,16 +5,64 @@ import jakarta.inject.Inject;
import lombok.Getter; import lombok.Getter;
import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.Config;
import java.util.Arrays;
import java.util.List;
@ApplicationScoped @ApplicationScoped
@Getter @Getter
public class DataSourceConfig { public class DataSourceConfig {
private final String spName; private final String spName;
private final String spIbsError; private final String spIbsError;
private final List<String> spAccountStatusEnable;
private final List<String> spAccountStatusDisabled;
private final List<String> spAccountTypeSaving;
private final List<String> spAccountTypeCurrent;
private final List<String> spAccountTypeInterestArrangement;
private final List<String> spAccountParent;
private final List<String> spCurrencyBase;
@Inject @Inject
public DataSourceConfig(Config config) { public DataSourceConfig(Config config) {
this.spName = config.getValue("datasource.sp.name", String.class); this.spName = config.getValue("datasource.sp.name", String.class);
this.spIbsError = config.getValue("datasource.sp.errors.ibs", String.class).toUpperCase(); this.spIbsError = config.getValue("datasource.sp.errors.ibs", String.class).toUpperCase();
this.spAccountStatusEnable = Arrays.stream(config.getValue(
"datasource.sp.allowed.account-status.enable",
String.class
).toUpperCase().split(",")).toList();
this.spAccountStatusDisabled = Arrays.stream(config.getValue(
"datasource.sp.allowed.account-status.disable",
String.class
).toUpperCase().split(",")).toList();
this.spAccountTypeSaving = Arrays.stream(config.getValue(
"datasource.sp.allowed.account-type.saving",
String.class
).toUpperCase().split(",")).toList();
this.spAccountTypeCurrent = Arrays.stream(config.getValue(
"datasource.sp.allowed.account-type.current",
String.class
).toUpperCase().split(",")).toList();
this.spAccountTypeInterestArrangement = Arrays.stream(config.getValue(
"datasource.sp.allowed.account-type.interest-arrangement",
String.class
).toUpperCase().split(",")).toList();
this.spAccountParent = Arrays.stream(config.getValue(
"datasource.sp.allowed.account-relationship-type.parent",
String.class
).toUpperCase().split(",")).toList();
this.spCurrencyBase = Arrays.stream(config.getValue(
"datasource.sp.allowed.currency.base",
String.class
).toUpperCase().split(",")).toList();
} }
} }

View File

@ -7,7 +7,7 @@ import org.eclipse.microprofile.config.Config;
@ApplicationScoped @ApplicationScoped
@Getter @Getter
public class ErrorMessagesConfig { public class MessagesConfig {
private final boolean readFromProps; private final boolean readFromProps;
private final String errorMessagesJson; private final String errorMessagesJson;
@ -16,7 +16,7 @@ public class ErrorMessagesConfig {
private static final String KEY = "domLogalCustomerProductDirectory"; private static final String KEY = "domLogalCustomerProductDirectory";
@Inject @Inject
public ErrorMessagesConfig(Config config) { public MessagesConfig(Config config) {
this.readFromProps = config.getValue("api.read-messages.from-props", Boolean.class); this.readFromProps = config.getValue("api.read-messages.from-props", Boolean.class);
this.errorMessagesJson = config.getValue("api." + KEY + ".messages.content", String.class); this.errorMessagesJson = config.getValue("api." + KEY + ".messages.content", String.class);
this.messagesKey = config.getValue("api." + KEY + ".messages.key", String.class); this.messagesKey = config.getValue("api." + KEY + ".messages.key", String.class);

View File

@ -3,6 +3,7 @@ package com.banesco.module.account.domain.model;
import com.banesco.module.party.domain.model.Party; import com.banesco.module.party.domain.model.Party;
import io.quarkus.runtime.annotations.RegisterForReflection; import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.*; import lombok.*;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
@Getter @Getter
@ToString @ToString
@ -12,5 +13,6 @@ import lombok.*;
@RegisterForReflection @RegisterForReflection
public class AccountInvolvement { public class AccountInvolvement {
private AccountInvolvementType accountInvolvementType; private AccountInvolvementType accountInvolvementType;
@Schema(description = "Información del cliente")
private Party partyReference; private Party partyReference;
} }

View File

@ -1,8 +1,7 @@
package com.banesco.module.legal_customer_product_directory.application.service; package com.banesco.module.legal_customer_product_directory.application.service;
import com.banesco.common.domain.exception.BadRequestException; import com.banesco.common.application.helper.MessageResponseHelper;
import com.banesco.common.domain.exception.BaseApiException; import com.banesco.common.domain.exception.*;
import com.banesco.common.domain.exception.ServiceUnavailableException;
import com.banesco.common.domain.model.*; import com.banesco.common.domain.model.*;
import com.banesco.module.account.domain.model.*; import com.banesco.module.account.domain.model.*;
import com.banesco.module.legal_customer_product_directory.application.repository.PersistenceRepository; import com.banesco.module.legal_customer_product_directory.application.repository.PersistenceRepository;
@ -18,12 +17,15 @@ import lombok.extern.slf4j.Slf4j;
@ApplicationScoped @ApplicationScoped
public class LegalCustomerProductDirectoryService implements LegalCustomerProductDirectoryUseCase { public class LegalCustomerProductDirectoryService implements LegalCustomerProductDirectoryUseCase {
private final MessageResponseHelper messageResponseHelper;
private final PersistenceRepository persistenceRepository; private final PersistenceRepository persistenceRepository;
@Inject @Inject
public LegalCustomerProductDirectoryService( public LegalCustomerProductDirectoryService(
MessageResponseHelper messageResponseHelper,
PersistenceRepository persistenceRepository PersistenceRepository persistenceRepository
) { ) {
this.messageResponseHelper = messageResponseHelper;
this.persistenceRepository = persistenceRepository; this.persistenceRepository = persistenceRepository;
} }
@ -38,6 +40,9 @@ public class LegalCustomerProductDirectoryService implements LegalCustomerProduc
} catch (BaseApiException e) { } catch (BaseApiException e) {
log.warn("Excepción controlada del sp: {} -> {}", e.getErrorCode(), e.getMessage()); log.warn("Excepción controlada del sp: {} -> {}", e.getErrorCode(), e.getMessage());
throw e; throw e;
} catch (PersistenceException e) {
log.warn("Excepción de la persistencia del sp: {} -> {}", e.getErrorCode(), e.getMessage());
throw new BadRequestException(e.getErrorCode(), null);
} catch (Exception e) { } catch (Exception e) {
log.warn("Excepción generica del sp: {}", e.getMessage()); log.warn("Excepción generica del sp: {}", e.getMessage());
throw new ServiceUnavailableException("503", e.getMessage(), null); throw new ServiceUnavailableException("503", e.getMessage(), null);
@ -52,17 +57,14 @@ public class LegalCustomerProductDirectoryService implements LegalCustomerProduc
CustomerProductAndServiceDirectory response = persistenceRepository.execute(request); CustomerProductAndServiceDirectory response = persistenceRepository.execute(request);
if(response == null) { if(response == null) {
throw new BadRequestException("503", null); throw new BadRequestException("400", null);
} }
return new ApiResponse<>( return new ApiResponse<>(
LegalCustomerProductDirectoryResponse.builder() LegalCustomerProductDirectoryResponse.builder()
.customerProductAndServiceDirectory(response) .customerProductAndServiceDirectory(response)
.build(), .build(),
StatusResponse.builder() messageResponseHelper.createSuccessResponse("200")
.statusCode("200")
.message("Operación exitosa")
.build()
); );
} }
} }

View File

@ -1,7 +1,6 @@
package com.banesco.module.legal_customer_product_directory.domain.model; package com.banesco.module.legal_customer_product_directory.domain.model;
import com.banesco.module.account.domain.model.Account; import com.banesco.module.account.domain.model.Account;
import com.banesco.module.party.domain.model.Party;
import io.quarkus.runtime.annotations.RegisterForReflection; import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.*; import lombok.*;
import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.eclipse.microprofile.openapi.annotations.media.Schema;

View File

@ -1,5 +1,6 @@
package com.banesco.module.legal_customer_product_directory.infrastructure.adapter; package com.banesco.module.legal_customer_product_directory.infrastructure.adapter;
import com.banesco.common.infrastructure.config.DataSourceConfig;
import com.banesco.module.legal_customer_product_directory.application.repository.PersistenceRepository; import com.banesco.module.legal_customer_product_directory.application.repository.PersistenceRepository;
import com.banesco.module.legal_customer_product_directory.domain.dto.request.LegalCustomerProductDirectoryRequest; import com.banesco.module.legal_customer_product_directory.domain.dto.request.LegalCustomerProductDirectoryRequest;
import com.banesco.module.legal_customer_product_directory.domain.dto.response.SPAccountResponse; import com.banesco.module.legal_customer_product_directory.domain.dto.response.SPAccountResponse;
@ -16,12 +17,15 @@ import java.util.List;
@ApplicationScoped @ApplicationScoped
public class PersistenceAdapter implements PersistenceRepository { public class PersistenceAdapter implements PersistenceRepository {
private final DataSourceConfig dataSourceConfig;
private final AccountRepository accountRepository; private final AccountRepository accountRepository;
@Inject @Inject
public PersistenceAdapter( public PersistenceAdapter(
DataSourceConfig dataSourceConfig,
AccountRepository accountRepository AccountRepository accountRepository
) { ) {
this.dataSourceConfig = dataSourceConfig;
this.accountRepository = accountRepository; this.accountRepository = accountRepository;
} }
@ -29,7 +33,9 @@ public class PersistenceAdapter implements PersistenceRepository {
public CustomerProductAndServiceDirectory execute( public CustomerProductAndServiceDirectory execute(
LegalCustomerProductDirectoryRequest request LegalCustomerProductDirectoryRequest request
) { ) {
List<SPAccountResponse> accountsFromSP = accountRepository.execute(request); List<SPAccountResponse> accountsFromSP = accountRepository.execute(
dataSourceConfig, request
);
log.info("Cuentas obtenidas por el SP: {}", accountsFromSP.size()); log.info("Cuentas obtenidas por el SP: {}", accountsFromSP.size());
@ -38,7 +44,9 @@ public class PersistenceAdapter implements PersistenceRepository {
} }
return CustomerProductAndServiceDirectory.builder() return CustomerProductAndServiceDirectory.builder()
.accounts(accountsFromSP.stream().map(AccountMapper::toAccount).toList()) .accounts(accountsFromSP.stream().map(spAccount ->
AccountMapper.toAccount(dataSourceConfig, spAccount)
).toList())
.build(); .build();
} }
} }

View File

@ -1,6 +1,7 @@
package com.banesco.module.legal_customer_product_directory.infrastructure.persistence.mapper; package com.banesco.module.legal_customer_product_directory.infrastructure.persistence.mapper;
import com.banesco.common.domain.model.*; import com.banesco.common.domain.model.*;
import com.banesco.common.infrastructure.config.DataSourceConfig;
import com.banesco.module.account.domain.model.*; import com.banesco.module.account.domain.model.*;
import com.banesco.module.legal_customer_product_directory.domain.dto.response.SPAccountResponse; import com.banesco.module.legal_customer_product_directory.domain.dto.response.SPAccountResponse;
import com.banesco.module.party.domain.model.Party; import com.banesco.module.party.domain.model.Party;
@ -14,29 +15,31 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
public class AccountMapper { public class AccountMapper {
private AccountMapper() {} private AccountMapper() {}
public static Account toAccount( public static Account toAccount(
SPAccountResponse spAccountResponse DataSourceConfig dataSourceConfig,
SPAccountResponse response
) { ) {
String accountType = response.getTipoCta().toUpperCase();
String currency = response.getMoneda().toUpperCase();
String parent = response.getParentChild().toUpperCase();
AccountStatus status = AccountStatus.builder() AccountStatus status = AccountStatus.builder()
.status(spAccountResponse.getEstatus()) .status(response.getEstatus())
.statusType((Objects.equals(spAccountResponse.getEstatus(), "A")) ? .statusType(getAccountStatusType(dataSourceConfig, response))
AccountStatusType.ENABLED :
AccountStatusType.DISABLED
)
.build(); .build();
AccountType type = (Objects.equals(spAccountResponse.getTipoCta().toUpperCase(), "SAV")) AccountType type = (dataSourceConfig.getSpAccountTypeSaving().contains(accountType))
? AccountType.SAVING_ACCOUNT ? AccountType.SAVING_ACCOUNT
: AccountType.CURRENT_ACCOUNT; : AccountType.CURRENT_ACCOUNT;
List<AccountCurrency> currencies = List.of( List<AccountCurrency> currencies = List.of(
AccountCurrency.builder() AccountCurrency.builder()
.currencyCode(spAccountResponse.getMoneda().toUpperCase()) .currencyCode(currency)
.currencyType((Objects.equals(spAccountResponse.getMoneda().toUpperCase(), "BS")) .currencyType((dataSourceConfig.getSpCurrencyBase().contains(currency))
? CurrencyType.BASE ? CurrencyType.BASE
: CurrencyType.SECONDARY : CurrencyType.SECONDARY
) )
@ -44,13 +47,13 @@ public class AccountMapper {
); );
List<AccountRelationship> relationships = List.of( List<AccountRelationship> relationships = List.of(
AccountRelationship.builder() AccountRelationship.builder()
.accountRelationshipType((Objects.equals(spAccountResponse.getParentChild().toUpperCase(), "PADRE")) .accountRelationshipType((dataSourceConfig.getSpAccountParent().contains(parent))
? AccountRelationshipType.ACCOUNT_IS_PARENT_ACCOUNT_FOR_ACCOUNT ? AccountRelationshipType.ACCOUNT_IS_PARENT_ACCOUNT_FOR_ACCOUNT
: AccountRelationshipType.ACCOUNT_IS_SUB_ACCOUNT_FOR_ACCOUNT : AccountRelationshipType.ACCOUNT_IS_SUB_ACCOUNT_FOR_ACCOUNT
) )
.build() .build()
); );
List<Agreement> agreements = (Objects.equals(spAccountResponse.getTipoCta().toUpperCase(), "MMK")) ? List.of( List<Agreement> agreements = (dataSourceConfig.getSpAccountTypeInterestArrangement().contains(accountType)) ? List.of(
Agreement.builder() Agreement.builder()
.arrangement(List.of( .arrangement(List.of(
Arrangement.builder() Arrangement.builder()
@ -66,7 +69,7 @@ public class AccountMapper {
Party.builder() Party.builder()
.partyName(List.of( .partyName(List.of(
Name.builder() Name.builder()
.fullName(spAccountResponse.getNombre()) .fullName(response.getNombre())
.build() .build()
)) ))
.partyType(PartyType.ORGANISATION) .partyType(PartyType.ORGANISATION)
@ -74,19 +77,19 @@ public class AccountMapper {
PartyIdentification.builder() PartyIdentification.builder()
.partyIdentificationType(PartyIdentificationType.TAX_IDENTIFICATION_NUMBER) .partyIdentificationType(PartyIdentificationType.TAX_IDENTIFICATION_NUMBER)
.partyIdentification(Identifier.builder() .partyIdentification(Identifier.builder()
.identifierValue(spAccountResponse.getRif()) .identifierValue(response.getRif())
.build()) .build())
.build(), .build(),
PartyIdentification.builder() PartyIdentification.builder()
.partyIdentificationType(PartyIdentificationType.TELEPHONE_NUMBER) .partyIdentificationType(PartyIdentificationType.TELEPHONE_NUMBER)
.partyIdentification(Identifier.builder() .partyIdentification(Identifier.builder()
.identifierValue(spAccountResponse.getCelular()) .identifierValue(response.getCelular())
.build()) .build())
.build(), .build(),
PartyIdentification.builder() PartyIdentification.builder()
.partyIdentificationType(PartyIdentificationType.TELEPHONE_OPERATOR) .partyIdentificationType(PartyIdentificationType.TELEPHONE_OPERATOR)
.partyIdentification(Identifier.builder() .partyIdentification(Identifier.builder()
.identifierValue(spAccountResponse.getOperadora()) .identifierValue(response.getOperadora())
.build()) .build())
.build() .build()
)) ))
@ -99,8 +102,8 @@ public class AccountMapper {
return Account.builder() return Account.builder()
.accountStatus(status) .accountStatus(status)
.accountType(type) .accountType(type)
.accountIdentification(getAccountIdentifications(spAccountResponse)) .accountIdentification(getAccountIdentifications(response))
.accountBalance(getAccountBalances(spAccountResponse)) .accountBalance(getAccountBalances(response))
.accountCurrency(currencies) .accountCurrency(currencies)
.accountInvolvement(involvements) .accountInvolvement(involvements)
.accountRelationship(relationships) .accountRelationship(relationships)
@ -108,59 +111,70 @@ public class AccountMapper {
.build(); .build();
} }
private static AccountStatusType getAccountStatusType(
DataSourceConfig dataSourceConfig,
SPAccountResponse response
) {
String accountStatus = response.getEstatus().toUpperCase();
if (dataSourceConfig.getSpAccountStatusEnable().contains(accountStatus)) return AccountStatusType.ENABLED;
if (dataSourceConfig.getSpAccountStatusDisabled().contains(accountStatus)) return AccountStatusType.DISABLED;
return AccountStatusType.PENDING;
}
private static List<AccountIdentification> getAccountIdentifications( private static List<AccountIdentification> getAccountIdentifications(
SPAccountResponse spAccountResponse SPAccountResponse response
) { ) {
return List.of( return List.of(
AccountIdentification.builder() AccountIdentification.builder()
.accountIdentificationType(AccountIdentificationType.ACCOUNT_NUMBER) .accountIdentificationType(AccountIdentificationType.ACCOUNT_NUMBER)
.accountIdentification(Identifier.builder() .accountIdentification(Identifier.builder()
.identifierValue(spAccountResponse.getCuenta()) .identifierValue(response.getCuenta())
.build()) .build())
.build(), .build(),
AccountIdentification.builder() AccountIdentification.builder()
.accountIdentificationType(AccountIdentificationType.BANK_NUMBER) .accountIdentificationType(AccountIdentificationType.BANK_NUMBER)
.accountIdentification(Identifier.builder() .accountIdentification(Identifier.builder()
.identifierValue(spAccountResponse.getBanco()) .identifierValue(response.getBanco())
.build()) .build())
.build(), .build(),
AccountIdentification.builder() AccountIdentification.builder()
.accountIdentificationType(AccountIdentificationType.PRODUCT_CODE) .accountIdentificationType(AccountIdentificationType.PRODUCT_CODE)
.accountIdentification(Identifier.builder() .accountIdentification(Identifier.builder()
.identifierValue(spAccountResponse.getProducto()) .identifierValue(response.getProducto())
.build()) .build())
.build(), .build(),
AccountIdentification.builder() AccountIdentification.builder()
.accountIdentificationType(AccountIdentificationType.ACCOUNT_CLASS) .accountIdentificationType(AccountIdentificationType.ACCOUNT_CLASS)
.accountIdentification(Identifier.builder() .accountIdentification(Identifier.builder()
.identifierValue(spAccountResponse.getClaseCta()) .identifierValue(response.getClaseCta())
.build()) .build())
.build() .build()
); );
} }
private static List<AccountBalance> getAccountBalances( private static List<AccountBalance> getAccountBalances(
SPAccountResponse spAccountResponse SPAccountResponse response
) { ) {
return List.of( return List.of(
AccountBalance.builder() AccountBalance.builder()
.balanceAmount(spAccountResponse.getSaldoDisponible()) .balanceAmount(response.getSaldoDisponible())
.balanceType(BalanceType.AVAILABLE_BALANCE) .balanceType(BalanceType.AVAILABLE_BALANCE)
.build(), .build(),
AccountBalance.builder() AccountBalance.builder()
.balanceAmount(spAccountResponse.getMaxDia()) .balanceAmount(response.getMaxDia())
.balanceType(BalanceType.DAILY_MAXIMUM) .balanceType(BalanceType.DAILY_MAXIMUM)
.build(), .build(),
AccountBalance.builder() AccountBalance.builder()
.balanceAmount(spAccountResponse.getMaxMens()) .balanceAmount(response.getMaxMens())
.balanceType(BalanceType.MONTHLY_MAXIMUM) .balanceType(BalanceType.MONTHLY_MAXIMUM)
.build(), .build(),
AccountBalance.builder() AccountBalance.builder()
.balanceAmount(spAccountResponse.getMinTran()) .balanceAmount(response.getMinTran())
.balanceType(BalanceType.TRANSACTION_MINIMUM) .balanceType(BalanceType.TRANSACTION_MINIMUM)
.build(), .build(),
AccountBalance.builder() AccountBalance.builder()
.balanceAmount(spAccountResponse.getMaxTran()) .balanceAmount(response.getMaxTran())
.balanceType(BalanceType.TRANSACTION_MAXIMUM) .balanceType(BalanceType.TRANSACTION_MAXIMUM)
.build() .build()
); );

View File

@ -1,6 +1,5 @@
package com.banesco.module.legal_customer_product_directory.infrastructure.persistence.repository; package com.banesco.module.legal_customer_product_directory.infrastructure.persistence.repository;
import com.banesco.common.domain.exception.BadRequestException;
import com.banesco.common.domain.exception.PersistenceException; import com.banesco.common.domain.exception.PersistenceException;
import com.banesco.common.infrastructure.config.DataSourceConfig; import com.banesco.common.infrastructure.config.DataSourceConfig;
import com.banesco.module.legal_customer_product_directory.domain.dto.request.LegalCustomerProductDirectoryRequest; import com.banesco.module.legal_customer_product_directory.domain.dto.request.LegalCustomerProductDirectoryRequest;
@ -23,33 +22,34 @@ import java.util.List;
@ApplicationScoped @ApplicationScoped
public class AccountRepository { public class AccountRepository {
private final DataSourceConfig dataSourceConfig;
private final AgroalDataSource dataSource; private final AgroalDataSource dataSource;
@Inject @Inject
public AccountRepository( public AccountRepository(
DataSourceConfig dataSourceConfig,
AgroalDataSource dataSource AgroalDataSource dataSource
) { ) {
this.dataSourceConfig = dataSourceConfig;
this.dataSource = dataSource; this.dataSource = dataSource;
} }
public List<SPAccountResponse> execute( public List<SPAccountResponse> execute(
DataSourceConfig dataSourceConfig,
LegalCustomerProductDirectoryRequest request LegalCustomerProductDirectoryRequest request
) { ) {
try { try {
return callSp(request); return callSp(dataSourceConfig, request);
} catch (SQLException e) { } catch (PersistenceException e) {
throw new PersistenceException("SP_ERROR", e.getMessage()); throw e;
} catch (Exception e) {
throw new PersistenceException("ERROR", e.getMessage());
} }
} }
private List<SPAccountResponse> callSp( private List<SPAccountResponse> callSp(
DataSourceConfig dataSourceConfig,
LegalCustomerProductDirectoryRequest request LegalCustomerProductDirectoryRequest request
) throws SQLException { ) {
List<SPAccountResponse> results; List<SPAccountResponse> results;
String spCall = buildSpCall(request); String spCall = buildSpCall(dataSourceConfig, request);
log.info("Iniciando llamada SP: {}", spCall); log.info("Iniciando llamada SP: {}", spCall);
@ -63,15 +63,14 @@ public class AccountRepository {
!StringUtil.isNullOrEmpty(results.get(0).getDscError()) && !StringUtil.isNullOrEmpty(results.get(0).getDscError()) &&
results.get(0).getDscError().toUpperCase().equals(dataSourceConfig.getSpIbsError()) results.get(0).getDscError().toUpperCase().equals(dataSourceConfig.getSpIbsError())
) { ) {
throw new BadRequestException( throw new PersistenceException("ERROR", results.get(0).getDscError());
"SP_ERROR",
results.get(0).getDscError(),
null
);
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error en conexión o ejecución SP {}: {}", spCall, e.getMessage()); log.error("Error en conexión o ejecución del SP {}: {}", spCall, e.getMessage());
throw e; throw new PersistenceException("ERROR", e.getMessage());
} catch (Exception e) {
log.error("Error genérico en la ejecución del SP {}: {}", spCall, e.getMessage());
throw new PersistenceException("ERROR", e.getMessage());
} finally { } finally {
log.info("SP conexión finalizada"); log.info("SP conexión finalizada");
} }
@ -122,6 +121,7 @@ public class AccountRepository {
} }
private String buildSpCall( private String buildSpCall(
DataSourceConfig dataSourceConfig,
LegalCustomerProductDirectoryRequest request LegalCustomerProductDirectoryRequest request
) { ) {
return "call " + dataSourceConfig.getSpName() + return "call " + dataSourceConfig.getSpName() +

View File

@ -1,6 +1,6 @@
package com.banesco.module.legal_customer_product_directory.infrastructure.resource; package com.banesco.module.legal_customer_product_directory.infrastructure.resource;
import com.banesco.common.application.helper.ErrorResponseHelper; import com.banesco.common.application.helper.MessageResponseHelper;
import com.banesco.common.domain.exception.BaseApiException; import com.banesco.common.domain.exception.BaseApiException;
import com.banesco.common.domain.model.ApiResponse; import com.banesco.common.domain.model.ApiResponse;
import com.banesco.common.domain.model.StatusResponse; import com.banesco.common.domain.model.StatusResponse;
@ -28,16 +28,17 @@ import java.util.Objects;
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public class LegalCustomerProductDirectoryResource { public class LegalCustomerProductDirectoryResource {
private final LegalCustomerProductDirectoryUseCase useCase; private final LegalCustomerProductDirectoryUseCase useCase;
private final ErrorResponseHelper errorResponseHelper; private final MessageResponseHelper messageResponseHelper;
@Inject @Inject
public LegalCustomerProductDirectoryResource( public LegalCustomerProductDirectoryResource(
LegalCustomerProductDirectoryUseCase useCase, MessageResponseHelper messageResponseHelper,
ErrorResponseHelper errorResponseHelper LegalCustomerProductDirectoryUseCase useCase
) { ) {
this.messageResponseHelper = messageResponseHelper;
this.useCase = useCase; this.useCase = useCase;
this.errorResponseHelper = errorResponseHelper;
} }
@GET @GET
@ -393,9 +394,9 @@ public class LegalCustomerProductDirectoryResource {
.build() .build()
)).build(); )).build();
} catch (BaseApiException e) { } catch (BaseApiException e) {
return errorResponseHelper.handleException(e); return messageResponseHelper.handleException(e);
} catch (Exception e) { } catch (Exception e) {
return errorResponseHelper.handleGenericException(e); return messageResponseHelper.handleGenericException(e);
} }
} }
} }

View File

@ -14,7 +14,7 @@ api:
allowed: allowed:
request-validation: request-validation:
customer-ibs-number: '\d+' customer-ibs-number: '\d+'
account-status: '^(A|O|ACTBSUSD)$' account-status: '^(A|D|ACTBSUSD)$'
product-cv-code: '^(CV|CVFL)$' product-cv-code: '^(CV|CVFL)$'
limit-type: '^(PAG|REC)$' limit-type: '^(PAG|REC)$'
cachea-indicator: '^(SI|NO)$' cachea-indicator: '^(SI|NO)$'
@ -28,5 +28,17 @@ api:
datasource: datasource:
sp: sp:
name: BANCYFIL2.CONCTABOLE name: BANCYFIL2.CONCTABOLE
allowed:
account-status:
enable: A
disable: D
account-type:
saving: SAV
current: DDA,MMK
interest-arrangement: MMK
account-relationship-type:
parent: PADRE
currency:
base: BS
errors: errors:
ibs: "DEBE ESPECIFICAR EL NRO DE CLIENTE" ibs: "DEBE ESPECIFICAR EL NRO DE CLIENTE"