From ed68b0676da39c26eecfd15a766c90f9ed7b0118 Mon Sep 17 00:00:00 2001 From: pramod Date: Wed, 26 Aug 2015 14:19:24 +0530 Subject: [PATCH] MIFOSX-2168 : changed transaction scope --- .../SavingsAccountWritePlatformService.java | 4 +- ...WritePlatformServiceJpaRepositoryImpl.java | 17 +----- .../service/SavingsSchedularService.java | 15 +++++ .../service/SavingsSchedularServiceImpl.java | 58 +++++++++++++++++++ 4 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsSchedularService.java create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsSchedularServiceImpl.java diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformService.java index d058106b1..5e3524eb0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformService.java @@ -32,8 +32,6 @@ public interface SavingsAccountWritePlatformService { CommandProcessingResult undoTransaction(Long savingsId, Long transactionId, boolean allowAccountTransferModification); - void postInterestForAccounts(); - CommandProcessingResult adjustSavingsTransaction(Long savingsId, Long transactionId, JsonCommand command); CommandProcessingResult close(Long savingsId, JsonCommand command); @@ -66,4 +64,6 @@ public interface SavingsAccountWritePlatformService { void processPostActiveActions(SavingsAccount account, DateTimeFormatter fmt, Set existingTransactionIds, Set existingReversedTransactionIds); + + void postInterest(SavingsAccount account); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java index 925a0a27f..3723894c2 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java @@ -37,8 +37,6 @@ import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; import org.mifosplatform.infrastructure.core.exception.PlatformServiceUnavailableException; import org.mifosplatform.infrastructure.core.service.DateUtils; -import org.mifosplatform.infrastructure.jobs.annotation.CronTarget; -import org.mifosplatform.infrastructure.jobs.service.JobName; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.holiday.domain.HolidayRepositoryWrapper; import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency; @@ -339,7 +337,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi .build(); } - @Transactional + @Override public CommandProcessingResult postInterest(final Long savingsId) { @@ -356,7 +354,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi } @Transactional - private void postInterest(final SavingsAccount account) { + @Override + public void postInterest(final SavingsAccount account) { final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); @@ -385,16 +384,6 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi } } - @CronTarget(jobName = JobName.POST_INTEREST_FOR_SAVINGS) - @Override - public void postInterestForAccounts() { - final List savingsAccounts = this.savingAccountRepository - .findSavingAccountByStatus(SavingsAccountStatusType.ACTIVE.getValue()); - for (final SavingsAccount savingsAccount : savingsAccounts) { - this.savingAccountAssembler.assignSavingAccountHelpers(savingsAccount); - postInterest(savingsAccount); - } - } @Override public CommandProcessingResult undoTransaction(final Long savingsId, final Long transactionId, diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsSchedularService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsSchedularService.java new file mode 100644 index 000000000..493930305 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsSchedularService.java @@ -0,0 +1,15 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.portfolio.savings.service; + +import org.mifosplatform.infrastructure.jobs.exception.JobExecutionException; + + +public interface SavingsSchedularService { + + void postInterestForAccounts() throws JobExecutionException; + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsSchedularServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsSchedularServiceImpl.java new file mode 100644 index 000000000..a0a3c86be --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsSchedularServiceImpl.java @@ -0,0 +1,58 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.portfolio.savings.service; + +import java.util.List; + +import org.mifosplatform.infrastructure.jobs.annotation.CronTarget; +import org.mifosplatform.infrastructure.jobs.exception.JobExecutionException; +import org.mifosplatform.infrastructure.jobs.service.JobName; +import org.mifosplatform.portfolio.savings.domain.SavingsAccount; +import org.mifosplatform.portfolio.savings.domain.SavingsAccountAssembler; +import org.mifosplatform.portfolio.savings.domain.SavingsAccountRepository; +import org.mifosplatform.portfolio.savings.domain.SavingsAccountStatusType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class SavingsSchedularServiceImpl implements SavingsSchedularService { + + private final SavingsAccountAssembler savingAccountAssembler; + private final SavingsAccountWritePlatformService savingsAccountWritePlatformService; + private final SavingsAccountRepository savingAccountRepository; + + @Autowired + public SavingsSchedularServiceImpl(final SavingsAccountAssembler savingAccountAssembler, + final SavingsAccountWritePlatformService savingsAccountWritePlatformService, + final SavingsAccountRepository savingAccountRepository) { + this.savingAccountAssembler = savingAccountAssembler; + this.savingsAccountWritePlatformService = savingsAccountWritePlatformService; + this.savingAccountRepository = savingAccountRepository; + } + + @CronTarget(jobName = JobName.POST_INTEREST_FOR_SAVINGS) + @Override + public void postInterestForAccounts() throws JobExecutionException { + final List savingsAccounts = this.savingAccountRepository.findSavingAccountByStatus(SavingsAccountStatusType.ACTIVE + .getValue()); + StringBuffer sb = new StringBuffer(); + for (final SavingsAccount savingsAccount : savingsAccounts) { + try { + this.savingAccountAssembler.assignSavingAccountHelpers(savingsAccount); + this.savingsAccountWritePlatformService.postInterest(savingsAccount); + } catch (Exception e) { + Throwable realCause = e; + if (e.getCause() != null) { + realCause = e.getCause(); + } + sb.append("failed to post interest for Savings with id " + savingsAccount.getId() + " with message " + + realCause.getMessage()); + } + } + + if (sb.length() > 0) { throw new JobExecutionException(sb.toString()); } + } +}