Example usage for org.joda.time.format DateTimeFormat forPattern

List of usage examples for org.joda.time.format DateTimeFormat forPattern

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormat forPattern.

Prototype

public static DateTimeFormatter forPattern(String pattern) 

Source Link

Document

Factory to create a formatter from a pattern string.

Usage

From source file:com.gst.portfolio.loanaccount.service.LoanWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

public LoanTransaction disburseLoanAmountToSavings(final Long loanId, Long loanChargeId,
        final JsonCommand command, final boolean isChargeIdIncludedInJson) {

    LoanTransaction transaction = null;/* w  ww. j  av  a2 s. c o m*/

    this.loanEventApiJsonValidator.validateChargePaymentTransaction(command.json(), isChargeIdIncludedInJson);
    if (isChargeIdIncludedInJson) {
        loanChargeId = command.longValueOfParameterNamed("chargeId");
    }
    final Loan loan = this.loanAssembler.assembleFrom(loanId);
    checkClientOrGroupActive(loan);
    final LoanCharge loanCharge = retrieveLoanChargeBy(loanId, loanChargeId);

    // Charges may be waived only when the loan associated with them are
    // active
    if (!loan.status().isActive()) {
        throw new LoanChargeCannotBePayedException(LOAN_CHARGE_CANNOT_BE_PAYED_REASON.LOAN_INACTIVE,
                loanCharge.getId());
    }

    // validate loan charge is not already paid or waived
    if (loanCharge.isWaived()) {
        throw new LoanChargeCannotBePayedException(LOAN_CHARGE_CANNOT_BE_PAYED_REASON.ALREADY_WAIVED,
                loanCharge.getId());
    } else if (loanCharge.isPaid()) {
        throw new LoanChargeCannotBePayedException(LOAN_CHARGE_CANNOT_BE_PAYED_REASON.ALREADY_PAID,
                loanCharge.getId());
    }

    if (!loanCharge.getChargePaymentMode().isPaymentModeAccountTransfer()) {
        throw new LoanChargeCannotBePayedException(
                LOAN_CHARGE_CANNOT_BE_PAYED_REASON.CHARGE_NOT_ACCOUNT_TRANSFER, loanCharge.getId());
    }

    final LocalDate transactionDate = command.localDateValueOfParameterNamed("transactionDate");

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    Integer loanInstallmentNumber = null;
    BigDecimal amount = loanCharge.amountOutstanding();
    if (loanCharge.isInstalmentFee()) {
        LoanInstallmentCharge chargePerInstallment = null;
        final LocalDate dueDate = command.localDateValueOfParameterNamed("dueDate");
        final Integer installmentNumber = command.integerValueOfParameterNamed("installmentNumber");
        if (dueDate != null) {
            chargePerInstallment = loanCharge.getInstallmentLoanCharge(dueDate);
        } else if (installmentNumber != null) {
            chargePerInstallment = loanCharge.getInstallmentLoanCharge(installmentNumber);
        }
        if (chargePerInstallment == null) {
            chargePerInstallment = loanCharge.getUnpaidInstallmentLoanCharge();
        }
        if (chargePerInstallment.isWaived()) {
            throw new LoanChargeCannotBePayedException(LOAN_CHARGE_CANNOT_BE_PAYED_REASON.ALREADY_WAIVED,
                    loanCharge.getId());
        } else if (chargePerInstallment.isPaid()) {
            throw new LoanChargeCannotBePayedException(LOAN_CHARGE_CANNOT_BE_PAYED_REASON.ALREADY_PAID,
                    loanCharge.getId());
        }
        loanInstallmentNumber = chargePerInstallment.getRepaymentInstallment().getInstallmentNumber();
        amount = chargePerInstallment.getAmountOutstanding();
    }

    final PortfolioAccountData portfolioAccountData = this.accountAssociationsReadPlatformService
            .retriveLoanLinkedAssociation(loanId);
    if (portfolioAccountData == null) {
        final String errorMessage = "Charge with id:" + loanChargeId
                + " requires linked savings account for payment";
        throw new LinkedAccountRequiredException("loanCharge.pay", errorMessage, loanChargeId);
    }
    final SavingsAccount fromSavingsAccount = null;
    final boolean isRegularTransaction = true;
    final boolean isExceptionForBalanceCheck = false;
    final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, amount,
            PortfolioAccountType.SAVINGS, PortfolioAccountType.LOAN, portfolioAccountData.accountId(), loanId,
            "Loan Charge Payment", locale, fmt, null, null, LoanTransactionType.CHARGE_PAYMENT.getValue(),
            loanChargeId, loanInstallmentNumber, AccountTransferType.CHARGE_PAYMENT.getValue(), null, null,
            null, null, null, fromSavingsAccount, isRegularTransaction, isExceptionForBalanceCheck);
    this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO);

    return transaction;
}

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

License:Apache License

public Collection<SavingsAccountTransactionDTO> assembleBulkMandatorySavingsAccountTransactionDTOs(
        final JsonCommand command, final PaymentDetail paymentDetail) {
    AppUser user = getAppUserIfPresent();
    final String json = command.json();
    if (StringUtils.isBlank(json)) {
        throw new InvalidJsonException();
    }/*from  w  ww  . j  a  v  a2  s . c  o m*/
    final JsonElement element = this.fromApiJsonHelper.parse(json);
    final Collection<SavingsAccountTransactionDTO> savingsAccountTransactions = new ArrayList<>();
    final LocalDate transactionDate = this.fromApiJsonHelper.extractLocalDateNamed(transactionDateParamName,
            element);
    final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(element.getAsJsonObject());
    final JsonObject topLevelJsonElement = element.getAsJsonObject();
    final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
    final DateTimeFormatter formatter = DateTimeFormat.forPattern(dateFormat).withLocale(locale);

    if (element.isJsonObject()) {
        if (topLevelJsonElement.has(bulkSavingsDueTransactionsParamName)
                && topLevelJsonElement.get(bulkSavingsDueTransactionsParamName).isJsonArray()) {
            final JsonArray array = topLevelJsonElement.get(bulkSavingsDueTransactionsParamName)
                    .getAsJsonArray();

            for (int i = 0; i < array.size(); i++) {
                final JsonObject savingsTransactionElement = array.get(i).getAsJsonObject();
                final Long savingsId = this.fromApiJsonHelper.extractLongNamed(savingsIdParamName,
                        savingsTransactionElement);
                final BigDecimal dueAmount = this.fromApiJsonHelper
                        .extractBigDecimalNamed(transactionAmountParamName, savingsTransactionElement, locale);
                PaymentDetail detail = paymentDetail;
                if (paymentDetail == null) {
                    detail = this.paymentDetailAssembler.fetchPaymentDetail(savingsTransactionElement);
                }
                final SavingsAccountTransactionDTO savingsAccountTransactionDTO = new SavingsAccountTransactionDTO(
                        formatter, transactionDate, dueAmount, detail, new Date(), savingsId, user);
                savingsAccountTransactions.add(savingsAccountTransactionDTO);
            }
        }
    }

    return savingsAccountTransactions;
}

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

License:Apache License

@Transactional
@Override//from ww  w .j  a  va2s  .co  m
public Long handleFDAccountClosure(final FixedDepositAccount account, final PaymentDetail paymentDetail,
        final AppUser user, final JsonCommand command, final LocalDate tenantsTodayDate,
        final Map<String, Object> changes) {

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();

    boolean isRegularTransaction = false;
    boolean isAccountTransfer = false;
    final boolean isPreMatureClosure = false;
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    /***
     * Update account transactionIds for post journal entries.
     */
    updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
    /*
     * <<<<<<< HEAD final SavingsAccountTransactionDTO transactionDTO = new
     * SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount,
     * paymentDetail, new Date()); final SavingsAccountTransaction deposit =
     * account.deposit(transactionDTO); boolean isInterestTransfer = false;
     * final MathContext mc = MathContext.DECIMAL64; if
     * (account.isBeforeLastPostingPeriod(transactionDate)) { final
     * LocalDate today = DateUtils.getLocalDateOfTenant();
     * account.postInterest(mc, today, isInterestTransfer); } else { final
     * LocalDate today = DateUtils.getLocalDateOfTenant();
     * account.calculateInterestUsing(mc, today, isInterestTransfer);
     * =======
     */
    final MathContext mc = MathContext.DECIMAL64;
    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate closedDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);
    Long savingsTransactionId = null;
    account.postMaturityInterest(isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
    final Integer onAccountClosureId = command.integerValueOfParameterNamed(onAccountClosureIdParamName);
    final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType.fromInt(onAccountClosureId);
    if (onClosureType.isReinvest()) {
        FixedDepositAccount reinvestedDeposit = account.reInvest(account.getAccountBalance());
        this.depositAccountAssembler.assignSavingAccountHelpers(reinvestedDeposit);
        reinvestedDeposit.updateMaturityDateAndAmountBeforeAccountActivation(mc, isPreMatureClosure,
                isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
        this.savingsAccountRepository.save(reinvestedDeposit);
        autoGenerateAccountNumber(reinvestedDeposit);
        final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate,
                account.getAccountBalance(), paymentDetail, false, isRegularTransaction);
        savingsTransactionId = withdrawal.getId();
    } else if (onClosureType.isTransferToSavings()) {
        final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName);
        final String transferDescription = command.stringValueOfParameterNamed(transferDescriptionParamName);
        final SavingsAccount toSavingsAccount = this.depositAccountAssembler.assembleFrom(toSavingsId,
                DepositAccountType.SAVINGS_DEPOSIT);
        final boolean isExceptionForBalanceCheck = false;
        final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(closedDate,
                account.getAccountBalance(), PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS, null,
                null, transferDescription, locale, fmt, null, null, null, null, null,
                AccountTransferType.ACCOUNT_TRANSFER.getValue(), null, null, null, null, toSavingsAccount,
                account, isAccountTransfer, isExceptionForBalanceCheck);
        this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO);
        updateAlreadyPostedTransactions(existingTransactionIds, account);
    } else {
        final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate,
                account.getAccountBalance(), paymentDetail, false, isRegularTransaction);
        savingsTransactionId = withdrawal.getId();
    }

    account.close(user, command, tenantsTodayDate, changes);
    this.savingsAccountRepository.save(account);

    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds, isAccountTransfer);

    return savingsTransactionId;
}

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

License:Apache License

@Transactional
@Override/*from  w  w  w.  j a  v  a2 s .  c  om*/
public Long handleRDAccountClosure(final RecurringDepositAccount account, final PaymentDetail paymentDetail,
        final AppUser user, final JsonCommand command, final LocalDate tenantsTodayDate,
        final Map<String, Object> changes) {

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();

    boolean isRegularTransaction = false;
    boolean isAccountTransfer = false;
    final boolean isPreMatureClosure = false;
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    /***
     * Update account transactionIds for post journal entries.
     */
    updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);

    final MathContext mc = MathContext.DECIMAL64;
    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate closedDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);
    Long savingsTransactionId = null;
    account.postMaturityInterest(isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth,
            closedDate);
    final BigDecimal transactionAmount = account.getAccountBalance();
    final Integer onAccountClosureId = command.integerValueOfParameterNamed(onAccountClosureIdParamName);
    final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType.fromInt(onAccountClosureId);
    if (onClosureType.isReinvest()) {
        RecurringDepositAccount reinvestedDeposit = account.reInvest(transactionAmount);
        depositAccountAssembler.assignSavingAccountHelpers(reinvestedDeposit);
        this.savingsAccountRepository.save(reinvestedDeposit);
        final CalendarInstance calendarInstance = getCalendarInstance(account, reinvestedDeposit);
        this.calendarInstanceRepository.save(calendarInstance);
        final Calendar calendar = calendarInstance.getCalendar();
        final PeriodFrequencyType frequencyType = CalendarFrequencyType
                .from(CalendarUtils.getFrequency(calendar.getRecurrence()));
        Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence());
        frequency = frequency == -1 ? 1 : frequency;
        reinvestedDeposit.generateSchedule(frequencyType, frequency, calendar);
        reinvestedDeposit.processAccountUponActivation(fmt, user);
        reinvestedDeposit.updateMaturityDateAndAmount(mc, isPreMatureClosure,
                isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
        this.savingsAccountRepository.save(reinvestedDeposit);
        autoGenerateAccountNumber(reinvestedDeposit);

        final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate,
                account.getAccountBalance(), paymentDetail, false, isRegularTransaction);
        savingsTransactionId = withdrawal.getId();

    } else if (onClosureType.isTransferToSavings()) {
        final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName);
        final String transferDescription = command.stringValueOfParameterNamed(transferDescriptionParamName);
        final SavingsAccount toSavingsAccount = this.depositAccountAssembler.assembleFrom(toSavingsId,
                DepositAccountType.SAVINGS_DEPOSIT);
        final boolean isExceptionForBalanceCheck = false;
        final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(closedDate, transactionAmount,
                PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS, null, null, transferDescription,
                locale, fmt, null, null, null, null, null, AccountTransferType.ACCOUNT_TRANSFER.getValue(),
                null, null, null, null, toSavingsAccount, account, isRegularTransaction,
                isExceptionForBalanceCheck);
        this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO);
        updateAlreadyPostedTransactions(existingTransactionIds, account);
    } else {
        final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate,
                account.getAccountBalance(), paymentDetail, false, isRegularTransaction);
        savingsTransactionId = withdrawal.getId();
    }

    account.close(user, command, tenantsTodayDate, changes);

    this.savingsAccountRepository.save(account);

    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds, isAccountTransfer);

    return savingsTransactionId;
}

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

License:Apache License

@Transactional
@Override/*from   w ww  . j  av  a 2  s.  c o  m*/
public Long handleFDAccountPreMatureClosure(final FixedDepositAccount account,
        final PaymentDetail paymentDetail, final AppUser user, final JsonCommand command,
        final LocalDate tenantsTodayDate, final Map<String, Object> changes) {

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();

    boolean isAccountTransfer = false;
    boolean isRegularTransaction = false;
    final boolean isPreMatureClosure = true;
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    /***
     * Update account transactionIds for post journal entries.
     */
    updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);

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

    // post interest
    account.postPreMaturityInterest(closedDate, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd,
            financialYearBeginningMonth);

    final Integer closureTypeValue = command
            .integerValueOfParameterNamed(DepositsApiConstants.onAccountClosureIdParamName);
    DepositAccountOnClosureType closureType = DepositAccountOnClosureType.fromInt(closureTypeValue);

    if (closureType.isTransferToSavings()) {
        final boolean isExceptionForBalanceCheck = false;
        final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName);
        final String transferDescription = command.stringValueOfParameterNamed(transferDescriptionParamName);
        final SavingsAccount toSavingsAccount = this.depositAccountAssembler.assembleFrom(toSavingsId,
                DepositAccountType.SAVINGS_DEPOSIT);
        final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(closedDate,
                account.getAccountBalance(), PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS, null,
                null, transferDescription, locale, fmt, null, null, null, null, null,
                AccountTransferType.ACCOUNT_TRANSFER.getValue(), null, null, null, null, toSavingsAccount,
                account, isRegularTransaction, isExceptionForBalanceCheck);
        this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO);
        updateAlreadyPostedTransactions(existingTransactionIds, account);
    } else {
        final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate,
                account.getAccountBalance(), paymentDetail, false, isRegularTransaction);
        savingsTransactionId = withdrawal.getId();
    }

    account.prematureClosure(user, command, tenantsTodayDate, changes);

    this.savingsAccountRepository.save(account);

    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds, isAccountTransfer);
    return savingsTransactionId;
}

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

License:Apache License

@Transactional
@Override//  ww  w.jav a 2 s .com
public Long handleRDAccountPreMatureClosure(final RecurringDepositAccount account,
        final PaymentDetail paymentDetail, final AppUser user, final JsonCommand command,
        final LocalDate tenantsTodayDate, final Map<String, Object> changes) {

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();

    boolean isAccountTransfer = false;
    final boolean isPreMatureClosure = true;
    boolean isRegularTransaction = false;
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    /***
     * Update account transactionIds for post journal entries.
     */
    updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);

    final LocalDate closedDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);
    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    Long savingsTransactionId = null;
    // post interest
    account.postPreMaturityInterest(closedDate, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd,
            financialYearBeginningMonth);

    final Integer closureTypeValue = command
            .integerValueOfParameterNamed(DepositsApiConstants.onAccountClosureIdParamName);
    DepositAccountOnClosureType closureType = DepositAccountOnClosureType.fromInt(closureTypeValue);

    if (closureType.isTransferToSavings()) {
        final boolean isExceptionForBalanceCheck = false;
        final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName);
        final String transferDescription = command.stringValueOfParameterNamed(transferDescriptionParamName);
        final SavingsAccount toSavingsAccount = this.depositAccountAssembler.assembleFrom(toSavingsId,
                DepositAccountType.SAVINGS_DEPOSIT);
        final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(closedDate,
                account.getAccountBalance(), PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS, null,
                null, transferDescription, locale, fmt, null, null, null, null, null,
                AccountTransferType.ACCOUNT_TRANSFER.getValue(), null, null, null, null, toSavingsAccount,
                account, isRegularTransaction, isExceptionForBalanceCheck);
        this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO);
        updateAlreadyPostedTransactions(existingTransactionIds, account);
    } else {
        final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate,
                account.getAccountBalance(), paymentDetail, false, isRegularTransaction);
        savingsTransactionId = withdrawal.getId();
    }

    account.prematureClosure(user, command, tenantsTodayDate, changes);
    this.savingsAccountRepository.save(account);
    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds, isAccountTransfer);
    return savingsTransactionId;
}

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  w w  w  .ja  v  a2 s .  com
    }

    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);
        }/*from   w w  w .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 (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  .j  a va 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 (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);
        }// ww w  .j  a va  2 s  . 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 (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);
}