continue fixed term deposit account basics
This commit is contained in:
@@ -175,7 +175,7 @@ public class DataValidatorBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataValidatorBuilder greaterThanZero() {
|
||||
public DataValidatorBuilder integerGreaterThanZero() {
|
||||
if (value == null && ignoreNullValue) {
|
||||
return this;
|
||||
}
|
||||
|
||||
+56
-34
@@ -3,6 +3,7 @@ package org.mifosng.platform.api;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
@@ -18,13 +19,15 @@ import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosng.platform.api.commands.SavingProductCommand;
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.api.data.CurrencyData;
|
||||
import org.mifosng.platform.api.data.DepositAccountData;
|
||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||
import org.mifosng.platform.api.data.SavingProductData;
|
||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||
import org.mifosng.platform.api.infrastructure.ApiParameterHelper;
|
||||
import org.mifosng.platform.savingproduct.service.SavingProductReadPlatformService;
|
||||
import org.mifosng.platform.savingproduct.service.SavingProductWritePlatformService;
|
||||
import org.mifosng.platform.currency.service.CurrencyReadPlatformService;
|
||||
import org.mifosng.platform.savingproduct.service.DepositAccountReadPlatformService;
|
||||
import org.mifosng.platform.savingproduct.service.DepositAccountWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -35,10 +38,13 @@ import org.springframework.stereotype.Component;
|
||||
public class DepositAccountsApiResource {
|
||||
|
||||
@Autowired
|
||||
private SavingProductReadPlatformService savingProductReadPlatformService;
|
||||
private DepositAccountReadPlatformService depositAccountReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
private SavingProductWritePlatformService savingProductWritePlatformService;
|
||||
private CurrencyReadPlatformService currencyReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
private DepositAccountWritePlatformService depositAccountWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
private ApiDataConversionService apiDataConversionService;
|
||||
@@ -48,31 +54,36 @@ public class DepositAccountsApiResource {
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response createDepositAccount(final String jsonRequestBody){
|
||||
|
||||
final SavingProductCommand command=this.apiDataConversionService.convertJsonToSavingProductCommand(null, jsonRequestBody);
|
||||
final DepositAccountCommand command = this.apiDataConversionService.convertJsonToDepositAccountCommand(null, jsonRequestBody);
|
||||
|
||||
EntityIdentifier entityIdentifier=this.savingProductWritePlatformService.createSavingProduct(command);
|
||||
EntityIdentifier entityIdentifier = this.depositAccountWritePlatformService.createDepositAccount(command);
|
||||
|
||||
return Response.ok().entity(entityIdentifier).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{productId}")
|
||||
@Path("{accountId}")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response updateSavingProduct(@PathParam("productId") final Long productId, final String jsonRequestBody){
|
||||
public Response updateSavingProduct(@PathParam("accountId") final Long accountId, final String jsonRequestBody){
|
||||
|
||||
final DepositAccountCommand command = this.apiDataConversionService.convertJsonToDepositAccountCommand(accountId, jsonRequestBody);
|
||||
|
||||
EntityIdentifier entityIdentifier = this.depositAccountWritePlatformService.updateDepositAccount(command);
|
||||
|
||||
SavingProductCommand command=this.apiDataConversionService.convertJsonToSavingProductCommand(productId, jsonRequestBody);
|
||||
EntityIdentifier entityIdentifier=this.savingProductWritePlatformService.updateSavingProduct(command);
|
||||
return Response.ok().entity(entityIdentifier).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveAllSavingProducts(@Context final UriInfo uriInfo) {
|
||||
public String retrieveAllDepositAccounts(@Context final UriInfo uriInfo) {
|
||||
|
||||
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "name", "description", "createdOn", "lastModifedOn",
|
||||
"interestRate","currencyCode","digitsAfterDecimal"));
|
||||
Set<String> typicalResponseParameters = new HashSet<String>(
|
||||
Arrays.asList("createdOn", "lastModifedOn",
|
||||
"id", "clientId", "clientName", "productId", "productName",
|
||||
"currency", "deposit", "interestRate")
|
||||
);
|
||||
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
@@ -80,63 +91,74 @@ public class DepositAccountsApiResource {
|
||||
}
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
Collection<SavingProductData> products = this.savingProductReadPlatformService.retrieveAllSavingProducts();
|
||||
Collection<DepositAccountData> accounts = this.depositAccountReadPlatformService.retrieveAllDepositAccounts();
|
||||
|
||||
return this.apiDataConversionService.convertSavingProductDataToJson(prettyPrint, responseParameters, products.toArray(new SavingProductData[products.size()]));
|
||||
return this.apiDataConversionService.convertDepositAccountDataToJson(prettyPrint, responseParameters, accounts.toArray(new DepositAccountData[accounts.size()]));
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{productId}")
|
||||
@Path("{accountId}")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveSavingProductDetails(@PathParam("productId") final Long productId, @Context final UriInfo uriInfo) {
|
||||
|
||||
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "name", "description", "createdOn", "lastModifedOn",
|
||||
"interestRate","currencyCode","digitsAfterDecimal"));
|
||||
public String retrieveDepositAccount(@PathParam("accountId") final Long accountId, @Context final UriInfo uriInfo) {
|
||||
|
||||
Set<String> typicalResponseParameters = new HashSet<String>(
|
||||
Arrays.asList("createdOn", "lastModifedOn",
|
||||
"id", "clientId", "clientName", "productId", "productName",
|
||||
"currency", "deposit", "interestRate")
|
||||
);
|
||||
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
}
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
DepositAccountData account = this.depositAccountReadPlatformService.retrieveDepositAccount(accountId);
|
||||
|
||||
boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
||||
if (template) {
|
||||
responseParameters.addAll(Arrays.asList("currencyOptions"));
|
||||
List<CurrencyData> allowedCurrencies = this.currencyReadPlatformService.retrieveAllowedCurrencies();
|
||||
account = new DepositAccountData(account, allowedCurrencies);
|
||||
}
|
||||
|
||||
SavingProductData savingProduct = this.savingProductReadPlatformService.retrieveSavingProduct(productId);
|
||||
|
||||
return this.apiDataConversionService.convertSavingProductDataToJson(prettyPrint, responseParameters, savingProduct);
|
||||
return this.apiDataConversionService.convertDepositAccountDataToJson(prettyPrint, responseParameters, account);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("template")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveNewSavingProductDetails(@Context final UriInfo uriInfo) {
|
||||
public String retrieveNewDepositAccountDetails(@Context final UriInfo uriInfo) {
|
||||
|
||||
Set<String> typicalResponseParameters = new HashSet<String>(
|
||||
Arrays.asList("id", "name", "description", "createdOn", "lastModifedOn","interestRate","currencyCode","digitsAfterDecimal", "currencyOptions"));
|
||||
Arrays.asList("createdOn", "lastModifedOn",
|
||||
"id", "clientId", "clientName", "productId", "productName",
|
||||
"currency", "deposit", "interestRate", "currencyOptions")
|
||||
);
|
||||
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
}
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
SavingProductData savingProduct = this.savingProductReadPlatformService.retrieveNewSavingProductDetails();
|
||||
|
||||
return this.apiDataConversionService.convertSavingProductDataToJson(prettyPrint, responseParameters, savingProduct);
|
||||
DepositAccountData account = this.depositAccountReadPlatformService.retrieveNewDepositAccountDetails();
|
||||
List<CurrencyData> allowedCurrencies = this.currencyReadPlatformService.retrieveAllowedCurrencies();
|
||||
account = new DepositAccountData(account, allowedCurrencies);
|
||||
|
||||
return this.apiDataConversionService.convertDepositAccountDataToJson(prettyPrint, responseParameters, account);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{productId}")
|
||||
@Path("{accountId}")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response deleteProduct(@PathParam("productId") final Long productId) {
|
||||
public Response deleteProduct(@PathParam("accountId") final Long accountId) {
|
||||
|
||||
this.savingProductWritePlatformService.deleteSavingProduct(productId);
|
||||
this.depositAccountWritePlatformService.deleteDepositAccount(accountId);
|
||||
|
||||
return Response.ok(new EntityIdentifier(productId)).build();
|
||||
return Response.ok(new EntityIdentifier(accountId)).build();
|
||||
}
|
||||
}
|
||||
+37
-8
@@ -9,26 +9,39 @@ import java.util.Set;
|
||||
public class DepositAccountCommand {
|
||||
|
||||
private final Long id;
|
||||
private final Long clientId;
|
||||
private final Long productId;
|
||||
private final String externalId;
|
||||
|
||||
private final String currencyCode;
|
||||
private final Integer digitsAfterDecimal;
|
||||
private final BigDecimal maturityActualInterestRate;
|
||||
|
||||
private final BigDecimal depositAmount;
|
||||
private final BigDecimal interestRate;
|
||||
private final Integer termInMonths;
|
||||
|
||||
private final Set<String> modifiedParameters;
|
||||
|
||||
public DepositAccountCommand(final Set<String> modifiedParameters,
|
||||
final Long id,
|
||||
final Long clientId,
|
||||
final Long productId,
|
||||
final String externalId,
|
||||
final String currencyCode,
|
||||
final Integer digitsAfterDecimal,
|
||||
final BigDecimal maturityActualInterestRate) {
|
||||
final BigDecimal depositAmount,
|
||||
final BigDecimal interestRate,
|
||||
final Integer termInMonths) {
|
||||
this.id = id;
|
||||
this.clientId = clientId;
|
||||
this.productId = productId;
|
||||
this.externalId = externalId;
|
||||
|
||||
this.currencyCode = currencyCode;
|
||||
this.digitsAfterDecimal = digitsAfterDecimal;
|
||||
this.maturityActualInterestRate = maturityActualInterestRate;
|
||||
|
||||
this.depositAmount = depositAmount;
|
||||
this.interestRate = interestRate;
|
||||
this.termInMonths = termInMonths;
|
||||
|
||||
this.modifiedParameters = modifiedParameters;
|
||||
}
|
||||
|
||||
@@ -36,6 +49,14 @@ public class DepositAccountCommand {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Long getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public Long getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public String getExternalId() {
|
||||
return externalId;
|
||||
}
|
||||
@@ -48,8 +69,16 @@ public class DepositAccountCommand {
|
||||
return digitsAfterDecimal;
|
||||
}
|
||||
|
||||
public BigDecimal getMaturityActualInterestRate() {
|
||||
return maturityActualInterestRate;
|
||||
public BigDecimal getDepositAmount() {
|
||||
return depositAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getInterestRate() {
|
||||
return interestRate;
|
||||
}
|
||||
|
||||
public Integer getTermInMonths() {
|
||||
return termInMonths;
|
||||
}
|
||||
|
||||
public boolean isCurrencyCodeChanged() {
|
||||
@@ -63,4 +92,4 @@ public class DepositAccountCommand {
|
||||
public boolean isMaturityActualInterestRateChanged() {
|
||||
return this.modifiedParameters.contains("interestRate");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package org.mifosng.platform.api.data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* Immutable data object for deposit accounts.
|
||||
*/
|
||||
public class DepositAccountData {
|
||||
|
||||
private final Long id;
|
||||
|
||||
private final Long clientId;
|
||||
private final String clientName;
|
||||
|
||||
private final Long productId;
|
||||
private final String productName;
|
||||
|
||||
private final CurrencyData currency;
|
||||
private final BigDecimal deposit;
|
||||
private final BigDecimal interestRate;
|
||||
|
||||
private final DateTime createdOn;
|
||||
private final DateTime lastModifedOn;
|
||||
|
||||
private final List<CurrencyData> currencyOptions;
|
||||
|
||||
public DepositAccountData() {
|
||||
this.createdOn = null;
|
||||
this.lastModifedOn = null;
|
||||
this.id = null;
|
||||
this.clientId = null;
|
||||
this.clientName = null;
|
||||
this.productId = null;
|
||||
this.productName = null;
|
||||
this.currency = null;
|
||||
this.deposit = null;
|
||||
this.interestRate = null;
|
||||
this.currencyOptions = new ArrayList<CurrencyData>();
|
||||
}
|
||||
|
||||
public DepositAccountData(final DepositAccountData account, final List<CurrencyData> currencies) {
|
||||
this.createdOn = account.getCreatedOn();
|
||||
this.lastModifedOn = account.getLastModifedOn();
|
||||
this.id = account.getId();
|
||||
this.clientId = account.getClientId();
|
||||
this.clientName = account.getClientName();
|
||||
this.productId = account.getProductId();
|
||||
this.productName = account.getProductName();
|
||||
this.currency = account.getCurrency();
|
||||
this.deposit = account.getDeposit();
|
||||
this.interestRate = account.getInterestRate();
|
||||
this.currencyOptions = currencies;
|
||||
}
|
||||
|
||||
public DepositAccountData(
|
||||
final DateTime createdOn,
|
||||
final DateTime lastModifedOn,
|
||||
final Long id,
|
||||
final Long clientId,
|
||||
final String clientName,
|
||||
final Long productId,
|
||||
final String productName,
|
||||
final CurrencyData currency,
|
||||
final BigDecimal deposit, BigDecimal interestRate) {
|
||||
this.createdOn=createdOn;
|
||||
this.lastModifedOn=lastModifedOn;
|
||||
this.id=id;
|
||||
this.clientId = clientId;
|
||||
this.clientName = clientName;
|
||||
this.productId = productId;
|
||||
this.productName = productName;
|
||||
this.currency = currency;
|
||||
this.deposit = deposit;
|
||||
this.interestRate=interestRate;
|
||||
this.currencyOptions = new ArrayList<CurrencyData>();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Long getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public String getClientName() {
|
||||
return clientName;
|
||||
}
|
||||
|
||||
public Long getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
return productName;
|
||||
}
|
||||
|
||||
public CurrencyData getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
public BigDecimal getDeposit() {
|
||||
return deposit;
|
||||
}
|
||||
|
||||
public BigDecimal getInterestRate() {
|
||||
return interestRate;
|
||||
}
|
||||
|
||||
public DateTime getCreatedOn() {
|
||||
return createdOn;
|
||||
}
|
||||
|
||||
public DateTime getLastModifedOn() {
|
||||
return lastModifedOn;
|
||||
}
|
||||
|
||||
public List<CurrencyData> getCurrencyOptions() {
|
||||
return currencyOptions;
|
||||
}
|
||||
}
|
||||
+6
@@ -6,6 +6,7 @@ import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand;
|
||||
import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
|
||||
import org.mifosng.platform.api.commands.ClientCommand;
|
||||
import org.mifosng.platform.api.commands.DepositProductCommand;
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.api.commands.FundCommand;
|
||||
import org.mifosng.platform.api.commands.GroupCommand;
|
||||
import org.mifosng.platform.api.commands.LoanProductCommand;
|
||||
@@ -25,6 +26,7 @@ import org.mifosng.platform.api.data.ClientData;
|
||||
import org.mifosng.platform.api.data.ClientLoanAccountSummaryCollectionData;
|
||||
import org.mifosng.platform.api.data.ConfigurationData;
|
||||
import org.mifosng.platform.api.data.DepositProductData;
|
||||
import org.mifosng.platform.api.data.DepositAccountData;
|
||||
import org.mifosng.platform.api.data.FundData;
|
||||
import org.mifosng.platform.api.data.GenericResultsetData;
|
||||
import org.mifosng.platform.api.data.GroupData;
|
||||
@@ -67,6 +69,8 @@ public interface ApiDataConversionService {
|
||||
|
||||
String convertDepositProductDataToJson(boolean prettyPrint, Set<String> responseParameters, DepositProductData... products);
|
||||
|
||||
String convertDepositAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, DepositAccountData... accounts);
|
||||
|
||||
String convertNewLoanDataToJson(boolean prettyPrint, Set<String> responseParameters, NewLoanData newLoanData);
|
||||
|
||||
String convertLoanAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanAccountData loanAccount);
|
||||
@@ -116,4 +120,6 @@ public interface ApiDataConversionService {
|
||||
OrganisationCurrencyCommand convertJsonToOrganisationCurrencyCommand(String jsonRequestBody);
|
||||
|
||||
NoteCommand convertJsonToNoteCommand(Long resourceIdentifier, Long clientId, String jsonRequestBody);
|
||||
|
||||
DepositAccountCommand convertJsonToDepositAccountCommand(Long resourceIdentifier, String jsonRequestBody);
|
||||
}
|
||||
+97
-6
@@ -22,6 +22,7 @@ import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand;
|
||||
import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
|
||||
import org.mifosng.platform.api.commands.ClientCommand;
|
||||
import org.mifosng.platform.api.commands.DepositProductCommand;
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.api.commands.FundCommand;
|
||||
import org.mifosng.platform.api.commands.GroupCommand;
|
||||
import org.mifosng.platform.api.commands.LoanProductCommand;
|
||||
@@ -42,6 +43,7 @@ import org.mifosng.platform.api.data.ClientData;
|
||||
import org.mifosng.platform.api.data.ClientLoanAccountSummaryCollectionData;
|
||||
import org.mifosng.platform.api.data.ConfigurationData;
|
||||
import org.mifosng.platform.api.data.DepositProductData;
|
||||
import org.mifosng.platform.api.data.DepositAccountData;
|
||||
import org.mifosng.platform.api.data.FundData;
|
||||
import org.mifosng.platform.api.data.GenericResultsetData;
|
||||
import org.mifosng.platform.api.data.GroupData;
|
||||
@@ -1479,10 +1481,42 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
||||
|
||||
return new SavingProductCommand(modifiedParameters, resourceIdentifier,name, description,currencyCode,digitsAfterDecimalValue,interestRate,minimumBalance,maximumBalance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DepositAccountCommand convertJsonToDepositAccountCommand(final Long resourceIdentifier, final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) {
|
||||
throw new InvalidJsonException();
|
||||
}
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType();
|
||||
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
Set<String> supportedParams = new HashSet<String>(
|
||||
Arrays.asList("clientId", "productId", "externalId", "currencyCode", "digitsAfterDecimal", "depositAmount", "interestRate", "termInMonths", "locale")
|
||||
);
|
||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||
Set<String> modifiedParameters = new HashSet<String>();
|
||||
|
||||
Long clientId = extractLongParameter("clientId", requestMap, modifiedParameters);
|
||||
Long productId = extractLongParameter("productId", requestMap, modifiedParameters);
|
||||
String externalId = extractStringParameter("externalId", requestMap,modifiedParameters);
|
||||
String currencyCode=extractStringParameter("currencyCode", requestMap,modifiedParameters);
|
||||
Integer digitsAfterDecimalValue = extractIntegerParameter("digitsAfterDecimal", requestMap, modifiedParameters);
|
||||
BigDecimal depositAmount=extractBigDecimalParameter("depositAmount", requestMap, modifiedParameters);
|
||||
BigDecimal interestRate = extractBigDecimalParameter("interestRate", requestMap, modifiedParameters);
|
||||
Integer termInMonths = extractIntegerParameter("termInMonths", requestMap, modifiedParameters);
|
||||
|
||||
// isRenewable, isPreClosureAllowed, expectedDepositDate, pojectMaturityDate, projectedInterestAccrued
|
||||
|
||||
return new DepositAccountCommand(modifiedParameters, resourceIdentifier, clientId, productId, externalId, currencyCode, digitsAfterDecimalValue, depositAmount, interestRate, termInMonths);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertSavingProductDataToJson(boolean prettyPrint,
|
||||
Set<String> responseParameters, SavingProductData... products) {
|
||||
public String convertSavingProductDataToJson(
|
||||
final boolean prettyPrint,
|
||||
final Set<String> responseParameters,
|
||||
final SavingProductData... products) {
|
||||
|
||||
Set<String> supportedParameters = new HashSet<String>(
|
||||
Arrays.asList("id", "name", "description","createdOn", "lastModifedOn","interestRate","currencyCode","digitsAfterDecimal", "currencyOptions", "minimumBalance","maximumBalance"));
|
||||
@@ -1519,7 +1553,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DepositProductCommand convertJsonToDepositProductCommand(Long resourceIdentifier, String json) {
|
||||
public DepositProductCommand convertJsonToDepositProductCommand(final Long resourceIdentifier, final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) {
|
||||
throw new InvalidJsonException();
|
||||
@@ -1556,17 +1590,27 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
||||
Set<String> responseParameters, DepositProductData... products) {
|
||||
|
||||
Set<String> supportedParameters = new HashSet<String>(
|
||||
Arrays.asList("id", "name", "description","createdOn", "lastModifedOn","currencyCode","digitsAfterDecimal", "currencyOptions", "minimumBalance","maximumBalance"));
|
||||
Arrays.asList("id", "name", "description","createdOn", "lastModifedOn","currencyCode","digitsAfterDecimal", "currencyOptions",
|
||||
"minimumBalance","maximumBalance"));
|
||||
|
||||
final Set<String> parameterNamesToSkip = new HashSet<String>();
|
||||
|
||||
if (!responseParameters.isEmpty()) {
|
||||
if (!supportedParameters.containsAll(responseParameters)) {
|
||||
throw new UnsupportedParameterException(new ArrayList<String>(responseParameters));
|
||||
|
||||
// strip out all know support params from expected response to see if unsupported parameters requested for response.
|
||||
Set<String> differentParametersSet = new HashSet<String>(responseParameters);
|
||||
differentParametersSet.removeAll(supportedParameters);
|
||||
|
||||
if (!differentParametersSet.isEmpty()) {
|
||||
throw new UnsupportedParameterException(new ArrayList<String>(differentParametersSet));
|
||||
}
|
||||
|
||||
parameterNamesToSkip.addAll(supportedParameters);
|
||||
parameterNamesToSkip.removeAll(responseParameters);
|
||||
}
|
||||
|
||||
ExclusionStrategy strategy = new ParameterListExclusionStrategy(parameterNamesToSkip);
|
||||
|
||||
GsonBuilder builder = new GsonBuilder().addSerializationExclusionStrategy(strategy);
|
||||
builder.registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter());
|
||||
builder.registerTypeAdapter(DateTime.class, new JodaDateTimeAdapter());
|
||||
@@ -1581,6 +1625,53 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
||||
} else {
|
||||
json = gsonDeserializer.toJson(products);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertDepositAccountDataToJson(
|
||||
final boolean prettyPrint,
|
||||
final Set<String> responseParameters,
|
||||
final DepositAccountData... accounts) {
|
||||
|
||||
Set<String> supportedParameters = new HashSet<String>(
|
||||
Arrays.asList("createdOn", "lastModifedOn",
|
||||
"id", "clientId", "clientName", "productId", "productName",
|
||||
"currency", "deposit", "interestRate", "currencyOptions")
|
||||
);
|
||||
|
||||
final Set<String> parameterNamesToSkip = new HashSet<String>();
|
||||
|
||||
if (!responseParameters.isEmpty()) {
|
||||
|
||||
// strip out all know support params from expected response to see if unsupported parameters requested for response.
|
||||
Set<String> differentParametersSet = new HashSet<String>(responseParameters);
|
||||
differentParametersSet.removeAll(supportedParameters);
|
||||
|
||||
if (!differentParametersSet.isEmpty()) {
|
||||
throw new UnsupportedParameterException(new ArrayList<String>(differentParametersSet));
|
||||
}
|
||||
|
||||
parameterNamesToSkip.addAll(supportedParameters);
|
||||
parameterNamesToSkip.removeAll(responseParameters);
|
||||
}
|
||||
|
||||
ExclusionStrategy strategy = new ParameterListExclusionStrategy(parameterNamesToSkip);
|
||||
|
||||
GsonBuilder builder = new GsonBuilder().addSerializationExclusionStrategy(strategy);
|
||||
builder.registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter());
|
||||
builder.registerTypeAdapter(DateTime.class, new JodaDateTimeAdapter());
|
||||
if (prettyPrint) {
|
||||
builder.setPrettyPrinting();
|
||||
}
|
||||
Gson gsonDeserializer = builder.create();
|
||||
|
||||
String json = "";
|
||||
if (accounts != null && accounts.length == 1) {
|
||||
json = gsonDeserializer.toJson(accounts[0]);
|
||||
} else {
|
||||
json = gsonDeserializer.toJson(accounts);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ public class ClientCommandValidator {
|
||||
baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100);
|
||||
|
||||
if (command.isOfficeChanged()) {
|
||||
baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).notNull().integerGreaterThanZero();
|
||||
}
|
||||
|
||||
baseDataValidator.reset().anyOfNotNull(command.getFirstname(), command.getLastname(), command.getClientOrBusinessName(),
|
||||
@@ -60,7 +60,7 @@ public class ClientCommandValidator {
|
||||
|
||||
baseDataValidator.reset().parameter("joiningDate").value(command.getJoiningDate()).notBlank();
|
||||
baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).notExceedingLengthOf(100);
|
||||
baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).notNull().integerGreaterThanZero();
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) {
|
||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package org.mifosng.platform.exceptions;
|
||||
|
||||
public class DepositAccountNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
public DepositAccountNotFoundException(final Long id) {
|
||||
super("error.msg.deposit.account.id.invalid", "Deposit account with identifier " + id + " does not exist", id);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -22,8 +22,8 @@ public class AdjustLoanTransactionCommandValidator {
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transaction");
|
||||
|
||||
baseDataValidator.reset().parameter("loanId").value(command.getLoanId()).notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("transactionId").value(command.getTransactionId()).notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("loanId").value(command.getLoanId()).notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("transactionId").value(command.getTransactionId()).notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("transactionDate").value(command.getTransactionDate()).notNull();
|
||||
baseDataValidator.reset().parameter("transactionAmount").value(command.getTransactionAmount()).notNull().positiveAmount();
|
||||
baseDataValidator.reset().parameter("note").value(command.getNote()).notExceedingLengthOf(1000);
|
||||
|
||||
+3
-3
@@ -24,11 +24,11 @@ public class CalculateLoanScheduleCommandValidator {
|
||||
|
||||
baseDataValidator.reset().parameter("principal").value(command.getPrincipal()).notNull().positiveAmount();
|
||||
|
||||
baseDataValidator.reset().parameter("loanTermFrequency").value(command.getLoanTermFrequency()).notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("loanTermFrequency").value(command.getLoanTermFrequency()).notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("loanTermFrequencyType").value(command.getLoanTermFrequencyType()).notNull().inMinMaxRange(0, 4);
|
||||
|
||||
baseDataValidator.reset().parameter("numberOfRepayments").value(command.getNumberOfRepayments()).notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("repaymentEvery").value(command.getRepaymentEvery()).notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("numberOfRepayments").value(command.getNumberOfRepayments()).notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("repaymentEvery").value(command.getRepaymentEvery()).notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("repaymentFrequencyType").value(command.getRepaymentFrequencyType()).notNull().inMinMaxRange(0, 3);
|
||||
|
||||
// FIXME - this constraint doesnt really need to be here. should be possible to express loan term as say 12 months whilst also saying
|
||||
|
||||
@@ -66,7 +66,7 @@ public class LoanAssembler {
|
||||
}
|
||||
|
||||
Client client = this.clientRepository.findOne(command.getClientId());
|
||||
if (client == null) {
|
||||
if (client == null || client.isDeleted()) {
|
||||
throw new ClientNotFoundException(command.getClientId());
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ public class LoanStateTransitionCommandValidator {
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transition");
|
||||
|
||||
baseDataValidator.reset().parameter("loanId").value(command.getLoanId()).notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("loanId").value(command.getLoanId()).notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("eventDate").value(command.getEventDate()).notNull();
|
||||
baseDataValidator.reset().parameter("note").value(command.getNote()).notExceedingLengthOf(1000);
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ public class LoanTransactionCommandValidator {
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transaction");
|
||||
|
||||
baseDataValidator.reset().parameter("loanId").value(command.getLoanId()).notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("loanId").value(command.getLoanId()).notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("transactionDate").value(command.getTransactionDate()).notNull();
|
||||
baseDataValidator.reset().parameter("transactionAmount").value(command.getTransactionAmount()).notNull().positiveAmount();
|
||||
baseDataValidator.reset().parameter("note").value(command.getNote()).notExceedingLengthOf(1000);
|
||||
|
||||
+4
-4
@@ -33,8 +33,8 @@ public class LoanProductCommandValidator {
|
||||
|
||||
baseDataValidator.reset().parameter("repaymentFrequencyType").value(command.getRepaymentFrequencyType()).ignoreIfNull().notNull().inMinMaxRange(0, 3);
|
||||
|
||||
baseDataValidator.reset().parameter("repaymentEvery").value(command.getRepaymentEvery()).ignoreIfNull().notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("numberOfRepayments").value(command.getNumberOfRepayments()).ignoreIfNull().notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("repaymentEvery").value(command.getRepaymentEvery()).ignoreIfNull().notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("numberOfRepayments").value(command.getNumberOfRepayments()).ignoreIfNull().notNull().integerGreaterThanZero();
|
||||
|
||||
baseDataValidator.reset().parameter("interestRatePerPeriod").value(command.getInterestRatePerPeriod()).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("interestRateFrequencyType").value(command.getInterestRateFrequencyType()).ignoreIfNull().notNull().inMinMaxRange(0, 3);
|
||||
@@ -67,8 +67,8 @@ public class LoanProductCommandValidator {
|
||||
baseDataValidator.reset().parameter("inArrearsTolerance").value(command.getInArrearsTolerance()).notNull().zeroOrPositiveAmount();
|
||||
|
||||
baseDataValidator.reset().parameter("repaymentFrequencyType").value(command.getRepaymentFrequencyType()).notNull().inMinMaxRange(0, 3);
|
||||
baseDataValidator.reset().parameter("repaymentEvery").value(command.getRepaymentEvery()).notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("numberOfRepayments").value(command.getNumberOfRepayments()).notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("repaymentEvery").value(command.getRepaymentEvery()).notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("numberOfRepayments").value(command.getNumberOfRepayments()).notNull().integerGreaterThanZero();
|
||||
|
||||
baseDataValidator.reset().parameter("interestRatePerPeriod").value(command.getInterestRatePerPeriod()).notNull();
|
||||
baseDataValidator.reset().parameter("interestRateFrequencyType").value(command.getInterestRateFrequencyType()).notNull().inMinMaxRange(0, 3);
|
||||
|
||||
+2
-2
@@ -22,8 +22,8 @@ public class BranchMoneyTransferCommandValidator {
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("office.money.transfer");
|
||||
|
||||
baseDataValidator.reset().parameter("fromOfficeId").value(command.getFromOfficeId()).ignoreIfNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("toOfficeId").value(command.getToOfficeId()).ignoreIfNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("fromOfficeId").value(command.getFromOfficeId()).ignoreIfNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("toOfficeId").value(command.getToOfficeId()).ignoreIfNull().integerGreaterThanZero();
|
||||
|
||||
if (command.getFromOfficeId() == null && command.getToOfficeId() == null) {
|
||||
baseDataValidator.reset().parameter("toOfficeId").value(command.getToOfficeId()).notNull();
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ public class OfficeCommandValidator {
|
||||
baseDataValidator.reset().parameter("name").value(command.getName()).notBlank();
|
||||
baseDataValidator.reset().parameter("openingDate").value(command.getOpeningDate()).notBlank();
|
||||
baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).notExceedingLengthOf(100);
|
||||
baseDataValidator.reset().parameter("parentId").value(command.getParentId()).notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("parentId").value(command.getParentId()).notNull().integerGreaterThanZero();
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) {
|
||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||
@@ -41,7 +41,7 @@ public class OfficeCommandValidator {
|
||||
baseDataValidator.reset().parameter("name").value(command.getName()).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("openingDate").value(command.getOpeningDate()).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100);
|
||||
baseDataValidator.reset().parameter("parentId").value(command.getParentId()).ignoreIfNull().notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("parentId").value(command.getParentId()).ignoreIfNull().notNull().integerGreaterThanZero();
|
||||
|
||||
baseDataValidator.reset().anyOfNotNull(command.getName(), command.getOpeningDate(), command.getExternalId(), command.getParentId());
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package org.mifosng.platform.saving.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.client.domain.Client;
|
||||
import org.mifosng.platform.currency.domain.MonetaryCurrency;
|
||||
import org.mifosng.platform.currency.domain.Money;
|
||||
import org.mifosng.platform.infrastructure.AbstractAuditableCustom;
|
||||
import org.mifosng.platform.user.domain.AppUser;
|
||||
|
||||
@Entity
|
||||
@Table(name = "portfolio_deposit_account", uniqueConstraints = @UniqueConstraint(name="deposit_acc_external_id", columnNames = { "external_id" }))
|
||||
public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "client_id", nullable = false)
|
||||
private Client client;
|
||||
|
||||
// @ManyToOne
|
||||
// @JoinColumn(name = "product_id")
|
||||
// private final DepositAccountProduct depositAccountProduct;
|
||||
|
||||
@Column(name = "external_id")
|
||||
private String externalId;
|
||||
|
||||
@Embedded
|
||||
private MonetaryCurrency currency;
|
||||
|
||||
@Column(name = "deposit_amount", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal depositAmount;
|
||||
|
||||
@Column(name = "maturity_interest_rate", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal interestRate;
|
||||
|
||||
@Column(name = "tenure_months", nullable = false)
|
||||
private Integer tenureInMonths;
|
||||
|
||||
@Column(name = "pre_closure_interest_rate", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal preClosureInterestRate;
|
||||
|
||||
@Column(name = "can_renew", nullable = false)
|
||||
private boolean renewalAllowed;
|
||||
|
||||
@Column(name = "can_pre_close", nullable = false)
|
||||
private boolean preClosureAllowed;
|
||||
|
||||
@Column(name = "is_deleted", nullable=false)
|
||||
private boolean deleted = false;
|
||||
|
||||
protected DepositAccount() {
|
||||
//
|
||||
}
|
||||
|
||||
public DepositAccount(final Client client, final String externalId, final Money deposit, final BigDecimal interestRate, final Integer termInMonths) {
|
||||
this.client = client;
|
||||
this.externalId = externalId;
|
||||
this.currency = deposit.getCurrency();
|
||||
this.depositAmount = deposit.getAmount();
|
||||
this.interestRate = interestRate;
|
||||
this.tenureInMonths = termInMonths;
|
||||
this.preClosureInterestRate = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
this.deleted = true;
|
||||
}
|
||||
|
||||
public void update(final DepositAccountCommand command) {
|
||||
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package org.mifosng.platform.saving.domain;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
public interface DepositAccountRepository extends
|
||||
JpaRepository<DepositAccount, Long>,
|
||||
JpaSpecificationExecutor<DepositAccount> {
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package org.mifosng.platform.savingproduct.service;
|
||||
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.client.domain.Client;
|
||||
import org.mifosng.platform.client.domain.ClientRepository;
|
||||
import org.mifosng.platform.currency.domain.MonetaryCurrency;
|
||||
import org.mifosng.platform.currency.domain.Money;
|
||||
import org.mifosng.platform.exceptions.ClientNotFoundException;
|
||||
import org.mifosng.platform.saving.domain.DepositAccount;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* An assembler for turning {@link DepositAccountCommand} into {@link DepositAccount}'s.
|
||||
*/
|
||||
@Service
|
||||
public class DepositAccountAssembler {
|
||||
|
||||
private final ClientRepository clientRepository;
|
||||
|
||||
@Autowired
|
||||
public DepositAccountAssembler(final ClientRepository clientRepository) {
|
||||
this.clientRepository = clientRepository;
|
||||
}
|
||||
|
||||
public DepositAccount assembleFrom(final DepositAccountCommand command) {
|
||||
|
||||
Client client = this.clientRepository.findOne(command.getClientId());
|
||||
if (client == null || client.isDeleted()) {
|
||||
throw new ClientNotFoundException(command.getClientId());
|
||||
}
|
||||
|
||||
MonetaryCurrency currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimal());
|
||||
Money deposit = Money.of(currency, command.getDepositAmount());
|
||||
|
||||
return new DepositAccount(client, command.getExternalId(), deposit, command.getInterestRate(), command.getTermInMonths());
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package org.mifosng.platform.savingproduct.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosng.platform.DataValidatorBuilder;
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.api.data.ApiParameterError;
|
||||
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
|
||||
|
||||
public class DepositAccountCommandValidator {
|
||||
|
||||
private final DepositAccountCommand command;
|
||||
|
||||
public DepositAccountCommandValidator(final DepositAccountCommand command) {
|
||||
this.command=command;
|
||||
}
|
||||
|
||||
public void validateForUpdate() {
|
||||
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.account");
|
||||
|
||||
baseDataValidator.reset().parameter("id").value(command.getId()).notNull();
|
||||
baseDataValidator.reset().parameter("clientId").value(command.getClientId()).ignoreIfNull().notNull();
|
||||
baseDataValidator.reset().parameter("productId").value(command.getProductId()).ignoreIfNull().notNull();
|
||||
baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100);
|
||||
|
||||
baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).ignoreIfNull().notNull().inMinMaxRange(0, 6);
|
||||
baseDataValidator.reset().parameter("depositAmount").value(command.getDepositAmount()).ignoreIfNull().notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("interestRate").value(command.getInterestRate()).ignoreIfNull().notNull().zeroOrPositiveAmount();
|
||||
baseDataValidator.reset().parameter("termInMonths").value(command.getTermInMonths()).ignoreIfNull().notNull().integerGreaterThanZero();
|
||||
|
||||
baseDataValidator.reset().anyOfNotNull(
|
||||
command.getClientId(), command.getProductId(), command.getExternalId(),
|
||||
command.getCurrencyCode(),command.getDigitsAfterDecimal(),
|
||||
command.getDepositAmount(), command.getInterestRate(),command.getTermInMonths());
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) {
|
||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateForCreate() {
|
||||
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.account");
|
||||
|
||||
baseDataValidator.reset().parameter("clientId").value(command.getClientId()).notNull();
|
||||
baseDataValidator.reset().parameter("productId").value(command.getProductId()).notNull();
|
||||
baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100);
|
||||
|
||||
baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank();
|
||||
baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).notNull().inMinMaxRange(0, 6);
|
||||
baseDataValidator.reset().parameter("depositAmount").value(command.getDepositAmount()).notNull().zeroOrPositiveAmount();
|
||||
baseDataValidator.reset().parameter("interestRate").value(command.getInterestRate()).notNull().zeroOrPositiveAmount();
|
||||
baseDataValidator.reset().parameter("termInMonths").value(command.getTermInMonths()).notNull().integerGreaterThanZero();
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) {
|
||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package org.mifosng.platform.savingproduct.service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosng.platform.api.data.DepositAccountData;
|
||||
|
||||
public interface DepositAccountReadPlatformService {
|
||||
|
||||
Collection<DepositAccountData> retrieveAllDepositAccounts();
|
||||
|
||||
DepositAccountData retrieveDepositAccount(Long accountId);
|
||||
|
||||
DepositAccountData retrieveNewDepositAccountDetails();
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
package org.mifosng.platform.savingproduct.service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.mifosng.platform.api.data.CurrencyData;
|
||||
import org.mifosng.platform.api.data.DepositAccountData;
|
||||
import org.mifosng.platform.exceptions.LoanProductNotFoundException;
|
||||
import org.mifosng.platform.infrastructure.JdbcSupport;
|
||||
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class DepositAccountReadPlatformServiceImpl implements DepositAccountReadPlatformService {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public DepositAccountReadPlatformServiceImpl(final PlatformSecurityContext context,final TenantAwareRoutingDataSource dataSource) {
|
||||
this.context=context;
|
||||
jdbcTemplate=new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<DepositAccountData> retrieveAllDepositAccounts() {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
DepositAccountMapper mapper = new DepositAccountMapper();
|
||||
|
||||
String sql = "select " + mapper.schema() + " where da.is_deleted=0";
|
||||
|
||||
return this.jdbcTemplate.query(sql,mapper, new Object[]{});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public DepositAccountData retrieveDepositAccount(final Long accountId) {
|
||||
try{
|
||||
DepositAccountMapper mapper = new DepositAccountMapper();
|
||||
|
||||
String sql = "select " + mapper.schema()
|
||||
+ " where da.id = ? and da.is_deleted=0";
|
||||
|
||||
DepositAccountData productData = this.jdbcTemplate.queryForObject(sql, mapper, new Object[] { accountId });
|
||||
|
||||
return productData;
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new LoanProductNotFoundException(accountId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DepositAccountData retrieveNewDepositAccountDetails() {
|
||||
|
||||
DepositAccountData productData = new DepositAccountData();
|
||||
|
||||
return productData;
|
||||
}
|
||||
|
||||
private static final class DepositAccountMapper implements RowMapper<DepositAccountData> {
|
||||
|
||||
public String schema() {
|
||||
return "da.id as id, da.client_id as clientId, da.product_id as productId,"
|
||||
+ " da.currency_code as currencyCode, da.currency_digits as currencyDigits, "
|
||||
+ " da.deposit_amount as depositAmount, "
|
||||
+ " da.maturity_interest_rate as interestRate, "
|
||||
+ " da.created_date as createdon, da.lastmodified_date as modifiedon, "
|
||||
+ " c.firstname as firstname, c.lastname as lastname, "
|
||||
+ " curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, curr.display_symbol as currencyDisplaySymbol"
|
||||
+ " from portfolio_deposit_account da join ref_currency curr on curr.code = da.currency_code join portfolio_client c on c.id = da.client_id";
|
||||
}
|
||||
|
||||
@Override
|
||||
public DepositAccountData mapRow(ResultSet rs, int rowNum)
|
||||
throws SQLException {
|
||||
|
||||
Long id = rs.getLong("id");
|
||||
Long clientId = rs.getLong("clientId");
|
||||
String clientName = rs.getString("firstname") + " " + rs.getString("lastname");
|
||||
Long productId = rs.getLong("productId");
|
||||
String productName = "";
|
||||
|
||||
String currencyCode = rs.getString("currencyCode");
|
||||
String currencyName = rs.getString("currencyName");
|
||||
String currencyNameCode = rs.getString("currencyNameCode");
|
||||
String currencyDisplaySymbol = rs.getString("currencyDisplaySymbol");
|
||||
Integer currencyDigits = JdbcSupport.getInteger(rs,"currencyDigits");
|
||||
CurrencyData currencyData = new CurrencyData(currencyCode,currencyName, currencyDigits, currencyDisplaySymbol,currencyNameCode);
|
||||
|
||||
BigDecimal depositAmount = rs.getBigDecimal("depositAmount");
|
||||
BigDecimal interestRate = rs.getBigDecimal("interestRate");
|
||||
|
||||
DateTime createdOn = JdbcSupport.getDateTime(rs, "createdon");
|
||||
DateTime lastModifedOn = JdbcSupport.getDateTime(rs, "modifiedon");
|
||||
|
||||
return new DepositAccountData(createdOn, lastModifedOn, id, clientId, clientName, productId, productName, currencyData, depositAmount, interestRate);
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package org.mifosng.platform.savingproduct.service;
|
||||
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
public interface DepositAccountWritePlatformService {
|
||||
|
||||
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')")
|
||||
EntityIdentifier createDepositAccount(DepositAccountCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')")
|
||||
EntityIdentifier updateDepositAccount(DepositAccountCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')")
|
||||
EntityIdentifier deleteDepositAccount(Long productId);
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package org.mifosng.platform.savingproduct.service;
|
||||
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||
import org.mifosng.platform.exceptions.DepositAccountNotFoundException;
|
||||
import org.mifosng.platform.exceptions.ProductNotFoundException;
|
||||
import org.mifosng.platform.saving.domain.DepositAccount;
|
||||
import org.mifosng.platform.saving.domain.DepositAccountRepository;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements DepositAccountWritePlatformService {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final DepositAccountRepository depositAccountRepository;
|
||||
private final DepositAccountAssembler depositAccountAssembler;
|
||||
|
||||
@Autowired
|
||||
public DepositAccountWritePlatformServiceJpaRepositoryImpl(
|
||||
final PlatformSecurityContext context,
|
||||
final DepositAccountRepository depositAccountRepository,
|
||||
final DepositAccountAssembler depositAccountAssembler) {
|
||||
|
||||
this.context=context;
|
||||
this.depositAccountRepository = depositAccountRepository;
|
||||
this.depositAccountAssembler = depositAccountAssembler;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier createDepositAccount(final DepositAccountCommand command) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
DepositAccountCommandValidator validator = new DepositAccountCommandValidator(command);
|
||||
validator.validateForCreate();
|
||||
|
||||
final DepositAccount account = this.depositAccountAssembler.assembleFrom(command);
|
||||
this.depositAccountRepository.save(account);
|
||||
|
||||
return new EntityIdentifier(account.getId());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier updateDepositAccount(final DepositAccountCommand command) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
DepositAccountCommandValidator validator = new DepositAccountCommandValidator(command);
|
||||
validator.validateForUpdate();
|
||||
|
||||
final DepositAccount account = this.depositAccountAssembler.assembleFrom(command);
|
||||
if (account == null || account.isDeleted()) {
|
||||
throw new DepositAccountNotFoundException(command.getId());
|
||||
}
|
||||
|
||||
account.update(command);
|
||||
this.depositAccountRepository.save(account);
|
||||
|
||||
return new EntityIdentifier(Long.valueOf(1));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier deleteDepositAccount(final Long accountId) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
DepositAccount account = this.depositAccountRepository.findOne(accountId);
|
||||
if (account==null || account.isDeleted()) {
|
||||
throw new ProductNotFoundException(accountId);
|
||||
}
|
||||
|
||||
account.delete();
|
||||
this.depositAccountRepository.save(account);
|
||||
|
||||
return new EntityIdentifier(accountId);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -26,7 +26,7 @@ public class UserCommandValidator {
|
||||
baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("lastname").value(command.getLastname()).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("email").value(command.getEmail()).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).ignoreIfNull().notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).ignoreIfNull().notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("roles").value(command.getRoles()).ignoreIfNull().arrayNotEmpty();
|
||||
|
||||
baseDataValidator.reset().parameter("password").value(command.getPassword()).ignoreIfNull().notBlank();
|
||||
@@ -51,7 +51,7 @@ public class UserCommandValidator {
|
||||
baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).notBlank();
|
||||
baseDataValidator.reset().parameter("lastname").value(command.getLastname()).notBlank();
|
||||
baseDataValidator.reset().parameter("email").value(command.getEmail()).notBlank();
|
||||
baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).notNull().greaterThanZero();
|
||||
baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("roles").value(command.getRoles()).arrayNotEmpty();
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user