FINERACT-1724 - Loan CatchUp fix
- [x] Update null loan cob date when hard lock - [x] Update hard lock to soft lock - [x] Ignore null loan cob date when catch up
This commit is contained in:
+8
-1
@@ -29,6 +29,7 @@ import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLock;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLockRepository;
|
||||
import org.apache.fineract.cob.domain.LockOwner;
|
||||
@@ -37,6 +38,7 @@ import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@Profile("test")
|
||||
@Component
|
||||
@@ -64,7 +66,7 @@ public class InternalLoanAccountLockApiResource implements InitializingBean {
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public Response placeLockOnLoanAccount(@Context final UriInfo uriInfo, @PathParam("loanId") Long loanId,
|
||||
@PathParam("lockOwner") String lockOwner) {
|
||||
@PathParam("lockOwner") String lockOwner, @RequestBody(required = false) String error) {
|
||||
log.warn("------------------------------------------------------------");
|
||||
log.warn(" ");
|
||||
log.warn("Placing lock on loan: {}", loanId);
|
||||
@@ -73,7 +75,12 @@ public class InternalLoanAccountLockApiResource implements InitializingBean {
|
||||
|
||||
LoanAccountLock loanAccountLock = new LoanAccountLock(loanId, LockOwner.valueOf(lockOwner),
|
||||
ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE));
|
||||
|
||||
if (StringUtils.isNotBlank(error)) {
|
||||
loanAccountLock.setError(error, error);
|
||||
}
|
||||
loanAccountLockRepository.save(loanAccountLock);
|
||||
return Response.status(Response.Status.ACCEPTED).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -57,7 +57,6 @@ public class LoanCOBCatchUpApiResource {
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = LoanCOBCatchUpApiResourceSwagger.GetOldestCOBProcessedLoanResponse.class))) })
|
||||
public String getOldestCOBProcessedLoan() {
|
||||
OldestCOBProcessedLoanDTO response = loanCOBCatchUpService.getOldestCOBProcessedLoan();
|
||||
|
||||
return oldestCOBProcessedLoanSerializeService.serialize(response);
|
||||
}
|
||||
|
||||
@@ -73,6 +72,7 @@ public class LoanCOBCatchUpApiResource {
|
||||
if (loanCOBCatchUpService.isCatchUpRunning().isCatchUpRunning()) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
loanCOBCatchUpService.unlockHardLockedLoans();
|
||||
OldestCOBProcessedLoanDTO oldestCOBProcessedLoan = loanCOBCatchUpService.getOldestCOBProcessedLoan();
|
||||
if (oldestCOBProcessedLoan.getCobProcessedDate().equals(oldestCOBProcessedLoan.getCobBusinessDate())) {
|
||||
return Response.status(Response.Status.OK).build();
|
||||
|
||||
+25
@@ -22,6 +22,8 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
public interface LoanAccountLockRepository extends JpaRepository<LoanAccountLock, Long>, JpaSpecificationExecutor<LoanAccountLock> {
|
||||
|
||||
@@ -32,4 +34,27 @@ public interface LoanAccountLockRepository extends JpaRepository<LoanAccountLock
|
||||
List<LoanAccountLock> findAllByLoanIdIn(List<Long> loanIds);
|
||||
|
||||
boolean existsByLoanIdAndLockOwner(Long loanId, LockOwner lockOwner);
|
||||
|
||||
@Query(value = """
|
||||
update m_loan set last_closed_business_date = (select lck.lock_placed_on_cob_business_date - 1
|
||||
from m_loan_account_locks lck
|
||||
where lck.loan_id = id
|
||||
and lck.lock_placed_on_cob_business_date is not null
|
||||
and lck.error is not null
|
||||
and lck.lock_owner in ('LOAN_COB_CHUNK_PROCESSING','LOAN_INLINE_COB_PROCESSING'))
|
||||
where last_closed_business_date is null and exists (select lck.loan_id
|
||||
from m_loan_account_locks lck where lck.loan_id = id
|
||||
and lck.lock_placed_on_cob_business_date is not null and lck.error is not null
|
||||
and lck.lock_owner in ('LOAN_COB_CHUNK_PROCESSING','LOAN_INLINE_COB_PROCESSING'))""", nativeQuery = true)
|
||||
@Modifying(flushAutomatically = true)
|
||||
void updateLoanFromAccountLocks();
|
||||
|
||||
@Query("""
|
||||
update LoanAccountLock lck set
|
||||
lck.error = null, lck.lockOwner=org.apache.fineract.cob.domain.LockOwner.LOAN_COB_PARTITIONING
|
||||
where lck.lockPlacedOnCobBusinessDate is not null and lck.error is not null and
|
||||
lck.lockOwner in (org.apache.fineract.cob.domain.LockOwner.LOAN_COB_CHUNK_PROCESSING,org.apache.fineract.cob.domain.LockOwner.LOAN_INLINE_COB_PROCESSING)
|
||||
""")
|
||||
@Modifying(flushAutomatically = true)
|
||||
void updateToSoftLockByOwner();
|
||||
}
|
||||
|
||||
+3
-3
@@ -41,7 +41,7 @@ import org.springframework.batch.repeat.RepeatStatus;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class ApplyLoanLockTasklet implements Tasklet {
|
||||
public class ApplyLoanLockTasklet implements Tasklet, LoanCatchUpSupport {
|
||||
|
||||
private final FineractProperties fineractProperties;
|
||||
private final LoanLockingService loanLockingService;
|
||||
@@ -57,8 +57,8 @@ public class ApplyLoanLockTasklet implements Tasklet {
|
||||
|| (loanCOBParameter.getMinLoanId().equals(0L) && loanCOBParameter.getMaxLoanId().equals(0L))) {
|
||||
loanIds = Collections.emptyList();
|
||||
} else {
|
||||
loanIds = new ArrayList<>(
|
||||
retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter));
|
||||
loanIds = new ArrayList<>(retrieveLoanIdService
|
||||
.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter, isCatchUp(contribution)));
|
||||
}
|
||||
List<List<Long>> loanIdPartitions = Lists.partition(loanIds, getInClauseParameterSizeLimit());
|
||||
List<LoanAccountLock> accountLocks = new ArrayList<>();
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.fineract.cob.loan;
|
||||
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
|
||||
public interface LoanCatchUpSupport {
|
||||
|
||||
default boolean isCatchUp(StepContribution contribution) {
|
||||
return isCatchUp(contribution.getStepExecution());
|
||||
}
|
||||
|
||||
default boolean isCatchUp(StepExecution execution) {
|
||||
return "true".equalsIgnoreCase(execution.getExecutionContext().getString(LoanCOBConstant.IS_CATCH_UP_PARAMETER_NAME, "false"));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -30,7 +30,7 @@ import org.springframework.batch.repeat.RepeatStatus;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class LoanIdParameterTasklet implements Tasklet {
|
||||
public class LoanIdParameterTasklet implements Tasklet, LoanCatchUpSupport {
|
||||
|
||||
private final RetrieveLoanIdService retrieveLoanIdService;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class LoanIdParameterTasklet implements Tasklet {
|
||||
.get(LoanCOBConstant.BUSINESS_DATE_PARAMETER_NAME);
|
||||
LocalDate businessDate = LocalDate.parse(Objects.requireNonNull(businessDateParameter));
|
||||
LoanCOBParameter minAndMaxLoanId = retrieveLoanIdService.retrieveMinAndMaxLoanIdsNDaysBehind(LoanCOBConstant.NUMBER_OF_DAYS_BEHIND,
|
||||
businessDate);
|
||||
businessDate, isCatchUp(contribution));
|
||||
if (Objects.isNull(minAndMaxLoanId)
|
||||
|| (Objects.isNull(minAndMaxLoanId.getMinLoanId()) && Objects.isNull(minAndMaxLoanId.getMaxLoanId()))) {
|
||||
contribution.getStepExecution().getJobExecution().getExecutionContext().put(LoanCOBConstant.LOAN_COB_PARAMETER,
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.annotation.BeforeStep;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
|
||||
public class LoanItemReader extends AbstractLoanItemReader {
|
||||
public class LoanItemReader extends AbstractLoanItemReader implements LoanCatchUpSupport {
|
||||
|
||||
private final RetrieveLoanIdService retrieveLoanIdService;
|
||||
|
||||
@@ -49,7 +49,8 @@ public class LoanItemReader extends AbstractLoanItemReader {
|
||||
|| (loanCOBParameter.getMinLoanId().equals(0L) && loanCOBParameter.getMaxLoanId().equals(0L))) {
|
||||
loanIds = Collections.emptyList();
|
||||
} else {
|
||||
loanIds = retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter);
|
||||
loanIds = retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter,
|
||||
isCatchUp(stepExecution));
|
||||
}
|
||||
setRemainingData(new ArrayList<>(loanIds));
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import org.apache.fineract.cob.domain.LockOwner;
|
||||
|
||||
public interface LoanLockingService {
|
||||
|
||||
void applySoftLock(LocalDate lastClosedBusinessDate, LoanCOBParameter loanCOBParameter);
|
||||
void applySoftLock(LocalDate lastClosedBusinessDate, LoanCOBParameter loanCOBParameter, boolean isCatchUp);
|
||||
|
||||
void upgradeLock(List<Long> accountsToLock, LockOwner lockOwner);
|
||||
|
||||
|
||||
+19
-9
@@ -36,22 +36,32 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@Slf4j
|
||||
public class LoanLockingServiceImpl implements LoanLockingService {
|
||||
|
||||
private static final String NORMAL_LOAN_INSERT = """
|
||||
INSERT INTO m_loan_account_locks (loan_id, version, lock_owner, lock_placed_on, lock_placed_on_cob_business_date)
|
||||
SELECT loan.id, ?, ?, ?, ? FROM m_loan loan
|
||||
WHERE loan.id NOT IN (SELECT loan_id FROM m_loan_account_locks)
|
||||
AND loan.id BETWEEN ? AND ?
|
||||
AND loan.loan_status_id IN (100,200,300,303,304)
|
||||
AND (? = loan.last_closed_business_date OR loan.last_closed_business_date IS NULL)
|
||||
""";
|
||||
private static final String CATCH_UP_LOAN_INSERT = """
|
||||
INSERT INTO m_loan_account_locks (loan_id, version, lock_owner, lock_placed_on, lock_placed_on_cob_business_date)
|
||||
SELECT loan.id, ?, ?, ?, ? FROM m_loan loan
|
||||
WHERE loan.id NOT IN (SELECT loan_id FROM m_loan_account_locks)
|
||||
AND loan.id BETWEEN ? AND ?
|
||||
AND loan.loan_status_id IN (100,200,300,303,304)
|
||||
AND (? = loan.last_closed_business_date)
|
||||
""";
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final FineractProperties fineractProperties;
|
||||
private final LoanAccountLockRepository loanAccountLockRepository;
|
||||
|
||||
@Override
|
||||
public void applySoftLock(LocalDate lastClosedBusinessDate, LoanCOBParameter loanCOBParameter) {
|
||||
public void applySoftLock(LocalDate lastClosedBusinessDate, LoanCOBParameter loanCOBParameter, boolean isCatchUp) {
|
||||
|
||||
LocalDate cobBusinessDate = ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE);
|
||||
jdbcTemplate.update("""
|
||||
INSERT INTO m_loan_account_locks (loan_id, version, lock_owner, lock_placed_on, lock_placed_on_cob_business_date)
|
||||
SELECT loan.id, ?, ?, ?, ? FROM m_loan loan
|
||||
WHERE loan.id NOT IN (SELECT loan_id FROM m_loan_account_locks)
|
||||
AND loan.id BETWEEN ? AND ?
|
||||
AND loan.loan_status_id IN (100,200,300,303,304)
|
||||
AND (? = loan.last_closed_business_date OR loan.last_closed_business_date IS NULL)
|
||||
""", ps -> {
|
||||
jdbcTemplate.update(isCatchUp ? CATCH_UP_LOAN_INSERT : NORMAL_LOAN_INSERT, ps -> {
|
||||
ps.setLong(1, 1);
|
||||
ps.setString(2, LockOwner.LOAN_COB_PARTITIONING.name());
|
||||
ps.setObject(3, DateUtils.getOffsetDateTimeOfTenant());
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.batch.repeat.RepeatStatus;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class LockLoanTasklet implements Tasklet {
|
||||
public class LockLoanTasklet implements Tasklet, LoanCatchUpSupport {
|
||||
|
||||
private final LoanLockingService loanLockingService;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class LockLoanTasklet implements Tasklet {
|
||||
|| (Objects.isNull(loanCOBParameter.getMinLoanId()) && Objects.isNull(loanCOBParameter.getMaxLoanId()))) {
|
||||
loanCOBParameter = new LoanCOBParameter(0L, 0L);
|
||||
}
|
||||
loanLockingService.applySoftLock(lastClosedBusinessDate, loanCOBParameter);
|
||||
loanLockingService.applySoftLock(lastClosedBusinessDate, loanCOBParameter, isCatchUp(contribution));
|
||||
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
|
||||
+17
-6
@@ -34,8 +34,12 @@ public class RetrieveAllNonClosedLoanIdServiceImpl implements RetrieveLoanIdServ
|
||||
private final LoanRepository loanRepository;
|
||||
|
||||
@Override
|
||||
public LoanCOBParameter retrieveMinAndMaxLoanIdsNDaysBehind(Long numberOfDays, LocalDate businessDate) {
|
||||
return loanRepository.findMinAndMaxNonClosedLoanIdsByLastClosedBusinessDate(businessDate.minusDays(numberOfDays));
|
||||
public LoanCOBParameter retrieveMinAndMaxLoanIdsNDaysBehind(Long numberOfDays, LocalDate businessDate, boolean isCatchUp) {
|
||||
if (isCatchUp) {
|
||||
return loanRepository.findMinAndMaxNonClosedLoanIdsByLastClosedBusinessDateNotNull(businessDate.minusDays(numberOfDays));
|
||||
} else {
|
||||
return loanRepository.findMinAndMaxNonClosedLoanIdsByLastClosedBusinessDate(businessDate.minusDays(numberOfDays));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,10 +53,17 @@ public class RetrieveAllNonClosedLoanIdServiceImpl implements RetrieveLoanIdServ
|
||||
}
|
||||
|
||||
@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));
|
||||
public List<Long> retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(LoanCOBParameter loanCOBParameter,
|
||||
boolean isCatchUp) {
|
||||
if (isCatchUp) {
|
||||
return loanRepository.findAllNonClosedLoansByLastClosedBusinessDateNotNullAndMinAndMaxLoanId(loanCOBParameter.getMinLoanId(),
|
||||
loanCOBParameter.getMaxLoanId(), ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE)
|
||||
.minusDays(LoanCOBConstant.NUMBER_OF_DAYS_BEHIND));
|
||||
} else {
|
||||
return loanRepository.findAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter.getMinLoanId(),
|
||||
loanCOBParameter.getMaxLoanId(), ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE)
|
||||
.minusDays(LoanCOBConstant.NUMBER_OF_DAYS_BEHIND));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -27,13 +27,13 @@ import org.springframework.data.repository.query.Param;
|
||||
|
||||
public interface RetrieveLoanIdService {
|
||||
|
||||
LoanCOBParameter retrieveMinAndMaxLoanIdsNDaysBehind(Long numberOfDays, LocalDate businessDate);
|
||||
LoanCOBParameter retrieveMinAndMaxLoanIdsNDaysBehind(Long numberOfDays, LocalDate businessDate, boolean isCatchUp);
|
||||
|
||||
List<LoanIdAndLastClosedBusinessDate> retrieveLoanIdsBehindDateOrNull(LocalDate businessDate, List<Long> loanIds);
|
||||
|
||||
List<LoanIdAndLastClosedBusinessDate> retrieveLoanIdsOldestCobProcessed(LocalDate businessDate);
|
||||
|
||||
List<Long> retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(LoanCOBParameter loanCOBParameter);
|
||||
List<Long> retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(LoanCOBParameter loanCOBParameter, boolean isCatchUp);
|
||||
|
||||
List<LoanIdAndExternalIdAndAccountNo> findAllStayedLockedByCobBusinessDate(@Param("cobBusinessDate") LocalDate cobBusinessDate);
|
||||
|
||||
|
||||
+1
-2
@@ -37,7 +37,6 @@ import org.apache.fineract.infrastructure.jobs.domain.ScheduledJobDetail;
|
||||
import org.apache.fineract.infrastructure.jobs.domain.ScheduledJobDetailRepository;
|
||||
import org.apache.fineract.infrastructure.jobs.exception.JobNotFoundException;
|
||||
import org.apache.fineract.infrastructure.jobs.service.JobStarter;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobParametersInvalidException;
|
||||
import org.springframework.batch.core.configuration.JobLocator;
|
||||
@@ -52,7 +51,6 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class AsyncLoanCOBExecutorServiceImpl implements AsyncLoanCOBExecutorService {
|
||||
|
||||
private final LoanRepository loanRepository;
|
||||
private final JobLocator jobLocator;
|
||||
private final ScheduledJobDetailRepository scheduledJobDetailRepository;
|
||||
private final JobStarter jobStarter;
|
||||
@@ -67,6 +65,7 @@ public class AsyncLoanCOBExecutorServiceImpl implements AsyncLoanCOBExecutorServ
|
||||
LocalDate cobBusinessDate = ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE);
|
||||
List<LoanIdAndLastClosedBusinessDate> loanIdAndLastClosedBusinessDate = retrieveLoanIdService
|
||||
.retrieveLoanIdsOldestCobProcessed(cobBusinessDate);
|
||||
|
||||
LocalDate oldestCOBProcessedDate = !loanIdAndLastClosedBusinessDate.isEmpty()
|
||||
? loanIdAndLastClosedBusinessDate.get(0).getLastClosedBusinessDate()
|
||||
: cobBusinessDate;
|
||||
|
||||
+2
@@ -28,4 +28,6 @@ public interface LoanAccountLockService {
|
||||
boolean isLoanHardLocked(Long loanId);
|
||||
|
||||
boolean isLoanSoftLocked(Long loanId);
|
||||
|
||||
void updateCobAndRemoveLocks();
|
||||
}
|
||||
|
||||
+10
@@ -27,6 +27,8 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -51,4 +53,12 @@ public class LoanAccountLockServiceImpl implements LoanAccountLockService {
|
||||
public boolean isLoanSoftLocked(Long loanId) {
|
||||
return loanAccountLockRepository.existsByLoanIdAndLockOwner(loanId, LockOwner.LOAN_COB_PARTITIONING);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public void updateCobAndRemoveLocks() {
|
||||
loanAccountLockRepository.updateLoanFromAccountLocks();
|
||||
loanAccountLockRepository.updateToSoftLockByOwner();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -23,6 +23,8 @@ import org.apache.fineract.cob.data.OldestCOBProcessedLoanDTO;
|
||||
|
||||
public interface LoanCOBCatchUpService {
|
||||
|
||||
void unlockHardLockedLoans();
|
||||
|
||||
OldestCOBProcessedLoanDTO getOldestCOBProcessedLoan();
|
||||
|
||||
void executeLoanCOBCatchUp();
|
||||
|
||||
+7
@@ -45,6 +45,13 @@ public class LoanCOBCatchUpServiceImpl implements LoanCOBCatchUpService {
|
||||
private final JobExplorer jobExplorer;
|
||||
private final RetrieveLoanIdService retrieveLoanIdService;
|
||||
|
||||
private final LoanAccountLockService accountLockService;
|
||||
|
||||
@Override
|
||||
public void unlockHardLockedLoans() {
|
||||
accountLockService.updateCobAndRemoveLocks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OldestCOBProcessedLoanDTO getOldestCOBProcessedLoan() {
|
||||
List<LoanIdAndLastClosedBusinessDate> loanIdAndLastClosedBusinessDate = retrieveLoanIdService
|
||||
|
||||
+11
@@ -78,6 +78,9 @@ public interface LoanRepository extends JpaRepository<Loan, Long>, JpaSpecificat
|
||||
String FIND_MIN_AND_MAX_NON_CLOSED_LOAN_IDS_BY_LAST_CLOSED_BUSINESS_DATE = "select new org.apache.fineract.cob.data.LoanCOBParameter(min(loan.id), max(loan.id)) from Loan loan where loan.loanStatus in (100,200,300,303,304) "
|
||||
+ "and (:businessDate = loan.lastClosedBusinessDate or loan.lastClosedBusinessDate is NULL)";
|
||||
|
||||
String FIND_MIN_AND_MAX_NON_CLOSED_AND_NON_NULL_LOAN_IDS_BY_LAST_CLOSED_BUSINESS_DATE = "select new org.apache.fineract.cob.data.LoanCOBParameter(min(loan.id), max(loan.id)) from Loan loan where loan.loanStatus in (100,200,300,303,304) "
|
||||
+ "and :businessDate = loan.lastClosedBusinessDate";
|
||||
|
||||
String FIND_NON_CLOSED_LOAN_THAT_BELONGS_TO_CLIENT = "select loan from Loan loan where loan.id = :loanId and loan.loanStatus = 300 and loan.client.id = :clientId";
|
||||
|
||||
String FIND_BY_ACCOUNT_NUMBER = "select loan from Loan loan where loan.accountNumber = :accountNumber";
|
||||
@@ -93,6 +96,7 @@ public interface LoanRepository extends JpaRepository<Loan, Long>, JpaSpecificat
|
||||
|
||||
String FIND_ALL_NON_CLOSED_LOANS_BY_LAST_CLOSED_BUSINESS_DATE_AND_MIN_AND_MAX_LOAN_ID = "select loan.id from Loan loan where loan.id BETWEEN :minLoanId and :maxLoanId and loan.loanStatus in (100,200,300,303,304) and (:cobBusinessDate = loan.lastClosedBusinessDate or loan.lastClosedBusinessDate is NULL)";
|
||||
|
||||
String FIND_ALL_NON_CLOSED_LOANS_BY_LAST_CLOSED_BUSINESS_DATE_NOT_NULL_AND_MIN_AND_MAX_LOAN_ID = "select loan.id from Loan loan where loan.id BETWEEN :minLoanId and :maxLoanId and loan.loanStatus in (100,200,300,303,304) and :cobBusinessDate = loan.lastClosedBusinessDate";
|
||||
String FIND_ALL_NON_CLOSED_LOANS_BEHIND_BY_LOAN_IDS = "select loan.id, loan.lastClosedBusinessDate from Loan loan where loan.id IN :loanIds and loan.loanStatus in (100,200,300,303,304) and loan.lastClosedBusinessDate < :cobBusinessDate";
|
||||
|
||||
String FIND_ALL_STAYED_LOCKED_BY_COB_BUSINESS_DATE = "select loan.id, loan.externalId, loan.accountNumber from LoanAccountLock lock left join Loan loan on lock.loanId = loan.id where lock.lockPlacedOnCobBusinessDate = :cobBusinessDate";
|
||||
@@ -198,6 +202,9 @@ public interface LoanRepository extends JpaRepository<Loan, Long>, JpaSpecificat
|
||||
@Query(FIND_MIN_AND_MAX_NON_CLOSED_LOAN_IDS_BY_LAST_CLOSED_BUSINESS_DATE)
|
||||
LoanCOBParameter findMinAndMaxNonClosedLoanIdsByLastClosedBusinessDate(@Param("businessDate") LocalDate businessDate);
|
||||
|
||||
@Query(FIND_MIN_AND_MAX_NON_CLOSED_AND_NON_NULL_LOAN_IDS_BY_LAST_CLOSED_BUSINESS_DATE)
|
||||
LoanCOBParameter findMinAndMaxNonClosedLoanIdsByLastClosedBusinessDateNotNull(@Param("businessDate") LocalDate businessDate);
|
||||
|
||||
@Query(FIND_ALL_NON_CLOSED_LOANS_BEHIND_BY_LOAN_IDS)
|
||||
List<LoanIdAndLastClosedBusinessDate> findAllNonClosedLoansBehindByLoanIds(@Param("cobBusinessDate") LocalDate cobBusinessDate,
|
||||
@Param("loanIds") List<Long> loanIds);
|
||||
@@ -210,6 +217,10 @@ public interface LoanRepository extends JpaRepository<Loan, Long>, JpaSpecificat
|
||||
List<Long> findAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(@Param("minLoanId") Long minLoanId,
|
||||
@Param("maxLoanId") Long maxLoanId, @Param("cobBusinessDate") LocalDate cobBusinessDate);
|
||||
|
||||
@Query(FIND_ALL_NON_CLOSED_LOANS_BY_LAST_CLOSED_BUSINESS_DATE_NOT_NULL_AND_MIN_AND_MAX_LOAN_ID)
|
||||
List<Long> findAllNonClosedLoansByLastClosedBusinessDateNotNullAndMinAndMaxLoanId(@Param("minLoanId") Long minLoanId,
|
||||
@Param("maxLoanId") Long maxLoanId, @Param("cobBusinessDate") LocalDate cobBusinessDate);
|
||||
|
||||
@Query(FIND_OLDEST_COB_PROCESSED_LOAN)
|
||||
List<LoanIdAndLastClosedBusinessDate> findOldestCOBProcessedLoan(@Param("cobBusinessDate") LocalDate cobBusinessDate);
|
||||
|
||||
|
||||
+2
-1
@@ -66,7 +66,8 @@ public class ApplyLoanLockTaskletStepDefinitions implements En {
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
LoanCOBParameter loanCOBParameter = new LoanCOBParameter(1L, 4L);
|
||||
executionContext.put(LoanCOBConstant.LOAN_COB_PARAMETER, loanCOBParameter);
|
||||
lenient().when(retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter))
|
||||
lenient().when(
|
||||
retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter, false))
|
||||
.thenReturn(List.of(1L, 2L, 3L, 4L));
|
||||
stepExecution.setExecutionContext(executionContext);
|
||||
stepContribution = new StepContribution(stepExecution);
|
||||
|
||||
+14
-4
@@ -53,6 +53,8 @@ public class FetchAndLockLoanStepDefinitions implements En {
|
||||
StepContribution contribution;
|
||||
ArgumentCaptor<LocalDate> dateValueCaptor = ArgumentCaptor.forClass(LocalDate.class);
|
||||
ArgumentCaptor<LoanCOBParameter> loanCOBParameterValueCaptor = ArgumentCaptor.forClass(LoanCOBParameter.class);
|
||||
|
||||
ArgumentCaptor<Boolean> isCatchUpParameterCaptor = ArgumentCaptor.forClass(Boolean.class);
|
||||
private LockLoanTasklet lockLoanTasklet;
|
||||
private String action;
|
||||
private RepeatStatus result;
|
||||
@@ -115,44 +117,52 @@ public class FetchAndLockLoanStepDefinitions implements En {
|
||||
if ("empty steps".equals(action)) {
|
||||
assertEquals(RepeatStatus.FINISHED, result);
|
||||
} else if ("good".equals(action)) {
|
||||
verify(loanLockingService).applySoftLock(dateValueCaptor.capture(), loanCOBParameterValueCaptor.capture());
|
||||
verify(loanLockingService).applySoftLock(dateValueCaptor.capture(), loanCOBParameterValueCaptor.capture(),
|
||||
isCatchUpParameterCaptor.capture());
|
||||
assertEquals(LocalDate.now(ZoneId.systemDefault()).minusDays(1), dateValueCaptor.getValue());
|
||||
assertEquals(1L, loanCOBParameterValueCaptor.getValue().getMinLoanId());
|
||||
assertEquals(3L, loanCOBParameterValueCaptor.getValue().getMaxLoanId());
|
||||
assertEquals(RepeatStatus.FINISHED, result);
|
||||
assertEquals(false, isCatchUpParameterCaptor.getValue());
|
||||
LoanCOBParameter loanCOBParameter = (LoanCOBParameter) contribution.getStepExecution().getJobExecution()
|
||||
.getExecutionContext().get(LoanCOBConstant.LOAN_COB_PARAMETER);
|
||||
assertEquals(2, loanCOBParameter.getMaxLoanId() - loanCOBParameter.getMinLoanId());
|
||||
assertEquals(1L, loanCOBParameter.getMinLoanId());
|
||||
assertEquals(3L, loanCOBParameter.getMaxLoanId());
|
||||
} else if ("soft lock".equals(action)) {
|
||||
verify(loanLockingService).applySoftLock(dateValueCaptor.capture(), loanCOBParameterValueCaptor.capture());
|
||||
verify(loanLockingService).applySoftLock(dateValueCaptor.capture(), loanCOBParameterValueCaptor.capture(),
|
||||
isCatchUpParameterCaptor.capture());
|
||||
assertEquals(LocalDate.now(ZoneId.systemDefault()).minusDays(1), dateValueCaptor.getValue());
|
||||
assertEquals(1L, loanCOBParameterValueCaptor.getValue().getMinLoanId());
|
||||
assertEquals(3L, loanCOBParameterValueCaptor.getValue().getMaxLoanId());
|
||||
assertEquals(RepeatStatus.FINISHED, result);
|
||||
assertEquals(false, isCatchUpParameterCaptor.getValue());
|
||||
LoanCOBParameter loanCOBParameter = (LoanCOBParameter) contribution.getStepExecution().getJobExecution()
|
||||
.getExecutionContext().get(LoanCOBConstant.LOAN_COB_PARAMETER);
|
||||
assertEquals(2, loanCOBParameter.getMaxLoanId() - loanCOBParameter.getMinLoanId());
|
||||
assertEquals(1L, loanCOBParameter.getMinLoanId());
|
||||
assertEquals(3L, loanCOBParameter.getMaxLoanId());
|
||||
} else if ("inline cob".equals(action)) {
|
||||
verify(loanLockingService).applySoftLock(dateValueCaptor.capture(), loanCOBParameterValueCaptor.capture());
|
||||
verify(loanLockingService).applySoftLock(dateValueCaptor.capture(), loanCOBParameterValueCaptor.capture(),
|
||||
isCatchUpParameterCaptor.capture());
|
||||
assertEquals(LocalDate.now(ZoneId.systemDefault()).minusDays(1), dateValueCaptor.getValue());
|
||||
assertEquals(1L, loanCOBParameterValueCaptor.getValue().getMinLoanId());
|
||||
assertEquals(3L, loanCOBParameterValueCaptor.getValue().getMaxLoanId());
|
||||
assertEquals(RepeatStatus.FINISHED, result);
|
||||
assertEquals(false, isCatchUpParameterCaptor.getValue());
|
||||
LoanCOBParameter loanCOBParameter = (LoanCOBParameter) contribution.getStepExecution().getJobExecution()
|
||||
.getExecutionContext().get(LoanCOBConstant.LOAN_COB_PARAMETER);
|
||||
assertEquals(2, loanCOBParameter.getMaxLoanId() - loanCOBParameter.getMinLoanId());
|
||||
assertEquals(1L, loanCOBParameter.getMinLoanId());
|
||||
assertEquals(3L, loanCOBParameter.getMaxLoanId());
|
||||
} else if ("chunk processing".equals(action)) {
|
||||
verify(loanLockingService).applySoftLock(dateValueCaptor.capture(), loanCOBParameterValueCaptor.capture());
|
||||
verify(loanLockingService).applySoftLock(dateValueCaptor.capture(), loanCOBParameterValueCaptor.capture(),
|
||||
isCatchUpParameterCaptor.capture());
|
||||
assertEquals(LocalDate.now(ZoneId.systemDefault()).minusDays(1), dateValueCaptor.getValue());
|
||||
assertEquals(1L, loanCOBParameterValueCaptor.getValue().getMinLoanId());
|
||||
assertEquals(3L, loanCOBParameterValueCaptor.getValue().getMaxLoanId());
|
||||
assertEquals(RepeatStatus.FINISHED, result);
|
||||
assertEquals(false, isCatchUpParameterCaptor.getValue());
|
||||
LoanCOBParameter loanCOBParameter = (LoanCOBParameter) contribution.getStepExecution().getJobExecution()
|
||||
.getExecutionContext().get(LoanCOBConstant.LOAN_COB_PARAMETER);
|
||||
assertEquals(2, loanCOBParameter.getMaxLoanId() - loanCOBParameter.getMinLoanId());
|
||||
|
||||
+2
-1
@@ -74,7 +74,8 @@ public class LoanItemReaderStepDefinitions implements En {
|
||||
stepExecutionContext.put(LoanCOBConstant.LOAN_COB_PARAMETER, loanCOBParameter);
|
||||
stepExecution.setExecutionContext(stepExecutionContext);
|
||||
|
||||
lenient().when(this.retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter))
|
||||
lenient().when(
|
||||
this.retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter, false))
|
||||
.thenReturn(splitAccounts);
|
||||
|
||||
HashMap<BusinessDateType, LocalDate> businessDates = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user