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.savings.domain.SavingsAccount.java

License:Apache License

public void modifyApplication(final JsonCommand command, final Map<String, Object> actualChanges,
        final DataValidatorBuilder baseDataValidator) {

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.hasStateOf(currentStatus)) {
        baseDataValidator.reset()/*from w w  w.j a  v  a 2s.c o  m*/
                .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state");
        return;
    }

    final String localeAsInput = command.locale();
    final String dateFormat = command.dateFormat();

    if (command.isChangeInLocalDateParameterNamed(SavingsApiConstants.submittedOnDateParamName,
            getSubmittedOnLocalDate())) {
        final LocalDate newValue = command
                .localDateValueOfParameterNamed(SavingsApiConstants.submittedOnDateParamName);
        final String newValueAsString = command
                .stringValueOfParameterNamed(SavingsApiConstants.submittedOnDateParamName);
        actualChanges.put(SavingsApiConstants.submittedOnDateParamName, newValueAsString);
        actualChanges.put(SavingsApiConstants.localeParamName, localeAsInput);
        actualChanges.put(SavingsApiConstants.dateFormatParamName, dateFormat);
        this.submittedOnDate = newValue.toDate();
    }

    if (command.isChangeInStringParameterNamed(SavingsApiConstants.accountNoParamName, this.accountNumber)) {
        final String newValue = command.stringValueOfParameterNamed(SavingsApiConstants.accountNoParamName);
        actualChanges.put(SavingsApiConstants.accountNoParamName, newValue);
        this.accountNumber = StringUtils.defaultIfEmpty(newValue, null);
    }

    if (command.isChangeInStringParameterNamed(SavingsApiConstants.externalIdParamName, this.externalId)) {
        final String newValue = command.stringValueOfParameterNamed(SavingsApiConstants.externalIdParamName);
        actualChanges.put(SavingsApiConstants.externalIdParamName, newValue);
        this.externalId = StringUtils.defaultIfEmpty(newValue, null);
    }

    if (command.isChangeInLongParameterNamed(SavingsApiConstants.clientIdParamName, clientId())) {
        final Long newValue = command.longValueOfParameterNamed(SavingsApiConstants.clientIdParamName);
        actualChanges.put(SavingsApiConstants.clientIdParamName, newValue);
    }

    if (command.isChangeInLongParameterNamed(SavingsApiConstants.groupIdParamName, groupId())) {
        final Long newValue = command.longValueOfParameterNamed(SavingsApiConstants.groupIdParamName);
        actualChanges.put(SavingsApiConstants.groupIdParamName, newValue);
    }

    if (command.isChangeInLongParameterNamed(SavingsApiConstants.productIdParamName, this.product.getId())) {
        final Long newValue = command.longValueOfParameterNamed(SavingsApiConstants.productIdParamName);
        actualChanges.put(SavingsApiConstants.productIdParamName, newValue);
    }

    if (command.isChangeInLongParameterNamed(SavingsApiConstants.fieldOfficerIdParamName,
            hasSavingsOfficerId())) {
        final Long newValue = command.longValueOfParameterNamed(SavingsApiConstants.fieldOfficerIdParamName);
        actualChanges.put(SavingsApiConstants.fieldOfficerIdParamName, newValue);
    }

    if (command.isChangeInBigDecimalParameterNamed(SavingsApiConstants.nominalAnnualInterestRateParamName,
            this.nominalAnnualInterestRate)) {
        final BigDecimal newValue = command
                .bigDecimalValueOfParameterNamed(SavingsApiConstants.nominalAnnualInterestRateParamName);
        actualChanges.put(SavingsApiConstants.nominalAnnualInterestRateParamName, newValue);
        actualChanges.put("locale", localeAsInput);
        this.nominalAnnualInterestRate = newValue;
    }

    if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestCompoundingPeriodTypeParamName,
            this.interestCompoundingPeriodType)) {
        final Integer newValue = command
                .integerValueOfParameterNamed(SavingsApiConstants.interestCompoundingPeriodTypeParamName);
        this.interestCompoundingPeriodType = newValue != null
                ? SavingsCompoundingInterestPeriodType.fromInt(newValue).getValue()
                : newValue;
        actualChanges.put(SavingsApiConstants.interestCompoundingPeriodTypeParamName,
                this.interestCompoundingPeriodType);
    }

    if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestPostingPeriodTypeParamName,
            this.interestPostingPeriodType)) {
        final Integer newValue = command
                .integerValueOfParameterNamed(SavingsApiConstants.interestPostingPeriodTypeParamName);
        this.interestPostingPeriodType = newValue != null
                ? SavingsPostingInterestPeriodType.fromInt(newValue).getValue()
                : newValue;
        actualChanges.put(SavingsApiConstants.interestPostingPeriodTypeParamName,
                this.interestPostingPeriodType);
    }

    if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestCalculationTypeParamName,
            this.interestCalculationType)) {
        final Integer newValue = command
                .integerValueOfParameterNamed(SavingsApiConstants.interestCalculationTypeParamName);
        this.interestCalculationType = newValue != null
                ? SavingsInterestCalculationType.fromInt(newValue).getValue()
                : newValue;
        actualChanges.put(SavingsApiConstants.interestCalculationTypeParamName, this.interestCalculationType);
    }

    if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestCalculationDaysInYearTypeParamName,
            this.interestCalculationDaysInYearType)) {
        final Integer newValue = command
                .integerValueOfParameterNamed(SavingsApiConstants.interestCalculationDaysInYearTypeParamName);
        this.interestCalculationDaysInYearType = newValue != null
                ? SavingsInterestCalculationDaysInYearType.fromInt(newValue).getValue()
                : newValue;
        actualChanges.put(SavingsApiConstants.interestCalculationDaysInYearTypeParamName,
                this.interestCalculationDaysInYearType);
    }

    if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(
            SavingsApiConstants.minRequiredOpeningBalanceParamName, this.minRequiredOpeningBalance)) {
        final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(
                SavingsApiConstants.minRequiredOpeningBalanceParamName);
        actualChanges.put(SavingsApiConstants.minRequiredOpeningBalanceParamName, newValue);
        actualChanges.put("locale", localeAsInput);
        this.minRequiredOpeningBalance = Money.of(this.currency, newValue).getAmount();
    }

    if (command.isChangeInIntegerParameterNamedDefaultingZeroToNull(
            SavingsApiConstants.lockinPeriodFrequencyParamName, this.lockinPeriodFrequency)) {
        final Integer newValue = command.integerValueOfParameterNamedDefaultToNullIfZero(
                SavingsApiConstants.lockinPeriodFrequencyParamName);
        actualChanges.put(SavingsApiConstants.lockinPeriodFrequencyParamName, newValue);
        actualChanges.put("locale", localeAsInput);
        this.lockinPeriodFrequency = newValue;
    }

    if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.lockinPeriodFrequencyTypeParamName,
            this.lockinPeriodFrequencyType)) {
        final Integer newValue = command
                .integerValueOfParameterNamed(SavingsApiConstants.lockinPeriodFrequencyTypeParamName);
        actualChanges.put(SavingsApiConstants.lockinPeriodFrequencyTypeParamName, newValue);
        this.lockinPeriodFrequencyType = newValue != null
                ? SavingsPeriodFrequencyType.fromInt(newValue).getValue()
                : newValue;
    }

    // set period type to null if frequency is null
    if (this.lockinPeriodFrequency == null) {
        this.lockinPeriodFrequencyType = null;
    }

    if (command.isChangeInBooleanParameterNamed(withdrawalFeeForTransfersParamName,
            this.withdrawalFeeApplicableForTransfer)) {
        final boolean newValue = command
                .booleanPrimitiveValueOfParameterNamed(withdrawalFeeForTransfersParamName);
        actualChanges.put(withdrawalFeeForTransfersParamName, newValue);
        this.withdrawalFeeApplicableForTransfer = newValue;
    }

    // charges
    final String chargesParamName = "charges";
    if (command.hasParameter(chargesParamName)) {
        final JsonArray jsonArray = command.arrayOfParameterNamed(chargesParamName);
        if (jsonArray != null) {
            actualChanges.put(chargesParamName, command.jsonFragment(chargesParamName));
        }
    }

    if (command.isChangeInBooleanParameterNamed(allowOverdraftParamName, this.allowOverdraft)) {
        final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(allowOverdraftParamName);
        actualChanges.put(allowOverdraftParamName, newValue);
        this.allowOverdraft = newValue;
    }

    if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(overdraftLimitParamName,
            this.overdraftLimit)) {
        final BigDecimal newValue = command
                .bigDecimalValueOfParameterNamedDefaultToNullIfZero(overdraftLimitParamName);
        actualChanges.put(overdraftLimitParamName, newValue);
        actualChanges.put(localeParamName, localeAsInput);
        this.overdraftLimit = newValue;
    }

    if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(
            nominalAnnualInterestRateOverdraftParamName, this.nominalAnnualInterestRateOverdraft)) {
        final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(
                nominalAnnualInterestRateOverdraftParamName);
        actualChanges.put(nominalAnnualInterestRateOverdraftParamName, newValue);
        actualChanges.put(localeParamName, localeAsInput);
        this.nominalAnnualInterestRateOverdraft = newValue;
    }

    if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(
            minOverdraftForInterestCalculationParamName, this.minOverdraftForInterestCalculation)) {
        final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(
                minOverdraftForInterestCalculationParamName);
        actualChanges.put(minOverdraftForInterestCalculationParamName, newValue);
        actualChanges.put(localeParamName, localeAsInput);
        this.minOverdraftForInterestCalculation = newValue;
    }

    if (!this.allowOverdraft) {
        this.overdraftLimit = null;
        this.nominalAnnualInterestRateOverdraft = null;
        this.minOverdraftForInterestCalculation = null;
    }

    if (command.isChangeInBooleanParameterNamed(enforceMinRequiredBalanceParamName,
            this.enforceMinRequiredBalance)) {
        final boolean newValue = command
                .booleanPrimitiveValueOfParameterNamed(enforceMinRequiredBalanceParamName);
        actualChanges.put(enforceMinRequiredBalanceParamName, newValue);
        this.enforceMinRequiredBalance = newValue;
    }

    if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(minRequiredBalanceParamName,
            this.minRequiredBalance)) {
        final BigDecimal newValue = command
                .bigDecimalValueOfParameterNamedDefaultToNullIfZero(minRequiredBalanceParamName);
        actualChanges.put(minRequiredBalanceParamName, newValue);
        actualChanges.put(localeParamName, localeAsInput);
        this.minRequiredBalance = newValue;
    }

    if (command.isChangeInBooleanParameterNamed(withHoldTaxParamName, this.withHoldTax)) {
        final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(withHoldTaxParamName);
        actualChanges.put(withHoldTaxParamName, newValue);
        this.withHoldTax = newValue;
        if (this.withHoldTax && this.taxGroup == null) {
            baseDataValidator.reset().parameter(withHoldTaxParamName)
                    .failWithCode("not.supported.for.this.account");
        }
    }

    validateLockinDetails(baseDataValidator);
    esnureOverdraftLimitsSetForOverdraftAccounts();
}

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

License:Apache License

public Map<String, Object> approveApplication(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.approvalAction);

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.hasStateOf(currentStatus)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.approvedOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/*from  w ww . ja v a2s . c o  m*/
    }

    this.status = SavingsAccountStatusType.APPROVED.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));

    // only do below if status has changed in the 'approval' case
    final LocalDate approvedOn = command
            .localDateValueOfParameterNamed(SavingsApiConstants.approvedOnDateParamName);
    final String approvedOnDateChange = command
            .stringValueOfParameterNamed(SavingsApiConstants.approvedOnDateParamName);

    this.approvedOnDate = approvedOn.toDate();
    this.approvedBy = currentUser;
    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.approvedOnDateParamName, approvedOnDateChange);

    final LocalDate submittalDate = getSubmittedOnLocalDate();
    if (approvedOn.isBefore(submittalDate)) {

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

        baseDataValidator.reset().parameter(SavingsApiConstants.approvedOnDateParamName)
                .value(submittalDateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.submittal.date");

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

    if (approvedOn.isAfter(tenantsTodayDate)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.approvedOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date");

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

    // FIXME - kw - support field officer history for savings accounts
    // if (this.fieldOfficer != null) {
    // final LoanOfficerAssignmentHistory loanOfficerAssignmentHistory =
    // LoanOfficerAssignmentHistory.createNew(this,
    // this.fieldOfficer, approvedOn);
    // this.loanOfficerHistory.add(loanOfficerAssignmentHistory);
    // }
    if (this.savingsOfficer != null) {
        final SavingsOfficerAssignmentHistory savingsOfficerAssignmentHistory = SavingsOfficerAssignmentHistory
                .createNew(this, this.savingsOfficer, approvedOn);
        this.savingsOfficerHistory.add(savingsOfficerAssignmentHistory);
    }
    return actualChanges;
}

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

License:Apache License

private Date findLatestAnnualFeeTransactionDueDate() {

    Date nextDueDate = null;//from  w w w .  ja va 2  s  .co  m

    LocalDate lastAnnualFeeTransactionDate = null;
    for (final SavingsAccountTransaction transaction : retreiveOrderedNonInterestPostingTransactions()) {
        if (transaction.isAnnualFeeAndNotReversed()) {
            if (lastAnnualFeeTransactionDate == null) {
                lastAnnualFeeTransactionDate = transaction.transactionLocalDate();
                nextDueDate = lastAnnualFeeTransactionDate.toDate();
            }

            if (transaction.transactionLocalDate().isAfter(lastAnnualFeeTransactionDate)) {
                lastAnnualFeeTransactionDate = transaction.transactionLocalDate();
                nextDueDate = lastAnnualFeeTransactionDate.toDate();
            }
        }
    }

    return nextDueDate;
}

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

License:Apache License

public Map<String, Object> rejectApplication(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.rejectAction);

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

        baseDataValidator.reset().parameter(SavingsApiConstants.rejectedOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }//from  w  w  w.j av  a  2 s.c o m
    }

    this.status = SavingsAccountStatusType.REJECTED.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));

    final LocalDate rejectedOn = command
            .localDateValueOfParameterNamed(SavingsApiConstants.rejectedOnDateParamName);
    final String rejectedOnAsString = command
            .stringValueOfParameterNamed(SavingsApiConstants.rejectedOnDateParamName);

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

    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.rejectedOnDateParamName, rejectedOnAsString);
    actualChanges.put(SavingsApiConstants.closedOnDateParamName, rejectedOnAsString);

    final LocalDate submittalDate = getSubmittedOnLocalDate();

    if (rejectedOn.isBefore(submittalDate)) {

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

        baseDataValidator.reset().parameter(SavingsApiConstants.rejectedOnDateParamName)
                .value(submittalDateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.submittal.date");

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

    if (rejectedOn.isAfter(tenantsTodayDate)) {

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

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

    return actualChanges;
}

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

License:Apache License

public Map<String, Object> applicantWithdrawsFromApplication(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.withdrawnByApplicantAction);

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

        baseDataValidator.reset().parameter(SavingsApiConstants.withdrawnOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/*from   ww w  . jav a2  s . c o m*/
    }

    this.status = SavingsAccountStatusType.WITHDRAWN_BY_APPLICANT.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));

    final LocalDate withdrawnOn = command
            .localDateValueOfParameterNamed(SavingsApiConstants.withdrawnOnDateParamName);
    final String withdrawnOnAsString = command
            .stringValueOfParameterNamed(SavingsApiConstants.withdrawnOnDateParamName);

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

    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.withdrawnOnDateParamName, withdrawnOnAsString);
    actualChanges.put(SavingsApiConstants.closedOnDateParamName, withdrawnOnAsString);

    final LocalDate submittalDate = getSubmittedOnLocalDate();
    if (withdrawnOn.isBefore(submittalDate)) {

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

        baseDataValidator.reset().parameter(SavingsApiConstants.withdrawnOnDateParamName)
                .value(submittalDateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.submittal.date");

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

    if (withdrawnOn.isAfter(tenantsTodayDate)) {

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

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

    return actualChanges;
}

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  w  w . j  a v a2s .co m
    }

    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);
        }// w w  w . j  ava2s  .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.SavingsAccountCharge.java

License:Apache License

private SavingsAccountCharge(final SavingsAccount savingsAccount, final Charge chargeDefinition,
        final BigDecimal amount, final ChargeTimeType chargeTime, final ChargeCalculationType chargeCalculation,
        final LocalDate dueDate, final boolean status, MonthDay feeOnMonthDay, final Integer feeInterval) {

    this.savingsAccount = savingsAccount;
    this.charge = chargeDefinition;
    this.penaltyCharge = chargeDefinition.isPenalty();
    this.chargeTime = (chargeTime == null) ? chargeDefinition.getChargeTimeType() : chargeTime.getValue();

    if (isOnSpecifiedDueDate()) {
        if (dueDate == null) {
            final String defaultUserMessage = "Savings Account charge is missing due date.";
            throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge",
                    dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(),
                    chargeDefinition.getName());
        }/*from w  ww  . j a  va 2s.  c  o m*/

    }

    if (isAnnualFee() || isMonthlyFee()) {
        feeOnMonthDay = (feeOnMonthDay == null) ? chargeDefinition.getFeeOnMonthDay() : feeOnMonthDay;
        if (feeOnMonthDay == null) {
            final String defaultUserMessage = "Savings Account charge is missing due date.";
            throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge",
                    dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(),
                    chargeDefinition.getName());
        }

        this.feeOnMonth = feeOnMonthDay.getMonthOfYear();
        this.feeOnDay = feeOnMonthDay.getDayOfMonth();

    } else if (isWeeklyFee()) {
        if (dueDate == null) {
            final String defaultUserMessage = "Savings Account charge is missing due date.";
            throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge",
                    dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(),
                    chargeDefinition.getName());
        }
        /**
         * For Weekly fee feeOnDay is ISO standard day of the week.
         * Monday=1, Tuesday=2
         */
        this.feeOnDay = dueDate.getDayOfWeek();
    } else {
        this.feeOnDay = null;
        this.feeOnMonth = null;
        this.feeInterval = null;
    }

    if (isMonthlyFee() || isWeeklyFee()) {
        this.feeInterval = (feeInterval == null) ? chargeDefinition.feeInterval() : feeInterval;
    }

    this.dueDate = (dueDate == null) ? null : dueDate.toDate();

    this.chargeCalculation = chargeDefinition.getChargeCalculation();
    if (chargeCalculation != null) {
        this.chargeCalculation = chargeCalculation.getValue();
    }

    BigDecimal chargeAmount = chargeDefinition.getAmount();
    if (amount != null) {
        chargeAmount = amount;
    }

    final BigDecimal transactionAmount = new BigDecimal(0);

    populateDerivedFields(transactionAmount, chargeAmount);

    if (this.isWithdrawalFee() || this.isSavingsNoActivity()) {
        this.amountOutstanding = BigDecimal.ZERO;
    }

    this.paid = determineIfFullyPaid();
    this.status = status;
}

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

License:Apache License

public void update(final BigDecimal amount, final LocalDate dueDate, final MonthDay feeOnMonthDay,
        final Integer feeInterval) {
    final BigDecimal transactionAmount = BigDecimal.ZERO;
    if (dueDate != null) {
        this.dueDate = dueDate.toDate();
        if (isWeeklyFee()) {
            this.feeOnDay = dueDate.getDayOfWeek();
        }/*ww w  .  jav  a2 s. c  o m*/
    }

    if (feeOnMonthDay != null) {
        this.feeOnMonth = feeOnMonthDay.getMonthOfYear();
        this.feeOnDay = feeOnMonthDay.getDayOfMonth();
    }

    if (feeInterval != null) {
        this.feeInterval = feeInterval;
    }

    if (amount != null) {
        switch (ChargeCalculationType.fromInt(this.chargeCalculation)) {
        case INVALID:
            break;
        case FLAT:
            this.amount = amount;
            break;
        case PERCENT_OF_AMOUNT:
            this.percentage = amount;
            this.amountPercentageAppliedTo = transactionAmount;
            this.amount = percentageOf(this.amountPercentageAppliedTo, this.percentage);
            this.amountOutstanding = calculateOutstanding();
            break;
        case PERCENT_OF_AMOUNT_AND_INTEREST:
            this.percentage = amount;
            this.amount = null;
            this.amountPercentageAppliedTo = null;
            this.amountOutstanding = null;
            break;
        case PERCENT_OF_INTEREST:
            this.percentage = amount;
            this.amount = null;
            this.amountPercentageAppliedTo = null;
            this.amountOutstanding = null;
            break;
        }
    }
}

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

License:Apache License

public Map<String, Object> update(final JsonCommand command) {

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

    final String dateFormatAsInput = command.dateFormat();
    final String localeAsInput = command.locale();

    if (command.isChangeInLocalDateParameterNamed(dueAsOfDateParamName, getDueLocalDate())) {
        final String valueAsInput = command.stringValueOfParameterNamed(dueAsOfDateParamName);
        actualChanges.put(dueAsOfDateParamName, valueAsInput);
        actualChanges.put(dateFormatParamName, dateFormatAsInput);
        actualChanges.put(localeParamName, localeAsInput);

        final LocalDate newValue = command.localDateValueOfParameterNamed(dueAsOfDateParamName);
        this.dueDate = newValue.toDate();
        if (this.isWeeklyFee()) {
            this.feeOnDay = newValue.getDayOfWeek();
        }/*from  ww w .  j  a  va2 s  . c  om*/
    }

    if (command.hasParameter(feeOnMonthDayParamName)) {
        final MonthDay monthDay = command.extractMonthDayNamed(feeOnMonthDayParamName);
        final String actualValueEntered = command.stringValueOfParameterNamed(feeOnMonthDayParamName);
        final Integer dayOfMonthValue = monthDay.getDayOfMonth();
        if (this.feeOnDay != dayOfMonthValue) {
            actualChanges.put(feeOnMonthDayParamName, actualValueEntered);
            actualChanges.put(localeParamName, localeAsInput);
            this.feeOnDay = dayOfMonthValue;
        }

        final Integer monthOfYear = monthDay.getMonthOfYear();
        if (this.feeOnMonth != monthOfYear) {
            actualChanges.put(feeOnMonthDayParamName, actualValueEntered);
            actualChanges.put(localeParamName, localeAsInput);
            this.feeOnMonth = monthOfYear;
        }
    }

    if (command.isChangeInBigDecimalParameterNamed(amountParamName, this.amount)) {
        final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(amountParamName);
        actualChanges.put(amountParamName, newValue);
        actualChanges.put(localeParamName, localeAsInput);
        switch (ChargeCalculationType.fromInt(this.chargeCalculation)) {
        case INVALID:
            break;
        case FLAT:
            this.amount = newValue;
            this.amountOutstanding = calculateOutstanding();
            break;
        case PERCENT_OF_AMOUNT:
            this.percentage = newValue;
            this.amountPercentageAppliedTo = null;
            this.amount = percentageOf(this.amountPercentageAppliedTo, this.percentage);
            this.amountOutstanding = calculateOutstanding();
            break;
        case PERCENT_OF_AMOUNT_AND_INTEREST:
            this.percentage = newValue;
            this.amount = null;
            this.amountPercentageAppliedTo = null;
            this.amountOutstanding = null;
            break;
        case PERCENT_OF_INTEREST:
            this.percentage = newValue;
            this.amount = null;
            this.amountPercentageAppliedTo = null;
            this.amountOutstanding = null;
            break;
        }
    }

    return actualChanges;
}