add JdbcSupport class for retrieving long and integer values with possible nulls.
This commit is contained in:
@@ -17,8 +17,6 @@ public class LoanProductData implements Serializable {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private boolean isFlexible;
|
||||
private boolean isInterestRebateAllowed;
|
||||
private MoneyData principalMoney;
|
||||
private BigDecimal interestRatePerPeriod = BigDecimal.ZERO;
|
||||
private int interestRatePeriod;
|
||||
@@ -47,8 +45,7 @@ public class LoanProductData implements Serializable {
|
||||
}
|
||||
|
||||
public LoanProductData(final Long id, final String name,
|
||||
String description, final boolean isFlexible,
|
||||
final boolean isInterestRebateAllowed,
|
||||
String description,
|
||||
final MoneyData principalMoney,
|
||||
final BigDecimal interestRatePerPeriod,
|
||||
final int interestRatePeriod, final BigDecimal annualInterestRate,
|
||||
@@ -59,8 +56,6 @@ public class LoanProductData implements Serializable {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.isFlexible = isFlexible;
|
||||
this.isInterestRebateAllowed = isInterestRebateAllowed;
|
||||
this.principalMoney = principalMoney;
|
||||
this.interestRatePerPeriod = interestRatePerPeriod;
|
||||
this.interestRatePeriod = interestRatePeriod;
|
||||
@@ -100,22 +95,6 @@ public class LoanProductData implements Serializable {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean isFlexible() {
|
||||
return isFlexible;
|
||||
}
|
||||
|
||||
public void setFlexible(boolean isFlexible) {
|
||||
this.isFlexible = isFlexible;
|
||||
}
|
||||
|
||||
public boolean isInterestRebateAllowed() {
|
||||
return isInterestRebateAllowed;
|
||||
}
|
||||
|
||||
public void setInterestRebateAllowed(boolean isInterestRebateAllowed) {
|
||||
this.isInterestRebateAllowed = isInterestRebateAllowed;
|
||||
}
|
||||
|
||||
public MoneyData getPrincipalMoney() {
|
||||
return principalMoney;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.mifosng.platform.infrastructure;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.springframework.jdbc.support.JdbcUtils;
|
||||
|
||||
/**
|
||||
* Support for retrieving possibly null values from jdbc recordset delegating to springs {@link JdbcUtils} where possible.
|
||||
*/
|
||||
public class JdbcSupport {
|
||||
|
||||
public static DateTime getDateTime(ResultSet rs, String columnName) throws SQLException {
|
||||
DateTime dateTime = null;
|
||||
Timestamp dateValue = rs.getTimestamp(columnName);
|
||||
if (dateValue != null) {
|
||||
dateTime = new DateTime(dateValue.getTime());
|
||||
}
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public static LocalDate getLocalDate(final ResultSet rs, final String columnName) throws SQLException {
|
||||
LocalDate localDate = null;
|
||||
Date dateValue = rs.getDate(columnName);
|
||||
if (dateValue != null) {
|
||||
localDate = new LocalDate(dateValue);
|
||||
}
|
||||
return localDate;
|
||||
}
|
||||
|
||||
public static Long getLong(final ResultSet rs, final String columnName) throws SQLException {
|
||||
return (Long) JdbcUtils.getResultSetValue(rs, rs.findColumn(columnName), Long.class);
|
||||
}
|
||||
|
||||
public static Integer getInteger(ResultSet rs, String columnName) throws SQLException {
|
||||
return (Integer) JdbcUtils.getResultSetValue(rs, rs.findColumn(columnName), Integer.class);
|
||||
}
|
||||
}
|
||||
+14
-20
@@ -15,6 +15,7 @@ import org.mifosng.data.LoanProductData;
|
||||
import org.mifosng.data.MoneyData;
|
||||
import org.mifosng.platform.currency.service.CurrencyReadPlatformService;
|
||||
import org.mifosng.platform.exceptions.PlatformResourceNotFoundException;
|
||||
import org.mifosng.platform.infrastructure.JdbcSupport;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
import org.mifosng.platform.user.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -126,12 +127,9 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
|
||||
Long id = rs.getLong("id");
|
||||
String name = rs.getString("name");
|
||||
String description = rs.getString("description");
|
||||
boolean isFlexible = rs.getBoolean("isFlexible");
|
||||
boolean isInterestRebateAllowed = rs
|
||||
.getBoolean("isInterestRebateAllowed");
|
||||
|
||||
String currencyCode = rs.getString("currencyCode");
|
||||
int currencyDigits = rs.getInt("currencyDigits");
|
||||
Integer currencyDigits = JdbcSupport.getInteger(rs, "currencyDigits");
|
||||
|
||||
CurrencyData currencyData = findCurrencyByCode(currencyCode, allowedCurrencies);
|
||||
if (currencyData != null) {
|
||||
@@ -144,25 +142,21 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
|
||||
MoneyData principalMoney = MoneyData.of(currencyData, principal);
|
||||
MoneyData toleranceMoney = MoneyData.of(currencyData, tolerance);
|
||||
|
||||
BigDecimal interestRatePerPeriod = rs.getBigDecimal("interestRatePerPeriod");
|
||||
Integer interestRatePeriod = JdbcSupport.getInteger(rs, "interestRatePerPeriodFreq");
|
||||
BigDecimal annualInterestRate = rs.getBigDecimal("annualInterestRate");
|
||||
Integer interestMethod = JdbcSupport.getInteger(rs, "interestMethod");
|
||||
Integer interestCalculationInPeriodMethod = JdbcSupport.getInteger(rs, "interestCalculationInPeriodMethod");
|
||||
|
||||
BigDecimal interestRatePerPeriod = rs
|
||||
.getBigDecimal("interestRatePerPeriod");
|
||||
int interestRatePeriod = rs.getInt("interestRatePerPeriodFreq");
|
||||
BigDecimal annualInterestRate = rs
|
||||
.getBigDecimal("annualInterestRate");
|
||||
int interestMethod = rs.getInt("interestMethod");
|
||||
int interestCalculationInPeriodMethod = rs.getInt("interestCalculationInPeriodMethod");
|
||||
Integer repaidEvery = JdbcSupport.getInteger(rs, "repaidEvery");
|
||||
Integer repaymentFrequency = JdbcSupport.getInteger(rs, "repaymentPeriodFrequency");
|
||||
Integer numberOfRepayments = JdbcSupport.getInteger(rs, "numberOfRepayments");
|
||||
Integer amortizationMethod = JdbcSupport.getInteger(rs, "amortizationMethod");
|
||||
|
||||
int repaidEvery = rs.getInt("repaidEvery");
|
||||
int repaymentFrequency = rs.getInt("repaymentPeriodFrequency");
|
||||
int numberOfRepayments = rs.getInt("numberOfRepayments");
|
||||
int amortizationMethod = rs.getInt("amortizationMethod");
|
||||
DateTime createdOn = JdbcSupport.getDateTime(rs, "createdon");
|
||||
DateTime lastModifedOn = JdbcSupport.getDateTime(rs, "modifiedon");
|
||||
|
||||
DateTime createdOn = new DateTime(rs.getDate("createdOn"));
|
||||
DateTime lastModifedOn = new DateTime(rs.getDate("modifiedon"));
|
||||
|
||||
return new LoanProductData(id, name, description, isFlexible,
|
||||
isInterestRebateAllowed, principalMoney,
|
||||
return new LoanProductData(id, name, description, principalMoney,
|
||||
interestRatePerPeriod, interestRatePeriod,
|
||||
annualInterestRate, interestMethod, interestCalculationInPeriodMethod,
|
||||
repaidEvery,
|
||||
|
||||
+7
-18
@@ -12,6 +12,7 @@ import org.joda.time.LocalDate;
|
||||
import org.mifosng.data.OfficeData;
|
||||
import org.mifosng.data.OfficeLookup;
|
||||
import org.mifosng.platform.exceptions.PlatformResourceNotFoundException;
|
||||
import org.mifosng.platform.infrastructure.JdbcSupport;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
import org.mifosng.platform.user.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -47,20 +48,16 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
|
||||
Long id = rs.getLong("id");
|
||||
String name = rs.getString("name");
|
||||
String externalId = rs.getString("externalId");
|
||||
LocalDate openingDate = new LocalDate(rs.getDate("openingDate"));
|
||||
LocalDate openingDate = JdbcSupport.getLocalDate(rs, "openingDate");
|
||||
String hierarchy = rs.getString("hierarchy");
|
||||
|
||||
Long parentId = getRSLong(rs.getString("parentId"), rs.getLong("parentId"));
|
||||
|
||||
Long parentId = JdbcSupport.getLong(rs, "parentId");
|
||||
String parentName = rs.getString("parentName");
|
||||
|
||||
return new OfficeData(id, name, externalId, openingDate, hierarchy,
|
||||
parentId, parentName);
|
||||
return new OfficeData(id, name, externalId, openingDate, hierarchy, parentId, parentName);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class OfficeLookupMapper implements
|
||||
RowMapper<OfficeLookup> {
|
||||
|
||||
private static final class OfficeLookupMapper implements RowMapper<OfficeLookup> {
|
||||
|
||||
public String officeLookupSchema() {
|
||||
return " o.id as id, o.name as name from org_office o ";
|
||||
@@ -106,8 +103,7 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
|
||||
+ rm.officeLookupSchema()
|
||||
+ "where o.org_id = ? and o.hierarchy like ? order by o.hierarchy";
|
||||
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] {
|
||||
currentUser.getOrganisation().getId(), hierarchySearchString });
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] {currentUser.getOrganisation().getId(), hierarchySearchString });
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,11 +162,4 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
|
||||
return filterParentLookups;
|
||||
|
||||
}
|
||||
|
||||
public static Long getRSLong(String stringVal, Long longVal) {
|
||||
if (stringVal == null)
|
||||
return null;
|
||||
|
||||
return longVal;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user