Example usage for org.joda.time LocalDate LocalDate

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

Introduction

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

Prototype

public LocalDate(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

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

License:Apache License

protected LocalDate getSubmittedOnLocalDate() {
    LocalDate submittedOn = null;
    if (this.submittedOnDate != null) {
        submittedOn = new LocalDate(this.submittedOnDate);
    }//from www . ja  v a2 s .  c  o m
    return submittedOn;
}

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

License:Apache License

private LocalDate getApprovedOnLocalDate() {
    LocalDate approvedOnLocalDate = null;
    if (this.approvedOnDate != null) {
        approvedOnLocalDate = new LocalDate(this.approvedOnDate);
    }/* w  w  w. j  a  va  2  s  .c  om*/
    return approvedOnLocalDate;
}

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

License:Apache License

public LocalDate getClosedOnDate() {
    return (LocalDate) ObjectUtils.defaultIfNull(new LocalDate(this.closedOnDate), null);
}

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  . j  a v a 2s  . 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.domain.SavingsAccountCharge.java

License:Apache License

public void updateNextDueDateForRecurringFees() {
    if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) {
        LocalDate nextDueLocalDate = new LocalDate(dueDate);
        nextDueLocalDate = calculateNextDueDate(nextDueLocalDate);
        this.dueDate = nextDueLocalDate.toDate();
    }/*from  w w  w . j a v  a2 s  .  c o m*/
}

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

License:Apache License

public void updateToPreviousDueDate() {
    if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) {
        LocalDate nextDueLocalDate = new LocalDate(dueDate);
        if (isAnnualFee()) {
            nextDueLocalDate = nextDueLocalDate.withMonthOfYear(this.feeOnMonth).minusYears(1);
            nextDueLocalDate = setDayOfMonth(nextDueLocalDate);
        } else if (isMonthlyFee()) {
            nextDueLocalDate = nextDueLocalDate.minusMonths(this.feeInterval);
            nextDueLocalDate = setDayOfMonth(nextDueLocalDate);
        } else if (isWeeklyFee()) {
            nextDueLocalDate = nextDueLocalDate.minusDays(7 * this.feeInterval);
            nextDueLocalDate = setDayOfWeek(nextDueLocalDate);
        }//from ww w  . j  a v a 2s . co  m

        this.dueDate = nextDueLocalDate.toDate();
    }
}

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

License:Apache License

public LocalDate transactionLocalDate() {
    return new LocalDate(this.dateOf);
}

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

License:Apache License

public LocalDate getTransactionLocalDate() {
    return new LocalDate(this.dateOf);
}

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

License:Apache License

private LocalDate getEndOfBalanceLocalDate() {
    LocalDate endDate = null;//from ww w  .  ja  v a  2  s .  c  om
    if (this.balanceEndDate != null) {
        endDate = new LocalDate(this.balanceEndDate);
    }
    return endDate;
}

From source file:com.gst.portfolio.shareaccounts.serialization.ShareAccountDataSerializer.java

License:Apache License

@SuppressWarnings("null")
public Map<String, Object> validateAndApprove(JsonCommand jsonCommand, ShareAccount account) {
    Map<String, Object> actualChanges = new HashMap<>();
    if (StringUtils.isBlank(jsonCommand.json())) {
        throw new InvalidJsonException();
    }//from w  ww . jav  a 2s.  c  o  m
    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(),
            ShareAccountApiConstants.approvalParameters);
    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource("sharesaccount");
    JsonElement element = jsonCommand.parsedJson();
    if (!account.status().equals(ShareAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.getValue())) {
        baseDataValidator.failWithCodeNoParameterAddedToErrorCode("is.not.pending.for.approval");
    }
    LocalDate approvedDate = this.fromApiJsonHelper
            .extractLocalDateNamed(ShareAccountApiConstants.approveddate_paramname, element);
    final LocalDate submittalDate = new LocalDate(account.getSubmittedDate());
    if (approvedDate != null && approvedDate.isBefore(submittalDate)) {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(jsonCommand.dateFormat())
                .withLocale(jsonCommand.extractLocale());
        final String submittalDateAsString = formatter.print(submittalDate);
        baseDataValidator.reset().parameter(ShareAccountApiConstants.approveddate_paramname)
                .value(submittalDateAsString)
                .failWithCodeNoParameterAddedToErrorCode("approved.date.cannot.be.before.submitted.date");
    }

    Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions();
    for (ShareAccountTransaction transaction : transactions) {
        if (transaction.isActive() && transaction.isPendingForApprovalTransaction()) {
            validateTotalSubsribedShares(account, transaction, baseDataValidator);
        }
    }

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

    AppUser approvedUser = this.platformSecurityContext.authenticatedUser();
    account.approve(approvedDate.toDate(), approvedUser);
    actualChanges.put(ShareAccountApiConstants.id_paramname, account.getId());
    updateTotalChargeDerived(account);
    return actualChanges;
}