Skip to content

Commit

Permalink
Mifosx 1523 - Loan Rescheduling modification
Browse files Browse the repository at this point in the history
  • Loading branch information
nazeer1100126 committed Sep 15, 2015
1 parent 928dbcc commit f094d13
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,14 @@ public RescheduleLoansApiResource(final DefaultToApiJsonSerializer<LoanReschedul
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveTemplate(@Context final UriInfo uriInfo, @QueryParam("commandParam") final String commandParam) {
public String retrieveTemplate(@Context final UriInfo uriInfo) {

this.platformSecurityContext.authenticatedUser().validateHasReadPermission(RescheduleLoansApiConstants.ENTITY_NAME);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());

LoanRescheduleRequestData loanRescheduleReasons = null;
if (compareIgnoreCase(commandParam, "rescheduleReason")) {
loanRescheduleReasons = this.loanRescheduleRequestReadPlatformService
.retrieveAllRescheduleReasons(RescheduleLoansApiConstants.LOAN_RESCHEDULE_REASON);
}
loanRescheduleReasons = this.loanRescheduleRequestReadPlatformService
.retrieveAllRescheduleReasons(RescheduleLoansApiConstants.LOAN_RESCHEDULE_REASON);

return this.loanRescheduleRequestToApiJsonSerializer.serialize(settings, loanRescheduleReasons);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,85 +32,84 @@

@Service
public class LoanRescheduleRequestReadPlatformServiceImpl implements LoanRescheduleRequestReadPlatformService {
private final JdbcTemplate jdbcTemplate;
private final LoanRepository loanRepository;
private final LoanRescheduleRequestRowMapper loanRescheduleRequestRowMapper = new LoanRescheduleRequestRowMapper();
private final CodeValueReadPlatformService codeValueReadPlatformService;
@Autowired
public LoanRescheduleRequestReadPlatformServiceImpl(final RoutingDataSource dataSource,
LoanRepository loanRepository, final CodeValueReadPlatformService codeValueReadPlatformService) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.loanRepository = loanRepository;
this.codeValueReadPlatformService = codeValueReadPlatformService ;
}
private static final class LoanRescheduleRequestRowMapper implements RowMapper<LoanRescheduleRequestData> {
private final String schema;
public LoanRescheduleRequestRowMapper() {
final StringBuilder sqlBuilder = new StringBuilder(200);
sqlBuilder.append("lr.id as id, lr.loan_id as loanId, lr.status_enum as statusEnum, ");
sqlBuilder.append("mc.display_name as clientName, ");
sqlBuilder.append("mc.id as clientId, ");
sqlBuilder.append("ml.account_no as loanAccountNumber, ");
sqlBuilder.append("lr.reschedule_from_installment as rescheduleFromInstallment, ");
sqlBuilder.append("lr.grace_on_principal as graceOnPrincipal, ");
sqlBuilder.append("lr.grace_on_interest as graceOnInterest, ");
sqlBuilder.append("lr.reschedule_from_date as rescheduleFromDate, ");
sqlBuilder.append("lr.adjusted_due_date as adjustedDueDate, ");
sqlBuilder.append("lr.extra_terms as extraTerms, ");
sqlBuilder.append("lr.recalculate_interest as recalculateInterest, ");
sqlBuilder.append("lr.interest_rate as interestRate, ");
sqlBuilder.append("lr.reschedule_reason_cv_id as rescheduleReasonCvId, ");
sqlBuilder.append("cv.code_value as rescheduleReasonCvValue, ");
sqlBuilder.append("lr.reschedule_reason_comment as rescheduleReasonComment, ");
sqlBuilder.append("lr.submitted_on_date as submittedOnDate, ");
sqlBuilder.append("sbu.username as submittedByUsername, ");
sqlBuilder.append("sbu.firstname as submittedByFirstname, ");
sqlBuilder.append("sbu.lastname as submittedByLastname, ");
sqlBuilder.append("lr.approved_on_date as approvedOnDate, ");
sqlBuilder.append("abu.username as approvedByUsername, ");
sqlBuilder.append("abu.firstname as approvedByFirstname, ");
sqlBuilder.append("abu.lastname as approvedByLastname, ");
sqlBuilder.append("lr.rejected_on_date as rejectedOnDate, ");
sqlBuilder.append("rbu.username as rejectedByUsername, ");
sqlBuilder.append("rbu.firstname as rejectedByFirstname, ");
sqlBuilder.append("rbu.lastname as rejectedByLastname ");
sqlBuilder.append("from " + loanRescheduleRequestTableName() + " lr ");
sqlBuilder.append("left join m_code_value cv on cv.id = lr.reschedule_reason_cv_id ");
sqlBuilder.append("left join m_appuser sbu on sbu.id = lr.submitted_by_user_id ");
sqlBuilder.append("left join m_appuser abu on abu.id = lr.approved_by_user_id ");
sqlBuilder.append("left join m_appuser rbu on rbu.id = lr.rejected_by_user_id ");
sqlBuilder.append("left join m_loan ml on ml.id = lr.loan_id ");
sqlBuilder.append("left join m_client mc on mc.id = ml.client_id ");
this.schema = sqlBuilder.toString();
}
public String schema() {

private final JdbcTemplate jdbcTemplate;
private final LoanRepository loanRepository;
private final LoanRescheduleRequestRowMapper loanRescheduleRequestRowMapper = new LoanRescheduleRequestRowMapper();
private final CodeValueReadPlatformService codeValueReadPlatformService;

@Autowired
public LoanRescheduleRequestReadPlatformServiceImpl(final RoutingDataSource dataSource, LoanRepository loanRepository,
final CodeValueReadPlatformService codeValueReadPlatformService) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.loanRepository = loanRepository;
this.codeValueReadPlatformService = codeValueReadPlatformService;
}

private static final class LoanRescheduleRequestRowMapper implements RowMapper<LoanRescheduleRequestData> {

private final String schema;

public LoanRescheduleRequestRowMapper() {
final StringBuilder sqlBuilder = new StringBuilder(200);

sqlBuilder.append("lr.id as id, lr.loan_id as loanId, lr.status_enum as statusEnum, ");
sqlBuilder.append("mc.display_name as clientName, ");
sqlBuilder.append("mc.id as clientId, ");
sqlBuilder.append("ml.account_no as loanAccountNumber, ");
sqlBuilder.append("lr.reschedule_from_installment as rescheduleFromInstallment, ");
sqlBuilder.append("lr.grace_on_principal as graceOnPrincipal, ");
sqlBuilder.append("lr.grace_on_interest as graceOnInterest, ");
sqlBuilder.append("lr.reschedule_from_date as rescheduleFromDate, ");
sqlBuilder.append("lr.adjusted_due_date as adjustedDueDate, ");
sqlBuilder.append("lr.extra_terms as extraTerms, ");
sqlBuilder.append("lr.recalculate_interest as recalculateInterest, ");
sqlBuilder.append("lr.interest_rate as interestRate, ");
sqlBuilder.append("lr.reschedule_reason_cv_id as rescheduleReasonCvId, ");
sqlBuilder.append("cv.code_value as rescheduleReasonCvValue, ");
sqlBuilder.append("lr.reschedule_reason_comment as rescheduleReasonComment, ");

sqlBuilder.append("lr.submitted_on_date as submittedOnDate, ");
sqlBuilder.append("sbu.username as submittedByUsername, ");
sqlBuilder.append("sbu.firstname as submittedByFirstname, ");
sqlBuilder.append("sbu.lastname as submittedByLastname, ");

sqlBuilder.append("lr.approved_on_date as approvedOnDate, ");
sqlBuilder.append("abu.username as approvedByUsername, ");
sqlBuilder.append("abu.firstname as approvedByFirstname, ");
sqlBuilder.append("abu.lastname as approvedByLastname, ");

sqlBuilder.append("lr.rejected_on_date as rejectedOnDate, ");
sqlBuilder.append("rbu.username as rejectedByUsername, ");
sqlBuilder.append("rbu.firstname as rejectedByFirstname, ");
sqlBuilder.append("rbu.lastname as rejectedByLastname ");

sqlBuilder.append("from " + loanRescheduleRequestTableName() + " lr ");
sqlBuilder.append("left join m_code_value cv on cv.id = lr.reschedule_reason_cv_id ");
sqlBuilder.append("left join m_appuser sbu on sbu.id = lr.submitted_by_user_id ");
sqlBuilder.append("left join m_appuser abu on abu.id = lr.approved_by_user_id ");
sqlBuilder.append("left join m_appuser rbu on rbu.id = lr.rejected_by_user_id ");
sqlBuilder.append("left join m_loan ml on ml.id = lr.loan_id ");
sqlBuilder.append("left join m_client mc on mc.id = ml.client_id ");

this.schema = sqlBuilder.toString();
}

public String schema() {
return this.schema;
}
public String loanRescheduleRequestTableName() {
return "m_loan_reschedule_request";
}
@Override
@SuppressWarnings("unused")
public LoanRescheduleRequestData mapRow(final ResultSet rs, final int rowNum) throws SQLException {
final Long id = rs.getLong("id");

public String loanRescheduleRequestTableName() {
return "m_loan_reschedule_request";
}

@Override
@SuppressWarnings("unused")
public LoanRescheduleRequestData mapRow(final ResultSet rs, final int rowNum) throws SQLException {
final Long id = rs.getLong("id");
final Long loanId = rs.getLong("loanId");
final Integer statusEnumId = JdbcSupport.getInteger(rs, "statusEnum");
final LoanRescheduleRequestStatusEnumData statusEnum = LoanRescheduleRequestEnumerations
.status(statusEnumId);
final LoanRescheduleRequestStatusEnumData statusEnum = LoanRescheduleRequestEnumerations.status(statusEnumId);
final String clientName = rs.getString("clientName");
final String loanAccountNumber = rs.getString("loanAccountNumber");
final Long clientId = rs.getLong("clientId");
Expand All @@ -123,86 +122,96 @@ public LoanRescheduleRequestData mapRow(final ResultSet rs, final int rowNum) th
final BigDecimal interestRate = rs.getBigDecimal("interestRate");
final Long rescheduleReasonCvId = JdbcSupport.getLong(rs, "rescheduleReasonCvId");
final String rescheduleReasonCvValue = rs.getString("rescheduleReasonCvValue");
final CodeValueData rescheduleReasonCodeValue = CodeValueData
.instance(rescheduleReasonCvId, rescheduleReasonCvValue);
final CodeValueData rescheduleReasonCodeValue = CodeValueData.instance(rescheduleReasonCvId, rescheduleReasonCvValue);
final String rescheduleReasonComment = rs.getString("rescheduleReasonComment");
final Boolean recalculateInterest = rs.getBoolean("recalculateInterest");

final LocalDate submittedOnDate = JdbcSupport.getLocalDate(rs, "submittedOnDate");
final String submittedByUsername = rs.getString("submittedByUsername");
final String submittedByFirstname = rs.getString("submittedByFirstname");
final String submittedByLastname = rs.getString("submittedByLastname");

final LocalDate approvedOnDate = JdbcSupport.getLocalDate(rs, "approvedOnDate");
final String approvedByUsername = rs.getString("approvedByUsername");
final String approvedByFirstname = rs.getString("approvedByFirstname");
final String approvedByLastname = rs.getString("approvedByLastname");

final LocalDate rejectedOnDate = JdbcSupport.getLocalDate(rs, "rejectedOnDate");
final String rejectedByUsername = rs.getString("rejectedByUsername");
final String rejectedByFirstname = rs.getString("rejectedByFirstname");
final String rejectedByLastname = rs.getString("rejectedByLastname");
final Collection<CodeValueData> rescheduleReasons = null ;
final LoanRescheduleRequestTimelineData timeline = new LoanRescheduleRequestTimelineData(submittedOnDate,
submittedByUsername, submittedByFirstname, submittedByLastname, approvedOnDate, approvedByUsername,
approvedByFirstname, approvedByLastname, rejectedOnDate, rejectedByUsername, rejectedByFirstname,
rejectedByLastname);

return LoanRescheduleRequestData.instance(id, loanId, statusEnum, rescheduleFromInstallment, graceOnPrincipal,
graceOnInterest, rescheduleFromDate, adjustedDueDate, extraTerms, interestRate, rescheduleReasonCodeValue,
rescheduleReasonComment, timeline, clientName, loanAccountNumber, clientId, recalculateInterest, rescheduleReasons);
}

}

@Override
public List<LoanRescheduleRequestData> readLoanRescheduleRequests(Long loanId) {
final Loan loan = this.loanRepository.findOne(loanId);

if(loan == null) {
throw new LoanNotFoundException(loanId);
final Collection<CodeValueData> rescheduleReasons = null;
final LoanRescheduleRequestTimelineData timeline = new LoanRescheduleRequestTimelineData(submittedOnDate, submittedByUsername,
submittedByFirstname, submittedByLastname, approvedOnDate, approvedByUsername, approvedByFirstname, approvedByLastname,
rejectedOnDate, rejectedByUsername, rejectedByFirstname, rejectedByLastname);

return LoanRescheduleRequestData.instance(id, loanId, statusEnum, rescheduleFromInstallment, graceOnPrincipal, graceOnInterest,
rescheduleFromDate, adjustedDueDate, extraTerms, interestRate, rescheduleReasonCodeValue, rescheduleReasonComment,
timeline, clientName, loanAccountNumber, clientId, recalculateInterest, rescheduleReasons);
}

final String sql = "select " + this.loanRescheduleRequestRowMapper.schema() + " where lr.loan_id = ?";

return this.jdbcTemplate.query(sql, this.loanRescheduleRequestRowMapper, new Object[] { loanId });
}

@Override
public LoanRescheduleRequestData readLoanRescheduleRequest(Long requestId) {

try {
final String sql = "select " + this.loanRescheduleRequestRowMapper.schema() + " where lr.id = ?";

return this.jdbcTemplate.queryForObject(sql, this.loanRescheduleRequestRowMapper, new Object[] { requestId });
}

catch(final EmptyResultDataAccessException e) {
return null;
}
}

@Override
public List<LoanRescheduleRequestData> readLoanRescheduleRequests(Long loanId, Integer statusEnum) {
final Loan loan = this.loanRepository.findOne(loanId);

if(loan == null) {
throw new LoanNotFoundException(loanId);

}

@Override
public List<LoanRescheduleRequestData> readLoanRescheduleRequests(Long loanId) {
final Loan loan = this.loanRepository.findOne(loanId);

if (loan == null) { throw new LoanNotFoundException(loanId); }

final String sql = "select " + this.loanRescheduleRequestRowMapper.schema() + " where lr.loan_id = ?";

return this.jdbcTemplate.query(sql, this.loanRescheduleRequestRowMapper, new Object[] { loanId });
}

@Override
public LoanRescheduleRequestData readLoanRescheduleRequest(Long requestId) {

try {
final String sql = "select " + this.loanRescheduleRequestRowMapper.schema() + " where lr.id = ?";

return this.jdbcTemplate.queryForObject(sql, this.loanRescheduleRequestRowMapper, new Object[] { requestId });
}

final String sql = "select " + this.loanRescheduleRequestRowMapper.schema() + " where lr.loan_id = ?"
+ " and lr.status_enum = ?";

return this.jdbcTemplate.query(sql, this.loanRescheduleRequestRowMapper, new Object[] { loanId, statusEnum });
}

catch (final EmptyResultDataAccessException e) {
return null;
}
}

@Override
public List<LoanRescheduleRequestData> readLoanRescheduleRequests(Long loanId, Integer statusEnum) {
final Loan loan = this.loanRepository.findOne(loanId);

if (loan == null) { throw new LoanNotFoundException(loanId); }

final String sql = "select " + this.loanRescheduleRequestRowMapper.schema() + " where lr.loan_id = ?" + " and lr.status_enum = ?";

return this.jdbcTemplate.query(sql, this.loanRescheduleRequestRowMapper, new Object[] { loanId, statusEnum });
}

@Override
public LoanRescheduleRequestData retrieveAllRescheduleReasons(String loanRescheduleReason) {
final List<CodeValueData> rescheduleReasons = new ArrayList<>(
this.codeValueReadPlatformService.retrieveCodeValuesByCode(loanRescheduleReason));

return LoanRescheduleRequestData.instance(null, null, null, null, null, null,
null, null, null, null, null, null,
null, null, null, null, null,rescheduleReasons);
final Long id = null;
final Long loanId = null;
final LoanRescheduleRequestStatusEnumData statusEnum = null;
final Integer rescheduleFromInstallment = null;
final Integer graceOnPrincipal = null;
final Integer graceOnInterest = null;
final LocalDate rescheduleFromDate = null;
final LocalDate adjustedDueDate = null;
final Integer extraTerms = null;
final BigDecimal interestRate = null;
final CodeValueData rescheduleReasonCodeValue = null;
final String rescheduleReasonComment = null;
final LoanRescheduleRequestTimelineData timeline = null;
final String clientName = null;
final String loanAccountNumber = null;
final Long clientId = null;
final Boolean recalculateInterest = null;

return LoanRescheduleRequestData.instance(id, loanId, statusEnum, rescheduleFromInstallment, graceOnPrincipal, graceOnInterest,
rescheduleFromDate, adjustedDueDate, extraTerms, interestRate, rescheduleReasonCodeValue, rescheduleReasonComment,
timeline, clientName, loanAccountNumber, clientId, recalculateInterest, rescheduleReasons);
}
}

0 comments on commit f094d13

Please sign in to comment.