FINERACT-1724: Abstracting out Loan ID set retrieval for Loan COB
catch-up and inline Loan COB
This commit is contained in:
committed by
Arnold Gálovics
parent
dbfedf5cfd
commit
da8cd2ca9d
+11
@@ -21,6 +21,7 @@ package org.apache.fineract.cob.loan;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.cob.data.LoanIdAndLastClosedBusinessDate;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@@ -32,4 +33,14 @@ public class RetrieveAllNonClosedLoanIdServiceImpl implements RetrieveLoanIdServ
|
||||
public List<Long> retrieveLoanIdsNDaysBehind(Long numberOfDays, LocalDate businessDate) {
|
||||
return loanRepository.findAllNonClosedLoanIdsByLastClosedBusinessDate(businessDate.minusDays(numberOfDays));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LoanIdAndLastClosedBusinessDate> retrieveLoanIdsBehindDateOrNull(LocalDate businessDate, List<Long> loanIds) {
|
||||
return loanRepository.findAllNonClosedLoansBehindOrNullByLoanIds(businessDate, loanIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LoanIdAndLastClosedBusinessDate> retrieveLoanIdsOldestCobProcessed(LocalDate businessDate) {
|
||||
return loanRepository.findOldestCOBProcessedLoan(businessDate);
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -20,8 +20,14 @@ package org.apache.fineract.cob.loan;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.cob.data.LoanIdAndLastClosedBusinessDate;
|
||||
|
||||
public interface RetrieveLoanIdService {
|
||||
|
||||
List<Long> retrieveLoanIdsNDaysBehind(Long numberOfDays, LocalDate businessDate);
|
||||
|
||||
List<LoanIdAndLastClosedBusinessDate> retrieveLoanIdsBehindDateOrNull(LocalDate businessDate, List<Long> loanIds);
|
||||
|
||||
List<LoanIdAndLastClosedBusinessDate> retrieveLoanIdsOldestCobProcessed(LocalDate businessDate);
|
||||
|
||||
}
|
||||
|
||||
+4
-2
@@ -26,6 +26,7 @@ import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.cob.data.LoanIdAndLastClosedBusinessDate;
|
||||
import org.apache.fineract.cob.loan.LoanCOBConstant;
|
||||
import org.apache.fineract.cob.loan.RetrieveLoanIdService;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractContext;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
@@ -56,6 +57,7 @@ public class AsyncLoanCOBExecutorServiceImpl implements AsyncLoanCOBExecutorServ
|
||||
private final ScheduledJobDetailRepository scheduledJobDetailRepository;
|
||||
private final JobStarter jobStarter;
|
||||
private final JobParameterRepository jobParameterRepository;
|
||||
private final RetrieveLoanIdService retrieveLoanIdService;
|
||||
|
||||
@Override
|
||||
@Async("loanCOBCatchUpThreadPoolTaskExecutor")
|
||||
@@ -63,8 +65,8 @@ public class AsyncLoanCOBExecutorServiceImpl implements AsyncLoanCOBExecutorServ
|
||||
try {
|
||||
ThreadLocalContextUtil.init(context);
|
||||
LocalDate cobBusinessDate = ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE);
|
||||
List<LoanIdAndLastClosedBusinessDate> loanIdAndLastClosedBusinessDate = loanRepository
|
||||
.findOldestCOBProcessedLoan(cobBusinessDate);
|
||||
List<LoanIdAndLastClosedBusinessDate> loanIdAndLastClosedBusinessDate = retrieveLoanIdService
|
||||
.retrieveLoanIdsOldestCobProcessed(cobBusinessDate);
|
||||
LocalDate oldestCOBProcessedDate = !loanIdAndLastClosedBusinessDate.isEmpty()
|
||||
? loanIdAndLastClosedBusinessDate.get(0).getLastClosedBusinessDate()
|
||||
: cobBusinessDate;
|
||||
|
||||
+3
-3
@@ -39,6 +39,7 @@ import org.apache.fineract.cob.domain.LoanAccountLockRepository;
|
||||
import org.apache.fineract.cob.domain.LockOwner;
|
||||
import org.apache.fineract.cob.exceptions.LoanAccountLockCannotBeOverruledException;
|
||||
import org.apache.fineract.cob.loan.LoanCOBConstant;
|
||||
import org.apache.fineract.cob.loan.RetrieveLoanIdService;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||
import org.apache.fineract.infrastructure.core.config.FineractProperties;
|
||||
@@ -54,7 +55,6 @@ import org.apache.fineract.infrastructure.jobs.exception.JobNotFoundException;
|
||||
import org.apache.fineract.infrastructure.jobs.service.InlineExecutorService;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.apache.fineract.infrastructure.springbatch.SpringBatchJobConstants;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
@@ -87,7 +87,7 @@ public class InlineLoanCOBExecutorServiceImpl implements InlineExecutorService<L
|
||||
private final TransactionTemplate transactionTemplate;
|
||||
private final CustomJobParameterRepository customJobParameterRepository;
|
||||
private final PlatformSecurityContext context;
|
||||
private final LoanRepository loanRepository;
|
||||
private final RetrieveLoanIdService retrieveLoanIdService;
|
||||
private final FineractProperties fineractProperties;
|
||||
|
||||
private final Gson gson = GoogleGsonSerializerHelper.createSimpleGson();
|
||||
@@ -163,7 +163,7 @@ public class InlineLoanCOBExecutorServiceImpl implements InlineExecutorService<L
|
||||
List<LoanIdAndLastClosedBusinessDate> loanIdAndLastClosedBusinessDates = new ArrayList<>();
|
||||
List<List<Long>> partitions = Lists.partition(loanIds, fineractProperties.getQuery().getInClauseParameterSizeLimit());
|
||||
partitions.forEach(partition -> loanIdAndLastClosedBusinessDates
|
||||
.addAll(loanRepository.findAllNonClosedLoansBehindOrNullByLoanIds(cobBusinessDate, partition)));
|
||||
.addAll(retrieveLoanIdService.retrieveLoanIdsBehindDateOrNull(cobBusinessDate, partition)));
|
||||
return loanIdAndLastClosedBusinessDates;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -27,11 +27,11 @@ import org.apache.fineract.cob.data.IsCatchUpRunningDTO;
|
||||
import org.apache.fineract.cob.data.LoanIdAndLastClosedBusinessDate;
|
||||
import org.apache.fineract.cob.data.OldestCOBProcessedLoanDTO;
|
||||
import org.apache.fineract.cob.loan.LoanCOBConstant;
|
||||
import org.apache.fineract.cob.loan.RetrieveLoanIdService;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractContext;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.infrastructure.jobs.domain.JobExecutionRepository;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -40,15 +40,15 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class LoanCOBCatchUpServiceImpl implements LoanCOBCatchUpService {
|
||||
|
||||
private final LoanRepository loanRepository;
|
||||
private final AsyncLoanCOBExecutorService asyncLoanCOBExecutorService;
|
||||
private final JobExecutionRepository jobExecutionRepository;
|
||||
private final JobExplorer jobExplorer;
|
||||
private final RetrieveLoanIdService retrieveLoanIdService;
|
||||
|
||||
@Override
|
||||
public OldestCOBProcessedLoanDTO getOldestCOBProcessedLoan() {
|
||||
List<LoanIdAndLastClosedBusinessDate> loanIdAndLastClosedBusinessDate = loanRepository
|
||||
.findOldestCOBProcessedLoan(ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE));
|
||||
List<LoanIdAndLastClosedBusinessDate> loanIdAndLastClosedBusinessDate = retrieveLoanIdService
|
||||
.retrieveLoanIdsOldestCobProcessed(ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE));
|
||||
OldestCOBProcessedLoanDTO oldestCOBProcessedLoanDTO = new OldestCOBProcessedLoanDTO();
|
||||
oldestCOBProcessedLoanDTO.setLoanIds(loanIdAndLastClosedBusinessDate.stream().map(LoanIdAndLastClosedBusinessDate::getId).toList());
|
||||
oldestCOBProcessedLoanDTO.setCobProcessedDate(
|
||||
|
||||
+5
-5
@@ -35,12 +35,12 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.cob.data.LoanIdAndLastClosedBusinessDate;
|
||||
import org.apache.fineract.cob.exceptions.LoanAccountLockCannotBeOverruledException;
|
||||
import org.apache.fineract.cob.loan.RetrieveLoanIdService;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||
import org.apache.fineract.infrastructure.core.config.FineractProperties;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -61,7 +61,7 @@ class InlineLoanCOBExecutorServiceImplTest {
|
||||
@Mock
|
||||
private InlineLoanCOBExecutionDataParser dataParser;
|
||||
@Mock
|
||||
private LoanRepository loanRepository;
|
||||
private RetrieveLoanIdService retrieveLoanIdService;
|
||||
@Mock
|
||||
private FineractProperties fineractProperties;
|
||||
@Mock
|
||||
@@ -89,7 +89,7 @@ class InlineLoanCOBExecutorServiceImplTest {
|
||||
when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
|
||||
when(fineractApiProperties.getBodyItemSizeLimit()).thenReturn(fineractBodyItemSizeLimitProperties);
|
||||
when(fineractBodyItemSizeLimitProperties.getInlineLoanCob()).thenReturn(1000);
|
||||
when(loanRepository.findAllNonClosedLoansBehindOrNullByLoanIds(any(), anyList())).thenReturn(List.of(loan));
|
||||
when(retrieveLoanIdService.retrieveLoanIdsBehindDateOrNull(any(), anyList())).thenReturn(List.of(loan));
|
||||
assertThrows(LoanAccountLockCannotBeOverruledException.class, () -> testObj.executeInlineJob(command, "INLINE_LOAN_COB"));
|
||||
}
|
||||
|
||||
@@ -113,9 +113,9 @@ class InlineLoanCOBExecutorServiceImplTest {
|
||||
when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(2);
|
||||
when(fineractApiProperties.getBodyItemSizeLimit()).thenReturn(fineractBodyItemSizeLimitProperties);
|
||||
when(fineractBodyItemSizeLimitProperties.getInlineLoanCob()).thenReturn(1000);
|
||||
when(loanRepository.findAllNonClosedLoansBehindOrNullByLoanIds(any(), anyList())).thenReturn(List.of(loan1, loan2, loan3));
|
||||
when(retrieveLoanIdService.retrieveLoanIdsBehindDateOrNull(any(), anyList())).thenReturn(List.of(loan1, loan2, loan3));
|
||||
assertThrows(LoanAccountLockCannotBeOverruledException.class, () -> testObj.executeInlineJob(command, "INLINE_LOAN_COB"));
|
||||
verify(loanRepository, times(2)).findAllNonClosedLoansBehindOrNullByLoanIds(any(), anyList());
|
||||
verify(retrieveLoanIdService, times(2)).retrieveLoanIdsBehindDateOrNull(any(), anyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user