remove unused jobs
This commit is contained in:
committed by
Arnold Gálovics
parent
a5bfa43dad
commit
e7b2d6dff5
+3
-3
@@ -20,9 +20,9 @@ package org.apache.fineract.infrastructure.jobs.service;
|
|||||||
|
|
||||||
public enum JobName {
|
public enum JobName {
|
||||||
|
|
||||||
UPDATE_LOAN_SUMMARY("Update loan Summary"), UPDATE_LOAN_ARREARS_AGEING("Update Loan Arrears Ageing"), UPDATE_LOAN_PAID_IN_ADVANCE(
|
UPDATE_LOAN_ARREARS_AGEING("Update Loan Arrears Ageing"), APPLY_ANNUAL_FEE_FOR_SAVINGS(
|
||||||
"Update Loan Paid In Advance"), APPLY_ANNUAL_FEE_FOR_SAVINGS("Apply Annual Fee For Savings"), APPLY_HOLIDAYS_TO_LOANS(
|
"Apply Annual Fee For Savings"), APPLY_HOLIDAYS_TO_LOANS("Apply Holidays To Loans"), POST_INTEREST_FOR_SAVINGS(
|
||||||
"Apply Holidays To Loans"), POST_INTEREST_FOR_SAVINGS("Post Interest For Savings"), TRANSFER_FEE_CHARGE_FOR_LOANS(
|
"Post Interest For Savings"), TRANSFER_FEE_CHARGE_FOR_LOANS(
|
||||||
"Transfer Fee For Loans From Savings"), ACCOUNTING_RUNNING_BALANCE_UPDATE(
|
"Transfer Fee For Loans From Savings"), ACCOUNTING_RUNNING_BALANCE_UPDATE(
|
||||||
"Update Accounting Running Balances"), PAY_DUE_SAVINGS_CHARGES(
|
"Update Accounting Running Balances"), PAY_DUE_SAVINGS_CHARGES(
|
||||||
"Pay Due Savings Charges"), APPLY_CHARGE_TO_OVERDUE_LOAN_INSTALLMENT(
|
"Pay Due Savings Charges"), APPLY_CHARGE_TO_OVERDUE_LOAN_INSTALLMENT(
|
||||||
|
|||||||
+15
-33
@@ -32,6 +32,8 @@ import java.util.concurrent.ExecutionException;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
|
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
|
||||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||||
@@ -43,19 +45,16 @@ import org.apache.fineract.infrastructure.jobs.service.JobName;
|
|||||||
import org.apache.fineract.portfolio.savings.data.SavingsAccountData;
|
import org.apache.fineract.portfolio.savings.data.SavingsAccountData;
|
||||||
import org.apache.fineract.portfolio.savings.domain.SavingsAccountAssembler;
|
import org.apache.fineract.portfolio.savings.domain.SavingsAccountAssembler;
|
||||||
import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepositoryWrapper;
|
import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepositoryWrapper;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.support.TransactionTemplate;
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class SavingsSchedularServiceImpl implements SavingsSchedularService {
|
public class SavingsSchedularServiceImpl implements SavingsSchedularService {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(SavingsSchedularServiceImpl.class);
|
|
||||||
|
|
||||||
private final SavingsAccountAssembler savingAccountAssembler;
|
private final SavingsAccountAssembler savingAccountAssembler;
|
||||||
private final SavingsAccountWritePlatformService savingsAccountWritePlatformService;
|
private final SavingsAccountWritePlatformService savingsAccountWritePlatformService;
|
||||||
private final SavingsAccountReadPlatformService savingAccountReadPlatformService;
|
private final SavingsAccountReadPlatformService savingAccountReadPlatformService;
|
||||||
@@ -67,23 +66,6 @@ public class SavingsSchedularServiceImpl implements SavingsSchedularService {
|
|||||||
private Queue<List<SavingsAccountData>> queue = new ArrayDeque<>();
|
private Queue<List<SavingsAccountData>> queue = new ArrayDeque<>();
|
||||||
private int queueSize = 1;
|
private int queueSize = 1;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public SavingsSchedularServiceImpl(final SavingsAccountAssembler savingAccountAssembler,
|
|
||||||
final SavingsAccountWritePlatformService savingsAccountWritePlatformService,
|
|
||||||
final SavingsAccountReadPlatformService savingAccountReadPlatformService,
|
|
||||||
final SavingsAccountRepositoryWrapper savingsAccountRepository, final ApplicationContext applicationContext,
|
|
||||||
final ConfigurationDomainService configurationDomainService, final JdbcTemplate jdbcTemplate,
|
|
||||||
final TransactionTemplate transactionTemplate) {
|
|
||||||
this.savingAccountAssembler = savingAccountAssembler;
|
|
||||||
this.savingsAccountWritePlatformService = savingsAccountWritePlatformService;
|
|
||||||
this.savingAccountReadPlatformService = savingAccountReadPlatformService;
|
|
||||||
this.savingsAccountRepository = savingsAccountRepository;
|
|
||||||
this.applicationContext = applicationContext;
|
|
||||||
this.configurationDomainService = configurationDomainService;
|
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
|
||||||
this.transactionTemplate = transactionTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@CronTarget(jobName = JobName.POST_INTEREST_FOR_SAVINGS)
|
@CronTarget(jobName = JobName.POST_INTEREST_FOR_SAVINGS)
|
||||||
public void postInterestForAccounts(Map<String, String> jobParameters) throws JobExecutionException {
|
public void postInterestForAccounts(Map<String, String> jobParameters) throws JobExecutionException {
|
||||||
@@ -98,14 +80,14 @@ public class SavingsSchedularServiceImpl implements SavingsSchedularService {
|
|||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
LOG.info("Reading Savings Account Data!");
|
log.info("Reading Savings Account Data!");
|
||||||
List<SavingsAccountData> savingsAccounts = this.savingAccountReadPlatformService
|
List<SavingsAccountData> savingsAccounts = this.savingAccountReadPlatformService
|
||||||
.retrieveAllSavingsDataForInterestPosting(backdatedTxnsAllowedTill, pageSize, ACTIVE.getValue(), maxSavingsIdInList);
|
.retrieveAllSavingsDataForInterestPosting(backdatedTxnsAllowedTill, pageSize, ACTIVE.getValue(), maxSavingsIdInList);
|
||||||
|
|
||||||
if (savingsAccounts != null && savingsAccounts.size() > 0) {
|
if (savingsAccounts != null && savingsAccounts.size() > 0) {
|
||||||
savingsAccounts = Collections.synchronizedList(savingsAccounts);
|
savingsAccounts = Collections.synchronizedList(savingsAccounts);
|
||||||
long finish = System.currentTimeMillis();
|
long finish = System.currentTimeMillis();
|
||||||
LOG.info("Done fetching Data within {} milliseconds", finish - start);
|
log.info("Done fetching Data within {} milliseconds", finish - start);
|
||||||
if (savingsAccounts != null) {
|
if (savingsAccounts != null) {
|
||||||
queue.add(savingsAccounts);
|
queue.add(savingsAccounts);
|
||||||
}
|
}
|
||||||
@@ -113,7 +95,7 @@ public class SavingsSchedularServiceImpl implements SavingsSchedularService {
|
|||||||
if (!CollectionUtils.isEmpty(queue)) {
|
if (!CollectionUtils.isEmpty(queue)) {
|
||||||
do {
|
do {
|
||||||
int totalFilteredRecords = savingsAccounts.size();
|
int totalFilteredRecords = savingsAccounts.size();
|
||||||
LOG.info("Starting Interest posting - total records - {}", totalFilteredRecords);
|
log.info("Starting Interest posting - total records - {}", totalFilteredRecords);
|
||||||
List<SavingsAccountData> queueElement = queue.element();
|
List<SavingsAccountData> queueElement = queue.element();
|
||||||
maxSavingsIdInList = queueElement.get(queueElement.size() - 1).getId();
|
maxSavingsIdInList = queueElement.get(queueElement.size() - 1).getId();
|
||||||
postInterest(queue.remove(), threadPoolSize, batchSize, executorService, backdatedTxnsAllowedTill, pageSize,
|
postInterest(queue.remove(), threadPoolSize, batchSize, executorService, backdatedTxnsAllowedTill, pageSize,
|
||||||
@@ -156,7 +138,7 @@ public class SavingsSchedularServiceImpl implements SavingsSchedularService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (queue.size() <= queueSize) {
|
while (queue.size() <= queueSize) {
|
||||||
LOG.info("Fetching while threads are running!");
|
log.info("Fetching while threads are running!");
|
||||||
List<SavingsAccountData> savingsAccountDataList = Collections.synchronizedList(this.savingAccountReadPlatformService
|
List<SavingsAccountData> savingsAccountDataList = Collections.synchronizedList(this.savingAccountReadPlatformService
|
||||||
.retrieveAllSavingsDataForInterestPosting(backdatedTxnsAllowedTill, pageSize, ACTIVE.getValue(), maxId));
|
.retrieveAllSavingsDataForInterestPosting(backdatedTxnsAllowedTill, pageSize, ACTIVE.getValue(), maxId));
|
||||||
if (savingsAccountDataList == null || savingsAccountDataList.isEmpty()) {
|
if (savingsAccountDataList == null || savingsAccountDataList.isEmpty()) {
|
||||||
@@ -207,21 +189,21 @@ public class SavingsSchedularServiceImpl implements SavingsSchedularService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (queue.size() <= queueSize) {
|
while (queue.size() <= queueSize) {
|
||||||
LOG.info("Fetching while threads are running!..:: this is not supposed to run........");
|
log.info("Fetching while threads are running!..:: this is not supposed to run........");
|
||||||
savingsAccounts = Collections.synchronizedList(this.savingAccountReadPlatformService
|
savingsAccounts = Collections.synchronizedList(this.savingAccountReadPlatformService
|
||||||
.retrieveAllSavingsDataForInterestPosting(backdatedTxnsAllowedTill, pageSize, ACTIVE.getValue(), maxId));
|
.retrieveAllSavingsDataForInterestPosting(backdatedTxnsAllowedTill, pageSize, ACTIVE.getValue(), maxId));
|
||||||
if (savingsAccounts == null || savingsAccounts.isEmpty()) {
|
if (savingsAccounts == null || savingsAccounts.isEmpty()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
maxId = savingsAccounts.get(savingsAccounts.size() - 1).getId();
|
maxId = savingsAccounts.get(savingsAccounts.size() - 1).getId();
|
||||||
LOG.info("Add to the Queue");
|
log.info("Add to the Queue");
|
||||||
queue.add(savingsAccounts);
|
queue.add(savingsAccounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkCompletion(responses);
|
checkCompletion(responses);
|
||||||
LOG.info("Queue size {}", queue.size());
|
log.info("Queue size {}", queue.size());
|
||||||
} catch (InterruptedException e1) {
|
} catch (InterruptedException e1) {
|
||||||
LOG.error("Interrupted while postInterest", e1);
|
log.error("Interrupted while postInterest", e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,12 +235,12 @@ public class SavingsSchedularServiceImpl implements SavingsSchedularService {
|
|||||||
}
|
}
|
||||||
allThreadsExecuted = noOfThreadsExecuted == responses.size();
|
allThreadsExecuted = noOfThreadsExecuted == responses.size();
|
||||||
if (!allThreadsExecuted) {
|
if (!allThreadsExecuted) {
|
||||||
LOG.error("All threads could not execute.");
|
log.error("All threads could not execute.");
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e1) {
|
} catch (InterruptedException e1) {
|
||||||
LOG.error("Interrupted while interest posting entries", e1);
|
log.error("Interrupted while interest posting entries", e1);
|
||||||
} catch (ExecutionException e2) {
|
} catch (ExecutionException e2) {
|
||||||
LOG.error("Execution exception while interest posting entries", e2);
|
log.error("Execution exception while interest posting entries", e2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-4
@@ -22,10 +22,6 @@ import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException;
|
|||||||
|
|
||||||
public interface ScheduledJobRunnerService {
|
public interface ScheduledJobRunnerService {
|
||||||
|
|
||||||
void updateLoanSummaryDetails();
|
|
||||||
|
|
||||||
void updateLoanPaidInAdvance();
|
|
||||||
|
|
||||||
void applyAnnualFeeForSavings();
|
void applyAnnualFeeForSavings();
|
||||||
|
|
||||||
void applyDueChargesForSavings() throws JobExecutionException;
|
void applyDueChargesForSavings() throws JobExecutionException;
|
||||||
|
|||||||
-121
@@ -113,127 +113,6 @@ public class ScheduledJobRunnerServiceImpl implements ScheduledJobRunnerService
|
|||||||
this.databaseTypeResolver = databaseTypeResolver;
|
this.databaseTypeResolver = databaseTypeResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
@Override
|
|
||||||
@CronTarget(jobName = JobName.UPDATE_LOAN_SUMMARY)
|
|
||||||
public void updateLoanSummaryDetails() {
|
|
||||||
|
|
||||||
final JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSourceServiceFactory.determineDataSourceService().retrieveDataSource());
|
|
||||||
|
|
||||||
boolean isMySQL = databaseTypeResolver.isMySQL();
|
|
||||||
|
|
||||||
String alias = isMySQL ? "l." : "";
|
|
||||||
final String selectPart = new StringBuilder().append(" (SELECT ml.id AS loan_id, ")
|
|
||||||
.append("SUM(mr.principal_amount) as principal_disbursed_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.principal_completed_derived,0)) as principal_repaid_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.principal_writtenoff_derived,0)) as principal_writtenoff_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.interest_amount,0)) as interest_charged_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.interest_completed_derived,0)) as interest_repaid_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.interest_waived_derived,0)) as interest_waived_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.interest_writtenoff_derived,0)) as interest_writtenoff_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.fee_charges_amount,0)) + ")
|
|
||||||
.append("COALESCE((select SUM(lc.amount) from m_loan_charge lc where lc.loan_id = ml.id and lc.is_active = true")
|
|
||||||
.append(" and lc.charge_time_enum=1),0) as fee_charges_charged_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.fee_charges_completed_derived,0)) + ")
|
|
||||||
.append("COALESCE((select SUM(lc.amount_paid_derived) from m_loan_charge lc where lc.loan_id = ml.id and lc.is_active = true")
|
|
||||||
.append(" and lc.charge_time_enum = 1), 0) as fee_charges_repaid_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.fee_charges_waived_derived,0)) as fee_charges_waived_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.fee_charges_writtenoff_derived,0)) as fee_charges_writtenoff_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.penalty_charges_amount,0)) as penalty_charges_charged_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.penalty_charges_completed_derived,0)) as penalty_charges_repaid_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.penalty_charges_waived_derived,0)) as penalty_charges_waived_derived, ")
|
|
||||||
.append("SUM(COALESCE(mr.penalty_charges_writtenoff_derived,0)) as penalty_charges_writtenoff_derived ")
|
|
||||||
.append("FROM m_loan ml ").append("INNER JOIN m_loan_repayment_schedule mr on mr.loan_id = ml.id ")
|
|
||||||
.append("WHERE ml.disbursedon_date is not null ").append("GROUP BY ml.id").append(") x").toString();
|
|
||||||
|
|
||||||
final String setPart = new StringBuilder().append(" SET ").append(alias)
|
|
||||||
.append("principal_disbursed_derived = x.principal_disbursed_derived, ").append(alias)
|
|
||||||
.append("principal_repaid_derived = x.principal_repaid_derived, ").append(alias)
|
|
||||||
.append("principal_writtenoff_derived = x.principal_writtenoff_derived, ").append(alias)
|
|
||||||
.append("principal_outstanding_derived = (x.principal_disbursed_derived - (x.principal_repaid_derived + x.principal_writtenoff_derived)), ")
|
|
||||||
.append(alias).append("interest_charged_derived = x.interest_charged_derived, ").append(alias)
|
|
||||||
.append("interest_repaid_derived = x.interest_repaid_derived, ").append(alias)
|
|
||||||
.append("interest_waived_derived = x.interest_waived_derived, ").append(alias)
|
|
||||||
.append("interest_writtenoff_derived = x.interest_writtenoff_derived, ").append(alias)
|
|
||||||
.append("interest_outstanding_derived = (x.interest_charged_derived - (x.interest_repaid_derived + x.interest_waived_derived + x.interest_writtenoff_derived)), ")
|
|
||||||
.append(alias).append("fee_charges_charged_derived = x.fee_charges_charged_derived, ").append(alias)
|
|
||||||
.append("fee_charges_repaid_derived = x.fee_charges_repaid_derived, ").append(alias)
|
|
||||||
.append("fee_charges_waived_derived = x.fee_charges_waived_derived, ").append(alias)
|
|
||||||
.append("fee_charges_writtenoff_derived = x.fee_charges_writtenoff_derived, ").append(alias)
|
|
||||||
.append("fee_charges_outstanding_derived = (x.fee_charges_charged_derived - (x.fee_charges_repaid_derived + x.fee_charges_waived_derived + x.fee_charges_writtenoff_derived)), ")
|
|
||||||
.append(alias).append("penalty_charges_charged_derived = x.penalty_charges_charged_derived, ").append(alias)
|
|
||||||
.append("penalty_charges_repaid_derived = x.penalty_charges_repaid_derived, ").append(alias)
|
|
||||||
.append("penalty_charges_waived_derived = x.penalty_charges_waived_derived, ").append(alias)
|
|
||||||
.append("penalty_charges_writtenoff_derived = x.penalty_charges_writtenoff_derived, ").append(alias)
|
|
||||||
.append("penalty_charges_outstanding_derived = (x.penalty_charges_charged_derived - (x.penalty_charges_repaid_derived + x.penalty_charges_waived_derived + x.penalty_charges_writtenoff_derived)), ")
|
|
||||||
.append(alias)
|
|
||||||
.append("total_expected_repayment_derived = (x.principal_disbursed_derived + x.interest_charged_derived + x.fee_charges_charged_derived + x.penalty_charges_charged_derived), ")
|
|
||||||
.append(alias)
|
|
||||||
.append("total_repayment_derived = (x.principal_repaid_derived + x.interest_repaid_derived + x.fee_charges_repaid_derived + x.penalty_charges_repaid_derived), ")
|
|
||||||
.append(alias)
|
|
||||||
.append("total_expected_costofloan_derived = (x.interest_charged_derived + x.fee_charges_charged_derived + x.penalty_charges_charged_derived), ")
|
|
||||||
.append(alias)
|
|
||||||
.append("total_costofloan_derived = (x.interest_repaid_derived + x.fee_charges_repaid_derived + x.penalty_charges_repaid_derived), ")
|
|
||||||
.append(alias)
|
|
||||||
.append("total_waived_derived = (x.interest_waived_derived + x.fee_charges_waived_derived + x.penalty_charges_waived_derived), ")
|
|
||||||
.append(alias)
|
|
||||||
.append("total_writtenoff_derived = (x.interest_writtenoff_derived + x.fee_charges_writtenoff_derived + x.penalty_charges_writtenoff_derived), ")
|
|
||||||
.append(alias)
|
|
||||||
.append("total_outstanding_derived = (x.principal_disbursed_derived - (x.principal_repaid_derived + x.principal_writtenoff_derived)) + ")
|
|
||||||
.append("(x.interest_charged_derived - (x.interest_repaid_derived + x.interest_waived_derived + x.interest_writtenoff_derived)) + ")
|
|
||||||
.append("(x.fee_charges_charged_derived - (x.fee_charges_repaid_derived + x.fee_charges_waived_derived + x.fee_charges_writtenoff_derived)) + ")
|
|
||||||
.append("(x.penalty_charges_charged_derived - (x.penalty_charges_repaid_derived + x.penalty_charges_waived_derived + x.penalty_charges_writtenoff_derived))")
|
|
||||||
.toString();
|
|
||||||
|
|
||||||
String wherePart = " x.loan_id = l.id";
|
|
||||||
|
|
||||||
final StringBuilder updateSqlBuilder = new StringBuilder();
|
|
||||||
updateSqlBuilder.append("UPDATE m_loan l");
|
|
||||||
if (isMySQL) {
|
|
||||||
updateSqlBuilder.append(" JOIN").append(selectPart).append(" ON").append(wherePart).append(' ').append(setPart);
|
|
||||||
} else {
|
|
||||||
updateSqlBuilder.append(setPart).append(" FROM").append(selectPart).append(" WHERE").append(wherePart);
|
|
||||||
}
|
|
||||||
final int result = jdbcTemplate.update(updateSqlBuilder.toString());
|
|
||||||
|
|
||||||
LOG.info("{}: Records affected by updateLoanSummaryDetails: {}", ThreadLocalContextUtil.getTenant().getName(), result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
@Override
|
|
||||||
@CronTarget(jobName = JobName.UPDATE_LOAN_PAID_IN_ADVANCE)
|
|
||||||
public void updateLoanPaidInAdvance() {
|
|
||||||
|
|
||||||
final JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSourceServiceFactory.determineDataSourceService().retrieveDataSource());
|
|
||||||
|
|
||||||
jdbcTemplate.execute("truncate table m_loan_paid_in_advance");
|
|
||||||
|
|
||||||
final StringBuilder updateSqlBuilder = new StringBuilder(900);
|
|
||||||
|
|
||||||
updateSqlBuilder.append(
|
|
||||||
"INSERT INTO m_loan_paid_in_advance(loan_id, principal_in_advance_derived, interest_in_advance_derived, fee_charges_in_advance_derived, penalty_charges_in_advance_derived, total_in_advance_derived)");
|
|
||||||
updateSqlBuilder.append(" select ml.id as loanId,");
|
|
||||||
updateSqlBuilder.append(" SUM(coalesce(mr.principal_completed_derived, 0)) as principal_in_advance_derived,");
|
|
||||||
updateSqlBuilder.append(" SUM(coalesce(mr.interest_completed_derived, 0)) as interest_in_advance_derived,");
|
|
||||||
updateSqlBuilder.append(" SUM(coalesce(mr.fee_charges_completed_derived, 0)) as fee_charges_in_advance_derived,");
|
|
||||||
updateSqlBuilder.append(" SUM(coalesce(mr.penalty_charges_completed_derived, 0)) as penalty_charges_in_advance_derived,");
|
|
||||||
updateSqlBuilder.append(
|
|
||||||
" (SUM(coalesce(mr.principal_completed_derived, 0)) + SUM(coalesce(mr.interest_completed_derived, 0)) + SUM(coalesce(mr.fee_charges_completed_derived, 0)) + SUM(coalesce(mr.penalty_charges_completed_derived, 0))) as total_in_advance_derived");
|
|
||||||
updateSqlBuilder.append(" FROM m_loan ml ");
|
|
||||||
updateSqlBuilder.append(" INNER JOIN m_loan_repayment_schedule mr on mr.loan_id = ml.id ");
|
|
||||||
updateSqlBuilder.append(" WHERE ml.loan_status_id = 300 ");
|
|
||||||
updateSqlBuilder.append(" and mr.duedate >= " + sqlGenerator.currentDate() + " ");
|
|
||||||
updateSqlBuilder.append(" GROUP BY ml.id");
|
|
||||||
updateSqlBuilder
|
|
||||||
.append(" HAVING (SUM(coalesce(mr.principal_completed_derived, 0)) + SUM(coalesce(mr.interest_completed_derived, 0)) +");
|
|
||||||
updateSqlBuilder.append(
|
|
||||||
" SUM(coalesce(mr.fee_charges_completed_derived, 0)) + SUM(coalesce(mr.penalty_charges_completed_derived, 0))) > 0.0");
|
|
||||||
|
|
||||||
final int result = jdbcTemplate.update(updateSqlBuilder.toString());
|
|
||||||
|
|
||||||
LOG.info("{}: Records affected by updateLoanPaidInAdvance: {}", ThreadLocalContextUtil.getTenant().getName(), result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@CronTarget(jobName = JobName.APPLY_ANNUAL_FEE_FOR_SAVINGS)
|
@CronTarget(jobName = JobName.APPLY_ANNUAL_FEE_FOR_SAVINGS)
|
||||||
public void applyAnnualFeeForSavings() {
|
public void applyAnnualFeeForSavings() {
|
||||||
|
|||||||
@@ -33,4 +33,5 @@
|
|||||||
<include file="parts/0011_add_credit_balance_refund_permission.xml" relativeToChangelogFile="true"/>
|
<include file="parts/0011_add_credit_balance_refund_permission.xml" relativeToChangelogFile="true"/>
|
||||||
<include file="parts/0012_add_merchantissuedrefund_payoutrefund_goodwillcredit_permissions.xml" relativeToChangelogFile="true"/>
|
<include file="parts/0012_add_merchantissuedrefund_payoutrefund_goodwillcredit_permissions.xml" relativeToChangelogFile="true"/>
|
||||||
<include file="parts/0013_remove_topics.xml" relativeToChangelogFile="true"/>
|
<include file="parts/0013_remove_topics.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="parts/0014_remove_unused_jobs.xml" relativeToChangelogFile="true"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
|||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
|
||||||
|
-->
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
|
||||||
|
<changeSet author="fineract" id="1">
|
||||||
|
<delete tableName="job">
|
||||||
|
<where>name='Update loan Summary'</where>
|
||||||
|
</delete>
|
||||||
|
<delete tableName="job">
|
||||||
|
<where>name='Update Loan Paid In Advance'</where>
|
||||||
|
</delete>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
||||||
+6
-4
@@ -28,6 +28,7 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import org.apache.fineract.infrastructure.jobs.service.JobName;
|
import org.apache.fineract.infrastructure.jobs.service.JobName;
|
||||||
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
|
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
|
||||||
import org.apache.fineract.integrationtests.common.Utils;
|
import org.apache.fineract.integrationtests.common.Utils;
|
||||||
@@ -63,7 +64,7 @@ public class SchedulerJobsTest {
|
|||||||
@AfterEach
|
@AfterEach
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
schedulerJobHelper.updateSchedulerStatus(originalSchedulerStatus);
|
schedulerJobHelper.updateSchedulerStatus(originalSchedulerStatus);
|
||||||
for (int jobId = 1; jobId < JobName.values().length; jobId++) {
|
for (Integer jobId : schedulerJobHelper.getAllSchedulerJobIds()) {
|
||||||
schedulerJobHelper.updateSchedulerJob(jobId, originalJobStatus.get(jobId));
|
schedulerJobHelper.updateSchedulerJob(jobId, originalJobStatus.get(jobId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,9 +75,10 @@ public class SchedulerJobsTest {
|
|||||||
// is a
|
// is a
|
||||||
// java.util.Date)
|
// java.util.Date)
|
||||||
schedulerJobHelper.updateSchedulerStatus(true);
|
schedulerJobHelper.updateSchedulerStatus(true);
|
||||||
schedulerJobHelper.updateSchedulerJob(1, true);
|
int minJobId = schedulerJobHelper.getAllSchedulerJobIds().stream().mapToInt(number -> number).min().orElse(Integer.MAX_VALUE);
|
||||||
String nextRunTimeText = await().until(() -> (String) schedulerJobHelper.getSchedulerJobById(1).get("nextRunTime"),
|
schedulerJobHelper.updateSchedulerJob(minJobId, true);
|
||||||
nextRunTime -> nextRunTime != null);
|
String nextRunTimeText = await().until(() -> (String) schedulerJobHelper.getSchedulerJobById(minJobId).get("nextRunTime"),
|
||||||
|
Objects::nonNull);
|
||||||
DateTimeFormatter.ISO_INSTANT.parse(nextRunTimeText);
|
DateTimeFormatter.ISO_INSTANT.parse(nextRunTimeText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-113
@@ -67,7 +67,6 @@ import org.apache.fineract.portfolio.account.domain.AccountTransferType;
|
|||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.MethodOrderer.MethodName;
|
import org.junit.jupiter.api.MethodOrderer.MethodName;
|
||||||
import org.junit.jupiter.api.Order;
|
import org.junit.jupiter.api.Order;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -454,118 +453,6 @@ public class SchedulerJobsTestResults {
|
|||||||
"Verifying Arrears Aging after Running Update Loan Arrears Aging Scheduler Job");
|
"Verifying Arrears Aging after Running Update Loan Arrears Aging Scheduler Job");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateLoanPaidInAdvanceJobOutcome() throws InterruptedException {
|
|
||||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
|
||||||
this.loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
|
|
||||||
|
|
||||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
|
||||||
|
|
||||||
Calendar todayDate = Calendar.getInstance();
|
|
||||||
|
|
||||||
todayDate.add(Calendar.MONTH, -1);
|
|
||||||
final String LOAN_DISBURSEMENT_DATE = dateFormat.format(todayDate.getTime());
|
|
||||||
|
|
||||||
todayDate = Calendar.getInstance();
|
|
||||||
todayDate.add(Calendar.DATE, -5);
|
|
||||||
final String LOAN_FIRST_REPAYMENT_DATE = dateFormat.format(todayDate.getTime());
|
|
||||||
|
|
||||||
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
|
||||||
Assertions.assertNotNull(clientID);
|
|
||||||
|
|
||||||
final Integer loanProductID = createLoanProduct(null);
|
|
||||||
Assertions.assertNotNull(loanProductID);
|
|
||||||
|
|
||||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
|
||||||
Assertions.assertNotNull(loanID);
|
|
||||||
|
|
||||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, responseSpec, loanID);
|
|
||||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
|
||||||
|
|
||||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan(AccountTransferTest.LOAN_APPROVAL_DATE, loanID);
|
|
||||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
|
||||||
|
|
||||||
String loanDetails = this.loanTransactionHelper.getLoanDetails(requestSpec, responseSpec, loanID);
|
|
||||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(LOAN_DISBURSEMENT_DATE, loanID,
|
|
||||||
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
|
|
||||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
|
||||||
|
|
||||||
ArrayList<HashMap> loanScheduleBefore = this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec, loanID);
|
|
||||||
|
|
||||||
Float totalDueForCurrentPeriod = (Float) loanScheduleBefore.get(1).get("totalDueForPeriod");
|
|
||||||
|
|
||||||
this.loanTransactionHelper.makeRepayment(LOAN_FIRST_REPAYMENT_DATE, totalDueForCurrentPeriod, loanID);
|
|
||||||
|
|
||||||
String JobName = "Update Loan Paid In Advance";
|
|
||||||
this.schedulerJobHelper.executeAndAwaitJob(JobName);
|
|
||||||
// Retrieving Loan Repayment Schedule after the successful
|
|
||||||
// completion of
|
|
||||||
// Update Loan Paid in Advance Scheduler Job
|
|
||||||
ArrayList<HashMap> loanScheduleAfter = this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec, loanID);
|
|
||||||
|
|
||||||
Float totalPaidInAdvance = (Float) loanScheduleAfter.get(1).get("totalPaidInAdvanceForPeriod");
|
|
||||||
|
|
||||||
Assertions.assertEquals(totalDueForCurrentPeriod, totalPaidInAdvance,
|
|
||||||
"Verifying Loan Repayment in Advance after Running Update Loan Paid in Advance Scheduler Job");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invalid test case as it won't affect summary (Loan summary is properly
|
|
||||||
// updated before running this job)
|
|
||||||
@Disabled
|
|
||||||
@Test
|
|
||||||
public void testUpdateLoanSummaryJobOutcome() throws InterruptedException {
|
|
||||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
|
||||||
this.loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
|
|
||||||
|
|
||||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
|
||||||
|
|
||||||
Calendar todaysDate = Calendar.getInstance();
|
|
||||||
|
|
||||||
todaysDate.add(Calendar.MONTH, -1);
|
|
||||||
final String LOAN_DISBURSEMENT_DATE = dateFormat.format(todaysDate.getTime());
|
|
||||||
|
|
||||||
todaysDate = Calendar.getInstance();
|
|
||||||
todaysDate.add(Calendar.DATE, -5);
|
|
||||||
|
|
||||||
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
|
||||||
Assertions.assertNotNull(clientID);
|
|
||||||
|
|
||||||
final Integer loanProductID = createLoanProduct(null);
|
|
||||||
Assertions.assertNotNull(loanProductID);
|
|
||||||
|
|
||||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
|
||||||
Assertions.assertNotNull(loanID);
|
|
||||||
|
|
||||||
Integer disburseChargeId = ChargesHelper.createCharges(requestSpec, responseSpec, ChargesHelper.getLoanDisbursementJSON());
|
|
||||||
Assertions.assertNotNull(disburseChargeId);
|
|
||||||
|
|
||||||
this.loanTransactionHelper.addChargesForLoan(loanID,
|
|
||||||
LoanTransactionHelper.getDisbursementChargesForLoanAsJSON(disburseChargeId.toString()));
|
|
||||||
ArrayList<HashMap> chargesPendingState = this.loanTransactionHelper.getLoanCharges(loanID);
|
|
||||||
Assertions.assertEquals(1, chargesPendingState.size());
|
|
||||||
|
|
||||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, responseSpec, loanID);
|
|
||||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
|
||||||
|
|
||||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan(AccountTransferTest.LOAN_APPROVAL_DATE, loanID);
|
|
||||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
|
||||||
|
|
||||||
String loanDetails = this.loanTransactionHelper.getLoanDetails(requestSpec, responseSpec, loanID);
|
|
||||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(LOAN_DISBURSEMENT_DATE, loanID,
|
|
||||||
JsonPath.from(loanDetails).get("netDisbursalAmount").toString());
|
|
||||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
|
||||||
|
|
||||||
HashMap loanSummaryBefore = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, loanID);
|
|
||||||
|
|
||||||
String JobName = "Update loan Summary";
|
|
||||||
this.schedulerJobHelper.executeAndAwaitJob(JobName);
|
|
||||||
Float expectedSummaryAfterJob = (Float) loanSummaryBefore.get("totalExpectedRepayment")
|
|
||||||
/* - (Float) loanSummaryBefore.get("feeChargesPaid") */;
|
|
||||||
HashMap loanSummaryAfter = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, loanID);
|
|
||||||
Assertions.assertEquals(expectedSummaryAfterJob, (Float) loanSummaryAfter.get("totalExpectedRepayment"),
|
|
||||||
"Verifying Loan Summary after Running Update Loan Summary Scheduler Job");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteStandingInstructionsJobOutcome() throws InterruptedException {
|
public void testExecuteStandingInstructionsJobOutcome() throws InterruptedException {
|
||||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||||
|
|||||||
Reference in New Issue
Block a user