Skip to content

Commit

Permalink
Fix FBR-692 (#803)
Browse files Browse the repository at this point in the history
* Fix for FBR-692

* Spotless fixes
  • Loading branch information
leonardohildt authored Jun 18, 2024
1 parent fb62951 commit cf19fc6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ public class LoanAdditionalData {

private String cliente_activo_fiador2;


public LoanAdditionProperties toEntity() {
final LoanAdditionProperties loanAdditionProperties = new LoanAdditionProperties();
BeanUtils.copyProperties(this, loanAdditionProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ private CheckValidationColor runCheck25(final ClientData clientData) {
* Credits
*/
private CheckValidationColor runCheck26(final ClientData clientData) {
if (!clientData.getIsLoanTopup()){
if (!clientData.getIsLoanTopup()) {
return null;
}
final String clientId = String.valueOf(clientData.getClientId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@
import java.util.Objects;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationProperty;
import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationRepositoryWrapper;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.InvalidJsonException;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.UnsupportedParameterException;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.core.serialization.JsonParserHelper;
import org.apache.fineract.portfolio.accountdetails.domain.AccountType;
import org.apache.fineract.portfolio.calendar.service.CalendarUtils;
import org.apache.fineract.portfolio.collateralmanagement.domain.ClientCollateralManagement;
Expand Down Expand Up @@ -132,14 +135,17 @@ public final class LoanApplicationCommandFromApiJsonHelper {
private final FromJsonHelper fromApiJsonHelper;
private final CalculateLoanScheduleQueryFromApiJsonHelper apiJsonHelper;
private final ClientCollateralManagementRepositoryWrapper clientCollateralManagementRepositoryWrapper;
private final GlobalConfigurationRepositoryWrapper globalConfigurationRepositoryWrapper;

@Autowired
public LoanApplicationCommandFromApiJsonHelper(final FromJsonHelper fromApiJsonHelper,
final CalculateLoanScheduleQueryFromApiJsonHelper apiJsonHelper,
final ClientCollateralManagementRepositoryWrapper clientCollateralManagementRepositoryWrapper) {
final ClientCollateralManagementRepositoryWrapper clientCollateralManagementRepositoryWrapper,
final GlobalConfigurationRepositoryWrapper globalConfigurationRepositoryWrapper) {
this.fromApiJsonHelper = fromApiJsonHelper;
this.apiJsonHelper = apiJsonHelper;
this.clientCollateralManagementRepositoryWrapper = clientCollateralManagementRepositoryWrapper;
this.globalConfigurationRepositoryWrapper = globalConfigurationRepositoryWrapper;
}

public void validateLoanAdditionalData(final JsonCommand command) {
Expand Down Expand Up @@ -490,6 +496,12 @@ public void validateForCreate(final String json, final boolean isMeetingMandator
final JsonObject topLevelJsonElement = element.getAsJsonObject();
final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement);
final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
Locale localeAmount = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
GlobalConfigurationProperty maintainAmountFormatToEN = this.globalConfigurationRepositoryWrapper
.findOneByNameWithNotFoundDetection("maintainAmountFormatToEN");
if (maintainAmountFormatToEN.isEnabled()) {
localeAmount = JsonParserHelper.localeFromString("en");
}

if (topLevelJsonElement.get(chargesParameterName).isJsonArray()) {
final Type arrayObjectParameterTypeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
Expand All @@ -508,7 +520,7 @@ public void validateForCreate(final String json, final boolean isMeetingMandator
baseDataValidator.reset().parameter("charges").parameterAtIndexArray("chargeId", i).value(chargeId).notNull()
.integerGreaterThanZero();

final BigDecimal amount = this.fromApiJsonHelper.extractBigDecimalNamed("amount", loanChargeElement, locale);
final BigDecimal amount = this.fromApiJsonHelper.extractBigDecimalNamed("amount", loanChargeElement, localeAmount);
baseDataValidator.reset().parameter("charges").parameterAtIndexArray("amount", i).value(amount).notNull()
.positiveAmount();

Expand Down Expand Up @@ -959,6 +971,12 @@ public void validateForModify(final String json, final LoanProduct loanProduct,
final JsonObject topLevelJsonElement = element.getAsJsonObject();
final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement);
final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
Locale localeAmount = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
GlobalConfigurationProperty maintainAmountFormatToEN = this.globalConfigurationRepositoryWrapper
.findOneByNameWithNotFoundDetection("maintainAmountFormatToEN");
if (maintainAmountFormatToEN.isEnabled()) {
localeAmount = JsonParserHelper.localeFromString("en");
}

if (topLevelJsonElement.get(chargesParameterName).isJsonArray()) {
final Type arrayObjectParameterTypeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
Expand All @@ -977,7 +995,7 @@ public void validateForModify(final String json, final LoanProduct loanProduct,
baseDataValidator.reset().parameter("charges").parameterAtIndexArray("chargeId", i).value(chargeId).notNull()
.integerGreaterThanZero();

final BigDecimal amount = this.fromApiJsonHelper.extractBigDecimalNamed("amount", loanChargeElement, locale);
final BigDecimal amount = this.fromApiJsonHelper.extractBigDecimalNamed("amount", loanChargeElement, localeAmount);
baseDataValidator.reset().parameter("charges").parameterAtIndexArray("amount", i).value(amount).notNull()
.positiveAmount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
import java.util.Locale;
import java.util.Set;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationProperty;
import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationRepositoryWrapper;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.core.serialization.JsonParserHelper;
import org.apache.fineract.portfolio.charge.domain.Charge;
import org.apache.fineract.portfolio.charge.domain.ChargeCalculationType;
import org.apache.fineract.portfolio.charge.domain.ChargePaymentMode;
Expand All @@ -57,14 +60,17 @@ public class LoanChargeAssembler {
private final ChargeRepositoryWrapper chargeRepository;
private final LoanChargeRepository loanChargeRepository;
private final LoanProductRepository loanProductRepository;
private final GlobalConfigurationRepositoryWrapper globalConfigurationRepositoryWrapper;

@Autowired
public LoanChargeAssembler(final FromJsonHelper fromApiJsonHelper, final ChargeRepositoryWrapper chargeRepository,
final LoanChargeRepository loanChargeRepository, final LoanProductRepository loanProductRepository) {
final LoanChargeRepository loanChargeRepository, final LoanProductRepository loanProductRepository,
final GlobalConfigurationRepositoryWrapper globalConfigurationRepositoryWrapper) {
this.fromApiJsonHelper = fromApiJsonHelper;
this.chargeRepository = chargeRepository;
this.loanChargeRepository = loanChargeRepository;
this.loanProductRepository = loanProductRepository;
this.globalConfigurationRepositoryWrapper = globalConfigurationRepositoryWrapper;
}

public Set<LoanCharge> fromParsedJson(JsonElement element, List<LoanDisbursementDetails> disbursementDetails,
Expand Down Expand Up @@ -105,6 +111,13 @@ public Set<LoanCharge> fromParsedJson(JsonElement element, List<LoanDisbursement
final JsonObject topLevelJsonElement = element.getAsJsonObject();
final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement);
final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
Locale localeAmount = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
GlobalConfigurationProperty maintainAmountFormatToEN = this.globalConfigurationRepositoryWrapper
.findOneByNameWithNotFoundDetection("maintainAmountFormatToEN");
if (maintainAmountFormatToEN.isEnabled()) {
localeAmount = JsonParserHelper.localeFromString("en");
}

if (topLevelJsonElement.has("charges") && topLevelJsonElement.get("charges").isJsonArray()) {
final JsonArray array = topLevelJsonElement.get("charges").getAsJsonArray();
for (int i = 0; i < array.size(); i++) {
Expand All @@ -113,7 +126,7 @@ public Set<LoanCharge> fromParsedJson(JsonElement element, List<LoanDisbursement

final Long id = this.fromApiJsonHelper.extractLongNamed("id", loanChargeElement);
final Long chargeId = this.fromApiJsonHelper.extractLongNamed("chargeId", loanChargeElement);
BigDecimal amount = this.fromApiJsonHelper.extractBigDecimalNamed("amount", loanChargeElement, locale);
BigDecimal amount = this.fromApiJsonHelper.extractBigDecimalNamed("amount", loanChargeElement, localeAmount);
final Integer chargeTimeType = this.fromApiJsonHelper.extractIntegerNamed("chargeTimeType", loanChargeElement, locale);
final Integer chargeCalculationType = this.fromApiJsonHelper.extractIntegerNamed("chargeCalculationType",
loanChargeElement, locale);
Expand Down

0 comments on commit cf19fc6

Please sign in to comment.