MIFOSX-2303 Add Product/Branch/Category filtering to Loan Provisioning report

This commit is contained in:
unknown
2015-10-29 18:20:19 +05:30
parent e61a5fba03
commit 6ae5d7d52d
6 changed files with 310 additions and 124 deletions
@@ -19,7 +19,9 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.mifosplatform.accounting.provisioning.constant.ProvisioningEntriesApiConstants;
import org.mifosplatform.accounting.provisioning.data.LoanProductProvisioningEntryData;
import org.mifosplatform.accounting.provisioning.data.ProvisioningEntryData;
import org.mifosplatform.accounting.provisioning.domain.LoanProductProvisioningEntry;
import org.mifosplatform.accounting.provisioning.service.ProvisioningEntriesReadPlatformService;
import org.mifosplatform.commands.domain.CommandWrapper;
import org.mifosplatform.commands.service.CommandWrapperBuilder;
@@ -29,6 +31,8 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.core.service.Page;
import org.mifosplatform.infrastructure.core.service.SearchParameters;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@@ -42,20 +46,22 @@ public class ProvisioningEntriesApiResource {
private final PlatformSecurityContext platformSecurityContext;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final DefaultToApiJsonSerializer<ProvisioningEntryData> toApiJsonSerializer;
private final ProvisioningEntriesReadPlatformService provisioningEntriesReadPlatformService ;
private final DefaultToApiJsonSerializer<Object> entriesApiJsonSerializer;
private final ProvisioningEntriesReadPlatformService provisioningEntriesReadPlatformService;
private final ApiRequestParameterHelper apiRequestParameterHelper;
@Autowired
public ProvisioningEntriesApiResource(final PlatformSecurityContext platformSecurityContext,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final DefaultToApiJsonSerializer<ProvisioningEntryData> toApiJsonSerializer,
final ProvisioningEntriesReadPlatformService provisioningEntriesReadPlatformService,
final ApiRequestParameterHelper apiRequestParameterHelper) {
final ApiRequestParameterHelper apiRequestParameterHelper, final DefaultToApiJsonSerializer<Object> entriesApiJsonSerializer) {
this.platformSecurityContext = platformSecurityContext;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.toApiJsonSerializer = toApiJsonSerializer;
this.provisioningEntriesReadPlatformService = provisioningEntriesReadPlatformService ;
this.apiRequestParameterHelper = apiRequestParameterHelper ;
this.provisioningEntriesReadPlatformService = provisioningEntriesReadPlatformService;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.entriesApiJsonSerializer = entriesApiJsonSerializer;
}
@POST
@@ -68,7 +74,7 @@ public class ProvisioningEntriesApiResource {
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
return this.toApiJsonSerializer.serialize(commandProcessingResult);
}
@POST
@Path("{entryId}")
@Consumes({ MediaType.APPLICATION_JSON })
@@ -77,36 +83,53 @@ public class ProvisioningEntriesApiResource {
final String apiRequestBodyAsJson) {
CommandWrapper commandWrapper = null;
this.platformSecurityContext.authenticatedUser();
if("createjournalentry".equals(commandParam)) {
if ("createjournalentry".equals(commandParam)) {
commandWrapper = new CommandWrapperBuilder().createProvisioningJournalEntries(entryId).withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
return this.toApiJsonSerializer.serialize(commandProcessingResult);
}else if("recreateprovisioningentry".equals(commandParam)) {
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService
.logCommandSource(commandWrapper);
return this.toApiJsonSerializer.serialize(commandProcessingResult);
} else if ("recreateprovisioningentry".equals(commandParam)) {
commandWrapper = new CommandWrapperBuilder().reCreateProvisioningEntries(entryId).withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
return this.toApiJsonSerializer.serialize(commandProcessingResult);
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService
.logCommandSource(commandWrapper);
return this.toApiJsonSerializer.serialize(commandProcessingResult);
}
throw new UnrecognizedQueryParamException("command", commandParam);
throw new UnrecognizedQueryParamException("command", commandParam);
}
@GET
@Path("{entryId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveProvisioningEntry(@PathParam("entryId") final Long entryId, @Context final UriInfo uriInfo) {
platformSecurityContext.authenticatedUser() ;
ProvisioningEntryData data = this.provisioningEntriesReadPlatformService.retrieveProvisioningEntryData(entryId) ;
platformSecurityContext.authenticatedUser();
ProvisioningEntryData data = this.provisioningEntriesReadPlatformService.retrieveProvisioningEntryData(entryId);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, data, ProvisioningEntriesApiConstants.PROVISIONING_ENTRY_PARAMETERS);
return this.toApiJsonSerializer.serialize(settings, data, ProvisioningEntriesApiConstants.PROVISIONING_ENTRY_PARAMETERS);
}
@GET
@Path("entries")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveProviioningEntries(@QueryParam("entryId") final Long entryId, @QueryParam("offset") final Integer offset,
@QueryParam("limit") final Integer limit, @QueryParam("officeId") final Long officeId,
@QueryParam("productId") final Long productId, @QueryParam("categoryId") final Long categoryId, @Context final UriInfo uriInfo) {
this.platformSecurityContext.authenticatedUser();
SearchParameters params = SearchParameters.forProvisioningEntries(entryId, officeId, productId, categoryId, offset, limit);
Page<LoanProductProvisioningEntryData> entries = this.provisioningEntriesReadPlatformService.retrieveProvisioningEntries(params);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.entriesApiJsonSerializer.serialize(settings, entries, ProvisioningEntriesApiConstants.PROVISIONING_ENTRY_PARAMETERS);
}
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveAllProvisioningEntries(@Context final UriInfo uriInfo) {
platformSecurityContext.authenticatedUser() ;
Collection<ProvisioningEntryData> data = this.provisioningEntriesReadPlatformService.retrieveAllProvisioningEntries() ;
public String retrieveAllProvisioningEntries(@QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
@Context final UriInfo uriInfo) {
platformSecurityContext.authenticatedUser();
Page<ProvisioningEntryData> data = this.provisioningEntriesReadPlatformService.retrieveAllProvisioningEntries(offset, limit);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, data, ProvisioningEntriesApiConstants.ALL_PROVISIONING_ENTRIES);
return this.entriesApiJsonSerializer.serialize(settings, data, ProvisioningEntriesApiConstants.ALL_PROVISIONING_ENTRIES);
}
}
@@ -5,6 +5,7 @@
*/
package org.mifosplatform.accounting.provisioning.data;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
@@ -24,6 +25,8 @@ public class ProvisioningEntryData {
Long modifiedById ;
private String modifiedUser ;
private BigDecimal reservedAmount ;
private Collection<LoanProductProvisioningEntryData> provisioningEntries ;
@@ -33,7 +36,7 @@ public class ProvisioningEntryData {
}
public ProvisioningEntryData(Long id, Boolean journalEntry, Long createdById,
String createdUser, Date createdDate, Long modifiedById, String modifiedUser) {
String createdUser, Date createdDate, Long modifiedById, String modifiedUser, BigDecimal totalReservedAmount) {
this.id = id ;
this.journalEntry = journalEntry ;
this.createdById = createdById ;
@@ -41,6 +44,7 @@ public class ProvisioningEntryData {
this.modifiedById = modifiedById ;
this.modifiedUser = modifiedUser ;
this.createdDate = createdDate ;
this.reservedAmount = totalReservedAmount ;
}
public void setEntries(Collection<LoanProductProvisioningEntryData> provisioningEntries) {
@@ -10,6 +10,8 @@ import java.util.Date;
import org.mifosplatform.accounting.provisioning.data.LoanProductProvisioningEntryData;
import org.mifosplatform.accounting.provisioning.data.ProvisioningEntryData;
import org.mifosplatform.infrastructure.core.service.Page;
import org.mifosplatform.infrastructure.core.service.SearchParameters;
public interface ProvisioningEntriesReadPlatformService {
@@ -18,11 +20,13 @@ public interface ProvisioningEntriesReadPlatformService {
public ProvisioningEntryData retrieveProvisioningEntryData(Long entryId) ;
public Collection<ProvisioningEntryData> retrieveAllProvisioningEntries() ;
public Page<ProvisioningEntryData> retrieveAllProvisioningEntries(Integer offset, Integer limit) ;
public ProvisioningEntryData retrieveProvisioningEntryData(String date) ;
public ProvisioningEntryData retrieveProvisioningEntryDataByCriteriaId(Long criteriaId) ;
public ProvisioningEntryData retrieveExistingProvisioningIdDateWithJournals() ;
public Page<LoanProductProvisioningEntryData> retrieveProvisioningEntries(SearchParameters searchParams) ;
}
@@ -9,14 +9,19 @@ import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.mifosplatform.accounting.provisioning.data.LoanProductProvisioningEntryData;
import org.mifosplatform.accounting.provisioning.data.ProvisioningEntryData;
import org.mifosplatform.infrastructure.core.service.Page;
import org.mifosplatform.infrastructure.core.service.PaginationHelper;
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
import org.mifosplatform.infrastructure.core.service.SearchParameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -28,6 +33,9 @@ public class ProvisioningEntriesReadPlatformServiceImpl implements ProvisioningE
private final JdbcTemplate jdbcTemplate;
private final PaginationHelper<LoanProductProvisioningEntryData> loanProductProvisioningEntryDataPaginationHelper = new PaginationHelper<>();
private final PaginationHelper<ProvisioningEntryData> provisioningEntryDataPaginationHelper = new PaginationHelper<>();
@Autowired
public ProvisioningEntriesReadPlatformServiceImpl(final RoutingDataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
@@ -58,8 +66,7 @@ public class ProvisioningEntriesReadPlatformServiceImpl implements ProvisioningE
.append(" JOIN m_provisioning_criteria_definition pcd on pcd.criteria_id = lpm.criteria_id and ")
.append("(pcd.min_age <= GREATEST(datediff(").append(formattedDate).append(",sch.duedate),0) and ")
.append("GREATEST(datediff(").append(formattedDate).append(",sch.duedate),0) <= pcd.max_age) and ")
.append("pcd.criteria_id is not null ")
.append("LEFT JOIN m_client mclient ON mclient.id = loan.client_id ")
.append("pcd.criteria_id is not null ").append("LEFT JOIN m_client mclient ON mclient.id = loan.client_id ")
.append("LEFT JOIN m_group mgroup ON mgroup.id = loan.group_id ")
.append("where loan.loan_status_id=300 and sch.completed_derived=false ")
.append("GROUP BY loan.id order by loan.product_id");
@@ -77,9 +84,9 @@ public class ProvisioningEntriesReadPlatformServiceImpl implements ProvisioningE
BigDecimal outstandingBalance = rs.getBigDecimal("outstandingbalance");
Long liabilityAccountCode = rs.getLong("liability_account");
Long expenseAccountCode = rs.getLong("expense_account");
Long criteriaId = rs.getLong("criteriaid") ;
Long criteriaId = rs.getLong("criteriaid");
Long historyId = null;
return new LoanProductProvisioningEntryData(historyId, officeId, currentcyCode, productId, categoryId, overdueDays, percentage,
outstandingBalance, liabilityAccountCode, expenseAccountCode, criteriaId);
}
@@ -91,155 +98,240 @@ public class ProvisioningEntriesReadPlatformServiceImpl implements ProvisioningE
@Override
public ProvisioningEntryData retrieveProvisioningEntryData(Long entryId) {
LoanProductProvisioningEntryRowMapper mapper = new LoanProductProvisioningEntryRowMapper();
final String sql = mapper.getSchema() + " where entry.history_id = ?";
Collection<LoanProductProvisioningEntryData> entries = this.jdbcTemplate.query(sql, mapper, new Object[] { entryId });
ProvisioningEntryDataMapper mapper1 = new ProvisioningEntryDataMapper() ;
final String sql1 = mapper1.getSchema() + " where entry.id = ?";
ProvisioningEntryData data= this.jdbcTemplate.queryForObject(sql1, mapper1, new Object[] { entryId });
data.setEntries(entries) ;
return data ;
ProvisioningEntryDataMapperWithSumReserved mapper1 = new ProvisioningEntryDataMapperWithSumReserved();
final String sql1 = "select" + mapper1.getSchema() + " where entry.id = ?";
ProvisioningEntryData data = this.jdbcTemplate.queryForObject(sql1, mapper1, new Object[] { entryId });
return data;
}
private static final class ProvisioningEntryDataMapper implements RowMapper<ProvisioningEntryData> {
private final StringBuilder sqlQuery = new StringBuilder()
.append("select entry.id, journal_entry_created, createdby_id, created_date, created.username as createduser,")
.append("lastmodifiedby_id, modified.username as modifieduser, lastmodified_date ")
.append("from m_provisioning_history entry ")
.append("left JOIN m_appuser created ON created.id = entry.createdby_id ")
.append("left JOIN m_appuser modified ON modified.id = entry.lastmodifiedby_id ") ;
.append(" entry.id, entry.journal_entry_created, entry.createdby_id, entry.created_date, created.username as createduser,")
.append("entry.lastmodifiedby_id, modified.username as modifieduser, entry.lastmodified_date ")
.append("from m_provisioning_history entry ").append("left JOIN m_appuser created ON created.id = entry.createdby_id ")
.append("left JOIN m_appuser modified ON modified.id = entry.lastmodifiedby_id ");
@Override
@SuppressWarnings("unused")
public ProvisioningEntryData mapRow(ResultSet rs, int rowNum) throws SQLException {
Long id = rs.getLong("id") ;
Boolean journalEntry = rs.getBoolean("journal_entry_created") ;
Long createdById = rs.getLong("createdby_id") ;
String createdUser = rs.getString("createduser") ;
Date createdDate = rs.getDate("created_date") ;
Long modifiedById = rs.getLong("lastmodifiedby_id") ;
String modifieUser = rs.getString("modifieduser") ;
return new ProvisioningEntryData(id, journalEntry, createdById, createdUser, createdDate, modifiedById, modifieUser);
Long id = rs.getLong("id");
Boolean journalEntry = rs.getBoolean("journal_entry_created");
Long createdById = rs.getLong("createdby_id");
String createdUser = rs.getString("createduser");
Date createdDate = rs.getDate("created_date");
Long modifiedById = rs.getLong("lastmodifiedby_id");
String modifieUser = rs.getString("modifieduser");
BigDecimal totalReservedAmount = null;
return new ProvisioningEntryData(id, journalEntry, createdById, createdUser, createdDate, modifiedById, modifieUser,
totalReservedAmount);
}
public String getSchema() {
return sqlQuery.toString() ;
return sqlQuery.toString();
}
}
private static final class LoanProductProvisioningEntryRowMapper implements RowMapper<LoanProductProvisioningEntryData> {
private final StringBuilder sqlQuery = new StringBuilder()
.append("select entry.id, entry.history_id as historyId, office_id, entry.criteria_id as criteriaid, office.name as officename, product.name as productname, entry.product_id, ")
.append("category_id, category.category_name, liability.id as liabilityid, liability.gl_code as liabilitycode, liability.name as liabilityname, ")
.append("expense.id as expenseid, expense.gl_code as expensecode, expense.name as expensename, entry.currency_code, entry.overdue_in_days, entry.reseve_amount from m_loanproduct_provisioning_entry entry ")
.append("left join m_office office ON office.id = entry.office_id ")
.append("left join m_product_loan product ON product.id = entry.product_id ")
.append("left join m_provision_category category ON category.id = entry.category_id ")
.append("left join acc_gl_account liability ON liability.id = entry.liability_account ")
.append("left join acc_gl_account expense ON expense.id = entry.expense_account ") ;
.append(" entry.id, entry.history_id as historyId, office_id, entry.criteria_id as criteriaid, office.name as officename, product.name as productname, entry.product_id, ")
.append("category_id, category.category_name, liability.id as liabilityid, liability.gl_code as liabilitycode, liability.name as liabilityname, ")
.append("expense.id as expenseid, expense.gl_code as expensecode, expense.name as expensename, entry.currency_code, entry.overdue_in_days, entry.reseve_amount from m_loanproduct_provisioning_entry entry ")
.append("left join m_office office ON office.id = entry.office_id ")
.append("left join m_product_loan product ON product.id = entry.product_id ")
.append("left join m_provision_category category ON category.id = entry.category_id ")
.append("left join acc_gl_account liability ON liability.id = entry.liability_account ")
.append("left join acc_gl_account expense ON expense.id = entry.expense_account ");
@Override
@SuppressWarnings("unused")
public LoanProductProvisioningEntryData mapRow(ResultSet rs, int rowNum) throws SQLException {
Long historyId = rs.getLong("historyId") ;
Long historyId = rs.getLong("historyId");
Long officeId = rs.getLong("office_id");
String officeName = rs.getString("officename") ;
String officeName = rs.getString("officename");
Long productId = rs.getLong("product_id");
String productName = rs.getString("productname") ;
String productName = rs.getString("productname");
String currentcyCode = rs.getString("currency_code");
Long overdueDays = rs.getLong("overdue_in_days");
Long categoryId = rs.getLong("category_id");
String categoryName = rs.getString("category_name") ;
String categoryName = rs.getString("category_name");
BigDecimal amountreserved = rs.getBigDecimal("reseve_amount");
Long liabilityAccountCode = rs.getLong("liabilityid");
String liabilityAccountglCode = rs.getString("liabilitycode") ;
String expenseAccountglCode = rs.getString("expensecode") ;
String liabilityAccountglCode = rs.getString("liabilitycode");
String expenseAccountglCode = rs.getString("expensecode");
Long expenseAccountCode = rs.getLong("expenseid");
Long criteriaId = rs.getLong("criteriaid") ;
String liabilityAccountName = rs.getString("liabilityname") ;
String expenseAccountName = rs.getString("expensename") ;
return new LoanProductProvisioningEntryData(historyId, officeId, officeName, currentcyCode, productId, productName, categoryId, categoryName, overdueDays, amountreserved,
liabilityAccountCode, liabilityAccountglCode, liabilityAccountName, expenseAccountCode, expenseAccountglCode, expenseAccountName, criteriaId);
Long criteriaId = rs.getLong("criteriaid");
String liabilityAccountName = rs.getString("liabilityname");
String expenseAccountName = rs.getString("expensename");
return new LoanProductProvisioningEntryData(historyId, officeId, officeName, currentcyCode, productId, productName, categoryId,
categoryName, overdueDays, amountreserved, liabilityAccountCode, liabilityAccountglCode, liabilityAccountName,
expenseAccountCode, expenseAccountglCode, expenseAccountName, criteriaId);
}
public String getSchema() {
return sqlQuery.toString() ;
return sqlQuery.toString();
}
}
@Override
public Collection<ProvisioningEntryData> retrieveAllProvisioningEntries() {
ProvisioningEntryDataMapper mapper = new ProvisioningEntryDataMapper() ;
final String sql1 = mapper.getSchema() + " order by entry.created_date ";
return this.jdbcTemplate.query(sql1, mapper, new Object[] {});
private static final class ProvisioningEntryDataMapperWithSumReserved implements RowMapper<ProvisioningEntryData> {
private final StringBuilder sqlQuery = new StringBuilder()
.append(" entry.id, journal_entry_created, createdby_id, created_date, created.username as createduser,")
.append("lastmodifiedby_id, modified.username as modifieduser, lastmodified_date, SUM(reserved.reseve_amount) as totalreserved ")
.append("from m_provisioning_history entry ")
.append("JOIN m_loanproduct_provisioning_entry reserved on entry.id = reserved.history_id ")
.append("left JOIN m_appuser created ON created.id = entry.createdby_id ")
.append("left JOIN m_appuser modified ON modified.id = entry.lastmodifiedby_id ");
@Override
@SuppressWarnings("unused")
public ProvisioningEntryData mapRow(ResultSet rs, int rowNum) throws SQLException {
Long id = rs.getLong("id");
Boolean journalEntry = rs.getBoolean("journal_entry_created");
Long createdById = rs.getLong("createdby_id");
String createdUser = rs.getString("createduser");
Date createdDate = rs.getDate("created_date");
Long modifiedById = rs.getLong("lastmodifiedby_id");
String modifieUser = rs.getString("modifieduser");
BigDecimal totalReservedAmount = rs.getBigDecimal("totalreserved");
return new ProvisioningEntryData(id, journalEntry, createdById, createdUser, createdDate, modifiedById, modifieUser,
totalReservedAmount);
}
public String getSchema() {
return sqlQuery.toString();
}
}
@Override
public Page<ProvisioningEntryData> retrieveAllProvisioningEntries(Integer offset, Integer limit) {
ProvisioningEntryDataMapper mapper = new ProvisioningEntryDataMapper();
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("select SQL_CALC_FOUND_ROWS ");
sqlBuilder.append(mapper.getSchema());
sqlBuilder.append(" order by entry.created_date");
sqlBuilder.append(" limit ").append(limit);
sqlBuilder.append(" offset ").append(offset);
final String sqlCountRows = "SELECT FOUND_ROWS()";
Object[] whereClauseItemsitems = new Object[] {};
return this.provisioningEntryDataPaginationHelper.fetchPage(this.jdbcTemplate, sqlCountRows, sqlBuilder.toString(),
whereClauseItemsitems, mapper);
}
@Override
public ProvisioningEntryData retrieveProvisioningEntryData(String date) {
ProvisioningEntryDataMapper mapper1 = new ProvisioningEntryDataMapper() ;
final String sql1 = mapper1.getSchema() + " where entry.created_date like " + "'"+date+"%'" ;
ProvisioningEntryData data = null ;
ProvisioningEntryDataMapper mapper1 = new ProvisioningEntryDataMapper();
final String sql1 = "select " + mapper1.getSchema() + " where entry.created_date like " + "'" + date + "%'";
ProvisioningEntryData data = null;
try {
data= this.jdbcTemplate.queryForObject(sql1, mapper1, new Object[] {});
}catch(EmptyResultDataAccessException e) {
data = this.jdbcTemplate.queryForObject(sql1, mapper1, new Object[] {});
} catch (EmptyResultDataAccessException e) {
}
return data ;
return data;
}
@Override
public ProvisioningEntryData retrieveProvisioningEntryDataByCriteriaId(Long criteriaId) {
ProvisioningEntryData data = null ;
ProvisioningEntryData data = null;
LoanProductProvisioningEntryRowMapper mapper = new LoanProductProvisioningEntryRowMapper();
final String sql = mapper.getSchema() + " where entry.criteria_id = ?";
final String sql = "select " + mapper.getSchema() + " where entry.criteria_id = ?";
Collection<LoanProductProvisioningEntryData> entries = this.jdbcTemplate.query(sql, mapper, new Object[] { criteriaId });
if(entries != null && entries.size() > 0) {
Long entryId = ((LoanProductProvisioningEntryData)entries.toArray()[0]).getHistoryId() ;
ProvisioningEntryDataMapper mapper1 = new ProvisioningEntryDataMapper() ;
final String sql1 = mapper1.getSchema() + " where entry.id = ?";
data= this.jdbcTemplate.queryForObject(sql1, mapper1, new Object[] { entryId });
data.setEntries(entries) ;
if (entries != null && entries.size() > 0) {
Long entryId = ((LoanProductProvisioningEntryData) entries.toArray()[0]).getHistoryId();
ProvisioningEntryDataMapper mapper1 = new ProvisioningEntryDataMapper();
final String sql1 = "select " + mapper1.getSchema() + " where entry.id = ?";
data = this.jdbcTemplate.queryForObject(sql1, mapper1, new Object[] { entryId });
data.setEntries(entries);
}
return data ;
return data;
}
@Override
public ProvisioningEntryData retrieveExistingProvisioningIdDateWithJournals() {
ProvisioningEntryData data = null ;
ProvisioningEntryIdDateRowMapper mapper = new ProvisioningEntryIdDateRowMapper() ;
ProvisioningEntryData data = null;
ProvisioningEntryIdDateRowMapper mapper = new ProvisioningEntryIdDateRowMapper();
try {
data = this.jdbcTemplate.queryForObject(mapper.schema(), mapper, new Object[] {});
}catch(EmptyResultDataAccessException e) {
data = null ;
data = this.jdbcTemplate.queryForObject(mapper.schema(), mapper, new Object[] {});
} catch (EmptyResultDataAccessException e) {
data = null;
}
return data ;
return data;
}
private static final class ProvisioningEntryIdDateRowMapper implements RowMapper<ProvisioningEntryData> {
StringBuffer buff = new StringBuffer()
.append("select history1.id, history1.created_date from m_provisioning_history history1 ")
.append("where history1.created_date = (select max(history2.created_date) from m_provisioning_history history2 ")
.append("where history2.journal_entry_created='1')");
StringBuffer buff = new StringBuffer().append("select history1.id, history1.created_date from m_provisioning_history history1 ")
.append("where history1.created_date = (select max(history2.created_date) from m_provisioning_history history2 ")
.append("where history2.journal_entry_created='1')");
@Override
@SuppressWarnings("unused")
public ProvisioningEntryData mapRow(ResultSet rs, int rowNum) throws SQLException {
Map<String, Object> map = new HashMap<>() ;
Long id = rs.getLong("id") ;
Date createdDate = rs.getDate("created_date") ;
Long createdBy = null ;
String createdName = null ;
Long modifiedBy = null ;
String modifiedName = null ;
return new ProvisioningEntryData(id, Boolean.TRUE, createdBy, createdName, createdDate, modifiedBy, modifiedName) ;
Map<String, Object> map = new HashMap<>();
Long id = rs.getLong("id");
Date createdDate = rs.getDate("created_date");
Long createdBy = null;
String createdName = null;
Long modifiedBy = null;
String modifiedName = null;
BigDecimal totalReservedAmount = null;
return new ProvisioningEntryData(id, Boolean.TRUE, createdBy, createdName, createdDate, modifiedBy, modifiedName,
totalReservedAmount);
}
public String schema() {
return buff.toString() ;
public String schema() {
return buff.toString();
}
}
@Override
public Page<LoanProductProvisioningEntryData> retrieveProvisioningEntries(SearchParameters searchParams) {
LoanProductProvisioningEntryRowMapper mapper = new LoanProductProvisioningEntryRowMapper();
final StringBuilder sqlBuilder = new StringBuilder(200);
sqlBuilder.append("select SQL_CALC_FOUND_ROWS ");
sqlBuilder.append(mapper.getSchema());
String whereClose = " where ";
List<Object> items = new ArrayList<>();
if (searchParams.isProvisioningEntryIdPassed()) {
sqlBuilder.append(whereClose + " entry.history_id = ?");
items.add(searchParams.getProvisioningEntryId());
whereClose = " and ";
}
if (searchParams.isOfficeIdPassed()) {
sqlBuilder.append(whereClose + " entry.office_id = ?");
items.add(searchParams.getOfficeId());
whereClose = " and ";
}
if (searchParams.isProductIdPassed()) {
sqlBuilder.append(whereClose + " entry.product_id = ?");
items.add(searchParams.getProductId());
whereClose = " and ";
}
if (searchParams.isCategoryIdPassed()) {
sqlBuilder.append(whereClose + " entry.category_id = ?");
items.add(searchParams.getCategoryId());
}
sqlBuilder.append(" order by entry.id");
if (searchParams.isLimited()) {
sqlBuilder.append(" limit ").append(searchParams.getLimit());
if (searchParams.isOffset()) {
sqlBuilder.append(" offset ").append(searchParams.getOffset());
}
}
Object[] whereClauseItemsitems = items.toArray();
final String sqlCountRows = "SELECT FOUND_ROWS()";
return this.loanProductProvisioningEntryDataPaginationHelper.fetchPage(this.jdbcTemplate, sqlCountRows, sqlBuilder.toString(),
whereClauseItemsitems, mapper);
}
}
@@ -30,6 +30,11 @@ public final class SearchParameters {
private final Long savingsId;
private final Boolean orphansOnly;
//Provisning Entries Search Params
private final Long provisioningEntryId ;
private final Long productId ;
private final Long categoryId ;
public static SearchParameters from(final String sqlSearch, final Long officeId, final String externalId, final String name,
final String hierarchy) {
final Long staffId = null;
@@ -134,6 +139,11 @@ public final class SearchParameters {
loanId, savingsId, orphansOnly);
}
public final static SearchParameters forProvisioningEntries(final Long provisioningEntryId, final Long officeId, final Long productId,
final Long categoryId, final Integer offset, final Integer limit) {
return new SearchParameters(provisioningEntryId, officeId, productId, categoryId, offset, limit) ;
}
public static SearchParameters forSavings(final String sqlSearch, final String externalId, final Integer offset, final Integer limit,
final String orderBy, final String sortOrder) {
@@ -183,8 +193,37 @@ public final class SearchParameters {
this.savingsId = savingsId;
this.orphansOnly = orphansOnly;
this.currencyCode = null;
this.provisioningEntryId = null ;
this.productId = null ;
this.categoryId = null ;
}
private SearchParameters(final Long provisioningEntryId, final Long officeId, final Long productId, final Long categoryId,
final Integer offset, final Integer limit) {
this.sqlSearch = null;
this.externalId = null;
this.name = null;
this.hierarchy = null;
this.firstname = null;
this.lastname = null;
this.orderBy = null;
this.sortOrder = null;
this.staffId = null;
this.accountNo = null;
this.loanId = null;
this.savingsId = null;
this.orphansOnly = null;
this.currencyCode = null;
this.officeId = officeId;
this.offset = offset;
this.limit = limit;
this.provisioningEntryId = provisioningEntryId ;
this.productId = productId ;
this.categoryId = categoryId ;
}
public SearchParameters(final String sqlSearch, final Long officeId, final String externalId, final String name, final String hierarchy,
final String firstname, final String lastname, final Integer offset, final Integer limit, final String orderBy,
final String sortOrder, final Long staffId, final String accountNo, final Long loanId, final Long savingsId,
@@ -206,6 +245,9 @@ public final class SearchParameters {
this.savingsId = savingsId;
this.orphansOnly = orphansOnly;
this.currencyCode = currencyCode;
this.provisioningEntryId = null ;
this.productId = null ;
this.categoryId = null ;
}
public boolean isOrderByRequested() {
@@ -331,6 +373,28 @@ public final class SearchParameters {
public Boolean isOrphansOnly() {
if (this.orphansOnly != null) { return this.orphansOnly; }
return false;
}
public Long getProvisioningEntryId() {
return this.provisioningEntryId;
}
public boolean isProvisioningEntryIdPassed() {
return this.provisioningEntryId != null && this.provisioningEntryId != 0 ;
}
public Long getProductId() {
return this.productId;
}
public boolean isProductIdPassed() {
return this.productId != null && this.productId != 0 ;
}
public Long getCategoryId() {
return this.categoryId;
}
public boolean isCategoryIdPassed() {
return this.categoryId != null && this.categoryId != 0 ;
}
}
@@ -58,7 +58,6 @@ public class ProvisioningCategoryApiResource {
}
@GET
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveAll(@Context final UriInfo uriInfo) {