FINERACT-1724: Using externalizable retrieval service for Loan COB so custom modules can override the input for it
This commit is contained in:
committed by
Arnold Gálovics
parent
08ecacd52d
commit
c62fb30c7a
+3
-7
@@ -32,11 +32,8 @@ import org.apache.fineract.cob.data.LoanCOBParameter;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLock;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLockRepository;
|
||||
import org.apache.fineract.cob.domain.LockOwner;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.core.config.FineractProperties;
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
@@ -52,7 +49,7 @@ public class ApplyLoanLockTasklet implements Tasklet {
|
||||
private final LoanAccountLockRepository accountLockRepository;
|
||||
private final FineractProperties fineractProperties;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final LoanRepository loanRepository;
|
||||
private final RetrieveLoanIdService retrieveLoanIdService;
|
||||
|
||||
@Override
|
||||
public RepeatStatus execute(@NotNull StepContribution contribution, @NotNull ChunkContext chunkContext) throws Exception {
|
||||
@@ -64,9 +61,8 @@ public class ApplyLoanLockTasklet implements Tasklet {
|
||||
|| (loanCOBParameter.getMinLoanId().equals(0L) && loanCOBParameter.getMaxLoanId().equals(0L))) {
|
||||
loanIds = Collections.emptyList();
|
||||
} else {
|
||||
loanIds = new ArrayList<>(loanRepository.findAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(
|
||||
loanCOBParameter.getMinLoanId(), loanCOBParameter.getMaxLoanId(), ThreadLocalContextUtil
|
||||
.getBusinessDateByType(BusinessDateType.COB_DATE).minusDays(LoanCOBConstant.NUMBER_OF_DAYS_BEHIND)));
|
||||
loanIds = new ArrayList<>(
|
||||
retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter));
|
||||
}
|
||||
List<List<Long>> loanIdPartitions = Lists.partition(loanIds, fineractProperties.getQuery().getInClauseParameterSizeLimit());
|
||||
List<LoanAccountLock> accountLocks = new ArrayList<>();
|
||||
|
||||
+4
-2
@@ -67,6 +67,8 @@ public class LoanCOBWorkerConfiguration {
|
||||
private AppUserRepositoryWrapper userRepository;
|
||||
@Autowired
|
||||
private TransactionTemplate transactionTemplate;
|
||||
@Autowired
|
||||
private RetrieveLoanIdService retrieveLoanIdService;
|
||||
|
||||
@Autowired
|
||||
private FineractProperties fineractProperties;
|
||||
@@ -123,7 +125,7 @@ public class LoanCOBWorkerConfiguration {
|
||||
|
||||
@Bean
|
||||
public ApplyLoanLockTasklet applyLock() {
|
||||
return new ApplyLoanLockTasklet(accountLockRepository, fineractProperties, jdbcTemplate, loanRepository);
|
||||
return new ApplyLoanLockTasklet(accountLockRepository, fineractProperties, jdbcTemplate, retrieveLoanIdService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -134,7 +136,7 @@ public class LoanCOBWorkerConfiguration {
|
||||
@Bean
|
||||
@StepScope
|
||||
public LoanItemReader cobWorkerItemReader() {
|
||||
return new LoanItemReader(loanRepository);
|
||||
return new LoanItemReader(loanRepository, retrieveLoanIdService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -23,8 +23,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.apache.fineract.cob.data.LoanCOBParameter;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
@@ -33,8 +31,11 @@ import org.springframework.batch.item.ExecutionContext;
|
||||
|
||||
public class LoanItemReader extends AbstractLoanItemReader {
|
||||
|
||||
public LoanItemReader(LoanRepository loanRepository) {
|
||||
private final RetrieveLoanIdService retrieveLoanIdService;
|
||||
|
||||
public LoanItemReader(LoanRepository loanRepository, RetrieveLoanIdService retrieveLoanIdService) {
|
||||
super(loanRepository);
|
||||
this.retrieveLoanIdService = retrieveLoanIdService;
|
||||
}
|
||||
|
||||
@BeforeStep
|
||||
@@ -48,9 +49,7 @@ public class LoanItemReader extends AbstractLoanItemReader {
|
||||
|| (loanCOBParameter.getMinLoanId().equals(0L) && loanCOBParameter.getMaxLoanId().equals(0L))) {
|
||||
loanIds = Collections.emptyList();
|
||||
} else {
|
||||
loanIds = loanRepository.findAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter.getMinLoanId(),
|
||||
loanCOBParameter.getMaxLoanId(), ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE)
|
||||
.minusDays(LoanCOBConstant.NUMBER_OF_DAYS_BEHIND));
|
||||
loanIds = retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter);
|
||||
}
|
||||
setRemainingData(new ArrayList<>(loanIds));
|
||||
}
|
||||
|
||||
+10
@@ -23,6 +23,8 @@ import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.cob.data.LoanCOBParameter;
|
||||
import org.apache.fineract.cob.data.LoanIdAndLastClosedBusinessDate;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@@ -44,4 +46,12 @@ public class RetrieveAllNonClosedLoanIdServiceImpl implements RetrieveLoanIdServ
|
||||
public List<LoanIdAndLastClosedBusinessDate> retrieveLoanIdsOldestCobProcessed(LocalDate businessDate) {
|
||||
return loanRepository.findOldestCOBProcessedLoan(businessDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(LoanCOBParameter loanCOBParameter) {
|
||||
return loanRepository.findAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter.getMinLoanId(),
|
||||
loanCOBParameter.getMaxLoanId(),
|
||||
ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE).minusDays(LoanCOBConstant.NUMBER_OF_DAYS_BEHIND));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -31,4 +31,6 @@ public interface RetrieveLoanIdService {
|
||||
|
||||
List<LoanIdAndLastClosedBusinessDate> retrieveLoanIdsOldestCobProcessed(LocalDate businessDate);
|
||||
|
||||
List<Long> retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(LoanCOBParameter loanCOBParameter);
|
||||
|
||||
}
|
||||
|
||||
+5
-7
@@ -20,8 +20,6 @@ package org.apache.fineract.cob.loan;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -39,7 +37,6 @@ import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
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.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
@@ -56,9 +53,9 @@ public class ApplyLoanLockTaskletStepDefinitions implements En {
|
||||
private FineractProperties fineractProperties = mock(FineractProperties.class);
|
||||
private JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
||||
private FineractProperties.FineractQueryProperties fineractQueryProperties = mock(FineractProperties.FineractQueryProperties.class);
|
||||
private LoanRepository loanRepository = mock(LoanRepository.class);
|
||||
private RetrieveLoanIdService retrieveLoanIdService = mock(RetrieveLoanIdService.class);
|
||||
private ApplyLoanLockTasklet applyLoanLockTasklet = new ApplyLoanLockTasklet(accountLockRepository, fineractProperties, jdbcTemplate,
|
||||
loanRepository);
|
||||
retrieveLoanIdService);
|
||||
private RepeatStatus resultItem;
|
||||
private StepContribution stepContribution;
|
||||
|
||||
@@ -70,8 +67,9 @@ public class ApplyLoanLockTaskletStepDefinitions implements En {
|
||||
ThreadLocalContextUtil.setBusinessDates(businessDateMap);
|
||||
StepExecution stepExecution = new StepExecution("test", null);
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
executionContext.put(LoanCOBConstant.LOAN_COB_PARAMETER, new LoanCOBParameter(1L, 4L));
|
||||
lenient().when(this.loanRepository.findAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(anyLong(), anyLong(), any()))
|
||||
LoanCOBParameter loanCOBParameter = new LoanCOBParameter(1L, 4L);
|
||||
executionContext.put(LoanCOBConstant.LOAN_COB_PARAMETER, loanCOBParameter);
|
||||
lenient().when(this.retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter))
|
||||
.thenReturn(List.of(1L, 2L, 3L, 4L));
|
||||
stepExecution.setExecutionContext(executionContext);
|
||||
this.stepContribution = new StepContribution(stepExecution);
|
||||
|
||||
+6
-5
@@ -21,8 +21,6 @@ package org.apache.fineract.cob.loan;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -48,7 +46,9 @@ public class LoanItemReaderStepDefinitions implements En {
|
||||
|
||||
private LoanRepository loanRepository = mock(LoanRepository.class);
|
||||
|
||||
private LoanItemReader loanItemReader = new LoanItemReader(loanRepository);
|
||||
private RetrieveLoanIdService retrieveLoanIdService = mock(RetrieveLoanIdService.class);
|
||||
|
||||
private LoanItemReader loanItemReader = new LoanItemReader(loanRepository, retrieveLoanIdService);
|
||||
|
||||
private Loan loan = mock(Loan.class);
|
||||
|
||||
@@ -70,10 +70,11 @@ public class LoanItemReaderStepDefinitions implements En {
|
||||
minLoanId = splitAccounts.get(0);
|
||||
maxLoanId = splitAccounts.get(splitAccounts.size() - 1);
|
||||
}
|
||||
stepExecutionContext.put(LoanCOBConstant.LOAN_COB_PARAMETER, new LoanCOBParameter(minLoanId, maxLoanId));
|
||||
LoanCOBParameter loanCOBParameter = new LoanCOBParameter(minLoanId, maxLoanId);
|
||||
stepExecutionContext.put(LoanCOBConstant.LOAN_COB_PARAMETER, loanCOBParameter);
|
||||
stepExecution.setExecutionContext(stepExecutionContext);
|
||||
|
||||
lenient().when(this.loanRepository.findAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(anyLong(), anyLong(), any()))
|
||||
lenient().when(this.retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter))
|
||||
.thenReturn(splitAccounts);
|
||||
|
||||
HashMap<BusinessDateType, LocalDate> businessDates = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user