private CurrencyData findCurrencyByCode( String currencyCode, List<CurrencyData> allowedCurrencies) { CurrencyData match = null; for (CurrencyData currencyData : allowedCurrencies) { if (currencyData.getCode().equalsIgnoreCase(currencyCode)) { match = currencyData; break; } } return match; }
@Override public LoanProductData mapRow(final ResultSet rs, final int rowNum) throws SQLException { Long id = rs.getLong("id"); String name = rs.getString("name"); String description = rs.getString("description"); String currencyCode = rs.getString("currencyCode"); Integer currencyDigits = JdbcSupport.getInteger(rs, "currencyDigits"); CurrencyData currencyData = findCurrencyByCode(currencyCode, allowedCurrencies); if (currencyData != null) { currencyData.setDecimalPlaces(currencyDigits); } BigDecimal principal = rs.getBigDecimal("principal"); BigDecimal tolerance = rs.getBigDecimal("tolerance"); MoneyData principalMoney = MoneyData.of(currencyData, principal); MoneyData toleranceMoney = MoneyData.of(currencyData, tolerance); Integer numberOfRepayments = JdbcSupport.getInteger(rs, "numberOfRepayments"); Integer repaymentEvery = JdbcSupport.getInteger(rs, "repaidEvery"); BigDecimal interestRatePerPeriod = rs.getBigDecimal("interestRatePerPeriod"); BigDecimal annualInterestRate = rs.getBigDecimal("annualInterestRate"); int repaymentFrequencyTypeId = JdbcSupport.getInteger(rs, "repaymentPeriodFrequency"); EnumOptionData repaymentFrequencyType = LoanEnumerations.repaymentFrequencyType(repaymentFrequencyTypeId); int amortizationTypeId = JdbcSupport.getInteger(rs, "amortizationMethod"); EnumOptionData amortizationType = LoanEnumerations.amortizationType(amortizationTypeId); int interestRateFrequencyTypeId = JdbcSupport.getInteger(rs, "interestRatePerPeriodFreq"); EnumOptionData interestRateFrequencyType = LoanEnumerations.interestRateFrequencyType(interestRateFrequencyTypeId); int interestTypeId = JdbcSupport.getInteger(rs, "interestMethod"); EnumOptionData interestType = LoanEnumerations.interestType(interestTypeId); int interestCalculationPeriodTypeId = JdbcSupport.getInteger(rs, "interestCalculationInPeriodMethod"); EnumOptionData interestCalculationPeriodType = LoanEnumerations.interestCalculationPeriodType(interestCalculationPeriodTypeId); DateTime createdOn = JdbcSupport.getDateTime(rs, "createdon"); DateTime lastModifedOn = JdbcSupport.getDateTime(rs, "modifiedon"); return new LoanProductData( createdOn, lastModifedOn, id, name, description, principalMoney, toleranceMoney, numberOfRepayments, repaymentEvery, interestRatePerPeriod, annualInterestRate, repaymentFrequencyType, interestRateFrequencyType, amortizationType, interestType, interestCalculationPeriodType); }