http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/911cab85/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java index 88e4be9..ebe4ba6 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java @@ -39,8 +39,6 @@ import java.util.Map; import java.util.Set; import org.apache.commons.lang.StringUtils; -import org.apache.fineract.accounting.journalentry.exception.JournalEntryInvalidException; -import org.apache.fineract.accounting.journalentry.exception.JournalEntryInvalidException.GL_JOURNAL_ENTRY_INVALID_REASON; import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; import org.apache.fineract.infrastructure.core.api.JsonCommand; @@ -73,6 +71,9 @@ import org.apache.fineract.portfolio.charge.domain.ChargeRepositoryWrapper; import org.apache.fineract.portfolio.charge.domain.ChargeTimeType; import org.apache.fineract.portfolio.client.domain.Client; import org.apache.fineract.portfolio.client.exception.ClientNotActiveException; +import org.apache.fineract.portfolio.common.BusinessEventNotificationConstants.BUSINESS_ENTITY; +import org.apache.fineract.portfolio.common.BusinessEventNotificationConstants.BUSINESS_EVENTS; +import org.apache.fineract.portfolio.common.service.BusinessEventNotifierService; import org.apache.fineract.portfolio.group.domain.Group; import org.apache.fineract.portfolio.group.exception.GroupNotActiveException; import org.apache.fineract.portfolio.note.domain.Note; @@ -98,13 +99,13 @@ import org.apache.fineract.portfolio.savings.domain.SavingsAccountStatusType; import org.apache.fineract.portfolio.savings.domain.SavingsAccountTransaction; import org.apache.fineract.portfolio.savings.domain.SavingsAccountTransactionRepository; import org.apache.fineract.portfolio.savings.exception.PostInterestAsOnDateException; +import org.apache.fineract.portfolio.savings.exception.PostInterestAsOnDateException.PostInterestAsOnException_TYPE; import org.apache.fineract.portfolio.savings.exception.PostInterestClosingDateException; import org.apache.fineract.portfolio.savings.exception.SavingsAccountClosingNotAllowedException; import org.apache.fineract.portfolio.savings.exception.SavingsAccountTransactionNotFoundException; import org.apache.fineract.portfolio.savings.exception.SavingsOfficerAssignmentException; import org.apache.fineract.portfolio.savings.exception.SavingsOfficerUnassignmentException; import org.apache.fineract.portfolio.savings.exception.TransactionUpdateNotAllowedException; -import org.apache.fineract.portfolio.savings.exception.PostInterestAsOnDateException.PostInterestAsOnException_TYPE; import org.apache.fineract.useradministration.domain.AppUser; import org.apache.fineract.useradministration.domain.AppUserRepositoryWrapper; import org.joda.time.LocalDate; @@ -141,6 +142,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi private final DepositAccountOnHoldTransactionRepository depositAccountOnHoldTransactionRepository; private final AppUserRepositoryWrapper appuserRepository; private final StandingInstructionRepository standingInstructionRepository; + private final BusinessEventNotifierService businessEventNotifierService; @Autowired public SavingsAccountWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, @@ -161,7 +163,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi final StaffRepositoryWrapper staffRepository, final ConfigurationDomainService configurationDomainService, final DepositAccountOnHoldTransactionRepository depositAccountOnHoldTransactionRepository, final AppUserRepositoryWrapper appuserRepository, - final StandingInstructionRepository standingInstructionRepository) { + final StandingInstructionRepository standingInstructionRepository, + final BusinessEventNotifierService businessEventNotifierService) { this.context = context; this.savingAccountRepositoryWrapper = savingAccountRepositoryWrapper; this.savingsAccountTransactionRepository = savingsAccountTransactionRepository; @@ -185,6 +188,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi this.depositAccountOnHoldTransactionRepository = depositAccountOnHoldTransactionRepository; this.appuserRepository = appuserRepository; this.standingInstructionRepository = standingInstructionRepository; + this.businessEventNotifierService = businessEventNotifierService; } @Transactional @@ -197,7 +201,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId); checkClientOrGroupActive(account); - + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.SAVINGS_ACTIVATE, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); final Set<Long> existingTransactionIds = new HashSet<>(); final Set<Long> existingReversedTransactionIds = new HashSet<>(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); @@ -211,6 +216,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi } postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_ACTIVATE, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); return new CommandProcessingResultBuilder() // .withEntityId(savingsId) // @@ -272,6 +279,9 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi boolean isRegularTransaction = true; final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(account, fmt, transactionDate, transactionAmount, paymentDetail, isAccountTransfer, isRegularTransaction); + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_DEPOSIT, + constructEntityMap(BUSINESS_ENTITY.SAVINGS_TRANSACTION, deposit)); + return new CommandProcessingResultBuilder() // .withEntityId(deposit.getId()) // .withOfficeId(account.officeId()) // @@ -315,6 +325,9 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi final SavingsAccountTransaction withdrawal = this.savingsAccountDomainService.handleWithdrawal(account, fmt, transactionDate, transactionAmount, paymentDetail, transactionBooleanValues); + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_WITHDRAWAL, + constructEntityMap(BUSINESS_ENTITY.SAVINGS_TRANSACTION, withdrawal)); + return new CommandProcessingResultBuilder() // .withEntityId(withdrawal.getId()) // .withOfficeId(account.officeId()) // @@ -333,11 +346,14 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository.findOneWithNotFoundDetection( savingsAccountChargeId, accountId); + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.SAVINGS_APPLY_ANNUAL_FEE, + constructEntityMap(BUSINESS_ENTITY.SAVING, savingsAccountCharge)); final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MM yyyy"); this.payCharge(savingsAccountCharge, savingsAccountCharge.getDueLocalDate(), savingsAccountCharge.amount(), fmt, user); - + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_APPLY_ANNUAL_FEE, + constructEntityMap(BUSINESS_ENTITY.SAVING, savingsAccountCharge)); return new CommandProcessingResultBuilder() // .withEntityId(savingsAccountCharge.getId()) // .withOfficeId(savingsAccountCharge.savingsAccount().officeId()) // @@ -357,7 +373,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId); checkClientOrGroupActive(account); - + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.SAVINGS_CALCULATE_INTEREST, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); final LocalDate today = DateUtils.getLocalDateOfTenant(); final MathContext mc = new MathContext(15, MoneyHelper.getRoundingMode()); boolean isInterestTransfer = false; @@ -366,6 +383,9 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi this.savingAccountRepositoryWrapper.save(account); + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_CALCULATE_INTEREST, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); + return new CommandProcessingResultBuilder() // .withEntityId(savingsId) // .withOfficeId(account.officeId()) // @@ -416,7 +436,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); final Integer financialYearBeginningMonth = this.configurationDomainService.retrieveFinancialYearBeginningMonth(); - + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.SAVINGS_POST_INTEREST, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); if (account.getNominalAnnualInterestRate().compareTo(BigDecimal.ZERO) > 0 || (account.allowOverdraft() && account.getNominalAnnualInterestRateOverdraft().compareTo(BigDecimal.ZERO) > 0)) { final Set<Long> existingTransactionIds = new HashSet<>(); @@ -442,6 +463,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi this.savingAccountRepositoryWrapper.saveAndFlush(account); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_POST_INTEREST, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); } } @@ -454,6 +477,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi final Integer financialYearBeginningMonth = this.configurationDomainService.retrieveFinancialYearBeginningMonth(); final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId); + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.SAVINGS_UNDO, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); final Set<Long> existingTransactionIds = new HashSet<>(); final Set<Long> existingReversedTransactionIds = new HashSet<>(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); @@ -506,7 +531,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi account.activateAccountBasedOnBalance(); this.savingAccountRepositoryWrapper.saveAndFlush(account); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); - + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_UNDO, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); return new CommandProcessingResultBuilder() // .withEntityId(savingsId) // .withOfficeId(account.officeId()) // @@ -541,6 +567,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi final LocalDate today = DateUtils.getLocalDateOfTenant(); final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId); + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.SAVINGS_ADJUST_TRANSACTION, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); if (account.isNotActive()) { throwValidationForActiveStatus(SavingsApiConstants.adjustTransactionAction); } @@ -595,6 +623,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi account.activateAccountBasedOnBalance(); this.savingAccountRepositoryWrapper.saveAndFlush(account); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_ADJUST_TRANSACTION, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); return new CommandProcessingResultBuilder() // .withEntityId(newtransactionId) // .withOfficeId(account.officeId()) // @@ -633,7 +663,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi this.savingsAccountTransactionDataValidator.validateClosing(command); final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId); - + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.SAVINGS_CLOSE, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); final boolean isLinkedWithAnyActiveLoan = this.accountAssociationsReadPlatformService.isLinkedWithAnyActiveAccount(savingsId); if (isLinkedWithAnyActiveLoan) { @@ -700,7 +731,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi // disable all standing orders linked to the savings account this.disableStandingInstructionsLinkedToClosedSavings(account); - + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_CLOSE, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); return new CommandProcessingResultBuilder() // .withEntityId(savingsId) // .withOfficeId(account.officeId()) // @@ -829,6 +861,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi final SavingsAccount savingsAccount = this.savingAccountAssembler.assembleFrom(savingsAccountId); checkClientOrGroupActive(savingsAccount); + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.SAVINGS_ADD_CHARGE, + constructEntityMap(BUSINESS_ENTITY.SAVING, savingsAccount)); final Locale locale = command.extractLocale(); final String format = command.dateFormat(); @@ -867,7 +901,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi savingsAccount.addCharge(fmt, savingsAccountCharge, chargeDefinition); this.savingsAccountChargeRepository.save(savingsAccountCharge); this.savingAccountRepositoryWrapper.saveAndFlush(savingsAccount); - + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_ADD_CHARGE, + constructEntityMap(BUSINESS_ENTITY.SAVING, savingsAccount)); return new CommandProcessingResultBuilder() // .withEntityId(savingsAccountCharge.getId()) // .withOfficeId(savingsAccount.officeId()) // @@ -946,6 +981,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi // Get Savings account from savings charge final SavingsAccount account = savingsAccountCharge.savingsAccount(); + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.SAVINGS_WAIVE_CHARGE, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); this.savingAccountAssembler.assignSavingAccountHelpers(account); final Set<Long> existingTransactionIds = new HashSet<>(); @@ -977,7 +1014,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi this.savingAccountRepositoryWrapper.saveAndFlush(account); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); - + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_WAIVE_CHARGE, + constructEntityMap(BUSINESS_ENTITY.SAVING, account)); return new CommandProcessingResultBuilder() // .withEntityId(savingsAccountChargeId) // .withOfficeId(account.officeId()) // @@ -1023,6 +1061,9 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository.findOneWithNotFoundDetection( savingsAccountChargeId, savingsAccountId); + + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.SAVINGS_PAY_CHARGE, + constructEntityMap(BUSINESS_ENTITY.SAVING, savingsAccountCharge)); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) @@ -1044,6 +1085,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi } this.payCharge(savingsAccountCharge, transactionDate, amountPaid, fmt, user); + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_PAY_CHARGE, + constructEntityMap(BUSINESS_ENTITY.SAVING, savingsAccountCharge)); return new CommandProcessingResultBuilder() // .withEntityId(savingsAccountCharge.getId()) // .withOfficeId(savingsAccountCharge.savingsAccount().officeId()) // @@ -1352,4 +1395,10 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi } } } + + private Map<BUSINESS_ENTITY, Object> constructEntityMap(final BUSINESS_ENTITY entityEvent, Object entity) { + Map<BUSINESS_ENTITY, Object> map = new HashMap<>(1); + map.put(entityEvent, entity); + return map; + } }
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/911cab85/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java index a63b49c..6ebb7ee 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java @@ -21,6 +21,7 @@ package org.apache.fineract.portfolio.savings.service; import static org.apache.fineract.portfolio.savings.SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -53,6 +54,9 @@ import org.apache.fineract.portfolio.client.domain.AccountNumberGenerator; import org.apache.fineract.portfolio.client.domain.Client; import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper; import org.apache.fineract.portfolio.client.exception.ClientNotActiveException; +import org.apache.fineract.portfolio.common.BusinessEventNotificationConstants.BUSINESS_ENTITY; +import org.apache.fineract.portfolio.common.BusinessEventNotificationConstants.BUSINESS_EVENTS; +import org.apache.fineract.portfolio.common.service.BusinessEventNotifierService; import org.apache.fineract.portfolio.group.domain.Group; import org.apache.fineract.portfolio.group.domain.GroupRepository; import org.apache.fineract.portfolio.group.exception.CenterNotActiveException; @@ -101,7 +105,8 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl private final SavingsAccountDomainService savingsAccountDomainService; private final SavingsAccountWritePlatformService savingsAccountWritePlatformService; private final AccountNumberFormatRepositoryWrapper accountNumberFormatRepository; - + private final BusinessEventNotifierService businessEventNotifierService; + @Autowired public SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final SavingsAccountRepositoryWrapper savingAccountRepository, final SavingsAccountAssembler savingAccountAssembler, @@ -113,7 +118,8 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl final SavingsAccountChargeAssembler savingsAccountChargeAssembler, final CommandProcessingService commandProcessingService, final SavingsAccountDomainService savingsAccountDomainService, final SavingsAccountWritePlatformService savingsAccountWritePlatformService, - final AccountNumberFormatRepositoryWrapper accountNumberFormatRepository) { + final AccountNumberFormatRepositoryWrapper accountNumberFormatRepository, + final BusinessEventNotifierService businessEventNotifierService) { this.context = context; this.savingAccountRepository = savingAccountRepository; this.savingAccountAssembler = savingAccountAssembler; @@ -130,6 +136,7 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl this.savingsAccountDomainService = savingsAccountDomainService; this.accountNumberFormatRepository = accountNumberFormatRepository; this.savingsAccountWritePlatformService = savingsAccountWritePlatformService; + this.businessEventNotifierService = businessEventNotifierService ; } /* @@ -415,7 +422,7 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl this.noteRepository.save(note); } } - + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_REJECT, constructEntityMap(BUSINESS_ENTITY.SAVING, savingsAccount)); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(savingsId) // @@ -506,4 +513,11 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl .setRollbackTransaction(rollbackTransaction)// .build(); } + + + private Map<BUSINESS_ENTITY, Object> constructEntityMap(final BUSINESS_ENTITY entityEvent, Object entity) { + Map<BUSINESS_ENTITY, Object> map = new HashMap<>(1); + map.put(entityEvent, entity); + return map; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/911cab85/fineract-provider/src/main/java/org/apache/fineract/portfolio/transfer/service/TransferWritePlatformServiceJpaRepositoryImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/transfer/service/TransferWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/transfer/service/TransferWritePlatformServiceJpaRepositoryImpl.java index c63bac7..522c9d3 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/transfer/service/TransferWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/transfer/service/TransferWritePlatformServiceJpaRepositoryImpl.java @@ -20,7 +20,9 @@ package org.apache.fineract.portfolio.transfer.service; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; @@ -40,6 +42,9 @@ import org.apache.fineract.portfolio.client.domain.Client; import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper; import org.apache.fineract.portfolio.client.domain.ClientStatus; import org.apache.fineract.portfolio.client.exception.ClientHasBeenClosedException; +import org.apache.fineract.portfolio.common.BusinessEventNotificationConstants.BUSINESS_ENTITY; +import org.apache.fineract.portfolio.common.BusinessEventNotificationConstants.BUSINESS_EVENTS; +import org.apache.fineract.portfolio.common.service.BusinessEventNotifierService; import org.apache.fineract.portfolio.group.domain.Group; import org.apache.fineract.portfolio.group.domain.GroupRepositoryWrapper; import org.apache.fineract.portfolio.group.exception.ClientNotInGroupException; @@ -79,6 +84,7 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr private final TransfersDataValidator transfersDataValidator; private final NoteWritePlatformService noteWritePlatformService; private final StaffRepositoryWrapper staffRepositoryWrapper; + private final BusinessEventNotifierService businessEventNotifierService; @Autowired public TransferWritePlatformServiceJpaRepositoryImpl(final ClientRepositoryWrapper clientRepositoryWrapper, @@ -87,7 +93,8 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr final LoanRepositoryWrapper loanRepositoryWrapper, final TransfersDataValidator transfersDataValidator, final NoteWritePlatformService noteWritePlatformService, final StaffRepositoryWrapper staffRepositoryWrapper, final SavingsAccountRepositoryWrapper savingsAccountRepositoryWrapper, - final SavingsAccountWritePlatformService savingsAccountWritePlatformService) { + final SavingsAccountWritePlatformService savingsAccountWritePlatformService, + final BusinessEventNotifierService businessEventNotifierService) { this.clientRepositoryWrapper = clientRepositoryWrapper; this.officeRepository = officeRepository; this.calendarInstanceRepository = calendarInstanceRepository; @@ -99,6 +106,7 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr this.staffRepositoryWrapper = staffRepositoryWrapper; this.savingsAccountRepositoryWrapper = savingsAccountRepositoryWrapper; this.savingsAccountWritePlatformService = savingsAccountWritePlatformService; + this.businessEventNotifierService = businessEventNotifierService; } @Override @@ -293,9 +301,12 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr final Long destinationOfficeId = jsonCommand.longValueOfParameterNamed(TransferApiConstants.destinationOfficeIdParamName); final Office office = this.officeRepository.findOneWithNotFoundDetection(destinationOfficeId); final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId); + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.CLIENTS_PROPOSE_TRANSFER, + constructEntityMap(BUSINESS_ENTITY.CLIENT, client)); handleClientTransferLifecycleEvent(client, office, TransferEventType.PROPOSAL, jsonCommand); this.clientRepositoryWrapper.save(client); - + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.CLIENTS_PROPOSE_TRANSFER, + constructEntityMap(BUSINESS_ENTITY.CLIENT, client)); return new CommandProcessingResultBuilder() // .withClientId(clientId) // .withEntityId(clientId) // @@ -321,9 +332,12 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr this.transfersDataValidator.validateForAcceptClientTransfer(jsonCommand.json()); final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId, true); validateClientAwaitingTransferAcceptance(client); - + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.CLIENTS_ACCEPT_TRANSFER, + constructEntityMap(BUSINESS_ENTITY.CLIENT, client)); handleClientTransferLifecycleEvent(client, client.getTransferToOffice(), TransferEventType.ACCEPTANCE, jsonCommand); this.clientRepositoryWrapper.save(client); + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.CLIENTS_ACCEPT_TRANSFER, + constructEntityMap(BUSINESS_ENTITY.CLIENT, client)); return new CommandProcessingResultBuilder() // .withClientId(clientId) // @@ -337,11 +351,13 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr // validation this.transfersDataValidator.validateForWithdrawClientTransfer(jsonCommand.json()); final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId); + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.CLIENTS_WITHDRAW_TRANSFER, + constructEntityMap(BUSINESS_ENTITY.CLIENT, client)); validateClientAwaitingTransferAcceptanceOnHold(client); - handleClientTransferLifecycleEvent(client, client.getOffice(), TransferEventType.WITHDRAWAL, jsonCommand); this.clientRepositoryWrapper.save(client); - + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.CLIENTS_WITHDRAW_TRANSFER, + constructEntityMap(BUSINESS_ENTITY.CLIENT, client)); return new CommandProcessingResultBuilder() // .withClientId(clientId) // .withEntityId(clientId) // @@ -354,9 +370,14 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr // validation this.transfersDataValidator.validateForRejectClientTransfer(jsonCommand.json()); final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId); + this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.CLIENTS_REJECT_TRANSFER, + constructEntityMap(BUSINESS_ENTITY.CLIENT, client)); handleClientTransferLifecycleEvent(client, client.getOffice(), TransferEventType.REJECTION, jsonCommand); this.clientRepositoryWrapper.save(client); + this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.CLIENTS_REJECT_TRANSFER, + constructEntityMap(BUSINESS_ENTITY.CLIENT, client)); + return new CommandProcessingResultBuilder() // .withClientId(clientId) // .withEntityId(clientId) // @@ -503,6 +524,12 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr if (!client.isTransferInProgressOrOnHold()) { throw new ClientNotAwaitingTransferApprovalOrOnHoldException(client.getId()); } } + private Map<BUSINESS_ENTITY, Object> constructEntityMap(final BUSINESS_ENTITY entityEvent, Object entity) { + Map<BUSINESS_ENTITY, Object> map = new HashMap<>(1); + map.put(entityEvent, entity); + return map; + } + /** * private void validateGroupAwaitingTransferAcceptanceOnHold(final Group * group) { if (!group.isTransferInProgressOrOnHold()) { throw new http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/911cab85/fineract-provider/src/main/resources/META-INF/spring/appContext.xml ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/resources/META-INF/spring/appContext.xml b/fineract-provider/src/main/resources/META-INF/spring/appContext.xml index 9984926..80ebec6 100644 --- a/fineract-provider/src/main/resources/META-INF/spring/appContext.xml +++ b/fineract-provider/src/main/resources/META-INF/spring/appContext.xml @@ -79,6 +79,7 @@ <jpa:repositories base-package="org.apache.fineract.mix.domain" /> <jpa:repositories base-package="org.apache.fineract.scheduledjobs.domain" /> <jpa:repositories base-package="org.apache.fineract.template.domain" /> + <jpa:repositories base-package="org.apache.fineract.infrastructure.campaigns.sms.domain" /> <import resource="infrastructure.xml" />
