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.shareaccounts.serialization.ShareAccountDataSerializer.java

License:Apache License

@SuppressWarnings("null")
public Map<String, Object> validateAndActivate(JsonCommand jsonCommand, ShareAccount account) {
    Map<String, Object> actualChanges = new HashMap<>();
    if (StringUtils.isBlank(jsonCommand.json())) {
        throw new InvalidJsonException();
    }/*from ww w.ja  v  a 2  s.  c o m*/
    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(),
            ShareAccountApiConstants.activateParameters);
    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource("sharesaccount");
    JsonElement element = jsonCommand.parsedJson();
    if (!account.status().equals(ShareAccountStatusType.APPROVED.getValue())) {
        baseDataValidator.failWithCodeNoParameterAddedToErrorCode("is.not.in.approved.status");
    }
    LocalDate activatedDate = this.fromApiJsonHelper
            .extractLocalDateNamed(ShareAccountApiConstants.activatedate_paramname, element);
    baseDataValidator.reset().parameter(ShareAccountApiConstants.activatedate_paramname).value(activatedDate)
            .notNull();
    final LocalDate approvedDate = new LocalDate(account.getApprovedDate());
    if (activatedDate != null && activatedDate.isBefore(approvedDate)) {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(jsonCommand.dateFormat())
                .withLocale(jsonCommand.extractLocale());
        final String submittalDateAsString = formatter.print(approvedDate);
        baseDataValidator.reset().parameter(ShareAccountApiConstants.activatedate_paramname)
                .value(submittalDateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.approved.date");
    }
    if (!dataValidationErrors.isEmpty()) {
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }
    AppUser approvedUser = this.platformSecurityContext.authenticatedUser();
    account.activate(activatedDate.toDate(), approvedUser);
    handlechargesOnActivation(account);
    actualChanges.put(ShareAccountApiConstants.charges_paramname, activatedDate.toDate());
    return actualChanges;
}

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

License:Apache License

public Map<String, Object> validateAndApplyAddtionalShares(JsonCommand jsonCommand, ShareAccount account) {
    Map<String, Object> actualChanges = new HashMap<>();
    if (StringUtils.isBlank(jsonCommand.json())) {
        throw new InvalidJsonException();
    }/*from  ww  w  . ja va2s.  co m*/
    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(),
            ShareAccountApiConstants.addtionalSharesParameters);
    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource("sharesaccount");
    JsonElement element = jsonCommand.parsedJson();
    if (!account.status().equals(ShareAccountStatusType.ACTIVE.getValue())) {
        baseDataValidator.failWithCodeNoParameterAddedToErrorCode("is.not.in.active.state");
    }
    LocalDate requestedDate = this.fromApiJsonHelper
            .extractLocalDateNamed(ShareAccountApiConstants.requesteddate_paramname, element);
    baseDataValidator.reset().parameter(ShareAccountApiConstants.requesteddate_paramname).value(requestedDate)
            .notNull();
    final Long sharesRequested = this.fromApiJsonHelper
            .extractLongNamed(ShareAccountApiConstants.requestedshares_paramname, element);
    baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname)
            .value(sharesRequested).notNull();
    ShareProduct shareProduct = account.getShareProduct();
    if (sharesRequested != null) {
        Long totalSharesAfterapproval = account.getTotalApprovedShares() + sharesRequested;
        if (shareProduct.getMaximumClientShares() != null
                && totalSharesAfterapproval > shareProduct.getMaximumClientShares()) {
            baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname)
                    .value(sharesRequested).failWithCode("exceeding.maximum.limit.defined.in.the.shareproduct",
                            "Existing and requested shares count is more than product definition");
        }
    }
    boolean isTransactionBeforeExistingTransactions = false;
    Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions();
    for (ShareAccountTransaction transaction : transactions) {
        if (!transaction.isChargeTransaction()) {
            LocalDate transactionDate = new LocalDate(transaction.getPurchasedDate());
            if (requestedDate.isBefore(transactionDate)) {
                isTransactionBeforeExistingTransactions = true;
                break;
            }
        }
    }
    if (isTransactionBeforeExistingTransactions) {
        baseDataValidator.reset().parameter(ShareAccountApiConstants.requesteddate_paramname)
                .value(requestedDate).failWithCodeNoParameterAddedToErrorCode(
                        "purchase.transaction.date.cannot.be.before.existing.transactions");
    }

    if (!dataValidationErrors.isEmpty()) {
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }
    final BigDecimal unitPrice = shareProduct.deriveMarketPrice(requestedDate.toDate());
    ShareAccountTransaction purchaseTransaction = new ShareAccountTransaction(requestedDate.toDate(),
            sharesRequested, unitPrice);
    account.addAdditionalPurchasedShares(purchaseTransaction);
    handleAdditionalSharesChargeTransactions(account, purchaseTransaction);
    actualChanges.put(ShareAccountApiConstants.additionalshares_paramname, purchaseTransaction);
    return actualChanges;
}

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

License:Apache License

public Map<String, Object> validateAndRedeemShares(JsonCommand jsonCommand, ShareAccount account) {
    Map<String, Object> actualChanges = new HashMap<>();
    if (StringUtils.isBlank(jsonCommand.json())) {
        throw new InvalidJsonException();
    }//from  w w  w.  j a  va2  s  . com
    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(),
            ShareAccountApiConstants.addtionalSharesParameters);
    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource("sharesaccount");
    JsonElement element = jsonCommand.parsedJson();
    LocalDate requestedDate = this.fromApiJsonHelper
            .extractLocalDateNamed(ShareAccountApiConstants.requesteddate_paramname, element);
    baseDataValidator.reset().parameter(ShareAccountApiConstants.requesteddate_paramname).value(requestedDate)
            .notNull();
    final Long sharesRequested = this.fromApiJsonHelper
            .extractLongNamed(ShareAccountApiConstants.requestedshares_paramname, element);
    baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname)
            .value(sharesRequested).notNull().longGreaterThanZero();
    boolean isTransactionBeforeExistingTransactions = false;
    Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions();
    for (ShareAccountTransaction transaction : transactions) {
        if (!transaction.isChargeTransaction() && transaction.isActive()) {
            LocalDate transactionDate = new LocalDate(transaction.getPurchasedDate());
            if (requestedDate.isBefore(transactionDate)) {
                isTransactionBeforeExistingTransactions = true;
                break;
            }
        }
    }
    if (isTransactionBeforeExistingTransactions) {
        baseDataValidator.reset().parameter(ShareAccountApiConstants.requesteddate_paramname)
                .value(requestedDate).failWithCodeNoParameterAddedToErrorCode(
                        "redeem.transaction.date.cannot.be.before.existing.transactions");
    }
    if (!dataValidationErrors.isEmpty()) {
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }
    BigDecimal unitPrice = account.getShareProduct().deriveMarketPrice(requestedDate.toDate());
    ShareAccountTransaction transaction = ShareAccountTransaction
            .createRedeemTransaction(requestedDate.toDate(), sharesRequested, unitPrice);
    validateRedeemRequest(account, transaction, baseDataValidator, dataValidationErrors);
    account.addAdditionalPurchasedShares(transaction);
    actualChanges.put(ShareAccountApiConstants.requestedshares_paramname, transaction);

    handleRedeemSharesChargeTransactions(account, transaction);
    return actualChanges;
}

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

License:Apache License

public Map<String, Object> validateAndClose(JsonCommand jsonCommand, ShareAccount account) {
    Map<String, Object> actualChanges = new HashMap<>();
    if (StringUtils.isBlank(jsonCommand.json())) {
        throw new InvalidJsonException();
    }/*from  www .  java  2 s.  c om*/
    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(),
            ShareAccountApiConstants.closeParameters);
    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource("sharesaccount");
    JsonElement element = jsonCommand.parsedJson();
    LocalDate closedDate = this.fromApiJsonHelper
            .extractLocalDateNamed(ShareAccountApiConstants.closeddate_paramname, element);
    baseDataValidator.reset().parameter(ShareAccountApiConstants.approveddate_paramname).value(closedDate)
            .notNull();
    if (!dataValidationErrors.isEmpty()) {
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }
    boolean isTransactionBeforeExistingTransactions = false;
    Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions();
    for (ShareAccountTransaction transaction : transactions) {
        if (!transaction.isChargeTransaction()) {
            LocalDate transactionDate = new LocalDate(transaction.getPurchasedDate());
            if (closedDate.isBefore(transactionDate)) {
                isTransactionBeforeExistingTransactions = true;
                break;
            }
        }
    }
    if (isTransactionBeforeExistingTransactions) {
        baseDataValidator.reset().parameter(ShareAccountApiConstants.closeddate_paramname).value(closedDate)
                .failWithCodeNoParameterAddedToErrorCode(
                        "share.account.cannot.be.closed.before.existing.transactions");
    }

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

    AppUser approvedUser = this.platformSecurityContext.authenticatedUser();
    final BigDecimal unitPrice = account.getShareProduct().deriveMarketPrice(DateUtils.getDateOfTenant());
    ShareAccountTransaction transaction = ShareAccountTransaction.createRedeemTransaction(closedDate.toDate(),
            account.getTotalApprovedShares(), unitPrice);
    account.addAdditionalPurchasedShares(transaction);
    account.close(closedDate.toDate(), approvedUser);
    handleRedeemSharesChargeTransactions(account, transaction);
    actualChanges.put(ShareAccountApiConstants.requestedshares_paramname, transaction);
    return actualChanges;
}

From source file:com.gst.portfolio.shareproducts.serialization.ShareProductDataSerializer.java

License:Apache License

private Set<ShareProductMarketPriceData> asembleShareMarketPriceForUpdate(final JsonElement element) {
    Set<ShareProductMarketPriceData> set = null;
    if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.marketprice_paramname, element)) {
        set = new HashSet<>();
        JsonArray array = this.fromApiJsonHelper
                .extractJsonArrayNamed(ShareProductApiConstants.marketprice_paramname, element);
        for (JsonElement arrayElement : array) {
            Long id = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.id_paramname,
                    arrayElement);/*  w  w  w  .  j av  a  2s  .  c  o m*/
            LocalDate localDate = this.fromApiJsonHelper
                    .extractLocalDateNamed(ShareProductApiConstants.startdate_paramname, arrayElement);
            final BigDecimal shareValue = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(
                    ShareProductApiConstants.sharevalue_paramname, arrayElement);
            ShareProductMarketPriceData obj = new ShareProductMarketPriceData(id, localDate.toDate(),
                    shareValue);
            set.add(obj);
        }
    }
    return set;
}

From source file:com.gst.portfolio.shareproducts.serialization.ShareProductDataSerializer.java

License:Apache License

private Set<ShareProductMarketPrice> asembleShareMarketPrice(final JsonElement element) {
    Set<ShareProductMarketPrice> set = new HashSet<>();
    if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.marketprice_paramname, element)) {
        set = new HashSet<>();
        JsonArray array = this.fromApiJsonHelper
                .extractJsonArrayNamed(ShareProductApiConstants.marketprice_paramname, element);
        for (JsonElement arrayElement : array) {
            LocalDate localDate = this.fromApiJsonHelper
                    .extractLocalDateNamed(ShareProductApiConstants.startdate_paramname, arrayElement);
            final BigDecimal shareValue = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(
                    ShareProductApiConstants.sharevalue_paramname, arrayElement);
            ShareProductMarketPrice obj = new ShareProductMarketPrice(localDate.toDate(), shareValue);
            set.add(obj);/*ww  w .  ja v  a2s  .  c  om*/
        }
    }
    return set;
}

From source file:com.gst.portfolio.shareproducts.service.ShareProductDividendAssembler.java

License:Apache License

public ShareProductDividendPayOutDetails calculateDividends(final Long productId, final BigDecimal amount,
        final LocalDate dividendPeriodStartDate, final LocalDate dividendPeriodEndDate) {

    ShareProductData product = (ShareProductData) this.shareProductReadPlatformService.retrieveOne(productId,
            false);/*from ww w.j a  va2  s.  co  m*/
    MonetaryCurrency currency = new MonetaryCurrency(product.getCurrency().code(),
            product.getCurrency().decimalPlaces(), product.getCurrency().currencyInMultiplesOf());
    Collection<ShareAccountData> shareAccountDatas = this.ShareAccountReadPlatformService
            .retrieveAllShareAccountDataForDividends(productId,
                    product.getAllowDividendCalculationForInactiveClients(), dividendPeriodStartDate);
    if (shareAccountDatas == null || shareAccountDatas.isEmpty()) {
        throw new ShareAccountsNotFoundException(product.getId());
    }

    ShareProductDividendPayOutDetails productDividendPayOutDetails = null;
    int minimumActivePeriod = 0;
    if (product.getMinimumActivePeriod() != null) { //minimum active period may be null 
        minimumActivePeriod = product.getMinimumActivePeriod();
    }
    final Map<Long, Long> numberOfSharesdaysPerAccount = new HashMap<>();
    long numberOfShareDays = calculateNumberOfShareDays(dividendPeriodEndDate, dividendPeriodStartDate,
            minimumActivePeriod, shareAccountDatas, numberOfSharesdaysPerAccount);

    if (numberOfShareDays > 0) {
        double amountPerShareDay = amount.doubleValue() / numberOfShareDays;
        productDividendPayOutDetails = new ShareProductDividendPayOutDetails(productId,
                Money.of(currency, amount).getAmount(), dividendPeriodStartDate.toDate(),
                dividendPeriodEndDate.toDate());
        for (ShareAccountData accountData : shareAccountDatas) {
            long numberOfShareDaysPerAccount = numberOfSharesdaysPerAccount.get(accountData.getId());
            double amountForAccount = numberOfShareDaysPerAccount * amountPerShareDay;
            final Money accountAmount = Money.of(currency, BigDecimal.valueOf(amountForAccount));
            ShareAccountDividendDetails dividendDetails = new ShareAccountDividendDetails(accountData.getId(),
                    accountAmount.getAmount());
            productDividendPayOutDetails.getAccountDividendDetails().add(dividendDetails);
        }
    }

    return productDividendPayOutDetails;
}

From source file:com.gst.portfolio.tax.domain.TaxComponent.java

License:Apache License

private TaxComponent(final String name, final BigDecimal percentage, final GLAccountType debitAccountType,
        final GLAccount debitAcount, final GLAccountType creditAccountType, final GLAccount creditAcount,
        final LocalDate startDate) {
    this.name = name;
    this.percentage = percentage;
    if (debitAccountType != null) {
        this.debitAccountType = debitAccountType.getValue();
    }// w  ww. j av a2 s.co m
    this.debitAcount = debitAcount;
    if (creditAccountType != null) {
        this.creditAccountType = creditAccountType.getValue();
    }
    this.creditAcount = creditAcount;
    this.startDate = startDate.toDate();
}

From source file:com.gst.portfolio.tax.domain.TaxComponent.java

License:Apache License

private void updateStartDate(final JsonCommand command, final Map<String, Object> changes,
        boolean setAsCurrentDate) {
    LocalDate startDate = DateUtils.getLocalDateOfTenant();
    if (command.parameterExists(TaxApiConstants.startDateParamName)) {
        LocalDate startDateFromUI = command.localDateValueOfParameterNamed(TaxApiConstants.startDateParamName);
        if (startDateFromUI != null) {
            startDate = startDateFromUI;
        }/*from  www. j  av  a 2 s  .c  om*/
        this.startDate = startDate.toDate();
        changes.put(TaxApiConstants.startDateParamName, startDate);
    } else if (setAsCurrentDate) {
        changes.put(TaxApiConstants.startDateParamName, startDate);
        this.startDate = startDate.toDate();
    }

}

From source file:com.gst.portfolio.tax.domain.TaxComponentHistory.java

License:Apache License

private TaxComponentHistory(final BigDecimal percentage, final LocalDate startDate, final LocalDate endDate) {
    this.percentage = percentage;
    this.startDate = startDate.toDate();
    this.endDate = endDate.toDate();
}