List of usage examples for org.joda.time LocalDate toDate
@SuppressWarnings("deprecation") public Date toDate()
java.util.Date
. From source file:org.apache.fineract.portfolio.savings.domain.SavingsAccount.java
License:Apache License
public void modifyApplication(final JsonCommand command, final Map<String, Object> actualChanges, final DataValidatorBuilder baseDataValidator) { final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status); if (!SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.hasStateOf(currentStatus)) { baseDataValidator.reset()//from w ww . j a v a 2 s . com .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state"); return; } final String localeAsInput = command.locale(); final String dateFormat = command.dateFormat(); if (command.isChangeInLocalDateParameterNamed(SavingsApiConstants.submittedOnDateParamName, getSubmittedOnLocalDate())) { final LocalDate newValue = command .localDateValueOfParameterNamed(SavingsApiConstants.submittedOnDateParamName); final String newValueAsString = command .stringValueOfParameterNamed(SavingsApiConstants.submittedOnDateParamName); actualChanges.put(SavingsApiConstants.submittedOnDateParamName, newValueAsString); actualChanges.put(SavingsApiConstants.localeParamName, localeAsInput); actualChanges.put(SavingsApiConstants.dateFormatParamName, dateFormat); this.submittedOnDate = newValue.toDate(); } if (command.isChangeInStringParameterNamed(SavingsApiConstants.accountNoParamName, this.accountNumber)) { final String newValue = command.stringValueOfParameterNamed(SavingsApiConstants.accountNoParamName); actualChanges.put(SavingsApiConstants.accountNoParamName, newValue); this.accountNumber = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(SavingsApiConstants.externalIdParamName, this.externalId)) { final String newValue = command.stringValueOfParameterNamed(SavingsApiConstants.externalIdParamName); actualChanges.put(SavingsApiConstants.externalIdParamName, newValue); this.externalId = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInLongParameterNamed(SavingsApiConstants.clientIdParamName, clientId())) { final Long newValue = command.longValueOfParameterNamed(SavingsApiConstants.clientIdParamName); actualChanges.put(SavingsApiConstants.clientIdParamName, newValue); } if (command.isChangeInLongParameterNamed(SavingsApiConstants.groupIdParamName, groupId())) { final Long newValue = command.longValueOfParameterNamed(SavingsApiConstants.groupIdParamName); actualChanges.put(SavingsApiConstants.groupIdParamName, newValue); } if (command.isChangeInLongParameterNamed(SavingsApiConstants.productIdParamName, this.product.getId())) { final Long newValue = command.longValueOfParameterNamed(SavingsApiConstants.productIdParamName); actualChanges.put(SavingsApiConstants.productIdParamName, newValue); } if (command.isChangeInLongParameterNamed(SavingsApiConstants.fieldOfficerIdParamName, hasSavingsOfficerId())) { final Long newValue = command.longValueOfParameterNamed(SavingsApiConstants.fieldOfficerIdParamName); actualChanges.put(SavingsApiConstants.fieldOfficerIdParamName, newValue); } if (command.isChangeInBigDecimalParameterNamed(SavingsApiConstants.nominalAnnualInterestRateParamName, this.nominalAnnualInterestRate)) { final BigDecimal newValue = command .bigDecimalValueOfParameterNamed(SavingsApiConstants.nominalAnnualInterestRateParamName); actualChanges.put(SavingsApiConstants.nominalAnnualInterestRateParamName, newValue); actualChanges.put("locale", localeAsInput); this.nominalAnnualInterestRate = newValue; } if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestCompoundingPeriodTypeParamName, this.interestCompoundingPeriodType)) { final Integer newValue = command .integerValueOfParameterNamed(SavingsApiConstants.interestCompoundingPeriodTypeParamName); this.interestCompoundingPeriodType = newValue != null ? SavingsCompoundingInterestPeriodType.fromInt(newValue).getValue() : newValue; actualChanges.put(SavingsApiConstants.interestCompoundingPeriodTypeParamName, this.interestCompoundingPeriodType); } if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestPostingPeriodTypeParamName, this.interestPostingPeriodType)) { final Integer newValue = command .integerValueOfParameterNamed(SavingsApiConstants.interestPostingPeriodTypeParamName); this.interestPostingPeriodType = newValue != null ? SavingsPostingInterestPeriodType.fromInt(newValue).getValue() : newValue; actualChanges.put(SavingsApiConstants.interestPostingPeriodTypeParamName, this.interestPostingPeriodType); } if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestCalculationTypeParamName, this.interestCalculationType)) { final Integer newValue = command .integerValueOfParameterNamed(SavingsApiConstants.interestCalculationTypeParamName); this.interestCalculationType = newValue != null ? SavingsInterestCalculationType.fromInt(newValue).getValue() : newValue; actualChanges.put(SavingsApiConstants.interestCalculationTypeParamName, this.interestCalculationType); } if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestCalculationDaysInYearTypeParamName, this.interestCalculationDaysInYearType)) { final Integer newValue = command .integerValueOfParameterNamed(SavingsApiConstants.interestCalculationDaysInYearTypeParamName); this.interestCalculationDaysInYearType = newValue != null ? SavingsInterestCalculationDaysInYearType.fromInt(newValue).getValue() : newValue; actualChanges.put(SavingsApiConstants.interestCalculationDaysInYearTypeParamName, this.interestCalculationDaysInYearType); } if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull( SavingsApiConstants.minRequiredOpeningBalanceParamName, this.minRequiredOpeningBalance)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero( SavingsApiConstants.minRequiredOpeningBalanceParamName); actualChanges.put(SavingsApiConstants.minRequiredOpeningBalanceParamName, newValue); actualChanges.put("locale", localeAsInput); this.minRequiredOpeningBalance = Money.of(this.currency, newValue).getAmount(); } if (command.isChangeInIntegerParameterNamedDefaultingZeroToNull( SavingsApiConstants.lockinPeriodFrequencyParamName, this.lockinPeriodFrequency)) { final Integer newValue = command.integerValueOfParameterNamedDefaultToNullIfZero( SavingsApiConstants.lockinPeriodFrequencyParamName); actualChanges.put(SavingsApiConstants.lockinPeriodFrequencyParamName, newValue); actualChanges.put("locale", localeAsInput); this.lockinPeriodFrequency = newValue; } if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.lockinPeriodFrequencyTypeParamName, this.lockinPeriodFrequencyType)) { final Integer newValue = command .integerValueOfParameterNamed(SavingsApiConstants.lockinPeriodFrequencyTypeParamName); actualChanges.put(SavingsApiConstants.lockinPeriodFrequencyTypeParamName, newValue); this.lockinPeriodFrequencyType = newValue != null ? SavingsPeriodFrequencyType.fromInt(newValue).getValue() : newValue; } // set period type to null if frequency is null if (this.lockinPeriodFrequency == null) { this.lockinPeriodFrequencyType = null; } if (command.isChangeInBooleanParameterNamed(withdrawalFeeForTransfersParamName, this.withdrawalFeeApplicableForTransfer)) { final boolean newValue = command .booleanPrimitiveValueOfParameterNamed(withdrawalFeeForTransfersParamName); actualChanges.put(withdrawalFeeForTransfersParamName, newValue); this.withdrawalFeeApplicableForTransfer = newValue; } // charges final String chargesParamName = "charges"; if (command.hasParameter(chargesParamName)) { final JsonArray jsonArray = command.arrayOfParameterNamed(chargesParamName); if (jsonArray != null) { actualChanges.put(chargesParamName, command.jsonFragment(chargesParamName)); } } if (command.isChangeInBooleanParameterNamed(allowOverdraftParamName, this.allowOverdraft)) { final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(allowOverdraftParamName); actualChanges.put(allowOverdraftParamName, newValue); this.allowOverdraft = newValue; } if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(overdraftLimitParamName, this.overdraftLimit)) { final BigDecimal newValue = command .bigDecimalValueOfParameterNamedDefaultToNullIfZero(overdraftLimitParamName); actualChanges.put(overdraftLimitParamName, newValue); actualChanges.put(localeParamName, localeAsInput); this.overdraftLimit = newValue; } if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull( nominalAnnualInterestRateOverdraftParamName, this.nominalAnnualInterestRateOverdraft)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero( nominalAnnualInterestRateOverdraftParamName); actualChanges.put(nominalAnnualInterestRateOverdraftParamName, newValue); actualChanges.put(localeParamName, localeAsInput); this.nominalAnnualInterestRateOverdraft = newValue; } if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull( minOverdraftForInterestCalculationParamName, this.minOverdraftForInterestCalculation)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero( minOverdraftForInterestCalculationParamName); actualChanges.put(minOverdraftForInterestCalculationParamName, newValue); actualChanges.put(localeParamName, localeAsInput); this.minOverdraftForInterestCalculation = newValue; } if (!this.allowOverdraft) { this.overdraftLimit = null; this.nominalAnnualInterestRateOverdraft = null; this.minOverdraftForInterestCalculation = null; } if (command.isChangeInBooleanParameterNamed(enforceMinRequiredBalanceParamName, this.enforceMinRequiredBalance)) { final boolean newValue = command .booleanPrimitiveValueOfParameterNamed(enforceMinRequiredBalanceParamName); actualChanges.put(enforceMinRequiredBalanceParamName, newValue); this.enforceMinRequiredBalance = newValue; } if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(minRequiredBalanceParamName, this.minRequiredBalance)) { final BigDecimal newValue = command .bigDecimalValueOfParameterNamedDefaultToNullIfZero(minRequiredBalanceParamName); actualChanges.put(minRequiredBalanceParamName, newValue); actualChanges.put(localeParamName, localeAsInput); this.minRequiredBalance = newValue; } validateLockinDetails(baseDataValidator); esnureOverdraftLimitsSetForOverdraftAccounts(); }
From source file:org.apache.fineract.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
private SavingsAccountCharge(final SavingsAccount savingsAccount, final Charge chargeDefinition, final BigDecimal amount, final ChargeTimeType chargeTime, final ChargeCalculationType chargeCalculation, final LocalDate dueDate, final boolean status, MonthDay feeOnMonthDay, final Integer feeInterval) { this.savingsAccount = savingsAccount; this.charge = chargeDefinition; this.penaltyCharge = chargeDefinition.isPenalty(); this.chargeTime = (chargeTime == null) ? chargeDefinition.getChargeTimeType() : chargeTime.getValue(); if (isOnSpecifiedDueDate()) { if (dueDate == null) { final String defaultUserMessage = "Savings Account charge is missing due date."; throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge", dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(), chargeDefinition.getName()); }/*w w w .j av a 2s. c om*/ } if (isAnnualFee() || isMonthlyFee()) { feeOnMonthDay = (feeOnMonthDay == null) ? chargeDefinition.getFeeOnMonthDay() : feeOnMonthDay; if (feeOnMonthDay == null) { final String defaultUserMessage = "Savings Account charge is missing due date."; throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge", dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(), chargeDefinition.getName()); } this.feeOnMonth = feeOnMonthDay.getMonthOfYear(); this.feeOnDay = feeOnMonthDay.getDayOfMonth(); } else if (isWeeklyFee()) { if (dueDate == null) { final String defaultUserMessage = "Savings Account charge is missing due date."; throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge", dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(), chargeDefinition.getName()); } /** * For Weekly fee feeOnDay is ISO standard day of the week. * Monday=1, Tuesday=2 */ this.feeOnDay = dueDate.getDayOfWeek(); } else { this.feeOnDay = null; this.feeOnMonth = null; this.feeInterval = null; } if (isMonthlyFee() || isWeeklyFee()) { this.feeInterval = (feeInterval == null) ? chargeDefinition.feeInterval() : feeInterval; } this.dueDate = (dueDate == null) ? null : dueDate.toDate(); this.chargeCalculation = chargeDefinition.getChargeCalculation(); if (chargeCalculation != null) { this.chargeCalculation = chargeCalculation.getValue(); } BigDecimal chargeAmount = chargeDefinition.getAmount(); if (amount != null) { chargeAmount = amount; } final BigDecimal transactionAmount = new BigDecimal(0); populateDerivedFields(transactionAmount, chargeAmount); if (this.isWithdrawalFee()) { this.amountOutstanding = BigDecimal.ZERO; } this.paid = determineIfFullyPaid(); this.status = status; }
From source file:org.apache.fineract.portfolio.savings.domain.SavingsAccountTransaction.java
License:Apache License
private SavingsAccountTransaction(final SavingsAccount savingsAccount, final Office office, final PaymentDetail paymentDetail, final Integer typeOf, final LocalDate transactionLocalDate, final Date createdDate, final BigDecimal amount, final boolean isReversed, final AppUser appUser) { this.savingsAccount = savingsAccount; this.office = office; this.typeOf = typeOf; this.dateOf = transactionLocalDate.toDate(); this.amount = amount; this.reversed = isReversed; this.paymentDetail = paymentDetail; this.createdDate = createdDate; this.appUser = appUser; }
From source file:org.apache.fineract.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(); }// www . j a va 2 s . 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(); 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; }
From source file:org.apache.fineract.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 ww. j ava 2 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(); 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:org.apache.fineract.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(); }// ww w. jav a 2 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(); 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 (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:org.apache.fineract.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 .java 2 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(); 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(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(element.getAsJsonObject()); final BigDecimal unitPrice = this.fromApiJsonHelper .extractBigDecimalNamed(ShareAccountApiConstants.purchasedprice_paramname, element, locale); baseDataValidator.reset().parameter(ShareAccountApiConstants.purchasedprice_paramname).value(unitPrice) .notNull().positiveAmount(); 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); } 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:org.apache.fineract.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 ava 2s . 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(); 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); updateTotalChargeDerived(account); return actualChanges; }
From source file:org.apache.fineract.portfolio.shareproducts.serialization.ShareProductDataSerializer.java
License:Apache License
private Set<ShareProductMarketPrice> asembleShareMarketPrice(final JsonElement element) { Set<ShareProductMarketPrice> 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) { 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);/* w w w . j a va2s.c o m*/ } } return set; }
From source file:org.apache.fineract.portfolio.shares.serialization.ShareProductDataSerializer.java
License:Apache License
private Set<ShareMarketPrice> asembleShareMarketPrice(final JsonElement element) { Set<ShareMarketPrice> 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) { LocalDate localDate = this.fromApiJsonHelper .extractLocalDateNamed(ShareProductApiConstants.startdate_paramname, arrayElement); final BigDecimal shareValue = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed( ShareProductApiConstants.sharevalue_paramname, arrayElement); ShareMarketPrice obj = new ShareMarketPrice(localDate.toDate(), shareValue); set.add(obj);//from ww w. j a v a2 s . c o m } } return set; }