FINERACT-1724: Extra logging and measurements for Loan COB business steps + minor fixes here and there

This commit is contained in:
Arnold Galovics
2023-03-09 16:16:05 +01:00
committed by Arnold Gálovics
parent 36f907906d
commit 83de7652e6
11 changed files with 290 additions and 20 deletions
@@ -156,6 +156,30 @@ final class GLAccountsApiResourceSwagger {
@Schema(example = "Cash at Bangalore")
public String name;
@Schema(example = "100001")
public String glCode;
@Schema(example = "true")
public Boolean manualEntriesAllowed;
@Schema(example = "1")
public Integer type;
@Schema(example = "10")
public Long tagId;
@Schema(example = "1")
public Long parentId;
@Schema(example = "1")
public Integer usage;
@Schema(example = "Desc")
public String description;
@Schema(example = "false")
public Boolean disabled;
}
@Schema(description = "PutGLAccountsResponse")
@@ -59,6 +59,8 @@ public class InitialisationTasklet implements Tasklet {
businessDates.put(BusinessDateType.COB_DATE, businessDate);
businessDates.put(BusinessDateType.BUSINESS_DATE, businessDate.plusDays(1));
ThreadLocalContextUtil.setBusinessDates(businessDates);
log.debug("Initialisation with Business Date [{}], COB Date [{}] and Action Context [{}]", businessDate.plusDays(1), businessDate,
ThreadLocalContextUtil.getActionContext());
return RepeatStatus.FINISHED;
}
}
@@ -19,6 +19,7 @@
package org.apache.fineract.cob.loan;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.cob.exceptions.BusinessStepException;
import org.apache.fineract.infrastructure.core.exception.MultiException;
import org.apache.fineract.infrastructure.core.service.DateUtils;
@@ -28,17 +29,20 @@ import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
@Slf4j
public class AddPeriodicAccrualEntriesBusinessStep implements LoanCOBBusinessStep {
private final LoanAccrualPlatformService loanAccrualPlatformService;
@Override
public Loan execute(Loan loan) {
log.debug("start processing period accrual business step for loan with Id [{}]", loan.getId());
try {
loanAccrualPlatformService.addPeriodicAccruals(DateUtils.getBusinessLocalDate(), loan);
} catch (MultiException e) {
throw new BusinessStepException(String.format("Fail to process period accrual for loan id [%s]", loan.getId()), e);
}
log.debug("end processing period accrual business step for loan Id [{}]", loan.getId());
return loan;
}
@@ -21,6 +21,7 @@ package org.apache.fineract.cob.loan;
import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.event.business.domain.loan.repayment.LoanRepaymentDueBusinessEvent;
@@ -29,6 +30,7 @@ import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@RequiredArgsConstructor
public class CheckLoanRepaymentDueBusinessStep implements LoanCOBBusinessStep {
@@ -38,6 +40,7 @@ public class CheckLoanRepaymentDueBusinessStep implements LoanCOBBusinessStep {
@Override
public Loan execute(Loan loan) {
log.debug("start processing loan repayment due business step loan for loan with id [{}]", loan.getId());
Long numberOfDaysBeforeDueDateToRaiseEvent = configurationDomainService.retrieveRepaymentDueDays();
final LocalDate currentDate = DateUtils.getBusinessLocalDate();
final List<LoanRepaymentScheduleInstallment> loanRepaymentScheduleInstallments = loan.getRepaymentScheduleInstallments();
@@ -48,6 +51,7 @@ public class CheckLoanRepaymentDueBusinessStep implements LoanCOBBusinessStep {
break;
}
}
log.debug("end processing loan repayment due business step loan for loan with id [{}]", loan.getId());
return loan;
}
@@ -21,6 +21,7 @@ package org.apache.fineract.cob.loan;
import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.event.business.domain.loan.repayment.LoanRepaymentOverdueBusinessEvent;
@@ -29,6 +30,7 @@ import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@RequiredArgsConstructor
public class CheckLoanRepaymentOverdueBusinessStep implements LoanCOBBusinessStep {
@@ -38,6 +40,7 @@ public class CheckLoanRepaymentOverdueBusinessStep implements LoanCOBBusinessSte
@Override
public Loan execute(Loan loan) {
log.debug("start processing loan repayment overdue business step for loan with Id [{}]", loan.getId());
Long numberOfDaysAfterDueDateToRaiseEvent = configurationDomainService.retrieveRepaymentOverdueDays();
final LocalDate currentDate = DateUtils.getBusinessLocalDate();
final List<LoanRepaymentScheduleInstallment> loanRepaymentScheduleInstallments = loan.getRepaymentScheduleInstallments();
@@ -50,6 +53,7 @@ public class CheckLoanRepaymentOverdueBusinessStep implements LoanCOBBusinessSte
}
}
}
log.debug("end processing loan repayment overdue business step for loan with Id [{}]", loan.getId());
return loan;
}
@@ -18,9 +18,15 @@
*/
package org.apache.fineract.cob.loan;
import static org.apache.fineract.infrastructure.core.service.MeasuringUtil.measure;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.domain.ActionContext;
import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanAccountDomainService;
import org.springframework.stereotype.Component;
@@ -34,8 +40,37 @@ public class SetLoanDelinquencyTagsBusinessStep implements LoanCOBBusinessStep {
@Override
public Loan execute(Loan loan) {
log.debug("Set Loan Delinquency Tags Business Step {}", loan.getId());
loanAccountDomainService.setLoanDelinquencyTag(loan, DateUtils.getBusinessLocalDate());
if (loan == null) {
log.debug("Ignoring delinquency tag processing for null loan.");
return null;
}
String externalId = Optional.ofNullable(loan.getExternalId()).map(ExternalId::getValue).orElse(null);
measure(() -> {
try {
log.debug("Starting delinquency tag processing for loan with Id [{}], account number [{}], external Id [{}]", loan.getId(),
loan.getAccountNumber(), externalId);
// Change the Action Context to DEFAULT for Business Date so that we can compare the loan due date to
// the
// current date and not the previous (COB) date.
ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT);
loanAccountDomainService.setLoanDelinquencyTag(loan, DateUtils.getBusinessLocalDate());
} catch (RuntimeException re) {
log.error(
"Received [{}] exception while processing delinquency tag for loan with Id [{}], account number [{}], external Id [{}]",
re.getMessage(), loan.getId(), loan.getAccountNumber(), externalId, re);
throw re;
} finally {
// Change the Action Context back to COB to resume COB steps.
ThreadLocalContextUtil.setActionContext(ActionContext.COB);
}
}, duration -> {
log.debug("Ending delinquency tag processing for loan with Id [{}], account number [{}], external Id [{}], finished in [{}]ms",
loan.getId(), loan.getAccountNumber(), externalId, duration.toMillis());
});
return loan;
}
@@ -42,9 +42,13 @@ public final class MeasuringUtil {
public static <T> T measure(Supplier<T> s, BiConsumer<T, Duration> c) {
StopWatch sw = new StopWatch();
sw.start();
T result = s.get();
sw.stop();
c.accept(result, Duration.ofMillis(sw.getTotalTimeMillis()));
T result = null;
try {
result = s.get();
} finally {
sw.stop();
c.accept(result, Duration.ofMillis(sw.getTotalTimeMillis()));
}
return result;
}
}
@@ -3115,7 +3115,7 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
private void validateRepaymentTypeAccountStatus(LoanTransaction repaymentTransaction, LoanEvent event) {
if (repaymentTransaction.isGoodwillCredit() || repaymentTransaction.isMerchantIssuedRefund()
|| repaymentTransaction.isPayoutRefund() || repaymentTransaction.isChargeRefund()) {
|| repaymentTransaction.isPayoutRefund() || repaymentTransaction.isChargeRefund() || repaymentTransaction.isRepayment()) {
if (!(isOpen() || isClosedObligationsMet() || isOverPaid())) {
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();