diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java index d285d843d..081ca06e3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java @@ -24,12 +24,9 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; import org.apache.commons.lang.StringUtils; -import org.mifosplatform.commands.domain.CommandWrapper; -import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; -import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -56,7 +53,7 @@ public class GroupsApiResource { "clientMembers", "allowedClients", "allowedOffices")); private final PlatformSecurityContext context; - private GroupReadPlatformService groupReadPlatformService; + private final GroupReadPlatformService groupReadPlatformService; private final GroupWritePlatformService groupWritePlatformService; private final ClientReadPlatformService clientReadPlatformService; private final OfficeReadPlatformService officeReadPlatformService; @@ -240,7 +237,7 @@ public class GroupsApiResource { // 'g.' preffix because of ERROR 1052 (23000): Column 'column_name' in where // clause is ambiguous // caused by the same name of columns in m_office and m_group tables - private String getGroupExtraCriteria(String sqlSearch, Long officeId, String externalId, String name, String hierarchy) { + private String getGroupExtraCriteria(String sqlSearch, final Long officeId, final String externalId, final String name, final String hierarchy) { String extraCriteria = ""; @@ -272,8 +269,4 @@ public class GroupsApiResource { return extraCriteria; } - - private boolean is(final String commandParam, final String commandValue) { - return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue); - } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java index f2b9c896f..23a2a1871 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java @@ -27,12 +27,10 @@ import org.springframework.data.jpa.domain.AbstractPersistable; @Table(name = "m_group") public class Group extends AbstractPersistable { - @SuppressWarnings("unused") @ManyToOne @JoinColumn(name = "office_id", nullable = false) private Office office; - @SuppressWarnings("unused") @ManyToOne @JoinColumn(name = "loan_officer_id", nullable = true) private Staff loanOfficer; @@ -56,11 +54,11 @@ public class Group extends AbstractPersistable { this.clientMembers = new HashSet(); } - public static Group newGroup(Office office, Staff loanOfficer , String name, String externalId, Set clientMembers) { + public static Group newGroup(final Office office, final Staff loanOfficer , final String name, final String externalId, final Set clientMembers) { return new Group(office, loanOfficer , name, externalId, clientMembers); } - public Group(Office office, Staff loanOfficer , String name, String externalId, Set clientMembers) { + public Group(final Office office, final Staff loanOfficer , final String name, final String externalId, final Set clientMembers) { this.office = office; this.loanOfficer = loanOfficer; if (StringUtils.isNotBlank(name)) { @@ -114,7 +112,7 @@ public class Group extends AbstractPersistable { } } - public void unassigLoanOfficer(GroupCommand command) { + public void unassigLoanOfficer(final GroupCommand command) { if (command.isLoanOfficerChanged()) { this.loanOfficer = null; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/data/SavingAccountData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/data/SavingAccountData.java index c01497393..d2732f31a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/data/SavingAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/data/SavingAccountData.java @@ -78,16 +78,18 @@ public class SavingAccountData { return new SavingAccountData(clientId, clientDisplayName); } - public SavingAccountData(Long id, EnumOptionData status, String externalId, Long clientId, String clientName, Long productId, - String productName, EnumOptionData productType, CurrencyData currencyData, BigDecimal savingsDepositAmountPerPeriod, - EnumOptionData savingsFrequencyType, BigDecimal totalDepositAmount, BigDecimal recurringInterestRate, - BigDecimal savingInterestRate, EnumOptionData interestType, EnumOptionData interestCalculationMethod, Integer tenure, - EnumOptionData tenureType, LocalDate projectedCommencementDate, LocalDate actualCommencementDate, LocalDate maturesOnDate, - BigDecimal projectedInterestAccuredOnMaturity, BigDecimal actualInterestAccured, BigDecimal projectedMaturityAmount, - BigDecimal actualMaturityAmount, boolean preClosureAllowed, BigDecimal preClosureInterestRate, LocalDate withdrawnonDate, - LocalDate rejectedonDate, LocalDate closedonDate, boolean isLockinPeriodAllowed, Integer lockinPeriod, - EnumOptionData lockinPeriodType, Integer depositEvery, BigDecimal outstandingAmount, Integer interestPostEvery, - EnumOptionData interestPostFrequency) { + public SavingAccountData(final Long id, final EnumOptionData status, final String externalId, final Long clientId, + final String clientName, final Long productId, final String productName, final EnumOptionData productType, + final CurrencyData currencyData, final BigDecimal savingsDepositAmountPerPeriod, final EnumOptionData savingsFrequencyType, + final BigDecimal totalDepositAmount, final BigDecimal recurringInterestRate, final BigDecimal savingInterestRate, + final EnumOptionData interestType, final EnumOptionData interestCalculationMethod, final Integer tenure, + final EnumOptionData tenureType, final LocalDate projectedCommencementDate, final LocalDate actualCommencementDate, + final LocalDate maturesOnDate, final BigDecimal projectedInterestAccuredOnMaturity, final BigDecimal actualInterestAccured, + final BigDecimal projectedMaturityAmount, final BigDecimal actualMaturityAmount, final boolean preClosureAllowed, + final BigDecimal preClosureInterestRate, final LocalDate withdrawnonDate, final LocalDate rejectedonDate, + final LocalDate closedonDate, final boolean isLockinPeriodAllowed, final Integer lockinPeriod, + final EnumOptionData lockinPeriodType, final Integer depositEvery, final BigDecimal outstandingAmount, + final Integer interestPostEvery, final EnumOptionData interestPostFrequency) { this.id = id; this.status = status; this.externalId = externalId; @@ -140,7 +142,7 @@ public class SavingAccountData { this.interestPostFrequency = interestPostFrequency; } - public SavingAccountData(Long clientId, String clientName) { + public SavingAccountData(final Long clientId, final String clientName) { this.id = null; this.status = null; this.externalId = null; @@ -193,11 +195,11 @@ public class SavingAccountData { this.interestPostFrequency = null; } - public SavingAccountData(SavingAccountData account, Collection productOptions, - Collection currencyOptions, List savingsProductTypeOptions, - List tenureTypeOptions, List savingFrequencyOptions, - List savingsInterestTypeOptions, List lockinPeriodTypeOptions, - List interestCalculationOptions, BigDecimal dueAmount) { + public SavingAccountData(final SavingAccountData account, final Collection productOptions, + final Collection currencyOptions, final List savingsProductTypeOptions, + final List tenureTypeOptions, final List savingFrequencyOptions, + final List savingsInterestTypeOptions, final List lockinPeriodTypeOptions, + final List interestCalculationOptions, final BigDecimal dueAmount) { this.id = account.id; this.status = account.status; this.externalId = account.externalId; @@ -252,12 +254,11 @@ public class SavingAccountData { this.interestPostFrequency = account.interestPostFrequency; } - // FIXME - Madhukar - unused variables been passed into construction - why? - public SavingAccountData(Long clientId, String clientName, Long productId, String productName, CurrencyData currency, - BigDecimal interestRate, BigDecimal savingsDepositAmountPerPeriod, EnumOptionData productType, EnumOptionData tenureType, - Integer tenure, EnumOptionData savingsFrequencyType, EnumOptionData interestType, EnumOptionData interestCalculationMethod, - BigDecimal minimumBalanceForWithdrawal, boolean partialDepositAllowed, boolean lockinPeriodAllowed, Integer lockinPeriod, - EnumOptionData lockinPeriodType, Integer depositEvery) { + public SavingAccountData(final Long clientId, final String clientName, final Long productId, final String productName, + final CurrencyData currency, final BigDecimal interestRate, final BigDecimal savingsDepositAmountPerPeriod, + final EnumOptionData productType, final EnumOptionData tenureType, final Integer tenure, + final EnumOptionData savingsFrequencyType, final EnumOptionData interestType, final EnumOptionData interestCalculationMethod, + final boolean lockinPeriodAllowed, final Integer lockinPeriod, final EnumOptionData lockinPeriodType, final Integer depositEvery) { this.id = null; this.status = null; this.externalId = null; @@ -310,7 +311,7 @@ public class SavingAccountData { this.interestPostFrequency = savingsFrequencyType; } - public SavingAccountData(SavingAccountData account, SavingPermissionData permissions) { + public SavingAccountData(final SavingAccountData account, final SavingPermissionData permissions) { this.id = account.id; this.status = account.status; this.externalId = account.externalId; @@ -364,7 +365,7 @@ public class SavingAccountData { this.interestPostFrequency = account.interestPostFrequency; } - public SavingAccountData(SavingAccountData account, SavingScheduleData savingScheduleData) { + public SavingAccountData(final SavingAccountData account, final SavingScheduleData savingScheduleData) { this.id = account.id; this.status = account.status; this.externalId = account.externalId; @@ -418,7 +419,7 @@ public class SavingAccountData { this.interestPostFrequency = account.interestPostFrequency; } - public SavingAccountData(SavingAccountData account, Collection transactions) { + public SavingAccountData(final SavingAccountData account, final Collection transactions) { this.id = account.id; this.status = account.status; this.externalId = account.externalId; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/ReccuringDepositInterestCalculator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/ReccuringDepositInterestCalculator.java index 65771f04e..5a3553ee5 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/ReccuringDepositInterestCalculator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/ReccuringDepositInterestCalculator.java @@ -9,110 +9,110 @@ import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; -import org.joda.time.LocalDate; import org.mifosplatform.organisation.monetary.domain.Money; import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingFrequencyType; import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingInterestCalculationMethod; -import org.mifosplatform.portfolio.savingsdepositproduct.domain.TenureTypeEnum; import org.springframework.stereotype.Service; @Service public class ReccuringDepositInterestCalculator { - - private final Integer monthsInYear = 12; - // FIXME - MADHUKAR - Are the unused field here needed? - public Money calculateInterestOnMaturityFor(Money savingsDepositPerPeriod, Integer tenure, BigDecimal reccuringInterestRate, - LocalDate commencementDate, TenureTypeEnum tenureTypeEnum, SavingFrequencyType savingFrequencyType, - SavingInterestCalculationMethod savingInterestCalculationMethod, Integer depositEvery) { - - BigDecimal finalAmount = BigDecimal.ZERO; - MathContext mc = new MathContext(8, RoundingMode.HALF_EVEN); - + private final Integer monthsInYear = 12; + + public Money calculateInterestOnMaturityFor(final Money savingsDepositPerPeriod, final Integer tenure, + final BigDecimal reccuringInterestRate, final SavingFrequencyType savingFrequencyType, + final SavingInterestCalculationMethod savingInterestCalculationMethod, Integer depositEvery) { + + BigDecimal finalAmount = BigDecimal.ZERO; + MathContext mc = new MathContext(8, RoundingMode.HALF_EVEN); BigDecimal interestRateAsFraction = reccuringInterestRate.divide(BigDecimal.valueOf(100), mc); Integer noofTimesInterestCompoundPerYear = determineIntValue(savingFrequencyType); - + BigDecimal interestRatePerPeriod = BigDecimal.valueOf(interestRateAsFraction.doubleValue() / noofTimesInterestCompoundPerYear.doubleValue()); - Integer noOfTimestobeCalculated = tenure/depositEvery; - - if(savingInterestCalculationMethod.isAverageBalance()){ - - BigDecimal termAmount = BigDecimal.ZERO; - BigDecimal totalInterest = BigDecimal.ZERO; - BigDecimal closingBalance = BigDecimal.ZERO; - BigDecimal amountPerPeriod = savingsDepositPerPeriod.getAmount(); - Integer depositEveryOriginalValue = depositEvery; - BigDecimal amountPermonth = BigDecimal.valueOf(amountPerPeriod.doubleValue()/depositEvery.doubleValue()); - - while (noOfTimestobeCalculated > 0) { - while (depositEvery > 0) { - closingBalance = closingBalance.add(amountPermonth); - termAmount = termAmount.add(closingBalance); - depositEvery--; - } - - BigDecimal averageAmount = BigDecimal.valueOf(termAmount.doubleValue()/depositEveryOriginalValue.doubleValue()); - BigDecimal interestRatePerTerm = BigDecimal.valueOf(interestRateAsFraction.doubleValue()/monthsInYear.doubleValue()*depositEveryOriginalValue.doubleValue()); - BigDecimal interestperTerm = averageAmount.multiply(interestRatePerTerm); - totalInterest = totalInterest.add(interestperTerm); - depositEvery = depositEveryOriginalValue; - termAmount = BigDecimal.ZERO; - noOfTimestobeCalculated--; - } - finalAmount = closingBalance.add(totalInterest); - - } else if(savingInterestCalculationMethod.isMonthlyCollection()){ - /* - * // Assuming tenure in months // see - * http://www.onemint.com/2012/04/03/ - * how-to-calculate-interest-on-recurring-deposits/ - * - * A=P(1+r/n)^nt - * - * A = final amount P = principal amount (initial investment) r = annual - * nominal interest rate (as a decimal, not in percentage) n = number of - * times the interest is compounded per year t = number of years - */ - - BigDecimal onePlusInterestRatePerPeriod = BigDecimal.ONE.add(interestRatePerPeriod); - BigDecimal monthsExpressedInYears; - BigDecimal timeforOneCalculationPeriod; - BigDecimal amountPerPeriod; - Integer tempTenure = tenure; - while (noOfTimestobeCalculated > 0) { - monthsExpressedInYears = BigDecimal.valueOf(tempTenure.doubleValue() / monthsInYear.doubleValue()); - timeforOneCalculationPeriod = BigDecimal.valueOf(noofTimesInterestCompoundPerYear * monthsExpressedInYears.doubleValue()); - amountPerPeriod = savingsDepositPerPeriod.getAmount().multiply( - BigDecimal.valueOf(Math.pow(onePlusInterestRatePerPeriod.doubleValue(), timeforOneCalculationPeriod.doubleValue()))); - finalAmount = finalAmount.add(amountPerPeriod); - noOfTimestobeCalculated--; - tempTenure = tempTenure-depositEvery; - } - } - return Money.of(savingsDepositPerPeriod.getCurrency(), finalAmount); - } - - private Integer determineIntValue(SavingFrequencyType frequencyType){ - Integer noofTimesInterestCompoundPerYear = Integer.valueOf(0); - switch (frequencyType) { - case MONTHLY: - noofTimesInterestCompoundPerYear = monthsInYear; - break; - case QUATERLY: - noofTimesInterestCompoundPerYear = monthsInYear / 3; - break; - case HALFYEARLY: - noofTimesInterestCompoundPerYear = monthsInYear / 6; - break; - case YEARLY: - noofTimesInterestCompoundPerYear = monthsInYear / 12; - break; - default: - throw new RuntimeException("The specified frequency not supported"); + Integer noOfTimestobeCalculated = tenure / depositEvery; - } - return noofTimesInterestCompoundPerYear; + if (savingInterestCalculationMethod.isAverageBalance()) { + + BigDecimal termAmount = BigDecimal.ZERO; + BigDecimal totalInterest = BigDecimal.ZERO; + BigDecimal closingBalance = BigDecimal.ZERO; + BigDecimal amountPerPeriod = savingsDepositPerPeriod.getAmount(); + Integer depositEveryOriginalValue = depositEvery; + BigDecimal amountPermonth = BigDecimal.valueOf(amountPerPeriod.doubleValue() / depositEvery.doubleValue()); + + while (noOfTimestobeCalculated > 0) { + while (depositEvery > 0) { + closingBalance = closingBalance.add(amountPermonth); + termAmount = termAmount.add(closingBalance); + depositEvery--; + } + + BigDecimal averageAmount = BigDecimal.valueOf(termAmount.doubleValue() / depositEveryOriginalValue.doubleValue()); + BigDecimal interestRatePerTerm = BigDecimal.valueOf(interestRateAsFraction.doubleValue() / monthsInYear.doubleValue() + * depositEveryOriginalValue.doubleValue()); + BigDecimal interestperTerm = averageAmount.multiply(interestRatePerTerm); + totalInterest = totalInterest.add(interestperTerm); + depositEvery = depositEveryOriginalValue; + termAmount = BigDecimal.ZERO; + noOfTimestobeCalculated--; + } + finalAmount = closingBalance.add(totalInterest); + + } else if (savingInterestCalculationMethod.isMonthlyCollection()) { + /* + * // Assuming tenure in months // see + * http://www.onemint.com/2012/04/03/ + * how-to-calculate-interest-on-recurring-deposits/ + * + * A=P(1+r/n)^nt + * + * A = final amount P = principal amount (initial investment) r = + * annual nominal interest rate (as a decimal, not in percentage) n + * = number of times the interest is compounded per year t = number + * of years + */ + + BigDecimal onePlusInterestRatePerPeriod = BigDecimal.ONE.add(interestRatePerPeriod); + BigDecimal monthsExpressedInYears; + BigDecimal timeforOneCalculationPeriod; + BigDecimal amountPerPeriod; + Integer tempTenure = tenure; + while (noOfTimestobeCalculated > 0) { + monthsExpressedInYears = BigDecimal.valueOf(tempTenure.doubleValue() / monthsInYear.doubleValue()); + timeforOneCalculationPeriod = BigDecimal.valueOf(noofTimesInterestCompoundPerYear * monthsExpressedInYears.doubleValue()); + amountPerPeriod = savingsDepositPerPeriod.getAmount() + .multiply( + BigDecimal.valueOf(Math.pow(onePlusInterestRatePerPeriod.doubleValue(), + timeforOneCalculationPeriod.doubleValue()))); + finalAmount = finalAmount.add(amountPerPeriod); + noOfTimestobeCalculated--; + tempTenure = tempTenure - depositEvery; + } + } + return Money.of(savingsDepositPerPeriod.getCurrency(), finalAmount); + } + + private Integer determineIntValue(final SavingFrequencyType frequencyType) { + Integer noofTimesInterestCompoundPerYear = Integer.valueOf(0); + switch (frequencyType) { + case MONTHLY: + noofTimesInterestCompoundPerYear = monthsInYear; + break; + case QUATERLY: + noofTimesInterestCompoundPerYear = monthsInYear / 3; + break; + case HALFYEARLY: + noofTimesInterestCompoundPerYear = monthsInYear / 6; + break; + case YEARLY: + noofTimesInterestCompoundPerYear = monthsInYear / 12; + break; + default: + throw new RuntimeException("The specified frequency not supported"); + + } + return noofTimesInterestCompoundPerYear; } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccount.java index 068edf2d2..b8ac861d3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccount.java @@ -131,7 +131,7 @@ public class SavingAccount extends AbstractAuditableCustom { private BigDecimal outstandingAmount; @Column(name = "is_preclosure_allowed", nullable = false) - private boolean preClosureAllowed = false; + private final boolean preClosureAllowed = false; @Column(name = "is_deleted", nullable = false) private boolean deleted = false; @@ -197,20 +197,20 @@ public class SavingAccount extends AbstractAuditableCustom { // } - public static SavingAccount openNew(Client client, SavingProduct product, String externalId, Money savingsDeposit, - BigDecimal reccuringInterestRate, BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate, - TenureTypeEnum tenureTypeEnum, SavingProductType savingProductType, SavingFrequencyType savingFrequencyType, - SavingsInterestType interestType, SavingInterestCalculationMethod savingInterestCalculationMethod, - boolean isLockinPeriodAllowed, Integer lockinPeriod, PeriodFrequencyType lockinPeriodType, - ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, - final DepositLifecycleStateMachine lifecycleStateMachine, Integer depositEvery, Integer interestPostEvery, - Integer interestPostFrequency) { + public static SavingAccount openNew(final Client client, final SavingProduct product, final String externalId, + final Money savingsDeposit, final BigDecimal reccuringInterestRate, final BigDecimal savingInterestRate, final Integer tenure, + final LocalDate commencementDate, final TenureTypeEnum tenureTypeEnum, final SavingProductType savingProductType, + final SavingFrequencyType savingFrequencyType, final SavingsInterestType interestType, + final SavingInterestCalculationMethod savingInterestCalculationMethod, final boolean isLockinPeriodAllowed, + final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType, + final ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, + final DepositLifecycleStateMachine lifecycleStateMachine, final Integer depositEvery, final Integer interestPostEvery, + final Integer interestPostFrequency) { Money futureValueOnMaturity = null; if (savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod()) { futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure, - reccuringInterestRate, commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod, - depositEvery); + reccuringInterestRate, savingFrequencyType, savingInterestCalculationMethod, depositEvery); } else if (savingProductType.isReccuring() && tenureTypeEnum.isPerpetual()) { futureValueOnMaturity = savingsDeposit; } else { @@ -223,12 +223,14 @@ public class SavingAccount extends AbstractAuditableCustom { interestPostEvery, interestPostFrequency); } - public SavingAccount(Client client, String externalId, SavingProduct product, Money savingsDeposit, BigDecimal reccuringInterestRate, - BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate, TenureTypeEnum tenureTypeEnum, - SavingProductType savingProductType, SavingFrequencyType savingFrequencyType, SavingsInterestType interestType, - SavingInterestCalculationMethod savingInterestCalculationMethod, boolean isLockinPeriodAllowed, Integer lockinPeriod, - PeriodFrequencyType lockinPeriodType, Money futureValueOnMaturity, final DepositLifecycleStateMachine lifecycleStateMachine, - Integer payEvery, Integer interestPostEvery, Integer interestPostFrequency) { + public SavingAccount(final Client client, final String externalId, final SavingProduct product, final Money savingsDeposit, + final BigDecimal reccuringInterestRate, final BigDecimal savingInterestRate, final Integer tenure, + final LocalDate commencementDate, final TenureTypeEnum tenureTypeEnum, final SavingProductType savingProductType, + final SavingFrequencyType savingFrequencyType, final SavingsInterestType interestType, + final SavingInterestCalculationMethod savingInterestCalculationMethod, final boolean isLockinPeriodAllowed, + final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType, final Money futureValueOnMaturity, + final DepositLifecycleStateMachine lifecycleStateMachine, final Integer payEvery, final Integer interestPostEvery, + final Integer interestPostFrequency) { DepositAccountStatus from = null; if (accountStatus != null) { @@ -274,18 +276,18 @@ public class SavingAccount extends AbstractAuditableCustom { this.interestPostFrequency = interestPostFrequency; } - public void modifyAccount(SavingProduct product, String externalId, Money savingsDeposit, BigDecimal reccuringInterestRate, - BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate, TenureTypeEnum tenureTypeEnum, - SavingProductType savingProductType, SavingFrequencyType savingFrequencyType, - SavingInterestCalculationMethod savingInterestCalculationMethod, boolean isLockinPeriodAllowed, Integer lockinPeriod, - PeriodFrequencyType lockinPeriodType, ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, Integer payEvery, - SavingsInterestType interestType, Integer interestPostEvery, Integer interestPostFrequency) { + public void modifyAccount(final SavingProduct product, final String externalId, final Money savingsDeposit, + final BigDecimal reccuringInterestRate, final BigDecimal savingInterestRate, final Integer tenure, + final LocalDate commencementDate, final TenureTypeEnum tenureTypeEnum, final SavingProductType savingProductType, + final SavingFrequencyType savingFrequencyType, final SavingInterestCalculationMethod savingInterestCalculationMethod, + final boolean isLockinPeriodAllowed, final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType, + final ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, final Integer payEvery, + final SavingsInterestType interestType, final Integer interestPostEvery, final Integer interestPostFrequency) { Money futureValueOnMaturity = null; if (savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod()) { - futureValueOnMaturity = reccuringDepositInterestCalculator - .calculateInterestOnMaturityFor(savingsDeposit, tenure, reccuringInterestRate, commencementDate, tenureTypeEnum, - savingFrequencyType, savingInterestCalculationMethod, payEvery); + futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure, + reccuringInterestRate, savingFrequencyType, savingInterestCalculationMethod, payEvery); } else if (savingProductType.isReccuring() && tenureTypeEnum.isPerpetual()) { futureValueOnMaturity = savingsDeposit; } else { @@ -432,7 +434,7 @@ public class SavingAccount extends AbstractAuditableCustom { this.savingScheduleInstallments.add(installment); } - public void reject(LocalDate rejectedOn, DepositLifecycleStateMachine depositLifecycleStateMachine) { + public void reject(final LocalDate rejectedOn, final DepositLifecycleStateMachine depositLifecycleStateMachine) { DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_REJECTED, DepositAccountStatus.fromInt(this.accountStatus)); @@ -467,7 +469,7 @@ public class SavingAccount extends AbstractAuditableCustom { return date; } - public void withdrawnByApplicant(LocalDate withdrawnOn, DepositLifecycleStateMachine depositLifecycleStateMachine) { + public void withdrawnByApplicant(final LocalDate withdrawnOn, final DepositLifecycleStateMachine depositLifecycleStateMachine) { DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_WITHDRAWN, DepositAccountStatus.fromInt(this.accountStatus)); @@ -493,7 +495,7 @@ public class SavingAccount extends AbstractAuditableCustom { } } - public void undoSavingAccountApproval(DepositLifecycleStateMachine depositLifecycleStateMachine) { + public void undoSavingAccountApproval(final DepositLifecycleStateMachine depositLifecycleStateMachine) { DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVAL_UNDO, DepositAccountStatus.fromInt(this.accountStatus)); this.accountStatus = statusEnum.getValue(); @@ -501,10 +503,12 @@ public class SavingAccount extends AbstractAuditableCustom { this.closedOnDate = new Date(); } - public void approveSavingAccount(LocalDate approvalDate, BigDecimal savingsDepositAmountPerPeriod, BigDecimal recurringInterestRate, - BigDecimal savingInterestRate, Integer interestType, Integer tenure, Integer tenureType, Integer frequency, Integer payEvery, - DepositLifecycleStateMachine depositLifecycleStateMachine, - ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, Integer interestPostEvery, Integer interestPostFrequency) { + public void approveSavingAccount(final LocalDate approvalDate, final BigDecimal savingsDepositAmountPerPeriod, + final BigDecimal recurringInterestRate, final BigDecimal savingInterestRate, final Integer interestType, final Integer tenure, + final Integer tenureType, final Integer frequency, final Integer payEvery, + final DepositLifecycleStateMachine depositLifecycleStateMachine, + final ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, final Integer interestPostEvery, + final Integer interestPostFrequency) { DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVED, DepositAccountStatus.fromInt(this.accountStatus)); @@ -518,7 +522,7 @@ public class SavingAccount extends AbstractAuditableCustom { Money futureValueOnMaturity = null; if (SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isFixedPeriod()) { futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsAmountPerPeriod, tenure, - recurringInterestRate, approvalDate, tenureTypeEnum, savingFrequencyType, interestCalculationMethod, payEvery); + recurringInterestRate, savingFrequencyType, interestCalculationMethod, payEvery); } else if (SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isPerpetual()) { futureValueOnMaturity = savingsAmountPerPeriod; } else { @@ -552,7 +556,7 @@ public class SavingAccount extends AbstractAuditableCustom { this.interestPostedAmount = BigDecimal.ZERO; } - public void depositMoney(SavingAccountDepositCommand command) { + public void depositMoney(final SavingAccountDepositCommand command) { BigDecimal depositAmount = BigDecimal.ZERO; BigDecimal remainAmountToBePaid = BigDecimal.ZERO; @@ -600,7 +604,7 @@ public class SavingAccount extends AbstractAuditableCustom { return DepositAccountStatus.fromInt(this.accountStatus).isActive(); } - public void withdrawAmount(BigDecimal amount, LocalDate transactionDate) { + public void withdrawAmount(final BigDecimal amount, final LocalDate transactionDate) { this.outstandingAmount = this.outstandingAmount.subtract(amount); SavingAccountTransaction savingAccountTransaction = SavingAccountTransaction.withdraw(amount, transactionDate); savingAccountTransaction.updateAccount(this); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccountTransaction.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccountTransaction.java index 84b5c625c..238412099 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccountTransaction.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccountTransaction.java @@ -26,12 +26,12 @@ import org.mifosplatform.useradministration.domain.AppUser; @Entity @Table(name = "m_saving_account_transaction") public class SavingAccountTransaction extends AbstractAuditableCustom { - + + @SuppressWarnings("unused") @ManyToOne(optional = false) @JoinColumn(name = "saving_account_id", nullable = false) private SavingAccount savingAccount; - // @Enumerated(EnumType.ORDINAL) @Column(name = "transaction_type_enum", nullable = false) private Integer typeOf; @@ -46,49 +46,51 @@ public class SavingAccountTransaction extends AbstractAuditableCustom savingProducts, Long productId) { + private SavingProductData findSavingProductById(final Collection savingProducts, final Long productId) { SavingProductData match = this.savingProductReadPlatformService.retrieveNewSavingProductDetails(); for (SavingProductLookup savingProductLookup : savingProducts) { if (savingProductLookup.hasId(productId)) { @@ -212,7 +212,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl } @Override - public SavingPermissionData retrieveSavingAccountPermissions(SavingAccountData savingAccountData) { + public SavingPermissionData retrieveSavingAccountPermissions(final SavingAccountData savingAccountData) { boolean pendingApproval = (savingAccountData.getStatus().getId().equals(100L)); boolean undoApprovalAllowed = (savingAccountData.getStatus().getId().equals(300L)); boolean renewelAllowed = false; @@ -230,7 +230,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl @SuppressWarnings("unused") @Override - public BigDecimal deriveSavingDueAmount(SavingAccountData account) { + public BigDecimal deriveSavingDueAmount(final SavingAccountData account) { BigDecimal dueAmount = BigDecimal.ZERO; EnumOptionData status = account.getStatus(); @@ -254,7 +254,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl } @Override - public SavingScheduleData retrieveSavingsAccountSchedule(Long accountId, CurrencyData currency) { + public SavingScheduleData retrieveSavingsAccountSchedule(final Long accountId, final CurrencyData currency) { this.context.authenticatedUser(); SavingAccountScheduleMapper mapper = new SavingAccountScheduleMapper(); String sql = "Select " + mapper.savingScheduleSchema() + " where ss.saving_account_id =? order by ss.installment"; @@ -281,7 +281,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl } @Override - public SavingSchedulePeriodData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException { + public SavingSchedulePeriodData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { LocalDate dueDate = JdbcSupport.getLocalDate(rs, "dueDate"); Integer installment = JdbcSupport.getInteger(rs, "installment"); @@ -308,7 +308,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl } @Override - public SavingAccountForLookup mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException { + public SavingAccountForLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { Long id = rs.getLong("id"); return new SavingAccountForLookup(id); } @@ -316,7 +316,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl } @Override - public Collection retrieveSavingsAccountTransactions(Long accountId) { + public Collection retrieveSavingsAccountTransactions(final Long accountId) { this.context.authenticatedUser(); SavingAccountTransactionMapper savingAccountTransactionMapper = new SavingAccountTransactionMapper(); String sql = "select " + savingAccountTransactionMapper.schema() + " where stxn.saving_account_id = ? "; @@ -330,7 +330,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl } @Override - public SavingAccountTransactionsData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException { + public SavingAccountTransactionsData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { Long id = rs.getLong("id"); LocalDate transactionDate = JdbcSupport.getLocalDate(rs, "transactionDate"); Integer transactionTypeValue = JdbcSupport.getInteger(rs, "type"); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccount.java index e56509efb..3065ebc20 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/domain/DepositAccount.java @@ -562,14 +562,14 @@ public class DepositAccount extends AbstractAuditableCustom { return date; } - public void updateAccount(DepositAccount account) { + public void updateAccount(final DepositAccount account) { this.renewdAccount = account; } - public void withdrawDepositAccountMoney(DepositLifecycleStateMachine depositLifecycleStateMachine, - FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, LocalDate eventDate) { + public void withdrawDepositAccountMoney(final DepositLifecycleStateMachine depositLifecycleStateMachine, + final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, final LocalDate eventDate) { if (eventDate.isBefore(getLastInterestPostedDate())) { final String errorMessage = "Deposit Account Preclosed date \"" + eventDate + "\"cannot before last interest posted date \"" @@ -647,7 +647,7 @@ public class DepositAccount extends AbstractAuditableCustom { * } */ - public void withdrawInterest(Money interest) { + public void withdrawInterest(final Money interest) { @SuppressWarnings("unused") boolean statustest = isActive(); if (isActive()) { @@ -662,7 +662,7 @@ public class DepositAccount extends AbstractAuditableCustom { } - public void closeDepositAccount(DepositLifecycleStateMachine depositLifecycleStateMachine) { + public void closeDepositAccount(final DepositLifecycleStateMachine depositLifecycleStateMachine) { DepositAccountStatus statusEnumForClose = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_CLOSED, DepositAccountStatus.fromInt(this.depositStatus)); this.depositStatus = statusEnumForClose.getValue(); @@ -732,7 +732,7 @@ public class DepositAccount extends AbstractAuditableCustom { return DepositAccountStatus.fromInt(this.depositStatus).isActive(); } - public void postInterestForDepositAccount(DepositAccount account, FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator) { + public void postInterestForDepositAccount(final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator) { LocalDate lastInterestPostedDate = getLastInterestPostedDate(); LocalDate nextInterestPostingDate = getNextInterestPostedDate(); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountAssembler.java index 592ef4cf6..d2e677a42 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountAssembler.java @@ -57,26 +57,31 @@ public class DepositAccountAssembler { } public DepositAccount assembleFrom(final JsonCommand command) { - final JsonElement element = command.parsedJson(); - - final Long clientId = fromApiJsonHelper.extractLongNamed("clientId", element); - final Long productId = fromApiJsonHelper.extractLongNamed("productId", element); - final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element); - final Boolean isInterestWithdrawable = fromApiJsonHelper.extractBooleanNamed("isInterestWithdrawable", element); - final BigDecimal depositValue = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("deposit", element); - final Integer tenureInMonthsCommandValue = fromApiJsonHelper.extractIntegerNamed("tenureInMonths", element, Locale.getDefault()); - final BigDecimal maturityInterestRateCommandValue = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityInterestRate", element); - final BigDecimal preClosureInterestRateCommandValue = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("preClosureInterestRate", element); - final Integer interestCompoundedEveryCommandValue = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEvery", element, Locale.getDefault()); - final Integer interestCompoundedEveryPeriodTypeCommandValue = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEveryPeriodType", element, Locale.getDefault()); - final Boolean renewalAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("renewalAllowed", element); - final Boolean preClosureAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("preClosureAllowed", element); - final Boolean interestCompoundingAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("interestCompoundingAllowed", element); - final Boolean isLockinPeriodAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element); - final Integer lockinPeriodCommandValue = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault()); - final Integer lockinPeriodTypeCommandValue = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault()); - final LocalDate commencementDate = fromApiJsonHelper.extractLocalDateNamed("commencementDate", element); - + final JsonElement element = command.parsedJson(); + + final Long clientId = fromApiJsonHelper.extractLongNamed("clientId", element); + final Long productId = fromApiJsonHelper.extractLongNamed("productId", element); + final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element); + final Boolean isInterestWithdrawable = fromApiJsonHelper.extractBooleanNamed("isInterestWithdrawable", element); + final BigDecimal depositValue = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("deposit", element); + final Integer tenureInMonthsCommandValue = fromApiJsonHelper.extractIntegerNamed("tenureInMonths", element, Locale.getDefault()); + final BigDecimal maturityInterestRateCommandValue = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityInterestRate", + element); + final BigDecimal preClosureInterestRateCommandValue = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("preClosureInterestRate", + element); + final Integer interestCompoundedEveryCommandValue = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEvery", element, + Locale.getDefault()); + final Integer interestCompoundedEveryPeriodTypeCommandValue = fromApiJsonHelper.extractIntegerNamed( + "interestCompoundedEveryPeriodType", element, Locale.getDefault()); + final Boolean renewalAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("renewalAllowed", element); + final Boolean preClosureAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("preClosureAllowed", element); + final Boolean interestCompoundingAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("interestCompoundingAllowed", element); + final Boolean isLockinPeriodAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element); + final Integer lockinPeriodCommandValue = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault()); + final Integer lockinPeriodTypeCommandValue = fromApiJsonHelper + .extractIntegerNamed("lockinPeriodType", element, Locale.getDefault()); + final LocalDate commencementDate = fromApiJsonHelper.extractLocalDateNamed("commencementDate", element); + Client client = this.clientRepository.findOne(clientId); if (client == null || client.isDeleted()) { throw new ClientNotFoundException(clientId); } @@ -147,10 +152,9 @@ public class DepositAccountAssembler { // end of details allowed to be overriden from product DepositAccount account = new DepositAccount().openNew(client, product, externalId, deposit, maturityInterestRate, - preClosureInterestRate, tenureInMonths, compoundingInterestEvery, compoundingInterestFrequency, - commencementDate, renewalAllowed, preClosureAllowed, this.fixedTermDepositInterestCalculator, - defaultDepositLifecycleStateMachine(), isInterestWithdrawable, interestCompoundingAllowed, isLockinPeriodAllowed, - lockinPeriod, lockinPeriodType); + preClosureInterestRate, tenureInMonths, compoundingInterestEvery, compoundingInterestFrequency, commencementDate, + renewalAllowed, preClosureAllowed, this.fixedTermDepositInterestCalculator, defaultDepositLifecycleStateMachine(), + isInterestWithdrawable, interestCompoundingAllowed, isLockinPeriodAllowed, lockinPeriod, lockinPeriodType); return account; } @@ -160,10 +164,10 @@ public class DepositAccountAssembler { return new DepositLifecycleStateMachineImpl(allowedDepositStatuses); } - public DepositAccount assembleFrom(DepositAccount account, JsonCommand command) { - - final Map actualChanges = new LinkedHashMap(20); - final String localeAsInput = command.locale(); + public DepositAccount assembleFrom(final DepositAccount account, final JsonCommand command) { + + final Map actualChanges = new LinkedHashMap(20); + final String localeAsInput = command.locale(); Client client = account.client(); @@ -178,7 +182,7 @@ public class DepositAccountAssembler { actualChanges.put(productIdParamName, newValue); actualChanges.put("locale", localeAsInput); } - + Money deposit = account.getDeposit(); final String depositParamName = "deposit"; if (command.isChangeInBigDecimalParameterNamed(depositParamName, deposit.getAmount())) { @@ -229,7 +233,8 @@ public class DepositAccountAssembler { PeriodFrequencyType interestCompoundedEveryPeriodType = account.getInterestCompoundedFrequencyType(); final String interestCompoundedEveryPeriodTypeParamName = "interestCompoundedEveryPeriodType"; - if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryPeriodTypeParamName, interestCompoundedEveryPeriodType.getValue())) { + if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryPeriodTypeParamName, + interestCompoundedEveryPeriodType.getValue())) { final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryPeriodTypeParamName); actualChanges.put(interestCompoundedEveryPeriodTypeParamName, newValue); actualChanges.put("locale", localeAsInput); @@ -239,7 +244,7 @@ public class DepositAccountAssembler { Boolean renewalAllowed = account.isRenewalAllowed(); final String renewalAllowedParamName = "renewalAllowed"; if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, renewalAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName); actualChanges.put(renewalAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); renewalAllowed = newValue; @@ -248,7 +253,7 @@ public class DepositAccountAssembler { Boolean preClosureAllowed = account.isPreClosureAllowed(); final String preClosureAllowedParamName = "preClosureAllowed"; if (command.isChangeInBooleanParameterNamed(preClosureAllowedParamName, preClosureAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName); actualChanges.put(preClosureAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); preClosureAllowed = newValue; @@ -257,7 +262,7 @@ public class DepositAccountAssembler { Boolean isInterestWithdrawable = account.isInterestWithdrawable(); final String isInterestWithdrawableParamName = "isInterestWithdrawable"; if (command.isChangeInBooleanParameterNamed(isInterestWithdrawableParamName, isInterestWithdrawable)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName); actualChanges.put(isInterestWithdrawableParamName, newValue); actualChanges.put("locale", localeAsInput); isInterestWithdrawable = newValue; @@ -266,7 +271,7 @@ public class DepositAccountAssembler { Boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed(); final String isInterestCompoundingAllowedParamName = "interestCompoundingAllowed"; if (command.isChangeInBooleanParameterNamed(isInterestCompoundingAllowedParamName, isInterestCompoundingAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestCompoundingAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestCompoundingAllowedParamName); actualChanges.put(isInterestCompoundingAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); isInterestCompoundingAllowed = newValue; @@ -275,14 +280,14 @@ public class DepositAccountAssembler { Boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed(); final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed"; if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, isLockinPeriodAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName); actualChanges.put(isLockinPeriodAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); isLockinPeriodAllowed = newValue; } Integer lockinPeriod = account.getLockinPeriod(); - final String lockinPeriodParamName = "lockinPeriod"; + final String lockinPeriodParamName = "lockinPeriod"; if (command.isChangeInIntegerParameterNamed(lockinPeriodParamName, lockinPeriod)) { final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodParamName); actualChanges.put(lockinPeriodParamName, newValue); @@ -291,7 +296,7 @@ public class DepositAccountAssembler { } PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType(); - final String lockinPeriodTypeParamName = "lockinPeriodType"; + final String lockinPeriodTypeParamName = "lockinPeriodType"; if (command.isChangeInIntegerParameterNamed(lockinPeriodTypeParamName, lockinPeriodType.getValue())) { final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodTypeParamName); actualChanges.put(lockinPeriodTypeParamName, newValue); @@ -310,13 +315,13 @@ public class DepositAccountAssembler { return newAccount; } - public Map assembleUpdatedDepositAccount(DepositAccount account, JsonCommand command) { - - final Map actualChanges = new LinkedHashMap(20); - final String localeAsInput = command.locale(); - - DepositProduct product = account.product(); - final String productIdParamName = "productId"; + public Map assembleUpdatedDepositAccount(final DepositAccount account, final JsonCommand command) { + + final Map actualChanges = new LinkedHashMap(20); + final String localeAsInput = command.locale(); + + DepositProduct product = account.product(); + final String productIdParamName = "productId"; if (command.isChangeInLongParameterNamed(productIdParamName, account.product().getId())) { final Long newValue = command.longValueOfParameterNamed(productIdParamName); if (newValue != null) { @@ -326,7 +331,7 @@ public class DepositAccountAssembler { actualChanges.put(productIdParamName, newValue); actualChanges.put("locale", localeAsInput); } - + String externalId = account.getExternalId(); final String externalIdParamName = "externalId"; if (command.isChangeInStringParameterNamed(externalIdParamName, externalId)) { @@ -334,15 +339,15 @@ public class DepositAccountAssembler { actualChanges.put(externalIdParamName, newValue); externalId = newValue; } - + LocalDate commencementDate = account.getProjectedCommencementDate(); final String commencementDateParamName = "commencementDate"; if (command.isChangeInLocalDateParameterNamed("commencementDate", commencementDate)) { - final LocalDate newValue = command.localDateValueOfParameterNamed(commencementDateParamName); - actualChanges.put(commencementDateParamName, newValue); - commencementDate = newValue; - } - + final LocalDate newValue = command.localDateValueOfParameterNamed(commencementDateParamName); + actualChanges.put(commencementDateParamName, newValue); + commencementDate = newValue; + } + Money deposit = account.getDeposit(); final String depositParamName = "deposit"; if (command.isChangeInBigDecimalParameterNamed(depositParamName, deposit.getAmount())) { @@ -351,7 +356,7 @@ public class DepositAccountAssembler { actualChanges.put("locale", localeAsInput); deposit = Money.of(deposit.getCurrency(), newValue); } - + Integer tenureInMonths = account.getTenureInMonths(); final String tenureInMonthsParamName = "tenureInMonths"; if (command.isChangeInIntegerParameterNamed(tenureInMonthsParamName, tenureInMonths)) { @@ -360,7 +365,7 @@ public class DepositAccountAssembler { actualChanges.put("locale", localeAsInput); tenureInMonths = newValue; } - + BigDecimal maturityInterestRate = account.getInterestRate(); final String maturityInterestRateParamName = "maturityInterestRate"; if (command.isChangeInBigDecimalParameterNamed(maturityInterestRateParamName, maturityInterestRate)) { @@ -369,7 +374,7 @@ public class DepositAccountAssembler { actualChanges.put("locale", localeAsInput); maturityInterestRate = newValue; } - + BigDecimal preClosureInterestRate = account.getPreClosureInterestRate(); final String preClosureInterestRateParamName = "preClosureInterestRate"; if (command.isChangeInBigDecimalParameterNamed(preClosureInterestRateParamName, preClosureInterestRate)) { @@ -378,10 +383,10 @@ public class DepositAccountAssembler { actualChanges.put("locale", localeAsInput); preClosureInterestRate = newValue; } - + if (product.getMaturityMinInterestRate().compareTo(preClosureInterestRate) == -1) { throw new DepositAccounDataValidationtException( preClosureInterestRate, product.getMaturityMinInterestRate()); } - + Integer interestCompoundedEvery = account.getInterestCompoundedEvery(); final String interestCompoundedEveryParamName = "interestCompoundedEvery"; if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryParamName, interestCompoundedEvery)) { @@ -390,96 +395,97 @@ public class DepositAccountAssembler { actualChanges.put("locale", localeAsInput); interestCompoundedEvery = newValue; } - + PeriodFrequencyType interestCompoundedEveryPeriodType = account.getInterestCompoundedFrequencyType(); final String interestCompoundedEveryPeriodTypeParamName = "interestCompoundedEveryPeriodType"; - if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryPeriodTypeParamName, interestCompoundedEveryPeriodType.getValue())) { + if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryPeriodTypeParamName, + interestCompoundedEveryPeriodType.getValue())) { final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryPeriodTypeParamName); actualChanges.put(interestCompoundedEveryPeriodTypeParamName, newValue); actualChanges.put("locale", localeAsInput); interestCompoundedEveryPeriodType = PeriodFrequencyType.fromInt(newValue); } - + Boolean renewalAllowed = account.isRenewalAllowed(); final String renewalAllowedParamName = "renewalAllowed"; if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, renewalAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName); actualChanges.put(renewalAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); renewalAllowed = newValue; } - + Boolean preClosureAllowed = account.isPreClosureAllowed(); final String preClosureAllowedParamName = "preClosureAllowed"; if (command.isChangeInBooleanParameterNamed(preClosureAllowedParamName, preClosureAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName); actualChanges.put(preClosureAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); preClosureAllowed = newValue; } - + Boolean isInterestWithdrawable = account.isInterestWithdrawable(); final String isInterestWithdrawableParamName = "isInterestWithdrawable"; if (command.isChangeInBooleanParameterNamed(isInterestWithdrawableParamName, isInterestWithdrawable)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName); actualChanges.put(isInterestWithdrawableParamName, newValue); actualChanges.put("locale", localeAsInput); isInterestWithdrawable = newValue; } - + Boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed(); final String isInterestCompoundingAllowedParamName = "interestCompoundingAllowed"; if (command.isChangeInBooleanParameterNamed(isInterestCompoundingAllowedParamName, isInterestCompoundingAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestCompoundingAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestCompoundingAllowedParamName); actualChanges.put(isInterestCompoundingAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); isInterestCompoundingAllowed = newValue; } - + Boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed(); final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed"; if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, isLockinPeriodAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName); actualChanges.put(isLockinPeriodAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); isLockinPeriodAllowed = newValue; } - + Integer lockinPeriod = account.getLockinPeriod(); - final String lockinPeriodParamName = "lockinPeriod"; + final String lockinPeriodParamName = "lockinPeriod"; if (command.isChangeInIntegerParameterNamed(lockinPeriodParamName, lockinPeriod)) { final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodParamName); actualChanges.put(lockinPeriodParamName, newValue); actualChanges.put("locale", localeAsInput); lockinPeriod = newValue; } - + PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType(); - final String lockinPeriodTypeParamName = "lockinPeriodType"; + final String lockinPeriodTypeParamName = "lockinPeriodType"; if (command.isChangeInIntegerParameterNamed(lockinPeriodTypeParamName, lockinPeriodType.getValue())) { final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodTypeParamName); actualChanges.put(lockinPeriodTypeParamName, newValue); actualChanges.put("locale", localeAsInput); lockinPeriodType = PeriodFrequencyType.fromInt(newValue); } - + account.update(product, externalId, commencementDate, deposit, tenureInMonths, maturityInterestRate, preClosureInterestRate, - interestCompoundedEvery, interestCompoundedEveryPeriodType, renewalAllowed, preClosureAllowed, isInterestWithdrawable, + interestCompoundedEvery, interestCompoundedEveryPeriodType, renewalAllowed, preClosureAllowed, isInterestWithdrawable, isInterestCompoundingAllowed, this.fixedTermDepositInterestCalculator, isLockinPeriodAllowed, lockinPeriod, lockinPeriodType); - + return actualChanges; } - public Map updateApprovedDepositAccount(DepositAccount account, JsonCommand command) { - - final Map actualChanges = new LinkedHashMap(20); - final String localeAsInput = command.locale(); - - Boolean renewalAllowed = account.isRenewalAllowed(); + public Map updateApprovedDepositAccount(final DepositAccount account, final JsonCommand command) { + + final Map actualChanges = new LinkedHashMap(20); + final String localeAsInput = command.locale(); + + Boolean renewalAllowed = account.isRenewalAllowed(); final String renewalAllowedParamName = "renewalAllowed"; if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, renewalAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName); actualChanges.put(renewalAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); renewalAllowed = newValue; @@ -488,28 +494,28 @@ public class DepositAccountAssembler { Boolean isInterestWithdrawable = account.isInterestWithdrawable(); final String isInterestWithdrawableParamName = "isInterestWithdrawable"; if (command.isChangeInBooleanParameterNamed(isInterestWithdrawableParamName, isInterestWithdrawable)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName); actualChanges.put(isInterestWithdrawableParamName, newValue); actualChanges.put("locale", localeAsInput); isInterestWithdrawable = newValue; } - + account.update(renewalAllowed, isInterestWithdrawable); - + return actualChanges; } - public void postInterest(DepositAccount account) { - account.postInterestForDepositAccount(account, this.fixedTermDepositInterestCalculator); + public void postInterest(final DepositAccount account) { + account.postInterestForDepositAccount(this.fixedTermDepositInterestCalculator); + } + + private Boolean isBooleanValueUpdated(final Boolean actualValue) { + Boolean isUpdated = false; + if (actualValue != null) { + isUpdated = true; + } + return isUpdated; } - - private Boolean isBooleanValueUpdated(Boolean actualValue) { - Boolean isUpdated = false; - if(actualValue != null){ - isUpdated = true; - } - return isUpdated; - } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/domain/DepositProduct.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/domain/DepositProduct.java index 2ff6bf4a7..d5287f0e6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/domain/DepositProduct.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/domain/DepositProduct.java @@ -24,193 +24,214 @@ import org.mifosplatform.portfolio.savingsdepositproduct.exception.DepositProduc import org.mifosplatform.useradministration.domain.AppUser; @Entity -@Table(name = "m_product_deposit", uniqueConstraints={ - @UniqueConstraint(columnNames = {"name"}, name="name_deposit_product"), - @UniqueConstraint(columnNames = {"external_id"}, name="externalid_deposit_product") -}) +@Table(name = "m_product_deposit", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "name_deposit_product"), + @UniqueConstraint(columnNames = { "external_id" }, name = "externalid_deposit_product") }) public class DepositProduct extends AbstractAuditableCustom { - - @Column(name = "name", nullable = false) - private String name; - - @Column(name = "external_id", length=100) - private String externalId; - @SuppressWarnings("unused") - @Column(name = "description") - private String description; - - @Column(name = "is_deleted", nullable=false) - private boolean deleted = false; - + @Column(name = "name", nullable = false) + private String name; + + @Column(name = "external_id", length = 100) + private String externalId; + + @Column(name = "description") + private String description; + + @Column(name = "is_deleted", nullable = false) + private boolean deleted = false; + @Embedded - private MonetaryCurrency currency; - - @Column(name = "minimum_balance", scale = 6, precision = 19, nullable = false) - private BigDecimal minimumBalance; - - @Column(name = "maximum_balance", scale = 6, precision = 19, nullable = false) - private BigDecimal maximumBalance; - - @Column(name = "interest_compounded_every", nullable=false) - private Integer interestCompoundedEvery; - - @Column(name = "interest_compounded_every_period_enum", nullable=false) - private PeriodFrequencyType interestCompoundedEveryPeriodType; - - @Column(name = "maturity_default_interest_rate", scale = 6, precision = 19, nullable = false) - private BigDecimal maturityDefaultInterestRate; - - @Column(name = "maturity_min_interest_rate", scale = 6, precision = 19, nullable = false) - private BigDecimal maturityMinInterestRate; - - @Column(name = "maturity_max_interest_rate", scale = 6, precision = 19, nullable = false) - private BigDecimal maturityMaxInterestRate; - - @Column(name = "tenure_months", nullable=false) - private Integer tenureInMonths; - - @Column(name = "is_renewal_allowed", nullable=false) - private boolean renewalAllowed = false; - - @Column(name = "is_preclosure_allowed", nullable=false) - private boolean preClosureAllowed = false; - - @Column(name = "is_compounding_interest_allowed", nullable=false) - private boolean interestCompoundingAllowed = false; - - @Column(name = "pre_closure_interest_rate", scale = 6, precision = 19, nullable = false) - private BigDecimal preClosureInterestRate; - - @Column(name = "is_lock_in_period_allowed", nullable=false) - private boolean isLockinPeriodAllowed = false; - - @Column(name = "lock_in_period", nullable=false) - private Integer lockinPeriod; - - @Column(name = "lock_in_period_type", nullable=false) - private PeriodFrequencyType lockinPeriodType; - - protected DepositProduct() { - // - } - - public DepositProduct(final String name, final String externalId, - final String description, - final MonetaryCurrency currency, final BigDecimal minimumBalance, - final BigDecimal maximumBalance, final Integer tenureMonths, - final BigDecimal maturityDefaultInterestRate, - final BigDecimal maturityMinInterestRate, - final BigDecimal maturityMaxInterestRate, - final Integer interestCompoundedEvery, - final PeriodFrequencyType interestCompoundedEveryPeriodType, - final boolean canRenew, - final boolean canPreClose, - final BigDecimal preClosureInterestRate, - final boolean isInterestCompoundingAllowed, - final boolean isLockinPeriodAllowed, - final Integer lockinPeriod, - final PeriodFrequencyType lockinPeriodType) { - this.name = name.trim(); - if (StringUtils.isNotBlank(description)) { - this.description = description.trim(); - } else { - this.description = null; - } - if (StringUtils.isNotBlank(externalId)) { - this.externalId = externalId.trim(); - } else { - this.externalId = null; - } - - this.currency = currency; - this.minimumBalance = minimumBalance; - this.maximumBalance = maximumBalance; - this.tenureInMonths = tenureMonths; - this.maturityDefaultInterestRate = maturityDefaultInterestRate; - this.maturityMinInterestRate = maturityMinInterestRate; - this.maturityMaxInterestRate = maturityMaxInterestRate; - this.interestCompoundedEvery = interestCompoundedEvery; - this.interestCompoundedEveryPeriodType = interestCompoundedEveryPeriodType; - this.renewalAllowed = canRenew; - this.preClosureAllowed = canPreClose; - this.preClosureInterestRate = preClosureInterestRate; - this.interestCompoundingAllowed = isInterestCompoundingAllowed; - this.isLockinPeriodAllowed = isLockinPeriodAllowed; - this.lockinPeriod = lockinPeriod; - this.lockinPeriodType = lockinPeriodType; - } - - public MonetaryCurrency getCurrency() { - return currency; - } - - public Integer getInterestCompoundedEvery() { - return interestCompoundedEvery; - } + private MonetaryCurrency currency; - public PeriodFrequencyType getInterestCompoundedEveryPeriodType() { - return interestCompoundedEveryPeriodType; - } + @Column(name = "minimum_balance", scale = 6, precision = 19, nullable = false) + private BigDecimal minimumBalance; - public Integer getTenureInMonths() { - return tenureInMonths; - } - - public BigDecimal getMaturityDefaultInterestRate() { - return maturityDefaultInterestRate; - } + @Column(name = "maximum_balance", scale = 6, precision = 19, nullable = false) + private BigDecimal maximumBalance; - public BigDecimal getMaturityMinInterestRate() { - return maturityMinInterestRate; - } + @Column(name = "interest_compounded_every", nullable = false) + private Integer interestCompoundedEvery; - public BigDecimal getPreClosureInterestRate() { - return preClosureInterestRate; - } + @Column(name = "interest_compounded_every_period_enum", nullable = false) + private PeriodFrequencyType interestCompoundedEveryPeriodType; - public boolean isRenewalAllowed() { - return this.renewalAllowed; - } + @Column(name = "maturity_default_interest_rate", scale = 6, precision = 19, nullable = false) + private BigDecimal maturityDefaultInterestRate; - public boolean isPreClosureAllowed() { - return this.preClosureAllowed; - } - - public boolean isInterestCompoundingAllowed() { - return interestCompoundingAllowed; - } + @Column(name = "maturity_min_interest_rate", scale = 6, precision = 19, nullable = false) + private BigDecimal maturityMinInterestRate; - public boolean isLockinPeriodAllowed() { - return isLockinPeriodAllowed; - } + @Column(name = "maturity_max_interest_rate", scale = 6, precision = 19, nullable = false) + private BigDecimal maturityMaxInterestRate; - public Integer getLockinPeriod() { - return lockinPeriod; - } + @Column(name = "tenure_months", nullable = false) + private Integer tenureInMonths; - public PeriodFrequencyType getLockinPeriodType() { - return lockinPeriodType; - } + @Column(name = "is_renewal_allowed", nullable = false) + private boolean renewalAllowed = false; - public boolean isDeleted() { - return deleted; - } - - /** - * Delete is a soft delete. Updates flag on product so it wont appear in query/report results. - * - * Any fields with unique constraints and prepended with id of record. - */ - public void delete() { - this.deleted = true; - this.name = this.getId() + "_DELETED_" + this.name; - this.externalId = this.getId() + "_DELETED_" + this.externalId; - } - - public Map update(final JsonCommand command){ - - final Map actualChanges = new LinkedHashMap(20); + @Column(name = "is_preclosure_allowed", nullable = false) + private boolean preClosureAllowed = false; + + @Column(name = "is_compounding_interest_allowed", nullable = false) + private boolean interestCompoundingAllowed = false; + + @Column(name = "pre_closure_interest_rate", scale = 6, precision = 19, nullable = false) + private BigDecimal preClosureInterestRate; + + @Column(name = "is_lock_in_period_allowed", nullable = false) + private boolean isLockinPeriodAllowed = false; + + @Column(name = "lock_in_period", nullable = false) + private Integer lockinPeriod; + + @Column(name = "lock_in_period_type", nullable = false) + private PeriodFrequencyType lockinPeriodType; + + public static DepositProduct assembleFromJson(final JsonCommand command, final PeriodFrequencyType interestCompoundingPeriodType, + final PeriodFrequencyType lockinPeriodType) { + + final String name = command.stringValueOfParameterNamed("name"); + final String externalId = command.stringValueOfParameterNamed("externalId"); + final String description = command.stringValueOfParameterNamed("description"); + final String currencyCode = command.stringValueOfParameterNamed("currencyCode"); + final Integer digitsAfterDecimal = command.integerValueOfParameterNamed("digitsAfterDecimal"); + + final MonetaryCurrency currency = new MonetaryCurrency(currencyCode, digitsAfterDecimal); + final BigDecimal minimumBalance = command.bigDecimalValueOfParameterNamed("minimumBalance"); + final BigDecimal maximumBalance = command.bigDecimalValueOfParameterNamed("maximumBalance"); + + final Integer tenureMonths = command.integerValueOfParameterNamed("tenureInMonths"); + final BigDecimal maturityDefaultInterestRate = command.bigDecimalValueOfParameterNamed("maturityDefaultInterestRate"); + final BigDecimal maturityMinInterestRate = command.bigDecimalValueOfParameterNamed("maturityMinInterestRate"); + final BigDecimal maturityMaxInterestRate = command.bigDecimalValueOfParameterNamed("maturityMaxInterestRate"); + final Integer interestCompoundedEvery = command.integerValueOfParameterNamed("interestCompoundedEvery"); + + final boolean canRenew = command.booleanPrimitiveValueOfParameterNamed("canRenew"); + final boolean canPreClose = command.booleanPrimitiveValueOfParameterNamed("canPreClose"); + final BigDecimal preClosureInterestRate = command.bigDecimalValueOfParameterNamed("preClosureInterestRate"); + final boolean isInterestCompoundingAllowed = command.booleanPrimitiveValueOfParameterNamed("isInterestCompoundingAllowed"); + final boolean isLockinPeriodAllowed = command.booleanPrimitiveValueOfParameterNamed("isLockinPeriodAllowed"); + final Integer lockinPeriod = command.integerValueOfParameterNamed("lockinPeriod"); + + return new DepositProduct(name, externalId, description, currency, minimumBalance, maximumBalance, tenureMonths, + maturityDefaultInterestRate, maturityMinInterestRate, maturityMaxInterestRate, interestCompoundedEvery, + interestCompoundingPeriodType, canRenew, canPreClose, preClosureInterestRate, isInterestCompoundingAllowed, + isLockinPeriodAllowed, lockinPeriod, lockinPeriodType); + } + + protected DepositProduct() { + // + } + + private DepositProduct(final String name, final String externalId, final String description, final MonetaryCurrency currency, + final BigDecimal minimumBalance, final BigDecimal maximumBalance, final Integer tenureMonths, + final BigDecimal maturityDefaultInterestRate, final BigDecimal maturityMinInterestRate, + final BigDecimal maturityMaxInterestRate, final Integer interestCompoundedEvery, + final PeriodFrequencyType interestCompoundedEveryPeriodType, final boolean canRenew, final boolean canPreClose, + final BigDecimal preClosureInterestRate, final boolean isInterestCompoundingAllowed, final boolean isLockinPeriodAllowed, + final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType) { + this.name = name.trim(); + if (StringUtils.isNotBlank(description)) { + this.description = description.trim(); + } else { + this.description = null; + } + if (StringUtils.isNotBlank(externalId)) { + this.externalId = externalId.trim(); + } else { + this.externalId = null; + } + + this.currency = currency; + this.minimumBalance = minimumBalance; + this.maximumBalance = maximumBalance; + this.tenureInMonths = tenureMonths; + this.maturityDefaultInterestRate = maturityDefaultInterestRate; + this.maturityMinInterestRate = maturityMinInterestRate; + this.maturityMaxInterestRate = maturityMaxInterestRate; + this.interestCompoundedEvery = interestCompoundedEvery; + this.interestCompoundedEveryPeriodType = interestCompoundedEveryPeriodType; + this.renewalAllowed = canRenew; + this.preClosureAllowed = canPreClose; + this.preClosureInterestRate = preClosureInterestRate; + this.interestCompoundingAllowed = isInterestCompoundingAllowed; + this.isLockinPeriodAllowed = isLockinPeriodAllowed; + this.lockinPeriod = lockinPeriod; + this.lockinPeriodType = lockinPeriodType; + } + + public MonetaryCurrency getCurrency() { + return currency; + } + + public Integer getInterestCompoundedEvery() { + return interestCompoundedEvery; + } + + public PeriodFrequencyType getInterestCompoundedEveryPeriodType() { + return interestCompoundedEveryPeriodType; + } + + public Integer getTenureInMonths() { + return tenureInMonths; + } + + public BigDecimal getMaturityDefaultInterestRate() { + return maturityDefaultInterestRate; + } + + public BigDecimal getMaturityMinInterestRate() { + return maturityMinInterestRate; + } + + public BigDecimal getPreClosureInterestRate() { + return preClosureInterestRate; + } + + public boolean isRenewalAllowed() { + return this.renewalAllowed; + } + + public boolean isPreClosureAllowed() { + return this.preClosureAllowed; + } + + public boolean isInterestCompoundingAllowed() { + return interestCompoundingAllowed; + } + + public boolean isLockinPeriodAllowed() { + return isLockinPeriodAllowed; + } + + public Integer getLockinPeriod() { + return lockinPeriod; + } + + public PeriodFrequencyType getLockinPeriodType() { + return lockinPeriodType; + } + + public boolean isDeleted() { + return deleted; + } + + /** + * Delete is a soft delete. Updates flag on product so it wont appear + * in query/report results. + * + * Any fields with unique constraints and prepended with id of record. + */ + public void delete() { + this.deleted = true; + this.name = this.getId() + "_DELETED_" + this.name; + this.externalId = this.getId() + "_DELETED_" + this.externalId; + } + + public Map update(final JsonCommand command) { + + final Map actualChanges = new LinkedHashMap(20); final String localeAsInput = command.locale(); @@ -227,17 +248,17 @@ public class DepositProduct extends AbstractAuditableCustom { actualChanges.put(descriptionParamName, newValue); this.description = newValue; } - + final String externalIdParamName = "externalId"; if (command.isChangeInStringParameterNamed(externalIdParamName, this.externalId)) { final String newValue = command.stringValueOfParameterNamed(externalIdParamName); actualChanges.put(externalIdParamName, newValue); this.externalId = newValue; } - + String currencyCode = this.currency.getCode(); Integer digitsAfterDecimal = this.currency.getDigitsAfterDecimal(); - + final String digitsAfterDecimalParamName = "digitsAfterDecimal"; if (command.isChangeInIntegerParameterNamed(digitsAfterDecimalParamName, digitsAfterDecimal)) { final Integer newValue = command.integerValueOfParameterNamed(digitsAfterDecimalParamName); @@ -254,7 +275,7 @@ public class DepositProduct extends AbstractAuditableCustom { currencyCode = newValue; this.currency = new MonetaryCurrency(currencyCode, digitsAfterDecimal); } - + final String minimumBalanceParamName = "minimumBalance"; if (command.isChangeInBigDecimalParameterNamed(minimumBalanceParamName, this.minimumBalance)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(minimumBalanceParamName); @@ -262,7 +283,7 @@ public class DepositProduct extends AbstractAuditableCustom { actualChanges.put("locale", localeAsInput); this.minimumBalance = newValue; } - + final String maximumBalanceParamName = "maximumBalance"; if (command.isChangeInBigDecimalParameterNamed(maximumBalanceParamName, this.maximumBalance)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(maximumBalanceParamName); @@ -270,7 +291,7 @@ public class DepositProduct extends AbstractAuditableCustom { actualChanges.put("locale", localeAsInput); this.maximumBalance = newValue; } - + final String tenureInMonthsParamName = "tenureInMonths"; if (command.isChangeInIntegerParameterNamed(tenureInMonthsParamName, this.tenureInMonths)) { final Integer newValue = command.integerValueOfParameterNamed(tenureInMonthsParamName); @@ -278,7 +299,7 @@ public class DepositProduct extends AbstractAuditableCustom { actualChanges.put("locale", localeAsInput); this.tenureInMonths = newValue; } - + final String defaultInterestRateParamName = "maturityDefaultInterestRate"; if (command.isChangeInBigDecimalParameterNamed(defaultInterestRateParamName, this.maturityDefaultInterestRate)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(defaultInterestRateParamName); @@ -286,7 +307,7 @@ public class DepositProduct extends AbstractAuditableCustom { actualChanges.put("locale", localeAsInput); this.maturityDefaultInterestRate = newValue; } - + final String minInterestRateParamName = "maturityMinInterestRate"; if (command.isChangeInBigDecimalParameterNamed(minInterestRateParamName, this.maturityMinInterestRate)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(minInterestRateParamName); @@ -294,7 +315,7 @@ public class DepositProduct extends AbstractAuditableCustom { actualChanges.put("locale", localeAsInput); this.maturityMinInterestRate = newValue; } - + final String maxInterestRateParamName = "maturityMaxInterestRate"; if (command.isChangeInBigDecimalParameterNamed(maxInterestRateParamName, this.maturityMaxInterestRate)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(maxInterestRateParamName); @@ -302,7 +323,7 @@ public class DepositProduct extends AbstractAuditableCustom { actualChanges.put("locale", localeAsInput); this.maturityMaxInterestRate = newValue; } - + final String interestCompoundedEveryParamName = "interestCompoundedEvery"; if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryParamName, this.interestCompoundedEvery)) { final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryParamName); @@ -310,31 +331,32 @@ public class DepositProduct extends AbstractAuditableCustom { actualChanges.put("locale", localeAsInput); this.interestCompoundedEvery = newValue; } - + final String interestCompoundedEveryPeriodTypeParamName = "interestCompoundedEveryPeriodType"; - if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryPeriodTypeParamName, this.interestCompoundedEveryPeriodType.getValue())) { + if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryPeriodTypeParamName, + this.interestCompoundedEveryPeriodType.getValue())) { final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryPeriodTypeParamName); actualChanges.put(interestCompoundedEveryPeriodTypeParamName, newValue); actualChanges.put("locale", localeAsInput); this.interestCompoundedEveryPeriodType = PeriodFrequencyType.fromInt(newValue); } - + final String renewalAllowedParamName = "renewalAllowed"; if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, this.renewalAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName); actualChanges.put(renewalAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); this.renewalAllowed = newValue; } - + final String preClosureAllowedParamName = "preClosureAllowed"; if (command.isChangeInBooleanParameterNamed(preClosureAllowedParamName, this.preClosureAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName); actualChanges.put(preClosureAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); this.preClosureAllowed = newValue; } - + final String preClosureInterestRateParamName = "preClosureInterestRate"; if (command.isChangeInBigDecimalParameterNamed(preClosureInterestRateParamName, this.preClosureInterestRate)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(preClosureInterestRateParamName); @@ -343,106 +365,74 @@ public class DepositProduct extends AbstractAuditableCustom { this.preClosureInterestRate = newValue; } - final String interestCompoundingAllowedParamName = "interestCompoundingAllowed"; + final String interestCompoundingAllowedParamName = "interestCompoundingAllowed"; if (command.isChangeInBooleanParameterNamed(interestCompoundingAllowedParamName, this.interestCompoundingAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(interestCompoundingAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(interestCompoundingAllowedParamName); actualChanges.put(interestCompoundingAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); this.interestCompoundingAllowed = newValue; } - + final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed"; if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, this.isLockinPeriodAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName); actualChanges.put(isLockinPeriodAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); this.isLockinPeriodAllowed = newValue; } - - final String lockinPeriodParamName = "lockinPeriod"; + + final String lockinPeriodParamName = "lockinPeriod"; if (command.isChangeInIntegerParameterNamed(lockinPeriodParamName, this.lockinPeriod)) { final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodParamName); actualChanges.put(lockinPeriodParamName, newValue); actualChanges.put("locale", localeAsInput); this.lockinPeriod = newValue; } - - - final String lockinPeriodTypeParamName = "lockinPeriodType"; + + final String lockinPeriodTypeParamName = "lockinPeriodType"; if (command.isChangeInIntegerParameterNamed(lockinPeriodTypeParamName, this.lockinPeriodType.getValue())) { final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodTypeParamName); actualChanges.put(lockinPeriodTypeParamName, newValue); actualChanges.put("locale", localeAsInput); this.lockinPeriodType = PeriodFrequencyType.fromInt(newValue); } - + return actualChanges; - } - - public void validateInterestRateInRange(final BigDecimal interestRate) { - boolean inRange = true; - if (interestRate.compareTo(this.maturityMinInterestRate) < 0) { - inRange = false; - } - - if (this.maturityMaxInterestRate.compareTo(interestRate) < 0) { - inRange = false; - } - - if (!inRange) { - final String actualValue = interestRate.toPlainString(); - final String minValue = (this.maturityMinInterestRate == null) ? "" : this.maturityMinInterestRate.toPlainString(); - final String maxValue = (this.maturityMaxInterestRate == null) ? "" : this.maturityMaxInterestRate.toPlainString(); - throw new DepositProductValueOutsideRangeException(actualValue, minValue, maxValue, "deposit.account.maturityInterestRate"); - } - } + } - public void validateDepositInRange(final BigDecimal depositAmount) { - boolean inRange = true; - if (depositAmount.compareTo(this.minimumBalance) < 0) { - inRange = false; - } - - if (this.maximumBalance != null && this.maximumBalance.compareTo(depositAmount) < 0) { - inRange = false; - } - - if (!inRange) { - final String actualValue = depositAmount.toPlainString(); - final String minValue = (this.minimumBalance == null) ? "" : this.minimumBalance.toPlainString(); - final String maxValue = (this.maximumBalance == null) ? "" : this.maximumBalance.toPlainString(); - throw new DepositProductValueOutsideRangeException(actualValue, minValue, maxValue, "deposit.account.deposit.amount"); - } - } + public void validateInterestRateInRange(final BigDecimal interestRate) { + boolean inRange = true; + if (interestRate.compareTo(this.maturityMinInterestRate) < 0) { + inRange = false; + } - public static DepositProduct assembleFromJson(JsonCommand command, PeriodFrequencyType interestCompoundingPeriodType, - PeriodFrequencyType lockinPeriodType) { - - final String name = command.stringValueOfParameterNamed("name"); - final String externalId = command.stringValueOfParameterNamed("externalId"); - final String description = command.stringValueOfParameterNamed("description"); - final String currencyCode = command.stringValueOfParameterNamed("currencyCode"); - final Integer digitsAfterDecimal = command.integerValueOfParameterNamed("digitsAfterDecimal"); - - final MonetaryCurrency currency = new MonetaryCurrency(currencyCode, digitsAfterDecimal); - final BigDecimal minimumBalance = command.bigDecimalValueOfParameterNamed("minimumBalance"); - final BigDecimal maximumBalance = command.bigDecimalValueOfParameterNamed("maximumBalance"); - - final Integer tenureMonths = command.integerValueOfParameterNamed("tenureInMonths"); - final BigDecimal maturityDefaultInterestRate = command.bigDecimalValueOfParameterNamed("maturityDefaultInterestRate"); - final BigDecimal maturityMinInterestRate = command.bigDecimalValueOfParameterNamed("maturityMinInterestRate"); - final BigDecimal maturityMaxInterestRate = command.bigDecimalValueOfParameterNamed("maturityMaxInterestRate"); - final Integer interestCompoundedEvery = command.integerValueOfParameterNamed("interestCompoundedEvery"); - - final boolean canRenew = command.booleanPrimitiveValueOfParameterNamed("canRenew"); - final boolean canPreClose = command.booleanPrimitiveValueOfParameterNamed("canPreClose"); - final BigDecimal preClosureInterestRate = command.bigDecimalValueOfParameterNamed("preClosureInterestRate"); - final boolean isInterestCompoundingAllowed = command.booleanPrimitiveValueOfParameterNamed("isInterestCompoundingAllowed"); - final boolean isLockinPeriodAllowed = command.booleanPrimitiveValueOfParameterNamed("isLockinPeriodAllowed"); - final Integer lockinPeriod = command.integerValueOfParameterNamed("lockinPeriod"); - - return new DepositProduct(name, externalId, description, currency, minimumBalance, maximumBalance, tenureMonths, maturityDefaultInterestRate, - maturityMinInterestRate, maturityMaxInterestRate, interestCompoundedEvery, interestCompoundingPeriodType, canRenew, canPreClose, - preClosureInterestRate, isInterestCompoundingAllowed, isLockinPeriodAllowed, lockinPeriod, lockinPeriodType); - } + if (this.maturityMaxInterestRate.compareTo(interestRate) < 0) { + inRange = false; + } + + if (!inRange) { + final String actualValue = interestRate.toPlainString(); + final String minValue = (this.maturityMinInterestRate == null) ? "" : this.maturityMinInterestRate.toPlainString(); + final String maxValue = (this.maturityMaxInterestRate == null) ? "" : this.maturityMaxInterestRate.toPlainString(); + throw new DepositProductValueOutsideRangeException(actualValue, minValue, maxValue, "deposit.account.maturityInterestRate"); + } + } + + public void validateDepositInRange(final BigDecimal depositAmount) { + boolean inRange = true; + if (depositAmount.compareTo(this.minimumBalance) < 0) { + inRange = false; + } + + if (this.maximumBalance != null && this.maximumBalance.compareTo(depositAmount) < 0) { + inRange = false; + } + + if (!inRange) { + final String actualValue = depositAmount.toPlainString(); + final String minValue = (this.minimumBalance == null) ? "" : this.minimumBalance.toPlainString(); + final String maxValue = (this.maximumBalance == null) ? "" : this.maximumBalance.toPlainString(); + throw new DepositProductValueOutsideRangeException(actualValue, minValue, maxValue, "deposit.account.deposit.amount"); + } + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/exception/DepositProductValueOutsideRangeException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/exception/DepositProductValueOutsideRangeException.java index 3219d2e13..ee6f2f96a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/exception/DepositProductValueOutsideRangeException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/exception/DepositProductValueOutsideRangeException.java @@ -12,7 +12,8 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRul */ public class DepositProductValueOutsideRangeException extends AbstractPlatformDomainRuleException { - public DepositProductValueOutsideRangeException(final String actualValue, final String rangeMin, final String rangeMax, final String fieldCode) { + public DepositProductValueOutsideRangeException(final String actualValue, final String rangeMin, final String rangeMax, + final String fieldCode) { super("error.msg." + fieldCode + ".outside.of.allowed.range", actualValue + " is outside of allowed range of [" + rangeMin + ", " + rangeMax + "].", actualValue, rangeMin, rangeMax); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/handler/CreateDepositProductCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/handler/CreateDepositProductCommandHandler.java index da9afb813..fc2e9f5c3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/handler/CreateDepositProductCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/handler/CreateDepositProductCommandHandler.java @@ -9,17 +9,16 @@ import org.springframework.stereotype.Service; @Service public class CreateDepositProductCommandHandler implements NewCommandSourceHandler { - - private final DepositProductWritePlatformService depositProductWritePlatformService; - - @Autowired - public CreateDepositProductCommandHandler(final DepositProductWritePlatformService depositProductWritePlatformService) { - this.depositProductWritePlatformService = depositProductWritePlatformService; - } - @Override - public CommandProcessingResult processCommand(JsonCommand command) { - return this.depositProductWritePlatformService.createDepositProduct(command); - } + private final DepositProductWritePlatformService depositProductWritePlatformService; -} + @Autowired + public CreateDepositProductCommandHandler(final DepositProductWritePlatformService depositProductWritePlatformService) { + this.depositProductWritePlatformService = depositProductWritePlatformService; + } + + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositProductWritePlatformService.createDepositProduct(command); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformService.java index a389cd2b7..8ba7255eb 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformService.java @@ -15,9 +15,8 @@ public interface DepositProductWritePlatformService { CommandProcessingResult createDepositProduct(JsonCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'UPDATE_DEPOSITPRODUCT')") - CommandProcessingResult updateDepositProduct(Long productId,JsonCommand command); + CommandProcessingResult updateDepositProduct(Long productId, JsonCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'DELETE_DEPOSITPRODUCT')") CommandProcessingResult deleteDepositProduct(Long productId); - } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformServiceJpaRepositoryImpl.java index fb1dfe753..58de6f975 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformServiceJpaRepositoryImpl.java @@ -49,77 +49,77 @@ public class DepositProductWritePlatformServiceJpaRepositoryImpl implements Depo private void handleDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) { Throwable realCause = dve.getMostSpecificCause(); - if (realCause.getMessage().contains("name_deposit_product")) { - final String name = command.stringValueOfParameterNamed("name"); - throw new PlatformDataIntegrityException( - "error.msg.desposit.product.duplicate.name", "Deposit product with name: " + name + " already exists", "name", - name); } + if (realCause.getMessage().contains("name_deposit_product")) { + final String name = command.stringValueOfParameterNamed("name"); + throw new PlatformDataIntegrityException("error.msg.desposit.product.duplicate.name", "Deposit product with name: " + name + + " already exists", "name", name); + } if (realCause.getMessage().contains("externalid_deposit_product")) { - final String externalId = command.stringValueOfParameterNamed("externalId"); - throw new PlatformDataIntegrityException( - "error.msg.desposit.product.duplicate.externalId", "Deposit product with externalId " + externalId - + " already exists", "externalId", externalId); } + final String externalId = command.stringValueOfParameterNamed("externalId"); + throw new PlatformDataIntegrityException("error.msg.desposit.product.duplicate.externalId", "Deposit product with externalId " + + externalId + " already exists", "externalId", externalId); + } logger.error(dve.getMessage(), dve); throw new PlatformDataIntegrityException("error.msg.deposit.product.unknown.data.integrity.issue", "Unknown data integrity issue with resource."); } - @Transactional + @Transactional @Override - public CommandProcessingResult createDepositProduct(JsonCommand command) { - try { - this.context.authenticatedUser(); - this.fromApiJsonDeserializer.validateForCreate(command.json()); - - final Integer interestCompoundingPeriodTypeIntValue = command.integerValueOfParameterNamed("interestCompoundedEveryPeriodType"); - PeriodFrequencyType interestCompoundingPeriodType = PeriodFrequencyType.fromInt(interestCompoundingPeriodTypeIntValue); - - final Integer lockinPeriodTypeIntValue = command.integerValueOfParameterNamed("lockinPeriodType"); - PeriodFrequencyType lockinPeriodType = PeriodFrequencyType.fromInt(lockinPeriodTypeIntValue); - - DepositProduct product = DepositProduct.assembleFromJson(command,interestCompoundingPeriodType,lockinPeriodType); - - this.depositProductRepository.save(product); - - return new CommandProcessingResultBuilder() // - .withEntityId(product.getId()) // - .build(); - } catch (DataIntegrityViolationException dve) { - handleDataIntegrityIssues(command, dve); - return new CommandProcessingResult(Long.valueOf(-1)); - } - } + public CommandProcessingResult createDepositProduct(final JsonCommand command) { + try { + this.context.authenticatedUser(); + this.fromApiJsonDeserializer.validateForCreate(command.json()); - @Transactional - @Override - public CommandProcessingResult updateDepositProduct(final Long productId, final JsonCommand command) { - try { - - this.context.authenticatedUser(); - - this.fromApiJsonDeserializer.validateForUpdate(command.json()); - - DepositProduct product = this.depositProductRepository.findOne(productId); + final Integer interestCompoundingPeriodTypeIntValue = command.integerValueOfParameterNamed("interestCompoundedEveryPeriodType"); + PeriodFrequencyType interestCompoundingPeriodType = PeriodFrequencyType.fromInt(interestCompoundingPeriodTypeIntValue); + + final Integer lockinPeriodTypeIntValue = command.integerValueOfParameterNamed("lockinPeriodType"); + PeriodFrequencyType lockinPeriodType = PeriodFrequencyType.fromInt(lockinPeriodTypeIntValue); + + DepositProduct product = DepositProduct.assembleFromJson(command, interestCompoundingPeriodType, lockinPeriodType); + + this.depositProductRepository.save(product); + + return new CommandProcessingResultBuilder() // + .withEntityId(product.getId()) // + .build(); + } catch (DataIntegrityViolationException dve) { + handleDataIntegrityIssues(command, dve); + return new CommandProcessingResult(Long.valueOf(-1)); + } + } + + @Transactional + @Override + public CommandProcessingResult updateDepositProduct(final Long productId, final JsonCommand command) { + try { + + this.context.authenticatedUser(); + + this.fromApiJsonDeserializer.validateForUpdate(command.json()); + + DepositProduct product = this.depositProductRepository.findOne(productId); if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(productId); } - - final Map changes = product.update(command); - - if (!changes.isEmpty()) { + + final Map changes = product.update(command); + + if (!changes.isEmpty()) { this.depositProductRepository.saveAndFlush(product); } - - return new CommandProcessingResultBuilder() // - .withCommandId(command.commandId()) // - .withEntityId(productId) // - .with(changes) // - .build(); - - } catch (DataIntegrityViolationException dve) { - handleDataIntegrityIssues(command, dve); - return new CommandProcessingResult(Long.valueOf(-1)); - } - } + + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(productId) // + .with(changes) // + .build(); + + } catch (DataIntegrityViolationException dve) { + handleDataIntegrityIssues(command, dve); + return new CommandProcessingResult(Long.valueOf(-1)); + } + } @Transactional @Override @@ -136,5 +136,4 @@ public class DepositProductWritePlatformServiceJpaRepositoryImpl implements Depo .withEntityId(product.getId()) // .build(); } - } \ No newline at end of file