List of usage examples for java.math BigDecimal ZERO
BigDecimal ZERO
To view the source code for java.math BigDecimal ZERO.
Click Source Link
From source file:com.gst.portfolio.loanproduct.serialization.LoanProductDataValidator.java
public void validateForCreate(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }//from w w w . ja va2s .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); 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:org.kuali.coeus.s2sgen.impl.generate.support.SF424V1_0Generator.java
/** * /* w w w. j av a2 s . c o m*/ * This method get budget informations.Budget informations includes * FederalEstimatedAmount,LocalEstimatedAmount * ProgramIncomeEstimatedAmount,OtherEstimatedAmount and * TotalEstimatedAmount * * @return Budget total estimated budget details. */ private Budget getBudget() throws S2SException { Budget budget = Budget.Factory.newInstance(); CurrencyCodeType.Enum currencyEnum = CurrencyCodeType.USD; budget.setCurrencyCode(currencyEnum); budget.setFederalEstimatedAmount(BigDecimal.ZERO); budget.setTotalEstimatedAmount(BigDecimal.ZERO); ProposalDevelopmentBudgetExtContract pBudget = s2SCommonBudgetService .getBudget(pdDoc.getDevelopmentProposal()); if (pBudget != null) { budget.setFederalEstimatedAmount(pBudget.getTotalCost().bigDecimalValue()); budget.setApplicantEstimatedAmount(pBudget.getCostSharingAmount().bigDecimalValue()); // Following values hardcoded as in coeus budget.setStateEstimatedAmount(BigDecimal.ZERO); budget.setLocalEstimatedAmount(BigDecimal.ZERO); budget.setOtherEstimatedAmount(BigDecimal.ZERO); BigDecimal projectIncome = BigDecimal.ZERO; for (BudgetProjectIncomeContract budgetProjectIncome : pBudget.getBudgetProjectIncomes()) { if (budgetProjectIncome.getProjectIncome() != null) { projectIncome = projectIncome.add(budgetProjectIncome.getProjectIncome().bigDecimalValue()); } } budget.setProgramIncomeEstimatedAmount(projectIncome); ScaleTwoDecimal totalEstimatedAmount = ScaleTwoDecimal.ZERO; if (pBudget.getTotalCost() != null) { totalEstimatedAmount = totalEstimatedAmount.add(pBudget.getTotalCost()); } if (pBudget.getCostSharingAmount() != null) { totalEstimatedAmount = totalEstimatedAmount.add(pBudget.getCostSharingAmount()); } budget.setTotalEstimatedAmount(totalEstimatedAmount.bigDecimalValue().add(projectIncome)); } return budget; }
From source file:com.gst.infrastructure.core.api.JsonCommand.java
private static BigDecimal defaultToNullIfZero(final BigDecimal value) { BigDecimal result = value;/*from w w w . java2 s. c o m*/ if (value != null && BigDecimal.ZERO.compareTo(value) == 0) { result = null; } return result; }
From source file:com.etcc.csc.presentation.datatype.PaymentContext.java
public BigDecimal getFirstInvTotalUnPaidAmount() { BigDecimal amount = BigDecimal.ZERO; if (!ArrayUtils.isEmpty(firstInvs)) { for (int i = 0; i < firstInvs.length; i++) { if ("N".equals(firstInvs[i].getPaidIndicator())) { amount = amount.add(firstInvs[i].getAmount()); }/*from w w w . j a va 2 s. com*/ } } return amount; }
From source file:alfio.manager.EventManager.java
public void updateEventPrices(Event original, EventModification em, String username) { checkOwnership(original, username, em.getOrganizationId()); int eventId = original.getId(); int seatsDifference = em.getAvailableSeats() - eventRepository.countExistingTickets(original.getId()); if (seatsDifference < 0) { int allocatedSeats = ticketCategoryRepository.findByEventId(original.getId()).stream() .filter(TicketCategory::isBounded).mapToInt(TicketCategory::getMaxTickets).sum(); if (em.getAvailableSeats() < allocatedSeats) { throw new IllegalArgumentException(format( "cannot reduce max tickets to %d. There are already %d tickets allocated. Try updating categories first.", em.getAvailableSeats(), allocatedSeats)); }//from w w w. j av a 2s. co m } String paymentProxies = collectPaymentProxies(em); BigDecimal vat = em.isFreeOfCharge() ? BigDecimal.ZERO : em.getVatPercentage(); eventRepository.updatePrices(em.getCurrency(), em.getAvailableSeats(), em.isVatIncluded(), vat, paymentProxies, eventId, em.getVatStatus(), em.getPriceInCents()); if (seatsDifference != 0) { Event modified = eventRepository.findById(eventId); if (seatsDifference > 0) { final MapSqlParameterSource[] params = generateEmptyTickets(modified, Date.from(ZonedDateTime.now(modified.getZoneId()).toInstant()), seatsDifference, TicketStatus.RELEASED).toArray(MapSqlParameterSource[]::new); jdbc.batchUpdate(ticketRepository.bulkTicketInitialization(), params); } else { List<Integer> ids = ticketRepository.selectNotAllocatedTicketsForUpdate(eventId, Math.abs(seatsDifference), singletonList(TicketStatus.FREE.name())); Validate.isTrue(ids.size() == Math.abs(seatsDifference), "cannot lock enough tickets for deletion."); int invalidatedTickets = ticketRepository.invalidateTickets(ids); Validate.isTrue(ids.size() == invalidatedTickets, String.format( "error during ticket invalidation: expected %d, got %d", ids.size(), invalidatedTickets)); } } }
From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
public Money pay(final MonetaryCurrency currency, final Money amountPaid) { Money amountPaidToDate = Money.of(currency, this.amountPaid); Money amountOutstanding = Money.of(currency, this.amountOutstanding); amountPaidToDate = amountPaidToDate.plus(amountPaid); amountOutstanding = amountOutstanding.minus(amountPaid); this.amountPaid = amountPaidToDate.getAmount(); this.amountOutstanding = amountOutstanding.getAmount(); this.paid = determineIfFullyPaid(); if (BigDecimal.ZERO.compareTo(this.amountOutstanding) == 0) { // full outstanding is paid, update to next due date updateNextDueDateForRecurringFees(); resetPropertiesForRecurringFees(); }/*from w w w . ja va 2 s . c o m*/ return Money.of(currency, this.amountOutstanding); }
From source file:org.jrecruiter.service.JobServiceUnitTest.java
private Job getJob(Long jobId) { Job job = new Job(jobId); job.setBusinessAddress1("businessAddress1"); job.setBusinessAddress2("businessAddress2"); job.setBusinessCity("businessCity"); job.setBusinessEmail("businessEmail"); job.setRegionOther("businessLocation"); job.setBusinessName("businessName"); job.setBusinessPhone("businessPhone"); job.setBusinessState("businessState"); job.setBusinessZip("businessZip"); job.setDescription("description"); job.setJobRestrictions("jobRestrictions"); job.setJobTitle("jobTitle"); job.setLatitude(BigDecimal.ONE); job.setLongitude(BigDecimal.ZERO); job.setOfferedBy(OfferedBy.RECRUITER); job.setRegistrationDate(new Date()); job.setSalary("10000"); job.setStatus(JobStatus.ACTIVE); job.setUpdateDate(new Date()); job.setWebsite("www.google.com"); return job;// w ww . java 2 s. co m }
From source file:com.axelor.apps.account.service.MoveLineExportService.java
/** * Mthode ralisant l'export SI - Agresso des en-ttes pour les journaux de type vente * @param mlr//from w ww . java2 s . com * @param replay * @throws AxelorException * @throws IOException */ @SuppressWarnings("unchecked") @Transactional(rollbackOn = { AxelorException.class, Exception.class }) public void exportMoveLineTypeSelect1006FILE1(MoveLineReport moveLineReport, boolean replay) throws AxelorException, IOException { log.info("In export service Type 1006 FILE 1 :"); Company company = moveLineReport.getCompany(); String dateQueryStr = String.format(" WHERE self.company = %s", company.getId()); JournalType journalType = moveLineReportService.getJournalType(moveLineReport); if (moveLineReport.getJournal() != null) { dateQueryStr += String.format(" AND self.journal = %s", moveLineReport.getJournal().getId()); } else { dateQueryStr += String.format(" AND self.journal.type = %s", journalType.getId()); } if (moveLineReport.getPeriod() != null) { dateQueryStr += String.format(" AND self.period = %s", moveLineReport.getPeriod().getId()); } if (replay) { dateQueryStr += String.format(" AND self.accountingOk = true AND self.moveLineReport = %s", moveLineReport.getId()); } else { dateQueryStr += " AND self.accountingOk = false "; } dateQueryStr += " AND self.ignoreInAccountingOk = false AND self.journal.notExportOk = false "; dateQueryStr += String.format(" AND self.statusSelect = %s ", MoveRepository.STATUS_VALIDATED); Query dateQuery = JPA.em().createQuery( "SELECT self.date from Move self" + dateQueryStr + "group by self.date order by self.date"); List<LocalDate> allDates = new ArrayList<LocalDate>(); allDates = dateQuery.getResultList(); log.debug("allDates : {}", allDates); List<String[]> allMoveData = new ArrayList<String[]>(); String companyCode = ""; String reference = ""; String moveQueryStr = ""; String moveLineQueryStr = ""; if (moveLineReport.getRef() != null) { reference = moveLineReport.getRef(); } if (company != null) { companyCode = company.getCode(); moveQueryStr += String.format(" AND self.company = %s", company.getId()); } if (moveLineReport.getPeriod() != null) { moveQueryStr += String.format(" AND self.period = %s", moveLineReport.getPeriod().getId()); } if (moveLineReport.getDateFrom() != null) { moveLineQueryStr += String.format(" AND self.date >= '%s'", moveLineReport.getDateFrom().toString()); } if (moveLineReport.getDateTo() != null) { moveLineQueryStr += String.format(" AND self.date <= '%s'", moveLineReport.getDateTo().toString()); } if (moveLineReport.getDate() != null) { moveLineQueryStr += String.format(" AND self.date <= '%s'", moveLineReport.getDate().toString()); } if (replay) { moveQueryStr += String.format(" AND self.accountingOk = true AND self.moveLineReport = %s", moveLineReport.getId()); } else { moveQueryStr += " AND self.accountingOk = false "; } moveQueryStr += String.format(" AND self.statusSelect = %s ", MoveRepository.STATUS_VALIDATED); LocalDate interfaceDate = moveLineReport.getDate(); for (LocalDate dt : allDates) { List<Journal> journalList = journalRepo.all() .filter("self.type = ?1 AND self.notExportOk = false", journalType).fetch(); if (moveLineReport.getJournal() != null) { journalList = new ArrayList<Journal>(); journalList.add(moveLineReport.getJournal()); } for (Journal journal : journalList) { List<? extends Move> moveList = moveRepo.all().filter( "self.date = ?1 AND self.ignoreInAccountingOk = false AND self.journal.notExportOk = false AND self.journal = ?2" + moveQueryStr, dt, journal).fetch(); String journalCode = journal.getExportCode(); if (moveList.size() > 0) { BigDecimal sumDebit = this.getSumDebit( "self.account.reconcileOk = true AND self.debit != 0.00 AND self.move in ?1 " + moveLineQueryStr, moveList); if (sumDebit.compareTo(BigDecimal.ZERO) == 1) { String exportNumber = this.getSaleExportNumber(company); Move firstMove = moveList.get(0); String periodCode = firstMove.getPeriod().getFromDate().format(MONTH_FORMAT); this.updateMoveList((List<Move>) moveList, moveLineReport, interfaceDate, exportNumber); String items[] = new String[8]; items[0] = companyCode; items[1] = journalCode; items[2] = exportNumber; items[3] = interfaceDate.format(DATE_FORMAT); items[4] = sumDebit.toString(); items[5] = reference; items[6] = dt.format(DATE_FORMAT); items[7] = periodCode; allMoveData.add(items); } } } } String fileName = "entete" + todayTime.format(DATE_TIME_FORMAT) + "ventes.dat"; String filePath = accountConfigService.getExportPath(accountConfigService.getAccountConfig(company)); new File(filePath).mkdirs(); log.debug("Full path to export : {}{}", filePath, fileName); CsvTool.csvWriter(filePath, fileName, '|', null, allMoveData); // Utilis pour le debuggage // CsvTool.csvWriter(filePath, fileName, '|', this.createHeaderForHeaderFile(mlr.getTypeSelect()), allMoveData); }
From source file:de.inren.service.banking.BankDataServiceImpl.java
@Override public BalanceSummary loadBalanceSummary(Date from, Date until) { BalanceSummary balanceSummary = new BalanceSummary(); balanceSummary.setFrom(from);/*from w w w .java 2 s. com*/ balanceSummary.setUntil(until); Iterable<Account> accounts = accountRepository.findAll(); for (Account account : accounts) { balanceSummary.getAccounts().add(account); List<Transaction> transactions = transactionRepository .findAll(new TransactionDateSpecification(from, until, account.getNumber()), SORT_VALUTA_ASC); if (!transactions.isEmpty()) { balanceSummary.getFromBalance().put(account.getNumber(), transactions.get(0).getBalance()); balanceSummary.getUntilBalance().put(account.getNumber(), transactions.get(transactions.size() - 1).getBalance()); } else { balanceSummary.getFromBalance().put(account.getNumber(), BigDecimal.ZERO); balanceSummary.getUntilBalance().put(account.getNumber(), BigDecimal.ZERO); } } return balanceSummary; }
From source file:jgnash.ui.report.compiled.PayeePieChart.java
private PieDataset[] createPieDataSet(final Account a) { DefaultPieDataset[] returnValue = new DefaultPieDataset[2]; returnValue[0] = new DefaultPieDataset(); returnValue[1] = new DefaultPieDataset(); if (a != null) { //System.out.print("Account = "); System.out.println(a); Map<String, BigDecimal> names = new HashMap<>(); List<TranTuple> list = getTransactions(a, new ArrayList<>(), startField.getLocalDate(), endField.getLocalDate()); CurrencyNode currency = a.getCurrencyNode(); for (final TranTuple tranTuple : list) { Transaction tran = tranTuple.transaction; Account account = tranTuple.account; String payee = tran.getPayee(); BigDecimal sum = tran.getAmount(account); sum = sum.multiply(account.getCurrencyNode().getExchangeRate(currency)); //System.out.print(" Transaction = "); System.out.print(payee); System.out.print(" "); System.out.println(sum); if (useFilters.isSelected()) { for (String aFilterList : filterList) { PayeeMatcher pm = new PayeeMatcher(aFilterList, false); if (pm.matches(tran)) { payee = aFilterList; //System.out.println(filterList.get(i)); break; }/*www .j a v a2 s. com*/ } } if (names.containsKey(payee)) { sum = sum.add(names.get(payee)); } names.put(payee, sum); } for (final Map.Entry<String, BigDecimal> entry : names.entrySet()) { BigDecimal value = entry.getValue(); if (value.compareTo(BigDecimal.ZERO) == -1) { value = value.negate(); returnValue[1].setValue(entry.getKey(), value); } else { returnValue[0].setValue(entry.getKey(), value); } } } return returnValue; }