From 816d3decf9f5b8aaaadfe5e364f998a8c66caa7f Mon Sep 17 00:00:00 2001 From: John Woodlock Date: Sat, 14 Jul 2012 01:25:37 +1000 Subject: [PATCH] did loanproduct read TODO about joining to currency rather than matching after --- .../LoanProductReadPlatformServiceImpl.java | 63 ++++++++----------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductReadPlatformServiceImpl.java index 4819ad23a..a8da01dc5 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductReadPlatformServiceImpl.java @@ -59,12 +59,7 @@ public class LoanProductReadPlatformServiceImpl implements public LoanProductData retrieveLoanProduct(final Long loanProductId) { try { - List allowedCurrencies = currencyReadPlatformService - .retrieveAllPlatformCurrencies(); - - Collection allFunds = this.fundReadPlatformService.retrieveAllFunds(); - - LoanProductMapper rm = new LoanProductMapper(allowedCurrencies, allFunds); + LoanProductMapper rm = new LoanProductMapper(); String sql = "select " + rm.loanProductSchema() + " where lp.id = ?"; @@ -83,12 +78,8 @@ public class LoanProductReadPlatformServiceImpl implements public Collection retrieveAllLoanProducts() { AppUser currentUser = this.context.authenticatedUser(); - - // TODO - include currency read in the sql - List allowedCurrencies = currencyReadPlatformService.retrieveAllPlatformCurrencies(); - Collection allFunds = this.fundReadPlatformService.retrieveAllFunds(); - LoanProductMapper rm = new LoanProductMapper(allowedCurrencies, allFunds); + LoanProductMapper rm = new LoanProductMapper(); String sql = "select " + rm.loanProductSchema() + " where lp.org_id = ?"; @@ -140,14 +131,13 @@ public class LoanProductReadPlatformServiceImpl implements return productData; } - private static final class LoanProductMapper implements RowMapper { + private static final class LoanProductMapper implements + RowMapper { - private final List allowedCurrencies; - private final Collection allFunds; + // private final List allowedCurrencies; + // private final Collection allFunds; - public LoanProductMapper(List allowedCurrencies, Collection allFunds) { - this.allowedCurrencies = allowedCurrencies; - this.allFunds = allFunds; + public LoanProductMapper() { } public String loanProductSchema() { @@ -157,8 +147,11 @@ public class LoanProductReadPlatformServiceImpl implements + "lp.annual_nominal_interest_rate as annualInterestRate, lp.interest_method_enum as interestMethod, lp.interest_calculated_in_period_enum as interestCalculationInPeriodMethod," + "lp.repay_every as repaidEvery, lp.repayment_period_frequency_enum as repaymentPeriodFrequency, lp.number_of_repayments as numberOfRepayments, " + "lp.amortization_method_enum as amortizationMethod, lp.arrearstolerance_amount as tolerance, " - + "lp.created_date as createdon, lp.lastmodified_date as modifiedon " - + " from portfolio_product_loan lp left join org_fund f on f.id = lp.fund_id"; + + "lp.created_date as createdon, lp.lastmodified_date as modifiedon, " + + "curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, curr.display_symbol as currencyDisplaySymbol " + + " from portfolio_product_loan lp " + + " left join org_fund f on f.id = lp.fund_id" + + " join ref_currency curr on curr.code = lp.currency_code"; } @Override @@ -171,16 +164,18 @@ public class LoanProductReadPlatformServiceImpl implements Long fundId = JdbcSupport.getLong(rs, "fundId"); String fundName = rs.getString("fundName"); - + 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 = findCurrencyByCode(currencyCode, - allowedCurrencies); - if (currencyData != null) { - currencyData.setDecimalPlaces(currencyDigits); - } + CurrencyData currencyData = new CurrencyData(currencyCode, + currencyName, currencyDigits, currencyDisplaySymbol, + currencyNameCode); BigDecimal principal = rs.getBigDecimal("principal"); BigDecimal tolerance = rs.getBigDecimal("tolerance"); @@ -231,16 +226,6 @@ public class LoanProductReadPlatformServiceImpl implements interestCalculationPeriodType, fundId, fundName); } - private CurrencyData findCurrencyByCode(String currencyCode, List allowedCurrencies) { - CurrencyData match = null; - for (CurrencyData currencyData : allowedCurrencies) { - if (currencyData.getCode().equalsIgnoreCase(currencyCode)) { - match = currencyData; - break; - } - } - return match; - } } private static final class LoanProductLookupMapper implements @@ -262,7 +247,8 @@ public class LoanProductReadPlatformServiceImpl implements } - private void populateProductDataWithDropdownOptions(LoanProductData productData) { + private void populateProductDataWithDropdownOptions( + LoanProductData productData) { List currencyOptions = currencyReadPlatformService .retrieveAllowedCurrencies(); @@ -276,8 +262,9 @@ public class LoanProductReadPlatformServiceImpl implements .retrieveRepaymentFrequencyTypeOptions(); List interestRateFrequencyTypeOptions = dropdownReadPlatformService .retrieveInterestRateFrequencyTypeOptions(); - - Collection fundOptions = this.fundReadPlatformService.retrieveAllFunds(); + + Collection fundOptions = this.fundReadPlatformService + .retrieveAllFunds(); productData.setCurrencyOptions(currencyOptions); productData.setAmortizationTypeOptions(amortizationTypeOptions);