Example usage for org.joda.time LocalDate toString

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

Introduction

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

Prototype

public String toString(String pattern) 

Source Link

Document

Output the date using the specified format pattern.

Usage

From source file:com.gst.portfolio.savings.domain.FixedDepositAccount.java

License:Apache License

public void prematureClosure(final AppUser currentUser, final JsonCommand command,
        final LocalDate tenantsTodayDate, final Map<String, Object> actualChanges) {

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(FIXED_DEPOSIT_ACCOUNT_RESOURCE_NAME + DepositsApiConstants.preMatureCloseAction);

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.ACTIVE.hasStateOf(currentStatus)) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("not.in.active.state");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }//from   ww w .j  a  v  a  2  s  . c  o m
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate closedDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);

    if (closedDate.isBefore(getActivationLocalDate())) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("must.be.after.activation.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (isAccountLocked(closedDate)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("must.be.after.lockin.period");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (closedDate.isAfter(maturityDate())) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("must.be.before.maturity.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (closedDate.isAfter(tenantsTodayDate)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("cannot.be.a.future.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    final List<SavingsAccountTransaction> savingsAccountTransactions = retreiveListOfTransactions();
    if (savingsAccountTransactions.size() > 0) {
        final SavingsAccountTransaction accountTransaction = savingsAccountTransactions
                .get(savingsAccountTransactions.size() - 1);
        if (accountTransaction.isAfter(closedDate)) {
            baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                    .failWithCode("must.be.after.last.transaction.date");
            if (!dataValidationErrors.isEmpty()) {
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }
    }

    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_CLOSE_ACCOUNT, closedDate);
    this.status = SavingsAccountStatusType.PRE_MATURE_CLOSURE.getValue();

    final Integer onAccountClosureId = command.integerValueOfParameterNamed(onAccountClosureIdParamName);
    final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType.fromInt(onAccountClosureId);
    this.accountTermAndPreClosure.updateOnAccountClosureStatus(onClosureType);

    /*
     * // withdraw deposit amount before closing the account final Money
     * transactionAmountMoney = Money.of(this.currency,
     * this.getAccountBalance()); final SavingsAccountTransaction withdraw =
     * SavingsAccountTransaction.withdrawal(this, office(), paymentDetail,
     * closedDate, transactionAmountMoney, new Date());
     * this.transactions.add(withdraw);
     */
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));
    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.closedOnDateParamName, closedDate.toString(fmt));

    this.rejectedOnDate = null;
    this.rejectedBy = null;
    this.withdrawnOnDate = null;
    this.withdrawnBy = null;
    this.closedOnDate = closedDate.toDate();
    this.closedBy = currentUser;
    this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions);
}

From source file:com.gst.portfolio.savings.domain.FixedDepositAccount.java

License:Apache License

public void close(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate,
        final Map<String, Object> actualChanges) {

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(FIXED_DEPOSIT_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.closeAction);

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.MATURED.hasStateOf(currentStatus)) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("not.in.matured.state");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/*  w ww.  j a  v a  2s .  c o  m*/
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate closedDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);

    if (closedDate.isBefore(getActivationLocalDate())) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("must.be.after.activation.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    if (closedDate.isBefore(maturityDate())) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("must.be.after.account.maturity.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    if (closedDate.isAfter(tenantsTodayDate)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("cannot.be.a.future.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    final List<SavingsAccountTransaction> savingsAccountTransactions = retreiveListOfTransactions();
    if (savingsAccountTransactions.size() > 0) {
        final SavingsAccountTransaction accountTransaction = savingsAccountTransactions
                .get(savingsAccountTransactions.size() - 1);
        if (accountTransaction.isAfter(closedDate)) {
            baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                    .failWithCode("must.be.after.last.transaction.date");
            if (!dataValidationErrors.isEmpty()) {
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }
    }

    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_CLOSE_ACCOUNT, closedDate);
    this.status = SavingsAccountStatusType.CLOSED.getValue();

    final Integer onAccountClosureId = command.integerValueOfParameterNamed(onAccountClosureIdParamName);
    final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType.fromInt(onAccountClosureId);
    this.accountTermAndPreClosure.updateOnAccountClosureStatus(onClosureType);

    // // withdraw deposit amount before closing the account
    // final Money transactionAmountMoney = Money.of(this.currency,
    // this.getAccountBalance());
    // final SavingsAccountTransaction withdraw =
    // SavingsAccountTransaction.withdrawal(this, office(), paymentDetail,
    // closedDate,
    // transactionAmountMoney, new Date());
    // this.transactions.add(withdraw);

    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));
    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.closedOnDateParamName, closedDate.toString(fmt));

    this.rejectedOnDate = null;
    this.rejectedBy = null;
    this.withdrawnOnDate = null;
    this.withdrawnBy = null;
    this.closedOnDate = closedDate.toDate();
    this.closedBy = currentUser;
    // this.summary.updateSummary(this.currency,
    // this.savingsAccountTransactionSummaryWrapper, this.transactions);
}

From source file:com.gst.portfolio.savings.domain.RecurringDepositAccount.java

License:Apache License

public void prematureClosure(final AppUser currentUser, final JsonCommand command,
        final LocalDate tenantsTodayDate, final Map<String, Object> actualChanges) {

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(RECURRING_DEPOSIT_ACCOUNT_RESOURCE_NAME + DepositsApiConstants.preMatureCloseAction);

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.ACTIVE.hasStateOf(currentStatus)) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("not.in.active.state");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }//from   w w  w  . ja v  a2s.  c om
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate closedDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);

    if (closedDate.isBefore(getActivationLocalDate())) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("must.be.after.activation.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (isAccountLocked(closedDate)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("must.be.after.lockin.period");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (closedDate.isAfter(maturityDate())) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("must.be.before.maturity.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (closedDate.isAfter(tenantsTodayDate)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("cannot.be.a.future.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (isAccountLocked(calculateMaturityDate())) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode(
                "deposit.period.must.be.greater.than.lock.in.period",
                "Deposit period must be greater than account lock-in period.");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    final List<SavingsAccountTransaction> savingsAccountTransactions = retreiveListOfTransactions();
    if (savingsAccountTransactions.size() > 0) {
        final SavingsAccountTransaction accountTransaction = savingsAccountTransactions
                .get(savingsAccountTransactions.size() - 1);
        if (accountTransaction.isAfter(closedDate)) {
            baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                    .failWithCode("must.be.after.last.transaction.date");
            if (!dataValidationErrors.isEmpty()) {
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }
    }

    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_CLOSE_ACCOUNT, closedDate);
    this.status = SavingsAccountStatusType.PRE_MATURE_CLOSURE.getValue();

    final Integer onAccountClosureId = command.integerValueOfParameterNamed(onAccountClosureIdParamName);
    final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType.fromInt(onAccountClosureId);
    this.accountTermAndPreClosure.updateOnAccountClosureStatus(onClosureType);

    /*
     * // withdraw deposit amount before closing the account final Money
     * transactionAmountMoney = Money.of(this.currency,
     * this.getAccountBalance()); final SavingsAccountTransaction withdraw =
     * SavingsAccountTransaction.withdrawal(this, office(), paymentDetail,
     * closedDate, transactionAmountMoney, new Date());
     * this.transactions.add(withdraw);
     */
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));
    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.closedOnDateParamName, closedDate.toString(fmt));

    this.rejectedOnDate = null;
    this.rejectedBy = null;
    this.withdrawnOnDate = null;
    this.withdrawnBy = null;
    this.closedOnDate = closedDate.toDate();
    this.closedBy = currentUser;
    this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions);

}

From source file:com.gst.portfolio.savings.domain.RecurringDepositAccount.java

License:Apache License

public void close(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate,
        final Map<String, Object> actualChanges) {

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(RECURRING_DEPOSIT_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.closeAction);

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.MATURED.hasStateOf(currentStatus) && this.maturityDate() != null) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("not.in.matured.state");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }// www . j  a  v  a 2  s  .c om
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate closedDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);

    if (closedDate.isBefore(getActivationLocalDate())) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("must.be.after.activation.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    if (maturityDate() != null && closedDate.isBefore(maturityDate())) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("must.be.after.account.maturity.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    if (closedDate.isAfter(tenantsTodayDate)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("cannot.be.a.future.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    final List<SavingsAccountTransaction> savingsAccountTransactions = retreiveListOfTransactions();
    if (savingsAccountTransactions.size() > 0) {
        final SavingsAccountTransaction accountTransaction = savingsAccountTransactions
                .get(savingsAccountTransactions.size() - 1);
        if (accountTransaction.isAfter(closedDate)) {
            baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                    .failWithCode("must.be.after.last.transaction.date");
            if (!dataValidationErrors.isEmpty()) {
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }
    }

    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_CLOSE_ACCOUNT, closedDate);
    this.status = SavingsAccountStatusType.CLOSED.getValue();

    final Integer onAccountClosureId = command.integerValueOfParameterNamed(onAccountClosureIdParamName);
    final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType.fromInt(onAccountClosureId);
    this.accountTermAndPreClosure.updateOnAccountClosureStatus(onClosureType);

    /*
     * // withdraw deposit amount before closing the account final Money
     * transactionAmountMoney = Money.of(this.currency,
     * this.getAccountBalance()); final SavingsAccountTransaction withdraw =
     * SavingsAccountTransaction.withdrawal(this, office(), paymentDetail,
     * closedDate, transactionAmountMoney, new Date());
     * this.transactions.add(withdraw);
     */

    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));
    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.closedOnDateParamName, closedDate.toString(fmt));

    this.rejectedOnDate = null;
    this.rejectedBy = null;
    this.withdrawnOnDate = null;
    this.withdrawnBy = null;
    this.closedOnDate = closedDate.toDate();
    this.closedBy = currentUser;
    this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions);
}

From source file:com.gst.portfolio.savings.domain.SavingsAccount.java

License:Apache License

public Map<String, Object> activate(final AppUser currentUser, final JsonCommand command,
        final LocalDate tenantsTodayDate) {

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

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(depositAccountType().resourceName() + SavingsApiConstants.activateAction);

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.APPROVED.hasStateOf(currentStatus)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("not.in.approved.state");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }//from   w  ww.  j  a  v a 2s. c  om
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate activationDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.activatedOnDateParamName);

    this.status = SavingsAccountStatusType.ACTIVE.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));
    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.activatedOnDateParamName, activationDate.toString(fmt));

    this.rejectedOnDate = null;
    this.rejectedBy = null;
    this.withdrawnOnDate = null;
    this.withdrawnBy = null;
    this.closedOnDate = null;
    this.closedBy = null;
    this.activatedOnDate = activationDate.toDate();
    this.activatedBy = currentUser;
    this.lockedInUntilDate = calculateDateAccountIsLockedUntil(getActivationLocalDate());

    /*
     * if (annualFeeSettingsSet()) {
     * updateToNextAnnualFeeDueDateFrom(getActivationLocalDate()); }
     */
    if (this.client != null && this.client.isActivatedAfter(activationDate)) {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String dateAsString = formatter.print(this.client.getActivationLocalDate());
        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(dateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.client.activation.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (this.group != null && this.group.isActivatedAfter(activationDate)) {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String dateAsString = formatter.print(this.client.getActivationLocalDate());
        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(dateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.group.activation.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    final LocalDate approvalDate = getApprovedOnLocalDate();
    if (activationDate.isBefore(approvalDate)) {

        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String dateAsString = formatter.print(approvalDate);

        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(dateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.approval.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (activationDate.isAfter(tenantsTodayDate)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(activationDate)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_ACTIVATE, activationDate);

    return actualChanges;
}

From source file:com.gst.portfolio.savings.domain.SavingsAccount.java

License:Apache License

public Map<String, Object> close(final AppUser currentUser, final JsonCommand command,
        final LocalDate tenantsTodayDate) {

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

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(SAVINGS_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.closeAction);

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.ACTIVE.hasStateOf(currentStatus)) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("not.in.active.state");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/* www  .jav a2s . co  m*/
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate closedDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);

    if (closedDate.isBefore(getActivationLocalDate())) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("must.be.after.activation.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    if (closedDate.isAfter(tenantsTodayDate)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("cannot.be.a.future.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    final List<SavingsAccountTransaction> savingsAccountTransactions = retreiveListOfTransactions();
    if (savingsAccountTransactions.size() > 0) {
        final SavingsAccountTransaction accountTransaction = savingsAccountTransactions
                .get(savingsAccountTransactions.size() - 1);
        if (accountTransaction.isAfter(closedDate)) {
            baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                    .failWithCode("must.be.after.last.transaction.date");
            if (!dataValidationErrors.isEmpty()) {
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }
    }
    if (getAccountBalance().doubleValue() != 0) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("results.in.balance.not.zero");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_CLOSE_ACCOUNT, closedDate);
    this.status = SavingsAccountStatusType.CLOSED.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));
    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.closedOnDateParamName, closedDate.toString(fmt));

    this.rejectedOnDate = null;
    this.rejectedBy = null;
    this.withdrawnOnDate = null;
    this.withdrawnBy = null;
    this.closedOnDate = closedDate.toDate();
    this.closedBy = currentUser;

    return actualChanges;
}

From source file:com.gst.portfolio.savings.domain.SavingsAccount.java

License:Apache License

public void payCharge(final SavingsAccountCharge savingsAccountCharge, final BigDecimal amountPaid,
        final LocalDate transactionDate, final DateTimeFormatter formatter, final AppUser user) {

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(SAVINGS_ACCOUNT_RESOURCE_NAME);

    if (isClosed()) {
        baseDataValidator.reset()/*w ww. ja  v  a2s .c  o m*/
                .failWithCodeNoParameterAddedToErrorCode("transaction.invalid.account.is.closed");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (isNotActive()) {
        baseDataValidator.reset()
                .failWithCodeNoParameterAddedToErrorCode("transaction.invalid.account.is.not.active");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (savingsAccountCharge.isNotActive()) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("charge.is.not.active");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (getActivationLocalDate() != null && transactionDate.isBefore(getActivationLocalDate())) {
        baseDataValidator.reset().parameter(dueAsOfDateParamName)
                .value(getActivationLocalDate().toString(formatter))
                .failWithCodeNoParameterAddedToErrorCode("transaction.before.activationDate");
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }

    if (DateUtils.isDateInTheFuture(transactionDate)) {
        baseDataValidator.reset().parameter(dueAsOfDateParamName).value(transactionDate.toString(formatter))
                .failWithCodeNoParameterAddedToErrorCode("transaction.is.futureDate");
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }

    if (savingsAccountCharge.isSavingsActivation()) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode(
                "transaction.not.valid.cannot.pay.activation.time.charge.is.automated");
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }

    if (savingsAccountCharge.isAnnualFee()) {
        final LocalDate annualFeeDueDate = savingsAccountCharge.getDueLocalDate();
        if (annualFeeDueDate == null) {
            baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("no.annualfee.settings");
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }

        if (!annualFeeDueDate.equals(transactionDate)) {
            baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("invalid.date");
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }

        Date currentAnnualFeeNextDueDate = findLatestAnnualFeeTransactionDueDate();
        if (currentAnnualFeeNextDueDate != null
                && new LocalDate(currentAnnualFeeNextDueDate).isEqual(transactionDate)) {
            baseDataValidator.reset().parameter("dueDate").value(transactionDate.toString(formatter))
                    .failWithCodeNoParameterAddedToErrorCode("transaction.exists.on.date");

            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    // validate charge is not already paid or waived
    if (savingsAccountCharge.isWaived()) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode(
                "transaction.invalid.account.charge.is.already.waived");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    } else if (savingsAccountCharge.isPaid()) {
        baseDataValidator.reset()
                .failWithCodeNoParameterAddedToErrorCode("transaction.invalid.account.charge.is.paid");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    final Money chargePaid = Money.of(currency, amountPaid);
    if (!savingsAccountCharge.getAmountOutstanding(getCurrency()).isGreaterThanOrEqualTo(chargePaid)) {
        baseDataValidator.reset()
                .failWithCodeNoParameterAddedToErrorCode("transaction.invalid.charge.amount.paid.in.access");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    this.payCharge(savingsAccountCharge, chargePaid, transactionDate, user);
}

From source file:com.gst.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

@Override
public CommandProcessingResult payCharge(final Long savingsAccountId, final Long savingsAccountChargeId,
        final JsonCommand command, @SuppressWarnings("unused") final DepositAccountType depositAccountType) {

    this.context.authenticatedUser();

    this.savingsAccountChargeDataValidator.validatePayCharge(command.json());
    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final BigDecimal amountPaid = command.bigDecimalValueOfParameterNamed(amountParamName);
    final LocalDate transactionDate = command.localDateValueOfParameterNamed(dueAsOfDateParamName);

    final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository
            .findOneWithNotFoundDetection(savingsAccountChargeId, savingsAccountId);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(SAVINGS_ACCOUNT_RESOURCE_NAME);

    // transaction date should not be on a holiday or non working day
    if (!this.configurationDomainService.allowTransactionsOnHolidayEnabled() && this.holidayRepository
            .isHoliday(savingsAccountCharge.savingsAccount().officeId(), transactionDate)) {
        baseDataValidator.reset().parameter(dueAsOfDateParamName).value(transactionDate.toString(fmt))
                .failWithCodeNoParameterAddedToErrorCode(
                        "transaction.not.allowed.transaction.date.is.on.holiday");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/*from w  ww . j  a  v a2s  . c  o m*/
    }

    if (!this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled()
            && !this.workingDaysRepository.isWorkingDay(transactionDate)) {
        baseDataValidator.reset().parameter(dueAsOfDateParamName).value(transactionDate.toString(fmt))
                .failWithCodeNoParameterAddedToErrorCode(
                        "transaction.not.allowed.transaction.date.is.a.nonworking.day");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    this.payCharge(savingsAccountCharge, transactionDate, amountPaid, fmt);
    return new CommandProcessingResultBuilder() //
            .withEntityId(savingsAccountCharge.getId()) //
            .withOfficeId(savingsAccountCharge.savingsAccount().officeId()) //
            .withClientId(savingsAccountCharge.savingsAccount().clientId()) //
            .withGroupId(savingsAccountCharge.savingsAccount().groupId()) //
            .withSavingsId(savingsAccountCharge.savingsAccount().getId()) //
            .build();

}

From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

@Transactional
@Override/*  ww  w  . j a v a2s  .c  o  m*/
public CommandProcessingResult addSavingsAccountCharge(final JsonCommand command) {

    this.context.authenticatedUser();
    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(SAVINGS_ACCOUNT_RESOURCE_NAME);

    final Long savingsAccountId = command.getSavingsId();
    this.savingsAccountChargeDataValidator.validateAdd(command.json());

    final SavingsAccount savingsAccount = this.savingAccountAssembler.assembleFrom(savingsAccountId);
    checkClientOrGroupActive(savingsAccount);

    final Locale locale = command.extractLocale();
    final String format = command.dateFormat();
    final DateTimeFormatter fmt = StringUtils.isNotBlank(format)
            ? DateTimeFormat.forPattern(format).withLocale(locale)
            : DateTimeFormat.forPattern("dd MM yyyy");

    final Long chargeDefinitionId = command.longValueOfParameterNamed(chargeIdParamName);
    final Charge chargeDefinition = this.chargeRepository.findOneWithNotFoundDetection(chargeDefinitionId);

    Integer chargeTimeType = chargeDefinition.getChargeTimeType();
    LocalDate dueAsOfDateParam = command.localDateValueOfParameterNamed(dueAsOfDateParamName);
    if ((chargeTimeType.equals(ChargeTimeType.WITHDRAWAL_FEE.getValue())
            || chargeTimeType.equals(ChargeTimeType.SAVINGS_NOACTIVITY_FEE.getValue()))
            && dueAsOfDateParam != null) {
        baseDataValidator.reset().parameter(dueAsOfDateParamName).value(dueAsOfDateParam.toString(fmt))
                .failWithCodeNoParameterAddedToErrorCode(
                        "charge.due.date.is.invalid.for." + ChargeTimeType.fromInt(chargeTimeType).getCode());
    }
    final SavingsAccountCharge savingsAccountCharge = SavingsAccountCharge.createNewFromJson(savingsAccount,
            chargeDefinition, command);

    if (savingsAccountCharge.getDueLocalDate() != null) {
        // transaction date should not be on a holiday or non working day
        if (!this.configurationDomainService.allowTransactionsOnHolidayEnabled() && this.holidayRepository
                .isHoliday(savingsAccount.officeId(), savingsAccountCharge.getDueLocalDate())) {
            baseDataValidator.reset().parameter(dueAsOfDateParamName)
                    .value(savingsAccountCharge.getDueLocalDate().toString(fmt))
                    .failWithCodeNoParameterAddedToErrorCode("charge.due.date.is.on.holiday");
        }

        if (!this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled()
                && !this.workingDaysRepository.isWorkingDay(savingsAccountCharge.getDueLocalDate())) {
            baseDataValidator.reset().parameter(dueAsOfDateParamName)
                    .value(savingsAccountCharge.getDueLocalDate().toString(fmt))
                    .failWithCodeNoParameterAddedToErrorCode("charge.due.date.is.a.nonworking.day");
        }
    }
    if (!dataValidationErrors.isEmpty()) {
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }

    savingsAccount.addCharge(fmt, savingsAccountCharge, chargeDefinition);
    this.savingsAccountChargeRepository.save(savingsAccountCharge);
    this.savingAccountRepositoryWrapper.saveAndFlush(savingsAccount);
    return new CommandProcessingResultBuilder() //
            .withEntityId(savingsAccountCharge.getId()) //
            .withOfficeId(savingsAccount.officeId()) //
            .withClientId(savingsAccount.clientId()) //
            .withGroupId(savingsAccount.groupId()) //
            .withSavingsId(savingsAccountId) //
            .build();
}

From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

@Override
public CommandProcessingResult payCharge(final Long savingsAccountId, final Long savingsAccountChargeId,
        final JsonCommand command) {

    AppUser user = getAppUserIfPresent();

    this.savingsAccountChargeDataValidator.validatePayCharge(command.json());
    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final BigDecimal amountPaid = command.bigDecimalValueOfParameterNamed(amountParamName);
    final LocalDate transactionDate = command.localDateValueOfParameterNamed(dueAsOfDateParamName);

    final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository
            .findOneWithNotFoundDetection(savingsAccountChargeId, savingsAccountId);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(SAVINGS_ACCOUNT_RESOURCE_NAME);

    // transaction date should not be on a holiday or non working day
    if (!this.configurationDomainService.allowTransactionsOnHolidayEnabled() && this.holidayRepository
            .isHoliday(savingsAccountCharge.savingsAccount().officeId(), transactionDate)) {
        baseDataValidator.reset().parameter(dueAsOfDateParamName).value(transactionDate.toString(fmt))
                .failWithCodeNoParameterAddedToErrorCode(
                        "transaction.not.allowed.transaction.date.is.on.holiday");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/*from   w  w  w .  j a v  a  2 s.  co m*/
    }

    if (!this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled()
            && !this.workingDaysRepository.isWorkingDay(transactionDate)) {
        baseDataValidator.reset().parameter(dueAsOfDateParamName).value(transactionDate.toString(fmt))
                .failWithCodeNoParameterAddedToErrorCode(
                        "transaction.not.allowed.transaction.date.is.a.nonworking.day");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    this.payCharge(savingsAccountCharge, transactionDate, amountPaid, fmt, user);
    return new CommandProcessingResultBuilder() //
            .withEntityId(savingsAccountCharge.getId()) //
            .withOfficeId(savingsAccountCharge.savingsAccount().officeId()) //
            .withClientId(savingsAccountCharge.savingsAccount().clientId()) //
            .withGroupId(savingsAccountCharge.savingsAccount().groupId()) //
            .withSavingsId(savingsAccountCharge.savingsAccount().getId()) //
            .build();

}