update loan products api docs

This commit is contained in:
Keith Woodlock
2013-01-29 20:23:19 +00:00
parent e0036e8d2b
commit 08e804d03f
12 changed files with 519 additions and 618 deletions
@@ -34,10 +34,11 @@ import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.office.data.OfficeLookup;
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
import org.mifosplatform.portfolio.client.command.ClientCommand;
import org.mifosplatform.portfolio.client.data.ClientAccountSummaryCollectionData;
import org.mifosplatform.portfolio.client.data.ClientData;
import org.mifosplatform.portfolio.client.serialization.ClientCommandFromApiJsonDeserializer;
import org.mifosplatform.portfolio.client.service.ClientReadPlatformService;
import org.mifosplatform.portfolio.savingsaccount.PortfolioApiDataConversionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@@ -47,8 +48,9 @@ import org.springframework.stereotype.Component;
@Scope("singleton")
public class ClientsApiResource {
private final Set<String> CLIENT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "accountNo", "officeId", "officeName", "externalId",
"firstname", "middlename", "lastname", "fullname", "joinedDate", "displayName", "clientOrBusinessName", "allowedOffices", "imagePresent"));
private final Set<String> CLIENT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "accountNo", "officeId", "officeName",
"externalId", "firstname", "middlename", "lastname", "fullname", "joinedDate", "displayName", "clientOrBusinessName",
"allowedOffices", "imagePresent"));
private final PlatformSecurityContext context;
private final ClientReadPlatformService clientReadPlatformService;
@@ -56,24 +58,25 @@ public class ClientsApiResource {
private final ToApiJsonSerializer<ClientData> toApiJsonSerializer;
private final ToApiJsonSerializer<ClientAccountSummaryCollectionData> clientAccountSummaryToApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioApiDataConversionService apiDataConversionService;
private final PortfolioCommandsReadPlatformService commandSourceReadPlatformService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final ClientCommandFromApiJsonDeserializer clientCommandFromApiJsonDeserializer;
@Autowired
public ClientsApiResource(final PlatformSecurityContext context, final ClientReadPlatformService readPlatformService,
final OfficeReadPlatformService officeReadPlatformService, final ToApiJsonSerializer<ClientData> toApiJsonSerializer,
final ClientCommandFromApiJsonDeserializer clientCommandFromApiJsonDeserializer,
final ToApiJsonSerializer<ClientAccountSummaryCollectionData> clientAccountSummaryToApiJsonSerializer,
final ApiRequestParameterHelper apiRequestParameterHelper, final PortfolioApiDataConversionService apiDataConversionService,
final ApiRequestParameterHelper apiRequestParameterHelper,
final PortfolioCommandsReadPlatformService commandsReadPlatformService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context;
this.clientReadPlatformService = readPlatformService;
this.officeReadPlatformService = officeReadPlatformService;
this.toApiJsonSerializer = toApiJsonSerializer;
this.clientCommandFromApiJsonDeserializer = clientCommandFromApiJsonDeserializer;
this.clientAccountSummaryToApiJsonSerializer = clientAccountSummaryToApiJsonSerializer;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.apiDataConversionService = apiDataConversionService;
this.commandSourceReadPlatformService = commandsReadPlatformService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@@ -173,7 +176,10 @@ public class ClientsApiResource {
private ClientData handleRequestToIntegrateProposedChangesFromCommand(final Long clientId, final Long commandId,
final ClientData clientData) {
final CommandSourceData entry = this.commandSourceReadPlatformService.retrieveById(commandId);
final ClientData currentChange = this.apiDataConversionService.convertInternalJsonFormatToClientDataChange(clientId, entry.json());
final ClientCommand command = this.clientCommandFromApiJsonDeserializer.commandFromApiJson(entry.json());
final ClientData currentChange = ClientData.dataChangeInstance(clientId, command.getOfficeId(), command.getExternalId(),
command.getFirstname(), command.getMiddlename(), command.getLastname(), command.getFullname(), command.getJoiningDate());
final Collection<ClientData> dataChanges = null; // retrieveAllUnprocessedDataChanges(clientId);
return ClientData.integrateChanges(clientData, currentChange, dataChanges);
@@ -185,8 +191,10 @@ public class ClientsApiResource {
Collection<CommandSourceData> unprocessedChanges = this.commandSourceReadPlatformService.retrieveUnprocessChangesByEntityNameAndId(
"CLIENT", clientId);
for (CommandSourceData commandSourceData : unprocessedChanges) {
ClientData change = this.apiDataConversionService.convertInternalJsonFormatToClientDataChange(clientId,
commandSourceData.json());
final ClientCommand command = this.clientCommandFromApiJsonDeserializer.commandFromApiJson(commandSourceData.json());
final ClientData change = ClientData
.dataChangeInstance(clientId, command.getOfficeId(), command.getExternalId(), command.getFirstname(),
command.getMiddlename(), command.getLastname(), command.getFullname(), command.getJoiningDate());
dataChanges.add(change);
}
@@ -176,6 +176,9 @@ public class LoanProductsApiResource {
final boolean feeChargesOnly = true;
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly);
chargeOptions.removeAll(productData.charges());
if (chargeOptions.isEmpty()) {
chargeOptions = null;
}
final Collection<CurrencyData> currencyOptions = currencyReadPlatformService.retrieveAllowedCurrencies();
final List<EnumOptionData> amortizationTypeOptions = dropdownReadPlatformService.retrieveLoanAmortizationTypeOptions();
@@ -187,14 +190,26 @@ public class LoanProductsApiResource {
final List<EnumOptionData> interestRateFrequencyTypeOptions = dropdownReadPlatformService
.retrieveInterestRateFrequencyTypeOptions();
final Collection<FundData> fundOptions = this.fundReadPlatformService.retrieveAllFunds();
Collection<FundData> fundOptions = this.fundReadPlatformService.retrieveAllFunds();
if (fundOptions.isEmpty()) {
fundOptions = null;
}
final Collection<TransactionProcessingStrategyData> transactionProcessingStrategyOptions = this.dropdownReadPlatformService
.retreiveTransactionProcessingStrategies();
final List<GLAccountData> assetAccountOptions = accountReadPlatformService.retrieveAllEnabledDetailGLAccounts(GLAccountType.ASSET);
final List<GLAccountData> incomeAccountOptions = accountReadPlatformService.retrieveAllEnabledDetailGLAccounts(GLAccountType.INCOME);;
final List<GLAccountData> expenseAccountOptions = accountReadPlatformService.retrieveAllEnabledDetailGLAccounts(GLAccountType.EXPENSE);;
List<GLAccountData> assetAccountOptions = accountReadPlatformService.retrieveAllEnabledDetailGLAccounts(GLAccountType.ASSET);
if (assetAccountOptions.isEmpty()) {
assetAccountOptions = null;
}
List<GLAccountData> incomeAccountOptions = accountReadPlatformService.retrieveAllEnabledDetailGLAccounts(GLAccountType.INCOME);
if (incomeAccountOptions.isEmpty()) {
incomeAccountOptions = null;
}
List<GLAccountData> expenseAccountOptions = accountReadPlatformService.retrieveAllEnabledDetailGLAccounts(GLAccountType.EXPENSE);
if (expenseAccountOptions.isEmpty()) {
expenseAccountOptions = null;
}
return new LoanProductData(productData, chargeOptions, currencyOptions, amortizationTypeOptions, interestTypeOptions,
interestCalculationPeriodTypeOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions,
interestRateFrequencyTypeOptions, fundOptions, transactionProcessingStrategyOptions,
@@ -5,7 +5,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.joda.time.DateTime;
import org.mifosplatform.accounting.api.data.GLAccountData;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.organisation.monetary.data.CurrencyData;
@@ -52,9 +51,6 @@ public class LoanProductData {
private final Collection<ChargeData> charges;
private final DateTime createdOn;
private final DateTime lastModifedOn;
private final Collection<CurrencyData> currencyOptions;
private final Collection<FundData> fundOptions;
private final Collection<TransactionProcessingStrategyData> transactionProcessingStrategyOptions;
@@ -87,8 +83,6 @@ public class LoanProductData {
* Used when returning lookup information about loan product for dropdowns.
*/
public static LoanProductData lookup(final Long id, final String name) {
final DateTime createdOn = null;
final DateTime lastModifedOn = null;
final String description = null;
final CurrencyData currency = null;
final BigDecimal principal = null;
@@ -111,16 +105,13 @@ public class LoanProductData {
final Collection<ChargeData> charges = null;
final Integer accountingType = null;
return new LoanProductData(createdOn, lastModifedOn, id, name, description, currency, principal, tolerance, numberOfRepayments,
loanTermFrequency, repaymentEvery, interestRatePerPeriod, annualInterestRate, loanTermFrequencyType,
repaymentFrequencyType, interestRateFrequencyType, amortizationType, interestType, interestCalculationPeriodType, fundId,
fundName, transactionProcessingStrategyId, transactionProcessingStrategyName, charges, accountingType);
return new LoanProductData(id, name, description, currency, principal, tolerance, numberOfRepayments, loanTermFrequency,
repaymentEvery, interestRatePerPeriod, annualInterestRate, loanTermFrequencyType, repaymentFrequencyType,
interestRateFrequencyType, amortizationType, interestType, interestCalculationPeriodType, fundId, fundName,
transactionProcessingStrategyId, transactionProcessingStrategyName, charges, accountingType);
}
public static LoanProductData sensibleDefaultsForNewLoanProductCreation() {
final DateTime createdOn = null;
final DateTime lastModifedOn = null;
final Long id = null;
final String name = null;
final String description = null;
@@ -146,22 +137,20 @@ public class LoanProductData {
final Collection<ChargeData> charges = null;
final Integer accountingType = 1;
return new LoanProductData(createdOn, lastModifedOn, id, name, description, currency, principal, tolerance, numberOfRepayments,
loanTermFrequency, repaymentEvery, interestRatePerPeriod, annualInterestRate, loanTermFrequencyType,
repaymentFrequencyType, interestRateFrequencyType, amortizationType, interestType, interestCalculationPeriodType, fundId,
fundName, transactionProcessingStrategyId, transactionProcessingStrategyName, charges, accountingType);
return new LoanProductData(id, name, description, currency, principal, tolerance, numberOfRepayments, loanTermFrequency,
repaymentEvery, interestRatePerPeriod, annualInterestRate, loanTermFrequencyType, repaymentFrequencyType,
interestRateFrequencyType, amortizationType, interestType, interestCalculationPeriodType, fundId, fundName,
transactionProcessingStrategyId, transactionProcessingStrategyName, charges, accountingType);
}
public LoanProductData(final DateTime createdOn, final DateTime lastModifedOn, final Long id, final String name,
final String description, final CurrencyData currency, final BigDecimal principal, final BigDecimal tolerance,
final Integer numberOfRepayments, final Integer loanTermFrequency, final Integer repaymentEvery,
final BigDecimal interestRatePerPeriod, final BigDecimal annualInterestRate, final EnumOptionData loanTermFrequencyType,
final EnumOptionData repaymentFrequencyType, final EnumOptionData interestRateFrequencyType,
final EnumOptionData amortizationType, final EnumOptionData interestType, final EnumOptionData interestCalculationPeriodType,
final Long fundId, final String fundName, final Long transactionProcessingStrategyId,
final String transactionProcessingStrategyName, final Collection<ChargeData> charges, final Integer accountingType) {
this.createdOn = createdOn;
this.lastModifedOn = lastModifedOn;
public LoanProductData(final Long id, final String name, final String description, final CurrencyData currency,
final BigDecimal principal, final BigDecimal tolerance, final Integer numberOfRepayments, final Integer loanTermFrequency,
final Integer repaymentEvery, final BigDecimal interestRatePerPeriod, final BigDecimal annualInterestRate,
final EnumOptionData loanTermFrequencyType, final EnumOptionData repaymentFrequencyType,
final EnumOptionData interestRateFrequencyType, final EnumOptionData amortizationType, final EnumOptionData interestType,
final EnumOptionData interestCalculationPeriodType, final Long fundId, final String fundName,
final Long transactionProcessingStrategyId, final String transactionProcessingStrategyName,
final Collection<ChargeData> charges, final Integer accountingType) {
this.id = id;
this.name = name;
this.description = description;
@@ -210,8 +199,6 @@ public class LoanProductData {
final Collection<TransactionProcessingStrategyData> transactionProcessingStrategyOptions,
final List<GLAccountData> assetAccountOptions, final List<GLAccountData> incomeAccountOptions,
final List<GLAccountData> expenseAccountOptions) {
this.createdOn = productData.createdOn;
this.lastModifedOn = productData.lastModifedOn;
this.id = productData.id;
this.name = productData.name;
this.description = productData.description;
@@ -232,7 +219,7 @@ public class LoanProductData {
this.fundName = productData.fundName;
this.transactionProcessingStrategyId = productData.transactionProcessingStrategyId;
this.transactionProcessingStrategyName = productData.transactionProcessingStrategyName;
this.charges = productData.charges();
this.charges = nullIfEmpty(productData.charges());
this.accountingType = productData.accountingType;
this.chargeOptions = chargeOptions;
@@ -256,6 +243,14 @@ public class LoanProductData {
this.expenseAccountOptions = expenseAccountOptions;
}
private Collection<ChargeData> nullIfEmpty(final Collection<ChargeData> charges) {
Collection<ChargeData> chargesLocal = charges;
if (charges == null || charges.isEmpty()) {
chargesLocal = null;
}
return chargesLocal;
}
public Collection<ChargeData> charges() {
Collection<ChargeData> chargesLocal = new ArrayList<ChargeData>();
if (this.charges != null) {
@@ -348,14 +343,6 @@ public class LoanProductData {
return interestCalculationPeriodType;
}
public DateTime getCreatedOn() {
return createdOn;
}
public DateTime getLastModifedOn() {
return lastModifedOn;
}
public Collection<FundData> getFundOptions() {
return fundOptions;
}
@@ -479,5 +466,4 @@ public class LoanProductData {
public Integer getAccountingType() {
return this.accountingType;
}
}
@@ -17,12 +17,11 @@ import javax.persistence.Table;
import org.apache.commons.lang.StringUtils;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
import org.mifosplatform.portfolio.charge.domain.Charge;
import org.mifosplatform.portfolio.fund.domain.Fund;
import org.mifosplatform.portfolio.loanaccount.loanschedule.domain.AprCalculator;
import org.mifosplatform.useradministration.domain.AppUser;
import org.springframework.data.jpa.domain.AbstractPersistable;
/**
* Loan products allow for categorisation of an organisations loans into
@@ -35,7 +34,7 @@ import org.mifosplatform.useradministration.domain.AppUser;
*/
@Entity
@Table(name = "m_product_loan")
public class LoanProduct extends AbstractAuditableCustom<AppUser, Long> {
public class LoanProduct extends AbstractPersistable<Long> {
@ManyToOne
@JoinColumn(name = "fund_id", nullable = true)
@@ -220,12 +219,12 @@ public class LoanProduct extends AbstractAuditableCustom<AppUser, Long> {
public boolean isAccountingEnabled() {
return !AccountingRuleType.NONE.getValue().equals(this.accountingType);
}
public boolean isCashBasedAccountingEnabled(){
public boolean isCashBasedAccountingEnabled() {
return AccountingRuleType.CASH_BASED.getValue().equals(this.accountingType);
}
public boolean isAccrualBasedAccountingEnabled(){
public boolean isAccrualBasedAccountingEnabled() {
return AccountingRuleType.ACCRUAL_BASED.getValue().equals(this.accountingType);
}
}
@@ -5,7 +5,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import org.joda.time.DateTime;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
@@ -24,168 +23,156 @@ import org.springframework.stereotype.Service;
@Service
public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatformService {
private final PlatformSecurityContext context;
private final JdbcTemplate jdbcTemplate;
private final PlatformSecurityContext context;
private final JdbcTemplate jdbcTemplate;
private final ChargeReadPlatformService chargeReadPlatformService;
@Autowired
public LoanProductReadPlatformServiceImpl(
final PlatformSecurityContext context,
final ChargeReadPlatformService chargeReadPlatformService,
final TenantAwareRoutingDataSource dataSource) {
this.context = context;
@Autowired
public LoanProductReadPlatformServiceImpl(final PlatformSecurityContext context,
final ChargeReadPlatformService chargeReadPlatformService, final TenantAwareRoutingDataSource dataSource) {
this.context = context;
this.chargeReadPlatformService = chargeReadPlatformService;
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Override
public LoanProductData retrieveLoanProduct(final Long loanProductId) {
@Override
public LoanProductData retrieveLoanProduct(final Long loanProductId) {
try {
final Collection<ChargeData> charges = this.chargeReadPlatformService.retrieveLoanProductCharges(loanProductId);
final LoanProductMapper rm = new LoanProductMapper(charges);
final String sql = "select " + rm.loanProductSchema() + " where lp.id = ?";
try {
final Collection<ChargeData> charges = this.chargeReadPlatformService.retrieveLoanProductCharges(loanProductId);
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { loanProductId });
} catch (EmptyResultDataAccessException e) {
throw new LoanProductNotFoundException(loanProductId);
}
}
final LoanProductMapper rm = new LoanProductMapper(charges);
final String sql = "select " + rm.loanProductSchema() + " where lp.id = ?";
@Override
public Collection<LoanProductData> retrieveAllLoanProducts() {
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { loanProductId });
this.context.authenticatedUser();
} catch (EmptyResultDataAccessException e) {
throw new LoanProductNotFoundException(loanProductId);
}
}
final LoanProductMapper rm = new LoanProductMapper(null);
@Override
public Collection<LoanProductData> retrieveAllLoanProducts() {
final String sql = "select " + rm.loanProductSchema();
this.context.authenticatedUser();
return this.jdbcTemplate.query(sql, rm, new Object[] {});
}
final LoanProductMapper rm = new LoanProductMapper(null);
@Override
public Collection<LoanProductData> retrieveAllLoanProductsForLookup() {
final String sql = "select " + rm.loanProductSchema();
this.context.authenticatedUser();
return this.jdbcTemplate.query(sql, rm, new Object[] {});
}
final LoanProductLookupMapper rm = new LoanProductLookupMapper();
@Override
public Collection<LoanProductData> retrieveAllLoanProductsForLookup() {
final String sql = "select " + rm.loanProductLookupSchema();
this.context.authenticatedUser();
return this.jdbcTemplate.query(sql, rm, new Object[] {});
}
final LoanProductLookupMapper rm = new LoanProductLookupMapper();
@Override
public LoanProductData retrieveNewLoanProductDetails() {
return LoanProductData.sensibleDefaultsForNewLoanProductCreation();
}
final String sql = "select " + rm.schema();
private static final class LoanProductMapper implements
RowMapper<LoanProductData> {
return this.jdbcTemplate.query(sql, rm, new Object[] {});
}
private final Collection<ChargeData> charges;
@Override
public LoanProductData retrieveNewLoanProductDetails() {
return LoanProductData.sensibleDefaultsForNewLoanProductCreation();
}
public LoanProductMapper(final Collection<ChargeData> charges) {
this.charges = charges;
}
private static final class LoanProductMapper implements RowMapper<LoanProductData> {
public String loanProductSchema() {
return "lp.id as id, lp.fund_id as fundId, f.name as fundName, lp.loan_transaction_strategy_id as transactionStrategyId, ltps.name as transactionStrategyName, "
+ "lp.name as name, lp.description as description, "
+ "lp.principal_amount as principal, lp.currency_code as currencyCode, lp.currency_digits as currencyDigits, "
+ "lp.nominal_interest_rate_per_period as interestRatePerPeriod, lp.interest_period_frequency_enum as interestRatePerPeriodFreq, "
+ "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, lp.accounting_type as accountingType, "
+ "curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, curr.display_symbol as currencyDisplaySymbol "
+ " from m_product_loan lp "
+ " left join m_fund f on f.id = lp.fund_id"
+ " left join ref_loan_transaction_processing_strategy ltps on ltps.id = lp.loan_transaction_strategy_id"
+ " join m_currency curr on curr.code = lp.currency_code";
}
private final Collection<ChargeData> charges;
@Override
public LoanProductData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
throws SQLException {
public LoanProductMapper(final Collection<ChargeData> charges) {
this.charges = charges;
}
final Long id = rs.getLong("id");
final String name = rs.getString("name");
final String description = rs.getString("description");
final Long fundId = JdbcSupport.getLong(rs, "fundId");
final String fundName = rs.getString("fundName");
final Long transactionStrategyId = JdbcSupport.getLong(rs, "transactionStrategyId");
final String transactionStrategyName = rs.getString("transactionStrategyName");
public String loanProductSchema() {
return "lp.id as id, lp.fund_id as fundId, f.name as fundName, lp.loan_transaction_strategy_id as transactionStrategyId, ltps.name as transactionStrategyName, "
+ "lp.name as name, lp.description as description, "
+ "lp.principal_amount as principal, lp.currency_code as currencyCode, lp.currency_digits as currencyDigits, "
+ "lp.nominal_interest_rate_per_period as interestRatePerPeriod, lp.interest_period_frequency_enum as interestRatePerPeriodFreq, "
+ "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.accounting_type as accountingType, "
+ "curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, curr.display_symbol as currencyDisplaySymbol "
+ " from m_product_loan lp "
+ " left join m_fund f on f.id = lp.fund_id"
+ " left join ref_loan_transaction_processing_strategy ltps on ltps.id = lp.loan_transaction_strategy_id"
+ " join m_currency curr on curr.code = lp.currency_code";
}
final String currencyCode = rs.getString("currencyCode");
final String currencyName = rs.getString("currencyName");
final String currencyNameCode = rs.getString("currencyNameCode");
final String currencyDisplaySymbol = rs.getString("currencyDisplaySymbol");
final Integer currencyDigits = JdbcSupport.getInteger(rs, "currencyDigits");
@Override
public LoanProductData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
final CurrencyData currency = new CurrencyData(currencyCode,
currencyName, currencyDigits, currencyDisplaySymbol,
currencyNameCode);
final Long id = rs.getLong("id");
final String name = rs.getString("name");
final String description = rs.getString("description");
final Long fundId = JdbcSupport.getLong(rs, "fundId");
final String fundName = rs.getString("fundName");
final Long transactionStrategyId = JdbcSupport.getLong(rs, "transactionStrategyId");
final String transactionStrategyName = rs.getString("transactionStrategyName");
final BigDecimal principal = rs.getBigDecimal("principal");
final BigDecimal tolerance = rs.getBigDecimal("tolerance");
final String currencyCode = rs.getString("currencyCode");
final String currencyName = rs.getString("currencyName");
final String currencyNameCode = rs.getString("currencyNameCode");
final String currencyDisplaySymbol = rs.getString("currencyDisplaySymbol");
final Integer currencyDigits = JdbcSupport.getInteger(rs, "currencyDigits");
final Integer numberOfRepayments = JdbcSupport.getInteger(rs,"numberOfRepayments");
final Integer repaymentEvery = JdbcSupport.getInteger(rs, "repaidEvery");
final Integer accountingType = JdbcSupport.getInteger(rs, "accountingType");
final Integer loanTermFrequency = repaymentEvery * numberOfRepayments;
final BigDecimal interestRatePerPeriod = rs.getBigDecimal("interestRatePerPeriod");
final BigDecimal annualInterestRate = rs.getBigDecimal("annualInterestRate");
final CurrencyData currency = new CurrencyData(currencyCode, currencyName, currencyDigits, currencyDisplaySymbol,
currencyNameCode);
final int repaymentFrequencyTypeId = JdbcSupport.getInteger(rs, "repaymentPeriodFrequency");
final EnumOptionData repaymentFrequencyType = LoanEnumerations.repaymentFrequencyType(repaymentFrequencyTypeId);
final EnumOptionData loanTermFrequencyType = LoanEnumerations.loanTermFrequencyType(repaymentFrequencyTypeId);
final BigDecimal principal = rs.getBigDecimal("principal");
final BigDecimal tolerance = rs.getBigDecimal("tolerance");
final int amortizationTypeId = JdbcSupport.getInteger(rs, "amortizationMethod");
final EnumOptionData amortizationType = LoanEnumerations.amortizationType(amortizationTypeId);
final Integer numberOfRepayments = JdbcSupport.getInteger(rs, "numberOfRepayments");
final Integer repaymentEvery = JdbcSupport.getInteger(rs, "repaidEvery");
final Integer accountingType = JdbcSupport.getInteger(rs, "accountingType");
final Integer loanTermFrequency = repaymentEvery * numberOfRepayments;
final BigDecimal interestRatePerPeriod = rs.getBigDecimal("interestRatePerPeriod");
final BigDecimal annualInterestRate = rs.getBigDecimal("annualInterestRate");
final int interestRateFrequencyTypeId = JdbcSupport.getInteger(rs,"interestRatePerPeriodFreq");
final EnumOptionData interestRateFrequencyType = LoanEnumerations.interestRateFrequencyType(interestRateFrequencyTypeId);
final int repaymentFrequencyTypeId = JdbcSupport.getInteger(rs, "repaymentPeriodFrequency");
final EnumOptionData repaymentFrequencyType = LoanEnumerations.repaymentFrequencyType(repaymentFrequencyTypeId);
final int interestTypeId = JdbcSupport.getInteger(rs, "interestMethod");
final EnumOptionData interestType = LoanEnumerations.interestType(interestTypeId);
final EnumOptionData loanTermFrequencyType = LoanEnumerations.loanTermFrequencyType(repaymentFrequencyTypeId);
final int interestCalculationPeriodTypeId = JdbcSupport.getInteger(rs,"interestCalculationInPeriodMethod");
final EnumOptionData interestCalculationPeriodType = LoanEnumerations.interestCalculationPeriodType(interestCalculationPeriodTypeId);
final int amortizationTypeId = JdbcSupport.getInteger(rs, "amortizationMethod");
final EnumOptionData amortizationType = LoanEnumerations.amortizationType(amortizationTypeId);
final DateTime createdOn = JdbcSupport.getDateTime(rs, "createdon");
final DateTime lastModifedOn = JdbcSupport.getDateTime(rs, "modifiedon");
final int interestRateFrequencyTypeId = JdbcSupport.getInteger(rs, "interestRatePerPeriodFreq");
final EnumOptionData interestRateFrequencyType = LoanEnumerations.interestRateFrequencyType(interestRateFrequencyTypeId);
return new LoanProductData(createdOn, lastModifedOn, id, name,
description, currency, principal, tolerance,
numberOfRepayments, loanTermFrequency, repaymentEvery, interestRatePerPeriod,
annualInterestRate, loanTermFrequencyType, repaymentFrequencyType,
interestRateFrequencyType, amortizationType, interestType,
interestCalculationPeriodType, fundId, fundName, transactionStrategyId, transactionStrategyName, this.charges, accountingType);
}
final int interestTypeId = JdbcSupport.getInteger(rs, "interestMethod");
final EnumOptionData interestType = LoanEnumerations.interestType(interestTypeId);
}
final int interestCalculationPeriodTypeId = JdbcSupport.getInteger(rs, "interestCalculationInPeriodMethod");
final EnumOptionData interestCalculationPeriodType = LoanEnumerations
.interestCalculationPeriodType(interestCalculationPeriodTypeId);
private static final class LoanProductLookupMapper implements
RowMapper<LoanProductData> {
return new LoanProductData(id, name, description, currency, principal, tolerance, numberOfRepayments, loanTermFrequency,
repaymentEvery, interestRatePerPeriod, annualInterestRate, loanTermFrequencyType, repaymentFrequencyType,
interestRateFrequencyType, amortizationType, interestType, interestCalculationPeriodType, fundId, fundName,
transactionStrategyId, transactionStrategyName, this.charges, accountingType);
}
public String loanProductLookupSchema() {
return "lp.id as id, lp.name as name from m_product_loan lp";
}
}
@Override
public LoanProductData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
throws SQLException {
private static final class LoanProductLookupMapper implements RowMapper<LoanProductData> {
final Long id = rs.getLong("id");
final String name = rs.getString("name");
public String schema() {
return "lp.id as id, lp.name as name from m_product_loan lp";
}
return LoanProductData.lookup(id, name);
}
}
@Override
public LoanProductData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
final Long id = rs.getLong("id");
final String name = rs.getString("name");
return LoanProductData.lookup(id, name);
}
}
}
@@ -1,6 +1,5 @@
package org.mifosplatform.portfolio.savingsaccount;
import org.mifosplatform.portfolio.client.data.ClientData;
import org.mifosplatform.portfolio.group.command.GroupCommand;
import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountApprovalCommand;
import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountCommand;
@@ -21,8 +20,6 @@ public interface PortfolioApiDataConversionService {
DepositProductCommand convertJsonToDepositProductCommand(Long resourceIdentifier, String json);
ClientData convertInternalJsonFormatToClientDataChange(Long clientId, String json);
GroupCommand convertJsonToGroupCommand(Long resourceIdentifier, String json);
DepositAccountCommand convertJsonToDepositAccountCommand(Long resourceIdentifier, String json);
@@ -21,9 +21,6 @@ import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
import org.mifosplatform.infrastructure.core.exception.UnsupportedParameterException;
import org.mifosplatform.portfolio.client.command.ClientCommand;
import org.mifosplatform.portfolio.client.data.ClientData;
import org.mifosplatform.portfolio.client.serialization.ClientCommandFromApiJsonDeserializer;
import org.mifosplatform.portfolio.group.command.GroupCommand;
import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountApprovalCommand;
import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountCommand;
@@ -37,7 +34,6 @@ import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountW
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionApprovalCommand;
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionCommand;
import org.mifosplatform.portfolio.savingsdepositproduct.command.DepositProductCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.number.NumberFormatter;
import org.springframework.stereotype.Service;
@@ -56,23 +52,10 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
*/
private final Gson gsonConverter;
private final ClientCommandFromApiJsonDeserializer clientCommandFromApiJsonDeserializer;
@Autowired
public PortfolioApiDataConversionServiceImpl(final ClientCommandFromApiJsonDeserializer clientCommandFromApiJsonDeserializer) {
this.clientCommandFromApiJsonDeserializer = clientCommandFromApiJsonDeserializer;
public PortfolioApiDataConversionServiceImpl() {
this.gsonConverter = new Gson();
}
@Override
public ClientData convertInternalJsonFormatToClientDataChange(final Long resourceIdentifier, final String json) {
final ClientCommand command = this.clientCommandFromApiJsonDeserializer.commandFromApiJson(json);
return ClientData.dataChangeInstance(resourceIdentifier, command.getOfficeId(), command.getExternalId(), command.getFirstname(),
command.getMiddlename(), command.getLastname(), command.getFullname(), command.getJoiningDate());
}
@Override
public GroupCommand convertJsonToGroupCommand(final Long resourceIdentifier, final String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
@@ -815,9 +798,9 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
// currencyCode, currencyDigits
Set<String> supportedParams = new HashSet<String>(Arrays.asList("clientId", "productId", "externalId", "currencyCode",
"digitsAfterDecimal", "savingsDepositAmountPerPeriod", "recurringInterestRate", "savingInterestRate", "tenure",
"commencementDate", "locale", "dateFormat", "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType",
"tenureType", "depositfrequency", "interestType", "interestCalculationMethod", "minimumBalanceForWithdrawal",
"isPartialDepositAllowed", "depositEvery","interestPostEvery","interestPostFrequency"));
"commencementDate", "locale", "dateFormat", "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "tenureType",
"depositfrequency", "interestType", "interestCalculationMethod", "minimumBalanceForWithdrawal", "isPartialDepositAllowed",
"depositEvery", "interestPostEvery", "interestPostFrequency"));
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
@@ -843,21 +826,20 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
BigDecimal minimumBalanceForWithdrawal = extractBigDecimalParameter("minimumBalanceForWithdrawal", requestMap, modifiedParameters);
boolean isPartialDepositAllowed = extractBooleanParameter("isPartialDepositAllowed", requestMap, modifiedParameters);
Integer depositEvery = extractIntegerParameter("depositEvery", requestMap, modifiedParameters);
Integer interestPostEvery = extractIntegerParameter("interestPostEvery", requestMap, modifiedParameters);
Integer interestPostFrequency = extractIntegerParameter("interestPostFrequency", requestMap, modifiedParameters);
return new SavingAccountCommand(modifiedParameters, resourceIdentifier, clientId, productId, externalId, currencyCode,
digitsAfterDecimalValue, savingsDepositAmount, recurringInterestRate, savingInterestRate, tenure, commencementDate,
tenureType, depositfrequency, interestType, minimumBalanceForWithdrawal, interestCalculationMethod,
isLockinPeriodAllowed, isPartialDepositAllowed, lockinPeriod, lockinPeriodType, depositEvery, interestPostEvery, interestPostFrequency);
tenureType, depositfrequency, interestType, minimumBalanceForWithdrawal, interestCalculationMethod, isLockinPeriodAllowed,
isPartialDepositAllowed, lockinPeriod, lockinPeriodType, depositEvery, interestPostEvery, interestPostFrequency);
}
@Override
public SavingStateTransitionsCommand convertJsonToSavingStateTransitionCommand(Long accountId, String json) {
@Override
public SavingStateTransitionsCommand convertJsonToSavingStateTransitionCommand( Long accountId, String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
@@ -872,26 +854,27 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
String note = extractStringParameter("note", requestMap, modifiedParameters);
return new SavingStateTransitionsCommand(accountId, eventDate, note);
}
@Override
public SavingAccountApprovalCommand convertJsonToSavingApprovalCommand( Long accountId, String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
}
@Override
public SavingAccountApprovalCommand convertJsonToSavingApprovalCommand(Long accountId, String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(Arrays.asList("locale", "dateFormat", "commencementDate", "savingsDepositAmountPerPeriod",
"minimumBalanceForWithdrawal", "recurringInterestRate", "savingInterestRate", "interestType", "tenure", "tenureType", "frequency", "payEvery", "note",
"interestPostEvery", "interestPostFrequency"));
Set<String> supportedParams = new HashSet<String>(Arrays.asList("locale", "dateFormat", "commencementDate",
"savingsDepositAmountPerPeriod", "minimumBalanceForWithdrawal", "recurringInterestRate", "savingInterestRate",
"interestType", "tenure", "tenureType", "frequency", "payEvery", "note", "interestPostEvery", "interestPostFrequency"));
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
LocalDate commencementDate = extractLocalDateParameter("commencementDate", requestMap, modifiedParameters);
BigDecimal savingsDepositAmountPerPeriod = extractBigDecimalParameter("savingsDepositAmountPerPeriod", requestMap, modifiedParameters);
BigDecimal savingsDepositAmountPerPeriod = extractBigDecimalParameter("savingsDepositAmountPerPeriod", requestMap,
modifiedParameters);
BigDecimal minimumBalanceForWithdrawal = extractBigDecimalParameter("minimumBalanceForWithdrawal", requestMap, modifiedParameters);
BigDecimal recurringInterestRate = extractBigDecimalParameter("recurringInterestRate", requestMap, modifiedParameters);
BigDecimal savingInterestRate = extractBigDecimalParameter("savingInterestRate", requestMap, modifiedParameters);
@@ -903,43 +886,46 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
String note = extractStringParameter("note", requestMap, modifiedParameters);
Integer interestPostEvery = extractIntegerParameter("interestPostEvery", requestMap, modifiedParameters);
Integer interestPostFrequency = extractIntegerParameter("interestPostFrequency", requestMap, modifiedParameters);
return new SavingAccountApprovalCommand(accountId, commencementDate, savingsDepositAmountPerPeriod, minimumBalanceForWithdrawal, recurringInterestRate,
savingInterestRate, interestType, tenure, tenureType, frequency, payEvery, note, interestPostEvery, interestPostFrequency);
}
return new SavingAccountApprovalCommand(accountId, commencementDate, savingsDepositAmountPerPeriod, minimumBalanceForWithdrawal,
recurringInterestRate, savingInterestRate, interestType, tenure, tenureType, frequency, payEvery, note, interestPostEvery,
interestPostFrequency);
}
@Override
public SavingAccountDepositCommand convertJsonToSavingAccountDepositCommand(Long accountId, String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
@Override
public SavingAccountDepositCommand convertJsonToSavingAccountDepositCommand(Long accountId, String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(Arrays.asList("locale", "dateFormat", "depositDate", "savingsDepositAmountPerPeriod", "note"));
Set<String> supportedParams = new HashSet<String>(Arrays.asList("locale", "dateFormat", "depositDate",
"savingsDepositAmountPerPeriod", "note"));
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
LocalDate depositDate = extractLocalDateParameter("depositDate", requestMap, modifiedParameters);
BigDecimal savingsDepositAmountPerPeriod = extractBigDecimalParameter("savingsDepositAmountPerPeriod", requestMap, modifiedParameters);
BigDecimal savingsDepositAmountPerPeriod = extractBigDecimalParameter("savingsDepositAmountPerPeriod", requestMap,
modifiedParameters);
String note = extractStringParameter("note", requestMap, modifiedParameters);
return new SavingAccountDepositCommand(accountId, savingsDepositAmountPerPeriod, depositDate, note);
}
return new SavingAccountDepositCommand(accountId, savingsDepositAmountPerPeriod, depositDate, note);
}
@Override
public SavingAccountWithdrawalCommand convertJsonToSavingAccountWithdrawalCommand(Long accountId, String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
@Override
public SavingAccountWithdrawalCommand convertJsonToSavingAccountWithdrawalCommand(Long accountId, String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(Arrays.asList("locale", "dateFormat", "transactionDate", "amount", "note"));
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
LocalDate transactionDate = extractLocalDateParameter("transactionDate", requestMap, modifiedParameters);
BigDecimal amount = extractBigDecimalParameter("amount", requestMap, modifiedParameters);
String note = extractStringParameter("note", requestMap, modifiedParameters);
return new SavingAccountWithdrawalCommand(accountId, transactionDate, amount, note);
}
return new SavingAccountWithdrawalCommand(accountId, transactionDate, amount, note);
}
}