[FINERACT-1678] Loan accounts stayed locked business event

This commit is contained in:
taskain7
2022-10-04 20:43:16 +02:00
committed by Aleksandar Vidakovic
parent f4979d2c9b
commit 24fc4f1939
3 changed files with 105 additions and 1 deletions
@@ -0,0 +1,42 @@
/**
* 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 java.util.List;
import org.apache.fineract.infrastructure.event.business.domain.AbstractBusinessEvent;
public class LoanAccountStayedLockedBusinessEvent extends AbstractBusinessEvent<List<Long>> {
private static final String CATEGORY = "Loan COB";
private static final String TYPE = "LoanAccountsStayedLockedBusinessEvent";
public LoanAccountStayedLockedBusinessEvent(List<Long> value) {
super(value);
}
@Override
public String getType() {
return TYPE;
}
@Override
public String getCategory() {
return CATEGORY;
}
}
@@ -22,6 +22,7 @@ import java.util.List;
import org.apache.fineract.cob.COBBusinessStepService;
import org.apache.fineract.cob.domain.LoanAccountLockRepository;
import org.apache.fineract.cob.listener.COBExecutionListenerRunner;
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
import org.apache.fineract.infrastructure.jobs.service.JobName;
import org.apache.fineract.infrastructure.springbatch.PropertyService;
import org.springframework.batch.core.Job;
@@ -69,6 +70,8 @@ public class LoanCOBManagerConfiguration {
private RetrieveLoanIdService retrieveLoanIdService;
@Autowired
private LoanAccountLockRepository accountLockRepository;
@Autowired
private BusinessEventNotifierService businessEventNotifierService;
@Bean
@JobScope
@@ -87,17 +90,28 @@ public class LoanCOBManagerConfiguration {
return localStepBuilderFactory.get("Fetch and Lock loan accounts - Step").tasklet(fetchAndLockLoanTasklet()).build();
}
@Bean
public Step stayedLockedStep() {
return localStepBuilderFactory.get("Stayed locked loan accounts - Step").tasklet(stayedLockedTasklet()).build();
}
@Bean
@JobScope
public FetchAndLockLoanTasklet fetchAndLockLoanTasklet() {
return new FetchAndLockLoanTasklet(accountLockRepository, retrieveLoanIdService);
}
@Bean
@JobScope
public StayedLockedLoansTasklet stayedLockedTasklet() {
return new StayedLockedLoansTasklet(accountLockRepository, businessEventNotifierService);
}
@Bean(name = "loanCOBJob")
public Job loanCOBJob() {
return jobBuilderFactory.get(JobName.LOAN_COB.name()) //
.listener(new COBExecutionListenerRunner(applicationContext, JobName.LOAN_COB.name())) //
.start(fetchAndLockStep()).next(loanCOBStep()) //
.start(fetchAndLockStep()).next(loanCOBStep()).next(stayedLockedStep()) //
.incrementer(new RunIdIncrementer()) //
.build();
}
@@ -0,0 +1,48 @@
/**
* 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 java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.cob.domain.LoanAccountLock;
import org.apache.fineract.cob.domain.LoanAccountLockRepository;
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
@Slf4j
@RequiredArgsConstructor
public class StayedLockedLoansTasklet implements Tasklet {
private final LoanAccountLockRepository loanAccountLockRepository;
private final BusinessEventNotifierService businessEventNotifierService;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
List<LoanAccountLock> loanAccountLocks = loanAccountLockRepository.findAll();
if (!loanAccountLocks.isEmpty()) {
List<Long> loanIds = loanAccountLocks.stream().map(LoanAccountLock::getLoanId).toList();
businessEventNotifierService.notifyPostBusinessEvent(new LoanAccountStayedLockedBusinessEvent(loanIds));
}
return RepeatStatus.FINISHED;
}
}