List of usage examples for org.joda.time LocalDate isAfter
public boolean isAfter(ReadablePartial partial)
From source file:com.gst.portfolio.interestratechart.data.InterestRateChartDataValidator.java
License:Apache License
public void validateForCreate(final String json, final DataValidatorBuilder baseDataValidator) { final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType();/*from ww w .java 2 s. c om*/ this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, INTERESTRATE_CHART_CREATE_REQUEST_DATA_PARAMETERS); final JsonElement element = this.fromApiJsonHelper.parse(json); if (this.fromApiJsonHelper.parameterExists(nameParamName, element)) { final String name = this.fromApiJsonHelper.extractStringNamed(nameParamName, element); baseDataValidator.reset().parameter(nameParamName).value(name).notBlank(); } if (this.fromApiJsonHelper.parameterExists(descriptionParamName, element)) { final String description = this.fromApiJsonHelper.extractStringNamed(descriptionParamName, element); baseDataValidator.reset().parameter(descriptionParamName).value(description).notNull(); } final LocalDate fromDate = this.fromApiJsonHelper.extractLocalDateNamed(fromDateParamName, element); baseDataValidator.reset().parameter(fromDateParamName).value(fromDate).notNull(); LocalDate toDate = null; if (this.fromApiJsonHelper.parameterExists(endDateParamName, element)) { toDate = this.fromApiJsonHelper.extractLocalDateNamed(endDateParamName, element); baseDataValidator.reset().parameter(endDateParamName).value(toDate).notNull(); } Boolean isPrimaryGroupingByAmount = this.fromApiJsonHelper .extractBooleanNamed(isPrimaryGroupingByAmountParamName, element); if (isPrimaryGroupingByAmount == null) { isPrimaryGroupingByAmount = false; } if (fromDate != null && toDate != null) { if (fromDate.isAfter(toDate)) { baseDataValidator.parameter(fromDateParamName).value(fromDate) .failWithCode("from.date.is.after.to.date"); } } // validate chart Slabs validateChartSlabs(element, baseDataValidator, isPrimaryGroupingByAmount); }
From source file:com.gst.portfolio.interestratechart.data.InterestRateChartDataValidator.java
License:Apache License
public void validateForUpdate(final String json, final DataValidatorBuilder baseDataValidator) { final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType();// w ww .j a v a 2s . c o m this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, INTERESTRATE_CHART_UPDATE_REQUEST_DATA_PARAMETERS); final JsonElement element = this.fromApiJsonHelper.parse(json); if (this.fromApiJsonHelper.parameterExists(productIdParamName, element)) { final Long savingsProductId = this.fromApiJsonHelper.extractLongNamed(productIdParamName, element); baseDataValidator.reset().parameter(productIdParamName).value(savingsProductId).notNull() .integerGreaterThanZero(); } if (this.fromApiJsonHelper.parameterExists(nameParamName, element)) { final String name = this.fromApiJsonHelper.extractStringNamed(nameParamName, element); baseDataValidator.reset().parameter(nameParamName).value(name).notBlank(); } if (this.fromApiJsonHelper.parameterExists(descriptionParamName, element)) { final String description = this.fromApiJsonHelper.extractStringNamed(descriptionParamName, element); baseDataValidator.reset().parameter(descriptionParamName).value(description).notNull(); } LocalDate fromDate = null; if (this.fromApiJsonHelper.parameterExists(fromDateParamName, element)) { fromDate = this.fromApiJsonHelper.extractLocalDateNamed(fromDateParamName, element); baseDataValidator.reset().parameter(fromDateParamName).value(fromDate).notNull(); } LocalDate toDate = null; if (this.fromApiJsonHelper.parameterExists(endDateParamName, element)) { toDate = this.fromApiJsonHelper.extractLocalDateNamed(endDateParamName, element); baseDataValidator.reset().parameter(endDateParamName).value(toDate).notNull(); } Boolean isPrimaryGroupingByAmount = this.fromApiJsonHelper .extractBooleanNamed(isPrimaryGroupingByAmountParamName, element); if (isPrimaryGroupingByAmount == null) { isPrimaryGroupingByAmount = false; } if (fromDate != null && toDate != null) { if (fromDate.isAfter(toDate)) { baseDataValidator.parameter(fromDateParamName).value(fromDate) .failWithCode("from.date.is.after.to.date"); } } validateChartSlabs(element, baseDataValidator, isPrimaryGroupingByAmount); }
From source file:com.gst.portfolio.interestratechart.domain.InterestRateChartFields.java
License:Apache License
public boolean isFromDateAfter(LocalDate compare) { final LocalDate fromDate = getFromDateAsLocalDate(); if (fromDate != null && compare != null) { return fromDate.isAfter(compare); }/*w w w .ja v a 2 s .c om*/ return false; }
From source file:com.gst.portfolio.loanaccount.data.DisbursementData.java
License:Apache License
private boolean occursOnDayFromAndUpToAndIncluding(final LocalDate fromNotInclusive, final LocalDate upToAndInclusive, final LocalDate target) { return target != null && target.isAfter(fromNotInclusive) && !target.isAfter(upToAndInclusive); }
From source file:com.gst.portfolio.loanaccount.data.LoanTermVariationsData.java
License:Apache License
private boolean occursOnDayFromAndUpTo(final LocalDate fromNotInclusive, final LocalDate upToInclusive, final LocalDate target) { return target != null && target.isAfter(fromNotInclusive) && !target.isAfter(upToInclusive); }
From source file:com.gst.portfolio.loanaccount.data.LoanTermVariationsData.java
License:Apache License
private boolean occursBefore(final LocalDate date, final LocalDate target) { return target != null && !target.isAfter(date); }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
private BigDecimal calculateOverdueAmountPercentageAppliedTo(final LoanCharge loanCharge, final int penaltyWaitPeriod) { LoanRepaymentScheduleInstallment installment = loanCharge.getOverdueInstallmentCharge().getInstallment(); LocalDate graceDate = DateUtils.getLocalDateOfTenant().minusDays(penaltyWaitPeriod); Money amount = Money.zero(getCurrency()); if (graceDate.isAfter(installment.getDueDate())) { amount = calculateOverdueAmountPercentageAppliedTo(installment, loanCharge.getChargeCalculation()); if (!amount.isGreaterThanZero()) { loanCharge.setActive(false); }/*from w ww.ja v a 2s.c om*/ } else { loanCharge.setActive(false); } return amount.getAmount(); }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
public void loanApplicationSubmittal(final AppUser currentUser, final LoanScheduleModel loanSchedule, final LoanApplicationTerms loanApplicationTerms, final LoanLifecycleStateMachine lifecycleStateMachine, final LocalDate submittedOn, final String externalId, final boolean allowTransactionsOnHoliday, final List<Holiday> holidays, final WorkingDays workingDays, final boolean allowTransactionsOnNonWorkingDay) { updateLoanSchedule(loanSchedule, currentUser); LoanStatus from = null;/*from ww w .j a v a2s.c o m*/ if (this.loanStatus != null) { from = LoanStatus.fromInt(this.loanStatus); } final LoanStatus statusEnum = lifecycleStateMachine.transition(LoanEvent.LOAN_CREATED, from); this.loanStatus = statusEnum.getValue(); this.externalId = externalId; this.termFrequency = loanApplicationTerms.getLoanTermFrequency(); this.termPeriodFrequencyType = loanApplicationTerms.getLoanTermPeriodFrequencyType().getValue(); this.submittedOnDate = submittedOn.toDate(); this.submittedBy = currentUser; this.expectedDisbursementDate = loanApplicationTerms.getExpectedDisbursementDate().toDate(); this.expectedFirstRepaymentOnDate = loanApplicationTerms.getRepaymentStartFromDate(); this.interestChargedFromDate = loanApplicationTerms.getInterestChargedFromDate(); updateLoanScheduleDependentDerivedFields(); if (submittedOn.isAfter(DateUtils.getLocalDateOfTenant())) { final String errorMessage = "The date on which a loan is submitted cannot be in the future."; throw new InvalidLoanStateTransitionException("submittal", "cannot.be.a.future.date", errorMessage, submittedOn); } if (this.client != null && this.client.isActivatedAfter(submittedOn)) { final String errorMessage = "The date on which a loan is submitted cannot be earlier than client's activation date."; throw new InvalidLoanStateTransitionException("submittal", "cannot.be.before.client.activation.date", errorMessage, submittedOn); } validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_CREATED, submittedOn); if (this.group != null && this.group.isActivatedAfter(submittedOn)) { final String errorMessage = "The date on which a loan is submitted cannot be earlier than groups's activation date."; throw new InvalidLoanStateTransitionException("submittal", "cannot.be.before.group.activation.date", errorMessage, submittedOn); } if (submittedOn.isAfter(getExpectedDisbursedOnLocalDate())) { final String errorMessage = "The date on which a loan is submitted cannot be after its expected disbursement date: " + getExpectedDisbursedOnLocalDate().toString(); throw new InvalidLoanStateTransitionException("submittal", "cannot.be.after.expected.disbursement.date", errorMessage, submittedOn, getExpectedDisbursedOnLocalDate()); } // charges are optional int penaltyWaitPeriod = 0; for (final LoanCharge loanCharge : charges()) { recalculateLoanCharge(loanCharge, penaltyWaitPeriod); } updateSummaryWithTotalFeeChargesDueAtDisbursement(deriveSumTotalOfChargesDueAtDisbursement()); // validate if disbursement date is a holiday or a non-working day validateDisbursementDateIsOnNonWorkingDay(workingDays, allowTransactionsOnNonWorkingDay); validateDisbursementDateIsOnHoliday(allowTransactionsOnHoliday, holidays); /** * Copy interest recalculation settings if interest recalculation is * enabled */ if (this.loanRepaymentScheduleDetail.isInterestRecalculationEnabled()) { this.loanInterestRecalculationDetails = LoanInterestRecalculationDetails .createFrom(this.loanProduct.getProductInterestRecalculationDetails()); this.loanInterestRecalculationDetails.updateLoan(this); } }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
public Map<String, Object> loanApplicationRejection(final AppUser currentUser, final JsonCommand command, final LoanLifecycleStateMachine loanLifecycleStateMachine) { validateAccountStatus(LoanEvent.LOAN_REJECTED); final Map<String, Object> actualChanges = new LinkedHashMap<>(); final LoanStatus statusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_REJECTED, LoanStatus.fromInt(this.loanStatus)); if (!statusEnum.hasStateOf(LoanStatus.fromInt(this.loanStatus))) { this.loanStatus = statusEnum.getValue(); actualChanges.put("status", LoanEnumerations.status(this.loanStatus)); final LocalDate rejectedOn = command.localDateValueOfParameterNamed("rejectedOnDate"); final Locale locale = new Locale(command.locale()); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); this.rejectedOnDate = rejectedOn.toDate(); this.rejectedBy = currentUser; this.closedOnDate = rejectedOn.toDate(); this.closedBy = currentUser; actualChanges.put("locale", command.locale()); actualChanges.put("dateFormat", command.dateFormat()); actualChanges.put("rejectedOnDate", rejectedOn.toString(fmt)); actualChanges.put("closedOnDate", rejectedOn.toString(fmt)); if (rejectedOn.isBefore(getSubmittedOnDate())) { final String errorMessage = "The date on which a loan is rejected cannot be before its submittal date: " + getSubmittedOnDate().toString(); throw new InvalidLoanStateTransitionException("reject", "cannot.be.before.submittal.date", errorMessage, rejectedOn, getSubmittedOnDate()); }/*w w w .j a va 2s.c om*/ validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_REJECTED, rejectedOn); if (rejectedOn.isAfter(DateUtils.getLocalDateOfTenant())) { final String errorMessage = "The date on which a loan is rejected cannot be in the future."; throw new InvalidLoanStateTransitionException("reject", "cannot.be.a.future.date", errorMessage, rejectedOn); } } else { final String errorMessage = "Only the loan applications with status 'Submitted and pending approval' are allowed to be rejected."; throw new InvalidLoanStateTransitionException("reject", "cannot.reject", errorMessage); } return actualChanges; }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
public Map<String, Object> loanApplicationWithdrawnByApplicant(final AppUser currentUser, final JsonCommand command, final LoanLifecycleStateMachine loanLifecycleStateMachine) { final Map<String, Object> actualChanges = new LinkedHashMap<>(); final LoanStatus statusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_WITHDRAWN, LoanStatus.fromInt(this.loanStatus)); if (!statusEnum.hasStateOf(LoanStatus.fromInt(this.loanStatus))) { this.loanStatus = statusEnum.getValue(); actualChanges.put("status", LoanEnumerations.status(this.loanStatus)); LocalDate withdrawnOn = command.localDateValueOfParameterNamed("withdrawnOnDate"); if (withdrawnOn == null) { withdrawnOn = command.localDateValueOfParameterNamed("eventDate"); }/* w ww . j a v a2s .c om*/ final Locale locale = new Locale(command.locale()); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); this.withdrawnOnDate = withdrawnOn.toDate(); this.withdrawnBy = currentUser; this.closedOnDate = withdrawnOn.toDate(); this.closedBy = currentUser; actualChanges.put("locale", command.locale()); actualChanges.put("dateFormat", command.dateFormat()); actualChanges.put("withdrawnOnDate", withdrawnOn.toString(fmt)); actualChanges.put("closedOnDate", withdrawnOn.toString(fmt)); if (withdrawnOn.isBefore(getSubmittedOnDate())) { final String errorMessage = "The date on which a loan is withdrawn cannot be before its submittal date: " + getSubmittedOnDate().toString(); throw new InvalidLoanStateTransitionException("withdraw", "cannot.be.before.submittal.date", errorMessage, command, getSubmittedOnDate()); } validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_WITHDRAWN, withdrawnOn); if (withdrawnOn.isAfter(DateUtils.getLocalDateOfTenant())) { final String errorMessage = "The date on which a loan is withdrawn cannot be in the future."; throw new InvalidLoanStateTransitionException("withdraw", "cannot.be.a.future.date", errorMessage, command); } } else { final String errorMessage = "Only the loan applications with status 'Submitted and pending approval' are allowed to be withdrawn by applicant."; throw new InvalidLoanStateTransitionException("withdraw", "cannot.withdraw", errorMessage); } return actualChanges; }