Example usage for org.joda.time LocalDate toDate

List of usage examples for org.joda.time LocalDate toDate

Introduction

In this page you can find the example usage for org.joda.time LocalDate toDate.

Prototype

@SuppressWarnings("deprecation")
public Date toDate() 

Source Link

Document

Get the date time as a java.util.Date.

Usage

From source file:com.gst.portfolio.group.domain.StaffAssignmentHistory.java

License:Apache License

public static StaffAssignmentHistory createNew(final Group center, final Staff staff,
        final LocalDate startDate) {
    return new StaffAssignmentHistory(center, staff, startDate.toDate(), null);
}

From source file:com.gst.portfolio.group.domain.StaffAssignmentHistory.java

License:Apache License

public void updateStartDate(final LocalDate startDate) {
    this.startDate = startDate.toDate();
}

From source file:com.gst.portfolio.group.domain.StaffAssignmentHistory.java

License:Apache License

public void updateEndDate(final LocalDate endDate) {
    this.endDate = endDate.toDate();
}

From source file:com.gst.portfolio.group.service.GroupingTypesWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

private void validateLoansAndSavingsForGroupOrCenterClose(final Group groupOrCenter,
        final LocalDate closureDate) {
    final Collection<Loan> groupLoans = this.loanRepositoryWrapper.findByGroupId(groupOrCenter.getId());
    for (final Loan loan : groupLoans) {
        final LoanStatusMapper loanStatus = new LoanStatusMapper(loan.status().getValue());
        if (loanStatus.isOpen()) {
            final String errorMessage = groupOrCenter.getGroupLevel().getLevelName()
                    + " cannot be closed because of non-closed loans.";
            throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(),
                    "close", "loan.not.closed", errorMessage);
        } else if (loanStatus.isClosed() && loan.getClosedOnDate().after(closureDate.toDate())) {
            final String errorMessage = groupOrCenter.getGroupLevel().getLevelName()
                    + "closureDate cannot be before the loan closedOnDate.";
            throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(),
                    "close", "date.cannot.before.loan.closed.date", errorMessage, closureDate,
                    loan.getClosedOnDate());
        } else if (loanStatus.isPendingApproval()) {
            final String errorMessage = groupOrCenter.getGroupLevel().getLevelName()
                    + " cannot be closed because of non-closed loans.";
            throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(),
                    "close", "loan.not.closed", errorMessage);
        } else if (loanStatus.isAwaitingDisbursal()) {
            final String errorMessage = "Group cannot be closed because of non-closed loans.";
            throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(),
                    "close", "loan.not.closed", errorMessage);
        }/*  www .  j  av  a 2 s .co  m*/
    }

    final List<SavingsAccount> groupSavingAccounts = this.savingsAccountRepositoryWrapper
            .findByGroupId(groupOrCenter.getId());

    for (final SavingsAccount saving : groupSavingAccounts) {
        if (saving.isActive() || saving.isSubmittedAndPendingApproval() || saving.isApproved()) {
            final String errorMessage = groupOrCenter.getGroupLevel().getLevelName()
                    + " cannot be closed with active savings accounts associated.";
            throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(),
                    "close", "savings.account.not.closed", errorMessage);
        } else if (saving.isClosed() && saving.getClosedOnDate().isAfter(closureDate)) {
            final String errorMessage = groupOrCenter.getGroupLevel().getLevelName()
                    + " closureDate cannot be before the loan closedOnDate.";
            throw new InvalidGroupStateTransitionException(groupOrCenter.getGroupLevel().getLevelName(),
                    "close", "date.cannot.before.loan.closed.date", errorMessage, closureDate,
                    saving.getClosedOnDate());
        }
    }
}

From source file:com.gst.portfolio.interestratechart.domain.InterestRateChartFields.java

License:Apache License

private InterestRateChartFields(String name, String description, LocalDate fromDate, LocalDate toDate,
        boolean isPrimaryGroupingByAmount) {
    this.name = name;
    this.description = description;
    this.fromDate = fromDate.toDate();
    this.endDate = (toDate == null) ? null : toDate.toDate();
    this.isPrimaryGroupingByAmount = isPrimaryGroupingByAmount;
}

From source file:com.gst.portfolio.loanaccount.domain.Loan.java

License:Apache License

private Map<String, Object> parseDisbursementDetails(final JsonObject jsonObject, String dateFormat,
        Locale locale) {/*from www.j  av  a  2s . co m*/
    Map<String, Object> returnObject = new HashMap<>();
    if (jsonObject.get(LoanApiConstants.disbursementDateParameterName) != null
            && jsonObject.get(LoanApiConstants.disbursementDateParameterName).isJsonPrimitive()) {
        final JsonPrimitive primitive = jsonObject.get(LoanApiConstants.disbursementDateParameterName)
                .getAsJsonPrimitive();
        final String valueAsString = primitive.getAsString();
        if (StringUtils.isNotBlank(valueAsString)) {
            LocalDate date = JsonParserHelper.convertFrom(valueAsString,
                    LoanApiConstants.disbursementDateParameterName, dateFormat, locale);
            if (date != null) {
                returnObject.put(LoanApiConstants.disbursementDateParameterName, date.toDate());
            }
        }
    }

    if (jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).isJsonPrimitive() && StringUtils
            .isNotBlank((jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).getAsString()))) {
        BigDecimal principal = jsonObject
                .getAsJsonPrimitive(LoanApiConstants.disbursementPrincipalParameterName).getAsBigDecimal();
        returnObject.put(LoanApiConstants.disbursementPrincipalParameterName, principal);
    }

    if (jsonObject.has(LoanApiConstants.disbursementIdParameterName)
            && jsonObject.get(LoanApiConstants.disbursementIdParameterName).isJsonPrimitive() && StringUtils
                    .isNotBlank((jsonObject.get(LoanApiConstants.disbursementIdParameterName).getAsString()))) {
        Long id = jsonObject.getAsJsonPrimitive(LoanApiConstants.disbursementIdParameterName).getAsLong();
        returnObject.put(LoanApiConstants.disbursementIdParameterName, id);
    }

    if (jsonObject.has(LoanApiConstants.loanChargeIdParameterName)
            && jsonObject.get(LoanApiConstants.loanChargeIdParameterName).isJsonPrimitive() && StringUtils
                    .isNotBlank((jsonObject.get(LoanApiConstants.loanChargeIdParameterName).getAsString()))) {
        returnObject.put(LoanApiConstants.loanChargeIdParameterName,
                jsonObject.getAsJsonPrimitive(LoanApiConstants.loanChargeIdParameterName).getAsString());
    }
    return returnObject;
}

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;//w  w  w.  ja va2  s.  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  v a2 s. c  o m*/

        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");
        }/*from   w w  w .ja  v a 2s  .  co m*/

        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;
}

From source file:com.gst.portfolio.loanaccount.domain.Loan.java

License:Apache License

public Map<String, Object> loanApplicationApproval(final AppUser currentUser, final JsonCommand command,
        final JsonArray disbursementDataArray, final LoanLifecycleStateMachine loanLifecycleStateMachine) {

    validateAccountStatus(LoanEvent.LOAN_APPROVED);

    final Map<String, Object> actualChanges = new LinkedHashMap<>();

    /*//w w w.  j  ava  2s  .c o m
     * statusEnum is holding the possible new status derived from
     * loanLifecycleStateMachine.transition.
     */

    final LoanStatus newStatusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_APPROVED,
            LoanStatus.fromInt(this.loanStatus));

    /*
     * FIXME: There is no need to check below condition, if
     * loanLifecycleStateMachine.transition is doing it's responsibility
     * properly. Better implementation approach is, if code passes invalid
     * combination of states (fromState and toState), state machine should
     * return invalidate state and below if condition should check for not
     * equal to invalidateState, instead of check new value is same as
     * present value.
     */

    if (!newStatusEnum.hasStateOf(LoanStatus.fromInt(this.loanStatus))) {
        this.loanStatus = newStatusEnum.getValue();
        actualChanges.put("status", LoanEnumerations.status(this.loanStatus));

        // only do below if status has changed in the 'approval' case
        LocalDate approvedOn = command.localDateValueOfParameterNamed("approvedOnDate");
        String approvedOnDateChange = command.stringValueOfParameterNamed("approvedOnDate");
        if (approvedOn == null) {
            approvedOn = command.localDateValueOfParameterNamed("eventDate");
            approvedOnDateChange = command.stringValueOfParameterNamed("eventDate");
        }

        LocalDate expecteddisbursementDate = command.localDateValueOfParameterNamed("expectedDisbursementDate");

        BigDecimal approvedLoanAmount = command
                .bigDecimalValueOfParameterNamed(LoanApiConstants.approvedLoanAmountParameterName);

        if (approvedLoanAmount != null) {

            // Approved amount has to be less than or equal to principal
            // amount demanded

            if (approvedLoanAmount.compareTo(this.proposedPrincipal) == -1) {

                this.approvedPrincipal = approvedLoanAmount;

                /*
                 * All the calculations are done based on the principal
                 * amount, so it is necessary to set principal amount to
                 * approved amount
                 */

                this.loanRepaymentScheduleDetail.setPrincipal(approvedLoanAmount);

                actualChanges.put(LoanApiConstants.approvedLoanAmountParameterName, approvedLoanAmount);
                actualChanges.put(LoanApiConstants.disbursementPrincipalParameterName, approvedLoanAmount);
            } else if (approvedLoanAmount.compareTo(this.proposedPrincipal) == 1) {
                final String errorMessage = "Loan approved amount can't be greater than loan amount demanded.";
                throw new InvalidLoanStateTransitionException("approval",
                        "amount.can't.be.greater.than.loan.amount.demanded", errorMessage,
                        this.proposedPrincipal, approvedLoanAmount);
            }

            /* Update disbursement details */
            if (disbursementDataArray != null) {
                updateDisbursementDetails(command, actualChanges);
            }
        }
        if (loanProduct.isMultiDisburseLoan()) {
            recalculateAllCharges();

            if (this.disbursementDetails.isEmpty()) {
                final String errorMessage = "For this loan product, disbursement details must be provided";
                throw new MultiDisbursementDataRequiredException(LoanApiConstants.disbursementDataParameterName,
                        errorMessage);
            }

            if (this.disbursementDetails.size() > loanProduct.maxTrancheCount()) {
                final String errorMessage = "Number of tranche shouldn't be greter than "
                        + loanProduct.maxTrancheCount();
                throw new ExceedingTrancheCountException(LoanApiConstants.disbursementDataParameterName,
                        errorMessage, loanProduct.maxTrancheCount(), disbursementDetails.size());
            }
        }
        this.approvedOnDate = approvedOn.toDate();
        this.approvedBy = currentUser;
        actualChanges.put("locale", command.locale());
        actualChanges.put("dateFormat", command.dateFormat());
        actualChanges.put("approvedOnDate", approvedOnDateChange);

        final LocalDate submittalDate = new LocalDate(this.submittedOnDate);
        if (approvedOn.isBefore(submittalDate)) {
            final String errorMessage = "The date on which a loan is approved cannot be before its submittal date: "
                    + submittalDate.toString();
            throw new InvalidLoanStateTransitionException("approval", "cannot.be.before.submittal.date",
                    errorMessage, getApprovedOnDate(), submittalDate);
        }

        if (expecteddisbursementDate != null) {
            this.expectedDisbursementDate = expecteddisbursementDate.toDate();
            actualChanges.put("expectedDisbursementDate", expectedDisbursementDate);

            if (expecteddisbursementDate.isBefore(approvedOn)) {
                final String errorMessage = "The expected disbursement date should be either on or after the approval date: "
                        + approvedOn.toString();
                throw new InvalidLoanStateTransitionException("expecteddisbursal",
                        "should.be.on.or.after.approval.date", errorMessage, getApprovedOnDate(),
                        expecteddisbursementDate);
            }
        }

        validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_APPROVED, approvedOn);

        if (approvedOn.isAfter(DateUtils.getLocalDateOfTenant())) {
            final String errorMessage = "The date on which a loan is approved cannot be in the future.";
            throw new InvalidLoanStateTransitionException("approval", "cannot.be.a.future.date", errorMessage,
                    getApprovedOnDate());
        }

        if (this.loanOfficer != null) {
            final LoanOfficerAssignmentHistory loanOfficerAssignmentHistory = LoanOfficerAssignmentHistory
                    .createNew(this, this.loanOfficer, approvedOn);
            this.loanOfficerHistory.add(loanOfficerAssignmentHistory);
        }
    }

    return actualChanges;
}