diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle index 5adfc25af..136982b73 100644 --- a/fineract-provider/build.gradle +++ b/fineract-provider/build.gradle @@ -150,6 +150,7 @@ configurations { driver } dependencies { + testImplementation 'org.projectlombok:lombok:1.18.22' driver 'org.mariadb.jdbc:mariadb-java-client' driver 'org.postgresql:postgresql' driver 'mysql:mysql-connector-java:8.0.31' diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/annotation/BulkEventSupport.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/annotation/BulkEventSupport.java new file mode 100644 index 000000000..6299bb8ff --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/annotation/BulkEventSupport.java @@ -0,0 +1,37 @@ +/** + * 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.infrastructure.event.business.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation to be used to collect events into BulkEvent + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Documented +@Inherited +public @interface BulkEventSupport { + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/aspect/BulkEventAspect.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/aspect/BulkEventAspect.java new file mode 100644 index 000000000..e89422dc8 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/aspect/BulkEventAspect.java @@ -0,0 +1,55 @@ +/** + * 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.infrastructure.event.business.aspect; + +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +@Aspect +public class BulkEventAspect { + + private final BusinessEventNotifierService businessEventNotifierService; + + @Around("execution(@org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport public * *(..)) || execution(public * (@org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport *).*(..))") + public Object processCommandJoinPoint(ProceedingJoinPoint proceedingJoinPoint) { + return bulkAroundWrapper(proceedingJoinPoint); + } + + @SneakyThrows + private Object bulkAroundWrapper(ProceedingJoinPoint proceedingJoinPoint) { + if (businessEventNotifierService.isExternalEventRecordingEnabled()) { + return proceedingJoinPoint.proceed(proceedingJoinPoint.getArgs()); + } + try { + businessEventNotifierService.startExternalEventRecording(); + Object result = proceedingJoinPoint.proceed(proceedingJoinPoint.getArgs()); + businessEventNotifierService.stopExternalEventRecording(); + return result; + } finally { + businessEventNotifierService.resetEventRecording(); + } + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/service/BusinessEventNotifierService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/service/BusinessEventNotifierService.java index d0176bc41..c5fb59fa0 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/service/BusinessEventNotifierService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/service/BusinessEventNotifierService.java @@ -23,7 +23,6 @@ import org.apache.fineract.infrastructure.event.business.domain.BusinessEvent; /** * Implemented class is responsible for notifying the business event to registered listeners. - * */ public interface BusinessEventNotifierService { @@ -47,9 +46,12 @@ public interface BusinessEventNotifierService { */ > void addPostBusinessEventListener(Class eventType, BusinessEventListener listener); + boolean isExternalEventRecordingEnabled(); + void startExternalEventRecording(); void stopExternalEventRecording(); void resetEventRecording(); + } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/service/BusinessEventNotifierServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/service/BusinessEventNotifierServiceImpl.java index dca732ad9..3573c03d8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/service/BusinessEventNotifierServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/service/BusinessEventNotifierServiceImpl.java @@ -110,7 +110,8 @@ public class BusinessEventNotifierServiceImpl implements BusinessEventNotifierSe businessEventListeners.add(listener); } - private boolean isExternalEventRecordingEnabled() { + @Override + public boolean isExternalEventRecordingEnabled() { return eventRecordingEnabled.get(); } @@ -161,4 +162,5 @@ public class BusinessEventNotifierServiceImpl implements BusinessEventNotifierSe eventRecordingEnabled.set(false); recordedEvents.remove(); } + } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/handler/CreateAccountTransferCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/handler/CreateAccountTransferCommandHandler.java index fef99250f..a9433c67f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/handler/CreateAccountTransferCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/handler/CreateAccountTransferCommandHandler.java @@ -23,6 +23,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.account.service.AccountTransfersWritePlatformService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,6 +31,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "ACCOUNTTRANSFER", action = "CREATE") +@BulkEventSupport public class CreateAccountTransferCommandHandler implements NewCommandSourceHandler { private final AccountTransfersWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/jobs/executestandinginstructions/ExecuteStandingInstructionsTasklet.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/jobs/executestandinginstructions/ExecuteStandingInstructionsTasklet.java index 16fd0c3e1..5be7e56e0 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/jobs/executestandinginstructions/ExecuteStandingInstructionsTasklet.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/jobs/executestandinginstructions/ExecuteStandingInstructionsTasklet.java @@ -30,6 +30,7 @@ import org.apache.fineract.infrastructure.core.exception.AbstractPlatformService import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException; import org.apache.fineract.portfolio.account.data.AccountTransferDTO; import org.apache.fineract.portfolio.account.data.StandingInstructionData; @@ -52,6 +53,7 @@ import org.springframework.jdbc.core.JdbcTemplate; @Slf4j @RequiredArgsConstructor +@BulkEventSupport public class ExecuteStandingInstructionsTasklet implements Tasklet { private final StandingInstructionReadPlatformService standingInstructionReadPlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/collectionsheet/handler/SaveIndividualCollectionSheetCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/collectionsheet/handler/SaveIndividualCollectionSheetCommandHandler.java index 943761270..ac94a7561 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/collectionsheet/handler/SaveIndividualCollectionSheetCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/collectionsheet/handler/SaveIndividualCollectionSheetCommandHandler.java @@ -22,6 +22,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.collectionsheet.service.CollectionSheetWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @CommandType(entity = "COLLECTIONSHEET", action = "SAVE") +@BulkEventSupport public class SaveIndividualCollectionSheetCommandHandler implements NewCommandSourceHandler { private final CollectionSheetWritePlatformService collectionSheetWritePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/collectionsheet/handler/UpdateCollectionSheetCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/collectionsheet/handler/UpdateCollectionSheetCommandHandler.java index 171e804bd..c77c189a5 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/collectionsheet/handler/UpdateCollectionSheetCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/collectionsheet/handler/UpdateCollectionSheetCommandHandler.java @@ -22,6 +22,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.collectionsheet.service.CollectionSheetWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @CommandType(entity = "COLLECTIONSHEET", action = "UPDATE") +@BulkEventSupport public class UpdateCollectionSheetCommandHandler implements NewCommandSourceHandler { private final CollectionSheetWritePlatformService collectionSheetWritePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/handler/SaveCenterCollectionSheetCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/handler/SaveCenterCollectionSheetCommandHandler.java index f134a8cfc..09199bb85 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/handler/SaveCenterCollectionSheetCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/handler/SaveCenterCollectionSheetCommandHandler.java @@ -22,6 +22,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.collectionsheet.service.CollectionSheetWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @CommandType(entity = "CENTER", action = "SAVECOLLECTIONSHEET") +@BulkEventSupport public class SaveCenterCollectionSheetCommandHandler implements NewCommandSourceHandler { private final CollectionSheetWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/handler/SaveGroupCollectionSheetCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/handler/SaveGroupCollectionSheetCommandHandler.java index 3eca03069..9435a79cb 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/handler/SaveGroupCollectionSheetCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/handler/SaveGroupCollectionSheetCommandHandler.java @@ -22,6 +22,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.collectionsheet.service.CollectionSheetWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @CommandType(entity = "GROUP", action = "SAVECOLLECTIONSHEET") +@BulkEventSupport public class SaveGroupCollectionSheetCommandHandler implements NewCommandSourceHandler { private final CollectionSheetWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/AddAndDeleteLoanDisburseDetailsCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/AddAndDeleteLoanDisburseDetailsCommandHandler.java index 07c161bdb..8678f6ebc 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/AddAndDeleteLoanDisburseDetailsCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/AddAndDeleteLoanDisburseDetailsCommandHandler.java @@ -22,12 +22,14 @@ import lombok.RequiredArgsConstructor; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor +@BulkEventSupport public class AddAndDeleteLoanDisburseDetailsCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/AddLoanChargeCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/AddLoanChargeCommandHandler.java index 46c50bb5b..8a92ff9bd 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/AddLoanChargeCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/AddLoanChargeCommandHandler.java @@ -24,6 +24,7 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.DataIntegrityErrorHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.service.LoanChargeWritePlatformService; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.orm.jpa.JpaSystemException; @@ -33,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "LOANCHARGE", action = "CREATE") +@BulkEventSupport public class AddLoanChargeCommandHandler implements NewCommandSourceHandler { private final LoanChargeWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/DisburseLoanCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/DisburseLoanCommandHandler.java index 83267c329..21f94b31b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/DisburseLoanCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/DisburseLoanCommandHandler.java @@ -24,6 +24,7 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.DataIntegrityErrorHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.orm.jpa.JpaSystemException; @@ -33,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "LOAN", action = "DISBURSE") +@BulkEventSupport public class DisburseLoanCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/DisburseLoanToSavingsCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/DisburseLoanToSavingsCommandHandler.java index 762b7c389..fb0424ab3 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/DisburseLoanToSavingsCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/DisburseLoanToSavingsCommandHandler.java @@ -23,6 +23,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,6 +31,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "LOAN", action = "DISBURSETOSAVINGS") +@BulkEventSupport public class DisburseLoanToSavingsCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/ForeClosureCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/ForeClosureCommandHandler.java index caf039903..73d3fb311 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/ForeClosureCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/ForeClosureCommandHandler.java @@ -23,12 +23,14 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor @CommandType(entity = "LOAN", action = "FORECLOSURE") +@BulkEventSupport public class ForeClosureCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/GlimLoanApplicationDisburseCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/GlimLoanApplicationDisburseCommandHandler.java index 3a3d5faaf..6fdc7971c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/GlimLoanApplicationDisburseCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/GlimLoanApplicationDisburseCommandHandler.java @@ -24,6 +24,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -31,6 +32,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "GLIMLOAN", action = "DISBURSE") +@BulkEventSupport public class GlimLoanApplicationDisburseCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanChargeRefundCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanChargeRefundCommandHandler.java index 245cf2473..49fa06afb 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanChargeRefundCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanChargeRefundCommandHandler.java @@ -24,6 +24,7 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.DataIntegrityErrorHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.service.LoanChargeWritePlatformService; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.orm.jpa.JpaSystemException; @@ -33,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "LOAN", action = "CHARGEREFUND") +@BulkEventSupport public class LoanChargeRefundCommandHandler implements NewCommandSourceHandler { private final LoanChargeWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanGoodwillCreditCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanGoodwillCreditCommandHandler.java index 196dd35a3..cd50d04e0 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanGoodwillCreditCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanGoodwillCreditCommandHandler.java @@ -24,6 +24,7 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.DataIntegrityErrorHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.dao.DataIntegrityViolationException; @@ -34,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "LOAN", action = "GOODWILLCREDIT") +@BulkEventSupport public class LoanGoodwillCreditCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanMerchantIssuedRefundCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanMerchantIssuedRefundCommandHandler.java index ef71cc222..e092f8f06 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanMerchantIssuedRefundCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanMerchantIssuedRefundCommandHandler.java @@ -24,6 +24,7 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.DataIntegrityErrorHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.dao.DataIntegrityViolationException; @@ -34,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "LOAN", action = "MERCHANTISSUEDREFUND") +@BulkEventSupport public class LoanMerchantIssuedRefundCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanPayoutRefundCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanPayoutRefundCommandHandler.java index 1de3ccfb8..e42c0c3a7 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanPayoutRefundCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanPayoutRefundCommandHandler.java @@ -24,6 +24,7 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.DataIntegrityErrorHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.dao.DataIntegrityViolationException; @@ -34,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "LOAN", action = "PAYOUTREFUND") +@BulkEventSupport public class LoanPayoutRefundCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanRecoveryPaymentCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanRecoveryPaymentCommandHandler.java index 8004f99f6..8413d5d86 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanRecoveryPaymentCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanRecoveryPaymentCommandHandler.java @@ -23,6 +23,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.stereotype.Service; @@ -30,6 +31,7 @@ import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor @CommandType(entity = "LOAN", action = "RECOVERYPAYMENT") +@BulkEventSupport public class LoanRecoveryPaymentCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanRepaymentAdjustmentCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanRepaymentAdjustmentCommandHandler.java index 3e313f152..536755262 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanRepaymentAdjustmentCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanRepaymentAdjustmentCommandHandler.java @@ -23,6 +23,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,6 +31,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "LOAN", action = "ADJUST") +@BulkEventSupport public class LoanRepaymentAdjustmentCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanRepaymentCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanRepaymentCommandHandler.java index 28d679b76..7e6b911dd 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanRepaymentCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/LoanRepaymentCommandHandler.java @@ -24,6 +24,7 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.DataIntegrityErrorHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.dao.DataIntegrityViolationException; @@ -34,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "LOAN", action = "REPAYMENT") +@BulkEventSupport public class LoanRepaymentCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/PayLoanChargeCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/PayLoanChargeCommandHandler.java index 1d3a25101..0ff2209a1 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/PayLoanChargeCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/PayLoanChargeCommandHandler.java @@ -23,6 +23,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.service.LoanChargeWritePlatformService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,6 +31,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "LOANCHARGE", action = "PAY") +@BulkEventSupport public class PayLoanChargeCommandHandler implements NewCommandSourceHandler { private final LoanChargeWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/RecoverFromGuarantorCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/RecoverFromGuarantorCommandHandler.java index 2c25fdfd7..ecec460ca 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/RecoverFromGuarantorCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/RecoverFromGuarantorCommandHandler.java @@ -23,12 +23,14 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor @CommandType(entity = "LOAN", action = "RECOVERGUARANTEES") +@BulkEventSupport public class RecoverFromGuarantorCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/UndoWriteOffLoanCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/UndoWriteOffLoanCommandHandler.java index f0559fa65..a02bb752a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/UndoWriteOffLoanCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/UndoWriteOffLoanCommandHandler.java @@ -23,6 +23,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,6 +31,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "LOAN", action = "UNDOWRITEOFF") +@BulkEventSupport public class UndoWriteOffLoanCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/UpdateLoanDisburseDateCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/UpdateLoanDisburseDateCommandHandler.java index 17fa829dc..a5b92501b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/UpdateLoanDisburseDateCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/UpdateLoanDisburseDateCommandHandler.java @@ -22,12 +22,14 @@ import lombok.RequiredArgsConstructor; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor +@BulkEventSupport public class UpdateLoanDisburseDateCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/WaiveInterestPortionOnLoanCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/WaiveInterestPortionOnLoanCommandHandler.java index a80f32b47..ca7ffcd76 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/WaiveInterestPortionOnLoanCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/WaiveInterestPortionOnLoanCommandHandler.java @@ -23,6 +23,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,6 +31,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @CommandType(entity = "LOAN", action = "WAIVEINTERESTPORTION") +@BulkEventSupport public class WaiveInterestPortionOnLoanCommandHandler implements NewCommandSourceHandler { private final LoanWritePlatformService writePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/applychargetooverdueloaninstallment/ApplyChargeToOverdueLoanInstallmentTasklet.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/applychargetooverdueloaninstallment/ApplyChargeToOverdueLoanInstallmentTasklet.java index bce7e33c4..92b52f673 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/applychargetooverdueloaninstallment/ApplyChargeToOverdueLoanInstallmentTasklet.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/applychargetooverdueloaninstallment/ApplyChargeToOverdueLoanInstallmentTasklet.java @@ -29,6 +29,7 @@ import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDoma import org.apache.fineract.infrastructure.core.data.ApiParameterError; import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException; import org.apache.fineract.portfolio.loanaccount.loanschedule.data.OverdueLoanScheduleData; import org.apache.fineract.portfolio.loanaccount.service.LoanChargeWritePlatformService; @@ -40,6 +41,7 @@ import org.springframework.batch.repeat.RepeatStatus; @Slf4j @RequiredArgsConstructor +@BulkEventSupport public class ApplyChargeToOverdueLoanInstallmentTasklet implements Tasklet { private final ConfigurationDomainService configurationDomainService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/recalculateinterestforloan/RecalculateInterestForLoanTasklet.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/recalculateinterestforloan/RecalculateInterestForLoanTasklet.java index 7d70c478b..043cf43ad 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/recalculateinterestforloan/RecalculateInterestForLoanTasklet.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/recalculateinterestforloan/RecalculateInterestForLoanTasklet.java @@ -31,6 +31,7 @@ import java.util.concurrent.Future; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException; import org.apache.fineract.organisation.office.data.OfficeData; import org.apache.fineract.organisation.office.exception.OfficeNotFoundException; @@ -46,6 +47,7 @@ import org.springframework.batch.repeat.RepeatStatus; @Slf4j @RequiredArgsConstructor +@BulkEventSupport public class RecalculateInterestForLoanTasklet implements Tasklet { private final LoanReadPlatformService loanReadPlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/transferfeechargeforloans/TransferFeeChargeForLoansTasklet.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/transferfeechargeforloans/TransferFeeChargeForLoansTasklet.java index 66c03a401..a814343f2 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/transferfeechargeforloans/TransferFeeChargeForLoansTasklet.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/transferfeechargeforloans/TransferFeeChargeForLoansTasklet.java @@ -25,6 +25,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.fineract.infrastructure.core.domain.ExternalId; import org.apache.fineract.infrastructure.core.service.DateUtils; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException; import org.apache.fineract.portfolio.account.PortfolioAccountType; import org.apache.fineract.portfolio.account.data.AccountTransferDTO; @@ -45,6 +46,7 @@ import org.springframework.batch.repeat.RepeatStatus; @Slf4j @RequiredArgsConstructor +@BulkEventSupport public class TransferFeeChargeForLoansTasklet implements Tasklet { private final LoanChargeReadPlatformService loanChargeReadPlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/rescheduleloan/handler/ApproveLoanRescheduleRequestCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/rescheduleloan/handler/ApproveLoanRescheduleRequestCommandHandler.java index 20964b619..8915d0c6c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/rescheduleloan/handler/ApproveLoanRescheduleRequestCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/rescheduleloan/handler/ApproveLoanRescheduleRequestCommandHandler.java @@ -22,6 +22,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.loanaccount.rescheduleloan.service.LoanRescheduleRequestWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @CommandType(entity = "RESCHEDULELOAN", action = "APPROVE") +@BulkEventSupport public class ApproveLoanRescheduleRequestCommandHandler implements NewCommandSourceHandler { private final LoanRescheduleRequestWritePlatformService loanRescheduleRequestWritePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ReplayedTransactionBusinessEventServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ReplayedTransactionBusinessEventServiceImpl.java index 1359e00e6..080ca0814 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ReplayedTransactionBusinessEventServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ReplayedTransactionBusinessEventServiceImpl.java @@ -41,19 +41,13 @@ public class ReplayedTransactionBusinessEventServiceImpl implements ReplayedTran return; } // Extra safety net to avoid event leaking - try { - businessEventNotifierService.startExternalEventRecording(); - for (Map.Entry mapEntry : changedTransactionDetail.getNewTransactionMappings().entrySet()) { - LoanTransaction oldTransaction = loanTransactionRepository.findById(mapEntry.getKey()) - .orElseThrow(() -> new LoanTransactionNotFoundException(mapEntry.getKey())); - LoanAdjustTransactionBusinessEvent.Data data = new LoanAdjustTransactionBusinessEvent.Data(oldTransaction); - data.setNewTransactionDetail(mapEntry.getValue()); - businessEventNotifierService.notifyPostBusinessEvent(new LoanAdjustTransactionBusinessEvent(data)); - } - businessEventNotifierService.stopExternalEventRecording(); - } catch (Exception e) { - businessEventNotifierService.resetEventRecording(); - throw e; + for (Map.Entry mapEntry : changedTransactionDetail.getNewTransactionMappings().entrySet()) { + LoanTransaction oldTransaction = loanTransactionRepository.findById(mapEntry.getKey()) + .orElseThrow(() -> new LoanTransactionNotFoundException(mapEntry.getKey())); + LoanAdjustTransactionBusinessEvent.Data data = new LoanAdjustTransactionBusinessEvent.Data(oldTransaction); + data.setNewTransactionDetail(mapEntry.getValue()); + businessEventNotifierService.notifyPostBusinessEvent(new LoanAdjustTransactionBusinessEvent(data)); } } + } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/ActivateFixedDepositAccountCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/ActivateFixedDepositAccountCommandHandler.java index 437ad8109..209906c6a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/ActivateFixedDepositAccountCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/ActivateFixedDepositAccountCommandHandler.java @@ -22,6 +22,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @CommandType(entity = "FIXEDDEPOSITACCOUNT", action = "ACTIVATE") +@BulkEventSupport public class ActivateFixedDepositAccountCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/ActivateRecurringDepositAccountCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/ActivateRecurringDepositAccountCommandHandler.java index bab80747c..4ce8798f8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/ActivateRecurringDepositAccountCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/ActivateRecurringDepositAccountCommandHandler.java @@ -22,6 +22,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @CommandType(entity = "RECURRINGDEPOSITACCOUNT", action = "ACTIVATE") +@BulkEventSupport public class ActivateRecurringDepositAccountCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/CloseFixedDepositAccountCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/CloseFixedDepositAccountCommandHandler.java index 8b105b5a8..39dead817 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/CloseFixedDepositAccountCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/CloseFixedDepositAccountCommandHandler.java @@ -22,6 +22,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @CommandType(entity = "FIXEDDEPOSITACCOUNT", action = "CLOSE") +@BulkEventSupport public class CloseFixedDepositAccountCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/CloseRecurringDepositAccountCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/CloseRecurringDepositAccountCommandHandler.java index c259d8499..959e482b9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/CloseRecurringDepositAccountCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/CloseRecurringDepositAccountCommandHandler.java @@ -22,6 +22,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @CommandType(entity = "RECURRINGDEPOSITACCOUNT", action = "CLOSE") +@BulkEventSupport public class CloseRecurringDepositAccountCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/PrematureCloseFixedDepositAccountCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/PrematureCloseFixedDepositAccountCommandHandler.java index cb509a3a7..84da79a52 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/PrematureCloseFixedDepositAccountCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/PrematureCloseFixedDepositAccountCommandHandler.java @@ -22,6 +22,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @CommandType(entity = "FIXEDDEPOSITACCOUNT", action = "PREMATURECLOSE") +@BulkEventSupport public class PrematureCloseFixedDepositAccountCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/PrematureCloseRecurringDepositAccountCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/PrematureCloseRecurringDepositAccountCommandHandler.java index 15044fe43..ec276000d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/PrematureCloseRecurringDepositAccountCommandHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/handler/PrematureCloseRecurringDepositAccountCommandHandler.java @@ -22,6 +22,7 @@ import org.apache.fineract.commands.annotation.CommandType; import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; @Service @CommandType(entity = "RECURRINGDEPOSITACCOUNT", action = "PREMATURECLOSE") +@BulkEventSupport public class PrematureCloseRecurringDepositAccountCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/jobs/transferinteresttosavings/TransferInterestToSavingsTasklet.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/jobs/transferinteresttosavings/TransferInterestToSavingsTasklet.java index 15252d122..34f2d448d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/jobs/transferinteresttosavings/TransferInterestToSavingsTasklet.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/jobs/transferinteresttosavings/TransferInterestToSavingsTasklet.java @@ -24,6 +24,7 @@ import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException; import org.apache.fineract.portfolio.account.data.AccountTransferDTO; import org.apache.fineract.portfolio.account.service.AccountTransfersWritePlatformService; @@ -36,6 +37,7 @@ import org.springframework.batch.repeat.RepeatStatus; @Slf4j @RequiredArgsConstructor +@BulkEventSupport public class TransferInterestToSavingsTasklet implements Tasklet { private final DepositAccountReadPlatformService depositAccountReadPlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/jobs/updatedepositsaccountmaturitydetails/UpdateDepositsAccountMaturityDetailsTasklet.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/jobs/updatedepositsaccountmaturitydetails/UpdateDepositsAccountMaturityDetailsTasklet.java index 5f956586a..d4d63886b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/jobs/updatedepositsaccountmaturitydetails/UpdateDepositsAccountMaturityDetailsTasklet.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/jobs/updatedepositsaccountmaturitydetails/UpdateDepositsAccountMaturityDetailsTasklet.java @@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.fineract.infrastructure.core.data.ApiParameterError; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; import org.apache.fineract.portfolio.savings.DepositAccountType; import org.apache.fineract.portfolio.savings.data.DepositAccountData; import org.apache.fineract.portfolio.savings.service.DepositAccountReadPlatformService; @@ -36,6 +37,7 @@ import org.springframework.batch.repeat.RepeatStatus; @Slf4j @RequiredArgsConstructor +@BulkEventSupport public class UpdateDepositsAccountMaturityDetailsTasklet implements Tasklet { private final DepositAccountReadPlatformService depositAccountReadPlatformService; diff --git a/fineract-provider/src/test/java/org/apache/fineract/AbstractSpringTest.java b/fineract-provider/src/test/java/org/apache/fineract/AbstractSpringTest.java new file mode 100644 index 000000000..88534b644 --- /dev/null +++ b/fineract-provider/src/test/java/org/apache/fineract/AbstractSpringTest.java @@ -0,0 +1,31 @@ +/** + * 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; + +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.web.WebAppConfiguration; + +@ExtendWith(SpringExtension.class) +@TestPropertySource("classpath:application-test.properties") +@WebAppConfiguration +@ContextConfiguration(classes = TestConfiguration.class) +public class AbstractSpringTest {} diff --git a/fineract-provider/src/test/java/org/apache/fineract/TestSuite.java b/fineract-provider/src/test/java/org/apache/fineract/CucumberTestSuite.java similarity index 90% rename from fineract-provider/src/test/java/org/apache/fineract/TestSuite.java rename to fineract-provider/src/test/java/org/apache/fineract/CucumberTestSuite.java index a19862348..d2b56f1c3 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/TestSuite.java +++ b/fineract-provider/src/test/java/org/apache/fineract/CucumberTestSuite.java @@ -25,12 +25,12 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; +// This configuration class is used for Cucumber tests, it's invoked via Cucumber glue (cucumber.properties) @CucumberContextConfiguration @ExtendWith(SpringExtension.class) @TestPropertySource("classpath:application-test.properties") @WebAppConfiguration @ContextConfiguration(classes = TestConfiguration.class) -// @SpringBootTest(classes = TestConfiguration.class) -public class TestSuite { +public class CucumberTestSuite { } diff --git a/fineract-provider/src/test/java/org/apache/fineract/TestConfiguration.java b/fineract-provider/src/test/java/org/apache/fineract/TestConfiguration.java index 3d30b193b..f9208fe65 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/TestConfiguration.java +++ b/fineract-provider/src/test/java/org/apache/fineract/TestConfiguration.java @@ -23,6 +23,7 @@ import static org.mockito.Mockito.mock; import com.zaxxer.hikari.HikariDataSource; import javax.sql.DataSource; +import org.apache.fineract.infrastructure.core.config.CacheConfig; import org.apache.fineract.infrastructure.core.config.FineractProperties; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.service.database.DatabaseIndependentQueryService; @@ -54,6 +55,7 @@ import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfigurati import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cache.jcache.JCacheCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -76,7 +78,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableWebSecurity @EnableConfigurationProperties({ FineractProperties.class, LiquibaseProperties.class }) @ComponentScan(basePackages = "org.apache.fineract", excludeFilters = { - @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ScheduledJobRunnerConfig.class) }) + @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ScheduledJobRunnerConfig.class), + @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = CacheConfig.class) }) @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) public class TestConfiguration { @@ -196,4 +199,9 @@ public class TestConfiguration { public JobRepository jobRepository() { return mock(JobRepository.class, RETURNS_MOCKS); } + + @Bean + public JCacheCacheManager jCacheCacheManager() { + return new JCacheCacheManager(); + } } diff --git a/fineract-provider/src/test/java/org/apache/fineract/bulk/BulkAspectTest.java b/fineract-provider/src/test/java/org/apache/fineract/bulk/BulkAspectTest.java new file mode 100644 index 000000000..bb4229090 --- /dev/null +++ b/fineract-provider/src/test/java/org/apache/fineract/bulk/BulkAspectTest.java @@ -0,0 +1,44 @@ +/** + * 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.bulk; + +import org.apache.fineract.AbstractSpringTest; +import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.SpyBean; + +public class BulkAspectTest extends AbstractSpringTest { + + @Autowired + private BulkTestEvent testEvent; + @SpyBean + private BusinessEventNotifierService notifier; + + @Test + public void testEventOnFail() { + + Assertions.assertThrows(IllegalStateException.class, () -> testEvent.processCommand(null)); + Mockito.verify(notifier, Mockito.times(1)).startExternalEventRecording(); + Mockito.verify(notifier, Mockito.times(0)).stopExternalEventRecording(); + Mockito.verify(notifier, Mockito.times(1)).resetEventRecording(); + } +} diff --git a/fineract-provider/src/test/java/org/apache/fineract/bulk/BulkTestEvent.java b/fineract-provider/src/test/java/org/apache/fineract/bulk/BulkTestEvent.java new file mode 100644 index 000000000..d3897b965 --- /dev/null +++ b/fineract-provider/src/test/java/org/apache/fineract/bulk/BulkTestEvent.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.bulk; + +import org.apache.fineract.commands.handler.NewCommandSourceHandler; +import org.apache.fineract.infrastructure.core.api.JsonCommand; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; +import org.springframework.stereotype.Component; + +@Component +@BulkEventSupport +public class BulkTestEvent implements NewCommandSourceHandler { + + private final NestedBulkTestEvent nestedBulkTestEvent; + + public BulkTestEvent(NestedBulkTestEvent nestedBulkTestEvent) { + this.nestedBulkTestEvent = nestedBulkTestEvent; + } + + @Override + public CommandProcessingResult processCommand(JsonCommand command) { + nestedBulkTestEvent.exec(); + return new CommandProcessingResult(1L); + } +} diff --git a/fineract-provider/src/test/java/org/apache/fineract/bulk/NestedBulkTestEvent.java b/fineract-provider/src/test/java/org/apache/fineract/bulk/NestedBulkTestEvent.java new file mode 100644 index 000000000..41cc009db --- /dev/null +++ b/fineract-provider/src/test/java/org/apache/fineract/bulk/NestedBulkTestEvent.java @@ -0,0 +1,31 @@ +/** + * 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.bulk; + +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; +import org.springframework.stereotype.Component; + +@Component +@BulkEventSupport +public class NestedBulkTestEvent { + + public void exec() { + throw new IllegalStateException("Not implemented"); + } +} diff --git a/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/service/DummyTasklet.java b/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/service/DummyTasklet.java new file mode 100644 index 000000000..8b860aab5 --- /dev/null +++ b/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/service/DummyTasklet.java @@ -0,0 +1,52 @@ +/** + * 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.portfolio.loanaccount.service; + +import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport; +import org.apache.fineract.portfolio.loanaccount.domain.ChangedTransactionDetail; +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; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class DummyTasklet implements Tasklet { + + private ChangedTransactionDetail changedTransactionDetail; + + @Autowired + private ReplayedTransactionBusinessEventService replayedTransactionBusinessService; + + @Override + @BulkEventSupport + public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { + replayedTransactionBusinessService.raiseTransactionReplayedEvents(changedTransactionDetail); + return RepeatStatus.FINISHED; + } + + public ChangedTransactionDetail getChangedTransactionDetail() { + return changedTransactionDetail; + } + + public void setChangedTransactionDetail(ChangedTransactionDetail changedTransactionDetail) { + this.changedTransactionDetail = changedTransactionDetail; + } +} diff --git a/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/service/ReplayedTransactionBusinessEventServiceIntegrationTest.java b/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/service/ReplayedTransactionBusinessEventServiceIntegrationTest.java index 824f22c15..090142fe0 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/service/ReplayedTransactionBusinessEventServiceIntegrationTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/service/ReplayedTransactionBusinessEventServiceIntegrationTest.java @@ -24,6 +24,7 @@ import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.verify; import java.util.Optional; +import org.apache.fineract.AbstractSpringTest; import org.apache.fineract.infrastructure.event.business.domain.loan.LoanAdjustTransactionBusinessEvent; import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService; import org.apache.fineract.portfolio.loanaccount.domain.ChangedTransactionDetail; @@ -31,75 +32,85 @@ import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction; import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.batch.core.StepContribution; +import org.springframework.batch.core.scope.context.ChunkContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; -@ExtendWith(MockitoExtension.class) -class ReplayedTransactionBusinessEventServiceIntegrationTest { +class ReplayedTransactionBusinessEventServiceIntegrationTest extends AbstractSpringTest { - @Mock + @MockBean private BusinessEventNotifierService businessEventNotifierService; - @Mock + @MockBean private LoanTransactionRepository loanTransactionRepository; - private ReplayedTransactionBusinessEventService underTest; + @Autowired + private DummyTasklet dummyTasklet; + + @Mock + private StepContribution stepContribution; + + @Mock + private ChunkContext chunkContext; @BeforeEach - public void setUp() { - underTest = new ReplayedTransactionBusinessEventServiceImpl(businessEventNotifierService, loanTransactionRepository); + void setUp() { + dummyTasklet.setChangedTransactionDetail(null); } @Test - public void testWhenParamIsNull() { + public void testWhenParamIsNull() throws Exception { // given - ChangedTransactionDetail changedTransactionDetail = null; + dummyTasklet.setChangedTransactionDetail(null); // when - underTest.raiseTransactionReplayedEvents(changedTransactionDetail); + dummyTasklet.execute(stepContribution, chunkContext); // then - verify(businessEventNotifierService, Mockito.times(0)).startExternalEventRecording(); + verify(businessEventNotifierService, Mockito.times(1)).startExternalEventRecording(); verify(businessEventNotifierService, Mockito.times(0)) .notifyPostBusinessEvent(Mockito.any(LoanAdjustTransactionBusinessEvent.class)); - verify(businessEventNotifierService, Mockito.times(0)).stopExternalEventRecording(); - verify(businessEventNotifierService, Mockito.times(0)).resetEventRecording(); + verify(businessEventNotifierService, Mockito.times(1)).stopExternalEventRecording(); + verify(businessEventNotifierService, Mockito.times(1)).resetEventRecording(); } @Test - public void testWhenParamHasNoMapping() { + public void testWhenParamHasNoMapping() throws Exception { // given ChangedTransactionDetail changedTransactionDetail = new ChangedTransactionDetail(); + dummyTasklet.setChangedTransactionDetail(changedTransactionDetail); // when - underTest.raiseTransactionReplayedEvents(changedTransactionDetail); + dummyTasklet.execute(stepContribution, chunkContext); // then - verify(businessEventNotifierService, Mockito.times(0)).startExternalEventRecording(); + verify(businessEventNotifierService, Mockito.times(1)).startExternalEventRecording(); verify(businessEventNotifierService, Mockito.times(0)) .notifyPostBusinessEvent(Mockito.any(LoanAdjustTransactionBusinessEvent.class)); - verify(businessEventNotifierService, Mockito.times(0)).stopExternalEventRecording(); - verify(businessEventNotifierService, Mockito.times(0)).resetEventRecording(); + verify(businessEventNotifierService, Mockito.times(1)).stopExternalEventRecording(); + verify(businessEventNotifierService, Mockito.times(1)).resetEventRecording(); } @Test - public void testWhenParamHasOneNewTransaction() { + public void testWhenParamHasOneNewTransaction() throws Exception { // given LoanTransaction oldLoanTransaction = Mockito.mock(LoanTransaction.class); LoanTransaction newLoanTransaction = Mockito.mock(LoanTransaction.class); lenient().when(loanTransactionRepository.findById(1L)).thenReturn(Optional.of(oldLoanTransaction)); ChangedTransactionDetail changedTransactionDetail = new ChangedTransactionDetail(); changedTransactionDetail.getNewTransactionMappings().put(1L, newLoanTransaction); + dummyTasklet.setChangedTransactionDetail(changedTransactionDetail); // when - underTest.raiseTransactionReplayedEvents(changedTransactionDetail); + dummyTasklet.execute(stepContribution, chunkContext); // then verify(businessEventNotifierService, Mockito.times(1)).startExternalEventRecording(); verify(businessEventNotifierService, Mockito.times(1)) .notifyPostBusinessEvent(Mockito.any(LoanAdjustTransactionBusinessEvent.class)); verify(businessEventNotifierService, Mockito.times(1)).stopExternalEventRecording(); - verify(businessEventNotifierService, Mockito.times(0)).resetEventRecording(); + verify(businessEventNotifierService, Mockito.times(1)).resetEventRecording(); } @Test - public void testWhenParamHasTwoNewTransaction() { + public void testWhenParamHasTwoNewTransaction() throws Exception { // given LoanTransaction oldLoanTransaction = Mockito.mock(LoanTransaction.class); LoanTransaction newLoanTransaction = Mockito.mock(LoanTransaction.class); @@ -108,28 +119,29 @@ class ReplayedTransactionBusinessEventServiceIntegrationTest { ChangedTransactionDetail changedTransactionDetail = new ChangedTransactionDetail(); changedTransactionDetail.getNewTransactionMappings().put(1L, newLoanTransaction); changedTransactionDetail.getNewTransactionMappings().put(2L, newLoanTransaction); + dummyTasklet.setChangedTransactionDetail(changedTransactionDetail); // when - underTest.raiseTransactionReplayedEvents(changedTransactionDetail); + dummyTasklet.execute(stepContribution, chunkContext); // then verify(businessEventNotifierService, Mockito.times(1)).startExternalEventRecording(); verify(businessEventNotifierService, Mockito.times(2)) .notifyPostBusinessEvent(Mockito.any(LoanAdjustTransactionBusinessEvent.class)); verify(businessEventNotifierService, Mockito.times(1)).stopExternalEventRecording(); - verify(businessEventNotifierService, Mockito.times(0)).resetEventRecording(); + verify(businessEventNotifierService, Mockito.times(1)).resetEventRecording(); } @Test public void testWhenParamHasError() { // given - doThrow(new RuntimeException()).when(businessEventNotifierService) - .notifyPostBusinessEvent(Mockito.any(LoanAdjustTransactionBusinessEvent.class)); + doThrow(new RuntimeException()).when(businessEventNotifierService).notifyPostBusinessEvent(Mockito.any()); LoanTransaction oldLoanTransaction = Mockito.mock(LoanTransaction.class); LoanTransaction newLoanTransaction = Mockito.mock(LoanTransaction.class); lenient().when(loanTransactionRepository.findById(1L)).thenReturn(Optional.of(oldLoanTransaction)); ChangedTransactionDetail changedTransactionDetail = new ChangedTransactionDetail(); changedTransactionDetail.getNewTransactionMappings().put(1L, newLoanTransaction); + dummyTasklet.setChangedTransactionDetail(changedTransactionDetail); // when - assertThrows(RuntimeException.class, () -> underTest.raiseTransactionReplayedEvents(changedTransactionDetail)); + assertThrows(RuntimeException.class, () -> dummyTasklet.execute(stepContribution, chunkContext)); // then verify(businessEventNotifierService, Mockito.times(1)).startExternalEventRecording(); verify(businessEventNotifierService, Mockito.times(1))