List of usage examples for org.joda.time LocalDate LocalDate
public LocalDate(Object instant)
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 w w w . j a v a2 s. com*/ 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 .jav a2 s . c o 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 ava 2 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
private void validateRedeemRequest(final ShareAccount account, ShareAccountTransaction redeemTransaction, final DataValidatorBuilder baseDataValidator, final List<ApiParameterError> dataValidationErrors) { if (account.getTotalApprovedShares() < redeemTransaction.getTotalShares()) { baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname) .value(redeemTransaction.getTotalShares()) .failWithCodeNoParameterAddedToErrorCode("cannot.be.redeemed.due.to.insufficient.shares"); }/*from w ww . ja va 2s . c om*/ if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } LocalDate redeemDate = new LocalDate(redeemTransaction.getPurchasedDate()); final Integer lockinPeriod = account.getLockinPeriodFrequency(); final PeriodFrequencyType periodType = account.getLockinPeriodFrequencyType(); if (lockinPeriod == null && periodType == null) { return; } Long totalSharesCanBeRedeemed = new Long(0); Long totalSharesPurchasedBeforeRedeem = new Long(0); boolean isPurchaseTransactionExist = false; Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions(); for (ShareAccountTransaction transaction : transactions) { if (transaction.isActive() && !transaction.isChargeTransaction()) { LocalDate purchaseDate = new LocalDate(transaction.getPurchasedDate()); LocalDate lockinDate = deriveLockinPeriodDuration(lockinPeriod, periodType, purchaseDate); if (!lockinDate.isAfter(redeemDate)) { if (transaction.isPurchasTransaction()) { totalSharesCanBeRedeemed += transaction.getTotalShares(); } else if (transaction.isRedeemTransaction()) { totalSharesCanBeRedeemed -= transaction.getTotalShares(); } } if (!purchaseDate.isAfter(redeemDate)) { isPurchaseTransactionExist = true; if (transaction.isPurchasTransaction()) { totalSharesPurchasedBeforeRedeem += transaction.getTotalShares(); } else if (transaction.isRedeemTransaction()) { totalSharesPurchasedBeforeRedeem -= transaction.getTotalShares(); } } } } if (!isPurchaseTransactionExist) { baseDataValidator.reset().parameter(ShareAccountApiConstants.requesteddate_paramname).value(redeemDate) .failWithCodeNoParameterAddedToErrorCode("no.purchase.transaction.found.before.redeem.date"); } else if (totalSharesPurchasedBeforeRedeem < redeemTransaction.getTotalShares()) { baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname) .value(redeemTransaction.getTotalShares()).failWithCodeNoParameterAddedToErrorCode( "cannot.be.redeemed.due.to.insufficient.shares.for.this.redeem.date"); } else if (totalSharesCanBeRedeemed < redeemTransaction.getTotalShares()) { baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname) .value(redeemTransaction.getTotalShares()) .failWithCodeNoParameterAddedToErrorCode("cannot.be.redeemed.due.to.lockinperiod"); } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } }
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 w ww . j a v a 2s .co m 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.shareaccounts.service.ShareAccountWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
private Map<String, Object> populateJournalEntries(final ShareAccount account, final Set<ShareAccountTransaction> transactions) { final Map<String, Object> accountingBridgeData = new HashMap<>(); Boolean cashBasedAccounting = account.getShareProduct().getAccountingType().intValue() == 2 ? Boolean.TRUE : Boolean.FALSE;//w w w .ja v a2s . co m accountingBridgeData.put("cashBasedAccountingEnabled", cashBasedAccounting); accountingBridgeData.put("accrualBasedAccountingEnabled", Boolean.FALSE); accountingBridgeData.put("shareAccountId", account.getId()); accountingBridgeData.put("shareProductId", account.getShareProduct().getId()); accountingBridgeData.put("officeId", account.getOfficeId()); MonetaryCurrency currency = account.getCurrency(); final CurrencyData currencyData = new CurrencyData(currency.getCode(), "", currency.getDigitsAfterDecimal(), currency.getCurrencyInMultiplesOf(), "", ""); accountingBridgeData.put("currency", currencyData); final List<Map<String, Object>> newTransactionsMap = new ArrayList<>(); accountingBridgeData.put("newTransactions", newTransactionsMap); for (ShareAccountTransaction transaction : transactions) { final Map<String, Object> transactionDto = new HashMap<>(); transactionDto.put("officeId", account.getOfficeId()); transactionDto.put("id", transaction.getId()); transactionDto.put("date", new LocalDate(transaction.getPurchasedDate())); final Integer status = transaction.getTransactionStatus(); final ShareAccountTransactionEnumData statusEnum = new ShareAccountTransactionEnumData( status.longValue(), null, null); final Integer type = transaction.getTransactionType(); final ShareAccountTransactionEnumData typeEnum = new ShareAccountTransactionEnumData(type.longValue(), null, null); transactionDto.put("status", statusEnum); transactionDto.put("type", typeEnum); if (transaction.isPurchaseRejectedTransaction() || transaction.isRedeemTransaction()) { BigDecimal amount = transaction.amount(); if (transaction.chargeAmount() != null) { amount = amount.add(transaction.chargeAmount()); } transactionDto.put("amount", amount); } else { transactionDto.put("amount", transaction.amount()); } transactionDto.put("chargeAmount", transaction.chargeAmount()); transactionDto.put("paymentTypeId", null); // FIXME::make it cash // payment if (transaction.getChargesPaidBy() != null && !transaction.getChargesPaidBy().isEmpty()) { final List<Map<String, Object>> chargesPaidData = new ArrayList<>(); transactionDto.put("chargesPaid", chargesPaidData); Set<ShareAccountChargePaidBy> chargesPaidBySet = transaction.getChargesPaidBy(); for (ShareAccountChargePaidBy chargesPaidBy : chargesPaidBySet) { Map<String, Object> chargesPaidDto = new HashMap<>(); chargesPaidDto.put("chargeId", chargesPaidBy.getChargeId()); chargesPaidDto.put("sharesChargeId", chargesPaidBy.getShareChargeId()); chargesPaidDto.put("amount", chargesPaidBy.getAmount()); chargesPaidData.add(chargesPaidDto); } } newTransactionsMap.add(transactionDto); } return accountingBridgeData; }
From source file:com.gst.portfolio.shareproducts.domain.ShareProductDividendPayOutDetails.java
License:Apache License
public LocalDate getDividendPeriodEndDateAsLocalDate() { LocalDate dividendPeriodEndDate = null; if (this.dividendPeriodEndDate != null) { dividendPeriodEndDate = new LocalDate(this.dividendPeriodEndDate); }//from w ww . j a v a2 s . c om return dividendPeriodEndDate; }
From source file:com.gst.portfolio.tax.domain.TaxComponent.java
License:Apache License
public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> changes = new HashMap<>(); if (command.isChangeInStringParameterNamed(TaxApiConstants.nameParamName, this.name)) { final String newValue = command.stringValueOfParameterNamed(TaxApiConstants.nameParamName); changes.put(TaxApiConstants.nameParamName, newValue); this.name = StringUtils.defaultIfEmpty(newValue, null); }//from w ww . j ava 2 s .c o m if (command.isChangeInBigDecimalParameterNamed(TaxApiConstants.percentageParamName, this.percentage)) { final BigDecimal newValue = command .bigDecimalValueOfParameterNamed(TaxApiConstants.percentageParamName); changes.put(TaxApiConstants.percentageParamName, newValue); LocalDate oldStartDate = new LocalDate(this.startDate); updateStartDate(command, changes, true); LocalDate newStartDate = new LocalDate(this.startDate); TaxComponentHistory history = TaxComponentHistory.createTaxComponentHistory(this.percentage, oldStartDate, newStartDate); this.taxComponentHistories.add(history); this.percentage = newValue; } return changes; }
From source file:com.gst.portfolio.tax.domain.TaxComponent.java
License:Apache License
public LocalDate startDate() { LocalDate startDate = null;/*from ww w . ja va 2 s. c o m*/ if (this.startDate != null) { startDate = new LocalDate(this.startDate); } return startDate; }
From source file:com.gst.portfolio.tax.domain.TaxComponentHistory.java
License:Apache License
public LocalDate endDate() { LocalDate endDate = null;// w w w .j ava2 s . co m if (this.endDate != null) { endDate = new LocalDate(this.endDate); } return endDate; }