List of usage examples for java.math BigDecimal compareTo
@Override public int compareTo(BigDecimal val)
From source file:org.apache.fineract.portfolio.loanproduct.serialization.LoanProductDataValidator.java
public void validateForCreate(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }// www. j av a 2 s . c o m final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("loanproduct"); final JsonElement element = this.fromApiJsonHelper.parse(json); final String name = this.fromApiJsonHelper.extractStringNamed("name", element); baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(100); final String shortName = this.fromApiJsonHelper.extractStringNamed(LoanProductConstants.shortName, element); baseDataValidator.reset().parameter(LoanProductConstants.shortName).value(shortName).notBlank() .notExceedingLengthOf(4); final String description = this.fromApiJsonHelper.extractStringNamed("description", element); baseDataValidator.reset().parameter("description").value(description).notExceedingLengthOf(500); if (this.fromApiJsonHelper.parameterExists("fundId", element)) { final Long fundId = this.fromApiJsonHelper.extractLongNamed("fundId", element); baseDataValidator.reset().parameter("fundId").value(fundId).ignoreIfNull().integerGreaterThanZero(); } if (this.fromApiJsonHelper .parameterExists(LoanProductConstants.minimumDaysBetweenDisbursalAndFirstRepayment, element)) { final Long minimumDaysBetweenDisbursalAndFirstRepayment = this.fromApiJsonHelper .extractLongNamed(LoanProductConstants.minimumDaysBetweenDisbursalAndFirstRepayment, element); baseDataValidator.reset().parameter(LoanProductConstants.minimumDaysBetweenDisbursalAndFirstRepayment) .value(minimumDaysBetweenDisbursalAndFirstRepayment).ignoreIfNull().integerGreaterThanZero(); } final Boolean includeInBorrowerCycle = this.fromApiJsonHelper.extractBooleanNamed("includeInBorrowerCycle", element); baseDataValidator.reset().parameter("includeInBorrowerCycle").value(includeInBorrowerCycle).ignoreIfNull() .validateForBooleanValue(); // terms final String currencyCode = this.fromApiJsonHelper.extractStringNamed("currencyCode", element); baseDataValidator.reset().parameter("currencyCode").value(currencyCode).notBlank().notExceedingLengthOf(3); final Integer digitsAfterDecimal = this.fromApiJsonHelper.extractIntegerNamed("digitsAfterDecimal", element, Locale.getDefault()); baseDataValidator.reset().parameter("digitsAfterDecimal").value(digitsAfterDecimal).notNull() .inMinMaxRange(0, 6); final Integer inMultiplesOf = this.fromApiJsonHelper.extractIntegerNamed("inMultiplesOf", element, Locale.getDefault()); baseDataValidator.reset().parameter("inMultiplesOf").value(inMultiplesOf).ignoreIfNull() .integerZeroOrGreater(); final BigDecimal principal = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("principal", element); baseDataValidator.reset().parameter("principal").value(principal).positiveAmount(); final String minPrincipalParameterName = "minPrincipal"; BigDecimal minPrincipalAmount = null; if (this.fromApiJsonHelper.parameterExists(minPrincipalParameterName, element)) { minPrincipalAmount = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(minPrincipalParameterName, element); baseDataValidator.reset().parameter(minPrincipalParameterName).value(minPrincipalAmount).ignoreIfNull() .positiveAmount(); } final String maxPrincipalParameterName = "maxPrincipal"; BigDecimal maxPrincipalAmount = null; if (this.fromApiJsonHelper.parameterExists(maxPrincipalParameterName, element)) { maxPrincipalAmount = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(maxPrincipalParameterName, element); baseDataValidator.reset().parameter(maxPrincipalParameterName).value(maxPrincipalAmount).ignoreIfNull() .positiveAmount(); } if (maxPrincipalAmount != null && maxPrincipalAmount.compareTo(BigDecimal.ZERO) != -1) { if (minPrincipalAmount != null && minPrincipalAmount.compareTo(BigDecimal.ZERO) != -1) { baseDataValidator.reset().parameter(maxPrincipalParameterName).value(maxPrincipalAmount) .notLessThanMin(minPrincipalAmount); if (minPrincipalAmount.compareTo(maxPrincipalAmount) <= 0 && principal != null) { baseDataValidator.reset().parameter("principal").value(principal) .inMinAndMaxAmountRange(minPrincipalAmount, maxPrincipalAmount); } } else if (principal != null) { baseDataValidator.reset().parameter("principal").value(principal) .notGreaterThanMax(maxPrincipalAmount); } } else if (minPrincipalAmount != null && minPrincipalAmount.compareTo(BigDecimal.ZERO) != -1 && principal != null) { baseDataValidator.reset().parameter("principal").value(principal).notLessThanMin(minPrincipalAmount); } final Integer numberOfRepayments = this.fromApiJsonHelper .extractIntegerWithLocaleNamed("numberOfRepayments", element); baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments).notNull() .integerGreaterThanZero(); final String minNumberOfRepaymentsParameterName = "minNumberOfRepayments"; Integer minNumberOfRepayments = null; if (this.fromApiJsonHelper.parameterExists(minNumberOfRepaymentsParameterName, element)) { minNumberOfRepayments = this.fromApiJsonHelper .extractIntegerWithLocaleNamed(minNumberOfRepaymentsParameterName, element); baseDataValidator.reset().parameter(minNumberOfRepaymentsParameterName).value(minNumberOfRepayments) .ignoreIfNull().integerGreaterThanZero(); } final String maxNumberOfRepaymentsParameterName = "maxNumberOfRepayments"; Integer maxNumberOfRepayments = null; if (this.fromApiJsonHelper.parameterExists(maxNumberOfRepaymentsParameterName, element)) { maxNumberOfRepayments = this.fromApiJsonHelper .extractIntegerWithLocaleNamed(maxNumberOfRepaymentsParameterName, element); baseDataValidator.reset().parameter(maxNumberOfRepaymentsParameterName).value(maxNumberOfRepayments) .ignoreIfNull().integerGreaterThanZero(); } if (maxNumberOfRepayments != null && maxNumberOfRepayments.compareTo(0) == 1) { if (minNumberOfRepayments != null && minNumberOfRepayments.compareTo(0) == 1) { baseDataValidator.reset().parameter(maxNumberOfRepaymentsParameterName).value(maxNumberOfRepayments) .notLessThanMin(minNumberOfRepayments); if (minNumberOfRepayments.compareTo(maxNumberOfRepayments) <= 0) { baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments) .inMinMaxRange(minNumberOfRepayments, maxNumberOfRepayments); } } else { baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments) .notGreaterThanMax(maxNumberOfRepayments); } } else if (minNumberOfRepayments != null && minNumberOfRepayments.compareTo(0) == 1) { baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments) .notLessThanMin(minNumberOfRepayments); } final Integer repaymentEvery = this.fromApiJsonHelper.extractIntegerWithLocaleNamed("repaymentEvery", element); baseDataValidator.reset().parameter("repaymentEvery").value(repaymentEvery).notNull() .integerGreaterThanZero(); final Integer repaymentFrequencyType = this.fromApiJsonHelper.extractIntegerNamed("repaymentFrequencyType", element, Locale.getDefault()); baseDataValidator.reset().parameter("repaymentFrequencyType").value(repaymentFrequencyType).notNull() .inMinMaxRange(0, 3); // settings final Integer amortizationType = this.fromApiJsonHelper.extractIntegerNamed("amortizationType", element, Locale.getDefault()); baseDataValidator.reset().parameter("amortizationType").value(amortizationType).notNull().inMinMaxRange(0, 1); final Integer interestType = this.fromApiJsonHelper.extractIntegerNamed("interestType", element, Locale.getDefault()); baseDataValidator.reset().parameter("interestType").value(interestType).notNull().inMinMaxRange(0, 1); final Integer interestCalculationPeriodType = this.fromApiJsonHelper .extractIntegerNamed("interestCalculationPeriodType", element, Locale.getDefault()); baseDataValidator.reset().parameter("interestCalculationPeriodType").value(interestCalculationPeriodType) .notNull().inMinMaxRange(0, 1); final BigDecimal inArrearsTolerance = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed("inArrearsTolerance", element); baseDataValidator.reset().parameter("inArrearsTolerance").value(inArrearsTolerance).ignoreIfNull() .zeroOrPositiveAmount(); final Long transactionProcessingStrategyId = this.fromApiJsonHelper .extractLongNamed("transactionProcessingStrategyId", element); baseDataValidator.reset().parameter("transactionProcessingStrategyId") .value(transactionProcessingStrategyId).notNull().integerGreaterThanZero(); // grace validation final Integer graceOnPrincipalPayment = this.fromApiJsonHelper .extractIntegerWithLocaleNamed("graceOnPrincipalPayment", element); baseDataValidator.reset().parameter("graceOnPrincipalPayment").value(graceOnPrincipalPayment) .zeroOrPositiveAmount(); final Integer graceOnInterestPayment = this.fromApiJsonHelper .extractIntegerWithLocaleNamed("graceOnInterestPayment", element); baseDataValidator.reset().parameter("graceOnInterestPayment").value(graceOnInterestPayment) .zeroOrPositiveAmount(); final Integer graceOnInterestCharged = this.fromApiJsonHelper .extractIntegerWithLocaleNamed("graceOnInterestCharged", element); baseDataValidator.reset().parameter("graceOnInterestCharged").value(graceOnInterestCharged) .zeroOrPositiveAmount(); final Integer graceOnArrearsAgeing = this.fromApiJsonHelper .extractIntegerWithLocaleNamed(LoanProductConstants.graceOnArrearsAgeingParameterName, element); baseDataValidator.reset().parameter(LoanProductConstants.graceOnArrearsAgeingParameterName) .value(graceOnArrearsAgeing).integerZeroOrGreater(); final Integer overdueDaysForNPA = this.fromApiJsonHelper .extractIntegerWithLocaleNamed(LoanProductConstants.overdueDaysForNPAParameterName, element); baseDataValidator.reset().parameter(LoanProductConstants.overdueDaysForNPAParameterName) .value(overdueDaysForNPA).integerZeroOrGreater(); /** * { @link DaysInYearType } */ final Integer daysInYearType = this.fromApiJsonHelper.extractIntegerNamed( LoanProductConstants.daysInYearTypeParameterName, element, Locale.getDefault()); baseDataValidator.reset().parameter(LoanProductConstants.daysInYearTypeParameterName).value(daysInYearType) .notNull().isOneOfTheseValues(1, 360, 364, 365); /** * { @link DaysInMonthType } */ final Integer daysInMonthType = this.fromApiJsonHelper.extractIntegerNamed( LoanProductConstants.daysInMonthTypeParameterName, element, Locale.getDefault()); baseDataValidator.reset().parameter(LoanProductConstants.daysInMonthTypeParameterName) .value(daysInMonthType).notNull().isOneOfTheseValues(1, 30); if (this.fromApiJsonHelper.parameterExists( LoanProductConstants.accountMovesOutOfNPAOnlyOnArrearsCompletionParamName, element)) { Boolean npaChangeConfig = this.fromApiJsonHelper.extractBooleanNamed( LoanProductConstants.accountMovesOutOfNPAOnlyOnArrearsCompletionParamName, element); baseDataValidator.reset() .parameter(LoanProductConstants.accountMovesOutOfNPAOnlyOnArrearsCompletionParamName) .value(npaChangeConfig).notNull().isOneOfTheseValues(true, false); } // Interest recalculation settings final Boolean isInterestRecalculationEnabled = this.fromApiJsonHelper .extractBooleanNamed(LoanProductConstants.isInterestRecalculationEnabledParameterName, element); baseDataValidator.reset().parameter(LoanProductConstants.isInterestRecalculationEnabledParameterName) .value(isInterestRecalculationEnabled).notNull().isOneOfTheseValues(true, false); if (isInterestRecalculationEnabled != null) { if (isInterestRecalculationEnabled.booleanValue()) { validateInterestRecalculationParams(element, baseDataValidator, null); } } // interest rates if (this.fromApiJsonHelper.parameterExists("isLinkedToFloatingInterestRates", element) && this.fromApiJsonHelper.extractBooleanNamed("isLinkedToFloatingInterestRates", element) == true) { if (this.fromApiJsonHelper.parameterExists("interestRatePerPeriod", element)) { baseDataValidator.reset().parameter("interestRatePerPeriod").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.true", "interestRatePerPeriod param is not supported when isLinkedToFloatingInterestRates is true"); } if (this.fromApiJsonHelper.parameterExists("minInterestRatePerPeriod", element)) { baseDataValidator.reset().parameter("minInterestRatePerPeriod").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.true", "minInterestRatePerPeriod param is not supported when isLinkedToFloatingInterestRates is true"); } if (this.fromApiJsonHelper.parameterExists("maxInterestRatePerPeriod", element)) { baseDataValidator.reset().parameter("maxInterestRatePerPeriod").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.true", "maxInterestRatePerPeriod param is not supported when isLinkedToFloatingInterestRates is true"); } if (this.fromApiJsonHelper.parameterExists("interestRateFrequencyType", element)) { baseDataValidator.reset().parameter("interestRateFrequencyType").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.true", "interestRateFrequencyType param is not supported when isLinkedToFloatingInterestRates is true"); } if ((interestType == null || interestType != InterestMethod.DECLINING_BALANCE.getValue()) || (isInterestRecalculationEnabled == null || isInterestRecalculationEnabled == false)) { baseDataValidator.reset().parameter("isLinkedToFloatingInterestRates").failWithCode( "supported.only.for.declining.balance.interest.recalculation.enabled", "Floating interest rates are supported only for declining balance and interest recalculation enabled loan products"); } final Integer floatingRatesId = this.fromApiJsonHelper.extractIntegerNamed("floatingRatesId", element, Locale.getDefault()); baseDataValidator.reset().parameter("floatingRatesId").value(floatingRatesId).notNull(); final BigDecimal interestRateDifferential = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed("interestRateDifferential", element); baseDataValidator.reset().parameter("interestRateDifferential").value(interestRateDifferential) .notNull().zeroOrPositiveAmount(); final String minDifferentialLendingRateParameterName = "minDifferentialLendingRate"; BigDecimal minDifferentialLendingRate = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed(minDifferentialLendingRateParameterName, element); baseDataValidator.reset().parameter(minDifferentialLendingRateParameterName) .value(minDifferentialLendingRate).notNull().zeroOrPositiveAmount(); final String defaultDifferentialLendingRateParameterName = "defaultDifferentialLendingRate"; BigDecimal defaultDifferentialLendingRate = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed(defaultDifferentialLendingRateParameterName, element); baseDataValidator.reset().parameter(defaultDifferentialLendingRateParameterName) .value(defaultDifferentialLendingRate).notNull().zeroOrPositiveAmount(); final String maxDifferentialLendingRateParameterName = "maxDifferentialLendingRate"; BigDecimal maxDifferentialLendingRate = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed(maxDifferentialLendingRateParameterName, element); baseDataValidator.reset().parameter(maxDifferentialLendingRateParameterName) .value(maxDifferentialLendingRate).notNull().zeroOrPositiveAmount(); if (defaultDifferentialLendingRate != null && defaultDifferentialLendingRate.compareTo(BigDecimal.ZERO) != -1) { if (minDifferentialLendingRate != null && minDifferentialLendingRate.compareTo(BigDecimal.ZERO) != -1) { baseDataValidator.reset().parameter("defaultDifferentialLendingRate") .value(defaultDifferentialLendingRate).notLessThanMin(minDifferentialLendingRate); } } if (maxDifferentialLendingRate != null && maxDifferentialLendingRate.compareTo(BigDecimal.ZERO) != -1) { if (minDifferentialLendingRate != null && minDifferentialLendingRate.compareTo(BigDecimal.ZERO) != -1) { baseDataValidator.reset().parameter("maxDifferentialLendingRate") .value(maxDifferentialLendingRate).notLessThanMin(minDifferentialLendingRate); } } if (maxDifferentialLendingRate != null && maxDifferentialLendingRate.compareTo(BigDecimal.ZERO) != -1) { if (defaultDifferentialLendingRate != null && defaultDifferentialLendingRate.compareTo(BigDecimal.ZERO) != -1) { baseDataValidator.reset().parameter("maxDifferentialLendingRate") .value(maxDifferentialLendingRate).notLessThanMin(defaultDifferentialLendingRate); } } final Boolean isFloatingInterestRateCalculationAllowed = this.fromApiJsonHelper .extractBooleanNamed("isFloatingInterestRateCalculationAllowed", element); baseDataValidator.reset().parameter("isFloatingInterestRateCalculationAllowed") .value(isFloatingInterestRateCalculationAllowed).notNull().isOneOfTheseValues(true, false); } else { if (this.fromApiJsonHelper.parameterExists("floatingRatesId", element)) { baseDataValidator.reset().parameter("floatingRatesId").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.false", "floatingRatesId param is not supported when isLinkedToFloatingInterestRates is not supplied or false"); } if (this.fromApiJsonHelper.parameterExists("interestRateDifferential", element)) { baseDataValidator.reset().parameter("interestRateDifferential").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.false", "interestRateDifferential param is not supported when isLinkedToFloatingInterestRates is not supplied or false"); } if (this.fromApiJsonHelper.parameterExists("minDifferentialLendingRate", element)) { baseDataValidator.reset().parameter("minDifferentialLendingRate").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.false", "minDifferentialLendingRate param is not supported when isLinkedToFloatingInterestRates is not supplied or false"); } if (this.fromApiJsonHelper.parameterExists("defaultDifferentialLendingRate", element)) { baseDataValidator.reset().parameter("defaultDifferentialLendingRate").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.false", "defaultDifferentialLendingRate param is not supported when isLinkedToFloatingInterestRates is not supplied or false"); } if (this.fromApiJsonHelper.parameterExists("maxDifferentialLendingRate", element)) { baseDataValidator.reset().parameter("maxDifferentialLendingRate").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.false", "maxDifferentialLendingRate param is not supported when isLinkedToFloatingInterestRates is not supplied or false"); } if (this.fromApiJsonHelper.parameterExists("isFloatingInterestRateCalculationAllowed", element)) { baseDataValidator.reset().parameter("isFloatingInterestRateCalculationAllowed").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.false", "isFloatingInterestRateCalculationAllowed param is not supported when isLinkedToFloatingInterestRates is not supplied or false"); } final BigDecimal interestRatePerPeriod = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed("interestRatePerPeriod", element); baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod).notNull() .zeroOrPositiveAmount(); final String minInterestRatePerPeriodParameterName = "minInterestRatePerPeriod"; BigDecimal minInterestRatePerPeriod = null; if (this.fromApiJsonHelper.parameterExists(minInterestRatePerPeriodParameterName, element)) { minInterestRatePerPeriod = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed(minInterestRatePerPeriodParameterName, element); baseDataValidator.reset().parameter(minInterestRatePerPeriodParameterName) .value(minInterestRatePerPeriod).ignoreIfNull().zeroOrPositiveAmount(); } final String maxInterestRatePerPeriodParameterName = "maxInterestRatePerPeriod"; BigDecimal maxInterestRatePerPeriod = null; if (this.fromApiJsonHelper.parameterExists(maxInterestRatePerPeriodParameterName, element)) { maxInterestRatePerPeriod = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed(maxInterestRatePerPeriodParameterName, element); baseDataValidator.reset().parameter(maxInterestRatePerPeriodParameterName) .value(maxInterestRatePerPeriod).ignoreIfNull().zeroOrPositiveAmount(); } if (maxInterestRatePerPeriod != null && maxInterestRatePerPeriod.compareTo(BigDecimal.ZERO) != -1) { if (minInterestRatePerPeriod != null && minInterestRatePerPeriod.compareTo(BigDecimal.ZERO) != -1) { baseDataValidator.reset().parameter(maxInterestRatePerPeriodParameterName) .value(maxInterestRatePerPeriod).notLessThanMin(minInterestRatePerPeriod); if (minInterestRatePerPeriod.compareTo(maxInterestRatePerPeriod) <= 0) { baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod) .inMinAndMaxAmountRange(minInterestRatePerPeriod, maxInterestRatePerPeriod); } } else { baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod) .notGreaterThanMax(maxInterestRatePerPeriod); } } else if (minInterestRatePerPeriod != null && minInterestRatePerPeriod.compareTo(BigDecimal.ZERO) != -1) { baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod) .notLessThanMin(minInterestRatePerPeriod); } final Integer interestRateFrequencyType = this.fromApiJsonHelper .extractIntegerNamed("interestRateFrequencyType", element, Locale.getDefault()); baseDataValidator.reset().parameter("interestRateFrequencyType").value(interestRateFrequencyType) .notNull().inMinMaxRange(0, 3); } // Guarantee Funds Boolean holdGuaranteeFunds = false; if (this.fromApiJsonHelper.parameterExists(LoanProductConstants.holdGuaranteeFundsParamName, element)) { holdGuaranteeFunds = this.fromApiJsonHelper .extractBooleanNamed(LoanProductConstants.holdGuaranteeFundsParamName, element); baseDataValidator.reset().parameter(LoanProductConstants.holdGuaranteeFundsParamName) .value(holdGuaranteeFunds).notNull().isOneOfTheseValues(true, false); } if (holdGuaranteeFunds != null) { if (holdGuaranteeFunds) { validateGuaranteeParams(element, baseDataValidator, null); } } BigDecimal principalThresholdForLastInstallment = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed( LoanProductConstants.principalThresholdForLastInstallmentParamName, element); baseDataValidator.reset().parameter(LoanProductConstants.principalThresholdForLastInstallmentParamName) .value(principalThresholdForLastInstallment).notLessThanMin(BigDecimal.ZERO) .notGreaterThanMax(BigDecimal.valueOf(100)); if (this.fromApiJsonHelper.parameterExists(LoanProductConstants.canDefineEmiAmountParamName, element)) { final Boolean canDefineInstallmentAmount = this.fromApiJsonHelper .extractBooleanNamed(LoanProductConstants.canDefineEmiAmountParamName, element); baseDataValidator.reset().parameter(LoanProductConstants.canDefineEmiAmountParamName) .value(canDefineInstallmentAmount).isOneOfTheseValues(true, false); } if (this.fromApiJsonHelper.parameterExists(LoanProductConstants.installmentAmountInMultiplesOfParamName, element)) { final Integer installmentAmountInMultiplesOf = this.fromApiJsonHelper.extractIntegerWithLocaleNamed( LoanProductConstants.installmentAmountInMultiplesOfParamName, element); baseDataValidator.reset().parameter(LoanProductConstants.installmentAmountInMultiplesOfParamName) .value(installmentAmountInMultiplesOf).ignoreIfNull().integerGreaterThanZero(); } // accounting related data validation final Integer accountingRuleType = this.fromApiJsonHelper.extractIntegerNamed("accountingRule", element, Locale.getDefault()); baseDataValidator.reset().parameter("accountingRule").value(accountingRuleType).notNull().inMinMaxRange(1, 4); if (isCashBasedAccounting(accountingRuleType) || isAccrualBasedAccounting(accountingRuleType)) { final Long fundAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.FUND_SOURCE.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.FUND_SOURCE.getValue()) .value(fundAccountId).notNull().integerGreaterThanZero(); final Long loanPortfolioAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.LOAN_PORTFOLIO.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.LOAN_PORTFOLIO.getValue()) .value(loanPortfolioAccountId).notNull().integerGreaterThanZero(); final Long transfersInSuspenseAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.TRANSFERS_SUSPENSE.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.TRANSFERS_SUSPENSE.getValue()) .value(transfersInSuspenseAccountId).notNull().integerGreaterThanZero(); final Long incomeFromInterestId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.INTEREST_ON_LOANS.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.INTEREST_ON_LOANS.getValue()) .value(incomeFromInterestId).notNull().integerGreaterThanZero(); final Long incomeFromFeeId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_FEES.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_FEES.getValue()) .value(incomeFromFeeId).notNull().integerGreaterThanZero(); final Long incomeFromPenaltyId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_PENALTIES.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_PENALTIES.getValue()) .value(incomeFromPenaltyId).notNull().integerGreaterThanZero(); final Long incomeFromRecoveryAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_RECOVERY.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_RECOVERY.getValue()) .value(incomeFromRecoveryAccountId).notNull().integerGreaterThanZero(); final Long writeOffAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.LOSSES_WRITTEN_OFF.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.LOSSES_WRITTEN_OFF.getValue()) .value(writeOffAccountId).notNull().integerGreaterThanZero(); final Long overpaymentAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.OVERPAYMENT.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.OVERPAYMENT.getValue()) .value(overpaymentAccountId).notNull().integerGreaterThanZero(); validatePaymentChannelFundSourceMappings(baseDataValidator, element); validateChargeToIncomeAccountMappings(baseDataValidator, element); } if (isAccrualBasedAccounting(accountingRuleType)) { final Long receivableInterestAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.INTEREST_RECEIVABLE.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.INTEREST_RECEIVABLE.getValue()) .value(receivableInterestAccountId).notNull().integerGreaterThanZero(); final Long receivableFeeAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.FEES_RECEIVABLE.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.FEES_RECEIVABLE.getValue()) .value(receivableFeeAccountId).notNull().integerGreaterThanZero(); final Long receivablePenaltyAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.PENALTIES_RECEIVABLE.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.PENALTIES_RECEIVABLE.getValue()) .value(receivablePenaltyAccountId).notNull().integerGreaterThanZero(); } if (this.fromApiJsonHelper.parameterExists(LoanProductConstants.useBorrowerCycleParameterName, element)) { final Boolean useBorrowerCycle = this.fromApiJsonHelper .extractBooleanNamed(LoanProductConstants.useBorrowerCycleParameterName, element); baseDataValidator.reset().parameter(LoanProductConstants.useBorrowerCycleParameterName) .value(useBorrowerCycle).ignoreIfNull().validateForBooleanValue(); if (useBorrowerCycle) { validateBorrowerCycleVariations(element, baseDataValidator); } } validateMultiDisburseLoanData(baseDataValidator, element); validateLoanConfigurableAttributes(baseDataValidator, element); validateVariableInstallmentSettings(baseDataValidator, element); validatePartialPeriodSupport(interestCalculationPeriodType, baseDataValidator, element, null); throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:logic.EntityCar.java
private void monetaryStaticCount(boolean first) throws Exception { BigDecimal minParamTox = BigDecimal.valueOf(1); BigDecimal minValueTox = BigDecimal.valueOf(1); if (first) {//from w w w .java 2 s. co m minParamTox = minParamToxic1; minValueTox = minValueToxic1; } else { minParamTox = minParamToxic2; minValueTox = minValueToxic2; } //suplog+=" secCount: "+resStatType+"; "; if (resStatType.equals(ResourceStaticType.BOTH)) { if (minValueTox.compareTo(BigDecimal.valueOf(1)) < 0) { for (CarColorValue ccv : car.getCarColorValues()) { //k++; Color col = ccv.getColor(); String suid = col.getUid().trim(); //suplog+="!! suid="+suid.trim()+"; "; BaseParam bp = getBaseParam(allParams, suid); //suplog+=""+k+"."+ccv.getTitle()+" - "+ccv.getColor().getName()+"; "; if (bp != null && StaticType.STATIC.equals(bp.getStaticType())) { List<String> colorRadList = ConvertSupport.getRadicalList(col.getRadical()); if (!colorRadList.isEmpty()) { String attrToxRad = ""; BigDecimal attrToxRate = BigDecimal.valueOf(-100); for (String colorRad : colorRadList) { BigDecimal ToxRate = BigDecimal .valueOf(getToxicRate(radCore.trim(), radColor.trim(), colorRad)); if (ToxRate.compareTo(attrToxRate) > 0) { attrToxRate = ToxRate; attrToxRad = colorRad; } } if (attrToxRad != null && !attrToxRad.equals("")) { BigDecimal attrModalRate = BigDecimal.valueOf(0); if (percType.equals(Perception.AUDIAL)) { if (col.getAudial() != null) { attrModalRate = BigDecimal.valueOf(col.getAudial()); } } else if (percType.equals(Perception.KINESTETIC)) { if (col.getKinestet() != null) { attrModalRate = BigDecimal.valueOf(col.getKinestet()); } } else if (percType.equals(Perception.VISUAL)) { if (col.getVisual() != null) { attrModalRate = BigDecimal.valueOf(col.getVisual()); } } if (attrToxRate.compareTo(minValueTox) >= 0) { String statType = " 1"; if (!first) { statType = " 2"; } EntityProperty ep = new EntityProperty(bp.getName(), ccv.getTitle(), suid, attrToxRate, attrToxRad, attrModalRate, (double) 0, PropertyType.OPTION, statType); List<EntityProperty> availEps = staticProps.get(suid); if (availEps == null || availEps.isEmpty()) { availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); } else { EntityProperty availEp = availEps.get(0); Boolean diffrentOption = (availEp.getValue().compareTo(attrToxRate) != 0) || (!availEp.title.equals(ccv.getTitle())) || (!availEp.type.equals(PropertyType.OPTION)) || (!availEp.name.equals(bp.getName())) || (availEp.price.compareTo(BigDecimal.valueOf(0))) != 0; if (diffrentOption) { if (attrToxRate.compareTo(availEp.value) == 0) { BigDecimal availModVal = availEp.modalValue; if (attrModalRate.compareTo(availModVal) > 0) { availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); } else if (attrModalRate.compareTo(availModVal) == 0) { availEps.add(ep); staticProps.put(suid, availEps); } } else if (attrToxRate.compareTo(availEp.getValue()) > 0) { availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); } } } } } } } } //suplog+=" fs: "+car.getFeatures().size()+"; "; for (Feature f : car.getFeatures()) { String suid = f.getUid().trim(); //suplog+="!! suid="+suid.trim()+"; "; BaseParam bp = getBaseParam(allParams, suid); //suplog+=""+k+"."+ccv.getTitle()+" - "+ccv.getColor().getName()+"; "; if (bp != null && StaticType.STATIC.equals(bp.getStaticType())) { List<String> colorRadList = ConvertSupport.getRadicalList(f.getRadical()); if (!colorRadList.isEmpty()) { String attrToxRad = ""; BigDecimal attrToxRate = BigDecimal.valueOf(-100); for (String colorRad : colorRadList) { BigDecimal ToxRate = BigDecimal .valueOf(getToxicRate(radCore.trim(), radColor.trim(), colorRad)); if (ToxRate.compareTo(attrToxRate) > 0) { attrToxRate = ToxRate; attrToxRad = colorRad; } } if (attrToxRad != null && !attrToxRad.equals("")) { BigDecimal attrModalRate = BigDecimal.valueOf(0); if (percType.equals(Perception.AUDIAL)) { if (f.getAudial() != null) { attrModalRate = BigDecimal.valueOf(f.getAudial()); } } else if (percType.equals(Perception.KINESTETIC)) { if (f.getKinestet() != null) { attrModalRate = BigDecimal.valueOf(f.getKinestet()); } } else if (percType.equals(Perception.VISUAL)) { if (f.getVisual() != null) { attrModalRate = BigDecimal.valueOf(f.getVisual()); } } if (attrToxRate.compareTo(minValueTox) >= 0) { String statType = " 1"; if (!first) { statType = " 2"; } EntityProperty ep = new EntityProperty(bp.getName(), f.getTitle(), suid, attrToxRate, attrToxRad, attrModalRate, (double) 0, PropertyType.FEATURE, statType); List<EntityProperty> availEps = staticProps.get(suid); if (availEps == null || availEps.isEmpty()) { availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); } else { EntityProperty availEp = availEps.get(0); Boolean diffrentOption = (availEp.getValue().compareTo(attrToxRate) != 0) || (!availEp.title.equals(f.getTitle())) || (!availEp.type.equals(PropertyType.FEATURE)) || (!availEp.name.equals(bp.getName())) || (availEp.price.compareTo(BigDecimal.valueOf(0))) != 0; if (diffrentOption) { if (attrToxRate.compareTo(availEp.value) == 0) { BigDecimal availModVal = availEp.modalValue; if (attrModalRate.compareTo(availModVal) > 0) { availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); } else if (attrModalRate.compareTo(availModVal) == 0) { availEps.add(ep); staticProps.put(suid, availEps); } } else if (attrToxRate.compareTo(availEp.getValue()) > 0) { availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); } } } } /*if (attrToxRate.compareTo(minValueTox) >= 0) { EntityProperty availEp = staticProps.get(suid); if (availEp == null) { staticProps.put(suid, new EntityProperty(bp.getName(), f.getTitle(), suid, attrToxRate, attrToxRad, attrModalRate, (double) 0, PropertyType.FEATURE)); } else { if (attrToxRate.compareTo(availEp.value) == 0) { BigDecimal availModVal = staticProps.get(suid).modalValue; if (attrModalRate.compareTo(availModVal) > 0) { staticProps.put(suid, new EntityProperty(bp.getName(), f.getTitle(), suid, attrToxRate, attrToxRad, attrModalRate, (double) 0, PropertyType.FEATURE)); } } else if (attrToxRate.compareTo(availEp.value) > 0) { staticProps.put(suid, new EntityProperty(bp.getName(), f.getTitle(), suid, attrToxRate, attrToxRad, attrModalRate, (double) 0, PropertyType.FEATURE)); } } //suplog+="COLOR: atr="+attrToxRate+"; am="+attrModalRate+"; etr="+essToxRate+"; statrate="+rel.toString()+"; "; }*/ } } } } } int i = 0; int m = 0; int n = 0; //suplog+=" covs: "+car.getCarOptionValues().size()+"; "; for (CarOptionValue cov : car.getCarOptionValues()) { CarCompletionOption cco = cov.getCCO(); String suid = cco.getUid().trim(); BaseParam bp = getBaseParam(allParams, suid); if (bp != null && StaticType.STATIC.equals(bp.getStaticType()) && BigDecimal.valueOf(cov.getPrice()).compareTo(moneyFound) <= 0) { i++; //suplog += " radseqs=" + cov.getRadical() + "; "; List<String> colorRadList = ConvertSupport.getRadicalList(cov.getRadical()); if (!colorRadList.isEmpty()) { m++; String attrToxRad = ""; BigDecimal attrToxRate = BigDecimal.valueOf(-100); for (String colorRad : colorRadList) { BigDecimal ToxRate = BigDecimal .valueOf(getToxicRate(radCore.trim(), radColor.trim(), colorRad)); if (ToxRate.compareTo(attrToxRate) > 0) { attrToxRate = ToxRate; attrToxRad = colorRad; } } //suplog += " atr=" + attrToxRate + "; atrad=" + attrToxRad + "; "; if (attrToxRad != null && !attrToxRad.equals("")) { BigDecimal attrModalRate = BigDecimal.valueOf(0); if (percType.equals(Perception.AUDIAL)) { if (cov.getAudial() != null) { attrModalRate = BigDecimal.valueOf(cov.getAudial()); } } else if (percType.equals(Perception.KINESTETIC)) { if (cov.getKinestet() != null) { attrModalRate = BigDecimal.valueOf(cov.getKinestet()); } } else if (percType.equals(Perception.VISUAL)) { if (cov.getVisual() != null) { attrModalRate = BigDecimal.valueOf(cov.getVisual()); } } //suplog += " amr=" + attrModalRate + "; "; if (attrToxRate.compareTo(minValueTox) >= 0) { String statType = " 1"; if (!first) { statType = " 2"; } EntityProperty ep = new EntityProperty(bp.getName(), cco.getTitle(), cov.getDescription(), suid, attrToxRate, attrToxRad, attrModalRate, cov.getPrice(), PropertyType.OPTION, statType); List<EntityProperty> availEps = staticProps.get(suid); if (availEps == null || availEps.isEmpty()) { availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } else { EntityProperty availEp = availEps.get(0); Boolean diffrentOption = (availEp.getValue().compareTo(attrToxRate) != 0) || (!availEp.title.equals(cco.getTitle())) || (!availEp.type.equals(PropertyType.OPTION)) || (!availEp.name.equals(bp.getName())) || (availEp.price.compareTo(BigDecimal.valueOf(cov.getPrice()))) != 0; if (diffrentOption) { if (attrToxRate.compareTo(availEp.value) == 0) { BigDecimal availModVal = availEp.modalValue; if (attrModalRate.compareTo(availModVal) > 0) { moneyFound = moneyFound.add(availEp.price); availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } else if (attrModalRate.compareTo(availModVal) == 0) { if (ep.price.compareTo(availEp.price) == 0) { availEps.add(ep); staticProps.put(suid, availEps); } else if (ep.price.compareTo(availEp.price) < 0) { moneyFound = moneyFound.add(availEp.price); availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } } } else if (attrToxRate.compareTo(availEp.getValue()) > 0) { moneyFound = moneyFound.add(availEp.price); availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } } } } /*if (attrToxRate.compareTo(minValueTox) >= 0) { EntityProperty availEp = staticProps.get(suid); n++; if (availEp == null) { staticProps.put(suid, new EntityProperty(bp.getName(), cco.getTitle(), cov.getDescription(), suid, attrToxRate, attrToxRad, attrModalRate, cov.getPrice(), PropertyType.OPTION)); } else { if (attrToxRate.compareTo(availEp.value) == 0) { BigDecimal availModVal = staticProps.get(suid).modalValue; if (attrModalRate.compareTo(availModVal) > 0) { staticProps.put(suid, new EntityProperty(bp.getName(), cco.getTitle(), cov.getDescription(), suid, attrToxRate, attrToxRad, attrModalRate, cov.getPrice(), PropertyType.OPTION)); } } else if (attrToxRate.compareTo(availEp.value) > 0) { staticProps.put(suid, new EntityProperty(bp.getName(), cco.getTitle(), cov.getDescription(), suid, attrToxRate, attrToxRad, attrModalRate, cov.getPrice(), PropertyType.OPTION)); } } }*/ } } } } //suplog += "? ?. ? : " + i + " ? ? : " + m + ", :"+n+"; minToxLv2=" + minParamToxic2 + "; "; //suplog+=" fos: "+car.getFreeOptions().size()+"; "; for (FreeOption fo : car.getFreeOptions()) { String suid = fo.getUid().trim(); BaseParam bp = getBaseParam(allParams, suid); if (bp != null && StaticType.STATIC.equals(bp.getStaticType()) && BigDecimal.valueOf(fo.getPrice()).compareTo(moneyFound) <= 0) { List<String> colorRadList = ConvertSupport.getRadicalList(fo.getRadical()); if (!colorRadList.isEmpty()) { String attrToxRad = ""; BigDecimal attrToxRate = BigDecimal.valueOf(-100); for (String colorRad : colorRadList) { BigDecimal ToxRate = BigDecimal .valueOf(getToxicRate(radCore.trim(), radColor.trim(), colorRad)); if (ToxRate.compareTo(attrToxRate) > 0) { attrToxRate = ToxRate; attrToxRad = colorRad; } } if (attrToxRad != null && !attrToxRad.equals("")) { BigDecimal attrModalRate = BigDecimal.valueOf(0); if (percType.equals(Perception.AUDIAL)) { if (fo.getAudial() != null) { attrModalRate = BigDecimal.valueOf(fo.getAudial()); } } else if (percType.equals(Perception.KINESTETIC)) { if (fo.getKinestetic() != null) { attrModalRate = BigDecimal.valueOf(fo.getKinestetic()); } } else if (percType.equals(Perception.VISUAL)) { if (fo.getVisual() != null) { attrModalRate = BigDecimal.valueOf(fo.getVisual()); } } if (attrToxRate.compareTo(minValueTox) >= 0) { String statType = " 1"; if (!first) { statType = " 2"; } EntityProperty ep = new EntityProperty(bp.getName(), fo.getTitle(), suid, attrToxRate, attrToxRad, attrModalRate, fo.getPrice(), fo.getType(), statType); List<EntityProperty> availEps = staticProps.get(suid); if (availEps == null || availEps.isEmpty()) { availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } else { EntityProperty availEp = availEps.get(0); Boolean diffrentOption = (availEp.getValue().compareTo(attrToxRate) != 0) || (!availEp.title.equals(fo.getTitle())) || (!availEp.type.equals(fo.getType())) || (!availEp.name.equals(bp.getName())) || (availEp.price.compareTo(BigDecimal.valueOf(fo.getPrice()))) != 0; if (diffrentOption) { if (attrToxRate.compareTo(availEp.value) == 0) { BigDecimal availModVal = availEp.modalValue; if (attrModalRate.compareTo(availModVal) > 0) { moneyFound = moneyFound.add(availEp.price); availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } else if (attrModalRate.compareTo(availModVal) == 0) { if (ep.price.compareTo(availEp.price) == 0) { availEps.add(ep); staticProps.put(suid, availEps); } else if (ep.price.compareTo(availEp.price) < 0) { moneyFound = moneyFound.add(availEp.price); availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } } } else if (attrToxRate.compareTo(availEp.getValue()) > 0) { moneyFound = moneyFound.add(availEp.price); availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } } } } /*if (attrToxRate.compareTo(minValueTox) >= 0) { EntityProperty availEp = staticProps.get(suid); if (availEp == null) { staticProps.put(suid, new EntityProperty(bp.getName(), fo.getTitle(), suid, attrToxRate, attrToxRad, attrModalRate, fo.getPrice(), fo.getType())); } else { if (attrToxRate.compareTo(availEp.value) == 0) { BigDecimal availModVal = staticProps.get(suid).modalValue; if (attrModalRate.compareTo(availModVal) > 0) { staticProps.put(suid, new EntityProperty(bp.getName(), fo.getTitle(), suid, attrToxRate, attrToxRad, attrModalRate, fo.getPrice(), fo.getType())); } } else if (attrToxRate.compareTo(availEp.value) > 0) { staticProps.put(suid, new EntityProperty(bp.getName(), fo.getTitle(), suid, attrToxRate, attrToxRad, attrModalRate, fo.getPrice(), fo.getType())); } } }*/ } } } } } else { //suplog += " covs2: " + car.getCarOptionValues().size() + "; "; for (CarOptionValue cov : car.getCarOptionValues()) { CarCompletionOption cco = cov.getCCO(); String suid = cco.getUid().trim(); BaseParam bp = getBaseParam(allParams, suid); if (bp != null && StaticType.STATIC.equals(bp.getStaticType()) && cov.getPrice().compareTo(Double.valueOf(0)) > 0 && BigDecimal.valueOf(cov.getPrice()).compareTo(moneyFound) <= 0) { List<String> colorRadList = ConvertSupport.getRadicalList(cov.getRadical()); if (!colorRadList.isEmpty()) { String attrToxRad = ""; BigDecimal attrToxRate = BigDecimal.valueOf(-100); for (String colorRad : colorRadList) { BigDecimal ToxRate = BigDecimal .valueOf(getToxicRate(radCore.trim(), radColor.trim(), colorRad)); if (ToxRate.compareTo(attrToxRate) > 0) { attrToxRate = ToxRate; attrToxRad = colorRad; } } if (attrToxRad != null && !attrToxRad.equals("")) { BigDecimal attrModalRate = BigDecimal.valueOf(0); if (percType.equals(Perception.AUDIAL)) { if (cov.getAudial() != null) { attrModalRate = BigDecimal.valueOf(cov.getAudial()); } } else if (percType.equals(Perception.KINESTETIC)) { if (cov.getKinestet() != null) { attrModalRate = BigDecimal.valueOf(cov.getKinestet()); } } else if (percType.equals(Perception.VISUAL)) { if (cov.getVisual() != null) { attrModalRate = BigDecimal.valueOf(cov.getVisual()); } } if (attrToxRate.compareTo(minValueTox) >= 0) { String statType = " 1"; if (!first) { statType = " 2"; } EntityProperty ep = new EntityProperty(bp.getName(), cco.getTitle(), cov.getDescription(), suid, attrToxRate, attrToxRad, attrModalRate, cov.getPrice(), PropertyType.OPTION, statType); List<EntityProperty> availEps = staticProps.get(suid); if (availEps == null || availEps.isEmpty()) { availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } else { EntityProperty availEp = availEps.get(0); Boolean diffrentOption = (availEp.getValue().compareTo(attrToxRate) != 0) || (!availEp.title.equals(cco.getTitle())) || (!availEp.type.equals(PropertyType.OPTION)) || (!availEp.name.equals(bp.getName())) || (availEp.price.compareTo(BigDecimal.valueOf(cov.getPrice()))) != 0; if (diffrentOption) { if (availEp.price.compareTo(BigDecimal.valueOf(0)) > 0) { if (attrToxRate.compareTo(availEp.value) == 0) { BigDecimal availModVal = availEp.modalValue; if (attrModalRate.compareTo(availModVal) > 0) { moneyFound = moneyFound.add(availEp.price); availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } else if (attrModalRate.compareTo(availModVal) == 0) { if (ep.price.compareTo(availEp.price) == 0) { availEps.add(ep); staticProps.put(suid, availEps); } else if (ep.price.compareTo(availEp.price) < 0) { moneyFound = moneyFound.add(availEp.price); availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } } } else if (attrToxRate.compareTo(availEp.getValue()) > 0) { moneyFound = moneyFound.add(availEp.price); availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } } } } } /*if (attrToxRate.compareTo(minValueTox) >= 0) { EntityProperty availEp = staticProps.get(suid); if (availEp == null) { staticProps.put(suid, new EntityProperty(bp.getName(), cco.getTitle(), cov.getDescription(), suid, attrToxRate, attrToxRad, attrModalRate, cov.getPrice(), PropertyType.OPTION)); } else { if (attrToxRate.compareTo(availEp.value) == 0) { BigDecimal availModVal = staticProps.get(suid).modalValue; if (attrModalRate.compareTo(availModVal) > 0) { staticProps.put(suid, new EntityProperty(bp.getName(), cco.getTitle(), cov.getDescription(), suid, attrToxRate, attrToxRad, attrModalRate, cov.getPrice(), PropertyType.OPTION)); } } else if (attrToxRate.compareTo(availEp.value) > 0) { staticProps.put(suid, new EntityProperty(bp.getName(), cco.getTitle(), cov.getDescription(), suid, attrToxRate, attrToxRad, attrModalRate, cov.getPrice(), PropertyType.OPTION)); } } }*/ } } } } //suplog += " fos2: " + car.getFreeOptions().size() + "; "; for (FreeOption fo : car.getFreeOptions()) { String suid = fo.getUid().trim(); BaseParam bp = getBaseParam(allParams, suid); if (bp != null && StaticType.STATIC.equals(bp.getStaticType()) && fo.getPrice().compareTo(Double.valueOf(0)) > 0 && BigDecimal.valueOf(fo.getPrice()).compareTo(moneyFound) <= 0) { List<String> colorRadList = ConvertSupport.getRadicalList(fo.getRadical()); if (!colorRadList.isEmpty()) { String attrToxRad = ""; BigDecimal attrToxRate = BigDecimal.valueOf(-100); for (String colorRad : colorRadList) { BigDecimal ToxRate = BigDecimal .valueOf(getToxicRate(radCore.trim(), radColor.trim(), colorRad)); if (ToxRate.compareTo(attrToxRate) > 0) { attrToxRate = ToxRate; attrToxRad = colorRad; } } if (attrToxRad != null && !attrToxRad.equals("")) { BigDecimal attrModalRate = BigDecimal.valueOf(0); if (percType.equals(Perception.AUDIAL)) { if (fo.getAudial() != null) { attrModalRate = BigDecimal.valueOf(fo.getAudial()); } } else if (percType.equals(Perception.KINESTETIC)) { if (fo.getKinestetic() != null) { attrModalRate = BigDecimal.valueOf(fo.getKinestetic()); } } else if (percType.equals(Perception.VISUAL)) { if (fo.getVisual() != null) { attrModalRate = BigDecimal.valueOf(fo.getVisual()); } } if (attrToxRate.compareTo(minValueTox) >= 0) { String statType = " 1"; if (!first) { statType = " 2"; } EntityProperty ep = new EntityProperty(bp.getName(), fo.getTitle(), suid, attrToxRate, attrToxRad, attrModalRate, fo.getPrice(), fo.getType(), statType); List<EntityProperty> availEps = staticProps.get(suid); if (availEps == null || availEps.isEmpty()) { availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } else { EntityProperty availEp = availEps.get(0); Boolean diffrentOption = (availEp.getValue().compareTo(attrToxRate) != 0) || (!availEp.title.equals(fo.getTitle())) || (!availEp.type.equals(fo.getType())) || (!availEp.name.equals(bp.getName())) || (availEp.price.compareTo(BigDecimal.valueOf(fo.getPrice()))) != 0; if (diffrentOption) { if (availEp.price.compareTo(BigDecimal.valueOf(0)) > 0) { if (attrToxRate.compareTo(availEp.value) == 0) { BigDecimal availModVal = availEp.modalValue; if (attrModalRate.compareTo(availModVal) > 0) { moneyFound = moneyFound.add(availEp.price); availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } else if (attrModalRate.compareTo(availModVal) == 0) { if (ep.price.compareTo(availEp.price) == 0) { availEps.add(ep); staticProps.put(suid, availEps); } else if (ep.price.compareTo(availEp.price) < 0) { moneyFound = moneyFound.add(availEp.price); availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } } } else if (attrToxRate.compareTo(availEp.getValue()) > 0) { moneyFound = moneyFound.add(availEp.price); availEps = new ArrayList(); availEps.add(ep); staticProps.put(suid, availEps); moneyFound = moneyFound.subtract(ep.price); } } } } } /*if (attrToxRate.compareTo(minValueTox) >= 0) { EntityProperty availEp = staticProps.get(suid); if (availEp == null) { staticProps.put(suid, new EntityProperty(bp.getName(), fo.getTitle(), suid, attrToxRate, attrToxRad, attrModalRate, fo.getPrice(), fo.getType())); } else { if (attrToxRate.compareTo(availEp.value) == 0) { BigDecimal availModVal = staticProps.get(suid).modalValue; if (attrModalRate.compareTo(availModVal) > 0) { staticProps.put(suid, new EntityProperty(bp.getName(), fo.getTitle(), suid, attrToxRate, attrToxRad, attrModalRate, fo.getPrice(), fo.getType())); } } else if (attrToxRate.compareTo(availEp.value) > 0) { staticProps.put(suid, new EntityProperty(bp.getName(), fo.getTitle(), suid, attrToxRate, attrToxRad, attrModalRate, fo.getPrice(), fo.getType())); } } }*/ } } } } } }
From source file:com.gst.portfolio.savings.domain.SavingsAccount.java
protected boolean createWithHoldTransaction(final BigDecimal amount, final LocalDate date) { boolean isTaxAdded = false; if (this.taxGroup != null && amount.compareTo(BigDecimal.ZERO) == 1) { Map<TaxComponent, BigDecimal> taxSplit = TaxUtils.splitTax(amount, date, this.taxGroup.getTaxGroupMappings(), amount.scale()); BigDecimal totalTax = TaxUtils.totalTaxAmount(taxSplit); if (totalTax.compareTo(BigDecimal.ZERO) == 1) { SavingsAccountTransaction withholdTransaction = SavingsAccountTransaction.withHoldTax(this, office(), date, Money.of(currency, totalTax), taxSplit); addTransaction(withholdTransaction); isTaxAdded = true;/*from w w w . j a v a 2s. co m*/ } } return isTaxAdded; }
From source file:com.turborep.turbotracker.sales.service.Salesserviceimpl.java
public void RollBackSalesOrderLineItems(Cuso cuso, Integer newstatus, Integer userID, String userName) { Session aSession = null;/*from w w w . j a v a 2s. c o m*/ boolean returnvalue = false; try { aSession = itsSessionFactory.openSession(); String prwarehouseQuery = "FROM Cusodetail WHERE cuSOID =" + cuso.getCuSoid(); Query aQuery = aSession.createQuery(prwarehouseQuery); if (cuso.getTransactionStatus() == 1 && (newstatus == -2 || newstatus == -1 || newstatus == 0 || newstatus == 2)) { String transstatus = ""; if (newstatus == -2) { transstatus = "Quote"; } else if (newstatus == -1) { transstatus = "Void"; } else if (newstatus == 0) { transstatus = "onHold"; } else if (newstatus == 2) { transstatus = "Closed"; } ArrayList<Cusodetail> cusodtllist = (ArrayList<Cusodetail>) aQuery.list(); for (Cusodetail aCusodetail : cusodtllist) { aCusodetail.setUserID(userID); aCusodetail.setUserName(userName); itsjobService.RollBackPrMasterPrWareHouseInventory(aCusodetail.getCuSoid(), aCusodetail.getCuSodetailId()); if (aCusodetail.getCuSodetailId() > 0) { Cuso aCuso = (Cuso) aSession.get(Cuso.class, aCusodetail.getCuSoid()); TpInventoryLog aTpInventoryLog = new TpInventoryLog(); Prmaster aPrmaster = productService .getProducts(" WHERE prMasterID=" + aCusodetail.getPrMasterId()); aTpInventoryLog.setPrMasterID(aCusodetail.getPrMasterId()); aTpInventoryLog.setProductCode(aPrmaster.getItemCode()); aTpInventoryLog.setWareHouseID(aCuso.getPrFromWarehouseId()); aTpInventoryLog.setTransType("SO"); aTpInventoryLog.setTransDecription("SO Status Open to " + transstatus); aTpInventoryLog.setTransID(aCusodetail.getCuSoid()); aTpInventoryLog.setTransDetailID(aCusodetail.getCuSodetailId()); aTpInventoryLog.setProductOut( aCusodetail.getQuantityOrdered().compareTo(new BigDecimal("0.0000")) == -1 ? aCusodetail.getQuantityOrdered() : new BigDecimal("0.0000")); aTpInventoryLog.setProductIn( aCusodetail.getQuantityOrdered().compareTo(new BigDecimal("0.0000")) == 1 ? aCusodetail.getQuantityOrdered() : new BigDecimal("0.0000")); aTpInventoryLog.setUserID(aCuso.getCreatedById()); aTpInventoryLog.setCreatedOn(new Date()); itsInventoryService.saveInventoryTransactions(aTpInventoryLog); /* * TpInventoryLogMaster Created on 04-12-2015 Code * Starts RollBack */ BigDecimal oqo = aCusodetail.getQuantityOrdered().subtract(aCusodetail.getQuantityBilled()); Prwarehouse otheprwarehouse = (Prwarehouse) aSession.get(Prwarehouse.class, aCuso.getPrFromWarehouseId()); Prwarehouseinventory otheprwarehsinventory = itsInventoryService .getPrwarehouseInventory(aCuso.getPrFromWarehouseId(), aPrmaster.getPrMasterId()); TpInventoryLogMaster oprmatpInventoryLogMstr = new TpInventoryLogMaster( aPrmaster.getPrMasterId(), aPrmaster.getItemCode(), aCuso.getPrFromWarehouseId(), otheprwarehouse.getSearchName(), aPrmaster.getInventoryOnHand(), otheprwarehsinventory.getInventoryOnHand(), oqo.multiply(new BigDecimal(-1)), BigDecimal.ZERO, "SO", aCuso.getCuSoid(), aCusodetail.getCuSodetailId(), aCuso.getSonumber(), null, /* Product out */(oqo.compareTo(BigDecimal.ZERO) < 0) ? oqo.multiply(new BigDecimal(-1)) : BigDecimal.ZERO, /* Product in */(oqo.compareTo(BigDecimal.ZERO) > 0) ? oqo : BigDecimal.ZERO, "SO Status Open to " + transstatus, aCusodetail.getUserID(), aCusodetail.getUserName(), new Date()); itsInventoryService.addTpInventoryLogMaster(oprmatpInventoryLogMstr); /* Code Ends */ } } } else if ((cuso.getTransactionStatus() == -2 || cuso.getTransactionStatus() == -1 || cuso.getTransactionStatus() == 0 || cuso.getTransactionStatus() == 2) && newstatus == 1) { String transstatus = ""; if (cuso.getTransactionStatus() == -2) { transstatus = "Quote"; } else if (cuso.getTransactionStatus() == -1) { transstatus = "Void"; } else if (cuso.getTransactionStatus() == 0) { transstatus = "onHold"; } else if (newstatus == 2) { transstatus = "Closed"; } ArrayList<Cusodetail> cusodtllist = (ArrayList<Cusodetail>) aQuery.list(); for (Cusodetail aCusodetail : cusodtllist) { aCusodetail.setUserID(userID); aCusodetail.setUserName(userName); itsjobService.insertPrMasterPrWareHouseInventory(aCusodetail.getCuSoid(), aCusodetail.getCuSodetailId()); if (aCusodetail.getCuSodetailId() > 0) { Cuso aCuso = (Cuso) aSession.get(Cuso.class, aCusodetail.getCuSoid()); TpInventoryLog aTpInventoryLog = new TpInventoryLog(); aTpInventoryLog.setPrMasterID(aCusodetail.getPrMasterId()); Prmaster aPrmaster = productService .getProducts(" WHERE prMasterID=" + aCusodetail.getPrMasterId()); aTpInventoryLog.setProductCode(aPrmaster.getItemCode()); aTpInventoryLog.setWareHouseID(aCuso.getPrFromWarehouseId()); aTpInventoryLog.setTransType("SO"); aTpInventoryLog.setTransDecription("SO Status " + transstatus + " to OPen"); aTpInventoryLog.setTransID(aCusodetail.getCuSoid()); aTpInventoryLog.setTransDetailID(aCusodetail.getCuSodetailId()); aTpInventoryLog.setProductOut( aCusodetail.getQuantityOrdered().compareTo(new BigDecimal("0.0000")) == 1 ? aCusodetail.getQuantityOrdered() : new BigDecimal("0.0000")); aTpInventoryLog.setProductIn( aCusodetail.getQuantityOrdered().compareTo(new BigDecimal("0.0000")) == -1 ? aCusodetail.getQuantityOrdered() : new BigDecimal("0.0000")); aTpInventoryLog.setUserID(aCuso.getCreatedById()); aTpInventoryLog.setCreatedOn(new Date()); itsInventoryService.saveInventoryTransactions(aTpInventoryLog); /* * TpInventoryLogMaster Created on 04-12-2015 Code * Starts */ BigDecimal qo = aCusodetail.getQuantityOrdered().subtract(aCusodetail.getQuantityBilled()); Prwarehouse theprwarehouse = (Prwarehouse) aSession.get(Prwarehouse.class, aCuso.getPrFromWarehouseId()); Prwarehouseinventory theprwarehsinventory = itsInventoryService .getPrwarehouseInventory(aCuso.getPrFromWarehouseId(), aPrmaster.getPrMasterId()); TpInventoryLogMaster prmatpInventoryLogMstr = new TpInventoryLogMaster( aPrmaster.getPrMasterId(), aPrmaster.getItemCode(), aCuso.getPrFromWarehouseId(), theprwarehouse.getSearchName(), aPrmaster.getInventoryOnHand(), theprwarehsinventory.getInventoryOnHand(), aCusodetail.getQuantityOrdered(), BigDecimal.ZERO, "SO", aCuso.getCuSoid(), aCusodetail.getCuSodetailId(), aCuso.getSonumber(), null, /* Product out */(qo.compareTo(BigDecimal.ZERO) > 0) ? qo : BigDecimal.ZERO, /* Product in */(qo.compareTo(BigDecimal.ZERO) < 0) ? qo.multiply(new BigDecimal(-1)) : BigDecimal.ZERO, "SO Status " + transstatus + " to OPen", aCusodetail.getUserID(), aCusodetail.getUserName(), new Date()); itsInventoryService.addTpInventoryLogMaster(prmatpInventoryLogMstr); /* Code Ends */ } } } } catch (Exception e) { itsLogger.error(e.getMessage(), e); } finally { aSession.flush(); aSession.close(); } }
From source file:com.gst.portfolio.loanproduct.serialization.LoanProductDataValidator.java
public void validateForCreate(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }/*w ww .j av a 2s .co m*/ final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("loanproduct"); final JsonElement element = this.fromApiJsonHelper.parse(json); final String name = this.fromApiJsonHelper.extractStringNamed("name", element); baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(100); final String shortName = this.fromApiJsonHelper.extractStringNamed(LoanProductConstants.shortName, element); baseDataValidator.reset().parameter(LoanProductConstants.shortName).value(shortName).notBlank() .notExceedingLengthOf(4); final String description = this.fromApiJsonHelper.extractStringNamed("description", element); baseDataValidator.reset().parameter("description").value(description).notExceedingLengthOf(500); if (this.fromApiJsonHelper.parameterExists("fundId", element)) { final Long fundId = this.fromApiJsonHelper.extractLongNamed("fundId", element); baseDataValidator.reset().parameter("fundId").value(fundId).ignoreIfNull().integerGreaterThanZero(); } if (this.fromApiJsonHelper .parameterExists(LoanProductConstants.minimumDaysBetweenDisbursalAndFirstRepayment, element)) { final Long minimumDaysBetweenDisbursalAndFirstRepayment = this.fromApiJsonHelper .extractLongNamed(LoanProductConstants.minimumDaysBetweenDisbursalAndFirstRepayment, element); baseDataValidator.reset().parameter(LoanProductConstants.minimumDaysBetweenDisbursalAndFirstRepayment) .value(minimumDaysBetweenDisbursalAndFirstRepayment).ignoreIfNull().integerGreaterThanZero(); } final Boolean includeInBorrowerCycle = this.fromApiJsonHelper.extractBooleanNamed("includeInBorrowerCycle", element); baseDataValidator.reset().parameter("includeInBorrowerCycle").value(includeInBorrowerCycle).ignoreIfNull() .validateForBooleanValue(); // terms final String currencyCode = this.fromApiJsonHelper.extractStringNamed("currencyCode", element); baseDataValidator.reset().parameter("currencyCode").value(currencyCode).notBlank().notExceedingLengthOf(3); final Integer digitsAfterDecimal = this.fromApiJsonHelper.extractIntegerNamed("digitsAfterDecimal", element, Locale.getDefault()); baseDataValidator.reset().parameter("digitsAfterDecimal").value(digitsAfterDecimal).notNull() .inMinMaxRange(0, 6); final Integer inMultiplesOf = this.fromApiJsonHelper.extractIntegerNamed("inMultiplesOf", element, Locale.getDefault()); baseDataValidator.reset().parameter("inMultiplesOf").value(inMultiplesOf).ignoreIfNull() .integerZeroOrGreater(); final BigDecimal principal = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("principal", element); baseDataValidator.reset().parameter("principal").value(principal).positiveAmount(); final String minPrincipalParameterName = "minPrincipal"; BigDecimal minPrincipalAmount = null; if (this.fromApiJsonHelper.parameterExists(minPrincipalParameterName, element)) { minPrincipalAmount = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(minPrincipalParameterName, element); baseDataValidator.reset().parameter(minPrincipalParameterName).value(minPrincipalAmount).ignoreIfNull() .positiveAmount(); } final String maxPrincipalParameterName = "maxPrincipal"; BigDecimal maxPrincipalAmount = null; if (this.fromApiJsonHelper.parameterExists(maxPrincipalParameterName, element)) { maxPrincipalAmount = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(maxPrincipalParameterName, element); baseDataValidator.reset().parameter(maxPrincipalParameterName).value(maxPrincipalAmount).ignoreIfNull() .positiveAmount(); } if (maxPrincipalAmount != null && maxPrincipalAmount.compareTo(BigDecimal.ZERO) != -1) { if (minPrincipalAmount != null && minPrincipalAmount.compareTo(BigDecimal.ZERO) != -1) { baseDataValidator.reset().parameter(maxPrincipalParameterName).value(maxPrincipalAmount) .notLessThanMin(minPrincipalAmount); if (minPrincipalAmount.compareTo(maxPrincipalAmount) <= 0 && principal != null) { baseDataValidator.reset().parameter("principal").value(principal) .inMinAndMaxAmountRange(minPrincipalAmount, maxPrincipalAmount); } } else if (principal != null) { baseDataValidator.reset().parameter("principal").value(principal) .notGreaterThanMax(maxPrincipalAmount); } } else if (minPrincipalAmount != null && minPrincipalAmount.compareTo(BigDecimal.ZERO) != -1 && principal != null) { baseDataValidator.reset().parameter("principal").value(principal).notLessThanMin(minPrincipalAmount); } final Integer numberOfRepayments = this.fromApiJsonHelper .extractIntegerWithLocaleNamed("numberOfRepayments", element); baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments).notNull() .integerGreaterThanZero(); final String minNumberOfRepaymentsParameterName = "minNumberOfRepayments"; Integer minNumberOfRepayments = null; if (this.fromApiJsonHelper.parameterExists(minNumberOfRepaymentsParameterName, element)) { minNumberOfRepayments = this.fromApiJsonHelper .extractIntegerWithLocaleNamed(minNumberOfRepaymentsParameterName, element); baseDataValidator.reset().parameter(minNumberOfRepaymentsParameterName).value(minNumberOfRepayments) .ignoreIfNull().integerGreaterThanZero(); } final String maxNumberOfRepaymentsParameterName = "maxNumberOfRepayments"; Integer maxNumberOfRepayments = null; if (this.fromApiJsonHelper.parameterExists(maxNumberOfRepaymentsParameterName, element)) { maxNumberOfRepayments = this.fromApiJsonHelper .extractIntegerWithLocaleNamed(maxNumberOfRepaymentsParameterName, element); baseDataValidator.reset().parameter(maxNumberOfRepaymentsParameterName).value(maxNumberOfRepayments) .ignoreIfNull().integerGreaterThanZero(); } if (maxNumberOfRepayments != null && maxNumberOfRepayments.compareTo(0) == 1) { if (minNumberOfRepayments != null && minNumberOfRepayments.compareTo(0) == 1) { baseDataValidator.reset().parameter(maxNumberOfRepaymentsParameterName).value(maxNumberOfRepayments) .notLessThanMin(minNumberOfRepayments); if (minNumberOfRepayments.compareTo(maxNumberOfRepayments) <= 0) { baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments) .inMinMaxRange(minNumberOfRepayments, maxNumberOfRepayments); } } else { baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments) .notGreaterThanMax(maxNumberOfRepayments); } } else if (minNumberOfRepayments != null && minNumberOfRepayments.compareTo(0) == 1) { baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments) .notLessThanMin(minNumberOfRepayments); } final Integer repaymentEvery = this.fromApiJsonHelper.extractIntegerWithLocaleNamed("repaymentEvery", element); baseDataValidator.reset().parameter("repaymentEvery").value(repaymentEvery).notNull() .integerGreaterThanZero(); final Integer repaymentFrequencyType = this.fromApiJsonHelper.extractIntegerNamed("repaymentFrequencyType", element, Locale.getDefault()); baseDataValidator.reset().parameter("repaymentFrequencyType").value(repaymentFrequencyType).notNull() .inMinMaxRange(0, 3); // settings final Integer amortizationType = this.fromApiJsonHelper.extractIntegerNamed("amortizationType", element, Locale.getDefault()); baseDataValidator.reset().parameter("amortizationType").value(amortizationType).notNull().inMinMaxRange(0, 1); final Integer interestType = this.fromApiJsonHelper.extractIntegerNamed("interestType", element, Locale.getDefault()); baseDataValidator.reset().parameter("interestType").value(interestType).notNull().inMinMaxRange(0, 1); final Integer interestCalculationPeriodType = this.fromApiJsonHelper .extractIntegerNamed("interestCalculationPeriodType", element, Locale.getDefault()); baseDataValidator.reset().parameter("interestCalculationPeriodType").value(interestCalculationPeriodType) .notNull().inMinMaxRange(0, 1); final BigDecimal inArrearsTolerance = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed("inArrearsTolerance", element); baseDataValidator.reset().parameter("inArrearsTolerance").value(inArrearsTolerance).ignoreIfNull() .zeroOrPositiveAmount(); final Long transactionProcessingStrategyId = this.fromApiJsonHelper .extractLongNamed("transactionProcessingStrategyId", element); baseDataValidator.reset().parameter("transactionProcessingStrategyId") .value(transactionProcessingStrategyId).notNull().integerGreaterThanZero(); // grace validation final Integer graceOnPrincipalPayment = this.fromApiJsonHelper .extractIntegerWithLocaleNamed("graceOnPrincipalPayment", element); baseDataValidator.reset().parameter("graceOnPrincipalPayment").value(graceOnPrincipalPayment) .zeroOrPositiveAmount(); final Integer graceOnInterestPayment = this.fromApiJsonHelper .extractIntegerWithLocaleNamed("graceOnInterestPayment", element); baseDataValidator.reset().parameter("graceOnInterestPayment").value(graceOnInterestPayment) .zeroOrPositiveAmount(); final Integer graceOnInterestCharged = this.fromApiJsonHelper .extractIntegerWithLocaleNamed("graceOnInterestCharged", element); baseDataValidator.reset().parameter("graceOnInterestCharged").value(graceOnInterestCharged) .zeroOrPositiveAmount(); final Integer graceOnArrearsAgeing = this.fromApiJsonHelper .extractIntegerWithLocaleNamed(LoanProductConstants.graceOnArrearsAgeingParameterName, element); baseDataValidator.reset().parameter(LoanProductConstants.graceOnArrearsAgeingParameterName) .value(graceOnArrearsAgeing).integerZeroOrGreater(); final Integer overdueDaysForNPA = this.fromApiJsonHelper .extractIntegerWithLocaleNamed(LoanProductConstants.overdueDaysForNPAParameterName, element); baseDataValidator.reset().parameter(LoanProductConstants.overdueDaysForNPAParameterName) .value(overdueDaysForNPA).integerZeroOrGreater(); /** * { @link DaysInYearType } */ final Integer daysInYearType = this.fromApiJsonHelper.extractIntegerNamed( LoanProductConstants.daysInYearTypeParameterName, element, Locale.getDefault()); baseDataValidator.reset().parameter(LoanProductConstants.daysInYearTypeParameterName).value(daysInYearType) .notNull().isOneOfTheseValues(1, 360, 364, 365); /** * { @link DaysInMonthType } */ final Integer daysInMonthType = this.fromApiJsonHelper.extractIntegerNamed( LoanProductConstants.daysInMonthTypeParameterName, element, Locale.getDefault()); baseDataValidator.reset().parameter(LoanProductConstants.daysInMonthTypeParameterName) .value(daysInMonthType).notNull().isOneOfTheseValues(1, 30); if (this.fromApiJsonHelper.parameterExists( LoanProductConstants.accountMovesOutOfNPAOnlyOnArrearsCompletionParamName, element)) { Boolean npaChangeConfig = this.fromApiJsonHelper.extractBooleanNamed( LoanProductConstants.accountMovesOutOfNPAOnlyOnArrearsCompletionParamName, element); baseDataValidator.reset() .parameter(LoanProductConstants.accountMovesOutOfNPAOnlyOnArrearsCompletionParamName) .value(npaChangeConfig).notNull().isOneOfTheseValues(true, false); } // Interest recalculation settings final Boolean isInterestRecalculationEnabled = this.fromApiJsonHelper .extractBooleanNamed(LoanProductConstants.isInterestRecalculationEnabledParameterName, element); baseDataValidator.reset().parameter(LoanProductConstants.isInterestRecalculationEnabledParameterName) .value(isInterestRecalculationEnabled).notNull().isOneOfTheseValues(true, false); if (isInterestRecalculationEnabled != null) { if (isInterestRecalculationEnabled.booleanValue()) { validateInterestRecalculationParams(element, baseDataValidator, null); } } // interest rates if (this.fromApiJsonHelper.parameterExists("isLinkedToFloatingInterestRates", element) && this.fromApiJsonHelper.extractBooleanNamed("isLinkedToFloatingInterestRates", element) == true) { if (this.fromApiJsonHelper.parameterExists("interestRatePerPeriod", element)) { baseDataValidator.reset().parameter("interestRatePerPeriod").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.true", "interestRatePerPeriod param is not supported when isLinkedToFloatingInterestRates is true"); } if (this.fromApiJsonHelper.parameterExists("minInterestRatePerPeriod", element)) { baseDataValidator.reset().parameter("minInterestRatePerPeriod").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.true", "minInterestRatePerPeriod param is not supported when isLinkedToFloatingInterestRates is true"); } if (this.fromApiJsonHelper.parameterExists("maxInterestRatePerPeriod", element)) { baseDataValidator.reset().parameter("maxInterestRatePerPeriod").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.true", "maxInterestRatePerPeriod param is not supported when isLinkedToFloatingInterestRates is true"); } if (this.fromApiJsonHelper.parameterExists("interestRateFrequencyType", element)) { baseDataValidator.reset().parameter("interestRateFrequencyType").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.true", "interestRateFrequencyType param is not supported when isLinkedToFloatingInterestRates is true"); } if ((interestType == null || interestType != InterestMethod.DECLINING_BALANCE.getValue()) || (isInterestRecalculationEnabled == null || isInterestRecalculationEnabled == false)) { baseDataValidator.reset().parameter("isLinkedToFloatingInterestRates").failWithCode( "supported.only.for.declining.balance.interest.recalculation.enabled", "Floating interest rates are supported only for declining balance and interest recalculation enabled loan products"); } final Integer floatingRatesId = this.fromApiJsonHelper.extractIntegerNamed("floatingRatesId", element, Locale.getDefault()); baseDataValidator.reset().parameter("floatingRatesId").value(floatingRatesId).notNull(); final BigDecimal interestRateDifferential = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed("interestRateDifferential", element); baseDataValidator.reset().parameter("interestRateDifferential").value(interestRateDifferential) .notNull().zeroOrPositiveAmount(); final String minDifferentialLendingRateParameterName = "minDifferentialLendingRate"; BigDecimal minDifferentialLendingRate = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed(minDifferentialLendingRateParameterName, element); baseDataValidator.reset().parameter(minDifferentialLendingRateParameterName) .value(minDifferentialLendingRate).notNull().zeroOrPositiveAmount(); final String defaultDifferentialLendingRateParameterName = "defaultDifferentialLendingRate"; BigDecimal defaultDifferentialLendingRate = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed(defaultDifferentialLendingRateParameterName, element); baseDataValidator.reset().parameter(defaultDifferentialLendingRateParameterName) .value(defaultDifferentialLendingRate).notNull().zeroOrPositiveAmount(); final String maxDifferentialLendingRateParameterName = "maxDifferentialLendingRate"; BigDecimal maxDifferentialLendingRate = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed(maxDifferentialLendingRateParameterName, element); baseDataValidator.reset().parameter(maxDifferentialLendingRateParameterName) .value(maxDifferentialLendingRate).notNull().zeroOrPositiveAmount(); if (defaultDifferentialLendingRate != null && defaultDifferentialLendingRate.compareTo(BigDecimal.ZERO) != -1) { if (minDifferentialLendingRate != null && minDifferentialLendingRate.compareTo(BigDecimal.ZERO) != -1) { baseDataValidator.reset().parameter("defaultDifferentialLendingRate") .value(defaultDifferentialLendingRate).notLessThanMin(minDifferentialLendingRate); } } if (maxDifferentialLendingRate != null && maxDifferentialLendingRate.compareTo(BigDecimal.ZERO) != -1) { if (minDifferentialLendingRate != null && minDifferentialLendingRate.compareTo(BigDecimal.ZERO) != -1) { baseDataValidator.reset().parameter("maxDifferentialLendingRate") .value(maxDifferentialLendingRate).notLessThanMin(minDifferentialLendingRate); } } if (maxDifferentialLendingRate != null && maxDifferentialLendingRate.compareTo(BigDecimal.ZERO) != -1) { if (defaultDifferentialLendingRate != null && defaultDifferentialLendingRate.compareTo(BigDecimal.ZERO) != -1) { baseDataValidator.reset().parameter("maxDifferentialLendingRate") .value(maxDifferentialLendingRate).notLessThanMin(defaultDifferentialLendingRate); } } final Boolean isFloatingInterestRateCalculationAllowed = this.fromApiJsonHelper .extractBooleanNamed("isFloatingInterestRateCalculationAllowed", element); baseDataValidator.reset().parameter("isFloatingInterestRateCalculationAllowed") .value(isFloatingInterestRateCalculationAllowed).notNull().isOneOfTheseValues(true, false); } else { if (this.fromApiJsonHelper.parameterExists("floatingRatesId", element)) { baseDataValidator.reset().parameter("floatingRatesId").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.false", "floatingRatesId param is not supported when isLinkedToFloatingInterestRates is not supplied or false"); } if (this.fromApiJsonHelper.parameterExists("interestRateDifferential", element)) { baseDataValidator.reset().parameter("interestRateDifferential").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.false", "interestRateDifferential param is not supported when isLinkedToFloatingInterestRates is not supplied or false"); } if (this.fromApiJsonHelper.parameterExists("minDifferentialLendingRate", element)) { baseDataValidator.reset().parameter("minDifferentialLendingRate").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.false", "minDifferentialLendingRate param is not supported when isLinkedToFloatingInterestRates is not supplied or false"); } if (this.fromApiJsonHelper.parameterExists("defaultDifferentialLendingRate", element)) { baseDataValidator.reset().parameter("defaultDifferentialLendingRate").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.false", "defaultDifferentialLendingRate param is not supported when isLinkedToFloatingInterestRates is not supplied or false"); } if (this.fromApiJsonHelper.parameterExists("maxDifferentialLendingRate", element)) { baseDataValidator.reset().parameter("maxDifferentialLendingRate").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.false", "maxDifferentialLendingRate param is not supported when isLinkedToFloatingInterestRates is not supplied or false"); } if (this.fromApiJsonHelper.parameterExists("isFloatingInterestRateCalculationAllowed", element)) { baseDataValidator.reset().parameter("isFloatingInterestRateCalculationAllowed").failWithCode( "not.supported.when.isLinkedToFloatingInterestRates.is.false", "isFloatingInterestRateCalculationAllowed param is not supported when isLinkedToFloatingInterestRates is not supplied or false"); } final BigDecimal interestRatePerPeriod = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed("interestRatePerPeriod", element); baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod).notNull() .zeroOrPositiveAmount(); final String minInterestRatePerPeriodParameterName = "minInterestRatePerPeriod"; BigDecimal minInterestRatePerPeriod = null; if (this.fromApiJsonHelper.parameterExists(minInterestRatePerPeriodParameterName, element)) { minInterestRatePerPeriod = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed(minInterestRatePerPeriodParameterName, element); baseDataValidator.reset().parameter(minInterestRatePerPeriodParameterName) .value(minInterestRatePerPeriod).ignoreIfNull().zeroOrPositiveAmount(); } final String maxInterestRatePerPeriodParameterName = "maxInterestRatePerPeriod"; BigDecimal maxInterestRatePerPeriod = null; if (this.fromApiJsonHelper.parameterExists(maxInterestRatePerPeriodParameterName, element)) { maxInterestRatePerPeriod = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed(maxInterestRatePerPeriodParameterName, element); baseDataValidator.reset().parameter(maxInterestRatePerPeriodParameterName) .value(maxInterestRatePerPeriod).ignoreIfNull().zeroOrPositiveAmount(); } if (maxInterestRatePerPeriod != null && maxInterestRatePerPeriod.compareTo(BigDecimal.ZERO) != -1) { if (minInterestRatePerPeriod != null && minInterestRatePerPeriod.compareTo(BigDecimal.ZERO) != -1) { baseDataValidator.reset().parameter(maxInterestRatePerPeriodParameterName) .value(maxInterestRatePerPeriod).notLessThanMin(minInterestRatePerPeriod); if (minInterestRatePerPeriod.compareTo(maxInterestRatePerPeriod) <= 0) { baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod) .inMinAndMaxAmountRange(minInterestRatePerPeriod, maxInterestRatePerPeriod); } } else { baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod) .notGreaterThanMax(maxInterestRatePerPeriod); } } else if (minInterestRatePerPeriod != null && minInterestRatePerPeriod.compareTo(BigDecimal.ZERO) != -1) { baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod) .notLessThanMin(minInterestRatePerPeriod); } final Integer interestRateFrequencyType = this.fromApiJsonHelper .extractIntegerNamed("interestRateFrequencyType", element, Locale.getDefault()); baseDataValidator.reset().parameter("interestRateFrequencyType").value(interestRateFrequencyType) .notNull().inMinMaxRange(0, 3); } // Guarantee Funds Boolean holdGuaranteeFunds = false; if (this.fromApiJsonHelper.parameterExists(LoanProductConstants.holdGuaranteeFundsParamName, element)) { holdGuaranteeFunds = this.fromApiJsonHelper .extractBooleanNamed(LoanProductConstants.holdGuaranteeFundsParamName, element); baseDataValidator.reset().parameter(LoanProductConstants.holdGuaranteeFundsParamName) .value(holdGuaranteeFunds).notNull().isOneOfTheseValues(true, false); } if (holdGuaranteeFunds != null) { if (holdGuaranteeFunds) { validateGuaranteeParams(element, baseDataValidator, null); } } BigDecimal principalThresholdForLastInstallment = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed( LoanProductConstants.principalThresholdForLastInstallmentParamName, element); baseDataValidator.reset().parameter(LoanProductConstants.principalThresholdForLastInstallmentParamName) .value(principalThresholdForLastInstallment).notLessThanMin(BigDecimal.ZERO) .notGreaterThanMax(BigDecimal.valueOf(100)); if (this.fromApiJsonHelper.parameterExists(LoanProductConstants.canDefineEmiAmountParamName, element)) { final Boolean canDefineInstallmentAmount = this.fromApiJsonHelper .extractBooleanNamed(LoanProductConstants.canDefineEmiAmountParamName, element); baseDataValidator.reset().parameter(LoanProductConstants.canDefineEmiAmountParamName) .value(canDefineInstallmentAmount).isOneOfTheseValues(true, false); } if (this.fromApiJsonHelper.parameterExists(LoanProductConstants.installmentAmountInMultiplesOfParamName, element)) { final Integer installmentAmountInMultiplesOf = this.fromApiJsonHelper.extractIntegerWithLocaleNamed( LoanProductConstants.installmentAmountInMultiplesOfParamName, element); baseDataValidator.reset().parameter(LoanProductConstants.installmentAmountInMultiplesOfParamName) .value(installmentAmountInMultiplesOf).ignoreIfNull().integerGreaterThanZero(); } // accounting related data validation final Integer accountingRuleType = this.fromApiJsonHelper.extractIntegerNamed("accountingRule", element, Locale.getDefault()); baseDataValidator.reset().parameter("accountingRule").value(accountingRuleType).notNull().inMinMaxRange(1, 4); if (isCashBasedAccounting(accountingRuleType) || isAccrualBasedAccounting(accountingRuleType)) { final Long fundAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.FUND_SOURCE.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.FUND_SOURCE.getValue()) .value(fundAccountId).notNull().integerGreaterThanZero(); final Long loanPortfolioAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.LOAN_PORTFOLIO.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.LOAN_PORTFOLIO.getValue()) .value(loanPortfolioAccountId).notNull().integerGreaterThanZero(); final Long transfersInSuspenseAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.TRANSFERS_SUSPENSE.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.TRANSFERS_SUSPENSE.getValue()) .value(transfersInSuspenseAccountId).notNull().integerGreaterThanZero(); final Long incomeFromInterestId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.INTEREST_ON_LOANS.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.INTEREST_ON_LOANS.getValue()) .value(incomeFromInterestId).notNull().integerGreaterThanZero(); final Long incomeFromFeeId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_FEES.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_FEES.getValue()) .value(incomeFromFeeId).notNull().integerGreaterThanZero(); final Long incomeFromPenaltyId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_PENALTIES.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_PENALTIES.getValue()) .value(incomeFromPenaltyId).notNull().integerGreaterThanZero(); final Long incomeFromRecoveryAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_RECOVERY.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_RECOVERY.getValue()) .value(incomeFromRecoveryAccountId).notNull().integerGreaterThanZero(); final Long writeOffAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.LOSSES_WRITTEN_OFF.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.LOSSES_WRITTEN_OFF.getValue()) .value(writeOffAccountId).notNull().integerGreaterThanZero(); final Long overpaymentAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.OVERPAYMENT.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.OVERPAYMENT.getValue()) .value(overpaymentAccountId).notNull().integerGreaterThanZero(); validatePaymentChannelFundSourceMappings(baseDataValidator, element); validateChargeToIncomeAccountMappings(baseDataValidator, element); } if (isAccrualBasedAccounting(accountingRuleType)) { final Long receivableInterestAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.INTEREST_RECEIVABLE.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.INTEREST_RECEIVABLE.getValue()) .value(receivableInterestAccountId).notNull().integerGreaterThanZero(); final Long receivableFeeAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.FEES_RECEIVABLE.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.FEES_RECEIVABLE.getValue()) .value(receivableFeeAccountId).notNull().integerGreaterThanZero(); final Long receivablePenaltyAccountId = this.fromApiJsonHelper .extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.PENALTIES_RECEIVABLE.getValue(), element); baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.PENALTIES_RECEIVABLE.getValue()) .value(receivablePenaltyAccountId).notNull().integerGreaterThanZero(); } if (this.fromApiJsonHelper.parameterExists(LoanProductConstants.useBorrowerCycleParameterName, element)) { final Boolean useBorrowerCycle = this.fromApiJsonHelper .extractBooleanNamed(LoanProductConstants.useBorrowerCycleParameterName, element); baseDataValidator.reset().parameter(LoanProductConstants.useBorrowerCycleParameterName) .value(useBorrowerCycle).ignoreIfNull().validateForBooleanValue(); if (useBorrowerCycle) { validateBorrowerCycleVariations(element, baseDataValidator); } } validateMultiDisburseLoanData(baseDataValidator, element); validateLoanConfigurableAttributes(baseDataValidator, element); validateVariableInstallmentSettings(baseDataValidator, element); validatePartialPeriodSupport(interestCalculationPeriodType, baseDataValidator, element, null); if (this.fromApiJsonHelper.parameterExists(LoanProductConstants.canUseForTopup, element)) { final Boolean canUseForTopup = this.fromApiJsonHelper .extractBooleanNamed(LoanProductConstants.canUseForTopup, element); baseDataValidator.reset().parameter(LoanProductConstants.canUseForTopup).value(canUseForTopup) .validateForBooleanValue(); } throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:com.gst.portfolio.savings.domain.SavingsAccount.java
protected boolean updateWithHoldTransaction(final BigDecimal amount, final SavingsAccountTransaction withholdTransaction) { boolean isTaxAdded = false; if (this.taxGroup != null && amount.compareTo(BigDecimal.ZERO) == 1) { Map<TaxComponent, BigDecimal> taxSplit = TaxUtils.splitTax(amount, withholdTransaction.transactionLocalDate(), this.taxGroup.getTaxGroupMappings(), amount.scale());//from w ww . j a v a 2 s .c o m BigDecimal totalTax = TaxUtils.totalTaxAmount(taxSplit); if (totalTax.compareTo(BigDecimal.ZERO) == 1) { if (withholdTransaction.getId() == null) { withholdTransaction.updateAmount(Money.of(currency, totalTax)); withholdTransaction.getTaxDetails().clear(); SavingsAccountTransaction.updateTaxDetails(taxSplit, withholdTransaction); isTaxAdded = true; } else if (totalTax.compareTo(withholdTransaction.getAmount()) != 0) { withholdTransaction.reverse(); SavingsAccountTransaction newWithholdTransaction = SavingsAccountTransaction.withHoldTax(this, office(), withholdTransaction.transactionLocalDate(), Money.of(currency, totalTax), taxSplit); addTransaction(newWithholdTransaction); isTaxAdded = true; } } } return isTaxAdded; }
From source file:org.egov.dao.budget.BudgetDetailsHibernateDAO.java
/** * To check budget available for the glcode with other parameters. if txnamt * is less than the budget available, it would return true, otherwise false. * //from w ww . j a va 2 s . co m * @param paramMap * @return @ */ private boolean checkCondition(final Map<String, Object> paramMap) { String txnType = null; String glCode = null; BigDecimal txnAmt = null; java.util.Date asondate = null; java.util.Date fromdate = null; try { if (paramMap.get("txnAmt") != null) txnAmt = (BigDecimal) paramMap.get("txnAmt"); if (paramMap.get("txnType") != null) txnType = paramMap.get("txnType").toString(); if (paramMap.get("glcode") != null) glCode = paramMap.get("glcode").toString(); if (paramMap.get(Constants.ASONDATE) != null) asondate = (Date) paramMap.get(Constants.ASONDATE); if (glCode == null) throw new ValidationException(EMPTY_STRING, "glcode is null"); if (txnAmt == null) throw new ValidationException(EMPTY_STRING, "txnAmt is null"); if (txnType == null) throw new ValidationException(EMPTY_STRING, "txnType is null"); if (asondate == null) throw new ValidationException(EMPTY_STRING, "As On Date is null"); // check the account code needs budget checking final CChartOfAccounts coa = chartOfAccountsHibernateDAO.getCChartOfAccountsByGlCode(glCode); if (coa.getBudgetCheckReq() != null && coa.getBudgetCheckReq()) { // get budgethead for the glcode // BudgetGroup bg = getBudgetHeadByGlcode(coa,paramMap); final List<BudgetGroup> budgetHeadListByGlcode = getBudgetHeadByGlcode(coa); if (budgetHeadListByGlcode == null || budgetHeadListByGlcode.size() == 0) throw new ValidationException(EMPTY_STRING, "Budget Check failed: Budget not defined for the given combination."); // get budgettinh type for first BG object if (!isBudgetCheckingRequiredForType(txnType, budgetHeadListByGlcode.get(0).getBudgetingType().toString())) { if (LOGGER.isDebugEnabled()) LOGGER.debug("No need to check budget for :" + glCode + " as the transaction type is " + txnType); return true; } paramMap.put("glcodeid", coa.getId()); // get the financialyear from asondate final CFinancialYear finyear = financialYearHibDAO.getFinancialYearByDate(asondate); if (finyear == null) throw new ValidationException(EMPTY_STRING, "Financial Year is not defined for-" + asondate); new SimpleDateFormat("dd-MMM-yyyy", Constants.LOCALE); fromdate = finyear.getStartingDate(); paramMap.put("fromdate", fromdate); // Here as on date is overridden by Financialyear ending date to // check all budget appropriation irrespective of // date paramMap.put(Constants.ASONDATE, finyear.getEndingDate()); paramMap.put("financialyearid", Long.valueOf(finyear.getId())); paramMap.put(BUDGETHEADID, budgetHeadListByGlcode); if (LOGGER.isDebugEnabled()) LOGGER.debug("************ BudgetCheck Details *********************"); // pass the list of bg to getBudgetedAmtForYear final BigDecimal budgetedAmt = getBudgetedAmtForYear(paramMap); // get // the // budgetedamount if (LOGGER.isDebugEnabled()) LOGGER.debug(".............Budgeted Amount For the year............" + budgetedAmt); if (budgetCheckConfigService.getConfigValue() .equalsIgnoreCase(BudgetControlType.BudgetCheckOption.MANDATORY.toString())) if (budgetedAmt.compareTo(BigDecimal.ZERO) == 0) return false; final BigDecimal actualAmt = getActualBudgetUtilizedForBudgetaryCheck(paramMap); // get // actual // amount if (LOGGER.isDebugEnabled()) LOGGER.debug(".............Voucher Actual amount............" + actualAmt); BigDecimal billAmt = getBillAmountForBudgetCheck(paramMap); // get // actual // amount if (LOGGER.isDebugEnabled()) LOGGER.debug(".............Bill Actual amount............" + billAmt); EgBillregister bill = null; if (paramMap.get("bill") != null) bill = (EgBillregister) persistenceService.find("from EgBillregister where id=? ", (Long) paramMap.get("bill")); if (bill != null && bill.getEgBillregistermis().getBudgetaryAppnumber() != null) { if (LOGGER.isDebugEnabled()) LOGGER.debug(".............Found BillId so subtracting txn amount......................" + txnAmt); billAmt = billAmt.subtract(txnAmt); } if (LOGGER.isDebugEnabled()) LOGGER.debug(".......Recalculated Bill Actual amount............" + billAmt); final BigDecimal diff = budgetedAmt.subtract(actualAmt).subtract(billAmt); // get // bill // amt if (LOGGER.isDebugEnabled()) LOGGER.debug(".................diff amount..........................." + diff); if (LOGGER.isDebugEnabled()) LOGGER.debug("************ BudgetCheck Details End****************"); // BigDecimal diff = budgetedAmt.subtract(actualAmt); if (budgetCheckConfigService.getConfigValue() .equalsIgnoreCase(BudgetControlType.BudgetCheckOption.MANDATORY.toString())) { if (txnAmt.compareTo(diff) <= 0) { generateBanNumber(paramMap, bill); return true; } else return false; } if (budgetCheckConfigService.getConfigValue() .equalsIgnoreCase(BudgetControlType.BudgetCheckOption.ANTICIPATORY.toString())) { generateBanNumber(paramMap, bill); return true; } } else // no budget check for coa return true; } catch (final ValidationException v) { throw v; } catch (final Exception e) { throw new ValidationException(EMPTY_STRING, e.getMessage()); } return true; }
From source file:com.gst.accounting.journalentry.service.AccountingProcessorHelper.java
public void createCreditJournalEntryOrReversalForLoanCharges(final Office office, final String currencyCode, final int accountMappingTypeId, final Long loanProductId, final Long loanId, final String transactionId, final Date transactionDate, final BigDecimal totalAmount, final Boolean isReversal, final List<ChargePaymentDTO> chargePaymentDTOs) { /***// www . j a v a 2 s.c o m * Map to track each account and the net credit to be made for a * particular account ***/ final Map<GLAccount, BigDecimal> creditDetailsMap = new LinkedHashMap<>(); for (final ChargePaymentDTO chargePaymentDTO : chargePaymentDTOs) { final Long chargeId = chargePaymentDTO.getChargeId(); final GLAccount chargeSpecificAccount = getLinkedGLAccountForLoanCharges(loanProductId, accountMappingTypeId, chargeId); BigDecimal chargeSpecificAmount = chargePaymentDTO.getAmount(); // adjust net credit amount if the account is already present in the // map if (creditDetailsMap.containsKey(chargeSpecificAccount)) { final BigDecimal existingAmount = creditDetailsMap.get(chargeSpecificAccount); chargeSpecificAmount = chargeSpecificAmount.add(existingAmount); } creditDetailsMap.put(chargeSpecificAccount, chargeSpecificAmount); } BigDecimal totalCreditedAmount = BigDecimal.ZERO; for (final Map.Entry<GLAccount, BigDecimal> entry : creditDetailsMap.entrySet()) { final GLAccount account = entry.getKey(); final BigDecimal amount = entry.getValue(); totalCreditedAmount = totalCreditedAmount.add(amount); if (isReversal) { createDebitJournalEntryForLoan(office, currencyCode, account, loanId, transactionId, transactionDate, amount); } else { createCreditJournalEntryForLoan(office, currencyCode, account, loanId, transactionId, transactionDate, amount); } } // TODO: Vishwas Temporary validation to be removed before moving to // release branch if (totalAmount.compareTo(totalCreditedAmount) != 0) { throw new PlatformDataIntegrityException( "Meltdown in advanced accounting...sum of all charges is not equal to the fee charge for a transaction", "Meltdown in advanced accounting...sum of all charges is not equal to the fee charge for a transaction", totalCreditedAmount, totalAmount); } }
From source file:org.egov.dao.budget.BudgetDetailsHibernateDAO.java
@Deprecated private BigDecimal getDetails(final Long financialyearid, final Integer moduleid, final String referencenumber, final Integer departmentid, final Long functionid, final Integer functionaryid, final Integer schemeid, final Integer subschemeid, final Integer boundaryid, final List<Long> budgetheadid, final Integer fundid, final double amount, final boolean consumeOrRelease, final String appropriationnumber) { try {/*from ww w . j av a 2 s .c om*/ if (LOGGER.isDebugEnabled()) LOGGER.debug("financialyearid==" + financialyearid + ",moduleid==" + moduleid + ",referencenumber==" + referencenumber + ",departmentid==" + departmentid + ",functionid==" + functionid + ",functionaryid==" + functionaryid + ",schemeid==" + schemeid + ",subschemeid==" + subschemeid + ",boundaryid==" + boundaryid + ",budgetheadid==" + budgetheadid + ",amount==" + amount); validateMandatoryParameters(moduleid, referencenumber); BigDecimal amtavailable = getPlanningBudgetAvailable(financialyearid, departmentid, functionid, functionaryid, schemeid, subschemeid, boundaryid, budgetheadid, fundid); if (consumeOrRelease) amtavailable = amtavailable.subtract(BigDecimal.valueOf(amount)); else amtavailable = amtavailable.add(BigDecimal.valueOf(amount)); if (LOGGER.isDebugEnabled()) LOGGER.debug("budget available after consuming/releasing=" + amtavailable); if (amtavailable != null && amtavailable.compareTo(BigDecimal.ZERO) >= 0) { // need to update budget details final String query = prepareQuery(departmentid, functionid, functionaryid, schemeid, subschemeid, boundaryid, fundid); final Query q = persistenceService.getSession().createQuery( " from BudgetDetail bd where bd.budget.financialYear.id=:finYearId and bd.budget.isbere=:type and bd.budgetGroup.id in (:bgId)" + query); if (budgetService.hasApprovedReForYear(financialyearid)) q.setParameter("type", "RE"); else q.setParameter("type", "BE"); q.setParameter("finYearId", financialyearid); q.setParameterList("bgId", budgetheadid); final List<BudgetDetail> bdList = q.list(); if (bdList == null || bdList.size() == 0) { if (LOGGER.isDebugEnabled()) LOGGER.debug( "IN consumeEncumbranceBudget()-getDetail() - No budget detail item defined for RE or BE for this combination!!"); if (LOGGER.isDebugEnabled()) LOGGER.debug("financial year id - " + financialyearid.toString() + " Budget Group - " + budgetheadid.toString() + " Query - " + query); throw new ValidationException(EMPTY_STRING, "Budgetary Check Failed"); } final BudgetDetail bd = bdList.get(0); bd.setBudgetAvailable(amtavailable); update(bd); final BudgetUsage budgetUsage = new BudgetUsage(); budgetUsage.setFinancialYearId(financialyearid.intValue()); budgetUsage.setModuleId(moduleid); budgetUsage.setReferenceNumber(referencenumber); budgetUsage.setBudgetDetail(bd); budgetUsage.setAppropriationnumber(appropriationnumber); if (consumeOrRelease) { budgetUsage.setConsumedAmount(amount); budgetUsage.setReleasedAmount(0.0); } else { budgetUsage.setConsumedAmount(0.0); budgetUsage.setReleasedAmount(amount); } budgetUsage.setCreatedby(ApplicationThreadLocals.getUserId().intValue()); budgetUsageService.create(budgetUsage); return BigDecimal.ONE; } else return BigDecimal.ZERO; } catch (final ValidationException v) { throw v; } catch (final Exception e) { throw new ValidationException(EMPTY_STRING, e.getMessage()); } }
From source file:com.att.pirates.controller.ProjectController.java
private static String getRowDueDatePercentageString(String Percentage, String Duedate, String UpdatedByUUID, String uuid, String headerDueDate, boolean left, boolean validateThreshold) { String[] datecreatedList = Duedate.split(","); String[] percentageList = Percentage.split(","); String[] uuidList = UpdatedByUUID.split(","); SimpleDateFormat xFormat = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat yFormat = new SimpleDateFormat("MM/dd/yy"); if (datecreatedList == null || datecreatedList.length == 0) { return "NA"; }//ww w. j a v a2 s . c o m if (("NA".equalsIgnoreCase(datecreatedList[0])) || ("NA".equalsIgnoreCase(headerDueDate))) { return "NA"; } if (percentageList.length != datecreatedList.length) { //logger.error("Error, DateCreated count does not equal Percentage count"); return ""; } try { // mchan: added code to evaluate if the latest updated date fits in the threashold // get threshold info for user, 1 = noupdate, 2 = duein List<Threshold> thresholds = DataService.getEmployeeThresholds(uuid); String warningMsg = ""; if (thresholds != null && !thresholds.isEmpty() && validateThreshold) { // since we have a list of dates, we just need the max List<Integer> noupdates = new ArrayList<Integer>(); List<Integer> dueins = new ArrayList<Integer>(); String percent = percentageList[0]; BigDecimal d = new BigDecimal(percent.trim().replace("%", "")).divide(BigDecimal.valueOf(100)); if (d.compareTo(BigDecimal.ONE) == 0) { //logger.error(d + ", is exactly one"); } else if (d.compareTo(BigDecimal.ONE) == 1) { //logger.error(d + ", is greater than one"); } else if (d.compareTo(BigDecimal.ONE) == -1) { //logger.error(d + ", is less than one"); } for (Threshold t : thresholds) { // process NoUpdate if (PiratesConstants.NOUPDATE.equalsIgnoreCase(t.getThresholdType())) { try { noupdates.add(Integer.parseInt(t.getThresholdValue())); } catch (NumberFormatException ex) { //logger.error("Error parsing threshold value, type: NOUPDATE, value: " + t.getThresholdValue()); } } // process DueIn if (PiratesConstants.DUEIN.equalsIgnoreCase(t.getThresholdType())) { try { dueins.add(Integer.parseInt(t.getThresholdValue())); } catch (NumberFormatException ex) { //logger.error("Error parsing threshold value, type: DUEIN, value: " + t.getThresholdValue()); } } } // done parsing thresholds if (!noupdates.isEmpty() && (d.compareTo(BigDecimal.ONE) == -1) && (!"NA".equalsIgnoreCase(datecreatedList[0])) && validateThreshold) { // compare dates, last updated and today and then match it with the maxnoupdate and maxduein // last updated date Date lastUpdated = xFormat.parse(datecreatedList[0]); Date today = new Date(); if (lastUpdated.before(today)) { long diff = today.getTime() - lastUpdated.getTime(); int diffindays = (int) (diff / (24 * 60 * 60 * 1000)); Collections.sort(noupdates); Integer[] foo = noupdates.toArray(new Integer[noupdates.size()]); // now in descending order ArrayUtils.reverse(foo); for (Integer i : foo) { if (diffindays >= i) { warningMsg = "Status is static for more than " + String.valueOf(i) + " days! <br/>"; break; } } } else { warningMsg = "Today cannot be before LastUpdatedDate ??!"; } } // check artifact due in x number if days, but ignore NA if ((!dueins.isEmpty()) && (d.compareTo(BigDecimal.ONE) == -1) && (!"NA".equalsIgnoreCase(headerDueDate))) { Collections.sort(dueins); Date dueDate = xFormat.parse(headerDueDate); Date today = new Date(); if (today.before(dueDate)) { // logger.error("dueDate.getTime() is: " + dueDate.getTime()); // logger.error("today.getTime() is: " + today.getTime()); long diff = dueDate.getTime() - today.getTime(); int diffindays = (int) (diff / (24 * 60 * 60 * 1000)); // logger.error("dueDate.getTime() - today.getTime() is: " + diffindays); Collections.sort(dueins); Integer[] foo = dueins.toArray(new Integer[dueins.size()]); // now in descending order ArrayUtils.reverse(foo); for (Integer i : foo) { if (diffindays <= i) { warningMsg = warningMsg + "Artifact is due in " + (diffindays == 0 ? "less than a day" : String.valueOf(diffindays) + " days"); break; } } } else { // logger.error("header duedate is: " + dueDate); // logger.error("today is: " + today); // logger.error("Today is NOT before due date ??"); warningMsg = warningMsg + "Project overdue"; } } } // end processing thresholds int i = 0; // display in dropdown from greatest to least, so we need to revert the array StringBuilder selectHtml = new StringBuilder(); if (!warningMsg.isEmpty()) { selectHtml.append( "<div class='dropdown'> <button style='background-color: #FF8080' class='btn btn-default dropdown-toggle' type='button' id='dropdownMenu1' data-toggle='dropdown' aria-expanded='true'>"); } else { selectHtml.append( "<div class='dropdown'> <button class='btn btn-default dropdown-toggle' type='button' id='dropdownMenu1' data-toggle='dropdown' aria-expanded='true'>"); } selectHtml.append(yFormat.format(xFormat.parse(datecreatedList[0]))).append(" ") .append(percentageList[0]); selectHtml.append("<span class='caret'></span></button>"); selectHtml.append("<ul class='dropdown-menu' role='menu' aria-labelledby='dropdownMenu1'>"); for (String s : datecreatedList) { String tmplblBRduedate = yFormat.format(xFormat.parse(s)); // logger.error("DueDate is: " + tmplblBRduedate); String percentStr = percentageList[i]; String byuuidstr = uuidList[i]; String newUUID = getATTEmployeeObjectByUUID(byuuidstr).getFullName(); if (i == 0 && !warningMsg.isEmpty()) { if (!left) { // tooltip on the right side selectHtml.append("<li role='presentation'>") .append("<a role='menuitem' tabindex='-1' href='#'>").append(tmplblBRduedate) .append(" " + percentStr + " ") .append("<span class='glyphicon glyphicon-question-sign question' id='mytimestamp' data='") .append(warningMsg).append("'></span>").append("</a>").append("</li>"); } else { // tooltip on left selectHtml.append( "<li role='presentation'><a role='menuitem' tabindex='-1' href='#'><span class='glyphicon glyphicon-question-sign question' id='mytimestamp' data='") .append(warningMsg).append("'></span> ").append(tmplblBRduedate) .append(" " + percentStr + "</a> </li>"); } } else { if (!left) { // tooltip on the right side selectHtml.append("<li role='presentation'>") .append("<a role='menuitem' tabindex='-1' href='#'>").append(tmplblBRduedate) .append(" " + percentStr + " ") .append("<span class='glyphicon glyphicon-question-sign question' id='mytimestamp' data='") .append("Last updated by: " + newUUID).append("'></span>").append("</a>") .append("</li>"); } else { selectHtml.append( "<li role='presentation'><a role='menuitem' tabindex='-1' href='#'><span class='glyphicon glyphicon-question-sign question' id='mytimestamp' data='") .append("Last updated by: " + newUUID).append("'></span> ") .append(tmplblBRduedate).append(" " + percentStr + "</a> </li>"); } } i++; } selectHtml.append("</ul>"); selectHtml.append("</div>"); return selectHtml.toString(); } catch (Exception ex) { logger.error(msgHeader + "Error occurred getRowDueDatePercentageString... " + ex.getMessage()); } return null; }