Merge remote-tracking branch 'madhukar/MIFOSX-144-Final'
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
CREATE TABLE `extra_client_details_hugo_specific` (
|
||||||
|
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||||
|
`client_id` bigint(20) NOT NULL,
|
||||||
|
`client_dob` date DEFAULT NULL,
|
||||||
|
`client_address` varchar(60) DEFAULT NULL,
|
||||||
|
`father_name` varchar(40) DEFAULT NULL,
|
||||||
|
`nominee` varchar(40) DEFAULT NULL,
|
||||||
|
`nominee_relationship` varchar(40) DEFAULT NULL,
|
||||||
|
`nominee_address` varchar(60) DEFAULT NULL,
|
||||||
|
`crime_no` varchar(40) DEFAULT NULL,
|
||||||
|
`police_station` varchar(40) DEFAULT NULL,
|
||||||
|
`other_notes` text,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `client_id` (`client_id`),
|
||||||
|
KEY `FK_extra_client_details_hugo_specific_1` (`client_id`),
|
||||||
|
CONSTRAINT `FK_extra_client_details_hugo_specific` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
|
||||||
@@ -360,4 +360,40 @@ public class CommandWrapper {
|
|||||||
public boolean isUpdateOfOwnUserDetails(final Long loggedInUserId) {
|
public boolean isUpdateOfOwnUserDetails(final Long loggedInUserId) {
|
||||||
return this.isUserResource() && isUpdate() && loggedInUserId.equals(this.entityId);
|
return this.isUserResource() && isUpdate() && loggedInUserId.equals(this.entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDepositProductResource() {
|
||||||
|
return this.entityName.equalsIgnoreCase("DEPOSITPRODUCT");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDepositAccountResource() {
|
||||||
|
return this.entityName.equalsIgnoreCase("DEPOSITACCOUNT");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isApprovalOfDeposit() {
|
||||||
|
return this.actionName.equalsIgnoreCase("APPROVE") && this.entityName.equalsIgnoreCase("DEPOSITACCOUNT");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWithdrawDepositAmount() {
|
||||||
|
return this.actionName.equalsIgnoreCase("WITHDRAWAL") && this.entityName.equalsIgnoreCase("DEPOSITACCOUNT");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWithdrawInterest() {
|
||||||
|
return this.actionName.equalsIgnoreCase("INTEREST") && this.entityName.equalsIgnoreCase("DEPOSITACCOUNT");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRenewOfDepositApplicaion() {
|
||||||
|
return this.actionName.equalsIgnoreCase("RENEW") && this.entityName.equalsIgnoreCase("DEPOSITACCOUNT");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRejectionOfDepositApplicaion() {
|
||||||
|
return this.actionName.equalsIgnoreCase("REJECT") && this.entityName.equalsIgnoreCase("DEPOSITACCOUNT");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWithdrawByApplicant() {
|
||||||
|
return this.actionName.equalsIgnoreCase("WITHDRAW") && this.entityName.equalsIgnoreCase("DEPOSITACCOUNT");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUndoApprovalOfDepositApplication() {
|
||||||
|
return this.actionName.equalsIgnoreCase("APPROVALUNDO") && this.entityName.equalsIgnoreCase("DEPOSITACCOUNT");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+105
@@ -665,4 +665,109 @@ public class CommandWrapperBuilder {
|
|||||||
this.href = "/journalentries/"+transactionId;
|
this.href = "/journalentries/"+transactionId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder createDepositProduct() {
|
||||||
|
this.actionName = "CREATE";
|
||||||
|
this.entityName = "DEPOSITPRODUCT";
|
||||||
|
this.entityId = null;
|
||||||
|
this.href = "/depositproducts/template";
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder updateDepositProduct(final Long productId) {
|
||||||
|
this.actionName = "UPDATE";
|
||||||
|
this.entityName = "DEPOSITPRODUCT";
|
||||||
|
this.entityId = productId;
|
||||||
|
this.href = "/depositproducts/"+productId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder deleteDepositProduct(final Long productId) {
|
||||||
|
this.actionName = "DELETE";
|
||||||
|
this.entityName = "DEPOSITPRODUCT";
|
||||||
|
this.entityId = productId;
|
||||||
|
this.href = "/depositproducts/"+productId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder createDepositAccount() {
|
||||||
|
this.actionName = "CREATE";
|
||||||
|
this.entityName = "DEPOSITACCOUNT";
|
||||||
|
this.entityId = null;
|
||||||
|
this.href = "/depositaccounts/template";
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder updateDepositAccount(Long accountId) {
|
||||||
|
this.actionName = "UPDATE";
|
||||||
|
this.entityName = "DEPOSITACCOUNT";
|
||||||
|
this.entityId = accountId;
|
||||||
|
this.href = "/depositaccounts/"+accountId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder deleteDepositAccount(Long accountId) {
|
||||||
|
this.actionName = "DELETE";
|
||||||
|
this.entityName = "DEPOSITACCOUNT";
|
||||||
|
this.entityId = accountId;
|
||||||
|
this.href = "/depositaccounts/"+accountId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder approveDepositApplication(Long accountId) {
|
||||||
|
this.actionName = "APPROVE";
|
||||||
|
this.entityName = "DEPOSITACCOUNT";
|
||||||
|
this.entityId = accountId;
|
||||||
|
this.href = "/depositaccounts/"+accountId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder withdrawDepositAmount(Long accountId) {
|
||||||
|
this.actionName = "WITHDRAWAL";
|
||||||
|
this.entityName = "DEPOSITACCOUNT";
|
||||||
|
this.entityId = accountId;
|
||||||
|
this.href = "/depositaccounts/"+accountId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder withdrawInterestDepositAmount(Long accountId) {
|
||||||
|
this.actionName = "INTEREST";
|
||||||
|
this.entityName = "DEPOSITACCOUNT";
|
||||||
|
this.entityId = accountId;
|
||||||
|
this.href = "/depositaccounts/"+accountId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder renewDepositAccount(Long accountId) {
|
||||||
|
this.actionName = "RENEW";
|
||||||
|
this.entityName = "DEPOSITACCOUNT";
|
||||||
|
this.entityId = accountId;
|
||||||
|
this.href = "/depositaccounts/"+accountId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder rejectDepositAccount(Long accountId) {
|
||||||
|
this.actionName = "REJECT";
|
||||||
|
this.entityName = "DEPOSITACCOUNT";
|
||||||
|
this.entityId = accountId;
|
||||||
|
this.href = "/depositaccounts/"+accountId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder withdrawDepositApplication(Long accountId) {
|
||||||
|
this.actionName = "WITHDRAW";
|
||||||
|
this.entityName = "DEPOSITACCOUNT";
|
||||||
|
this.entityId = accountId;
|
||||||
|
this.href = "/depositaccounts/"+accountId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder undoDepositApplicationApproval(Long accountId) {
|
||||||
|
this.actionName = "APPROVALUNDO";
|
||||||
|
this.entityName = "DEPOSITACCOUNT";
|
||||||
|
this.entityId = accountId;
|
||||||
|
this.href = "/depositaccounts/"+accountId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+34
@@ -336,6 +336,40 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
|||||||
handler = applicationContext.getBean("reverseJournalEntryCommandHandler", NewCommandSourceHandler.class);
|
handler = applicationContext.getBean("reverseJournalEntryCommandHandler", NewCommandSourceHandler.class);
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedCommandException(wrapper.commandName());
|
throw new UnsupportedCommandException(wrapper.commandName());
|
||||||
|
}
|
||||||
|
} else if (wrapper.isDepositProductResource()) {
|
||||||
|
if (wrapper.isCreate()) {
|
||||||
|
handler = applicationContext.getBean("createDepositProductCommandHandler", NewCommandSourceHandler.class);
|
||||||
|
} else if (wrapper.isUpdate()) {
|
||||||
|
handler = applicationContext.getBean("updateDepositProductCommandHandler", NewCommandSourceHandler.class);
|
||||||
|
} else if (wrapper.isDelete()) {
|
||||||
|
handler = applicationContext.getBean("deleteDepositProductCommandHandler", NewCommandSourceHandler.class);
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedCommandException(wrapper.commandName());
|
||||||
|
}
|
||||||
|
} else if (wrapper.isDepositAccountResource()) {
|
||||||
|
if (wrapper.isCreate()) {
|
||||||
|
handler = applicationContext.getBean("createDepositAccountCommandHandler", NewCommandSourceHandler.class);
|
||||||
|
} else if (wrapper.isUpdate()) {
|
||||||
|
handler = applicationContext.getBean("updateDepositAccountCommandHandler", NewCommandSourceHandler.class);
|
||||||
|
} else if (wrapper.isDelete()) {
|
||||||
|
handler = applicationContext.getBean("deleteDepositAccountCommandHandler", NewCommandSourceHandler.class);
|
||||||
|
} else if (wrapper.isApprovalOfDeposit()) {
|
||||||
|
handler = applicationContext.getBean("approveDepositAccountCommandHandler", NewCommandSourceHandler.class);
|
||||||
|
} else if (wrapper.isWithdrawDepositAmount()) {
|
||||||
|
handler = applicationContext.getBean("withdrawDepositAccountAmountCommandHandler", NewCommandSourceHandler.class);
|
||||||
|
} else if (wrapper.isWithdrawInterest()) {
|
||||||
|
handler = applicationContext.getBean("withdrawInterestDepositAccountAmountCommandHandler", NewCommandSourceHandler.class);
|
||||||
|
} else if (wrapper.isRenewOfDepositApplicaion()) {
|
||||||
|
handler = applicationContext.getBean("renewDepositAccountCommandHandler", NewCommandSourceHandler.class);
|
||||||
|
} else if (wrapper.isRejectionOfDepositApplicaion()) {
|
||||||
|
handler = applicationContext.getBean("rejectDepositAccountCommandHandler", NewCommandSourceHandler.class);
|
||||||
|
} else if (wrapper.isWithdrawByApplicant()) {
|
||||||
|
handler = applicationContext.getBean("withDrawByApplicantDepositAccountCommandHandler", NewCommandSourceHandler.class);
|
||||||
|
} else if (wrapper.isUndoApprovalOfDepositApplication()) {
|
||||||
|
handler = applicationContext.getBean("undoApprovalDepositAccountCommandHandler", NewCommandSourceHandler.class);
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedCommandException(wrapper.commandName());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedCommandException(wrapper.commandName());
|
throw new UnsupportedCommandException(wrapper.commandName());
|
||||||
|
|||||||
+41
-39
@@ -70,34 +70,16 @@ import org.springframework.stereotype.Component;
|
|||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class SavingsAccountApiResource {
|
public class SavingsAccountApiResource {
|
||||||
|
|
||||||
@Autowired
|
private final SavingAccountWritePlatformService savingAccountWritePlatformService;
|
||||||
private SavingAccountWritePlatformService savingAccountWritePlatformService;
|
private final SavingAccountReadPlatformService savingAccountReadPlatformService;
|
||||||
|
private final PortfolioApiDataConversionService apiDataConversionService;
|
||||||
@Autowired
|
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||||
private SavingAccountReadPlatformService savingAccountReadPlatformService;
|
private final SavingProductReadPlatformService savingProductReadPlatformService;
|
||||||
|
private final CurrencyReadPlatformService currencyReadPlatformService;
|
||||||
@Autowired
|
|
||||||
private PortfolioApiDataConversionService apiDataConversionService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SavingProductReadPlatformService savingProductReadPlatformService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CurrencyReadPlatformService currencyReadPlatformService;
|
|
||||||
|
|
||||||
private final String entityType = "SAVINGSACCOUNT";
|
private final String entityType = "SAVINGSACCOUNT";
|
||||||
|
private final PlatformSecurityContext context;
|
||||||
@Autowired
|
private final CalculateSavingSchedule calculateSavingSchedule;
|
||||||
private PlatformSecurityContext context;
|
private final ToApiJsonSerializer<SavingAccountData> toApiJsonSerializer;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CalculateSavingSchedule calculateSavingSchedule;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ToApiJsonSerializer<SavingAccountData> toApiJsonSerializer;
|
|
||||||
|
|
||||||
private static final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "status", "externalId",
|
private static final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "status", "externalId",
|
||||||
"clientId", "clientName", "productId", "productName", "productType", "currencyData", "savingsDepostiAmountPerPeriod",
|
"clientId", "clientName", "productId", "productName", "productType", "currencyData", "savingsDepostiAmountPerPeriod",
|
||||||
@@ -107,6 +89,26 @@ public class SavingsAccountApiResource {
|
|||||||
"preClosureAllowed", "preClosureInterestRate", "withdrawnonDate", "rejectedonDate", "closedonDate", "isLockinPeriodAllowed",
|
"preClosureAllowed", "preClosureInterestRate", "withdrawnonDate", "rejectedonDate", "closedonDate", "isLockinPeriodAllowed",
|
||||||
"lockinPeriod", "lockinPeriodType", "outstandingAmount", "savingScheduleData", "transactions", "interestPostEvery",
|
"lockinPeriod", "lockinPeriodType", "outstandingAmount", "savingScheduleData", "transactions", "interestPostEvery",
|
||||||
"interestPostFrequency"));
|
"interestPostFrequency"));
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public SavingsAccountApiResource(final SavingAccountWritePlatformService savingAccountWritePlatformService,
|
||||||
|
final SavingAccountReadPlatformService savingAccountReadPlatformService,
|
||||||
|
final PortfolioApiDataConversionService apiDataConversionService,
|
||||||
|
final PortfolioApiJsonSerializerService apiJsonSerializerService,
|
||||||
|
final SavingProductReadPlatformService savingProductReadPlatformService,
|
||||||
|
final CurrencyReadPlatformService currencyReadPlatformService,
|
||||||
|
final PlatformSecurityContext context,final CalculateSavingSchedule calculateSavingSchedule,
|
||||||
|
final ToApiJsonSerializer<SavingAccountData> toApiJsonSerializer) {
|
||||||
|
this.savingAccountWritePlatformService = savingAccountWritePlatformService;
|
||||||
|
this.savingAccountReadPlatformService = savingAccountReadPlatformService;
|
||||||
|
this.apiDataConversionService = apiDataConversionService;
|
||||||
|
this.apiJsonSerializerService =apiJsonSerializerService;
|
||||||
|
this.savingProductReadPlatformService = savingProductReadPlatformService;
|
||||||
|
this.currencyReadPlatformService = currencyReadPlatformService;
|
||||||
|
this.context = context;
|
||||||
|
this.calculateSavingSchedule = calculateSavingSchedule;
|
||||||
|
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@@ -139,13 +141,13 @@ public class SavingsAccountApiResource {
|
|||||||
@Path("{accountId}")
|
@Path("{accountId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response updateSavingAccount(@PathParam("accountId") final Long accountId, final String jsonRequestBody) {
|
public String updateSavingAccount(@PathParam("accountId") final Long accountId, final String jsonRequestBody) {
|
||||||
|
|
||||||
final SavingAccountCommand command = this.apiDataConversionService.convertJsonToSavingAccountCommand(accountId, jsonRequestBody);
|
final SavingAccountCommand command = this.apiDataConversionService.convertJsonToSavingAccountCommand(accountId, jsonRequestBody);
|
||||||
|
|
||||||
CommandProcessingResult entityIdentifier = this.savingAccountWritePlatformService.updateSavingAccount(command);
|
CommandProcessingResult entityIdentifier = this.savingAccountWritePlatformService.updateSavingAccount(command);
|
||||||
|
|
||||||
return Response.ok().entity(entityIdentifier).build();
|
return this.toApiJsonSerializer.serialize(entityIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@@ -283,38 +285,38 @@ public class SavingsAccountApiResource {
|
|||||||
@Path("{accountId}")
|
@Path("{accountId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response savingStateTransitions(@PathParam("accountId") final Long accountId, @QueryParam("command") final String commandParam,
|
public String savingStateTransitions(@PathParam("accountId") final Long accountId, @QueryParam("command") final String commandParam,
|
||||||
final String jsonRequestBody) {
|
final String jsonRequestBody) {
|
||||||
Response response = null;
|
String response = null;
|
||||||
if (is(commandParam, "approve")) {
|
if (is(commandParam, "approve")) {
|
||||||
SavingAccountApprovalCommand command = this.apiDataConversionService.convertJsonToSavingApprovalCommand(accountId,
|
SavingAccountApprovalCommand command = this.apiDataConversionService.convertJsonToSavingApprovalCommand(accountId,
|
||||||
jsonRequestBody);
|
jsonRequestBody);
|
||||||
CommandProcessingResult identifier = this.savingAccountWritePlatformService.approveSavingAccount(command);
|
CommandProcessingResult identifier = this.savingAccountWritePlatformService.approveSavingAccount(command);
|
||||||
response = Response.ok().entity(identifier).build();
|
response = this.toApiJsonSerializer.serialize(identifier);
|
||||||
} else if (is(commandParam, "depositmoney")) {
|
} else if (is(commandParam, "depositmoney")) {
|
||||||
SavingAccountDepositCommand command = this.apiDataConversionService.convertJsonToSavingAccountDepositCommand(accountId,
|
SavingAccountDepositCommand command = this.apiDataConversionService.convertJsonToSavingAccountDepositCommand(accountId,
|
||||||
jsonRequestBody);
|
jsonRequestBody);
|
||||||
CommandProcessingResult identifier = this.savingAccountWritePlatformService.depositMoney(command);
|
CommandProcessingResult identifier = this.savingAccountWritePlatformService.depositMoney(command);
|
||||||
response = Response.ok().entity(identifier).build();
|
response = this.toApiJsonSerializer.serialize(identifier);
|
||||||
} else if (is(commandParam, "withdraw")) {
|
} else if (is(commandParam, "withdraw")) {
|
||||||
SavingAccountWithdrawalCommand command = this.apiDataConversionService.convertJsonToSavingAccountWithdrawalCommand(accountId,
|
SavingAccountWithdrawalCommand command = this.apiDataConversionService.convertJsonToSavingAccountWithdrawalCommand(accountId,
|
||||||
jsonRequestBody);
|
jsonRequestBody);
|
||||||
CommandProcessingResult identifier = this.savingAccountWritePlatformService.withdrawSavingAmount(command);
|
CommandProcessingResult identifier = this.savingAccountWritePlatformService.withdrawSavingAmount(command);
|
||||||
response = Response.ok().entity(identifier).build();
|
response = this.toApiJsonSerializer.serialize(identifier);
|
||||||
} else {
|
} else {
|
||||||
SavingStateTransitionsCommand command = this.apiDataConversionService.convertJsonToSavingStateTransitionCommand(accountId,
|
SavingStateTransitionsCommand command = this.apiDataConversionService.convertJsonToSavingStateTransitionCommand(accountId,
|
||||||
jsonRequestBody);
|
jsonRequestBody);
|
||||||
if (is(commandParam, "reject")) {
|
if (is(commandParam, "reject")) {
|
||||||
CommandProcessingResult identifier = this.savingAccountWritePlatformService.rejectSavingApplication(command);
|
CommandProcessingResult identifier = this.savingAccountWritePlatformService.rejectSavingApplication(command);
|
||||||
response = Response.ok().entity(identifier).build();
|
response = this.toApiJsonSerializer.serialize(identifier);
|
||||||
} else if (is(commandParam, "withdrewbyclient")) {
|
} else if (is(commandParam, "withdrewbyclient")) {
|
||||||
CommandProcessingResult identifier = this.savingAccountWritePlatformService.withdrawSavingApplication(command);
|
CommandProcessingResult identifier = this.savingAccountWritePlatformService.withdrawSavingApplication(command);
|
||||||
response = Response.ok().entity(identifier).build();
|
response =this.toApiJsonSerializer.serialize(identifier);
|
||||||
}
|
}
|
||||||
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(accountId, command.getNote());
|
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(accountId, command.getNote());
|
||||||
if (is(commandParam, "undoapproval")) {
|
if (is(commandParam, "undoapproval")) {
|
||||||
CommandProcessingResult identifier = this.savingAccountWritePlatformService.undoSavingAccountApproval(undoCommand);
|
CommandProcessingResult identifier = this.savingAccountWritePlatformService.undoSavingAccountApproval(undoCommand);
|
||||||
response = Response.ok().entity(identifier).build();
|
response = this.toApiJsonSerializer.serialize(identifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (response == null) { throw new UnrecognizedQueryParamException("command", commandParam); }
|
if (response == null) { throw new UnrecognizedQueryParamException("command", commandParam); }
|
||||||
@@ -336,11 +338,11 @@ public class SavingsAccountApiResource {
|
|||||||
@Path("postinterest")
|
@Path("postinterest")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response postInterest() {
|
public String postInterest() {
|
||||||
|
|
||||||
Collection<SavingAccountForLookup> savingAccounts = this.savingAccountReadPlatformService.retrieveSavingAccountsForLookUp();
|
Collection<SavingAccountForLookup> savingAccounts = this.savingAccountReadPlatformService.retrieveSavingAccountsForLookUp();
|
||||||
CommandProcessingResult entityIdentifier = this.savingAccountWritePlatformService.postInterest(savingAccounts);
|
CommandProcessingResult entityIdentifier = this.savingAccountWritePlatformService.postInterest(savingAccounts);
|
||||||
return Response.ok().entity(entityIdentifier).build();
|
return this.toApiJsonSerializer.serialize(entityIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+32
-10
@@ -6,6 +6,8 @@
|
|||||||
package org.mifosplatform.portfolio.savingsaccount.service;
|
package org.mifosplatform.portfolio.savingsaccount.service;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -72,7 +74,9 @@ public class SavingAccountWritePlatformServiceJpaRepositoryImpl implements Savin
|
|||||||
SavingAccount account = this.savingAccountAssembler.assembleFrom(command);
|
SavingAccount account = this.savingAccountAssembler.assembleFrom(command);
|
||||||
this.savingAccountRepository.save(account);
|
this.savingAccountRepository.save(account);
|
||||||
|
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
} catch (DataIntegrityViolationException dve) {
|
} catch (DataIntegrityViolationException dve) {
|
||||||
handleDataIntegrityIssues(command, dve);
|
handleDataIntegrityIssues(command, dve);
|
||||||
return new CommandProcessingResult(Long.valueOf(-1));
|
return new CommandProcessingResult(Long.valueOf(-1));
|
||||||
@@ -93,7 +97,9 @@ public class SavingAccountWritePlatformServiceJpaRepositoryImpl implements Savin
|
|||||||
this.savingAccountAssembler.assembleFrom(command, account);
|
this.savingAccountAssembler.assembleFrom(command, account);
|
||||||
this.savingAccountRepository.save(account);
|
this.savingAccountRepository.save(account);
|
||||||
}
|
}
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
} catch (DataIntegrityViolationException dve) {
|
} catch (DataIntegrityViolationException dve) {
|
||||||
handleDataIntegrityIssues(command, dve);
|
handleDataIntegrityIssues(command, dve);
|
||||||
return new CommandProcessingResult(Long.valueOf(-1));
|
return new CommandProcessingResult(Long.valueOf(-1));
|
||||||
@@ -138,7 +144,9 @@ public class SavingAccountWritePlatformServiceJpaRepositoryImpl implements Savin
|
|||||||
this.noteRepository.save(note);
|
this.noteRepository.save(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private DepositLifecycleStateMachine defaultDepositLifecycleStateMachine() {
|
private DepositLifecycleStateMachine defaultDepositLifecycleStateMachine() {
|
||||||
@@ -167,7 +175,9 @@ public class SavingAccountWritePlatformServiceJpaRepositoryImpl implements Savin
|
|||||||
this.noteRepository.save(note);
|
this.noteRepository.save(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -187,7 +197,9 @@ public class SavingAccountWritePlatformServiceJpaRepositoryImpl implements Savin
|
|||||||
this.noteRepository.save(note);
|
this.noteRepository.save(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -213,7 +225,9 @@ public class SavingAccountWritePlatformServiceJpaRepositoryImpl implements Savin
|
|||||||
this.noteRepository.save(note);
|
this.noteRepository.save(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -236,7 +250,9 @@ public class SavingAccountWritePlatformServiceJpaRepositoryImpl implements Savin
|
|||||||
Note note = Note.savingNote(account, noteText);
|
Note note = Note.savingNote(account, noteText);
|
||||||
this.noteRepository.save(note);
|
this.noteRepository.save(note);
|
||||||
}
|
}
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -255,7 +271,9 @@ public class SavingAccountWritePlatformServiceJpaRepositoryImpl implements Savin
|
|||||||
Note note = Note.savingNote(account, noteText);
|
Note note = Note.savingNote(account, noteText);
|
||||||
this.noteRepository.save(note);
|
this.noteRepository.save(note);
|
||||||
}
|
}
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -267,7 +285,9 @@ public class SavingAccountWritePlatformServiceJpaRepositoryImpl implements Savin
|
|||||||
}
|
}
|
||||||
account.delete();
|
account.delete();
|
||||||
this.savingAccountRepository.save(account);
|
this.savingAccountRepository.save(account);
|
||||||
return new CommandProcessingResult(accountId);
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -280,7 +300,9 @@ public class SavingAccountWritePlatformServiceJpaRepositoryImpl implements Savin
|
|||||||
this.savingAccountAssembler.postInterest(account);
|
this.savingAccountAssembler.postInterest(account);
|
||||||
this.savingAccountRepository.save(account);
|
this.savingAccountRepository.save(account);
|
||||||
}
|
}
|
||||||
return new CommandProcessingResult(new Long(savingAccounts.size()));
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(Long.valueOf(savingAccounts.size())) //
|
||||||
|
.build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new CommandProcessingResult(Long.valueOf(-1));
|
return new CommandProcessingResult(Long.valueOf(-1));
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-23
@@ -21,12 +21,12 @@ import javax.ws.rs.PathParam;
|
|||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||||
|
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.organisation.monetary.data.CurrencyData;
|
import org.mifosplatform.organisation.monetary.data.CurrencyData;
|
||||||
import org.mifosplatform.organisation.monetary.service.CurrencyReadPlatformService;
|
import org.mifosplatform.organisation.monetary.service.CurrencyReadPlatformService;
|
||||||
@@ -52,46 +52,53 @@ import org.springframework.stereotype.Component;
|
|||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class SavingProductsApiResource {
|
public class SavingProductsApiResource {
|
||||||
|
|
||||||
@Autowired
|
private final SavingProductReadPlatformService savingProductReadPlatformService;
|
||||||
private SavingProductReadPlatformService savingProductReadPlatformService;
|
private final SavingProductWritePlatformService savingProductWritePlatformService;
|
||||||
|
private final PortfolioApiDataConversionService apiDataConversionService;
|
||||||
@Autowired
|
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||||
private SavingProductWritePlatformService savingProductWritePlatformService;
|
private final CurrencyReadPlatformService currencyReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PortfolioApiDataConversionService apiDataConversionService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CurrencyReadPlatformService currencyReadPlatformService;
|
|
||||||
|
|
||||||
private final String entityType = "SAVINGSPRODUCT";
|
private final String entityType = "SAVINGSPRODUCT";
|
||||||
|
private final PlatformSecurityContext context;
|
||||||
|
private final DefaultToApiJsonSerializer<SavingProductData> toApiJsonSerializer;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PlatformSecurityContext context;
|
public SavingProductsApiResource(final SavingProductReadPlatformService savingProductReadPlatformService,
|
||||||
|
final SavingProductWritePlatformService savingProductWritePlatformService,
|
||||||
|
final PortfolioApiDataConversionService apiDataConversionService,
|
||||||
|
final PortfolioApiJsonSerializerService apiJsonSerializerService,
|
||||||
|
final CurrencyReadPlatformService currencyReadPlatformService,
|
||||||
|
final PlatformSecurityContext context,
|
||||||
|
final DefaultToApiJsonSerializer<SavingProductData> toApiJsonSerializer) {
|
||||||
|
this.savingProductReadPlatformService = savingProductReadPlatformService;
|
||||||
|
this.savingProductWritePlatformService = savingProductWritePlatformService;
|
||||||
|
this.apiDataConversionService = apiDataConversionService;
|
||||||
|
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||||
|
this.currencyReadPlatformService = currencyReadPlatformService;
|
||||||
|
this.context = context;
|
||||||
|
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response createSavingProduct(final String jsonRequestBody) {
|
public String createSavingProduct(final String jsonRequestBody) {
|
||||||
|
|
||||||
final SavingProductCommand command = this.apiDataConversionService.convertJsonToSavingProductCommand(null, jsonRequestBody);
|
final SavingProductCommand command = this.apiDataConversionService.convertJsonToSavingProductCommand(null, jsonRequestBody);
|
||||||
|
|
||||||
CommandProcessingResult entityIdentifier = this.savingProductWritePlatformService.createSavingProduct(command);
|
CommandProcessingResult entityIdentifier = this.savingProductWritePlatformService.createSavingProduct(command);
|
||||||
|
|
||||||
return Response.ok().entity(entityIdentifier).build();
|
return this.toApiJsonSerializer.serialize(entityIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{productId}")
|
@Path("{productId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response updateSavingProduct(@PathParam("productId") final Long productId, final String jsonRequestBody) {
|
public String updateSavingProduct(@PathParam("productId") final Long productId, final String jsonRequestBody) {
|
||||||
|
|
||||||
SavingProductCommand command = this.apiDataConversionService.convertJsonToSavingProductCommand(productId, jsonRequestBody);
|
SavingProductCommand command = this.apiDataConversionService.convertJsonToSavingProductCommand(productId, jsonRequestBody);
|
||||||
CommandProcessingResult entityIdentifier = this.savingProductWritePlatformService.updateSavingProduct(command);
|
CommandProcessingResult entityIdentifier = this.savingProductWritePlatformService.updateSavingProduct(command);
|
||||||
return Response.ok().entity(entityIdentifier).build();
|
return this.toApiJsonSerializer.serialize(entityIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@@ -210,10 +217,10 @@ public class SavingProductsApiResource {
|
|||||||
@Path("{productId}")
|
@Path("{productId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response deleteProduct(@PathParam("productId") final Long productId) {
|
public String deleteProduct(@PathParam("productId") final Long productId) {
|
||||||
|
|
||||||
this.savingProductWritePlatformService.deleteSavingProduct(productId);
|
this.savingProductWritePlatformService.deleteSavingProduct(productId);
|
||||||
|
|
||||||
return Response.ok(new CommandProcessingResult(productId)).build();
|
return this.toApiJsonSerializer.serialize(productId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+10
-3
@@ -6,6 +6,7 @@
|
|||||||
package org.mifosplatform.portfolio.savingsaccountproduct.service;
|
package org.mifosplatform.portfolio.savingsaccountproduct.service;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
|
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
|
||||||
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
|
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
|
||||||
@@ -69,7 +70,9 @@ public class SavingProductWritePlatformServiceJpaRepositoryImpl implements Savin
|
|||||||
command.getLockinPeriod(), lockinPeriodType);
|
command.getLockinPeriod(), lockinPeriodType);
|
||||||
|
|
||||||
this.savingProductRepository.save(product);
|
this.savingProductRepository.save(product);
|
||||||
return new CommandProcessingResult(product.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(product.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -84,7 +87,9 @@ public class SavingProductWritePlatformServiceJpaRepositoryImpl implements Savin
|
|||||||
if (product == null) { throw new SavingProductNotFoundException(command.getId()); }
|
if (product == null) { throw new SavingProductNotFoundException(command.getId()); }
|
||||||
product.update(command);
|
product.update(command);
|
||||||
this.savingProductRepository.save(product);
|
this.savingProductRepository.save(product);
|
||||||
return new CommandProcessingResult(Long.valueOf(product.getId()));
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(product.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -96,7 +101,9 @@ public class SavingProductWritePlatformServiceJpaRepositoryImpl implements Savin
|
|||||||
if (product == null || product.isDeleted()) { throw new SavingsProductNotFoundException(productId); }
|
if (product == null || product.isDeleted()) { throw new SavingsProductNotFoundException(productId); }
|
||||||
product.delete();
|
product.delete();
|
||||||
this.savingProductRepository.save(product);
|
this.savingProductRepository.save(product);
|
||||||
return new CommandProcessingResult(Long.valueOf(product.getId()));
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(product.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+105
-124
@@ -28,21 +28,19 @@ import javax.ws.rs.core.Response.ResponseBuilder;
|
|||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||||
|
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||||
|
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
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.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||||
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
|
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
|
||||||
|
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||||
|
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.portfolio.loanaccount.command.UndoStateTransitionCommand;
|
|
||||||
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
|
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
|
||||||
import org.mifosplatform.portfolio.savingsaccount.PortfolioApiDataConversionService;
|
|
||||||
import org.mifosplatform.portfolio.savingsaccount.PortfolioApiJsonSerializerService;
|
|
||||||
import org.mifosplatform.portfolio.savingsaccountproduct.service.SavingsDepositEnumerations;
|
import org.mifosplatform.portfolio.savingsaccountproduct.service.SavingsDepositEnumerations;
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountWithdrawInterestCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountWithdrawalCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionApprovalCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositAccountData;
|
import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositAccountData;
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositAccountsForLookup;
|
import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositAccountsForLookup;
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositPermissionData;
|
import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositPermissionData;
|
||||||
@@ -59,57 +57,72 @@ import org.springframework.stereotype.Component;
|
|||||||
@Component
|
@Component
|
||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class DepositAccountsApiResource {
|
public class DepositAccountsApiResource {
|
||||||
|
|
||||||
@Autowired
|
private static final Set<String> SAVINGS_DEPOSIT_ACCOUNT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("productOptions",
|
||||||
private DepositAccountReadPlatformService depositAccountReadPlatformService;
|
"interestCompoundedEveryPeriodTypeOptions", "id", "externalId", "clientId", "clientName", "productId", "productName", "status",
|
||||||
|
"currency", "deposit", "maturityInterestRate", "tenureInMonths", "interestCompoundedEvery",
|
||||||
@Autowired
|
"interestCompoundedEveryPeriodType", "renewalAllowed", "preClosureAllowed", "preClosureInterestRate", "withdrawnonDate",
|
||||||
private DepositProductReadPlatformService depositProductReadPlatformService;
|
"rejectedonDate", "closedonDate", "transactions", "permissions", "isInterestWithdrawable", "interestPaid",
|
||||||
|
"interestCompoundingAllowed", "availableInterestForWithdrawal", "availableWithdrawalAmount", "todaysDate",
|
||||||
@Autowired
|
|
||||||
private DepositAccountWritePlatformService depositAccountWritePlatformService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PortfolioApiDataConversionService apiDataConversionService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
|
||||||
|
|
||||||
private final String entityType = "DEPOSITACCOUNT";
|
|
||||||
@Autowired
|
|
||||||
private PlatformSecurityContext context;
|
|
||||||
|
|
||||||
private static final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "externalId", "clientId",
|
|
||||||
"clientName", "productId", "productName", "status", "currency", "deposit", "maturityInterestRate", "tenureInMonths",
|
|
||||||
"interestCompoundedEvery", "interestCompoundingAllowed", "interestCompoundedEveryPeriodType", "renewalAllowed",
|
|
||||||
"preClosureAllowed", "preClosureInterestRate", "withdrawnonDate", "rejectedonDate", "closedonDate", "transactions",
|
|
||||||
"interestPaid", "isInterestWithdrawable", "availableInterestForWithdrawal", "availableWithdrawalAmount", "todaysDate",
|
|
||||||
"isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "printFDdetailsLocation", "availableInterest",
|
"isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "printFDdetailsLocation", "availableInterest",
|
||||||
"interestPostedAmount", "lastInterestPostedDate", "nextInterestPostedDate", "fatherName", "address", "imageKey"));
|
"interestPostedAmount", "lastInterestPostedDate", "nextInterestPostedDate", "fatherName", "address", "imageKey"));
|
||||||
|
|
||||||
|
private final DepositAccountReadPlatformService depositAccountReadPlatformService;
|
||||||
|
|
||||||
|
private final DepositProductReadPlatformService depositProductReadPlatformService;
|
||||||
|
|
||||||
|
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
|
||||||
|
|
||||||
|
private final String entityType = "DEPOSITACCOUNT";
|
||||||
|
|
||||||
|
private final PlatformSecurityContext context;
|
||||||
|
|
||||||
|
private final DefaultToApiJsonSerializer<DepositAccountData> toApiJsonSerializer;
|
||||||
|
|
||||||
|
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||||
|
|
||||||
|
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DepositAccountsApiResource(final DepositAccountReadPlatformService depositAccountReadPlatformService,
|
||||||
|
final DepositProductReadPlatformService depositProductReadPlatformService,
|
||||||
|
final DepositAccountWritePlatformService depositAccountWritePlatformService,
|
||||||
|
final PlatformSecurityContext context,
|
||||||
|
final DefaultToApiJsonSerializer<DepositAccountData> toApiJsonSerializer,
|
||||||
|
final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||||
|
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService ) {
|
||||||
|
this.depositAccountReadPlatformService = depositAccountReadPlatformService;
|
||||||
|
this.depositProductReadPlatformService = depositProductReadPlatformService;
|
||||||
|
this.depositAccountWritePlatformService = depositAccountWritePlatformService;
|
||||||
|
this.context = context;
|
||||||
|
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||||
|
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||||
|
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response createDepositAccount(final String jsonRequestBody) {
|
public String createDepositAccount(final String apiRequestBodyAsJson) {
|
||||||
|
|
||||||
final DepositAccountCommand command = this.apiDataConversionService.convertJsonToDepositAccountCommand(null, jsonRequestBody);
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().createDepositAccount().withJson(apiRequestBodyAsJson).build();
|
||||||
|
|
||||||
|
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
CommandProcessingResult entityIdentifier = this.depositAccountWritePlatformService.createDepositAccount(command);
|
return this.toApiJsonSerializer.serialize(result);
|
||||||
|
|
||||||
return Response.ok().entity(entityIdentifier).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{accountId}")
|
@Path("{accountId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response updateDepositAccount(@PathParam("accountId") final Long accountId, final String jsonRequestBody) {
|
public String updateDepositAccount(@PathParam("accountId") final Long accountId, final String apiRequestBodyAsJson) {
|
||||||
|
|
||||||
final DepositAccountCommand command = this.apiDataConversionService.convertJsonToDepositAccountCommand(accountId, jsonRequestBody);
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateDepositAccount(accountId).withJson(apiRequestBodyAsJson).build();
|
||||||
|
|
||||||
|
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
CommandProcessingResult entityIdentifier = this.depositAccountWritePlatformService.updateDepositAccount(command);
|
return this.toApiJsonSerializer.serialize(result);
|
||||||
|
|
||||||
return Response.ok().entity(entityIdentifier).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@@ -119,15 +132,11 @@ public class DepositAccountsApiResource {
|
|||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
|
||||||
if (responseParameters.isEmpty()) {
|
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
|
||||||
}
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
|
||||||
|
|
||||||
Collection<DepositAccountData> accounts = this.depositAccountReadPlatformService.retrieveAllDepositAccounts();
|
Collection<DepositAccountData> accounts = this.depositAccountReadPlatformService.retrieveAllDepositAccounts();
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeDepositAccountDataToJson(prettyPrint, responseParameters, accounts);
|
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
|
return this.toApiJsonSerializer.serialize(settings, accounts, SAVINGS_DEPOSIT_ACCOUNT_DATA_PARAMETERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@@ -137,35 +146,26 @@ public class DepositAccountsApiResource {
|
|||||||
public String retrieveDepositAccount(@PathParam("accountId") final Long accountId, @Context final UriInfo uriInfo) {
|
public String retrieveDepositAccount(@PathParam("accountId") final Long accountId, @Context final UriInfo uriInfo) {
|
||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
|
||||||
|
|
||||||
DepositPermissionData permissions = null;
|
DepositPermissionData permissions = null;
|
||||||
|
|
||||||
if (responseParameters.isEmpty()) {
|
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
|
||||||
}
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
|
||||||
|
|
||||||
DepositAccountData account = this.depositAccountReadPlatformService.retrieveDepositAccount(accountId);
|
DepositAccountData account = this.depositAccountReadPlatformService.retrieveDepositAccount(accountId);
|
||||||
|
|
||||||
|
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
if (settings.isTemplate()) {
|
||||||
if (template) {
|
account = handleTemplateRelatedData(account);
|
||||||
account = handleTemplateRelatedData(responseParameters, account);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
if (!associationParameters.isEmpty()) {
|
if (!associationParameters.isEmpty()) {
|
||||||
if (associationParameters.contains("all")) {
|
if (associationParameters.contains("all")) {
|
||||||
responseParameters.addAll(Arrays.asList("permissions"));
|
permissions = this.depositAccountReadPlatformService.retrieveDepositAccountsPermissions(account);
|
||||||
} else {
|
account = new DepositAccountData(account, permissions, account.getTransactions());
|
||||||
responseParameters.addAll(associationParameters);
|
|
||||||
}
|
}
|
||||||
permissions = this.depositAccountReadPlatformService.retrieveDepositAccountsPermissions(account);
|
|
||||||
account = new DepositAccountData(account, permissions, account.getTransactions());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeDepositAccountDataToJson(prettyPrint, responseParameters, account);
|
return this.toApiJsonSerializer.serialize(settings, account, SAVINGS_DEPOSIT_ACCOUNT_DATA_PARAMETERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@@ -177,33 +177,29 @@ public class DepositAccountsApiResource {
|
|||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
|
||||||
if (responseParameters.isEmpty()) {
|
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
|
||||||
}
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
|
||||||
|
|
||||||
DepositAccountData account = this.depositAccountReadPlatformService.retrieveNewDepositAccountDetails(clientId, productId);
|
DepositAccountData account = this.depositAccountReadPlatformService.retrieveNewDepositAccountDetails(clientId, productId);
|
||||||
|
|
||||||
account = handleTemplateRelatedData(responseParameters, account);
|
account = handleTemplateRelatedData(account);
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeDepositAccountDataToJson(prettyPrint, responseParameters, account);
|
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
|
return this.toApiJsonSerializer.serialize(settings, account, SAVINGS_DEPOSIT_ACCOUNT_DATA_PARAMETERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{accountId}")
|
@Path("{accountId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response deleteProduct(@PathParam("accountId") final Long accountId) {
|
public String deleteProduct(@PathParam("accountId") final Long accountId) {
|
||||||
|
|
||||||
this.depositAccountWritePlatformService.deleteDepositAccount(accountId);
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteDepositAccount(accountId).build();
|
||||||
|
|
||||||
|
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
return Response.ok(new CommandProcessingResult(accountId)).build();
|
return this.toApiJsonSerializer.serialize(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DepositAccountData handleTemplateRelatedData(final Set<String> responseParameters, final DepositAccountData account) {
|
private DepositAccountData handleTemplateRelatedData(final DepositAccountData account) {
|
||||||
|
|
||||||
responseParameters.addAll(Arrays.asList("interestCompoundedEveryPeriodTypeOptions", "productOptions"));
|
|
||||||
|
|
||||||
Collection<DepositProductLookup> productOptions = depositProductReadPlatformService.retrieveAllDepositProductsForLookup();
|
Collection<DepositProductLookup> productOptions = depositProductReadPlatformService.retrieveAllDepositProductsForLookup();
|
||||||
|
|
||||||
@@ -217,52 +213,36 @@ public class DepositAccountsApiResource {
|
|||||||
@Path("{accountId}")
|
@Path("{accountId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response SubmitDepositApplication(@PathParam("accountId") final Long accountId,
|
public String SubmitDepositApplication(@PathParam("accountId") final Long accountId,
|
||||||
@QueryParam("command") final String commandParam, final String jsonRequestBody) {
|
@QueryParam("command") final String commandParam, final String apiRequestBodyAsJson) {
|
||||||
|
|
||||||
Response response = null;
|
CommandWrapperBuilder builder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson);
|
||||||
|
CommandProcessingResult result = null;
|
||||||
|
|
||||||
if (is(commandParam, "approve")) {
|
if (is(commandParam, "approve")) {
|
||||||
DepositStateTransitionApprovalCommand command = apiDataConversionService.convertJsonToDepositStateTransitionApprovalCommand(
|
final CommandWrapper commandRequest = builder.approveDepositApplication(accountId).build();
|
||||||
accountId, jsonRequestBody);
|
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
CommandProcessingResult identifier = this.depositAccountWritePlatformService.approveDepositApplication(command);
|
|
||||||
response = Response.ok().entity(identifier).build();
|
|
||||||
} else if (is(commandParam, "withdrawal")) {
|
} else if (is(commandParam, "withdrawal")) {
|
||||||
DepositAccountWithdrawalCommand command = apiDataConversionService.convertJsonToDepositWithdrawalCommand(accountId,
|
final CommandWrapper commandRequest = builder.withdrawDepositAmount(accountId).build();
|
||||||
jsonRequestBody);
|
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
CommandProcessingResult identifier = this.depositAccountWritePlatformService.withdrawDepositAccountMoney(command);
|
|
||||||
response = Response.ok().entity(identifier).build();
|
|
||||||
} else if (is(commandParam, "interestwithdraw")) {
|
} else if (is(commandParam, "interestwithdraw")) {
|
||||||
DepositAccountWithdrawInterestCommand command = apiDataConversionService.convertJsonToDepositAccountWithdrawInterestCommand(
|
final CommandWrapper commandRequest = builder.withdrawInterestDepositAmount(accountId).build();
|
||||||
accountId, jsonRequestBody);
|
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
CommandProcessingResult identifier = this.depositAccountWritePlatformService.withdrawDepositAccountInterestMoney(command);
|
|
||||||
response = Response.ok().entity(identifier).build();
|
|
||||||
} else if (is(commandParam, "renew")) {
|
} else if (is(commandParam, "renew")) {
|
||||||
DepositAccountCommand command = apiDataConversionService.convertJsonToDepositAccountCommand(accountId, jsonRequestBody);
|
final CommandWrapper commandRequest = builder.renewDepositAccount(accountId).build();
|
||||||
CommandProcessingResult entityIdentifier = this.depositAccountWritePlatformService.renewDepositAccount(command);
|
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
return Response.ok().entity(entityIdentifier).build();
|
} else if (is(commandParam, "reject")) {
|
||||||
} else {
|
final CommandWrapper commandRequest = builder.rejectDepositAccount(accountId).build();
|
||||||
DepositStateTransitionCommand command = apiDataConversionService.convertJsonToDepositStateTransitionCommand(accountId,
|
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
jsonRequestBody);
|
} else if (is(commandParam, "withdrewbyclient")) {
|
||||||
if (is(commandParam, "reject")) {
|
final CommandWrapper commandRequest = builder.withdrawDepositApplication(accountId).build();
|
||||||
CommandProcessingResult identifier = this.depositAccountWritePlatformService.rejectDepositApplication(command);
|
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
response = Response.ok().entity(identifier).build();
|
} else if (is(commandParam, "undoapproval")) {
|
||||||
} else if (is(commandParam, "withdrewbyclient")) {
|
final CommandWrapper commandRequest = builder.undoDepositApplicationApproval(accountId).build();
|
||||||
CommandProcessingResult identifier = this.depositAccountWritePlatformService.withdrawDepositApplication(command);
|
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
response = Response.ok().entity(identifier).build();
|
} else { throw new UnrecognizedQueryParamException("command", commandParam); }
|
||||||
}
|
|
||||||
|
|
||||||
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(accountId, command.getNote());
|
return this.toApiJsonSerializer.serialize(result);
|
||||||
|
|
||||||
if (is(commandParam, "undoapproval")) {
|
|
||||||
CommandProcessingResult identifier = this.depositAccountWritePlatformService.undoDepositApproval(undoCommand);
|
|
||||||
response = Response.ok().entity(identifier).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response == null) { throw new UnrecognizedQueryParamException("command", commandParam); }
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean is(final String commandParam, final String commandValue) {
|
private boolean is(final String commandParam, final String commandValue) {
|
||||||
@@ -273,14 +253,15 @@ public class DepositAccountsApiResource {
|
|||||||
@Path("postinterest")
|
@Path("postinterest")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response postInterest() {
|
public String postInterest() {
|
||||||
Collection<DepositAccountsForLookup> accounts = this.depositAccountReadPlatformService.retrieveDepositAccountForLookup();
|
Collection<DepositAccountsForLookup> accounts = this.depositAccountReadPlatformService.retrieveDepositAccountForLookup();
|
||||||
CommandProcessingResult entityIdentifier = this.depositAccountWritePlatformService.postInterestToDepositAccount(accounts);
|
CommandProcessingResult entityIdentifier = this.depositAccountWritePlatformService.postInterestToDepositAccount(accounts);
|
||||||
return Response.ok().entity(entityIdentifier).build();
|
return this.toApiJsonSerializer.serialize(entityIdentifier);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@SuppressWarnings("null")
|
||||||
|
@GET
|
||||||
@Path("{accountId}/print")
|
@Path("{accountId}/print")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
|||||||
+42
-14
@@ -8,7 +8,9 @@ package org.mifosplatform.portfolio.savingsdepositaccount.domain;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
@@ -30,12 +32,12 @@ import org.hibernate.annotations.LazyCollectionOption;
|
|||||||
import org.joda.time.Days;
|
import org.joda.time.Days;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.joda.time.Months;
|
import org.joda.time.Months;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
|
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
|
||||||
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
|
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
|
||||||
import org.mifosplatform.organisation.monetary.domain.Money;
|
import org.mifosplatform.organisation.monetary.domain.Money;
|
||||||
import org.mifosplatform.portfolio.client.domain.Client;
|
import org.mifosplatform.portfolio.client.domain.Client;
|
||||||
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
|
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionApprovalCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.exception.InvalidDepositStateTransitionException;
|
import org.mifosplatform.portfolio.savingsdepositaccount.exception.InvalidDepositStateTransitionException;
|
||||||
import org.mifosplatform.portfolio.savingsdepositproduct.domain.DepositProduct;
|
import org.mifosplatform.portfolio.savingsdepositproduct.domain.DepositProduct;
|
||||||
import org.mifosplatform.useradministration.domain.AppUser;
|
import org.mifosplatform.useradministration.domain.AppUser;
|
||||||
@@ -276,31 +278,56 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
this.externalId = this.getId() + "_" + this.externalId;
|
this.externalId = this.getId() + "_" + this.externalId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void approve(final LocalDate actualCommencementDate, final DepositLifecycleStateMachine depositLifecycleStateMachine,
|
public Map<String, Object> approve(final LocalDate actualCommencementDate, final DepositLifecycleStateMachine depositLifecycleStateMachine,
|
||||||
final DepositStateTransitionApprovalCommand command, final FixedTermDepositInterestCalculator calculator) {
|
final JsonCommand command, final FixedTermDepositInterestCalculator calculator) {
|
||||||
|
|
||||||
|
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20);
|
||||||
|
final String localeAsInput = command.locale();
|
||||||
|
|
||||||
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVED,
|
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVED,
|
||||||
DepositAccountStatus.fromInt(this.depositStatus));
|
DepositAccountStatus.fromInt(this.depositStatus));
|
||||||
this.depositStatus = statusEnum.getValue();
|
this.depositStatus = statusEnum.getValue();
|
||||||
|
|
||||||
if (command.getTenureInMonths() != null) {
|
final String tenureInMonthsParamName = "tenureInMonths";
|
||||||
this.tenureInMonths = command.getTenureInMonths();
|
if (command.isChangeInIntegerParameterNamed(tenureInMonthsParamName, this.tenureInMonths)) {
|
||||||
|
final Integer newValue = command.integerValueOfParameterNamed(tenureInMonthsParamName);
|
||||||
|
actualChanges.put(tenureInMonthsParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.tenureInMonths = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.getMaturityInterestRate() != null) {
|
final String maturityInterestRateParamName = "maturityInterestRate";
|
||||||
this.interestRate = command.getMaturityInterestRate();
|
if (command.isChangeInBigDecimalParameterNamed(maturityInterestRateParamName, this.interestRate)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(maturityInterestRateParamName);
|
||||||
|
actualChanges.put(maturityInterestRateParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.interestRate = newValue;
|
||||||
}
|
}
|
||||||
this.product.validateInterestRateInRange(this.interestRate);
|
this.product.validateInterestRateInRange(this.interestRate);
|
||||||
|
|
||||||
if (command.getDepositAmount() != null) {
|
final String depositParamName = "deposit";
|
||||||
this.depositAmount = command.getDepositAmount();
|
if (command.isChangeInBigDecimalParameterNamed(depositParamName, this.depositAmount)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(depositParamName);
|
||||||
|
actualChanges.put(depositParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.depositAmount = newValue;
|
||||||
}
|
}
|
||||||
this.product.validateDepositInRange(this.depositAmount);
|
this.product.validateDepositInRange(this.depositAmount);
|
||||||
|
|
||||||
|
final String interestCompoundedEveryParamName = "interestCompoundedEvery";
|
||||||
|
if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryParamName, this.interestCompoundedEvery)) {
|
||||||
|
final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryParamName);
|
||||||
|
actualChanges.put(interestCompoundedEveryParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.interestCompoundedEvery = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
this.interestCompoundedEvery = command.getInterestCompoundedEvery();
|
final String interestCompoundedEveryPeriodTypeParamName = "interestCompoundedEveryPeriodType";
|
||||||
|
if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryPeriodTypeParamName, this.interestCompoundedFrequencyType)) {
|
||||||
if (command.getInterestCompoundedEveryPeriodType() != null) {
|
final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryPeriodTypeParamName);
|
||||||
this.interestCompoundedFrequencyType = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType()).getValue();
|
actualChanges.put(interestCompoundedEveryPeriodTypeParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.interestCompoundedFrequencyType = PeriodFrequencyType.fromInt(newValue).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.actualCommencementDate = actualCommencementDate.toDate();
|
this.actualCommencementDate = actualCommencementDate.toDate();
|
||||||
@@ -341,6 +368,7 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
throw new InvalidDepositStateTransitionException("approval", "cannot.be.a.future.date", errorMessage,
|
throw new InvalidDepositStateTransitionException("approval", "cannot.be.a.future.date", errorMessage,
|
||||||
getActualCommencementDate());
|
getActualCommencementDate());
|
||||||
}
|
}
|
||||||
|
return actualChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDate getActualCommencementDate() {
|
public LocalDate getActualCommencementDate() {
|
||||||
|
|||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositaccount.handler;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositaccount.service.DepositAccountWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ApproveDepositAccountCommandHandler implements NewCommandSourceHandler {
|
||||||
|
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ApproveDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) {
|
||||||
|
this.depositAccountWritePlatformService = depositAccountWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||||
|
return this.depositAccountWritePlatformService.approveDepositApplication(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositaccount.handler;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositaccount.service.DepositAccountWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CreateDepositAccountCommandHandler implements NewCommandSourceHandler {
|
||||||
|
|
||||||
|
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public CreateDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) {
|
||||||
|
this.depositAccountWritePlatformService = depositAccountWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||||
|
return this.depositAccountWritePlatformService.createDepositAccount(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositaccount.handler;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositaccount.service.DepositAccountWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DeleteDepositAccountCommandHandler implements NewCommandSourceHandler {
|
||||||
|
|
||||||
|
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DeleteDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) {
|
||||||
|
this.depositAccountWritePlatformService = depositAccountWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||||
|
return this.depositAccountWritePlatformService.deleteDepositAccount(command.entityId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositaccount.handler;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositaccount.service.DepositAccountWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RejectDepositAccountCommandHandler implements NewCommandSourceHandler {
|
||||||
|
|
||||||
|
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public RejectDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) {
|
||||||
|
this.depositAccountWritePlatformService = depositAccountWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||||
|
return this.depositAccountWritePlatformService.rejectDepositApplication(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositaccount.handler;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositaccount.service.DepositAccountWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RenewDepositAccountCommandHandler implements NewCommandSourceHandler {
|
||||||
|
|
||||||
|
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public RenewDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) {
|
||||||
|
this.depositAccountWritePlatformService = depositAccountWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||||
|
return this.depositAccountWritePlatformService.renewDepositAccount(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositaccount.handler;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositaccount.service.DepositAccountWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UndoApprovalDepositAccountCommandHandler implements NewCommandSourceHandler {
|
||||||
|
|
||||||
|
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UndoApprovalDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) {
|
||||||
|
this.depositAccountWritePlatformService = depositAccountWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||||
|
return this.depositAccountWritePlatformService.undoDepositApproval(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositaccount.handler;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositaccount.service.DepositAccountWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UpdateDepositAccountCommandHandler implements NewCommandSourceHandler {
|
||||||
|
|
||||||
|
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UpdateDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) {
|
||||||
|
this.depositAccountWritePlatformService = depositAccountWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||||
|
return this.depositAccountWritePlatformService.updateDepositAccount(command.entityId(), command);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositaccount.handler;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositaccount.service.DepositAccountWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class WithDrawByApplicantDepositAccountCommandHandler implements NewCommandSourceHandler {
|
||||||
|
|
||||||
|
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public WithDrawByApplicantDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) {
|
||||||
|
this.depositAccountWritePlatformService = depositAccountWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||||
|
return this.depositAccountWritePlatformService.withdrawDepositApplication(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositaccount.handler;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositaccount.service.DepositAccountWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class WithdrawDepositAccountAmountCommandHandler implements NewCommandSourceHandler {
|
||||||
|
|
||||||
|
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public WithdrawDepositAccountAmountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) {
|
||||||
|
this.depositAccountWritePlatformService = depositAccountWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||||
|
return this.depositAccountWritePlatformService.withdrawDepositAccountMoney(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositaccount.handler;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositaccount.service.DepositAccountWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class WithdrawInterestDepositAccountAmountCommandHandler implements NewCommandSourceHandler {
|
||||||
|
|
||||||
|
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public WithdrawInterestDepositAccountAmountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) {
|
||||||
|
this.depositAccountWritePlatformService = depositAccountWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||||
|
return this.depositAccountWritePlatformService.withdrawDepositAccountInterestMoney(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+247
@@ -0,0 +1,247 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositaccount.serialization;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||||
|
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||||
|
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||||
|
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DepositAccountCommandFromApiJsonDeserializer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The parameters supported for this command.
|
||||||
|
*/
|
||||||
|
|
||||||
|
private final Set<String> supportedParams = new HashSet<String>(Arrays.asList("clientId", "productId", "externalId", "deposit",
|
||||||
|
"maturityInterestRate", "preClosureInterestRate", "tenureInMonths", "interestCompoundedEvery",
|
||||||
|
"interestCompoundedEveryPeriodType", "commencementDate", "renewalAllowed", "preClosureAllowed",
|
||||||
|
"interestCompoundingAllowed", "locale", "dateFormat", "isInterestWithdrawable", "isLockinPeriodAllowed", "lockinPeriod",
|
||||||
|
"lockinPeriodType","note"));
|
||||||
|
|
||||||
|
private final FromJsonHelper fromApiJsonHelper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DepositAccountCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||||
|
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateForCreate(final String json) {
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
|
|
||||||
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
|
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams);
|
||||||
|
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.account");
|
||||||
|
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
|
final Long clientId = fromApiJsonHelper.extractLongNamed("clientId", element);
|
||||||
|
baseDataValidator.reset().parameter("clientId").value(clientId).notNull();
|
||||||
|
|
||||||
|
final Long productId = fromApiJsonHelper.extractLongNamed("productId", element);
|
||||||
|
baseDataValidator.reset().parameter("productId").value(productId).notNull();
|
||||||
|
|
||||||
|
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element);
|
||||||
|
baseDataValidator.reset().parameter("externalId").value(externalId).ignoreIfNull().notExceedingLengthOf(100);
|
||||||
|
|
||||||
|
final BigDecimal deposit = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("deposit", element);
|
||||||
|
baseDataValidator.reset().parameter("deposit").value(deposit).notNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer tenureInMonths = fromApiJsonHelper.extractIntegerNamed("tenureInMonths", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("tenureInMonths").value(tenureInMonths).notNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final BigDecimal maturityInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("maturityInterestRate").value(maturityInterestRate).notNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer interestCompoundedEvery = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEvery", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("interestCompoundedEvery").value(interestCompoundedEvery).notNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer interestCompoundedEveryPeriodType = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEveryPeriodType", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(interestCompoundedEveryPeriodType).notNull().inMinMaxRange(1, 3);
|
||||||
|
|
||||||
|
final BigDecimal preClosureInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("preClosureInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("preClosureInterestRate").value(preClosureInterestRate).notNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final LocalDate commencementDate = fromApiJsonHelper.extractLocalDateNamed("commencementDate", element);
|
||||||
|
baseDataValidator.reset().parameter("commencementDate").value(commencementDate).notNull();
|
||||||
|
|
||||||
|
final Boolean isInterestWithdrawable = fromApiJsonHelper.extractBooleanNamed("isInterestWithdrawable", element);
|
||||||
|
final Boolean isInterestWithdrawableChanged = isBooleanValueUpdated(isInterestWithdrawable);
|
||||||
|
baseDataValidator.reset().parameter("isInterestWithdrawable").trueOrFalseRequired(isInterestWithdrawableChanged);
|
||||||
|
|
||||||
|
final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).ignoreIfNull().inMinMaxRange(1, 3);
|
||||||
|
|
||||||
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
||||||
|
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||||
|
"Validation errors exist.", dataValidationErrors); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean isBooleanValueUpdated(Boolean actualValue) {
|
||||||
|
Boolean isUpdated = false;
|
||||||
|
if(actualValue != null){
|
||||||
|
isUpdated = true;
|
||||||
|
}
|
||||||
|
return isUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateForApprove(String json) {
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
|
|
||||||
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
|
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams);
|
||||||
|
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.account");
|
||||||
|
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
|
final LocalDate commencementDate = fromApiJsonHelper.extractLocalDateNamed("commencementDate", element);
|
||||||
|
baseDataValidator.reset().parameter("commencementDate").value(commencementDate).notNull();
|
||||||
|
|
||||||
|
final BigDecimal deposit = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("deposit", element);
|
||||||
|
baseDataValidator.reset().parameter("deposit").value(deposit).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final BigDecimal maturityInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("maturityInterestRate").value(maturityInterestRate).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer tenureInMonths = fromApiJsonHelper.extractIntegerNamed("tenureInMonths", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("tenureInMonths").value(tenureInMonths).ignoreIfNull().integerGreaterThanZero();
|
||||||
|
|
||||||
|
final Integer interestCompoundedEveryPeriodType = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEveryPeriodType", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(interestCompoundedEveryPeriodType).ignoreIfNull().inMinMaxRange(2, 2);
|
||||||
|
|
||||||
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateForRenew(String json) {
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
|
|
||||||
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
|
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams);
|
||||||
|
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.account");
|
||||||
|
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
|
final Long clientId = fromApiJsonHelper.extractLongNamed("clientId", element);
|
||||||
|
baseDataValidator.reset().parameter("clientId").value(clientId).ignoreIfNull();
|
||||||
|
|
||||||
|
final Long productId = fromApiJsonHelper.extractLongNamed("productId", element);
|
||||||
|
baseDataValidator.reset().parameter("productId").value(productId).ignoreIfNull();
|
||||||
|
|
||||||
|
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element);
|
||||||
|
baseDataValidator.reset().parameter("externalId").value(externalId).ignoreIfNull().notExceedingLengthOf(100);
|
||||||
|
|
||||||
|
final BigDecimal deposit = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("deposit", element);
|
||||||
|
baseDataValidator.reset().parameter("deposit").value(deposit).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final BigDecimal maturityInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("maturityInterestRate").value(maturityInterestRate).ignoreIfNull()
|
||||||
|
.zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final BigDecimal preClosureInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("preClosureInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("preClosureInterestRate").value(preClosureInterestRate).ignoreIfNull()
|
||||||
|
.zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer tenureInMonths = fromApiJsonHelper.extractIntegerNamed("tenureInMonths", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("tenureInMonths").value(tenureInMonths).ignoreIfNull().integerGreaterThanZero();
|
||||||
|
|
||||||
|
final Integer interestCompoundedEvery = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEvery", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("interestCompoundedEvery").value(interestCompoundedEvery).ignoreIfNull()
|
||||||
|
.integerGreaterThanZero();
|
||||||
|
|
||||||
|
final Integer interestCompoundedEveryPeriodType = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEveryPeriodType", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(interestCompoundedEveryPeriodType)
|
||||||
|
.ignoreIfNull().inMinMaxRange(2, 2);
|
||||||
|
|
||||||
|
final LocalDate commencementDate = fromApiJsonHelper.extractLocalDateNamed("commencementDate", element);
|
||||||
|
baseDataValidator.reset().parameter("commencementDate").value(commencementDate).ignoreIfNull();
|
||||||
|
|
||||||
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateForUpdate(String json) {
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
|
|
||||||
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
|
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams);
|
||||||
|
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.account");
|
||||||
|
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
|
final Long clientId = fromApiJsonHelper.extractLongNamed("clientId", element);
|
||||||
|
baseDataValidator.reset().parameter("clientId").value(clientId).ignoreIfNull();
|
||||||
|
|
||||||
|
final Long productId = fromApiJsonHelper.extractLongNamed("productId", element);
|
||||||
|
baseDataValidator.reset().parameter("productId").value(productId).ignoreIfNull();
|
||||||
|
|
||||||
|
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element);
|
||||||
|
baseDataValidator.reset().parameter("externalId").value(externalId).ignoreIfNull().notExceedingLengthOf(100);
|
||||||
|
|
||||||
|
final BigDecimal deposit = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("deposit", element);
|
||||||
|
baseDataValidator.reset().parameter("deposit").value(deposit).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer tenureInMonths = fromApiJsonHelper.extractIntegerNamed("tenureInMonths", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("tenureInMonths").value(tenureInMonths).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final BigDecimal maturityInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("maturityInterestRate").value(maturityInterestRate).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer interestCompoundedEvery = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEvery", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("interestCompoundedEvery").value(interestCompoundedEvery).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer interestCompoundedEveryPeriodType = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEveryPeriodType", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(interestCompoundedEveryPeriodType).ignoreIfNull().inMinMaxRange(1, 3);
|
||||||
|
|
||||||
|
final BigDecimal preClosureInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("preClosureInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("preClosureInterestRate").value(preClosureInterestRate).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final LocalDate commencementDate = fromApiJsonHelper.extractLocalDateNamed("commencementDate", element);
|
||||||
|
baseDataValidator.reset().parameter("commencementDate").value(commencementDate).ignoreIfNull();
|
||||||
|
|
||||||
|
final Boolean isInterestWithdrawable = fromApiJsonHelper.extractBooleanNamed("isInterestWithdrawable", element);
|
||||||
|
final Boolean isInterestWithdrawableChanged = isBooleanValueUpdated(isInterestWithdrawable);
|
||||||
|
baseDataValidator.reset().parameter("isInterestWithdrawable").trueOrFalseRequired(isInterestWithdrawableChanged);
|
||||||
|
|
||||||
|
final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).ignoreIfNull().inMinMaxRange(1, 3);
|
||||||
|
|
||||||
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+115
@@ -0,0 +1,115 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositaccount.serialization;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||||
|
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||||
|
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||||
|
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DepositAccountStateTransitionCommandFromApiJsonDeserializer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The parameters supported for this command.
|
||||||
|
*/
|
||||||
|
|
||||||
|
private final Set<String> supportedParams = new HashSet<String>(Arrays.asList("eventDate", "locale", "dateFormat", "note", "maturesOnDate", "amount" ));
|
||||||
|
|
||||||
|
private final FromJsonHelper fromApiJsonHelper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DepositAccountStateTransitionCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||||
|
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateForReject(String json) {
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
|
|
||||||
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
|
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams);
|
||||||
|
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.account");
|
||||||
|
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
|
final LocalDate eventDate = fromApiJsonHelper.extractLocalDateNamed("eventDate", element);
|
||||||
|
baseDataValidator.reset().parameter("eventDate").value(eventDate).notNull();
|
||||||
|
|
||||||
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
||||||
|
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||||
|
"Validation errors exist.", dataValidationErrors); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateForWithdrawDepositApplication(String json) {
|
||||||
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
|
|
||||||
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
|
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams);
|
||||||
|
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.account");
|
||||||
|
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
|
final LocalDate eventDate = fromApiJsonHelper.extractLocalDateNamed("eventDate", element);
|
||||||
|
baseDataValidator.reset().parameter("eventDate").value(eventDate).notNull();
|
||||||
|
|
||||||
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateForWithdrawDepositAmount(String json) {
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
|
|
||||||
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
|
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams);
|
||||||
|
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.account");
|
||||||
|
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
|
final LocalDate maturesOnDate = fromApiJsonHelper.extractLocalDateNamed("maturesOnDate", element);
|
||||||
|
baseDataValidator.reset().parameter("maturesOnDate").value(maturesOnDate).notNull();
|
||||||
|
|
||||||
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateForWithdrawInterestAmount(String json) {
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
|
|
||||||
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
|
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams);
|
||||||
|
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.account");
|
||||||
|
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
|
final BigDecimal amount = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("amount", element);
|
||||||
|
baseDataValidator.reset().parameter("deposit").value(amount).notNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+321
-149
@@ -7,9 +7,14 @@ package org.mifosplatform.portfolio.savingsdepositaccount.service;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||||
import org.mifosplatform.organisation.monetary.domain.Money;
|
import org.mifosplatform.organisation.monetary.domain.Money;
|
||||||
import org.mifosplatform.portfolio.client.domain.Client;
|
import org.mifosplatform.portfolio.client.domain.Client;
|
||||||
import org.mifosplatform.portfolio.client.domain.ClientRepository;
|
import org.mifosplatform.portfolio.client.domain.ClientRepository;
|
||||||
@@ -28,6 +33,8 @@ import org.mifosplatform.portfolio.savingsdepositproduct.exception.DepositProduc
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An assembler for turning {@link DepositAccountCommand} into
|
* An assembler for turning {@link DepositAccountCommand} into
|
||||||
* {@link DepositAccount}'s.
|
* {@link DepositAccount}'s.
|
||||||
@@ -38,91 +45,110 @@ public class DepositAccountAssembler {
|
|||||||
private final ClientRepository clientRepository;
|
private final ClientRepository clientRepository;
|
||||||
private final DepositProductRepository depositProductRepository;
|
private final DepositProductRepository depositProductRepository;
|
||||||
private final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator;
|
private final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator;
|
||||||
|
private final FromJsonHelper fromApiJsonHelper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DepositAccountAssembler(final ClientRepository clientRepository, final DepositProductRepository depositProductRepository,
|
public DepositAccountAssembler(final ClientRepository clientRepository, final DepositProductRepository depositProductRepository,
|
||||||
final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator) {
|
final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, final FromJsonHelper fromApiJsonHelper) {
|
||||||
this.clientRepository = clientRepository;
|
this.clientRepository = clientRepository;
|
||||||
this.depositProductRepository = depositProductRepository;
|
this.depositProductRepository = depositProductRepository;
|
||||||
this.fixedTermDepositInterestCalculator = fixedTermDepositInterestCalculator;
|
this.fixedTermDepositInterestCalculator = fixedTermDepositInterestCalculator;
|
||||||
|
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DepositAccount assembleFrom(final DepositAccountCommand command) {
|
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);
|
||||||
|
|
||||||
|
Client client = this.clientRepository.findOne(clientId);
|
||||||
|
if (client == null || client.isDeleted()) { throw new ClientNotFoundException(clientId); }
|
||||||
|
|
||||||
Client client = this.clientRepository.findOne(command.getClientId());
|
DepositProduct product = this.depositProductRepository.findOne(productId);
|
||||||
if (client == null || client.isDeleted()) { throw new ClientNotFoundException(command.getClientId()); }
|
if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(productId); }
|
||||||
|
|
||||||
DepositProduct product = this.depositProductRepository.findOne(command.getProductId());
|
|
||||||
if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(command.getProductId()); }
|
|
||||||
|
|
||||||
boolean isInterestWithdrawable = command.isInterestWithdrawable();
|
|
||||||
|
|
||||||
// details inherited from product setting (unless allowed to be
|
// details inherited from product setting (unless allowed to be
|
||||||
// overridden through account creation api
|
// overridden through account creation api
|
||||||
Money deposit = Money.of(product.getCurrency(), command.getDepositAmount());
|
Money deposit = Money.of(product.getCurrency(), depositValue);
|
||||||
|
|
||||||
Integer tenureInMonths = product.getTenureInMonths();
|
Integer tenureInMonths = product.getTenureInMonths();
|
||||||
if (command.getTenureInMonths() != null) {
|
if (tenureInMonthsCommandValue != null) {
|
||||||
tenureInMonths = command.getTenureInMonths();
|
tenureInMonths = tenureInMonthsCommandValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal maturityInterestRate = product.getMaturityDefaultInterestRate();
|
BigDecimal maturityInterestRate = product.getMaturityDefaultInterestRate();
|
||||||
if (command.getMaturityInterestRate() != null) {
|
if (maturityInterestRateCommandValue != null) {
|
||||||
maturityInterestRate = command.getMaturityInterestRate();
|
maturityInterestRate = maturityInterestRateCommandValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal preClosureInterestRate = product.getPreClosureInterestRate();
|
BigDecimal preClosureInterestRate = product.getPreClosureInterestRate();
|
||||||
if (command.getPreClosureInterestRate() != null) {
|
if (preClosureInterestRateCommandValue != null) {
|
||||||
preClosureInterestRate = command.getPreClosureInterestRate();
|
preClosureInterestRate = preClosureInterestRateCommandValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (product.getMaturityMinInterestRate().compareTo(preClosureInterestRate) == -1) { throw new DepositAccounDataValidationtException(
|
if (product.getMaturityMinInterestRate().compareTo(preClosureInterestRate) == -1) { throw new DepositAccounDataValidationtException(
|
||||||
preClosureInterestRate, product.getMaturityMinInterestRate()); }
|
preClosureInterestRate, product.getMaturityMinInterestRate()); }
|
||||||
|
|
||||||
Integer compoundingInterestEvery = product.getInterestCompoundedEvery();
|
Integer compoundingInterestEvery = product.getInterestCompoundedEvery();
|
||||||
if (command.getInterestCompoundedEvery() != null) {
|
if (interestCompoundedEveryCommandValue != null) {
|
||||||
compoundingInterestEvery = command.getInterestCompoundedEvery();
|
compoundingInterestEvery = interestCompoundedEveryCommandValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PeriodFrequencyType compoundingInterestFrequency = product.getInterestCompoundedEveryPeriodType();
|
PeriodFrequencyType compoundingInterestFrequency = product.getInterestCompoundedEveryPeriodType();
|
||||||
if (command.getInterestCompoundedEveryPeriodType() != null) {
|
if (interestCompoundedEveryPeriodTypeCommandValue != null) {
|
||||||
compoundingInterestFrequency = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType());
|
compoundingInterestFrequency = PeriodFrequencyType.fromInt(interestCompoundedEveryPeriodTypeCommandValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean renewalAllowed = product.isRenewalAllowed();
|
boolean renewalAllowed = product.isRenewalAllowed();
|
||||||
if (command.isRenewalAllowedChanged()) {
|
if (isBooleanValueUpdated(renewalAllowedCommandValue)) {
|
||||||
renewalAllowed = command.isRenewalAllowed();
|
renewalAllowed = renewalAllowedCommandValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean preClosureAllowed = product.isPreClosureAllowed();
|
boolean preClosureAllowed = product.isPreClosureAllowed();
|
||||||
if (command.isPreClosureAllowedChanged()) {
|
if (isBooleanValueUpdated(preClosureAllowedCommandValue)) {
|
||||||
preClosureAllowed = command.isPreClosureAllowed();
|
preClosureAllowed = preClosureAllowedCommandValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean interestCompoundingAllowed = product.isInterestCompoundingAllowed();
|
boolean interestCompoundingAllowed = product.isInterestCompoundingAllowed();
|
||||||
if (command.isInterestCompoundingAllowedChanged()) {
|
if (isBooleanValueUpdated(interestCompoundingAllowedCommandValue)) {
|
||||||
interestCompoundingAllowed = command.isInterestCompoundingAllowed();
|
interestCompoundingAllowed = interestCompoundingAllowedCommandValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isLockinPeriodAllowed = product.isLockinPeriodAllowed();
|
boolean isLockinPeriodAllowed = product.isLockinPeriodAllowed();
|
||||||
if (command.isLockinPeriodChanged()) {
|
if (isBooleanValueUpdated(isLockinPeriodAllowedCommandValue)) {
|
||||||
isLockinPeriodAllowed = command.isLockinPeriodAllowed();
|
isLockinPeriodAllowed = isLockinPeriodAllowedCommandValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer lockinPeriod = product.getLockinPeriod();
|
Integer lockinPeriod = product.getLockinPeriod();
|
||||||
if (command.getLockinPeriod() != null) {
|
if (lockinPeriodCommandValue != null) {
|
||||||
lockinPeriod = command.getLockinPeriod();
|
lockinPeriod = lockinPeriodCommandValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PeriodFrequencyType lockinPeriodType = product.getLockinPeriodType();
|
PeriodFrequencyType lockinPeriodType = product.getLockinPeriodType();
|
||||||
if (command.getLockinPeriodType() != null) {
|
if (lockinPeriodTypeCommandValue != null) {
|
||||||
lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType());
|
lockinPeriodType = PeriodFrequencyType.fromInt(lockinPeriodTypeCommandValue);
|
||||||
}
|
}
|
||||||
// end of details allowed to be overriden from product
|
// end of details allowed to be overriden from product
|
||||||
|
|
||||||
DepositAccount account = new DepositAccount().openNew(client, product, command.getExternalId(), deposit, maturityInterestRate,
|
DepositAccount account = new DepositAccount().openNew(client, product, externalId, deposit, maturityInterestRate,
|
||||||
preClosureInterestRate, tenureInMonths, compoundingInterestEvery, compoundingInterestFrequency,
|
preClosureInterestRate, tenureInMonths, compoundingInterestEvery, compoundingInterestFrequency,
|
||||||
command.getCommencementDate(), renewalAllowed, preClosureAllowed, this.fixedTermDepositInterestCalculator,
|
commencementDate, renewalAllowed, preClosureAllowed, this.fixedTermDepositInterestCalculator,
|
||||||
defaultDepositLifecycleStateMachine(), isInterestWithdrawable, interestCompoundingAllowed, isLockinPeriodAllowed,
|
defaultDepositLifecycleStateMachine(), isInterestWithdrawable, interestCompoundingAllowed, isLockinPeriodAllowed,
|
||||||
lockinPeriod, lockinPeriodType);
|
lockinPeriod, lockinPeriodType);
|
||||||
|
|
||||||
@@ -134,86 +160,147 @@ public class DepositAccountAssembler {
|
|||||||
return new DepositLifecycleStateMachineImpl(allowedDepositStatuses);
|
return new DepositLifecycleStateMachineImpl(allowedDepositStatuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DepositAccount assembleFrom(DepositAccount account, DepositAccountCommand command) {
|
public DepositAccount assembleFrom(DepositAccount account, JsonCommand command) {
|
||||||
|
|
||||||
|
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20);
|
||||||
|
final String localeAsInput = command.locale();
|
||||||
|
|
||||||
Client client = account.client();
|
Client client = account.client();
|
||||||
|
|
||||||
DepositProduct product = account.product();
|
DepositProduct product = account.product();
|
||||||
if (command.getProductId() != null) {
|
final String productIdParamName = "productId";
|
||||||
product = this.depositProductRepository.findOne(command.getProductId());
|
if (command.isChangeInLongParameterNamed(productIdParamName, account.product().getId())) {
|
||||||
if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(command.getProductId()); }
|
final Long newValue = command.longValueOfParameterNamed(productIdParamName);
|
||||||
|
if (newValue != null) {
|
||||||
|
product = this.depositProductRepository.findOne(newValue);
|
||||||
|
if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(newValue); }
|
||||||
|
}
|
||||||
|
actualChanges.put(productIdParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
Money deposit = account.getDeposit();
|
Money deposit = account.getDeposit();
|
||||||
if (command.getDepositAmount() != null) {
|
final String depositParamName = "deposit";
|
||||||
deposit = Money.of(account.getDeposit().getCurrency(), command.getDepositAmount());
|
if (command.isChangeInBigDecimalParameterNamed(depositParamName, deposit.getAmount())) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(depositParamName);
|
||||||
|
actualChanges.put(depositParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
deposit = Money.of(deposit.getCurrency(), newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer tenureInMonths = account.getTenureInMonths();
|
Integer tenureInMonths = account.getTenureInMonths();
|
||||||
if (command.getTenureInMonths() != null) {
|
final String tenureInMonthsParamName = "tenureInMonths";
|
||||||
tenureInMonths = command.getTenureInMonths();
|
if (command.isChangeInIntegerParameterNamed(tenureInMonthsParamName, tenureInMonths)) {
|
||||||
|
final Integer newValue = command.integerValueOfParameterNamed(tenureInMonthsParamName);
|
||||||
|
actualChanges.put(tenureInMonthsParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
tenureInMonths = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal maturityInterestRate = account.getInterestRate();
|
BigDecimal maturityInterestRate = account.getInterestRate();
|
||||||
if (command.getMaturityInterestRate() != null) {
|
final String maturityInterestRateParamName = "maturityInterestRate";
|
||||||
maturityInterestRate = command.getMaturityInterestRate();
|
if (command.isChangeInBigDecimalParameterNamed(maturityInterestRateParamName, maturityInterestRate)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(maturityInterestRateParamName);
|
||||||
|
actualChanges.put(maturityInterestRateParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
maturityInterestRate = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal preClosureInterestRate = account.getPreClosureInterestRate();
|
BigDecimal preClosureInterestRate = account.getPreClosureInterestRate();
|
||||||
if (command.getPreClosureInterestRate() != null) {
|
final String preClosureInterestRateParamName = "preClosureInterestRate";
|
||||||
preClosureInterestRate = command.getPreClosureInterestRate();
|
if (command.isChangeInBigDecimalParameterNamed(preClosureInterestRateParamName, preClosureInterestRate)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(preClosureInterestRateParamName);
|
||||||
|
actualChanges.put(preClosureInterestRateParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
preClosureInterestRate = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (product.getMaturityMinInterestRate().compareTo(preClosureInterestRate) == -1) { throw new DepositAccounDataValidationtException(
|
if (product.getMaturityMinInterestRate().compareTo(preClosureInterestRate) == -1) { throw new DepositAccounDataValidationtException(
|
||||||
preClosureInterestRate, product.getMaturityMinInterestRate()); }
|
preClosureInterestRate, product.getMaturityMinInterestRate()); }
|
||||||
|
|
||||||
Integer compoundingInterestEvery = account.getInterestCompoundedEvery();
|
Integer interestCompoundedEvery = account.getInterestCompoundedEvery();
|
||||||
if (command.getInterestCompoundedEvery() != null) {
|
final String interestCompoundedEveryParamName = "interestCompoundedEvery";
|
||||||
compoundingInterestEvery = command.getInterestCompoundedEvery();
|
if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryParamName, interestCompoundedEvery)) {
|
||||||
|
final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryParamName);
|
||||||
|
actualChanges.put(interestCompoundedEveryParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
interestCompoundedEvery = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PeriodFrequencyType compoundingInterestFrequency = account.getInterestCompoundedFrequencyType();
|
PeriodFrequencyType interestCompoundedEveryPeriodType = account.getInterestCompoundedFrequencyType();
|
||||||
if (command.getInterestCompoundedEveryPeriodType() != null) {
|
final String interestCompoundedEveryPeriodTypeParamName = "interestCompoundedEveryPeriodType";
|
||||||
compoundingInterestFrequency = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType());
|
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();
|
Boolean renewalAllowed = account.isRenewalAllowed();
|
||||||
if (command.isRenewalAllowedChanged()) {
|
final String renewalAllowedParamName = "renewalAllowed";
|
||||||
renewalAllowed = command.isRenewalAllowed();
|
if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, renewalAllowed)) {
|
||||||
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName);
|
||||||
|
actualChanges.put(renewalAllowedParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
renewalAllowed = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean preClosureAllowed = account.isPreClosureAllowed();
|
Boolean preClosureAllowed = account.isPreClosureAllowed();
|
||||||
if (command.isPreClosureAllowedChanged()) {
|
final String preClosureAllowedParamName = "preClosureAllowed";
|
||||||
preClosureAllowed = command.isPreClosureAllowed();
|
if (command.isChangeInBooleanParameterNamed(preClosureAllowedParamName, preClosureAllowed)) {
|
||||||
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName);
|
||||||
|
actualChanges.put(preClosureAllowedParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
preClosureAllowed = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isInterestWithdrawable = account.isInterestWithdrawable();
|
Boolean isInterestWithdrawable = account.isInterestWithdrawable();
|
||||||
if (command.isInterestWithdrawableChanged()) {
|
final String isInterestWithdrawableParamName = "isInterestWithdrawable";
|
||||||
isInterestWithdrawable = command.isInterestWithdrawable();
|
if (command.isChangeInBooleanParameterNamed(isInterestWithdrawableParamName, isInterestWithdrawable)) {
|
||||||
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName);
|
||||||
|
actualChanges.put(isInterestWithdrawableParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
isInterestWithdrawable = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed();
|
Boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed();
|
||||||
if (command.isInterestCompoundingAllowedChanged()) {
|
final String isInterestCompoundingAllowedParamName = "interestCompoundingAllowed";
|
||||||
isInterestCompoundingAllowed = command.isInterestCompoundingAllowed();
|
if (command.isChangeInBooleanParameterNamed(isInterestCompoundingAllowedParamName, isInterestCompoundingAllowed)) {
|
||||||
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestCompoundingAllowedParamName);
|
||||||
|
actualChanges.put(isInterestCompoundingAllowedParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
isInterestCompoundingAllowed = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed();
|
Boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed();
|
||||||
if (command.isLockinPeriodChanged()) {
|
final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed";
|
||||||
isLockinPeriodAllowed = command.isLockinPeriodAllowed();
|
if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, isLockinPeriodAllowed)) {
|
||||||
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName);
|
||||||
|
actualChanges.put(isLockinPeriodAllowedParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
isLockinPeriodAllowed = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer lockinPeriod = account.getLockinPeriod();
|
Integer lockinPeriod = account.getLockinPeriod();
|
||||||
if (command.getLockinPeriod() != null) {
|
final String lockinPeriodParamName = "lockinPeriod";
|
||||||
lockinPeriod = command.getLockinPeriod();
|
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();
|
PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType();
|
||||||
if (command.getLockinPeriodType() != null) {
|
final String lockinPeriodTypeParamName = "lockinPeriodType";
|
||||||
lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType());
|
if (command.isChangeInIntegerParameterNamed(lockinPeriodTypeParamName, lockinPeriodType.getValue())) {
|
||||||
|
final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodTypeParamName);
|
||||||
|
actualChanges.put(lockinPeriodTypeParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
lockinPeriodType = PeriodFrequencyType.fromInt(newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
DepositAccount newAccount = new DepositAccount().openNew(client, product, null, deposit, maturityInterestRate,
|
DepositAccount newAccount = new DepositAccount().openNew(client, product, null, deposit, maturityInterestRate,
|
||||||
preClosureInterestRate, tenureInMonths, compoundingInterestEvery, compoundingInterestFrequency, account.maturesOnDate()
|
preClosureInterestRate, tenureInMonths, interestCompoundedEvery, interestCompoundedEveryPeriodType, account.maturesOnDate()
|
||||||
.plusDays(1), renewalAllowed, preClosureAllowed, this.fixedTermDepositInterestCalculator,
|
.plusDays(1), renewalAllowed, preClosureAllowed, this.fixedTermDepositInterestCalculator,
|
||||||
defaultDepositLifecycleStateMachine(), isInterestWithdrawable, isInterestCompoundingAllowed, isLockinPeriodAllowed,
|
defaultDepositLifecycleStateMachine(), isInterestWithdrawable, isInterestCompoundingAllowed, isLockinPeriodAllowed,
|
||||||
lockinPeriod, lockinPeriodType);
|
lockinPeriod, lockinPeriodType);
|
||||||
@@ -223,121 +310,206 @@ public class DepositAccountAssembler {
|
|||||||
return newAccount;
|
return newAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
public Map<String, Object> assembleUpdatedDepositAccount(DepositAccount account, JsonCommand command) {
|
||||||
* public void adjustTotalAmountForPreclosureInterest(DepositAccount
|
|
||||||
* account,LocalDate eventDate) {
|
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20);
|
||||||
* account.adjustTotalAmountForPreclosureInterest
|
final String localeAsInput = command.locale();
|
||||||
* (account,this.fixedTermDepositInterestCalculator,eventDate); }
|
|
||||||
*/
|
DepositProduct product = account.product();
|
||||||
|
final String productIdParamName = "productId";
|
||||||
public void assembleUpdatedDepositAccount(DepositAccount account, DepositAccountCommand command) {
|
if (command.isChangeInLongParameterNamed(productIdParamName, account.product().getId())) {
|
||||||
|
final Long newValue = command.longValueOfParameterNamed(productIdParamName);
|
||||||
DepositProduct product = account.product();
|
if (newValue != null) {
|
||||||
if (command.getProductId() != null) {
|
product = this.depositProductRepository.findOne(newValue);
|
||||||
product = this.depositProductRepository.findOne(command.getProductId());
|
if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(newValue); }
|
||||||
if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(command.getProductId()); }
|
}
|
||||||
|
actualChanges.put(productIdParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
String externalId = account.getExternalId();
|
String externalId = account.getExternalId();
|
||||||
if (command.isExternalIdChanged()) {
|
final String externalIdParamName = "externalId";
|
||||||
externalId = command.getExternalId();
|
if (command.isChangeInStringParameterNamed(externalIdParamName, externalId)) {
|
||||||
|
final String newValue = command.stringValueOfParameterNamed(externalIdParamName);
|
||||||
|
actualChanges.put(externalIdParamName, newValue);
|
||||||
|
externalId = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalDate commencementDate = account.getProjectedCommencementDate();
|
LocalDate commencementDate = account.getProjectedCommencementDate();
|
||||||
if (command.isCommencementDateChanged()) {
|
final String commencementDateParamName = "commencementDate";
|
||||||
commencementDate = new LocalDate(command.getCommencementDate());
|
if (command.isChangeInLocalDateParameterNamed("commencementDate", commencementDate)) {
|
||||||
}
|
final LocalDate newValue = command.localDateValueOfParameterNamed(commencementDateParamName);
|
||||||
|
actualChanges.put(commencementDateParamName, newValue);
|
||||||
|
commencementDate = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
Money deposit = account.getDeposit();
|
Money deposit = account.getDeposit();
|
||||||
if (command.isDepositAmountChanged()) {
|
final String depositParamName = "deposit";
|
||||||
deposit = Money.of(product.getCurrency(), command.getDepositAmount());
|
if (command.isChangeInBigDecimalParameterNamed(depositParamName, deposit.getAmount())) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(depositParamName);
|
||||||
|
actualChanges.put(depositParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
deposit = Money.of(deposit.getCurrency(), newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer tenureInMonths = account.getTenureInMonths();
|
Integer tenureInMonths = account.getTenureInMonths();
|
||||||
if (command.isTenureInMonthsChanged()) {
|
final String tenureInMonthsParamName = "tenureInMonths";
|
||||||
tenureInMonths = command.getTenureInMonths();
|
if (command.isChangeInIntegerParameterNamed(tenureInMonthsParamName, tenureInMonths)) {
|
||||||
|
final Integer newValue = command.integerValueOfParameterNamed(tenureInMonthsParamName);
|
||||||
|
actualChanges.put(tenureInMonthsParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
tenureInMonths = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal maturityInterestRate = account.getInterestRate();
|
BigDecimal maturityInterestRate = account.getInterestRate();
|
||||||
if (command.isMaturityActualInterestRateChanged()) {
|
final String maturityInterestRateParamName = "maturityInterestRate";
|
||||||
maturityInterestRate = command.getMaturityInterestRate();
|
if (command.isChangeInBigDecimalParameterNamed(maturityInterestRateParamName, maturityInterestRate)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(maturityInterestRateParamName);
|
||||||
|
actualChanges.put(maturityInterestRateParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
maturityInterestRate = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal preClosureInterestRate = account.getPreClosureInterestRate();
|
BigDecimal preClosureInterestRate = account.getPreClosureInterestRate();
|
||||||
if (command.isPreClosureInterestRateChanged()) {
|
final String preClosureInterestRateParamName = "preClosureInterestRate";
|
||||||
preClosureInterestRate = command.getPreClosureInterestRate();
|
if (command.isChangeInBigDecimalParameterNamed(preClosureInterestRateParamName, preClosureInterestRate)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(preClosureInterestRateParamName);
|
||||||
|
actualChanges.put(preClosureInterestRateParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
preClosureInterestRate = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (product.getMaturityMinInterestRate().compareTo(preClosureInterestRate) == -1) { throw new DepositAccounDataValidationtException(
|
if (product.getMaturityMinInterestRate().compareTo(preClosureInterestRate) == -1) { throw new DepositAccounDataValidationtException(
|
||||||
preClosureInterestRate, product.getMaturityMinInterestRate()); }
|
preClosureInterestRate, product.getMaturityMinInterestRate()); }
|
||||||
|
|
||||||
Integer compoundingInterestEvery = account.getInterestCompoundedEvery();
|
Integer interestCompoundedEvery = account.getInterestCompoundedEvery();
|
||||||
if (command.isCompoundingInterestEveryChanged()) {
|
final String interestCompoundedEveryParamName = "interestCompoundedEvery";
|
||||||
compoundingInterestEvery = command.getInterestCompoundedEvery();
|
if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryParamName, interestCompoundedEvery)) {
|
||||||
|
final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryParamName);
|
||||||
|
actualChanges.put(interestCompoundedEveryParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
interestCompoundedEvery = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PeriodFrequencyType compoundingInterestFrequency = account.getInterestCompoundedFrequencyType();
|
PeriodFrequencyType interestCompoundedEveryPeriodType = account.getInterestCompoundedFrequencyType();
|
||||||
if (command.getInterestCompoundedEveryPeriodType() != null) {
|
final String interestCompoundedEveryPeriodTypeParamName = "interestCompoundedEveryPeriodType";
|
||||||
compoundingInterestFrequency = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType());
|
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();
|
Boolean renewalAllowed = account.isRenewalAllowed();
|
||||||
if (command.isRenewalAllowedChanged()) {
|
final String renewalAllowedParamName = "renewalAllowed";
|
||||||
renewalAllowed = command.isRenewalAllowed();
|
if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, renewalAllowed)) {
|
||||||
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName);
|
||||||
|
actualChanges.put(renewalAllowedParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
renewalAllowed = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean preClosureAllowed = account.isPreClosureAllowed();
|
Boolean preClosureAllowed = account.isPreClosureAllowed();
|
||||||
if (command.isPreClosureAllowedChanged()) {
|
final String preClosureAllowedParamName = "preClosureAllowed";
|
||||||
preClosureAllowed = command.isPreClosureAllowed();
|
if (command.isChangeInBooleanParameterNamed(preClosureAllowedParamName, preClosureAllowed)) {
|
||||||
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName);
|
||||||
|
actualChanges.put(preClosureAllowedParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
preClosureAllowed = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isInterestWithdrawable = account.isInterestWithdrawable();
|
Boolean isInterestWithdrawable = account.isInterestWithdrawable();
|
||||||
if (command.isInterestWithdrawableChanged()) {
|
final String isInterestWithdrawableParamName = "isInterestWithdrawable";
|
||||||
isInterestWithdrawable = command.isInterestWithdrawable();
|
if (command.isChangeInBooleanParameterNamed(isInterestWithdrawableParamName, isInterestWithdrawable)) {
|
||||||
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName);
|
||||||
|
actualChanges.put(isInterestWithdrawableParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
isInterestWithdrawable = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed();
|
Boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed();
|
||||||
if (command.isInterestCompoundingAllowedChanged()) {
|
final String isInterestCompoundingAllowedParamName = "interestCompoundingAllowed";
|
||||||
isInterestCompoundingAllowed = command.isInterestCompoundingAllowed();
|
if (command.isChangeInBooleanParameterNamed(isInterestCompoundingAllowedParamName, isInterestCompoundingAllowed)) {
|
||||||
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestCompoundingAllowedParamName);
|
||||||
|
actualChanges.put(isInterestCompoundingAllowedParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
isInterestCompoundingAllowed = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed();
|
Boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed();
|
||||||
if (command.isLockinPeriodChanged()) {
|
final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed";
|
||||||
isLockinPeriodAllowed = command.isLockinPeriodAllowed();
|
if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, isLockinPeriodAllowed)) {
|
||||||
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName);
|
||||||
|
actualChanges.put(isLockinPeriodAllowedParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
isLockinPeriodAllowed = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer lockinPeriod = account.getLockinPeriod();
|
Integer lockinPeriod = account.getLockinPeriod();
|
||||||
if (command.getLockinPeriod() != null) {
|
final String lockinPeriodParamName = "lockinPeriod";
|
||||||
lockinPeriod = command.getLockinPeriod();
|
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();
|
PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType();
|
||||||
if (command.getLockinPeriodType() != null) {
|
final String lockinPeriodTypeParamName = "lockinPeriodType";
|
||||||
lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType());
|
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,
|
account.update(product, externalId, commencementDate, deposit, tenureInMonths, maturityInterestRate, preClosureInterestRate,
|
||||||
compoundingInterestEvery, compoundingInterestFrequency, renewalAllowed, preClosureAllowed, isInterestWithdrawable,
|
interestCompoundedEvery, interestCompoundedEveryPeriodType, renewalAllowed, preClosureAllowed, isInterestWithdrawable,
|
||||||
isInterestCompoundingAllowed, this.fixedTermDepositInterestCalculator, isLockinPeriodAllowed, lockinPeriod,
|
isInterestCompoundingAllowed, this.fixedTermDepositInterestCalculator, isLockinPeriodAllowed, lockinPeriod,
|
||||||
lockinPeriodType);
|
lockinPeriodType);
|
||||||
|
|
||||||
|
return actualChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateApprovedDepositAccount(DepositAccount account, DepositAccountCommand command) {
|
public Map<String, Object> updateApprovedDepositAccount(DepositAccount account, JsonCommand command) {
|
||||||
|
|
||||||
boolean renewalAllowed = account.isRenewalAllowed();
|
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20);
|
||||||
if (command.isRenewalAllowedChanged()) {
|
final String localeAsInput = command.locale();
|
||||||
renewalAllowed = command.isRenewalAllowed();
|
|
||||||
|
Boolean renewalAllowed = account.isRenewalAllowed();
|
||||||
|
final String renewalAllowedParamName = "renewalAllowed";
|
||||||
|
if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, renewalAllowed)) {
|
||||||
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName);
|
||||||
|
actualChanges.put(renewalAllowedParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
renewalAllowed = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isInterestWithdrawable = account.isInterestWithdrawable();
|
Boolean isInterestWithdrawable = account.isInterestWithdrawable();
|
||||||
if (command.isInterestWithdrawableChanged()) {
|
final String isInterestWithdrawableParamName = "isInterestWithdrawable";
|
||||||
isInterestWithdrawable = command.isInterestWithdrawable();
|
if (command.isChangeInBooleanParameterNamed(isInterestWithdrawableParamName, isInterestWithdrawable)) {
|
||||||
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName);
|
||||||
|
actualChanges.put(isInterestWithdrawableParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
isInterestWithdrawable = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
account.update(renewalAllowed, isInterestWithdrawable);
|
account.update(renewalAllowed, isInterestWithdrawable);
|
||||||
|
|
||||||
|
return actualChanges;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void postInterest(DepositAccount account) {
|
public void postInterest(DepositAccount account) {
|
||||||
account.postInterestForDepositAccount(account, this.fixedTermDepositInterestCalculator);
|
account.postInterestForDepositAccount(account, this.fixedTermDepositInterestCalculator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Boolean isBooleanValueUpdated(Boolean actualValue) {
|
||||||
|
Boolean isUpdated = false;
|
||||||
|
if(actualValue != null){
|
||||||
|
isUpdated = true;
|
||||||
|
}
|
||||||
|
return isUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -155,7 +155,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead
|
|||||||
+ " ecd.father_name as fatherName, ecd.client_address as clientAddress " + " from m_deposit_account da "
|
+ " ecd.father_name as fatherName, ecd.client_address as clientAddress " + " from m_deposit_account da "
|
||||||
+ " join m_currency curr on curr.code = da.currency_code " + " join m_client c on c.id = da.client_id "
|
+ " join m_currency curr on curr.code = da.currency_code " + " join m_client c on c.id = da.client_id "
|
||||||
+ " join m_product_deposit pd on pd.id = da.product_id"
|
+ " join m_product_deposit pd on pd.id = da.product_id"
|
||||||
+ " left join extra_client_details ecd on da.client_id = ecd.client_id ";
|
+ " left join extra_client_details_hugo_specific ecd on da.client_id = ecd.client_id ";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+11
-25
@@ -7,56 +7,42 @@ package org.mifosplatform.portfolio.savingsdepositaccount.service;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.portfolio.loanaccount.command.UndoStateTransitionCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountWithdrawInterestCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountWithdrawalCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionApprovalCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositAccountsForLookup;
|
import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositAccountsForLookup;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
|
||||||
public interface DepositAccountWritePlatformService {
|
public interface DepositAccountWritePlatformService {
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'CREATE_DEPOSITACCOUNT')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'CREATE_DEPOSITACCOUNT')")
|
||||||
CommandProcessingResult createDepositAccount(DepositAccountCommand command);
|
CommandProcessingResult createDepositAccount(JsonCommand command);
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'UPDATE_DEPOSITACCOUNT')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'UPDATE_DEPOSITACCOUNT')")
|
||||||
CommandProcessingResult updateDepositAccount(DepositAccountCommand command);
|
CommandProcessingResult updateDepositAccount(Long accountId, JsonCommand command);
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'DELETE_DEPOSITACCOUNT')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'DELETE_DEPOSITACCOUNT')")
|
||||||
CommandProcessingResult deleteDepositAccount(Long productId);
|
CommandProcessingResult deleteDepositAccount(Long entityId);
|
||||||
|
|
||||||
// NOTE - took out permissions relating to doing things with deposit
|
|
||||||
// accounts in the past as doesn't appear to be code for it
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'APPROVE_DEPOSITACCOUNT')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'APPROVE_DEPOSITACCOUNT')")
|
||||||
CommandProcessingResult approveDepositApplication(DepositStateTransitionApprovalCommand command);
|
CommandProcessingResult approveDepositApplication(JsonCommand command);
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'REJECT_DEPOSITACCOUNT')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'REJECT_DEPOSITACCOUNT')")
|
||||||
CommandProcessingResult rejectDepositApplication(DepositStateTransitionCommand command);
|
CommandProcessingResult rejectDepositApplication(JsonCommand command);
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'WITHDRAW_DEPOSITACCOUNT')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'WITHDRAW_DEPOSITACCOUNT')")
|
||||||
CommandProcessingResult withdrawDepositApplication(DepositStateTransitionCommand command);
|
CommandProcessingResult withdrawDepositApplication(JsonCommand command);
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'APPROVALUNDO_DEPOSITACCOUNT')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'APPROVALUNDO_DEPOSITACCOUNT')")
|
||||||
CommandProcessingResult undoDepositApproval(UndoStateTransitionCommand undoCommand);
|
CommandProcessingResult undoDepositApproval(JsonCommand undoCommand);
|
||||||
|
|
||||||
/*
|
|
||||||
* @PreAuthorize(value =
|
|
||||||
* "hasAnyRole('ALL_FUNCTIONS', '')" )
|
|
||||||
* EntityIdentifier matureDepositApplication(DepositStateTransitionCommand
|
|
||||||
* command);
|
|
||||||
*/
|
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'WITHDRAWAL_DEPOSITACCOUNT')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'WITHDRAWAL_DEPOSITACCOUNT')")
|
||||||
CommandProcessingResult withdrawDepositAccountMoney(DepositAccountWithdrawalCommand command);
|
CommandProcessingResult withdrawDepositAccountMoney(JsonCommand command);
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'INTEREST_DEPOSITACCOUNT')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'INTEREST_DEPOSITACCOUNT')")
|
||||||
CommandProcessingResult withdrawDepositAccountInterestMoney(DepositAccountWithdrawInterestCommand command);
|
CommandProcessingResult withdrawDepositAccountInterestMoney(JsonCommand command);
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'RENEW_DEPOSITACCOUNT')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'RENEW_DEPOSITACCOUNT')")
|
||||||
CommandProcessingResult renewDepositAccount(DepositAccountCommand command);
|
CommandProcessingResult renewDepositAccount(JsonCommand command);
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS')")
|
||||||
CommandProcessingResult postInterestToDepositAccount(Collection<DepositAccountsForLookup> accounts);
|
CommandProcessingResult postInterestToDepositAccount(Collection<DepositAccountsForLookup> accounts);
|
||||||
|
|||||||
+133
-177
@@ -8,27 +8,22 @@ package org.mifosplatform.portfolio.savingsdepositaccount.service;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||||
|
import org.mifosplatform.infrastructure.security.exception.NoAuthorizationException;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.organisation.monetary.domain.Money;
|
import org.mifosplatform.organisation.monetary.domain.Money;
|
||||||
import org.mifosplatform.portfolio.client.domain.Note;
|
import org.mifosplatform.portfolio.client.domain.Note;
|
||||||
import org.mifosplatform.portfolio.client.domain.NoteRepository;
|
import org.mifosplatform.portfolio.client.domain.NoteRepository;
|
||||||
import org.mifosplatform.portfolio.loanaccount.command.UndoStateTransitionCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsaccountproduct.exception.SavingsProductNotFoundException;
|
import org.mifosplatform.portfolio.savingsaccountproduct.exception.SavingsProductNotFoundException;
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountCommandValidator;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountWithdrawInterestCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountWithdrawalCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountWithdrawalCommandValidator;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionApprovalCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionApprovalCommandValidator;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.WithDrawDepositAccountInterestCommandValidator;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositAccountsForLookup;
|
import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositAccountsForLookup;
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.domain.DepositAccount;
|
import org.mifosplatform.portfolio.savingsdepositaccount.domain.DepositAccount;
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.domain.DepositAccountRepository;
|
import org.mifosplatform.portfolio.savingsdepositaccount.domain.DepositAccountRepository;
|
||||||
@@ -39,6 +34,8 @@ import org.mifosplatform.portfolio.savingsdepositaccount.domain.FixedTermDeposit
|
|||||||
import org.mifosplatform.portfolio.savingsdepositaccount.exception.DepositAccountNotFoundException;
|
import org.mifosplatform.portfolio.savingsdepositaccount.exception.DepositAccountNotFoundException;
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.exception.DepositAccountReopenException;
|
import org.mifosplatform.portfolio.savingsdepositaccount.exception.DepositAccountReopenException;
|
||||||
import org.mifosplatform.portfolio.savingsdepositaccount.exception.DepositAccountTransactionsException;
|
import org.mifosplatform.portfolio.savingsdepositaccount.exception.DepositAccountTransactionsException;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositaccount.serialization.DepositAccountCommandFromApiJsonDeserializer;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositaccount.serialization.DepositAccountStateTransitionCommandFromApiJsonDeserializer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -56,28 +53,36 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
private final DepositAccountAssembler depositAccountAssembler;
|
private final DepositAccountAssembler depositAccountAssembler;
|
||||||
private final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator;
|
private final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator;
|
||||||
private final NoteRepository noteRepository;
|
private final NoteRepository noteRepository;
|
||||||
|
private final DepositAccountCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||||
|
private final DepositAccountStateTransitionCommandFromApiJsonDeserializer depositAccountStateTransitionCommandFromApiJsonDeserializer;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DepositAccountWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
public DepositAccountWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
||||||
final DepositAccountRepository depositAccountRepository, final DepositAccountAssembler depositAccountAssembler,
|
final DepositAccountRepository depositAccountRepository, final DepositAccountAssembler depositAccountAssembler,
|
||||||
final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, final NoteRepository noteRepository) {
|
final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, final NoteRepository noteRepository,
|
||||||
|
final DepositAccountCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||||
|
final DepositAccountStateTransitionCommandFromApiJsonDeserializer depositAccountStateTransitionCommandFromApiJsonDeserializer) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.depositAccountRepository = depositAccountRepository;
|
this.depositAccountRepository = depositAccountRepository;
|
||||||
this.depositAccountAssembler = depositAccountAssembler;
|
this.depositAccountAssembler = depositAccountAssembler;
|
||||||
this.fixedTermDepositInterestCalculator = fixedTermDepositInterestCalculator;
|
this.fixedTermDepositInterestCalculator = fixedTermDepositInterestCalculator;
|
||||||
this.noteRepository = noteRepository;
|
this.noteRepository = noteRepository;
|
||||||
|
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||||
|
this.depositAccountStateTransitionCommandFromApiJsonDeserializer = depositAccountStateTransitionCommandFromApiJsonDeserializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Guaranteed to throw an exception no matter what the data integrity issue
|
* Guaranteed to throw an exception no matter what the data integrity issue
|
||||||
* is.
|
* is.
|
||||||
*/
|
*/
|
||||||
private void handleDataIntegrityIssues(final DepositAccountCommand command, final DataIntegrityViolationException dve) {
|
private void handleDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) {
|
||||||
|
|
||||||
Throwable realCause = dve.getMostSpecificCause();
|
Throwable realCause = dve.getMostSpecificCause();
|
||||||
if (realCause.getMessage().contains("deposit_acc_external_id")) { throw new PlatformDataIntegrityException(
|
if (realCause.getMessage().contains("deposit_acc_external_id")) {
|
||||||
"error.msg.desposit.account.duplicate.externalId", "Deposit account with externalId " + command.getExternalId()
|
final String externalId = command.stringValueOfParameterNamed("externalId");
|
||||||
+ " already exists", "externalId", command.getExternalId()); }
|
throw new PlatformDataIntegrityException(
|
||||||
|
"error.msg.desposit.account.duplicate.externalId", "Deposit account with externalId " + externalId
|
||||||
|
+ " already exists", "externalId", externalId); }
|
||||||
|
|
||||||
logger.error(dve.getMessage(), dve);
|
logger.error(dve.getMessage(), dve);
|
||||||
throw new PlatformDataIntegrityException("error.msg.deposit.account.unknown.data.integrity.issue",
|
throw new PlatformDataIntegrityException("error.msg.deposit.account.unknown.data.integrity.issue",
|
||||||
@@ -86,18 +91,18 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult createDepositAccount(final DepositAccountCommand command) {
|
public CommandProcessingResult createDepositAccount(final JsonCommand command) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
this.fromApiJsonDeserializer.validateForCreate(command.json());
|
||||||
DepositAccountCommandValidator validator = new DepositAccountCommandValidator(command);
|
|
||||||
validator.validateForCreate();
|
|
||||||
|
|
||||||
final DepositAccount account = this.depositAccountAssembler.assembleFrom(command);
|
final DepositAccount account = this.depositAccountAssembler.assembleFrom(command);
|
||||||
this.depositAccountRepository.save(account);
|
this.depositAccountRepository.save(account);
|
||||||
|
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
} catch (DataIntegrityViolationException dve) {
|
} catch (DataIntegrityViolationException dve) {
|
||||||
handleDataIntegrityIssues(command, dve);
|
handleDataIntegrityIssues(command, dve);
|
||||||
return new CommandProcessingResult(Long.valueOf(-1));
|
return new CommandProcessingResult(Long.valueOf(-1));
|
||||||
@@ -116,49 +121,43 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
account.delete();
|
account.delete();
|
||||||
this.depositAccountRepository.save(account);
|
this.depositAccountRepository.save(account);
|
||||||
|
|
||||||
return new CommandProcessingResult(accountId);
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(accountId) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult approveDepositApplication(final DepositStateTransitionApprovalCommand command) {
|
public CommandProcessingResult approveDepositApplication(final JsonCommand command) {
|
||||||
|
|
||||||
// AppUser currentUser = context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
this.fromApiJsonDeserializer.validateForApprove(command.json());
|
||||||
|
|
||||||
DepositStateTransitionApprovalCommandValidator validator = new DepositStateTransitionApprovalCommandValidator(command);
|
DepositAccount account = this.depositAccountRepository.findOne(command.entityId());
|
||||||
validator.validate();
|
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.entityId()); }
|
||||||
|
|
||||||
DepositAccount account = this.depositAccountRepository.findOne(command.getAccountId());
|
final LocalDate commencementDate = command.localDateValueOfParameterNamed("commencementDate");
|
||||||
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.getAccountId()); }
|
|
||||||
|
|
||||||
// FIXME - madhukar - you are checking for loan permission here instead
|
Map<String, Object> actualChanges = account.approve(commencementDate, defaultDepositLifecycleStateMachine(), command, this.fixedTermDepositInterestCalculator);
|
||||||
// of some specific deposit account permission.
|
|
||||||
// removing check for now until rules dealing with creating and
|
|
||||||
// maintaining deposit accounts in the past is clarified
|
|
||||||
LocalDate eventDate = command.getEventDate();
|
|
||||||
// if (this.isBeforeToday(eventDate) &&
|
|
||||||
// currentUser.canNotApproveLoanInPast()) {
|
|
||||||
// throw new
|
|
||||||
// NoAuthorizationException("User has no authority to approve deposit with a date in the past.");
|
|
||||||
// }
|
|
||||||
|
|
||||||
account.approve(eventDate, defaultDepositLifecycleStateMachine(), command, this.fixedTermDepositInterestCalculator);
|
|
||||||
|
|
||||||
this.depositAccountRepository.save(account);
|
this.depositAccountRepository.save(account);
|
||||||
|
|
||||||
String noteText = command.getNote();
|
String noteText = command.stringValueOfParameterNamed("note");
|
||||||
if (StringUtils.isNotBlank(noteText)) {
|
if (StringUtils.isNotBlank(noteText)) {
|
||||||
Note note = Note.depositNote(account, noteText);
|
Note note = Note.depositNote(account, noteText);
|
||||||
this.noteRepository.save(note);
|
this.noteRepository.save(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.with(actualChanges)
|
||||||
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private boolean isBeforeToday(final LocalDate date) {
|
private boolean isBeforeToday(final LocalDate date) {
|
||||||
// return date.isBefore(new LocalDate());
|
return date.isBefore(new LocalDate());
|
||||||
// }
|
}
|
||||||
private DepositLifecycleStateMachine defaultDepositLifecycleStateMachine() {
|
private DepositLifecycleStateMachine defaultDepositLifecycleStateMachine() {
|
||||||
List<DepositAccountStatus> allowedDepositStatuses = Arrays.asList(DepositAccountStatus.values());
|
List<DepositAccountStatus> allowedDepositStatuses = Arrays.asList(DepositAccountStatus.values());
|
||||||
return new DepositLifecycleStateMachineImpl(allowedDepositStatuses);
|
return new DepositLifecycleStateMachineImpl(allowedDepositStatuses);
|
||||||
@@ -166,141 +165,95 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult rejectDepositApplication(DepositStateTransitionCommand command) {
|
public CommandProcessingResult rejectDepositApplication(JsonCommand command) {
|
||||||
|
|
||||||
// AppUser currentUser = context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
this.depositAccountStateTransitionCommandFromApiJsonDeserializer.validateForReject(command.json());
|
||||||
|
|
||||||
DepositStateTransitionCommandValidator validator = new DepositStateTransitionCommandValidator(command);
|
DepositAccount account = this.depositAccountRepository.findOne(command.entityId());
|
||||||
validator.validate();
|
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.entityId()); }
|
||||||
|
|
||||||
DepositAccount account = this.depositAccountRepository.findOne(command.getAccountId());
|
LocalDate eventDate = command.localDateValueOfParameterNamed("eventDate");
|
||||||
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.getAccountId()); }
|
if (this.isBeforeToday(eventDate)) {
|
||||||
|
throw new NoAuthorizationException("User has no authority to reject deposit with a date in the past.");
|
||||||
// removing check for now until rules dealing with creating and
|
}
|
||||||
// maintaining deposit accounts in the past is clarified
|
|
||||||
LocalDate eventDate = command.getEventDate();
|
|
||||||
// if (this.isBeforeToday(eventDate) &&
|
|
||||||
// currentUser.canNotApproveLoanInPast()) {
|
|
||||||
// throw new
|
|
||||||
// NoAuthorizationException("User has no authority to approve deposit with a date in the past.");
|
|
||||||
// }
|
|
||||||
|
|
||||||
account.reject(eventDate, defaultDepositLifecycleStateMachine());
|
account.reject(eventDate, defaultDepositLifecycleStateMachine());
|
||||||
this.depositAccountRepository.save(account);
|
this.depositAccountRepository.save(account);
|
||||||
|
|
||||||
String noteText = command.getNote();
|
String noteText = command.stringValueOfParameterNamed("note");
|
||||||
if (StringUtils.isNotBlank(noteText)) {
|
if (StringUtils.isNotBlank(noteText)) {
|
||||||
Note note = Note.depositNote(account, noteText);
|
Note note = Note.depositNote(account, noteText);
|
||||||
this.noteRepository.save(note);
|
this.noteRepository.save(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult withdrawDepositApplication(DepositStateTransitionCommand command) {
|
public CommandProcessingResult withdrawDepositApplication(JsonCommand command) {
|
||||||
|
|
||||||
// AppUser currentUser = context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
this.depositAccountStateTransitionCommandFromApiJsonDeserializer.validateForWithdrawDepositApplication(command.json());
|
||||||
|
|
||||||
DepositStateTransitionCommandValidator validator = new DepositStateTransitionCommandValidator(command);
|
DepositAccount account = this.depositAccountRepository.findOne(command.entityId());
|
||||||
validator.validate();
|
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.entityId()); }
|
||||||
|
|
||||||
DepositAccount account = this.depositAccountRepository.findOne(command.getAccountId());
|
LocalDate eventDate = command.localDateValueOfParameterNamed("eventDate");
|
||||||
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.getAccountId()); }
|
if (this.isBeforeToday(eventDate)) {
|
||||||
|
throw new NoAuthorizationException("User has no authority to reject deposit with a date in the past.");
|
||||||
// removing check for now until rules dealing with creating and
|
}
|
||||||
// maintaining deposit accounts in the past is clarified
|
|
||||||
LocalDate eventDate = command.getEventDate();
|
|
||||||
// if (this.isBeforeToday(eventDate) &&
|
|
||||||
// currentUser.canNotApproveLoanInPast()) {
|
|
||||||
// throw new
|
|
||||||
// NoAuthorizationException("User has no authority to approve deposit with a date in the past.");
|
|
||||||
// }
|
|
||||||
|
|
||||||
account.withdrawnByApplicant(eventDate, defaultDepositLifecycleStateMachine());
|
account.withdrawnByApplicant(eventDate, defaultDepositLifecycleStateMachine());
|
||||||
this.depositAccountRepository.save(account);
|
this.depositAccountRepository.save(account);
|
||||||
|
|
||||||
String noteText = command.getNote();
|
String noteText = command.stringValueOfParameterNamed("note");
|
||||||
if (StringUtils.isNotBlank(noteText)) {
|
if (StringUtils.isNotBlank(noteText)) {
|
||||||
Note note = Note.depositNote(account, noteText);
|
Note note = Note.depositNote(account, noteText);
|
||||||
this.noteRepository.save(note);
|
this.noteRepository.save(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult undoDepositApproval(UndoStateTransitionCommand command) {
|
public CommandProcessingResult undoDepositApproval(JsonCommand command) {
|
||||||
|
|
||||||
context.authenticatedUser();
|
context.authenticatedUser();
|
||||||
|
|
||||||
DepositAccount account = this.depositAccountRepository.findOne(command.getLoanId());
|
DepositAccount account = this.depositAccountRepository.findOne(command.entityId());
|
||||||
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.getLoanId()); }
|
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.entityId()); }
|
||||||
|
|
||||||
account.undoDepositApproval(defaultDepositLifecycleStateMachine());
|
account.undoDepositApproval(defaultDepositLifecycleStateMachine());
|
||||||
this.depositAccountRepository.save(account);
|
this.depositAccountRepository.save(account);
|
||||||
|
|
||||||
String noteText = command.getNote();
|
String noteText = command.stringValueOfParameterNamed("note");
|
||||||
if (StringUtils.isNotBlank(noteText)) {
|
if (StringUtils.isNotBlank(noteText)) {
|
||||||
Note note = Note.depositNote(account, noteText);
|
Note note = Note.depositNote(account, noteText);
|
||||||
this.noteRepository.save(note);
|
this.noteRepository.save(note);
|
||||||
}
|
}
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* @Transactional
|
|
||||||
*
|
|
||||||
* @Override public EntityIdentifier
|
|
||||||
* matureDepositApplication(DepositStateTransitionCommand command) {
|
|
||||||
*
|
|
||||||
* AppUser currentUser = context.authenticatedUser();
|
|
||||||
*
|
|
||||||
* DepositStateTransitionCommandValidator validator = new
|
|
||||||
* DepositStateTransitionCommandValidator(command); validator.validate();
|
|
||||||
*
|
|
||||||
* DepositAccount account =
|
|
||||||
* this.depositAccountRepository.findOne(command.getAccountId()); if
|
|
||||||
* (account == null || account.isDeleted()) { throw new
|
|
||||||
* DepositAccountNotFoundException(command.getAccountId()); }
|
|
||||||
*
|
|
||||||
* LocalDate eventDate = command.getEventDate(); if
|
|
||||||
* (this.isBeforeToday(eventDate) && currentUser.canNotApproveLoanInPast())
|
|
||||||
* { throw new NoAuthorizationException(
|
|
||||||
* "User has no authority to mature deposit with a date in the past."); }
|
|
||||||
*
|
|
||||||
* account.matureDepositApplication(eventDate,
|
|
||||||
* defaultDepositLifecycleStateMachine());
|
|
||||||
* this.depositAccountRepository.save(account);
|
|
||||||
*
|
|
||||||
* if(account.isRenewalAllowed()){ final DepositAccount renewedAccount =
|
|
||||||
* this.depositAccountAssembler.assembleFrom(account);
|
|
||||||
* this.depositAccountRepository.save(renewedAccount); return new
|
|
||||||
* EntityIdentifier(renewedAccount.getId()); //returns the new deposit
|
|
||||||
* application id }
|
|
||||||
*
|
|
||||||
* String noteText = command.getNote(); if
|
|
||||||
* (StringUtils.isNotBlank(noteText)) { Note note =
|
|
||||||
* Note.depositNote(account, noteText); this.noteRepository.save(note); }
|
|
||||||
*
|
|
||||||
* return new EntityIdentifier(account.getId()); }
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult withdrawDepositAccountMoney(final DepositAccountWithdrawalCommand command) {
|
public CommandProcessingResult withdrawDepositAccountMoney(final JsonCommand command) {
|
||||||
|
|
||||||
context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
this.depositAccountStateTransitionCommandFromApiJsonDeserializer.validateForWithdrawDepositAmount(command.json());
|
||||||
|
|
||||||
DepositAccountWithdrawalCommandValidator validator = new DepositAccountWithdrawalCommandValidator(command);
|
DepositAccount account = this.depositAccountRepository.findOne(command.entityId());
|
||||||
validator.validate();
|
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.entityId()); }
|
||||||
|
|
||||||
DepositAccount account = this.depositAccountRepository.findOne(command.getAccountId());
|
LocalDate eventDate = command.localDateValueOfParameterNamed("maturesOnDate");
|
||||||
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.getAccountId()); }
|
|
||||||
|
|
||||||
LocalDate eventDate = command.getMaturesOnDate();
|
|
||||||
|
|
||||||
Integer lockinPeriod = account.getLockinPeriod();
|
Integer lockinPeriod = account.getLockinPeriod();
|
||||||
LocalDate lockinPeriodExpDate = account.getActualCommencementDate().plusMonths(Integer.valueOf(lockinPeriod));
|
LocalDate lockinPeriodExpDate = account.getActualCommencementDate().plusMonths(Integer.valueOf(lockinPeriod));
|
||||||
@@ -315,26 +268,27 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
// }
|
// }
|
||||||
account.withdrawDepositAccountMoney(defaultDepositLifecycleStateMachine(), fixedTermDepositInterestCalculator, eventDate);
|
account.withdrawDepositAccountMoney(defaultDepositLifecycleStateMachine(), fixedTermDepositInterestCalculator, eventDate);
|
||||||
this.depositAccountRepository.save(account);
|
this.depositAccountRepository.save(account);
|
||||||
String noteText = command.getNote();
|
String noteText = command.stringValueOfParameterNamed("note");
|
||||||
if (StringUtils.isNotBlank(noteText)) {
|
if (StringUtils.isNotBlank(noteText)) {
|
||||||
Note note = Note.depositNote(account, noteText);
|
Note note = Note.depositNote(account, noteText);
|
||||||
this.noteRepository.save(note);
|
this.noteRepository.save(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult withdrawDepositAccountInterestMoney(DepositAccountWithdrawInterestCommand command) {
|
public CommandProcessingResult withdrawDepositAccountInterestMoney(JsonCommand command) {
|
||||||
|
|
||||||
context.authenticatedUser();
|
context.authenticatedUser();
|
||||||
|
this.depositAccountStateTransitionCommandFromApiJsonDeserializer.validateForWithdrawInterestAmount(command.json());
|
||||||
|
|
||||||
WithDrawDepositAccountInterestCommandValidator validator = new WithDrawDepositAccountInterestCommandValidator(command);
|
BigDecimal interestAmount = command.bigDecimalValueOfParameterNamed("amount");
|
||||||
validator.validate();
|
DepositAccount account = this.depositAccountRepository.findOne(command.entityId());
|
||||||
|
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.entityId()); }
|
||||||
DepositAccount account = this.depositAccountRepository.findOne(command.getAccountId());
|
|
||||||
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.getAccountId()); }
|
|
||||||
if (account.isInterestWithdrawable() && !account.isInterestCompoundingAllowed()) {
|
if (account.isInterestWithdrawable() && !account.isInterestCompoundingAllowed()) {
|
||||||
|
|
||||||
// BigDecimal totalAvailableInterestForWithdrawal = getTotalWithdrawableInterestAvailable(account);
|
// BigDecimal totalAvailableInterestForWithdrawal = getTotalWithdrawableInterestAvailable(account);
|
||||||
@@ -342,9 +296,9 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
BigDecimal remainInterestForWithdrawal = account.getAvailableInterest(); //totalAvailableInterestForWithdrawal.subtract(interestPaid);
|
BigDecimal remainInterestForWithdrawal = account.getAvailableInterest(); //totalAvailableInterestForWithdrawal.subtract(interestPaid);
|
||||||
|
|
||||||
if (remainInterestForWithdrawal.doubleValue() > 0) {
|
if (remainInterestForWithdrawal.doubleValue() > 0) {
|
||||||
if (remainInterestForWithdrawal.doubleValue() >= command.getWithdrawInterest().doubleValue()
|
if (remainInterestForWithdrawal.doubleValue() >= interestAmount.doubleValue()
|
||||||
&& command.getWithdrawInterest().doubleValue() > 0) {
|
&& interestAmount.doubleValue() > 0) {
|
||||||
account.withdrawInterest(Money.of(account.getDeposit().getCurrency(), command.getWithdrawInterest()));
|
account.withdrawInterest(Money.of(account.getDeposit().getCurrency(), interestAmount));
|
||||||
this.depositAccountRepository.save(account);
|
this.depositAccountRepository.save(account);
|
||||||
} else {
|
} else {
|
||||||
throw new DepositAccountTransactionsException("deposit.transaction.interest.withdrawal.exceed", "You can Withdraw "
|
throw new DepositAccountTransactionsException("deposit.transaction.interest.withdrawal.exceed", "You can Withdraw "
|
||||||
@@ -358,28 +312,20 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
throw new DepositAccountTransactionsException("deposit.transaction.interest.withdrawal.cannot.withdraw",
|
throw new DepositAccountTransactionsException("deposit.transaction.interest.withdrawal.cannot.withdraw",
|
||||||
"You can not withdraw interst for this account");
|
"You can not withdraw interst for this account");
|
||||||
}
|
}
|
||||||
return new CommandProcessingResult(account.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* private BigDecimal getTotalWithdrawableInterestAvailable(DepositAccount account) {
|
|
||||||
BigDecimal interstGettingForPeriod = BigDecimal.valueOf(account.getAccuredInterest().getAmount().doubleValue()
|
|
||||||
/ new Double(account.getTenureInMonths()));
|
|
||||||
Integer noOfMonthsforInterestCal = Months.monthsBetween(account.getActualCommencementDate(), new LocalDate()).getMonths();
|
|
||||||
Integer noOfPeriods = noOfMonthsforInterestCal / account.getInterestCompoundedEvery();
|
|
||||||
return interstGettingForPeriod.multiply(new BigDecimal(noOfPeriods));
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult renewDepositAccount(DepositAccountCommand command) {
|
public CommandProcessingResult renewDepositAccount(JsonCommand command) {
|
||||||
|
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
this.fromApiJsonDeserializer.validateForRenew(command.json());
|
||||||
RenewDepositAccountCommandValidator validator = new RenewDepositAccountCommandValidator(command);
|
|
||||||
validator.validateForCreate();
|
DepositAccount account = this.depositAccountRepository.findOne(command.entityId());
|
||||||
|
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.entityId()); }
|
||||||
DepositAccount account = this.depositAccountRepository.findOne(command.getId());
|
|
||||||
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.getId()); }
|
|
||||||
|
|
||||||
// FIXME - KW - extract whats in this if into a method that naturally
|
// FIXME - KW - extract whats in this if into a method that naturally
|
||||||
// describes what you are checking.
|
// describes what you are checking.
|
||||||
@@ -391,7 +337,9 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
this.depositAccountRepository.save(renewedAccount);
|
this.depositAccountRepository.save(renewedAccount);
|
||||||
account.closeDepositAccount(defaultDepositLifecycleStateMachine());
|
account.closeDepositAccount(defaultDepositLifecycleStateMachine());
|
||||||
this.depositAccountRepository.save(account);
|
this.depositAccountRepository.save(account);
|
||||||
return new CommandProcessingResult(renewedAccount.getId());
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new DepositAccountReopenException(account.getMaturityDate());
|
throw new DepositAccountReopenException(account.getMaturityDate());
|
||||||
@@ -400,27 +348,33 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
throw new DepositAccountReopenException(account.getMaturityDate());
|
throw new DepositAccountReopenException(account.getMaturityDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult updateDepositAccount(DepositAccountCommand command) {
|
public CommandProcessingResult updateDepositAccount(Long accountId, JsonCommand command) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.context.authenticatedUser();
|
|
||||||
|
this.context.authenticatedUser();
|
||||||
DepositAccountCommandValidator validator = new DepositAccountCommandValidator(command);
|
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
||||||
validator.validateForUpdate();
|
|
||||||
|
Map<String, Object> changes = new LinkedHashMap<String, Object>(20);;
|
||||||
final DepositAccount account = this.depositAccountRepository.findOne(command.getId());
|
|
||||||
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(command.getId()); }
|
final DepositAccount account = this.depositAccountRepository.findOne(accountId);
|
||||||
|
if (account == null || account.isDeleted()) { throw new DepositAccountNotFoundException(accountId); }
|
||||||
if (account.isSubmittedAndPendingApproval()) {
|
|
||||||
this.depositAccountAssembler.assembleUpdatedDepositAccount(account, command);
|
if (account.isSubmittedAndPendingApproval()) {
|
||||||
} else if (account.isActive()) {
|
changes = this.depositAccountAssembler.assembleUpdatedDepositAccount(account, command);
|
||||||
this.depositAccountAssembler.updateApprovedDepositAccount(account, command);
|
} else if (account.isActive()) {
|
||||||
}
|
changes = this.depositAccountAssembler.updateApprovedDepositAccount(account, command);
|
||||||
|
}
|
||||||
this.depositAccountRepository.save(account);
|
|
||||||
|
this.depositAccountRepository.save(account);
|
||||||
return new CommandProcessingResult(account.getId());
|
|
||||||
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(account.getId()) //
|
||||||
|
.with(changes)
|
||||||
|
.build();
|
||||||
|
|
||||||
} catch (DataIntegrityViolationException dve) {
|
} catch (DataIntegrityViolationException dve) {
|
||||||
handleDataIntegrityIssues(command, dve);
|
handleDataIntegrityIssues(command, dve);
|
||||||
return new CommandProcessingResult(Long.valueOf(-1));
|
return new CommandProcessingResult(Long.valueOf(-1));
|
||||||
@@ -439,7 +393,9 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
this.depositAccountAssembler.postInterest(account);
|
this.depositAccountAssembler.postInterest(account);
|
||||||
this.depositAccountRepository.save(account);
|
this.depositAccountRepository.save(account);
|
||||||
}
|
}
|
||||||
return new CommandProcessingResult(new Long(accounts.size()));
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withEntityId(Long.valueOf(accounts.size())) //
|
||||||
|
.build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new CommandProcessingResult(Long.valueOf(-1));
|
return new CommandProcessingResult(Long.valueOf(-1));
|
||||||
}
|
}
|
||||||
|
|||||||
+43
-80
@@ -23,22 +23,21 @@ import javax.ws.rs.core.Context;
|
|||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||||
|
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||||
|
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
|
||||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||||
|
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.organisation.monetary.data.CurrencyData;
|
import org.mifosplatform.organisation.monetary.data.CurrencyData;
|
||||||
import org.mifosplatform.organisation.monetary.service.CurrencyReadPlatformService;
|
import org.mifosplatform.organisation.monetary.service.CurrencyReadPlatformService;
|
||||||
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
|
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
|
||||||
import org.mifosplatform.portfolio.savingsaccount.PortfolioApiDataConversionService;
|
|
||||||
import org.mifosplatform.portfolio.savingsaccount.PortfolioApiJsonSerializerService;
|
|
||||||
import org.mifosplatform.portfolio.savingsaccountproduct.service.SavingsDepositEnumerations;
|
import org.mifosplatform.portfolio.savingsaccountproduct.service.SavingsDepositEnumerations;
|
||||||
import org.mifosplatform.portfolio.savingsdepositproduct.command.DepositProductCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositproduct.data.DepositProductData;
|
import org.mifosplatform.portfolio.savingsdepositproduct.data.DepositProductData;
|
||||||
import org.mifosplatform.portfolio.savingsdepositproduct.service.DepositProductReadPlatformService;
|
import org.mifosplatform.portfolio.savingsdepositproduct.service.DepositProductReadPlatformService;
|
||||||
import org.mifosplatform.portfolio.savingsdepositproduct.service.DepositProductWritePlatformService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -47,42 +46,44 @@ import org.springframework.stereotype.Component;
|
|||||||
@Component
|
@Component
|
||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class DepositProductsApiResource {
|
public class DepositProductsApiResource {
|
||||||
|
|
||||||
|
private final Set<String> DEPOSIT_PRODUCT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "externalId", "name", "description", "createdOn", "lastModifedOn",
|
||||||
|
"currencyCode", "digitsAfterDecimal", "minimumBalance", "maximumBalance", "tenureInMonths", "maturityDefaultInterestRate", "maturityMinInterestRate",
|
||||||
|
"maturityMaxInterestRate", "interestCompoundedEvery", "interestCompoundedEveryPeriodType", "renewalAllowed", "preClosureAllowed", "preClosureInterestRate",
|
||||||
|
"interestCompoundingAllowed", "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "currency","currencyOptions", "interestCompoundedEveryPeriodTypeOptions"));
|
||||||
|
|
||||||
private final String entityType = "DEPOSITPRODUCT";
|
private final String entityType = "DEPOSITPRODUCT";
|
||||||
|
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final DepositProductReadPlatformService depositProductReadPlatformService;
|
private final DepositProductReadPlatformService depositProductReadPlatformService;
|
||||||
private final CurrencyReadPlatformService currencyReadPlatformService;
|
private final CurrencyReadPlatformService currencyReadPlatformService;
|
||||||
private final DepositProductWritePlatformService depositProductWritePlatformService;
|
|
||||||
private final PortfolioApiDataConversionService apiDataConversionService;
|
|
||||||
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
|
|
||||||
private final DefaultToApiJsonSerializer<DepositProductData> toApiJsonSerializer;
|
private final DefaultToApiJsonSerializer<DepositProductData> toApiJsonSerializer;
|
||||||
|
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||||
|
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DepositProductsApiResource(final PlatformSecurityContext context,
|
public DepositProductsApiResource(final PlatformSecurityContext context,
|
||||||
final DepositProductReadPlatformService depositProductReadPlatformService,
|
final DepositProductReadPlatformService depositProductReadPlatformService,
|
||||||
final CurrencyReadPlatformService currencyReadPlatformService,
|
final CurrencyReadPlatformService currencyReadPlatformService,
|
||||||
final DepositProductWritePlatformService depositProductWritePlatformService,
|
final DefaultToApiJsonSerializer<DepositProductData> toApiJsonSerializer,
|
||||||
final PortfolioApiDataConversionService apiDataConversionService,
|
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
|
||||||
final PortfolioApiJsonSerializerService apiJsonSerializerService,
|
final ApiRequestParameterHelper apiRequestParameterHelper) {
|
||||||
final DefaultToApiJsonSerializer<DepositProductData> toApiJsonSerializer) {
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.depositProductReadPlatformService = depositProductReadPlatformService;
|
this.depositProductReadPlatformService = depositProductReadPlatformService;
|
||||||
this.currencyReadPlatformService = currencyReadPlatformService;
|
this.currencyReadPlatformService = currencyReadPlatformService;
|
||||||
this.depositProductWritePlatformService = depositProductWritePlatformService;
|
|
||||||
this.apiDataConversionService = apiDataConversionService;
|
|
||||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
|
||||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||||
|
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||||
|
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String createDepositProduct(final String jsonRequestBody) {
|
public String createDepositProduct(final String apiRequestBodyAsJson) {
|
||||||
|
|
||||||
final DepositProductCommand command = this.apiDataConversionService.convertJsonToDepositProductCommand(null, jsonRequestBody);
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().createDepositProduct().withJson(apiRequestBodyAsJson).build();
|
||||||
|
|
||||||
final CommandProcessingResult result = this.depositProductWritePlatformService.createDepositProduct(command);
|
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
return this.toApiJsonSerializer.serialize(result);
|
return this.toApiJsonSerializer.serialize(result);
|
||||||
}
|
}
|
||||||
@@ -91,10 +92,11 @@ public class DepositProductsApiResource {
|
|||||||
@Path("{productId}")
|
@Path("{productId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String updateDepositProduct(@PathParam("productId") final Long productId, final String jsonRequestBody) {
|
public String updateDepositProduct(@PathParam("productId") final Long productId, final String apiRequestBodyAsJson) {
|
||||||
|
|
||||||
final DepositProductCommand command = this.apiDataConversionService.convertJsonToDepositProductCommand(productId, jsonRequestBody);
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateDepositProduct(productId).withJson(apiRequestBodyAsJson).build();
|
||||||
final CommandProcessingResult result = this.depositProductWritePlatformService.updateDepositProduct(command);
|
|
||||||
|
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
return this.toApiJsonSerializer.serialize(result);
|
return this.toApiJsonSerializer.serialize(result);
|
||||||
}
|
}
|
||||||
@@ -104,10 +106,10 @@ public class DepositProductsApiResource {
|
|||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String deleteDepositProduct(@PathParam("productId") final Long productId) {
|
public String deleteDepositProduct(@PathParam("productId") final Long productId) {
|
||||||
|
|
||||||
this.depositProductWritePlatformService.deleteDepositProduct(productId);
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteDepositProduct(productId).build();
|
||||||
|
|
||||||
final CommandProcessingResult result = new CommandProcessingResultBuilder().withEntityId(productId).build();
|
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
return this.toApiJsonSerializer.serialize(result);
|
return this.toApiJsonSerializer.serialize(result);
|
||||||
}
|
}
|
||||||
@@ -116,23 +118,10 @@ public class DepositProductsApiResource {
|
|||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveAllDepositProducts(@Context final UriInfo uriInfo) {
|
public String retrieveAllDepositProducts(@Context final UriInfo uriInfo) {
|
||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||||
|
|
||||||
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "externalId", "name", "description", "createdOn",
|
|
||||||
"lastModifedOn", "currencyCode", "digitsAfterDecimal", "minimumBalance", "maximumBalance", "tenureInMonths",
|
|
||||||
"maturityDefaultInterestRate", "maturityMinInterestRate", "maturityMaxInterestRate", "interestCompoundedEvery",
|
|
||||||
"interestCompoundedEveryPeriodType", "renewalAllowed", "preClosureAllowed", "preClosureInterestRate",
|
|
||||||
"interestCompoundingAllowed", "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "currency"));
|
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
|
||||||
if (responseParameters.isEmpty()) {
|
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
|
||||||
}
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
|
||||||
|
|
||||||
Collection<DepositProductData> products = this.depositProductReadPlatformService.retrieveAllDepositProducts();
|
Collection<DepositProductData> products = this.depositProductReadPlatformService.retrieveAllDepositProducts();
|
||||||
return this.apiJsonSerializerService.serializeDepositProductDataToJson(prettyPrint, responseParameters, products);
|
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
|
return this.toApiJsonSerializer.serialize(settings, products, DEPOSIT_PRODUCT_DATA_PARAMETERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@@ -142,27 +131,14 @@ public class DepositProductsApiResource {
|
|||||||
public String retrieveDepositProductDetails(@PathParam("productId") final Long productId, @Context final UriInfo uriInfo) {
|
public String retrieveDepositProductDetails(@PathParam("productId") final Long productId, @Context final UriInfo uriInfo) {
|
||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||||
|
|
||||||
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "externalId", "name", "description", "createdOn",
|
|
||||||
"lastModifedOn", "currencyCode", "digitsAfterDecimal", "minimumBalance", "maximumBalance", "tenureInMonths",
|
|
||||||
"maturityDefaultInterestRate", "maturityMinInterestRate", "maturityMaxInterestRate", "interestCompoundedEvery",
|
|
||||||
"interestCompoundedEveryPeriodType", "renewalAllowed", "preClosureAllowed", "preClosureInterestRate",
|
|
||||||
"interestCompoundingAllowed", "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "currency"));
|
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
|
||||||
if (responseParameters.isEmpty()) {
|
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
|
||||||
}
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
|
||||||
|
|
||||||
DepositProductData productData = this.depositProductReadPlatformService.retrieveDepositProductData(productId);
|
DepositProductData productData = this.depositProductReadPlatformService.retrieveDepositProductData(productId);
|
||||||
|
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
|
||||||
if (template) {
|
if (settings.isTemplate()) {
|
||||||
productData = handleTemplateRelatedData(responseParameters, productData);
|
productData = handleTemplateRelatedData(productData);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeDepositProductDataToJson(prettyPrint, responseParameters, productData);
|
return this.toApiJsonSerializer.serialize(settings, productData, DEPOSIT_PRODUCT_DATA_PARAMETERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@@ -173,29 +149,16 @@ public class DepositProductsApiResource {
|
|||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||||
|
|
||||||
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("currencyOptions",
|
|
||||||
"interestCompoundedEveryPeriodTypeOptions", "id", "externalId", "name", "description", "createdOn", "lastModifedOn",
|
|
||||||
"currencyCode", "digitsAfterDecimal", "minimumBalance", "maximumBalance", "tenureInMonths", "maturityDefaultInterestRate",
|
|
||||||
"maturityMinInterestRate", "maturityMaxInterestRate", "interestCompoundedEvery", "interestCompoundedEveryPeriodType",
|
|
||||||
"renewalAllowed", "preClosureAllowed", "preClosureInterestRate", "isLockinPeriodAllowed", "lockinPeriod",
|
|
||||||
"lockinPeriodType", "currency"));
|
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
|
||||||
if (responseParameters.isEmpty()) {
|
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
|
||||||
}
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
|
||||||
|
|
||||||
DepositProductData depositProduct = this.depositProductReadPlatformService.retrieveNewDepositProductDetails();
|
DepositProductData depositProduct = this.depositProductReadPlatformService.retrieveNewDepositProductDetails();
|
||||||
|
|
||||||
depositProduct = handleTemplateRelatedData(responseParameters, depositProduct);
|
depositProduct = handleTemplateRelatedData(depositProduct);
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeDepositProductDataToJson(prettyPrint, responseParameters, depositProduct);
|
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
|
return this.toApiJsonSerializer.serialize(settings, depositProduct, DEPOSIT_PRODUCT_DATA_PARAMETERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DepositProductData handleTemplateRelatedData(final Set<String> responseParameters, final DepositProductData productData) {
|
private DepositProductData handleTemplateRelatedData(final DepositProductData productData) {
|
||||||
|
|
||||||
responseParameters.addAll(Arrays.asList("currencyOptions", "interestCompoundedEveryPeriodTypeOptions"));
|
|
||||||
Collection<CurrencyData> allowedCurrencies = this.currencyReadPlatformService.retrieveAllowedCurrencies();
|
Collection<CurrencyData> allowedCurrencies = this.currencyReadPlatformService.retrieveAllowedCurrencies();
|
||||||
|
|
||||||
EnumOptionData monthly = SavingsDepositEnumerations.interestCompoundingPeriodType(PeriodFrequencyType.MONTHS);
|
EnumOptionData monthly = SavingsDepositEnumerations.interestCompoundingPeriodType(PeriodFrequencyType.MONTHS);
|
||||||
|
|||||||
+2
-2
@@ -85,8 +85,8 @@ public class DepositProductData {
|
|||||||
this.lockinPeriodType = lockinPeriodType;
|
this.lockinPeriodType = lockinPeriodType;
|
||||||
this.isLockinPeriodAllowed = isLockinPeriodAllowed;
|
this.isLockinPeriodAllowed = isLockinPeriodAllowed;
|
||||||
this.currency = currencyData;
|
this.currency = currencyData;
|
||||||
this.currencyOptions = new ArrayList<CurrencyData>();
|
this.currencyOptions = null;
|
||||||
this.interestCompoundedEveryPeriodTypeOptions = new ArrayList<EnumOptionData>();
|
this.interestCompoundedEveryPeriodTypeOptions = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DepositProductData(final Collection<CurrencyData> currencyOptions,
|
public DepositProductData(final Collection<CurrencyData> currencyOptions,
|
||||||
|
|||||||
+195
-80
@@ -6,6 +6,8 @@
|
|||||||
package org.mifosplatform.portfolio.savingsdepositproduct.domain;
|
package org.mifosplatform.portfolio.savingsdepositproduct.domain;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Embedded;
|
import javax.persistence.Embedded;
|
||||||
@@ -14,10 +16,10 @@ import javax.persistence.Table;
|
|||||||
import javax.persistence.UniqueConstraint;
|
import javax.persistence.UniqueConstraint;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
|
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
|
||||||
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
|
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
|
||||||
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
|
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
|
||||||
import org.mifosplatform.portfolio.savingsdepositproduct.command.DepositProductCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositproduct.exception.DepositProductValueOutsideRangeException;
|
import org.mifosplatform.portfolio.savingsdepositproduct.exception.DepositProductValueOutsideRangeException;
|
||||||
import org.mifosplatform.useradministration.domain.AppUser;
|
import org.mifosplatform.useradministration.domain.AppUser;
|
||||||
|
|
||||||
@@ -206,93 +208,175 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
this.externalId = this.getId() + "_DELETED_" + this.externalId;
|
this.externalId = this.getId() + "_DELETED_" + this.externalId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(final DepositProductCommand command, final PeriodFrequencyType interestCompoundingFrequency, final PeriodFrequencyType lockinPeriodType){
|
public Map<String, Object> update(final JsonCommand command){
|
||||||
|
|
||||||
if (command.isExternalIdChanged()) {
|
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20);
|
||||||
this.externalId = command.getExternalId();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command.isNameChanged()) {
|
|
||||||
this.name = command.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command.isDescriptionChanged()) {
|
final String localeAsInput = command.locale();
|
||||||
this.description = command.getDescription();
|
|
||||||
}
|
final String nameParamName = "name";
|
||||||
|
if (command.isChangeInStringParameterNamed(nameParamName, this.name)) {
|
||||||
|
final String newValue = command.stringValueOfParameterNamed(nameParamName);
|
||||||
|
actualChanges.put(nameParamName, newValue);
|
||||||
|
this.name = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String descriptionParamName = "description";
|
||||||
|
if (command.isChangeInStringParameterNamed(descriptionParamName, this.description)) {
|
||||||
|
final String newValue = command.stringValueOfParameterNamed(descriptionParamName);
|
||||||
|
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);
|
||||||
|
actualChanges.put(digitsAfterDecimalParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
digitsAfterDecimal = newValue;
|
||||||
|
this.currency = new MonetaryCurrency(currencyCode, digitsAfterDecimal);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String currencyCodeParamName = "currencyCode";
|
||||||
|
if (command.isChangeInStringParameterNamed(currencyCodeParamName, currencyCode)) {
|
||||||
|
final String newValue = command.stringValueOfParameterNamed(currencyCodeParamName);
|
||||||
|
actualChanges.put(currencyCodeParamName, newValue);
|
||||||
|
currencyCode = newValue;
|
||||||
|
this.currency = new MonetaryCurrency(currencyCode, digitsAfterDecimal);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String minimumBalanceParamName = "minimumBalance";
|
||||||
|
if (command.isChangeInBigDecimalParameterNamed(minimumBalanceParamName, this.minimumBalance)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(minimumBalanceParamName);
|
||||||
|
actualChanges.put(minimumBalanceParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.minimumBalance = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String maximumBalanceParamName = "maximumBalance";
|
||||||
|
if (command.isChangeInBigDecimalParameterNamed(maximumBalanceParamName, this.maximumBalance)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(maximumBalanceParamName);
|
||||||
|
actualChanges.put(maximumBalanceParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.maximumBalance = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String tenureInMonthsParamName = "tenureInMonths";
|
||||||
|
if (command.isChangeInIntegerParameterNamed(tenureInMonthsParamName, this.tenureInMonths)) {
|
||||||
|
final Integer newValue = command.integerValueOfParameterNamed(tenureInMonthsParamName);
|
||||||
|
actualChanges.put(tenureInMonthsParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.tenureInMonths = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String defaultInterestRateParamName = "maturityDefaultInterestRate";
|
||||||
|
if (command.isChangeInBigDecimalParameterNamed(defaultInterestRateParamName, this.maturityDefaultInterestRate)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(defaultInterestRateParamName);
|
||||||
|
actualChanges.put(defaultInterestRateParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.maturityDefaultInterestRate = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String minInterestRateParamName = "maturityMinInterestRate";
|
||||||
|
if (command.isChangeInBigDecimalParameterNamed(minInterestRateParamName, this.maturityMinInterestRate)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(minInterestRateParamName);
|
||||||
|
actualChanges.put(minInterestRateParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.maturityMinInterestRate = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String maxInterestRateParamName = "maturityMaxInterestRate";
|
||||||
|
if (command.isChangeInBigDecimalParameterNamed(maxInterestRateParamName, this.maturityMaxInterestRate)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(maxInterestRateParamName);
|
||||||
|
actualChanges.put(maxInterestRateParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.maturityMaxInterestRate = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String interestCompoundedEveryParamName = "interestCompoundedEvery";
|
||||||
|
if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryParamName, this.interestCompoundedEvery)) {
|
||||||
|
final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryParamName);
|
||||||
|
actualChanges.put(interestCompoundedEveryParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.interestCompoundedEvery = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String interestCompoundedEveryPeriodTypeParamName = "interestCompoundedEveryPeriodType";
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
Integer digitsAfterDecimalChanged = this.currency.getDigitsAfterDecimal();
|
final String renewalAllowedParamName = "renewalAllowed";
|
||||||
if (command.isDigitsAfterDecimalChanged()) {
|
if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, this.renewalAllowed)) {
|
||||||
digitsAfterDecimalChanged = command.getDigitsAfterDecimal();
|
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);
|
||||||
|
actualChanges.put(preClosureAllowedParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.preClosureAllowed = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
String currencyCodeChanged = this.currency.getCode();
|
final String preClosureInterestRateParamName = "preClosureInterestRate";
|
||||||
if (command.isCurrencyCodeChanged()) {
|
if (command.isChangeInBigDecimalParameterNamed(preClosureInterestRateParamName, this.preClosureInterestRate)) {
|
||||||
currencyCodeChanged = command.getCurrencyCode();
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(preClosureInterestRateParamName);
|
||||||
}
|
actualChanges.put(preClosureInterestRateParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.preClosureInterestRate = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String interestCompoundingAllowedParamName = "interestCompoundingAllowed";
|
||||||
|
if (command.isChangeInBooleanParameterNamed(interestCompoundingAllowedParamName, this.interestCompoundingAllowed)) {
|
||||||
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(interestCompoundingAllowedParamName);
|
||||||
|
actualChanges.put(interestCompoundingAllowedParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.interestCompoundingAllowed = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
if (command.isDigitsAfterDecimalChanged() || command.isCurrencyCodeChanged()) {
|
final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed";
|
||||||
this.currency = new MonetaryCurrency(currencyCodeChanged, digitsAfterDecimalChanged);
|
if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, this.isLockinPeriodAllowed)) {
|
||||||
}
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName);
|
||||||
|
actualChanges.put(isLockinPeriodAllowedParamName, newValue);
|
||||||
if(command.isMinimumBalanceChanged()){
|
actualChanges.put("locale", localeAsInput);
|
||||||
this.minimumBalance=command.getMinimumBalance();
|
this.isLockinPeriodAllowed = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(command.isMaximumBalanceChanged()){
|
final String lockinPeriodParamName = "lockinPeriod";
|
||||||
this.maximumBalance=command.getMaximumBalance();
|
if (command.isChangeInIntegerParameterNamed(lockinPeriodParamName, this.lockinPeriod)) {
|
||||||
}
|
final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodParamName);
|
||||||
|
actualChanges.put(lockinPeriodParamName, newValue);
|
||||||
|
actualChanges.put("locale", localeAsInput);
|
||||||
|
this.lockinPeriod = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
if(command.isTenureMonthsChanged()){
|
|
||||||
this.tenureInMonths=command.getTenureInMonths();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command.isMaturityDefaultInterestRateChanged()) {
|
final String lockinPeriodTypeParamName = "lockinPeriodType";
|
||||||
this.maturityDefaultInterestRate=command.getMaturityDefaultInterestRate();
|
if (command.isChangeInIntegerParameterNamed(lockinPeriodTypeParamName, this.lockinPeriodType.getValue())) {
|
||||||
}
|
final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodTypeParamName);
|
||||||
|
actualChanges.put(lockinPeriodTypeParamName, newValue);
|
||||||
if(command.isMaturityMaxInterestRateChanged()){
|
actualChanges.put("locale", localeAsInput);
|
||||||
this.maturityMaxInterestRate=command.getMaturityMaxInterestRate();
|
this.lockinPeriodType = PeriodFrequencyType.fromInt(newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.isMaturityMinInterestRateChanged()) {
|
return actualChanges;
|
||||||
this.maturityMinInterestRate=command.getMaturityMinInterestRate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command.isInterestCompoundedEveryChanged()) {
|
|
||||||
this.interestCompoundedEvery = command.getInterestCompoundedEvery();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command.isInterestCompoundedEveryPeriodTypeChanged()) {
|
|
||||||
this.interestCompoundedEveryPeriodType = interestCompoundingFrequency;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command.isRenewalAllowedChanged()) {
|
|
||||||
this.renewalAllowed=command.isRenewalAllowed();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command.isPreClosureAllowed()) {
|
|
||||||
this.preClosureAllowed=command.isPreClosureAllowed();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command.isPreClosureInterestRateChanged()) {
|
|
||||||
this.preClosureInterestRate=command.getPreClosureInterestRate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(command.interestCompoundingAllowedChanged()){
|
|
||||||
this.interestCompoundingAllowed = command.isInterestCompoundingAllowed();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(command.isLockinPeriodAllowedChanged()){
|
|
||||||
this.isLockinPeriodAllowed = command.isLockinPeriodAllowed();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(command.isLockinPeriodChanged()){
|
|
||||||
this.lockinPeriod = command.getLockinPeriod();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(command.isLockinPeriodTypeChanged()){
|
|
||||||
this.lockinPeriodType = lockinPeriodType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void validateInterestRateInRange(final BigDecimal interestRate) {
|
public void validateInterestRateInRange(final BigDecimal interestRate) {
|
||||||
@@ -330,4 +414,35 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
throw new DepositProductValueOutsideRangeException(actualValue, minValue, maxValue, "deposit.account.deposit.amount");
|
throw new DepositProductValueOutsideRangeException(actualValue, minValue, maxValue, "deposit.account.deposit.amount");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositproduct.handler;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositproduct.service.DepositProductWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositproduct.handler;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositproduct.service.DepositProductWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DeleteDepositProductCommandHandler implements NewCommandSourceHandler {
|
||||||
|
|
||||||
|
private final DepositProductWritePlatformService depositProductWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DeleteDepositProductCommandHandler(final DepositProductWritePlatformService depositProductWritePlatformService) {
|
||||||
|
this.depositProductWritePlatformService = depositProductWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||||
|
return this.depositProductWritePlatformService.deleteDepositProduct(command.entityId());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositproduct.handler;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositproduct.service.DepositProductWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UpdateDepositProductCommandHandler implements NewCommandSourceHandler {
|
||||||
|
|
||||||
|
private final DepositProductWritePlatformService depositProductWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UpdateDepositProductCommandHandler(final DepositProductWritePlatformService depositProductWritePlatformService) {
|
||||||
|
this.depositProductWritePlatformService = depositProductWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||||
|
return this.depositProductWritePlatformService.updateDepositProduct(command.entityId(),command);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+221
@@ -0,0 +1,221 @@
|
|||||||
|
package org.mifosplatform.portfolio.savingsdepositproduct.serialization;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||||
|
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||||
|
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||||
|
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public final class DepositProductCommandFromApiJsonDeserializer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The parameters supported for this command.
|
||||||
|
*/
|
||||||
|
|
||||||
|
Set<String> supportedParams = new HashSet<String>(Arrays.asList("locale", "name", "externalId", "description", "currencyCode",
|
||||||
|
"digitsAfterDecimal", "minimumBalance", "maximumBalance", "tenureInMonths", "maturityDefaultInterestRate",
|
||||||
|
"maturityMinInterestRate", "maturityMaxInterestRate", "interestCompoundedEvery", "interestCompoundedEveryPeriodType",
|
||||||
|
"renewalAllowed", "preClosureAllowed", "preClosureInterestRate", "interestCompoundingAllowed", "isLockinPeriodAllowed",
|
||||||
|
"lockinPeriod", "lockinPeriodType"));
|
||||||
|
|
||||||
|
private final FromJsonHelper fromApiJsonHelper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DepositProductCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||||
|
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateForCreate(final String json) {
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
|
|
||||||
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
|
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams);
|
||||||
|
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.product");
|
||||||
|
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
|
final String name = fromApiJsonHelper.extractStringNamed("name", element);
|
||||||
|
baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(100);
|
||||||
|
|
||||||
|
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element);
|
||||||
|
baseDataValidator.reset().parameter("externalId").value(externalId).ignoreIfNull().notExceedingLengthOf(100);
|
||||||
|
|
||||||
|
final String description = fromApiJsonHelper.extractStringNamed("description", element);
|
||||||
|
baseDataValidator.reset().parameter("description").value(description).notExceedingLengthOf(500);
|
||||||
|
|
||||||
|
final String currencyCode = fromApiJsonHelper.extractStringNamed("currencyCode", element);
|
||||||
|
baseDataValidator.reset().parameter("currencyCode").value(currencyCode).notBlank();
|
||||||
|
|
||||||
|
final Integer digitsAfterDecimal = fromApiJsonHelper.extractIntegerNamed("digitsAfterDecimal", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("digitsAfterDecimal").value(digitsAfterDecimal).notNull().inMinMaxRange(0, 6);
|
||||||
|
|
||||||
|
final BigDecimal minimumBalance = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalance", element);
|
||||||
|
baseDataValidator.reset().parameter("minimumBalance").value(minimumBalance).notNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final BigDecimal maximumBalance = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maximumBalance", element);
|
||||||
|
baseDataValidator.reset().parameter("maximumBalance").value(maximumBalance).zeroOrPositiveAmount();
|
||||||
|
baseDataValidator.reset().parameter("minimumBalance").comapareMinimumAndMaximumAmounts(minimumBalance, maximumBalance);
|
||||||
|
|
||||||
|
final Integer tenureInMonths = fromApiJsonHelper.extractIntegerNamed("tenureInMonths", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("tenureInMonths").value(tenureInMonths).notNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final BigDecimal maturityDefaultInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityDefaultInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("maturityDefaultInterestRate").value(maturityDefaultInterestRate).notNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final BigDecimal maturityMinInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityMinInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("maturityMinInterestRate").value(maturityMinInterestRate).notNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final BigDecimal maturityMaxInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityMaxInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("maturityMaxInterestRate").value(maturityMaxInterestRate).notNull().zeroOrPositiveAmount();
|
||||||
|
baseDataValidator.reset().parameter("maturityMinInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(maturityMinInterestRate, maturityMaxInterestRate);
|
||||||
|
baseDataValidator.reset().parameter("maturityDefaultInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(maturityDefaultInterestRate, maturityMaxInterestRate);
|
||||||
|
baseDataValidator.reset().parameter("maturityMinInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(maturityMinInterestRate, maturityDefaultInterestRate);
|
||||||
|
|
||||||
|
final Integer interestCompoundedEvery = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEvery", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("interestCompoundedEvery").value(interestCompoundedEvery).notNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer interestCompoundedEveryPeriodType = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEveryPeriodType", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(interestCompoundedEveryPeriodType).notNull().inMinMaxRange(1, 3);
|
||||||
|
|
||||||
|
final Boolean renewalAllowed = fromApiJsonHelper.extractBooleanNamed("renewalAllowed", element);
|
||||||
|
baseDataValidator.reset().parameter("renewalAllowed").trueOrFalseRequired(renewalAllowed);
|
||||||
|
|
||||||
|
final Boolean preClosureAllowed = fromApiJsonHelper.extractBooleanNamed("preClosureAllowed", element);
|
||||||
|
baseDataValidator.reset().parameter("preClosureAllowed").trueOrFalseRequired(preClosureAllowed);
|
||||||
|
|
||||||
|
final Boolean interestCompoundingAllowed = fromApiJsonHelper.extractBooleanNamed("interestCompoundingAllowed", element);
|
||||||
|
baseDataValidator.reset().parameter("interestCompoundingAllowed").trueOrFalseRequired(interestCompoundingAllowed);
|
||||||
|
|
||||||
|
final BigDecimal preClosureInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("preClosureInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("preClosureInterestRate").value(preClosureInterestRate).notNull().zeroOrPositiveAmount();
|
||||||
|
baseDataValidator.reset().parameter("preClosureInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(preClosureInterestRate,maturityMinInterestRate);
|
||||||
|
|
||||||
|
final Boolean isLockinPeriodAllowed = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element);
|
||||||
|
baseDataValidator.reset().parameter("isLockinPeriodAllowed").trueOrFalseRequired(isLockinPeriodAllowed);
|
||||||
|
|
||||||
|
final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).notNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).notNull().inMinMaxRange(1, 3);
|
||||||
|
|
||||||
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateForUpdate(String json) {
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
|
|
||||||
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
|
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams);
|
||||||
|
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.product");
|
||||||
|
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
|
final String name = fromApiJsonHelper.extractStringNamed("name", element);
|
||||||
|
baseDataValidator.reset().parameter("name").value(name).notBlank().ignoreIfNull().notExceedingLengthOf(100);
|
||||||
|
|
||||||
|
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element);
|
||||||
|
baseDataValidator.reset().parameter("externalId").value(externalId).ignoreIfNull().notExceedingLengthOf(100);
|
||||||
|
|
||||||
|
final String description = fromApiJsonHelper.extractStringNamed("description", element);
|
||||||
|
baseDataValidator.reset().parameter("description").value(description).notExceedingLengthOf(500);
|
||||||
|
|
||||||
|
final String currencyCode = fromApiJsonHelper.extractStringNamed("currencyCode", element);
|
||||||
|
baseDataValidator.reset().parameter("currencyCode").value(currencyCode).notBlank();
|
||||||
|
|
||||||
|
final Integer digitsAfterDecimal = fromApiJsonHelper.extractIntegerNamed("digitsAfterDecimal", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("digitsAfterDecimal").value(digitsAfterDecimal).ignoreIfNull().inMinMaxRange(0, 6);
|
||||||
|
|
||||||
|
final BigDecimal minimumBalance = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalance", element);
|
||||||
|
baseDataValidator.reset().parameter("minimumBalance").value(minimumBalance).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final BigDecimal maximumBalance = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maximumBalance", element);
|
||||||
|
baseDataValidator.reset().parameter("maximumBalance").value(maximumBalance).zeroOrPositiveAmount();
|
||||||
|
baseDataValidator.reset().parameter("minimumBalance").comapareMinimumAndMaximumAmounts(minimumBalance, maximumBalance);
|
||||||
|
|
||||||
|
final Integer tenureInMonths = fromApiJsonHelper.extractIntegerNamed("tenureInMonths", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("tenureInMonths").value(tenureInMonths).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final BigDecimal maturityDefaultInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityDefaultInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("maturityDefaultInterestRate").value(maturityDefaultInterestRate).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final BigDecimal maturityMinInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityMinInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("maturityMinInterestRate").value(maturityMinInterestRate).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final BigDecimal maturityMaxInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityMaxInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("maturityMaxInterestRate").value(maturityMaxInterestRate).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
baseDataValidator.reset().parameter("maturityMinInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(maturityMinInterestRate, maturityMaxInterestRate);
|
||||||
|
baseDataValidator.reset().parameter("maturityDefaultInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(maturityDefaultInterestRate, maturityMaxInterestRate);
|
||||||
|
baseDataValidator.reset().parameter("maturityMinInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(maturityMinInterestRate, maturityDefaultInterestRate);
|
||||||
|
|
||||||
|
final Integer interestCompoundedEvery = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEvery", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("interestCompoundedEvery").value(interestCompoundedEvery).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer interestCompoundedEveryPeriodType = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEveryPeriodType", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(interestCompoundedEveryPeriodType).ignoreIfNull().inMinMaxRange(1, 3);
|
||||||
|
|
||||||
|
final Boolean renewalAllowed = fromApiJsonHelper.extractBooleanNamed("renewalAllowed", element);
|
||||||
|
final Boolean isrenewalAllowedChanged = isBooleanValueUpdated(renewalAllowed);
|
||||||
|
baseDataValidator.reset().parameter("renewalAllowed").trueOrFalseRequired(isrenewalAllowedChanged);
|
||||||
|
|
||||||
|
final Boolean preClosureAllowed = fromApiJsonHelper.extractBooleanNamed("preClosureAllowed", element);
|
||||||
|
final Boolean isPreClosureAllowedChanged = isBooleanValueUpdated(preClosureAllowed);
|
||||||
|
baseDataValidator.reset().parameter("preClosureAllowed").trueOrFalseRequired(isPreClosureAllowedChanged);
|
||||||
|
|
||||||
|
final Boolean interestCompoundingAllowed = fromApiJsonHelper.extractBooleanNamed("interestCompoundingAllowed", element);
|
||||||
|
final Boolean isInterestCompoundingAllowed = isBooleanValueUpdated(interestCompoundingAllowed);
|
||||||
|
baseDataValidator.reset().parameter("interestCompoundingAllowed").trueOrFalseRequired(isInterestCompoundingAllowed);
|
||||||
|
|
||||||
|
final BigDecimal preClosureInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("preClosureInterestRate", element);
|
||||||
|
baseDataValidator.reset().parameter("preClosureInterestRate").value(preClosureInterestRate).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
baseDataValidator.reset().parameter("preClosureInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(preClosureInterestRate,maturityMinInterestRate);
|
||||||
|
|
||||||
|
final Boolean lockinPeriodAllowed = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element);
|
||||||
|
final Boolean isLockinPeriodAllowed = isBooleanValueUpdated(lockinPeriodAllowed);
|
||||||
|
baseDataValidator.reset().parameter("isLockinPeriodAllowed").trueOrFalseRequired(isLockinPeriodAllowed);
|
||||||
|
|
||||||
|
final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault());
|
||||||
|
baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).ignoreIfNull().inMinMaxRange(1, 3);
|
||||||
|
|
||||||
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean isBooleanValueUpdated(Boolean actualValue) {
|
||||||
|
Boolean isUpdated = false;
|
||||||
|
if(actualValue != null){
|
||||||
|
isUpdated = true;
|
||||||
|
}
|
||||||
|
return isUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
||||||
|
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||||
|
"Validation errors exist.", dataValidationErrors); }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+4
-1
@@ -26,6 +26,9 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class DepositProductReadPlatformServiceImpl implements DepositProductReadPlatformService {
|
public class DepositProductReadPlatformServiceImpl implements DepositProductReadPlatformService {
|
||||||
|
|
||||||
@@ -50,7 +53,7 @@ public class DepositProductReadPlatformServiceImpl implements DepositProductRead
|
|||||||
public Collection<DepositProductLookup> retrieveAllDepositProductsForLookup() {
|
public Collection<DepositProductLookup> retrieveAllDepositProductsForLookup() {
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
DepositProductLookupMapper depositProductLookupMapper = new DepositProductLookupMapper();
|
DepositProductLookupMapper depositProductLookupMapper = new DepositProductLookupMapper();
|
||||||
String sql = "select " + depositProductLookupMapper.depositProductLookupSchema();
|
String sql = "select " + depositProductLookupMapper.depositProductLookupSchema() + " where dp.is_deleted=0";
|
||||||
return this.jdbcTemplate.query(sql, depositProductLookupMapper, new Object[] {});
|
return this.jdbcTemplate.query(sql, depositProductLookupMapper, new Object[] {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -5,18 +5,19 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.portfolio.savingsdepositproduct.service;
|
package org.mifosplatform.portfolio.savingsdepositproduct.service;
|
||||||
|
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.portfolio.savingsdepositproduct.command.DepositProductCommand;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
|
||||||
public interface DepositProductWritePlatformService {
|
public interface DepositProductWritePlatformService {
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'CREATE_DEPOSITPRODUCT')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'CREATE_DEPOSITPRODUCT')")
|
||||||
CommandProcessingResult createDepositProduct(DepositProductCommand command);
|
CommandProcessingResult createDepositProduct(JsonCommand command);
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'UPDATE_DEPOSITPRODUCT')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'UPDATE_DEPOSITPRODUCT')")
|
||||||
CommandProcessingResult updateDepositProduct(DepositProductCommand command);
|
CommandProcessingResult updateDepositProduct(Long productId,JsonCommand command);
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'DELETE_DEPOSITPRODUCT')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'DELETE_DEPOSITPRODUCT')")
|
||||||
CommandProcessingResult deleteDepositProduct(Long productId);
|
CommandProcessingResult deleteDepositProduct(Long productId);
|
||||||
|
|
||||||
}
|
}
|
||||||
+73
-70
@@ -5,16 +5,18 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.portfolio.savingsdepositproduct.service;
|
package org.mifosplatform.portfolio.savingsdepositproduct.service;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
|
|
||||||
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
|
import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType;
|
||||||
import org.mifosplatform.portfolio.savingsdepositproduct.command.DepositProductCommand;
|
|
||||||
import org.mifosplatform.portfolio.savingsdepositproduct.domain.DepositProduct;
|
import org.mifosplatform.portfolio.savingsdepositproduct.domain.DepositProduct;
|
||||||
import org.mifosplatform.portfolio.savingsdepositproduct.domain.DepositProductRepository;
|
import org.mifosplatform.portfolio.savingsdepositproduct.domain.DepositProductRepository;
|
||||||
import org.mifosplatform.portfolio.savingsdepositproduct.exception.DepositProductNotFoundException;
|
import org.mifosplatform.portfolio.savingsdepositproduct.exception.DepositProductNotFoundException;
|
||||||
|
import org.mifosplatform.portfolio.savingsdepositproduct.serialization.DepositProductCommandFromApiJsonDeserializer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -29,95 +31,95 @@ public class DepositProductWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
|
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final DepositProductRepository depositProductRepository;
|
private final DepositProductRepository depositProductRepository;
|
||||||
|
private final DepositProductCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DepositProductWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
public DepositProductWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
||||||
final DepositProductRepository depositProductRepository) {
|
final DepositProductRepository depositProductRepository,
|
||||||
|
final DepositProductCommandFromApiJsonDeserializer fromApiJsonDeserializer) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.depositProductRepository = depositProductRepository;
|
this.depositProductRepository = depositProductRepository;
|
||||||
|
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Guaranteed to throw an exception no matter what the data integrity issue
|
* Guaranteed to throw an exception no matter what the data integrity issue
|
||||||
* is.
|
* is.
|
||||||
*/
|
*/
|
||||||
private void handleDataIntegrityIssues(final DepositProductCommand command, final DataIntegrityViolationException dve) {
|
private void handleDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) {
|
||||||
|
|
||||||
Throwable realCause = dve.getMostSpecificCause();
|
Throwable realCause = dve.getMostSpecificCause();
|
||||||
if (realCause.getMessage().contains("name_deposit_product")) { throw new PlatformDataIntegrityException(
|
if (realCause.getMessage().contains("name_deposit_product")) {
|
||||||
"error.msg.desposit.product.duplicate.name", "Deposit product with name: " + command.getName() + " already exists", "name",
|
final String name = command.stringValueOfParameterNamed("name");
|
||||||
command.getName()); }
|
throw new PlatformDataIntegrityException(
|
||||||
if (realCause.getMessage().contains("externalid_deposit_product")) { throw new PlatformDataIntegrityException(
|
"error.msg.desposit.product.duplicate.name", "Deposit product with name: " + name + " already exists", "name",
|
||||||
"error.msg.desposit.product.duplicate.externalId", "Deposit product with externalId " + command.getExternalId()
|
name); }
|
||||||
+ " already exists", "externalId", command.getExternalId()); }
|
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); }
|
||||||
|
|
||||||
logger.error(dve.getMessage(), dve);
|
logger.error(dve.getMessage(), dve);
|
||||||
throw new PlatformDataIntegrityException("error.msg.deposit.product.unknown.data.integrity.issue",
|
throw new PlatformDataIntegrityException("error.msg.deposit.product.unknown.data.integrity.issue",
|
||||||
"Unknown data integrity issue with resource.");
|
"Unknown data integrity issue with resource.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult createDepositProduct(final DepositProductCommand command) {
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
@Transactional
|
||||||
this.context.authenticatedUser();
|
@Override
|
||||||
DepositProductCommandValidator validator = new DepositProductCommandValidator(command);
|
public CommandProcessingResult updateDepositProduct(final Long productId, final JsonCommand command) {
|
||||||
validator.validateForCreate();
|
try {
|
||||||
|
|
||||||
PeriodFrequencyType interestCompoundingPeriodType = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType());
|
this.context.authenticatedUser();
|
||||||
PeriodFrequencyType lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType());
|
|
||||||
MonetaryCurrency currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimal());
|
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
||||||
DepositProduct product = new DepositProduct(command.getName(), command.getExternalId(), command.getDescription(), currency,
|
|
||||||
command.getMinimumBalance(), command.getMaximumBalance(), command.getTenureInMonths(),
|
DepositProduct product = this.depositProductRepository.findOne(productId);
|
||||||
command.getMaturityDefaultInterestRate(), command.getMaturityMinInterestRate(), command.getMaturityMaxInterestRate(),
|
if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(productId); }
|
||||||
command.getInterestCompoundedEvery(), interestCompoundingPeriodType, command.isRenewalAllowed(),
|
|
||||||
command.isPreClosureAllowed(), command.getPreClosureInterestRate(), command.isInterestCompoundingAllowed(),
|
final Map<String, Object> changes = product.update(command);
|
||||||
command.isLockinPeriodAllowed(), command.getLockinPeriod(), lockinPeriodType);
|
|
||||||
this.depositProductRepository.save(product);
|
if (!changes.isEmpty()) {
|
||||||
|
this.depositProductRepository.saveAndFlush(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 DepositProductCommand command) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.context.authenticatedUser();
|
|
||||||
DepositProductCommandValidator validator = new DepositProductCommandValidator(command);
|
|
||||||
validator.validateForUpdate();
|
|
||||||
|
|
||||||
DepositProduct product = this.depositProductRepository.findOne(command.getId());
|
|
||||||
if (product == null) { throw new DepositProductNotFoundException(command.getId()); }
|
|
||||||
|
|
||||||
PeriodFrequencyType interestCompoundingFrequency = null;
|
|
||||||
if (command.isInterestCompoundedEveryPeriodTypeChanged()) {
|
|
||||||
interestCompoundingFrequency = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PeriodFrequencyType lockinPeriodType = null;
|
return new CommandProcessingResultBuilder() //
|
||||||
if (command.isLockinPeriodTypeChanged()) {
|
.withCommandId(command.commandId()) //
|
||||||
lockinPeriodType = PeriodFrequencyType.fromInt(command.getLockinPeriodType());
|
.withEntityId(productId) //
|
||||||
}
|
.with(changes) //
|
||||||
|
.build();
|
||||||
product.update(command, interestCompoundingFrequency, lockinPeriodType);
|
|
||||||
this.depositProductRepository.save(product);
|
} catch (DataIntegrityViolationException dve) {
|
||||||
|
handleDataIntegrityIssues(command, dve);
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResult(Long.valueOf(-1));
|
||||||
.withEntityId(product.getId()) //
|
}
|
||||||
.build();
|
}
|
||||||
} catch (DataIntegrityViolationException dve) {
|
|
||||||
handleDataIntegrityIssues(command, dve);
|
|
||||||
return new CommandProcessingResult(Long.valueOf(-1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
@@ -125,7 +127,7 @@ public class DepositProductWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
|
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
DepositProduct product = this.depositProductRepository.findOne(productId);
|
DepositProduct product = this.depositProductRepository.findOne(productId);
|
||||||
if (product == null) { throw new DepositProductNotFoundException(productId); }
|
if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(productId); }
|
||||||
product.delete();
|
product.delete();
|
||||||
|
|
||||||
this.depositProductRepository.save(product);
|
this.depositProductRepository.save(product);
|
||||||
@@ -134,4 +136,5 @@ public class DepositProductWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
.withEntityId(product.getId()) //
|
.withEntityId(product.getId()) //
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user