more api doc updates and make available LoanProductLookup to loan template

This commit is contained in:
John Woodlock
2012-05-31 13:27:59 +10:00
parent 803db98668
commit b491d53f10
9 changed files with 642 additions and 677 deletions
+380 -554
View File
File diff suppressed because it is too large Load Diff
+5 -12
View File
@@ -8,24 +8,16 @@ recreate()
Lost permissions again... restore fixed it up... must be some prob with permissions/roles maintenance Lost permissions again... restore fixed it up... must be some prob with permissions/roles maintenance
also, maybe I should be using a user that has everything but role admin. also, maybe I should be using a user that has everything but role admin.
users - delete still falls over if user doesn't exist. DOING
Loan Products
List/Retrieve - should show textual values of enums? DOING
Create - principal is later called principalMoney , also consistency between other loan fields and loan product fields with Type on them DOING
clients - parentid = id or id 1 has parentId not null DOING
list clients notes - noteType needs a 'text'
createdOn & updatedOn values... do they need reformatting?
are they ord
updating client note - ignores clientId anyhow! so is it really a notes resource? list clients notes - noteType needs a 'text'TODO
createdOn & updatedOn values... do they need reformatting?TODO
updating client note - ignores clientId anyhow! so is it really a notes resource? TODO
loan template loan template
Formatted field still there Formatted field still there
Type fields rename and with associated text?
allowedProduct should maybe just be id & name
which fields have defaults as not all on NewLoanWorkflowStepOneData dto seem to be default.
loan retrieve loan retrieve
break up data into categories.. e.g. break up data into categories.. e.g.
@@ -43,6 +35,7 @@ loanRepayments
Additional Fields Additional Fields
put right message for parameter not recognized etc.(plus tht 9 other jpwwrongmsg items) put right message for parameter not recognized etc.(plus tht 9 other jpwwrongmsg items)
should be able to get clients by branch as well (but not for now)
@@ -32,7 +32,7 @@ import org.springframework.stereotype.Component;
@Scope("singleton") @Scope("singleton")
public class LoanProductApiResource { public class LoanProductApiResource {
private String defaultFieldList = "principal,inArrearsTolerance,numberOfRepayments,repaymentEvery,interestRatePerPeriod,annualInterestRate,repaymentFrequencyType,interestRateFrequencyType,amortizationType,interestType,interestCalculationPeriodType"; private String defaultFieldList = "principal,inArrearsTolerance,interestRatePerPeriod,annualInterestRate,repaymentFrequencyType,interestRateFrequencyType,amortizationType,interestType,interestCalculationPeriodType";
private String allowedFieldList = "currencyOptions,amortizationTypeOptions,interestTypeOptions,interestCalculationPeriodTypeOptions,repaymentFrequencyTypeOptions,interestRateFrequencyTypeOptions"; private String allowedFieldList = "currencyOptions,amortizationTypeOptions,interestTypeOptions,interestCalculationPeriodTypeOptions,repaymentFrequencyTypeOptions,interestRateFrequencyTypeOptions";
private String filterName = "myFilter"; private String filterName = "myFilter";
@@ -67,7 +67,7 @@ public class ApiGlobalErrorResponse {
public static ApiGlobalErrorResponse domainRuleViolation(String globalisationMessageCode, String defaultUserMessage, Object... defaultUserMessageArgs) { public static ApiGlobalErrorResponse domainRuleViolation(String globalisationMessageCode, String defaultUserMessage, Object... defaultUserMessageArgs) {
ApiGlobalErrorResponse globalErrorResponse = new ApiGlobalErrorResponse(); ApiGlobalErrorResponse globalErrorResponse = new ApiGlobalErrorResponse();
globalErrorResponse.setHttpStatusCode("403"); globalErrorResponse.setHttpStatusCode("403");
globalErrorResponse.setDeveloperMessage("Request was understoon but caused a domain rule violation."); globalErrorResponse.setDeveloperMessage("Request was understood but caused a domain rule violation.");
globalErrorResponse.setDeveloperDocLink("https://github.com/keithwoodlock/mifosx/wiki/HTTP-API-Error-codes"); globalErrorResponse.setDeveloperDocLink("https://github.com/keithwoodlock/mifosx/wiki/HTTP-API-Error-codes");
globalErrorResponse.setUserMessageGlobalisationCode("validation.msg.domain.rule.violation"); globalErrorResponse.setUserMessageGlobalisationCode("validation.msg.domain.rule.violation");
globalErrorResponse.setDefaultUserMessage("Errors contain reason for domain rule violation."); globalErrorResponse.setDefaultUserMessage("Errors contain reason for domain rule violation.");
@@ -0,0 +1,34 @@
package org.mifosng.platform.api.data;
import java.io.Serializable;
public class LoanProductLookup implements Serializable {
private Long id;
private String name;
public LoanProductLookup() {
//
}
public LoanProductLookup(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@@ -20,7 +20,7 @@ public class NewLoanData implements Serializable {
private Long productId; private Long productId;
private String productName; private String productName;
private List<LoanProductData> allowedProducts = new ArrayList<LoanProductData>(); private List<LoanProductLookup> allowedProducts = new ArrayList<LoanProductLookup>();
// extra // extra
private String dateFormat; private String dateFormat;
@@ -93,11 +93,11 @@ public class NewLoanData implements Serializable {
this.productName = productName; this.productName = productName;
} }
public List<LoanProductData> getAllowedProducts() { public List<LoanProductLookup> getAllowedProducts() {
return allowedProducts; return allowedProducts;
} }
public void setAllowedProducts(List<LoanProductData> allowedProducts) { public void setAllowedProducts(List<LoanProductLookup> allowedProducts) {
this.allowedProducts = allowedProducts; this.allowedProducts = allowedProducts;
} }
@@ -137,7 +137,8 @@ public class NewLoanData implements Serializable {
return repaymentsStartingFromDate; return repaymentsStartingFromDate;
} }
public void setRepaymentsStartingFromDate(LocalDate repaymentsStartingFromDate) { public void setRepaymentsStartingFromDate(
LocalDate repaymentsStartingFromDate) {
this.repaymentsStartingFromDate = repaymentsStartingFromDate; this.repaymentsStartingFromDate = repaymentsStartingFromDate;
} }
@@ -145,7 +146,8 @@ public class NewLoanData implements Serializable {
return interestCalculatedFromDate; return interestCalculatedFromDate;
} }
public void setInterestCalculatedFromDate(LocalDate interestCalculatedFromDate) { public void setInterestCalculatedFromDate(
LocalDate interestCalculatedFromDate) {
this.interestCalculatedFromDate = interestCalculatedFromDate; this.interestCalculatedFromDate = interestCalculatedFromDate;
} }
@@ -14,6 +14,7 @@ import org.mifosng.data.LoanRepaymentData;
import org.mifosng.data.MoneyData; import org.mifosng.data.MoneyData;
import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.ClientData;
import org.mifosng.platform.api.data.LoanProductData; import org.mifosng.platform.api.data.LoanProductData;
import org.mifosng.platform.api.data.LoanProductLookup;
import org.mifosng.platform.api.data.NewLoanData; import org.mifosng.platform.api.data.NewLoanData;
import org.mifosng.platform.client.service.ClientReadPlatformService; import org.mifosng.platform.client.service.ClientReadPlatformService;
import org.mifosng.platform.currency.domain.ApplicationCurrency; import org.mifosng.platform.currency.domain.ApplicationCurrency;
@@ -44,9 +45,13 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
private final LoanTransactionRepository loanTransactionRepository; private final LoanTransactionRepository loanTransactionRepository;
@Autowired @Autowired
public LoanReadPlatformServiceImpl(final PlatformSecurityContext context, public LoanReadPlatformServiceImpl(
final LoanRepository loanRepository, final LoanTransactionRepository loanTransactionRepository, final ApplicationCurrencyRepository applicationCurrencyRepository, final PlatformSecurityContext context,
final LoanProductReadPlatformService loanProductReadPlatformService, final ClientReadPlatformService clientReadPlatformService) { final LoanRepository loanRepository,
final LoanTransactionRepository loanTransactionRepository,
final ApplicationCurrencyRepository applicationCurrencyRepository,
final LoanProductReadPlatformService loanProductReadPlatformService,
final ClientReadPlatformService clientReadPlatformService) {
this.context = context; this.context = context;
this.loanRepository = loanRepository; this.loanRepository = loanRepository;
this.loanTransactionRepository = loanTransactionRepository; this.loanTransactionRepository = loanTransactionRepository;
@@ -62,13 +67,16 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
// need of loan information. // need of loan information.
AppUser currentUser = context.authenticatedUser(); AppUser currentUser = context.authenticatedUser();
Loan loan = this.loanRepository.findOne(loansThatMatch(currentUser.getOrganisation(), loanId)); Loan loan = this.loanRepository.findOne(loansThatMatch(
currentUser.getOrganisation(), loanId));
if (loan == null) { if (loan == null) {
throw new LoanNotFoundException(loanId); throw new LoanNotFoundException(loanId);
} }
final String currencyCode = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyCode(); final String currencyCode = loan.getLoanRepaymentScheduleDetail()
ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode); .getPrincipal().getCurrencyCode();
ApplicationCurrency currency = this.applicationCurrencyRepository
.findOneByCode(currencyCode);
if (currency == null) { if (currency == null) {
throw new CurrencyNotFoundException(currencyCode); throw new CurrencyNotFoundException(currencyCode);
} }
@@ -168,20 +176,26 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
} }
@Override @Override
public NewLoanData retrieveClientAndProductDetails(final Long clientId, final Long productId) { public NewLoanData retrieveClientAndProductDetails(final Long clientId,
final Long productId) {
AppUser currentUser = context.authenticatedUser(); AppUser currentUser = context.authenticatedUser();
NewLoanData workflowData = new NewLoanData(); NewLoanData workflowData = new NewLoanData();
workflowData.setOrganisationId(currentUser.getOrganisation().getId()); workflowData.setOrganisationId(currentUser.getOrganisation().getId());
workflowData.setOrganisationName(currentUser.getOrganisation().getName()); workflowData.setOrganisationName(currentUser.getOrganisation()
.getName());
Collection<LoanProductData> loanProducts = this.loanProductReadPlatformService.retrieveAllLoanProducts(); Collection<LoanProductLookup> loanProducts = this.loanProductReadPlatformService
workflowData.setAllowedProducts(new ArrayList<LoanProductData>(loanProducts)); .retrieveAllLoanProductsForLookup();
workflowData.setAllowedProducts(new ArrayList<LoanProductLookup>(
loanProducts));
if (loanProducts.size() == 1) { if (loanProducts.size() == 1) {
Long allowedProductId = workflowData.getAllowedProducts().get(0).getId(); Long allowedProductId = workflowData.getAllowedProducts().get(0)
LoanProductData selectedProduct = this.loanProductReadPlatformService.retrieveLoanProduct(allowedProductId); .getId();
LoanProductData selectedProduct = this.loanProductReadPlatformService
.retrieveLoanProduct(allowedProductId);
if (selectedProduct == null) { if (selectedProduct == null) {
throw new LoanProductNotFoundException(allowedProductId); throw new LoanProductNotFoundException(allowedProductId);
} }
@@ -190,7 +204,8 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
workflowData.setProductName(selectedProduct.getName()); workflowData.setProductName(selectedProduct.getName());
workflowData.setSelectedProduct(selectedProduct); workflowData.setSelectedProduct(selectedProduct);
} else { } else {
LoanProductData selectedProduct = findLoanProductById(loanProducts, productId); LoanProductData selectedProduct = findLoanProductById(loanProducts,
productId);
if (selectedProduct == null) { if (selectedProduct == null) {
throw new LoanProductNotFoundException(productId); throw new LoanProductNotFoundException(productId);
} }
@@ -199,7 +214,8 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
workflowData.setSelectedProduct(selectedProduct); workflowData.setSelectedProduct(selectedProduct);
} }
ClientData clientAccount = this.clientReadPlatformService.retrieveIndividualClient(clientId); ClientData clientAccount = this.clientReadPlatformService
.retrieveIndividualClient(clientId);
workflowData.setClientId(clientAccount.getId()); workflowData.setClientId(clientAccount.getId());
workflowData.setClientName(clientAccount.getDisplayName()); workflowData.setClientName(clientAccount.getDisplayName());
@@ -207,20 +223,19 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
} }
private LoanProductData findLoanProductById( private LoanProductData findLoanProductById(
Collection<LoanProductData> loanProducts, Long productId) { Collection<LoanProductLookup> loanProducts, Long productId) {
LoanProductData match = this.loanProductReadPlatformService LoanProductData match = this.loanProductReadPlatformService
.retrieveNewLoanProductDetails(); .retrieveNewLoanProductDetails();
for (LoanProductData loanProductData : loanProducts) { for (LoanProductLookup loanProductLookup : loanProducts) {
if (loanProductData.getId().equals(productId)) { if (loanProductLookup.getId().equals(productId)) {
match = this.loanProductReadPlatformService match = this.loanProductReadPlatformService
.retrieveLoanProduct(loanProductData.getId()); .retrieveLoanProduct(loanProductLookup.getId());
break; break;
} }
} }
return match; return match;
} }
@Override @Override
public LoanRepaymentData retrieveNewLoanRepaymentDetails(Long loanId) { public LoanRepaymentData retrieveNewLoanRepaymentDetails(Long loanId) {
@@ -228,13 +243,16 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
// TODO - OPTIMIZE - write simple sql query to fetch back date of // TODO - OPTIMIZE - write simple sql query to fetch back date of
// possible next transaction date. // possible next transaction date.
Loan loan = this.loanRepository.findOne(loansThatMatch(currentUser.getOrganisation(), loanId)); Loan loan = this.loanRepository.findOne(loansThatMatch(
currentUser.getOrganisation(), loanId));
if (loan == null) { if (loan == null) {
throw new LoanNotFoundException(loanId); throw new LoanNotFoundException(loanId);
} }
final String currencyCode = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyCode(); final String currencyCode = loan.getLoanRepaymentScheduleDetail()
ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode); .getPrincipal().getCurrencyCode();
ApplicationCurrency currency = this.applicationCurrencyRepository
.findOneByCode(currencyCode);
if (currency == null) { if (currency == null) {
throw new CurrencyNotFoundException(currencyCode); throw new CurrencyNotFoundException(currencyCode);
} }
@@ -243,9 +261,11 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
currency.getName(), currency.getDecimalPlaces(), currency.getName(), currency.getDecimalPlaces(),
currency.getDisplaySymbol(), currency.getNameCode()); currency.getDisplaySymbol(), currency.getNameCode());
LocalDate earliestUnpaidInstallmentDate = loan.possibleNextRepaymentDate(); LocalDate earliestUnpaidInstallmentDate = loan
.possibleNextRepaymentDate();
Money possibleNextRepaymentAmount = loan.possibleNextRepaymentAmount(); Money possibleNextRepaymentAmount = loan.possibleNextRepaymentAmount();
MoneyData possibleNextRepayment = MoneyData.of(currencyData, possibleNextRepaymentAmount.getAmount()); MoneyData possibleNextRepayment = MoneyData.of(currencyData,
possibleNextRepaymentAmount.getAmount());
LoanRepaymentData newRepaymentDetails = new LoanRepaymentData(); LoanRepaymentData newRepaymentDetails = new LoanRepaymentData();
newRepaymentDetails.setDate(earliestUnpaidInstallmentDate); newRepaymentDetails.setDate(earliestUnpaidInstallmentDate);
@@ -261,13 +281,16 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
// TODO - OPTIMIZE - write simple sql query to fetch back date of // TODO - OPTIMIZE - write simple sql query to fetch back date of
// possible next transaction date. // possible next transaction date.
Loan loan = this.loanRepository.findOne(loansThatMatch(currentUser.getOrganisation(), loanId)); Loan loan = this.loanRepository.findOne(loansThatMatch(
currentUser.getOrganisation(), loanId));
if (loan == null) { if (loan == null) {
throw new LoanNotFoundException(loanId); throw new LoanNotFoundException(loanId);
} }
final String currencyCode = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyCode(); final String currencyCode = loan.getLoanRepaymentScheduleDetail()
ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode); .getPrincipal().getCurrencyCode();
ApplicationCurrency currency = this.applicationCurrencyRepository
.findOneByCode(currencyCode);
if (currency == null) { if (currency == null) {
throw new CurrencyNotFoundException(currencyCode); throw new CurrencyNotFoundException(currencyCode);
} }
@@ -288,22 +311,28 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
} }
@Override @Override
public LoanRepaymentData retrieveLoanRepaymentDetails(Long loanId, Long transactionId) { public LoanRepaymentData retrieveLoanRepaymentDetails(Long loanId,
Long transactionId) {
AppUser currentUser = context.authenticatedUser(); AppUser currentUser = context.authenticatedUser();
Loan loan = this.loanRepository.findOne(loansThatMatch(currentUser.getOrganisation(), loanId)); Loan loan = this.loanRepository.findOne(loansThatMatch(
currentUser.getOrganisation(), loanId));
if (loan == null) { if (loan == null) {
throw new LoanNotFoundException(loanId); throw new LoanNotFoundException(loanId);
} }
final String currencyCode = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyCode(); final String currencyCode = loan.getLoanRepaymentScheduleDetail()
ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode); .getPrincipal().getCurrencyCode();
ApplicationCurrency currency = this.applicationCurrencyRepository
.findOneByCode(currencyCode);
if (currency == null) { if (currency == null) {
throw new CurrencyNotFoundException(currencyCode); throw new CurrencyNotFoundException(currencyCode);
} }
LoanTransaction transaction = this.loanTransactionRepository.findOne(loanTransactionsThatMatch(currentUser.getOrganisation(), transactionId)); LoanTransaction transaction = this.loanTransactionRepository
.findOne(loanTransactionsThatMatch(
currentUser.getOrganisation(), transactionId));
if (transaction == null) { if (transaction == null) {
throw new LoanTransactionNotFoundException(transactionId); throw new LoanTransactionNotFoundException(transactionId);
} }
@@ -3,11 +3,14 @@ package org.mifosng.platform.loanproduct.service;
import java.util.Collection; import java.util.Collection;
import org.mifosng.platform.api.data.LoanProductData; import org.mifosng.platform.api.data.LoanProductData;
import org.mifosng.platform.api.data.LoanProductLookup;
public interface LoanProductReadPlatformService { public interface LoanProductReadPlatformService {
Collection<LoanProductData> retrieveAllLoanProducts(); Collection<LoanProductData> retrieveAllLoanProducts();
Collection<LoanProductLookup> retrieveAllLoanProductsForLookup();
LoanProductData retrieveLoanProduct(Long productId); LoanProductData retrieveLoanProduct(Long productId);
LoanProductData retrieveNewLoanProductDetails(); LoanProductData retrieveNewLoanProductDetails();
@@ -13,6 +13,7 @@ import org.mifosng.data.CurrencyData;
import org.mifosng.data.MoneyData; import org.mifosng.data.MoneyData;
import org.mifosng.platform.api.data.EnumOptionData; import org.mifosng.platform.api.data.EnumOptionData;
import org.mifosng.platform.api.data.LoanProductData; import org.mifosng.platform.api.data.LoanProductData;
import org.mifosng.platform.api.data.LoanProductLookup;
import org.mifosng.platform.currency.service.CurrencyReadPlatformService; import org.mifosng.platform.currency.service.CurrencyReadPlatformService;
import org.mifosng.platform.exceptions.LoanProductNotFoundException; import org.mifosng.platform.exceptions.LoanProductNotFoundException;
import org.mifosng.platform.infrastructure.JdbcSupport; import org.mifosng.platform.infrastructure.JdbcSupport;
@@ -29,7 +30,8 @@ import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatformService { public class LoanProductReadPlatformServiceImpl implements
LoanProductReadPlatformService {
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final CurrencyReadPlatformService currencyReadPlatformService; private final CurrencyReadPlatformService currencyReadPlatformService;
@@ -37,7 +39,9 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
private final LoanDropdownReadPlatformService dropdownReadPlatformService; private final LoanDropdownReadPlatformService dropdownReadPlatformService;
@Autowired @Autowired
public LoanProductReadPlatformServiceImpl(final PlatformSecurityContext context, final CurrencyReadPlatformService currencyReadPlatformService, public LoanProductReadPlatformServiceImpl(
final PlatformSecurityContext context,
final CurrencyReadPlatformService currencyReadPlatformService,
final LoanDropdownReadPlatformService dropdownReadPlatformService, final LoanDropdownReadPlatformService dropdownReadPlatformService,
final DataSource dataSource) { final DataSource dataSource) {
this.context = context; this.context = context;
@@ -50,12 +54,15 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
public LoanProductData retrieveLoanProduct(final Long loanProductId) { public LoanProductData retrieveLoanProduct(final Long loanProductId) {
try { try {
List<CurrencyData> allowedCurrencies = currencyReadPlatformService.retrieveAllPlatformCurrencies(); List<CurrencyData> allowedCurrencies = currencyReadPlatformService
.retrieveAllPlatformCurrencies();
LoanProductMapper rm = new LoanProductMapper(allowedCurrencies); LoanProductMapper rm = new LoanProductMapper(allowedCurrencies);
String sql = "select " + rm.loanProductSchema() + " where lp.id = ?"; String sql = "select " + rm.loanProductSchema()
+ " where lp.id = ?";
LoanProductData productData = this.jdbcTemplate.queryForObject(sql, rm, new Object[] { loanProductId }); LoanProductData productData = this.jdbcTemplate.queryForObject(sql,
rm, new Object[] { loanProductId });
populateProductDataWithDropdownOptions(productData); populateProductDataWithDropdownOptions(productData);
@@ -69,14 +76,31 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
public Collection<LoanProductData> retrieveAllLoanProducts() { public Collection<LoanProductData> retrieveAllLoanProducts() {
AppUser currentUser = this.context.authenticatedUser(); AppUser currentUser = this.context.authenticatedUser();
// TODO - include currency read in the sql
List<CurrencyData> allowedCurrencies = currencyReadPlatformService.retrieveAllPlatformCurrencies(); List<CurrencyData> allowedCurrencies = currencyReadPlatformService
.retrieveAllPlatformCurrencies();
LoanProductMapper rm = new LoanProductMapper(allowedCurrencies); LoanProductMapper rm = new LoanProductMapper(allowedCurrencies);
String sql = "select " + rm.loanProductSchema() + " where lp.org_id = ?"; String sql = "select " + rm.loanProductSchema()
+ " where lp.org_id = ?";
return this.jdbcTemplate.query(sql, rm, new Object[] { currentUser.getOrganisation().getId() }); return this.jdbcTemplate.query(sql, rm, new Object[] { currentUser
.getOrganisation().getId() });
}
@Override
public Collection<LoanProductLookup> retrieveAllLoanProductsForLookup() {
AppUser currentUser = this.context.authenticatedUser();
LoanProductLookupMapper rm = new LoanProductLookupMapper();
String sql = "select " + rm.loanProductLookupSchema()
+ " where lp.org_id = ?";
return this.jdbcTemplate.query(sql, rm, new Object[] { currentUser
.getOrganisation().getId() });
} }
@Override @Override
@@ -84,11 +108,17 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
LoanProductData productData = new LoanProductData(); LoanProductData productData = new LoanProductData();
productData.setAmortizationType(LoanEnumerations.amortizationType(AmortizationMethod.EQUAL_INSTALLMENTS)); productData.setAmortizationType(LoanEnumerations
productData.setInterestType(LoanEnumerations.interestType(InterestMethod.DECLINING_BALANCE)); .amortizationType(AmortizationMethod.EQUAL_INSTALLMENTS));
productData.setRepaymentFrequencyType(LoanEnumerations.repaymentFrequencyType(PeriodFrequencyType.MONTHS)); productData.setInterestType(LoanEnumerations
productData.setInterestRateFrequencyType(LoanEnumerations.interestRateFrequencyType(PeriodFrequencyType.MONTHS)); .interestType(InterestMethod.DECLINING_BALANCE));
productData.setInterestCalculationPeriodType(LoanEnumerations.interestCalculationPeriodType(InterestCalculationPeriodMethod.SAME_AS_REPAYMENT_PERIOD)); productData.setRepaymentFrequencyType(LoanEnumerations
.repaymentFrequencyType(PeriodFrequencyType.MONTHS));
productData.setInterestRateFrequencyType(LoanEnumerations
.interestRateFrequencyType(PeriodFrequencyType.MONTHS));
productData
.setInterestCalculationPeriodType(LoanEnumerations
.interestCalculationPeriodType(InterestCalculationPeriodMethod.SAME_AS_REPAYMENT_PERIOD));
populateProductDataWithDropdownOptions(productData); populateProductDataWithDropdownOptions(productData);
@@ -102,7 +132,8 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
return productData; return productData;
} }
private static final class LoanProductMapper implements RowMapper<LoanProductData> { private static final class LoanProductMapper implements
RowMapper<LoanProductData> {
private final List<CurrencyData> allowedCurrencies; private final List<CurrencyData> allowedCurrencies;
@@ -130,9 +161,11 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
String description = rs.getString("description"); String description = rs.getString("description");
String currencyCode = rs.getString("currencyCode"); String currencyCode = rs.getString("currencyCode");
Integer currencyDigits = JdbcSupport.getInteger(rs, "currencyDigits"); Integer currencyDigits = JdbcSupport.getInteger(rs,
"currencyDigits");
CurrencyData currencyData = findCurrencyByCode(currencyCode, allowedCurrencies); CurrencyData currencyData = findCurrencyByCode(currencyCode,
allowedCurrencies);
if (currencyData != null) { if (currencyData != null) {
currencyData.setDecimalPlaces(currencyDigits); currencyData.setDecimalPlaces(currencyDigits);
} }
@@ -143,35 +176,51 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
MoneyData principalMoney = MoneyData.of(currencyData, principal); MoneyData principalMoney = MoneyData.of(currencyData, principal);
MoneyData toleranceMoney = MoneyData.of(currencyData, tolerance); MoneyData toleranceMoney = MoneyData.of(currencyData, tolerance);
Integer numberOfRepayments = JdbcSupport.getInteger(rs, "numberOfRepayments"); Integer numberOfRepayments = JdbcSupport.getInteger(rs,
"numberOfRepayments");
Integer repaymentEvery = JdbcSupport.getInteger(rs, "repaidEvery"); Integer repaymentEvery = JdbcSupport.getInteger(rs, "repaidEvery");
BigDecimal interestRatePerPeriod = rs.getBigDecimal("interestRatePerPeriod"); BigDecimal interestRatePerPeriod = rs
BigDecimal annualInterestRate = rs.getBigDecimal("annualInterestRate"); .getBigDecimal("interestRatePerPeriod");
BigDecimal annualInterestRate = rs
.getBigDecimal("annualInterestRate");
int repaymentFrequencyTypeId = JdbcSupport.getInteger(rs, "repaymentPeriodFrequency"); int repaymentFrequencyTypeId = JdbcSupport.getInteger(rs,
EnumOptionData repaymentFrequencyType = LoanEnumerations.repaymentFrequencyType(repaymentFrequencyTypeId); "repaymentPeriodFrequency");
EnumOptionData repaymentFrequencyType = LoanEnumerations
.repaymentFrequencyType(repaymentFrequencyTypeId);
int amortizationTypeId = JdbcSupport.getInteger(rs, "amortizationMethod"); int amortizationTypeId = JdbcSupport.getInteger(rs,
EnumOptionData amortizationType = LoanEnumerations.amortizationType(amortizationTypeId); "amortizationMethod");
EnumOptionData amortizationType = LoanEnumerations
.amortizationType(amortizationTypeId);
int interestRateFrequencyTypeId = JdbcSupport.getInteger(rs, "interestRatePerPeriodFreq"); int interestRateFrequencyTypeId = JdbcSupport.getInteger(rs,
EnumOptionData interestRateFrequencyType = LoanEnumerations.interestRateFrequencyType(interestRateFrequencyTypeId); "interestRatePerPeriodFreq");
EnumOptionData interestRateFrequencyType = LoanEnumerations
.interestRateFrequencyType(interestRateFrequencyTypeId);
int interestTypeId = JdbcSupport.getInteger(rs, "interestMethod"); int interestTypeId = JdbcSupport.getInteger(rs, "interestMethod");
EnumOptionData interestType = LoanEnumerations.interestType(interestTypeId); EnumOptionData interestType = LoanEnumerations
.interestType(interestTypeId);
int interestCalculationPeriodTypeId = JdbcSupport.getInteger(rs, "interestCalculationInPeriodMethod"); int interestCalculationPeriodTypeId = JdbcSupport.getInteger(rs,
EnumOptionData interestCalculationPeriodType = LoanEnumerations.interestCalculationPeriodType(interestCalculationPeriodTypeId); "interestCalculationInPeriodMethod");
EnumOptionData interestCalculationPeriodType = LoanEnumerations
.interestCalculationPeriodType(interestCalculationPeriodTypeId);
DateTime createdOn = JdbcSupport.getDateTime(rs, "createdon"); DateTime createdOn = JdbcSupport.getDateTime(rs, "createdon");
DateTime lastModifedOn = JdbcSupport.getDateTime(rs, "modifiedon"); DateTime lastModifedOn = JdbcSupport.getDateTime(rs, "modifiedon");
return new LoanProductData(createdOn, lastModifedOn, id, name, description, principalMoney, toleranceMoney, return new LoanProductData(createdOn, lastModifedOn, id, name,
numberOfRepayments, repaymentEvery, interestRatePerPeriod, annualInterestRate, description, principalMoney, toleranceMoney,
repaymentFrequencyType, interestRateFrequencyType, amortizationType, interestType, interestCalculationPeriodType); numberOfRepayments, repaymentEvery, interestRatePerPeriod,
annualInterestRate, repaymentFrequencyType,
interestRateFrequencyType, amortizationType, interestType,
interestCalculationPeriodType);
} }
private CurrencyData findCurrencyByCode(String currencyCode, List<CurrencyData> allowedCurrencies) { private CurrencyData findCurrencyByCode(String currencyCode,
List<CurrencyData> allowedCurrencies) {
CurrencyData match = null; CurrencyData match = null;
for (CurrencyData currencyData : allowedCurrencies) { for (CurrencyData currencyData : allowedCurrencies) {
if (currencyData.getCode().equalsIgnoreCase(currencyCode)) { if (currencyData.getCode().equalsIgnoreCase(currencyCode)) {
@@ -183,21 +232,50 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
} }
} }
private void populateProductDataWithDropdownOptions(LoanProductData productData) { private static final class LoanProductLookupMapper implements
RowMapper<LoanProductLookup> {
List<CurrencyData> currencyOptions = currencyReadPlatformService.retrieveAllowedCurrencies(); public String loanProductLookupSchema() {
List<EnumOptionData> amortizationTypeOptions = dropdownReadPlatformService.retrieveLoanAmortizationTypeOptions(); return "lp.id as id, lp.name as name from portfolio_product_loan lp";
List<EnumOptionData> interestTypeOptions = dropdownReadPlatformService.retrieveLoanInterestTypeOptions(); }
List<EnumOptionData> interestCalculationPeriodTypeOptions = dropdownReadPlatformService.retrieveLoanInterestRateCalculatedInPeriodOptions();
List<EnumOptionData> repaymentFrequencyTypeOptions = dropdownReadPlatformService.retrieveRepaymentFrequencyTypeOptions(); @Override
List<EnumOptionData> interestRateFrequencyTypeOptions = dropdownReadPlatformService.retrieveInterestRateFrequencyTypeOptions(); public LoanProductLookup mapRow(final ResultSet rs, final int rowNum)
throws SQLException {
Long id = rs.getLong("id");
String name = rs.getString("name");
return new LoanProductLookup(id, name);
}
}
private void populateProductDataWithDropdownOptions(
LoanProductData productData) {
List<CurrencyData> currencyOptions = currencyReadPlatformService
.retrieveAllowedCurrencies();
List<EnumOptionData> amortizationTypeOptions = dropdownReadPlatformService
.retrieveLoanAmortizationTypeOptions();
List<EnumOptionData> interestTypeOptions = dropdownReadPlatformService
.retrieveLoanInterestTypeOptions();
List<EnumOptionData> interestCalculationPeriodTypeOptions = dropdownReadPlatformService
.retrieveLoanInterestRateCalculatedInPeriodOptions();
List<EnumOptionData> repaymentFrequencyTypeOptions = dropdownReadPlatformService
.retrieveRepaymentFrequencyTypeOptions();
List<EnumOptionData> interestRateFrequencyTypeOptions = dropdownReadPlatformService
.retrieveInterestRateFrequencyTypeOptions();
productData.setCurrencyOptions(currencyOptions); productData.setCurrencyOptions(currencyOptions);
productData.setAmortizationTypeOptions(amortizationTypeOptions); productData.setAmortizationTypeOptions(amortizationTypeOptions);
productData.setInterestTypeOptions(interestTypeOptions); productData.setInterestTypeOptions(interestTypeOptions);
productData.setInterestCalculationPeriodTypeOptions(interestCalculationPeriodTypeOptions); productData
productData.setRepaymentFrequencyTypeOptions(repaymentFrequencyTypeOptions); .setInterestCalculationPeriodTypeOptions(interestCalculationPeriodTypeOptions);
productData.setInterestRateFrequencyTypeOptions(interestRateFrequencyTypeOptions); productData
.setRepaymentFrequencyTypeOptions(repaymentFrequencyTypeOptions);
productData
.setInterestRateFrequencyTypeOptions(interestRateFrequencyTypeOptions);
} }
} }