List of usage examples for com.google.gson JsonArray get
public JsonElement get(int i)
From source file:com.gst.portfolio.loanaccount.serialization.LoanApplicationCommandFromApiJsonHelper.java
License:Apache License
public void validateLoanMultiDisbursementdate(final JsonElement element, final DataValidatorBuilder baseDataValidator, LocalDate expectedDisbursement, BigDecimal totalPrincipal) { this.validateDisbursementsAreDatewiseOrdered(element, baseDataValidator); final JsonObject topLevelJsonElement = element.getAsJsonObject(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement); if (this.fromApiJsonHelper.parameterExists(LoanApiConstants.disbursementDataParameterName, element) && expectedDisbursement != null && totalPrincipal != null) { BigDecimal tatalDisbursement = BigDecimal.ZERO; boolean isFirstinstallmentOnExpectedDisbursementDate = false; final JsonArray variationArray = this.fromApiJsonHelper .extractJsonArrayNamed(LoanApiConstants.disbursementDataParameterName, element); List<LocalDate> expectedDisbursementDates = new ArrayList<>(); if (variationArray != null && variationArray.size() > 0) { int i = 0; do {//from ww w . j a v a2 s . c o m final JsonObject jsonObject = variationArray.get(i).getAsJsonObject(); if (jsonObject.has(LoanApiConstants.disbursementDateParameterName) && jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName)) { LocalDate expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed( LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale); if (expectedDisbursementDates.contains(expectedDisbursementDate)) { baseDataValidator.reset().parameter(LoanApiConstants.disbursementDateParameterName) .failWithCode(LoanApiConstants.DISBURSEMENT_DATE_UNIQUE_ERROR); } if (expectedDisbursementDate.isBefore(expectedDisbursement)) { baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName) .failWithCode(LoanApiConstants.DISBURSEMENT_DATE_BEFORE_ERROR); } expectedDisbursementDates.add(expectedDisbursementDate); BigDecimal principal = this.fromApiJsonHelper.extractBigDecimalNamed( LoanApiConstants.disbursementPrincipalParameterName, jsonObject, locale); baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName) .parameterAtIndexArray(LoanApiConstants.disbursementPrincipalParameterName, i) .value(principal).notBlank(); if (principal != null) { tatalDisbursement = tatalDisbursement.add(principal); } baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName) .parameterAtIndexArray(LoanApiConstants.disbursementDateParameterName, i) .value(expectedDisbursementDate).notNull(); if (expectedDisbursement.equals(expectedDisbursementDate)) { isFirstinstallmentOnExpectedDisbursementDate = true; } } i++; } while (i < variationArray.size()); if (!isFirstinstallmentOnExpectedDisbursementDate) { baseDataValidator.reset().parameter(LoanApiConstants.disbursementDateParameterName) .failWithCode(LoanApiConstants.DISBURSEMENT_DATE_START_WITH_ERROR); } if (tatalDisbursement.compareTo(totalPrincipal) == 1) { baseDataValidator.reset().parameter(LoanApiConstants.disbursementPrincipalParameterName) .failWithCode(LoanApiConstants.APPROVED_AMOUNT_IS_LESS_THAN_SUM_OF_TRANCHES); } final String interestTypeParameterName = "interestType"; final Integer interestType = this.fromApiJsonHelper .extractIntegerSansLocaleNamed(interestTypeParameterName, element); baseDataValidator.reset().parameter(interestTypeParameterName).value(interestType).ignoreIfNull() .integerSameAsNumber(InterestMethod.DECLINING_BALANCE.getValue()); } } }
From source file:com.gst.portfolio.loanaccount.serialization.VariableLoanScheduleFromApiJsonValidator.java
License:Apache License
private void validateLoanTermVariations(final Loan loan, final DataValidatorBuilder baseDataValidator, final String dateFormat, final Locale locale, final JsonArray modificationsArray, final Set<String> supportParams, final String arrayName) { for (int i = 1; i <= modificationsArray.size(); i++) { final JsonObject arrayElement = modificationsArray.get(i - 1).getAsJsonObject(); this.fromApiJsonHelper.checkForUnsupportedParameters(arrayElement, supportParams); final BigDecimal installmentAmount = this.fromApiJsonHelper .extractBigDecimalNamed(LoanApiConstants.installmentAmountParamName, arrayElement, locale); baseDataValidator.reset().parameter(arrayName) .parameterAtIndexArray(LoanApiConstants.installmentAmountParamName, i).value(installmentAmount) .positiveAmount();/* w w w. ja v a 2s .c o m*/ final BigDecimal principalAmount = this.fromApiJsonHelper .extractBigDecimalNamed(LoanApiConstants.principalParamName, arrayElement, locale); baseDataValidator.reset().parameter(arrayName) .parameterAtIndexArray(LoanApiConstants.principalParamName, i).value(principalAmount) .zeroOrPositiveAmount(); if (loan.getLoanProductRelatedDetail().getInterestMethod().isDecliningBalnce() && loan.getLoanProductRelatedDetail().getAmortizationMethod().isEqualInstallment() && principalAmount != null) { List<String> unsupportedParams = new ArrayList<>(1); unsupportedParams.add(LoanApiConstants.principalParamName); throw new UnsupportedParameterException(unsupportedParams); } else if ((!loan.getLoanProductRelatedDetail().getInterestMethod().isDecliningBalnce() || loan.getLoanProductRelatedDetail().getAmortizationMethod().isEqualPrincipal()) && installmentAmount != null) { List<String> unsupportedParams = new ArrayList<>(1); unsupportedParams.add(LoanApiConstants.installmentAmountParamName); throw new UnsupportedParameterException(unsupportedParams); } LocalDate duedate = this.fromApiJsonHelper.extractLocalDateNamed(LoanApiConstants.dueDateParamName, arrayElement, dateFormat, locale); baseDataValidator.reset().parameter(arrayName) .parameterAtIndexArray(LoanApiConstants.dueDateParamName, i).value(duedate).notNull() .validateDateAfter(loan.getExpectedDisbursedOnLocalDate()); LocalDate modifiedDuedate = this.fromApiJsonHelper.extractLocalDateNamed( LoanApiConstants.modifiedDueDateParamName, arrayElement, dateFormat, locale); baseDataValidator.reset().parameter(arrayName) .parameterAtIndexArray(LoanApiConstants.modifiedDueDateParamName, i).value(modifiedDuedate) .validateDateAfter(loan.getExpectedDisbursedOnLocalDate()); if (arrayName.equals(LoanApiConstants.modifiedinstallmentsParamName) && modifiedDuedate == null && installmentAmount == null && principalAmount == null) { baseDataValidator.reset().parameter(arrayName).failWithCode("variation.required", "At least one vario"); } } }
From source file:com.gst.portfolio.loanaccount.service.LoanChargeAssembler.java
License:Apache License
public Set<LoanCharge> fromParsedJson(final JsonElement element, List<LoanDisbursementDetails> disbursementDetails) { JsonArray jsonDisbursement = this.fromApiJsonHelper.extractJsonArrayNamed("disbursementData", element); List<Long> disbursementChargeIds = new ArrayList<>(); if (jsonDisbursement != null && jsonDisbursement.size() > 0) { for (int i = 0; i < jsonDisbursement.size(); i++) { final JsonObject jsonObject = jsonDisbursement.get(i).getAsJsonObject(); if (jsonObject != null && jsonObject.getAsJsonPrimitive(LoanApiConstants.loanChargeIdParameterName) != null) { String chargeIds = jsonObject.getAsJsonPrimitive(LoanApiConstants.loanChargeIdParameterName) .getAsString();// w ww. j av a2 s . c om if (chargeIds != null) { if (chargeIds.indexOf(",") != -1) { String[] chargeId = chargeIds.split(","); for (String loanChargeId : chargeId) { disbursementChargeIds.add(Long.parseLong(loanChargeId)); } } else { disbursementChargeIds.add(Long.parseLong(chargeIds)); } } } } } final Set<LoanCharge> loanCharges = new HashSet<>(); final BigDecimal principal = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("principal", element); final Integer numberOfRepayments = this.fromApiJsonHelper .extractIntegerWithLocaleNamed("numberOfRepayments", element); final Long productId = this.fromApiJsonHelper.extractLongNamed("productId", element); final LoanProduct loanProduct = this.loanProductRepository.findOne(productId); if (loanProduct == null) { throw new LoanProductNotFoundException(productId); } final boolean isMultiDisbursal = loanProduct.isMultiDisburseLoan(); LocalDate expectedDisbursementDate = null; if (element.isJsonObject()) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); if (topLevelJsonElement.has("charges") && topLevelJsonElement.get("charges").isJsonArray()) { final JsonArray array = topLevelJsonElement.get("charges").getAsJsonArray(); for (int i = 0; i < array.size(); i++) { final JsonObject loanChargeElement = array.get(i).getAsJsonObject(); final Long id = this.fromApiJsonHelper.extractLongNamed("id", loanChargeElement); final Long chargeId = this.fromApiJsonHelper.extractLongNamed("chargeId", loanChargeElement); final BigDecimal amount = this.fromApiJsonHelper.extractBigDecimalNamed("amount", loanChargeElement, locale); final Integer chargeTimeType = this.fromApiJsonHelper.extractIntegerNamed("chargeTimeType", loanChargeElement, locale); final Integer chargeCalculationType = this.fromApiJsonHelper .extractIntegerNamed("chargeCalculationType", loanChargeElement, locale); final LocalDate dueDate = this.fromApiJsonHelper.extractLocalDateNamed("dueDate", loanChargeElement, dateFormat, locale); final Integer chargePaymentMode = this.fromApiJsonHelper .extractIntegerNamed("chargePaymentMode", loanChargeElement, locale); if (id == null) { final Charge chargeDefinition = this.chargeRepository .findOneWithNotFoundDetection(chargeId); if (chargeDefinition.isOverdueInstallment()) { final String defaultUserMessage = "Installment charge cannot be added to the loan."; throw new LoanChargeCannotBeAddedException("loanCharge", "overdue.charge", defaultUserMessage, null, chargeDefinition.getName()); } ChargeTimeType chargeTime = null; if (chargeTimeType != null) { chargeTime = ChargeTimeType.fromInt(chargeTimeType); } ChargeCalculationType chargeCalculation = null; if (chargeCalculationType != null) { chargeCalculation = ChargeCalculationType.fromInt(chargeCalculationType); } ChargePaymentMode chargePaymentModeEnum = null; if (chargePaymentMode != null) { chargePaymentModeEnum = ChargePaymentMode.fromInt(chargePaymentMode); } if (!isMultiDisbursal) { final LoanCharge loanCharge = LoanCharge.createNewWithoutLoan(chargeDefinition, principal, amount, chargeTime, chargeCalculation, dueDate, chargePaymentModeEnum, numberOfRepayments); loanCharges.add(loanCharge); } else { if (topLevelJsonElement.has("disbursementData") && topLevelJsonElement.get("disbursementData").isJsonArray()) { final JsonArray disbursementArray = topLevelJsonElement.get("disbursementData") .getAsJsonArray(); if (disbursementArray.size() > 0) { JsonObject disbursementDataElement = disbursementArray.get(0).getAsJsonObject(); expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed( LoanApiConstants.disbursementDateParameterName, disbursementDataElement, dateFormat, locale); } } if (ChargeTimeType.DISBURSEMENT.getValue() .equals(chargeDefinition.getChargeTimeType())) { for (LoanDisbursementDetails disbursementDetail : disbursementDetails) { LoanTrancheDisbursementCharge loanTrancheDisbursementCharge = null; if (chargeDefinition.isPercentageOfApprovedAmount() && disbursementDetail.expectedDisbursementDateAsLocalDate() .equals(expectedDisbursementDate)) { final LoanCharge loanCharge = LoanCharge.createNewWithoutLoan( chargeDefinition, principal, amount, chargeTime, chargeCalculation, dueDate, chargePaymentModeEnum, numberOfRepayments); loanCharges.add(loanCharge); if (loanCharge.isTrancheDisbursementCharge()) { loanTrancheDisbursementCharge = new LoanTrancheDisbursementCharge( loanCharge, disbursementDetail); loanCharge.updateLoanTrancheDisbursementCharge( loanTrancheDisbursementCharge); } } else { if (disbursementDetail.expectedDisbursementDateAsLocalDate() .equals(expectedDisbursementDate)) { final LoanCharge loanCharge = LoanCharge.createNewWithoutLoan( chargeDefinition, disbursementDetail.principal(), amount, chargeTime, chargeCalculation, disbursementDetail.expectedDisbursementDateAsLocalDate(), chargePaymentModeEnum, numberOfRepayments); loanCharges.add(loanCharge); if (loanCharge.isTrancheDisbursementCharge()) { loanTrancheDisbursementCharge = new LoanTrancheDisbursementCharge( loanCharge, disbursementDetail); loanCharge.updateLoanTrancheDisbursementCharge( loanTrancheDisbursementCharge); } } } } } else if (ChargeTimeType.TRANCHE_DISBURSEMENT.getValue() .equals(chargeDefinition.getChargeTimeType())) { LoanTrancheDisbursementCharge loanTrancheDisbursementCharge = null; for (LoanDisbursementDetails disbursementDetail : disbursementDetails) { if (ChargeTimeType.TRANCHE_DISBURSEMENT.getValue() .equals(chargeDefinition.getChargeTimeType())) { final LoanCharge loanCharge = LoanCharge.createNewWithoutLoan( chargeDefinition, disbursementDetail.principal(), amount, chargeTime, chargeCalculation, disbursementDetail.expectedDisbursementDateAsLocalDate(), chargePaymentModeEnum, numberOfRepayments); loanCharges.add(loanCharge); loanTrancheDisbursementCharge = new LoanTrancheDisbursementCharge( loanCharge, disbursementDetail); loanCharge .updateLoanTrancheDisbursementCharge(loanTrancheDisbursementCharge); } } } else { final LoanCharge loanCharge = LoanCharge.createNewWithoutLoan(chargeDefinition, principal, amount, chargeTime, chargeCalculation, dueDate, chargePaymentModeEnum, numberOfRepayments); loanCharges.add(loanCharge); } } } else { final Long loanChargeId = id; final LoanCharge loanCharge = this.loanChargeRepository.findOne(loanChargeId); if (loanCharge != null) { if (!loanCharge.isTrancheDisbursementCharge() || disbursementChargeIds.contains(loanChargeId)) { loanCharge.update(amount, dueDate, numberOfRepayments); loanCharges.add(loanCharge); } } } } } } return loanCharges; }
From source file:com.gst.portfolio.loanaccount.service.LoanChargeAssembler.java
License:Apache License
public Set<Charge> getNewLoanTrancheCharges(final JsonElement element) { final Set<Charge> associatedChargesForLoan = new HashSet<>(); if (element.isJsonObject()) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); if (topLevelJsonElement.has("charges") && topLevelJsonElement.get("charges").isJsonArray()) { final JsonArray array = topLevelJsonElement.get("charges").getAsJsonArray(); for (int i = 0; i < array.size(); i++) { final JsonObject loanChargeElement = array.get(i).getAsJsonObject(); final Long id = this.fromApiJsonHelper.extractLongNamed("id", loanChargeElement); final Long chargeId = this.fromApiJsonHelper.extractLongNamed("chargeId", loanChargeElement); if (id == null) { final Charge chargeDefinition = this.chargeRepository .findOneWithNotFoundDetection(chargeId); if (chargeDefinition.getChargeTimeType() == ChargeTimeType.TRANCHE_DISBURSEMENT .getValue()) { associatedChargesForLoan.add(chargeDefinition); }//from w w w. j a va 2 s . c o m } } } } return associatedChargesForLoan; }
From source file:com.gst.portfolio.loanaccount.service.LoanUtilService.java
License:Apache License
public List<LoanDisbursementDetails> fetchDisbursementData(final JsonObject command) { final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(command); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(command); List<LoanDisbursementDetails> disbursementDatas = new ArrayList<>(); if (command.has(LoanApiConstants.disbursementDataParameterName)) { final JsonArray disbursementDataArray = command .getAsJsonArray(LoanApiConstants.disbursementDataParameterName); if (disbursementDataArray != null && disbursementDataArray.size() > 0) { int i = 0; do {/*w w w.j a va 2 s . c om*/ final JsonObject jsonObject = disbursementDataArray.get(i).getAsJsonObject(); Date expectedDisbursementDate = null; Date actualDisbursementDate = null; BigDecimal principal = null; if (jsonObject.has(LoanApiConstants.disbursementDateParameterName)) { LocalDate date = this.fromApiJsonHelper.extractLocalDateNamed( LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale); if (date != null) { expectedDisbursementDate = date.toDate(); } } if (jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName) && jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).isJsonPrimitive() && StringUtils.isNotBlank((jsonObject .get(LoanApiConstants.disbursementPrincipalParameterName).getAsString()))) { principal = jsonObject .getAsJsonPrimitive(LoanApiConstants.disbursementPrincipalParameterName) .getAsBigDecimal(); } disbursementDatas.add(new LoanDisbursementDetails(expectedDisbursementDate, actualDisbursementDate, principal)); i++; } while (i < disbursementDataArray.size()); } } return disbursementDatas; }
From source file:com.gst.portfolio.loanproduct.domain.LoanProduct.java
License:Apache License
private static void assembleVaritions(final JsonCommand command, final Set<LoanProductBorrowerCycleVariations> loanProductBorrowerCycleVariations, Integer paramType, String variationParameterName) { if (command.parameterExists(variationParameterName)) { final JsonArray variationArray = command.arrayOfParameterNamed(variationParameterName); if (variationArray != null && variationArray.size() > 0) { int i = 0; do {// w w w . j a v a 2s.c o m final JsonObject jsonObject = variationArray.get(i).getAsJsonObject(); BigDecimal defaultValue = null; BigDecimal minValue = null; BigDecimal maxValue = null; Integer cycleNumber = null; Integer valueUsageCondition = null; if (jsonObject.has(LoanProductConstants.defaultValueParameterName) && jsonObject.get(LoanProductConstants.defaultValueParameterName).isJsonPrimitive()) { defaultValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.defaultValueParameterName) .getAsBigDecimal(); } if (jsonObject.has(LoanProductConstants.minValueParameterName) && jsonObject.get(LoanProductConstants.minValueParameterName).isJsonPrimitive() && StringUtils.isNotBlank( (jsonObject.get(LoanProductConstants.minValueParameterName).getAsString()))) { minValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.minValueParameterName) .getAsBigDecimal(); } if (jsonObject.has(LoanProductConstants.maxValueParameterName) && jsonObject.get(LoanProductConstants.maxValueParameterName).isJsonPrimitive() && StringUtils.isNotBlank( (jsonObject.get(LoanProductConstants.maxValueParameterName).getAsString()))) { maxValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.maxValueParameterName) .getAsBigDecimal(); } if (jsonObject.has(LoanProductConstants.borrowerCycleNumberParamName) && jsonObject .get(LoanProductConstants.borrowerCycleNumberParamName).isJsonPrimitive()) { cycleNumber = jsonObject .getAsJsonPrimitive(LoanProductConstants.borrowerCycleNumberParamName).getAsInt(); } if (jsonObject.has(LoanProductConstants.valueConditionTypeParamName) && jsonObject.get(LoanProductConstants.valueConditionTypeParamName).isJsonPrimitive()) { valueUsageCondition = jsonObject .getAsJsonPrimitive(LoanProductConstants.valueConditionTypeParamName).getAsInt(); } LoanProductBorrowerCycleVariations borrowerCycleVariations = new LoanProductBorrowerCycleVariations( cycleNumber, paramType, valueUsageCondition, minValue, maxValue, defaultValue); loanProductBorrowerCycleVariations.add(borrowerCycleVariations); i++; } while (i < variationArray.size()); } } }
From source file:com.gst.portfolio.loanproduct.domain.LoanProduct.java
License:Apache License
private void updateBorrowerCycleVaritions(final JsonCommand command, Integer paramType, String variationParameterName, final Map<String, Object> actualChanges, List<Long> variationIds) { if (command.parameterExists(variationParameterName)) { final JsonArray variationArray = command.arrayOfParameterNamed(variationParameterName); if (variationArray != null && variationArray.size() > 0) { int i = 0; do {//from w w w . ja v a2 s . c om final JsonObject jsonObject = variationArray.get(i).getAsJsonObject(); BigDecimal defaultValue = null; BigDecimal minValue = null; BigDecimal maxValue = null; Integer cycleNumber = null; Integer valueUsageCondition = null; Long id = null; if (jsonObject.has(LoanProductConstants.defaultValueParameterName) && jsonObject.get(LoanProductConstants.defaultValueParameterName).isJsonPrimitive()) { defaultValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.defaultValueParameterName) .getAsBigDecimal(); } if (jsonObject.has(LoanProductConstants.minValueParameterName) && jsonObject.get(LoanProductConstants.minValueParameterName).isJsonPrimitive() && StringUtils.isNotBlank( (jsonObject.get(LoanProductConstants.minValueParameterName).getAsString()))) { minValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.minValueParameterName) .getAsBigDecimal(); } if (jsonObject.has(LoanProductConstants.maxValueParameterName) && jsonObject.get(LoanProductConstants.maxValueParameterName).isJsonPrimitive() && StringUtils.isNotBlank( (jsonObject.get(LoanProductConstants.maxValueParameterName).getAsString()))) { maxValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.maxValueParameterName) .getAsBigDecimal(); } if (jsonObject.has(LoanProductConstants.borrowerCycleNumberParamName) && jsonObject .get(LoanProductConstants.borrowerCycleNumberParamName).isJsonPrimitive()) { cycleNumber = jsonObject .getAsJsonPrimitive(LoanProductConstants.borrowerCycleNumberParamName).getAsInt(); } if (jsonObject.has(LoanProductConstants.valueConditionTypeParamName) && jsonObject.get(LoanProductConstants.valueConditionTypeParamName).isJsonPrimitive()) { valueUsageCondition = jsonObject .getAsJsonPrimitive(LoanProductConstants.valueConditionTypeParamName).getAsInt(); } if (jsonObject.has(LoanProductConstants.borrowerCycleIdParameterName) && jsonObject.get(LoanProductConstants.borrowerCycleIdParameterName).isJsonPrimitive() && StringUtils.isNotBlank((jsonObject .get(LoanProductConstants.borrowerCycleIdParameterName).getAsString()))) { id = jsonObject.getAsJsonPrimitive(LoanProductConstants.borrowerCycleIdParameterName) .getAsLong(); } LoanProductBorrowerCycleVariations borrowerCycleVariations = new LoanProductBorrowerCycleVariations( cycleNumber, paramType, valueUsageCondition, minValue, maxValue, defaultValue); if (id == null) { borrowerCycleVariations.updateLoanProduct(this); this.borrowerCycleVariations.add(borrowerCycleVariations); actualChanges.put("borrowerCycleParamType", paramType); } else { variationIds.remove(id); LoanProductBorrowerCycleVariations existingCycleVariation = fetchLoanProductBorrowerCycleVariationById( id); if (!existingCycleVariation.equals(borrowerCycleVariations)) { existingCycleVariation.copy(borrowerCycleVariations); actualChanges.put("borrowerCycleId", id); } } i++; } while (i < variationArray.size()); } } }
From source file:com.gst.portfolio.loanproduct.serialization.LoanProductDataValidator.java
License:Apache License
private void validatePaymentChannelFundSourceMappings(final DataValidatorBuilder baseDataValidator, final JsonElement element) { if (this.fromApiJsonHelper.parameterExists( LOAN_PRODUCT_ACCOUNTING_PARAMS.PAYMENT_CHANNEL_FUND_SOURCE_MAPPING.getValue(), element)) { final JsonArray paymentChannelMappingArray = this.fromApiJsonHelper.extractJsonArrayNamed( LOAN_PRODUCT_ACCOUNTING_PARAMS.PAYMENT_CHANNEL_FUND_SOURCE_MAPPING.getValue(), element); if (paymentChannelMappingArray != null && paymentChannelMappingArray.size() > 0) { int i = 0; do {//from w w w. ja v a 2 s . c o m final JsonObject jsonObject = paymentChannelMappingArray.get(i).getAsJsonObject(); final Long paymentTypeId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.PAYMENT_TYPE.getValue(), jsonObject); final Long paymentSpecificFundAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.FUND_SOURCE.getValue(), jsonObject); baseDataValidator.reset() .parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.PAYMENT_CHANNEL_FUND_SOURCE_MAPPING.getValue() + "[" + i + "]." + LOAN_PRODUCT_ACCOUNTING_PARAMS.PAYMENT_TYPE.getValue()) .value(paymentTypeId).notNull().integerGreaterThanZero(); baseDataValidator.reset() .parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.PAYMENT_CHANNEL_FUND_SOURCE_MAPPING.getValue() + "[" + i + "]." + LOAN_PRODUCT_ACCOUNTING_PARAMS.FUND_SOURCE.getValue()) .value(paymentSpecificFundAccountId).notNull().integerGreaterThanZero(); i++; } while (i < paymentChannelMappingArray.size()); } } }
From source file:com.gst.portfolio.loanproduct.serialization.LoanProductDataValidator.java
License:Apache License
private void validateChargeToIncomeAccountMappings(final DataValidatorBuilder baseDataValidator, final JsonElement element, final boolean isPenalty) { String parameterName;/* w w w . j a v a2 s. c o m*/ if (isPenalty) { parameterName = LOAN_PRODUCT_ACCOUNTING_PARAMS.PENALTY_INCOME_ACCOUNT_MAPPING.getValue(); } else { parameterName = LOAN_PRODUCT_ACCOUNTING_PARAMS.FEE_INCOME_ACCOUNT_MAPPING.getValue(); } if (this.fromApiJsonHelper.parameterExists(parameterName, element)) { final JsonArray chargeToIncomeAccountMappingArray = this.fromApiJsonHelper .extractJsonArrayNamed(parameterName, element); if (chargeToIncomeAccountMappingArray != null && chargeToIncomeAccountMappingArray.size() > 0) { int i = 0; do { final JsonObject jsonObject = chargeToIncomeAccountMappingArray.get(i).getAsJsonObject(); final Long chargeId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.CHARGE_ID.getValue(), jsonObject); final Long incomeAccountId = this.fromApiJsonHelper.extractLongNamed( LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_ACCOUNT_ID.getValue(), jsonObject); baseDataValidator.reset() .parameter(parameterName + "[" + i + "]." + LOAN_PRODUCT_ACCOUNTING_PARAMS.CHARGE_ID.getValue()) .value(chargeId).notNull().integerGreaterThanZero(); baseDataValidator.reset() .parameter(parameterName + "[" + i + "]." + LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_ACCOUNT_ID.getValue()) .value(incomeAccountId).notNull().integerGreaterThanZero(); i++; } while (i < chargeToIncomeAccountMappingArray.size()); } } }
From source file:com.gst.portfolio.loanproduct.serialization.LoanProductDataValidator.java
License:Apache License
private void validateBorrowerCycleVariations(final JsonElement element, final DataValidatorBuilder baseDataValidator, final String variationParameterName, final String defaultParameterName, final String minParameterName, final String maxParameterName, final String valueUsageConditionParamName, final String cycleNumbersParamName) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); Integer lastCycleNumber = 0;//w w w. j ava2 s .c o m LoanProductValueConditionType lastConditionType = LoanProductValueConditionType.EQUAL; if (this.fromApiJsonHelper.parameterExists(variationParameterName, element)) { final JsonArray variationArray = this.fromApiJsonHelper.extractJsonArrayNamed(variationParameterName, element); if (variationArray != null && variationArray.size() > 0) { int i = 0; do { final JsonObject jsonObject = variationArray.get(i).getAsJsonObject(); BigDecimal defaultValue = this.fromApiJsonHelper.extractBigDecimalNamed( LoanProductConstants.defaultValueParameterName, jsonObject, locale); BigDecimal minValue = this.fromApiJsonHelper .extractBigDecimalNamed(LoanProductConstants.minValueParameterName, jsonObject, locale); BigDecimal maxValue = this.fromApiJsonHelper .extractBigDecimalNamed(LoanProductConstants.maxValueParameterName, jsonObject, locale); Integer cycleNumber = this.fromApiJsonHelper.extractIntegerNamed( LoanProductConstants.borrowerCycleNumberParamName, jsonObject, locale); Integer valueUsageCondition = this.fromApiJsonHelper.extractIntegerNamed( LoanProductConstants.valueConditionTypeParamName, jsonObject, locale); baseDataValidator.reset().parameter(defaultParameterName).value(defaultValue).notBlank(); if (minValue != null) { baseDataValidator.reset().parameter(minParameterName).value(minValue) .notGreaterThanMax(maxValue); } if (maxValue != null) { baseDataValidator.reset().parameter(maxParameterName).value(maxValue) .notLessThanMin(minValue); } if ((minValue != null && minValue.compareTo(BigDecimal.ZERO) == 1) && (maxValue != null && maxValue.compareTo(BigDecimal.ZERO) == 1)) { baseDataValidator.reset().parameter(defaultParameterName).value(defaultValue) .inMinAndMaxAmountRange(minValue, maxValue); } else { if (minValue != null && minValue.compareTo(BigDecimal.ZERO) == 1) { baseDataValidator.reset().parameter(defaultParameterName).value(defaultValue) .notLessThanMin(minValue); } else if (maxValue != null && maxValue.compareTo(BigDecimal.ZERO) == 1) { baseDataValidator.reset().parameter(defaultParameterName).value(defaultValue) .notGreaterThanMax(maxValue); } } LoanProductValueConditionType conditionType = LoanProductValueConditionType.INVALID; if (valueUsageCondition != null) { conditionType = LoanProductValueConditionType.fromInt(valueUsageCondition); } baseDataValidator.reset().parameter(valueUsageConditionParamName).value(valueUsageCondition) .notNull().inMinMaxRange(LoanProductValueConditionType.EQUAL.getValue(), LoanProductValueConditionType.GREATERTHAN.getValue()); if (lastConditionType.equals(LoanProductValueConditionType.EQUAL) && conditionType.equals(LoanProductValueConditionType.GREATERTHAN)) { if (lastCycleNumber == 0) { baseDataValidator.reset().parameter(cycleNumbersParamName) .failWithCode(LoanProductConstants.VALUE_CONDITION_START_WITH_ERROR); lastCycleNumber = 1; } baseDataValidator.reset().parameter(cycleNumbersParamName).value(cycleNumber).notNull() .integerSameAsNumber(lastCycleNumber); } else if (lastConditionType.equals(LoanProductValueConditionType.EQUAL)) { baseDataValidator.reset().parameter(cycleNumbersParamName).value(cycleNumber).notNull() .integerSameAsNumber(lastCycleNumber + 1); } else if (lastConditionType.equals(LoanProductValueConditionType.GREATERTHAN)) { baseDataValidator.reset().parameter(cycleNumbersParamName).value(cycleNumber).notNull() .integerGreaterThanNumber(lastCycleNumber); } if (conditionType != null) { lastConditionType = conditionType; } if (cycleNumber != null) { lastCycleNumber = cycleNumber; } i++; } while (i < variationArray.size()); if (!lastConditionType.equals(LoanProductValueConditionType.GREATERTHAN)) { baseDataValidator.reset().parameter(cycleNumbersParamName) .failWithCode(LoanProductConstants.VALUE_CONDITION_END_WITH_ERROR); } } } }