This is an automated email from the ASF dual-hosted git repository.

aleks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 24fc4f193 [FINERACT-1678] Loan accounts stayed locked business event
24fc4f193 is described below

commit 24fc4f19390720ccd952e878e1fd5add1a83d0ec
Author: taskain7 <[email protected]>
AuthorDate: Tue Oct 4 10:59:03 2022 +0200

    [FINERACT-1678] Loan accounts stayed locked business event
---
 .../loan/LoanAccountStayedLockedBusinessEvent.java | 42 +++++++++++++++++++
 .../cob/loan/LoanCOBManagerConfiguration.java      | 16 +++++++-
 .../cob/loan/StayedLockedLoansTasklet.java         | 48 ++++++++++++++++++++++
 3 files changed, 105 insertions(+), 1 deletion(-)

diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanAccountStayedLockedBusinessEvent.java
 
b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanAccountStayedLockedBusinessEvent.java
new file mode 100644
index 000000000..e8d097aad
--- /dev/null
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanAccountStayedLockedBusinessEvent.java
@@ -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;
+    }
+}
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBManagerConfiguration.java
 
b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBManagerConfiguration.java
index de3988c9b..8c20a4b12 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBManagerConfiguration.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBManagerConfiguration.java
@@ -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();
     }
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/StayedLockedLoansTasklet.java
 
b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/StayedLockedLoansTasklet.java
new file mode 100644
index 000000000..df418d92f
--- /dev/null
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/StayedLockedLoansTasklet.java
@@ -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;
+    }
+}

Reply via email to