fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject [1/4] incubator-fineract git commit: Loading child entites lazy
Date Wed, 21 Sep 2016 08:44:24 GMT
Repository: incubator-fineract
Updated Branches:
  refs/heads/develop 19c0defe4 -> 025ff9c70
Updated Tags:  refs/tags/mifosplatform-0.12.0.beta [created] ee9d722dd
  refs/tags/mifosplatform-1.9.0-tag [created] e436a7990


http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountAssembler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountAssembler.java
index c26bb52..97ea3c6 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountAssembler.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountAssembler.java
@@ -309,7 +309,7 @@ public class SavingsAccountAssembler {
      * request inheriting details where relevant from chosen
      * {@link SavingsProduct}.
      */
-    public SavingsAccount assembleFrom(final Client client, final Group group, final SavingsProduct product, final LocalDate appliedonDate,
+    public SavingsAccount assembleFrom(final Client client, final Group group, final Long productId, final LocalDate appliedonDate,
             final AppUser appliedBy) {
 
         AccountType accountType = AccountType.INVALID;
@@ -330,7 +330,7 @@ public class SavingsAccountAssembler {
             if (!group.hasClientAsMember(client)) { throw new ClientNotInGroupException(client.getId(), group.getId()); }
             accountType = AccountType.JLG;
         }
-
+        final SavingsProduct product = this.savingProductRepository.findOne(productId) ;
         final Set<SavingsAccountCharge> charges = this.savingsAccountChargeAssembler.fromSavingsProduct(product);
         final SavingsAccount account = SavingsAccount.createNewApplicationForSubmittal(client, group, product, null, null, null,
                 accountType, appliedonDate, appliedBy, product.nominalAnnualInterestRate(), product.interestCompoundingPeriodType(),

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepository.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepository.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepository.java
index b614b25..5a28d66 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepository.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepository.java
@@ -25,6 +25,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.Param;
 
+//Use SavingsAccountRepositoryWrapper.
 public interface SavingsAccountRepository extends JpaRepository<SavingsAccount, Long>, JpaSpecificationExecutor<SavingsAccount> {
 
     @Query("from SavingsAccount s_acc where s_acc.client.id = :clientId")

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepositoryWrapper.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepositoryWrapper.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepositoryWrapper.java
index e1a7a58..9742759 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepositoryWrapper.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepositoryWrapper.java
@@ -18,10 +18,14 @@
  */
 package org.apache.fineract.portfolio.savings.domain;
 
+import java.util.List;
+
 import org.apache.fineract.portfolio.savings.DepositAccountType;
 import org.apache.fineract.portfolio.savings.exception.SavingsAccountNotFoundException;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * <p>
@@ -38,6 +42,7 @@ import org.springframework.stereotype.Service;
 @Service
 public class SavingsAccountRepositoryWrapper {
 
+    
     private final SavingsAccountRepository repository;
 
     @Autowired
@@ -45,27 +50,72 @@ public class SavingsAccountRepositoryWrapper {
         this.repository = repository;
     }
 
+    @Transactional(readOnly=true)
     public SavingsAccount findOneWithNotFoundDetection(final Long savingsId) {
         final SavingsAccount account = this.repository.findOne(savingsId);
         if (account == null) { throw new SavingsAccountNotFoundException(savingsId); }
+        account.loadLazyCollections();
         return account;
     }
 
+    @Transactional(readOnly=true)
     public SavingsAccount findOneWithNotFoundDetection(final Long savingsId, final DepositAccountType depositAccountType) {
         final SavingsAccount account = this.repository.findByIdAndDepositAccountType(savingsId, depositAccountType.getValue());
         if (account == null) { throw new SavingsAccountNotFoundException(savingsId); }
+        account.loadLazyCollections();
         return account;
     }
 
-    public void save(final SavingsAccount account) {
-        this.repository.save(account);
+    @Transactional(readOnly=true)
+    public List<SavingsAccount> findSavingAccountByClientId(@Param("clientId") Long clientId) {
+        List<SavingsAccount> accounts = this.repository.findSavingAccountByClientId(clientId) ;
+        loadLazyCollections(accounts); 
+        return accounts ;
+    }
+
+    @Transactional(readOnly=true)
+    public List<SavingsAccount> findSavingAccountByStatus(@Param("status") Integer status) {
+        List<SavingsAccount> accounts = this.repository.findSavingAccountByStatus(status) ;
+        loadLazyCollections(accounts); 
+        return accounts ;
+    }
+
+    //Root Entities are enough
+    public List<SavingsAccount> findByClientIdAndGroupId(@Param("clientId") Long clientId, @Param("groupId") Long groupId) {
+        return this.repository.findByClientIdAndGroupId(clientId, groupId) ;
+    }
+
+    public boolean doNonClosedSavingAccountsExistForClient(@Param("clientId") Long clientId) {
+        return this.repository.doNonClosedSavingAccountsExistForClient(clientId) ;
+    }
+
+    //Root Entities are enough
+    public List<SavingsAccount> findByGroupId(@Param("groupId") Long groupId) {
+        return this.repository.findByGroupId(groupId) ;
+    }
+
+    //Root Entity is enough
+    public SavingsAccount findNonClosedAccountByAccountNumber(@Param("accountNumber") String accountNumber) {
+        return this.repository.findNonClosedAccountByAccountNumber(accountNumber) ;
+    }
+    
+    public SavingsAccount save(final SavingsAccount account) {
+        return this.repository.save(account);
     }
 
     public void delete(final SavingsAccount account) {
         this.repository.delete(account);
     }
 
-    public void saveAndFlush(final SavingsAccount account) {
-        this.repository.saveAndFlush(account);
+    public SavingsAccount saveAndFlush(final SavingsAccount account) {
+        return this.repository.saveAndFlush(account);
+    }
+    
+    private void loadLazyCollections(final List<SavingsAccount> accounts) {
+        if(accounts != null && accounts.size() >0) {
+            for(SavingsAccount account: accounts) {
+                account.loadLazyCollections();
+            }
+        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountSummary.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountSummary.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountSummary.java
index ea902d4..735016d 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountSummary.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountSummary.java
@@ -21,7 +21,6 @@ package org.apache.fineract.portfolio.savings.domain;
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
-import java.util.Set;
 
 import javax.persistence.Column;
 import javax.persistence.Embeddable;
@@ -91,7 +90,7 @@ public final class SavingsAccountSummary {
     }
 
     public void updateSummary(final MonetaryCurrency currency, final SavingsAccountTransactionSummaryWrapper wrapper,
-            final Set<SavingsAccountTransaction> transactions) {
+            final List<SavingsAccountTransaction> transactions) {
 
         this.totalDeposits = wrapper.calculateTotalDeposits(currency, transactions);
         this.totalWithdrawals = wrapper.calculateTotalWithdrawals(currency, transactions);

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountTransactionSummaryWrapper.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountTransactionSummaryWrapper.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountTransactionSummaryWrapper.java
index 0aceb2b..6f7ffe6 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountTransactionSummaryWrapper.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountTransactionSummaryWrapper.java
@@ -19,7 +19,7 @@
 package org.apache.fineract.portfolio.savings.domain;
 
 import java.math.BigDecimal;
-import java.util.Set;
+import java.util.List;
 
 import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
 import org.apache.fineract.organisation.monetary.domain.Money;
@@ -32,7 +32,7 @@ import org.springframework.stereotype.Component;
 @Component
 public final class SavingsAccountTransactionSummaryWrapper {
 
-    public BigDecimal calculateTotalDeposits(final MonetaryCurrency currency, final Set<SavingsAccountTransaction> transactions) {
+    public BigDecimal calculateTotalDeposits(final MonetaryCurrency currency, final List<SavingsAccountTransaction> transactions) {
         Money total = Money.zero(currency);
         for (final SavingsAccountTransaction transaction : transactions) {
             if (transaction.isDepositAndNotReversed() || transaction.isDividendPayoutAndNotReversed()) {
@@ -42,7 +42,7 @@ public final class SavingsAccountTransactionSummaryWrapper {
         return total.getAmountDefaultedToNullIfZero();
     }
 
-    public BigDecimal calculateTotalWithdrawals(final MonetaryCurrency currency, final Set<SavingsAccountTransaction> transactions) {
+    public BigDecimal calculateTotalWithdrawals(final MonetaryCurrency currency, final List<SavingsAccountTransaction> transactions) {
         Money total = Money.zero(currency);
         for (final SavingsAccountTransaction transaction : transactions) {
             if (transaction.isWithdrawal() && transaction.isNotReversed()) {
@@ -52,7 +52,7 @@ public final class SavingsAccountTransactionSummaryWrapper {
         return total.getAmountDefaultedToNullIfZero();
     }
 
-    public BigDecimal calculateTotalInterestPosted(final MonetaryCurrency currency, final Set<SavingsAccountTransaction> transactions) {
+    public BigDecimal calculateTotalInterestPosted(final MonetaryCurrency currency, final List<SavingsAccountTransaction> transactions) {
         Money total = Money.zero(currency);
         for (final SavingsAccountTransaction transaction : transactions) {
             if (transaction.isInterestPostingAndNotReversed() && transaction.isNotReversed()) {
@@ -62,7 +62,7 @@ public final class SavingsAccountTransactionSummaryWrapper {
         return total.getAmountDefaultedToNullIfZero();
     }
 
-    public BigDecimal calculateTotalWithdrawalFees(final MonetaryCurrency currency, final Set<SavingsAccountTransaction> transactions) {
+    public BigDecimal calculateTotalWithdrawalFees(final MonetaryCurrency currency, final List<SavingsAccountTransaction> transactions) {
         Money total = Money.zero(currency);
         for (final SavingsAccountTransaction transaction : transactions) {
             if (transaction.isWithdrawalFeeAndNotReversed() && transaction.isNotReversed()) {
@@ -72,7 +72,7 @@ public final class SavingsAccountTransactionSummaryWrapper {
         return total.getAmountDefaultedToNullIfZero();
     }
 
-    public BigDecimal calculateTotalAnnualFees(final MonetaryCurrency currency, final Set<SavingsAccountTransaction> transactions) {
+    public BigDecimal calculateTotalAnnualFees(final MonetaryCurrency currency, final List<SavingsAccountTransaction> transactions) {
         Money total = Money.zero(currency);
         for (final SavingsAccountTransaction transaction : transactions) {
             if (transaction.isAnnualFeeAndNotReversed() && transaction.isNotReversed()) {
@@ -82,7 +82,7 @@ public final class SavingsAccountTransactionSummaryWrapper {
         return total.getAmountDefaultedToNullIfZero();
     }
 
-    public BigDecimal calculateTotalFeesCharge(final MonetaryCurrency currency, final Set<SavingsAccountTransaction> transactions) {
+    public BigDecimal calculateTotalFeesCharge(final MonetaryCurrency currency, final List<SavingsAccountTransaction> transactions) {
         Money total = Money.zero(currency);
         for (final SavingsAccountTransaction transaction : transactions) {
             if (transaction.isFeeChargeAndNotReversed()) {
@@ -92,7 +92,7 @@ public final class SavingsAccountTransactionSummaryWrapper {
         return total.getAmountDefaultedToNullIfZero();
     }
 
-    public BigDecimal calculateTotalFeesChargeWaived(final MonetaryCurrency currency, final Set<SavingsAccountTransaction> transactions) {
+    public BigDecimal calculateTotalFeesChargeWaived(final MonetaryCurrency currency, final List<SavingsAccountTransaction> transactions) {
         Money total = Money.zero(currency);
         for (final SavingsAccountTransaction transaction : transactions) {
             if (transaction.isWaiveFeeChargeAndNotReversed()) {
@@ -102,7 +102,7 @@ public final class SavingsAccountTransactionSummaryWrapper {
         return total.getAmountDefaultedToNullIfZero();
     }
 
-    public BigDecimal calculateTotalPenaltyCharge(final MonetaryCurrency currency, final Set<SavingsAccountTransaction> transactions) {
+    public BigDecimal calculateTotalPenaltyCharge(final MonetaryCurrency currency, final List<SavingsAccountTransaction> transactions) {
         Money total = Money.zero(currency);
         for (final SavingsAccountTransaction transaction : transactions) {
             if (transaction.isPenaltyChargeAndNotReversed()) {
@@ -112,7 +112,7 @@ public final class SavingsAccountTransactionSummaryWrapper {
         return total.getAmountDefaultedToNullIfZero();
     }
 
-    public BigDecimal calculateTotalPenaltyChargeWaived(final MonetaryCurrency currency, final Set<SavingsAccountTransaction> transactions) {
+    public BigDecimal calculateTotalPenaltyChargeWaived(final MonetaryCurrency currency, final List<SavingsAccountTransaction> transactions) {
         Money total = Money.zero(currency);
         for (final SavingsAccountTransaction transaction : transactions) {
             if (transaction.isWaivePenaltyChargeAndNotReversed()) {
@@ -122,7 +122,7 @@ public final class SavingsAccountTransactionSummaryWrapper {
         return total.getAmountDefaultedToNullIfZero();
     }
 
-    public BigDecimal calculateTotalOverdraftInterest(MonetaryCurrency currency, Set<SavingsAccountTransaction> transactions) {
+    public BigDecimal calculateTotalOverdraftInterest(MonetaryCurrency currency, List<SavingsAccountTransaction> transactions) {
         Money total = Money.zero(currency);
         for (final SavingsAccountTransaction transaction : transactions) {
             if (transaction.isOverdraftInterestAndNotReversed()) {
@@ -131,7 +131,7 @@ public final class SavingsAccountTransactionSummaryWrapper {
         }
         return total.getAmountDefaultedToNullIfZero();
     }
-    public BigDecimal calculateTotalWithholdTaxWithdrawal(MonetaryCurrency currency, Set<SavingsAccountTransaction> transactions) {
+    public BigDecimal calculateTotalWithholdTaxWithdrawal(MonetaryCurrency currency, List<SavingsAccountTransaction> transactions) {
         Money total = Money.zero(currency);
         for (final SavingsAccountTransaction transaction : transactions) {
             if (transaction.isWithHoldTaxAndNotReversed()) {

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java
index 75ed667..5f2834d 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java
@@ -18,6 +18,23 @@
  */
 package org.apache.fineract.portfolio.savings.service;
 
+import static org.apache.fineract.portfolio.savings.DepositsApiConstants.RECURRING_DEPOSIT_ACCOUNT_RESOURCE_NAME;
+import static org.apache.fineract.portfolio.savings.SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME;
+import static org.apache.fineract.portfolio.savings.SavingsApiConstants.amountParamName;
+import static org.apache.fineract.portfolio.savings.SavingsApiConstants.chargeIdParamName;
+import static org.apache.fineract.portfolio.savings.SavingsApiConstants.dueAsOfDateParamName;
+
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.commons.lang.StringUtils;
 import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService;
 import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
@@ -84,7 +101,7 @@ import org.apache.fineract.portfolio.savings.domain.RecurringDepositAccount;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccountCharge;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccountChargeRepositoryWrapper;
-import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepository;
+import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepositoryWrapper;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccountStatusType;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccountTransaction;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccountTransactionRepository;
@@ -100,28 +117,11 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.math.BigDecimal;
-import java.math.MathContext;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import static org.apache.fineract.portfolio.savings.DepositsApiConstants.RECURRING_DEPOSIT_ACCOUNT_RESOURCE_NAME;
-import static org.apache.fineract.portfolio.savings.SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME;
-import static org.apache.fineract.portfolio.savings.SavingsApiConstants.amountParamName;
-import static org.apache.fineract.portfolio.savings.SavingsApiConstants.chargeIdParamName;
-import static org.apache.fineract.portfolio.savings.SavingsApiConstants.dueAsOfDateParamName;
-
 @Service
 public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements DepositAccountWritePlatformService {
 
     private final PlatformSecurityContext context;
-    private final SavingsAccountRepository savingAccountRepository;
+    private final SavingsAccountRepositoryWrapper savingAccountRepositoryWrapper;
     private final SavingsAccountTransactionRepository savingsAccountTransactionRepository;
     private final DepositAccountAssembler depositAccountAssembler;
     private final DepositAccountTransactionDataValidator depositAccountTransactionDataValidator;
@@ -146,7 +146,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
 
     @Autowired
     public DepositAccountWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
-            final SavingsAccountRepository savingAccountRepository,
+            final SavingsAccountRepositoryWrapper savingAccountRepositoryWrapper,
             final SavingsAccountTransactionRepository savingsAccountTransactionRepository,
             final DepositAccountAssembler depositAccountAssembler,
             final DepositAccountTransactionDataValidator depositAccountTransactionDataValidator,
@@ -165,7 +165,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
             final DepositAccountOnHoldTransactionRepository depositAccountOnHoldTransactionRepository) {
 
         this.context = context;
-        this.savingAccountRepository = savingAccountRepository;
+        this.savingAccountRepositoryWrapper = savingAccountRepositoryWrapper;
         this.savingsAccountTransactionRepository = savingsAccountTransactionRepository;
         this.depositAccountAssembler = depositAccountAssembler;
         this.depositAccountTransactionDataValidator = depositAccountTransactionDataValidator;
@@ -256,7 +256,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
                 depositAccountOnHoldTransactions = this.depositAccountOnHoldTransactionRepository.findBySavingsAccountAndReversedFalseOrderByCreatedDateAsc(account);
             }
             account.validateAccountBalanceDoesNotBecomeNegative(SavingsAccountTransactionType.PAY_CHARGE.name(),depositAccountOnHoldTransactions);
-            this.savingAccountRepository.save(account);
+            this.savingAccountRepositoryWrapper.save(account);
         }
 
         postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
@@ -354,7 +354,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
 
             account.validateAccountBalanceDoesNotBecomeNegative(SavingsAccountTransactionType.PAY_CHARGE.name(),depositAccountOnHoldTransactions);
 
-            this.savingAccountRepository.save(account);
+            this.savingAccountRepositoryWrapper.save(account);
         }
 
         postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
@@ -497,7 +497,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
         account.calculateInterestUsing(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
                 financialYearBeginningMonth);
 
-        this.savingAccountRepository.save(account);
+        this.savingAccountRepositoryWrapper.save(account);
 
         return new CommandProcessingResultBuilder() //
                 .withEntityId(savingsId) //
@@ -538,7 +538,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
         final MathContext mc = new MathContext(10, MoneyHelper.getRoundingMode());
         boolean isInterestTransfer = false;
         account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
-        this.savingAccountRepository.save(account);
+        this.savingAccountRepositoryWrapper.save(account);
 
         postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
     }
@@ -926,7 +926,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
                 financialYearBeginningMonth);
 
         this.savingsAccountTransactionRepository.save(newTransferTransaction);
-        this.savingAccountRepository.save(savingsAccount);
+        this.savingAccountRepositoryWrapper.save(savingsAccount);
 
         postJournalEntries(savingsAccount, existingTransactionIds, existingReversedTransactionIds);
 
@@ -959,7 +959,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
                 financialYearBeginningMonth);
 
         this.savingsAccountTransactionRepository.save(withdrawtransferTransaction);
-        this.savingAccountRepository.save(savingsAccount);
+        this.savingAccountRepositoryWrapper.save(savingsAccount);
 
         postJournalEntries(savingsAccount, existingTransactionIds, existingReversedTransactionIds);
 
@@ -970,7 +970,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
     public void rejectSavingsTransfer(final Long accountId, final DepositAccountType depositAccountType) {
         final SavingsAccount savingsAccount = this.depositAccountAssembler.assembleFrom(accountId, depositAccountType);
         savingsAccount.setStatus(SavingsAccountStatusType.TRANSFER_ON_HOLD.getValue());
-        this.savingAccountRepository.save(savingsAccount);
+        this.savingAccountRepositoryWrapper.save(savingsAccount);
     }
 
     @Override
@@ -1002,7 +1002,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
                 financialYearBeginningMonth);
 
         this.savingsAccountTransactionRepository.save(acceptTransferTransaction);
-        this.savingAccountRepository.save(savingsAccount);
+        this.savingAccountRepositoryWrapper.save(savingsAccount);
 
         postJournalEntries(savingsAccount, existingTransactionIds, existingReversedTransactionIds);
 
@@ -1053,7 +1053,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
 
         savingsAccount.addCharge(fmt, savingsAccountCharge, chargeDefinition);
 
-        this.savingAccountRepository.saveAndFlush(savingsAccount);
+        this.savingAccountRepositoryWrapper.saveAndFlush(savingsAccount);
 
         return new CommandProcessingResultBuilder() //
                 .withEntityId(savingsAccountCharge.getId()) //
@@ -1158,7 +1158,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
 
         account.validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.waiveChargeTransactionAction,depositAccountOnHoldTransactions);
 
-        this.savingAccountRepository.saveAndFlush(account);
+        this.savingAccountRepositoryWrapper.saveAndFlush(account);
 
         postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
 
@@ -1183,7 +1183,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
                 .findOneWithNotFoundDetection(savingsAccountChargeId, savingsAccountId);
 
         savingsAccount.removeCharge(savingsAccountCharge);
-        this.savingAccountRepository.saveAndFlush(savingsAccount);
+        this.savingAccountRepositoryWrapper.saveAndFlush(savingsAccount);
 
         return new CommandProcessingResultBuilder() //
                 .withEntityId(savingsAccountChargeId) //
@@ -1289,7 +1289,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
 
         account.validateAccountBalanceDoesNotBecomeNegative("." + SavingsAccountTransactionType.PAY_CHARGE.getCode(),depositAccountOnHoldTransactions);
 
-        this.savingAccountRepository.save(account);
+        this.savingAccountRepositoryWrapper.save(account);
 
         postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
     }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformService.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformService.java
index d428d42..c8bf578 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformService.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformService.java
@@ -49,13 +49,13 @@ public interface SavingsAccountWritePlatformService {
 
     CommandProcessingResult close(Long savingsId, JsonCommand command);
 
-    SavingsAccountTransaction initiateSavingsTransfer(Long accountId, LocalDate transferDate);
+    SavingsAccountTransaction initiateSavingsTransfer(SavingsAccount account, LocalDate transferDate);
 
-    SavingsAccountTransaction withdrawSavingsTransfer(Long accountId, LocalDate transferDate);
+    SavingsAccountTransaction withdrawSavingsTransfer(SavingsAccount account, LocalDate transferDate);
 
-    void rejectSavingsTransfer(Long accountId);
+    void rejectSavingsTransfer(SavingsAccount account);
 
-    SavingsAccountTransaction acceptSavingsTransfer(Long accountId, LocalDate transferDate, Office acceptedInOffice, Staff staff);
+    SavingsAccountTransaction acceptSavingsTransfer(SavingsAccount account, LocalDate transferDate, Office acceptedInOffice, Staff staff);
 
     CommandProcessingResult addSavingsAccountCharge(JsonCommand command);
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/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 9fe5f17..30ce57b 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
@@ -91,7 +91,6 @@ import org.apache.fineract.portfolio.savings.domain.SavingsAccountAssembler;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccountCharge;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccountChargeRepositoryWrapper;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccountDomainService;
-import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepository;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepositoryWrapper;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccountStatusType;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccountTransaction;
@@ -115,9 +114,8 @@ import org.springframework.util.CollectionUtils;
 public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements SavingsAccountWritePlatformService {
 
     private final PlatformSecurityContext context;
-    private final SavingsAccountRepository savingAccountRepository;
     private final SavingsAccountDataValidator fromApiJsonDeserializer;
-    private final SavingsAccountRepositoryWrapper savingsRepository;
+    private final SavingsAccountRepositoryWrapper savingAccountRepositoryWrapper;
     private final StaffRepositoryWrapper staffRepository;
     private final SavingsAccountTransactionRepository savingsAccountTransactionRepository;
     private final SavingsAccountAssembler savingAccountAssembler;
@@ -141,7 +139,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
 
     @Autowired
     public SavingsAccountWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
-            final SavingsAccountRepository savingAccountRepository,
+            final SavingsAccountRepositoryWrapper savingAccountRepositoryWrapper,
             final SavingsAccountTransactionRepository savingsAccountTransactionRepository,
             final SavingsAccountAssembler savingAccountAssembler,
             final SavingsAccountTransactionDataValidator savingsAccountTransactionDataValidator,
@@ -154,13 +152,13 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
             final HolidayRepositoryWrapper holidayRepository, final WorkingDaysRepositoryWrapper workingDaysRepository,
             final AccountAssociationsReadPlatformService accountAssociationsReadPlatformService,
             final ChargeRepositoryWrapper chargeRepository, final SavingsAccountChargeRepositoryWrapper savingsAccountChargeRepository,
-            final SavingsAccountDataValidator fromApiJsonDeserializer, final SavingsAccountRepositoryWrapper savingsRepository,
+            final SavingsAccountDataValidator fromApiJsonDeserializer, 
             final StaffRepositoryWrapper staffRepository, final ConfigurationDomainService configurationDomainService,
             final DepositAccountOnHoldTransactionRepository depositAccountOnHoldTransactionRepository,
             final AppUserRepositoryWrapper appuserRepository, 
             final StandingInstructionRepository standingInstructionRepository) {
         this.context = context;
-        this.savingAccountRepository = savingAccountRepository;
+        this.savingAccountRepositoryWrapper = savingAccountRepositoryWrapper;
         this.savingsAccountTransactionRepository = savingsAccountTransactionRepository;
         this.savingAccountAssembler = savingAccountAssembler;
         this.savingsAccountTransactionDataValidator = savingsAccountTransactionDataValidator;
@@ -177,7 +175,6 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
         this.holidayRepository = holidayRepository;
         this.workingDaysRepository = workingDaysRepository;
         this.fromApiJsonDeserializer = fromApiJsonDeserializer;
-        this.savingsRepository = savingsRepository;
         this.staffRepository = staffRepository;
         this.configurationDomainService = configurationDomainService;
         this.depositAccountOnHoldTransactionRepository = depositAccountOnHoldTransactionRepository;
@@ -205,7 +202,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
             final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
             processPostActiveActions(account, fmt, existingTransactionIds, existingReversedTransactionIds);
 
-            this.savingAccountRepository.save(account);
+            this.savingAccountRepositoryWrapper.save(account);
         }
 
         postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
@@ -364,7 +361,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
         account.calculateInterestUsing(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
                 financialYearBeginningMonth);
 
-        this.savingAccountRepository.save(account);
+        this.savingAccountRepositoryWrapper.save(account);
 
         return new CommandProcessingResultBuilder() //
                 .withEntityId(savingsId) //
@@ -416,7 +413,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
                 }
             }
 
-            this.savingAccountRepository.save(account);
+            this.savingAccountRepositoryWrapper.save(account);
 
             postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
         }
@@ -644,7 +641,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
         final Map<String, Object> accountChanges = account.close(user, command, DateUtils.getLocalDateOfTenant());
         changes.putAll(accountChanges);
         if (!changes.isEmpty()) {
-            this.savingAccountRepository.save(account);
+            this.savingAccountRepositoryWrapper.save(account);
             final String noteText = command.stringValueOfParameterNamed("note");
             if (StringUtils.isNotBlank(noteText)) {
                 final Note note = Note.savingNote(account, noteText);
@@ -668,16 +665,14 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
     }
 
     @Override
-    public SavingsAccountTransaction initiateSavingsTransfer(final Long accountId, final LocalDate transferDate) {
+    public SavingsAccountTransaction initiateSavingsTransfer(final SavingsAccount savingsAccount, final LocalDate transferDate) {
 
         AppUser user = getAppUserIfPresent();
 
         final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
                 .isSavingsInterestPostingAtCurrentPeriodEnd();
         final Integer financialYearBeginningMonth = this.configurationDomainService.retrieveFinancialYearBeginningMonth();
-
-        final SavingsAccount savingsAccount = this.savingAccountAssembler.assembleFrom(accountId);
-
+        this.savingAccountAssembler.setHelpers(savingsAccount);
         final Set<Long> existingTransactionIds = new HashSet<>();
         final Set<Long> existingReversedTransactionIds = new HashSet<>();
         updateExistingTransactionsDetails(savingsAccount, existingTransactionIds, existingReversedTransactionIds);
@@ -692,7 +687,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
                 financialYearBeginningMonth);
 
         this.savingsAccountTransactionRepository.save(newTransferTransaction);
-        this.savingAccountRepository.save(savingsAccount);
+        this.savingAccountRepositoryWrapper.save(savingsAccount);
 
         postJournalEntries(savingsAccount, existingTransactionIds, existingReversedTransactionIds);
 
@@ -700,16 +695,14 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
     }
 
     @Override
-    public SavingsAccountTransaction withdrawSavingsTransfer(final Long accountId, final LocalDate transferDate) {
+    public SavingsAccountTransaction withdrawSavingsTransfer(final SavingsAccount savingsAccount, final LocalDate transferDate) {
 
         AppUser user = getAppUserIfPresent();
 
         final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
                 .isSavingsInterestPostingAtCurrentPeriodEnd();
         final Integer financialYearBeginningMonth = this.configurationDomainService.retrieveFinancialYearBeginningMonth();
-
-        final SavingsAccount savingsAccount = this.savingAccountAssembler.assembleFrom(accountId);
-
+        this.savingAccountAssembler.setHelpers(savingsAccount);
         final Set<Long> existingTransactionIds = new HashSet<>();
         final Set<Long> existingReversedTransactionIds = new HashSet<>();
         updateExistingTransactionsDetails(savingsAccount, existingTransactionIds, existingReversedTransactionIds);
@@ -724,7 +717,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
                 financialYearBeginningMonth);
 
         this.savingsAccountTransactionRepository.save(withdrawtransferTransaction);
-        this.savingAccountRepository.save(savingsAccount);
+        this.savingAccountRepositoryWrapper.save(savingsAccount);
 
         postJournalEntries(savingsAccount, existingTransactionIds, existingReversedTransactionIds);
 
@@ -732,14 +725,14 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
     }
 
     @Override
-    public void rejectSavingsTransfer(final Long accountId) {
-        final SavingsAccount savingsAccount = this.savingAccountAssembler.assembleFrom(accountId);
+    public void rejectSavingsTransfer(final SavingsAccount savingsAccount) {
+        this.savingAccountAssembler.setHelpers(savingsAccount);
         savingsAccount.setStatus(SavingsAccountStatusType.TRANSFER_ON_HOLD.getValue());
-        this.savingAccountRepository.save(savingsAccount);
+        this.savingAccountRepositoryWrapper.save(savingsAccount);
     }
 
     @Override
-    public SavingsAccountTransaction acceptSavingsTransfer(final Long accountId, final LocalDate transferDate,
+    public SavingsAccountTransaction acceptSavingsTransfer(final SavingsAccount savingsAccount, final LocalDate transferDate,
             final Office acceptedInOffice, final Staff fieldOfficer) {
 
         AppUser user = getAppUserIfPresent();
@@ -747,9 +740,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
         final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
                 .isSavingsInterestPostingAtCurrentPeriodEnd();
         final Integer financialYearBeginningMonth = this.configurationDomainService.retrieveFinancialYearBeginningMonth();
-
-        final SavingsAccount savingsAccount = this.savingAccountAssembler.assembleFrom(accountId);
-
+        this.savingAccountAssembler.setHelpers(savingsAccount);
         final Set<Long> existingTransactionIds = new HashSet<>();
         final Set<Long> existingReversedTransactionIds = new HashSet<>();
         updateExistingTransactionsDetails(savingsAccount, existingTransactionIds, existingReversedTransactionIds);
@@ -767,7 +758,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
                 financialYearBeginningMonth);
 
         this.savingsAccountTransactionRepository.save(acceptTransferTransaction);
-        this.savingAccountRepository.save(savingsAccount);
+        this.savingAccountRepositoryWrapper.save(savingsAccount);
 
         postJournalEntries(savingsAccount, existingTransactionIds, existingReversedTransactionIds);
 
@@ -825,7 +816,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
 
         savingsAccount.addCharge(fmt, savingsAccountCharge, chargeDefinition);
 
-        this.savingAccountRepository.saveAndFlush(savingsAccount);
+        this.savingAccountRepositoryWrapper.saveAndFlush(savingsAccount);
 
         return new CommandProcessingResultBuilder() //
                 .withEntityId(savingsAccountCharge.getId()) //
@@ -931,7 +922,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
         account.validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.waiveChargeTransactionAction,
                 depositAccountOnHoldTransactions);
 
-        this.savingAccountRepository.saveAndFlush(account);
+        this.savingAccountRepositoryWrapper.saveAndFlush(account);
 
         postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
 
@@ -956,7 +947,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
                 savingsAccountChargeId, savingsAccountId);
 
         savingsAccount.removeCharge(savingsAccountCharge);
-        this.savingAccountRepository.saveAndFlush(savingsAccount);
+        this.savingAccountRepositoryWrapper.saveAndFlush(savingsAccount);
 
         return new CommandProcessingResultBuilder() //
                 .withEntityId(savingsAccountChargeId) //
@@ -1063,7 +1054,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
         account.validateAccountBalanceDoesNotBecomeNegative("." + SavingsAccountTransactionType.PAY_CHARGE.getCode(),
                 depositAccountOnHoldTransactions);
 
-        this.savingAccountRepository.save(account);
+        this.savingAccountRepositoryWrapper.save(account);
 
         postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
     }
@@ -1163,7 +1154,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
         Staff toSavingsOfficer = null;
         this.fromApiJsonDeserializer.validateForAssignSavingsOfficer(command.json());
 
-        final SavingsAccount savingsForUpdate = this.savingsRepository.findOneWithNotFoundDetection(savingsAccountId);
+        final SavingsAccount savingsForUpdate = this.savingAccountRepositoryWrapper.findOneWithNotFoundDetection(savingsAccountId);
         final Long fromSavingsOfficerId = command.longValueOfParameterNamed("fromSavingsOfficerId");
         final Long toSavingsOfficerId = command.longValueOfParameterNamed("toSavingsOfficerId");
         final LocalDate dateOfSavingsOfficerAssignment = command.localDateValueOfParameterNamed("assignmentDate");
@@ -1182,7 +1173,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
 
         savingsForUpdate.reassignSavingsOfficer(toSavingsOfficer, dateOfSavingsOfficerAssignment);
 
-        this.savingsRepository.saveAndFlush(savingsForUpdate);
+        this.savingAccountRepositoryWrapper.saveAndFlush(savingsForUpdate);
 
         return new CommandProcessingResultBuilder() //
                 .withCommandId(command.commandId()) //
@@ -1202,14 +1193,14 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
         final Map<String, Object> actualChanges = new LinkedHashMap<>(5);
         this.fromApiJsonDeserializer.validateForUnAssignSavingsOfficer(command.json());
 
-        final SavingsAccount savingsForUpdate = this.savingsRepository.findOneWithNotFoundDetection(savingsAccountId);
+        final SavingsAccount savingsForUpdate = this.savingAccountRepositoryWrapper.findOneWithNotFoundDetection(savingsAccountId);
         if (savingsForUpdate.getSavingsOfficer() == null) { throw new SavingsOfficerUnassignmentException(savingsAccountId); }
 
         final LocalDate dateOfSavingsOfficerUnassigned = command.localDateValueOfParameterNamed("unassignedDate");
 
         savingsForUpdate.removeSavingsOfficer(dateOfSavingsOfficerUnassigned);
 
-        this.savingsRepository.saveAndFlush(savingsForUpdate);
+        this.savingAccountRepositoryWrapper.saveAndFlush(savingsForUpdate);
 
         actualChanges.put("toSavingsOfficerId", null);
 
@@ -1225,7 +1216,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
     @Override
     public CommandProcessingResult modifyWithHoldTax(Long savingsAccountId, JsonCommand command) {
         final Map<String, Object> actualChanges = new HashMap<>(1);
-        final SavingsAccount savingsForUpdate = this.savingsRepository.findOneWithNotFoundDetection(savingsAccountId);
+        final SavingsAccount savingsForUpdate = this.savingAccountRepositoryWrapper.findOneWithNotFoundDetection(savingsAccountId);
         if (command.isChangeInBooleanParameterNamed(withHoldTaxParamName, savingsForUpdate.withHoldTax())) {
             final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(withHoldTaxParamName);
             actualChanges.put(withHoldTaxParamName, newValue);
@@ -1254,7 +1245,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
         final Set<Long> existingReversedTransactionIds = new HashSet<>();
         updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
         account.setSubStatusInactive(appuserRepository.fetchSystemUser());
-        this.savingAccountRepository.save(account);
+        this.savingAccountRepositoryWrapper.save(account);
         postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
     }
 
@@ -1263,7 +1254,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
 	public void setSubStatusDormant(Long savingsId){
         final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId);
         account.setSubStatusDormant();
-    	this.savingAccountRepository.save(account);
+    	this.savingAccountRepositoryWrapper.save(account);
     }
 
     @Override
@@ -1274,7 +1265,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
         final Set<Long> existingReversedTransactionIds = new HashSet<>();
         updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
         account.escheat(appuserRepository.fetchSystemUser());
-        this.savingAccountRepository.save(account);
+        this.savingAccountRepositoryWrapper.save(account);
         postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
     }
 	

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsSchedularServiceImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsSchedularServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsSchedularServiceImpl.java
index 24aefa6..7563f85 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsSchedularServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsSchedularServiceImpl.java
@@ -26,7 +26,7 @@ import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException;
 import org.apache.fineract.infrastructure.jobs.service.JobName;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccountAssembler;
-import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepository;
+import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepositoryWrapper;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccountStatusType;
 import org.joda.time.LocalDate;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -37,24 +37,24 @@ public class SavingsSchedularServiceImpl implements SavingsSchedularService {
 
     private final SavingsAccountAssembler savingAccountAssembler;
     private final SavingsAccountWritePlatformService savingsAccountWritePlatformService;
-    private final SavingsAccountRepository savingAccountRepository;
+    private final SavingsAccountRepositoryWrapper savingAccountRepositoryWrapper;
     private final SavingsAccountReadPlatformService savingAccountReadPlatformService;
 
     @Autowired
     public SavingsSchedularServiceImpl(final SavingsAccountAssembler savingAccountAssembler,
             final SavingsAccountWritePlatformService savingsAccountWritePlatformService,
-            final SavingsAccountRepository savingAccountRepository,
+            final SavingsAccountRepositoryWrapper savingAccountRepositoryWrapper,
             final SavingsAccountReadPlatformService savingAccountReadPlatformService) {
         this.savingAccountAssembler = savingAccountAssembler;
         this.savingsAccountWritePlatformService = savingsAccountWritePlatformService;
-        this.savingAccountRepository = savingAccountRepository;
+        this.savingAccountRepositoryWrapper = savingAccountRepositoryWrapper;
         this.savingAccountReadPlatformService = savingAccountReadPlatformService;
     }
 
     @CronTarget(jobName = JobName.POST_INTEREST_FOR_SAVINGS)
     @Override
     public void postInterestForAccounts() throws JobExecutionException {
-        final List<SavingsAccount> savingsAccounts = this.savingAccountRepository.findSavingAccountByStatus(SavingsAccountStatusType.ACTIVE
+        final List<SavingsAccount> savingsAccounts = this.savingAccountRepositoryWrapper.findSavingAccountByStatus(SavingsAccountStatusType.ACTIVE
                 .getValue());
         StringBuffer sb = new StringBuffer();
         for (final SavingsAccount savingsAccount : savingsAccounts) {

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/account/service/SelfBeneficiariesTPTWritePlatformServiceImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/account/service/SelfBeneficiariesTPTWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/account/service/SelfBeneficiariesTPTWritePlatformServiceImpl.java
index 9a4e8fd..e24c45d 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/account/service/SelfBeneficiariesTPTWritePlatformServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/account/service/SelfBeneficiariesTPTWritePlatformServiceImpl.java
@@ -34,9 +34,9 @@ import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityEx
 import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
 import org.apache.fineract.portfolio.account.PortfolioAccountType;
 import org.apache.fineract.portfolio.loanaccount.domain.Loan;
-import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
-import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepository;
+import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepositoryWrapper;
 import org.apache.fineract.portfolio.self.account.data.SelfBeneficiariesTPTDataValidator;
 import org.apache.fineract.portfolio.self.account.domain.SelfBeneficiariesTPT;
 import org.apache.fineract.portfolio.self.account.domain.SelfBeneficiariesTPTRepository;
@@ -58,21 +58,21 @@ public class SelfBeneficiariesTPTWritePlatformServiceImpl implements
 	private final PlatformSecurityContext context;
 	private final SelfBeneficiariesTPTRepository repository;
 	private final SelfBeneficiariesTPTDataValidator validator;
-	private final LoanRepository loanRepo;
-	private final SavingsAccountRepository savingRepo;
+	private final LoanRepositoryWrapper loanRepositoryWrapper;
+	private final SavingsAccountRepositoryWrapper savingRepositoryWrapper;
 
 	@Autowired
 	public SelfBeneficiariesTPTWritePlatformServiceImpl(
 			final PlatformSecurityContext context,
 			final SelfBeneficiariesTPTRepository repository,
 			final SelfBeneficiariesTPTDataValidator validator,
-			final LoanRepository loanRepo,
-			final SavingsAccountRepository savingRepo) {
+			final LoanRepositoryWrapper loanRepositoryWrapper,
+			final SavingsAccountRepositoryWrapper savingRepositoryWrapper) {
 		this.context = context;
 		this.repository = repository;
 		this.validator = validator;
-		this.loanRepo = loanRepo;
-		this.savingRepo = savingRepo;
+		this.loanRepositoryWrapper = loanRepositoryWrapper;
+		this.savingRepositoryWrapper = savingRepositoryWrapper;
 		this.logger = LoggerFactory
 				.getLogger(SelfBeneficiariesTPTWritePlatformServiceImpl.class);
 	}
@@ -95,8 +95,7 @@ public class SelfBeneficiariesTPTWritePlatformServiceImpl implements
 
 		boolean validAccountDetails = true;
 		if (accountType.equals(PortfolioAccountType.LOAN)) {
-			Loan loan = this.loanRepo
-					.findNonClosedLoanByAccountNumber(accountNumber);
+			Loan loan = this.loanRepositoryWrapper.findNonClosedLoanByAccountNumber(accountNumber);
 			if (loan != null && loan.getClientId() != null
 					&& loan.getOffice().getName().equals(officeName)) {
 				accountId = loan.getId();
@@ -106,7 +105,7 @@ public class SelfBeneficiariesTPTWritePlatformServiceImpl implements
 				validAccountDetails = false;
 			}
 		} else {
-			SavingsAccount savings = this.savingRepo
+			SavingsAccount savings = this.savingRepositoryWrapper
 					.findNonClosedAccountByAccountNumber(accountNumber);
 			if (savings != null
 					&& savings.getClient() != null

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/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 6a7442a..c63bac7 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
@@ -45,11 +45,11 @@ import org.apache.fineract.portfolio.group.domain.GroupRepositoryWrapper;
 import org.apache.fineract.portfolio.group.exception.ClientNotInGroupException;
 import org.apache.fineract.portfolio.group.exception.GroupNotActiveException;
 import org.apache.fineract.portfolio.loanaccount.domain.Loan;
-import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
 import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
 import org.apache.fineract.portfolio.note.service.NoteWritePlatformService;
 import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
-import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepository;
+import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepositoryWrapper;
 import org.apache.fineract.portfolio.savings.service.SavingsAccountWritePlatformService;
 import org.apache.fineract.portfolio.transfer.api.TransferApiConstants;
 import org.apache.fineract.portfolio.transfer.data.TransfersDataValidator;
@@ -68,36 +68,36 @@ import com.google.gson.JsonObject;
 @Service
 public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWritePlatformService {
 
-    private final ClientRepositoryWrapper clientRepository;
+    private final ClientRepositoryWrapper clientRepositoryWrapper;
     private final OfficeRepositoryWrapper officeRepository;
     private final CalendarInstanceRepository calendarInstanceRepository;
     private final GroupRepositoryWrapper groupRepository;
     private final LoanWritePlatformService loanWritePlatformService;
     private final SavingsAccountWritePlatformService savingsAccountWritePlatformService;
-    private final LoanRepository loanRepository;
-    private final SavingsAccountRepository savingsAccountRepository;
+    private final LoanRepositoryWrapper loanRepositoryWrapper;
+    private final SavingsAccountRepositoryWrapper savingsAccountRepositoryWrapper;
     private final TransfersDataValidator transfersDataValidator;
     private final NoteWritePlatformService noteWritePlatformService;
     private final StaffRepositoryWrapper staffRepositoryWrapper;
 
     @Autowired
-    public TransferWritePlatformServiceJpaRepositoryImpl(final ClientRepositoryWrapper clientRepository,
+    public TransferWritePlatformServiceJpaRepositoryImpl(final ClientRepositoryWrapper clientRepositoryWrapper,
             final OfficeRepositoryWrapper officeRepository, final CalendarInstanceRepository calendarInstanceRepository,
             final LoanWritePlatformService loanWritePlatformService, final GroupRepositoryWrapper groupRepository,
-            final LoanRepository loanRepository, final TransfersDataValidator transfersDataValidator,
+            final LoanRepositoryWrapper loanRepositoryWrapper, final TransfersDataValidator transfersDataValidator,
             final NoteWritePlatformService noteWritePlatformService, final StaffRepositoryWrapper staffRepositoryWrapper,
-            final SavingsAccountRepository savingsAccountRepository,
+            final SavingsAccountRepositoryWrapper savingsAccountRepositoryWrapper,
             final SavingsAccountWritePlatformService savingsAccountWritePlatformService) {
-        this.clientRepository = clientRepository;
+        this.clientRepositoryWrapper = clientRepositoryWrapper;
         this.officeRepository = officeRepository;
         this.calendarInstanceRepository = calendarInstanceRepository;
         this.loanWritePlatformService = loanWritePlatformService;
         this.groupRepository = groupRepository;
-        this.loanRepository = loanRepository;
+        this.loanRepositoryWrapper = loanRepositoryWrapper;
         this.transfersDataValidator = transfersDataValidator;
         this.noteWritePlatformService = noteWritePlatformService;
         this.staffRepositoryWrapper = staffRepositoryWrapper;
-        this.savingsAccountRepository = savingsAccountRepository;
+        this.savingsAccountRepositoryWrapper = savingsAccountRepositoryWrapper;
         this.savingsAccountWritePlatformService = savingsAccountWritePlatformService;
     }
 
@@ -214,12 +214,12 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr
         }
 
         client.getGroups().add(destinationGroup);
-        this.clientRepository.saveAndFlush(client);
+        this.clientRepositoryWrapper.saveAndFlush(client);
 
         /**
          * Active JLG loans are now linked to the new Group and Loan officer
          **/
-        final List<Loan> allClientJLGLoans = this.loanRepository.findByClientIdAndGroupId(client.getId(), sourceGroup.getId());
+        final List<Loan> allClientJLGLoans = this.loanRepositoryWrapper.findByClientIdAndGroupId(client.getId(), sourceGroup.getId());
         for (final Loan loan : allClientJLGLoans) {
             if (loan.status().isActiveOrAwaitingApprovalOrDisbursal()) {
                 loan.updateGroup(destinationGroup);
@@ -229,7 +229,7 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr
                 } else if (newLoanOfficer != null) {
                     loan.reassignLoanOfficer(newLoanOfficer, DateUtils.getLocalDateOfTenant());
                 }
-                this.loanRepository.saveAndFlush(loan);
+                this.loanRepositoryWrapper.saveAndFlush(loan);
             }
         }
 
@@ -260,11 +260,11 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr
 
         final Long destinationOfficeId = jsonCommand.longValueOfParameterNamed(TransferApiConstants.destinationOfficeIdParamName);
         final Office office = this.officeRepository.findOneWithNotFoundDetection(destinationOfficeId);
-        final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId);
+        final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId, true);
         handleClientTransferLifecycleEvent(client, office, TransferEventType.PROPOSAL, jsonCommand);
-        this.clientRepository.saveAndFlush(client);
+        this.clientRepositoryWrapper.saveAndFlush(client);
         handleClientTransferLifecycleEvent(client, client.getTransferToOffice(), TransferEventType.ACCEPTANCE, jsonCommand);
-        this.clientRepository.save(client);
+        this.clientRepositoryWrapper.save(client);
 
         return new CommandProcessingResultBuilder() //
                 .withClientId(clientId) //
@@ -292,9 +292,9 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr
 
         final Long destinationOfficeId = jsonCommand.longValueOfParameterNamed(TransferApiConstants.destinationOfficeIdParamName);
         final Office office = this.officeRepository.findOneWithNotFoundDetection(destinationOfficeId);
-        final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId);
+        final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId);
         handleClientTransferLifecycleEvent(client, office, TransferEventType.PROPOSAL, jsonCommand);
-        this.clientRepository.save(client);
+        this.clientRepositoryWrapper.save(client);
 
         return new CommandProcessingResultBuilder() //
                 .withClientId(clientId) //
@@ -319,11 +319,11 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr
     public CommandProcessingResult acceptClientTransfer(final Long clientId, final JsonCommand jsonCommand) {
         // validation
         this.transfersDataValidator.validateForAcceptClientTransfer(jsonCommand.json());
-        final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId);
+        final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId, true);
         validateClientAwaitingTransferAcceptance(client);
 
         handleClientTransferLifecycleEvent(client, client.getTransferToOffice(), TransferEventType.ACCEPTANCE, jsonCommand);
-        this.clientRepository.save(client);
+        this.clientRepositoryWrapper.save(client);
 
         return new CommandProcessingResultBuilder() //
                 .withClientId(clientId) //
@@ -336,11 +336,11 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr
     public CommandProcessingResult withdrawClientTransfer(final Long clientId, final JsonCommand jsonCommand) {
         // validation
         this.transfersDataValidator.validateForWithdrawClientTransfer(jsonCommand.json());
-        final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId);
+        final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId);
         validateClientAwaitingTransferAcceptanceOnHold(client);
 
         handleClientTransferLifecycleEvent(client, client.getOffice(), TransferEventType.WITHDRAWAL, jsonCommand);
-        this.clientRepository.save(client);
+        this.clientRepositoryWrapper.save(client);
 
         return new CommandProcessingResultBuilder() //
                 .withClientId(clientId) //
@@ -353,9 +353,9 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr
     public CommandProcessingResult rejectClientTransfer(final Long clientId, final JsonCommand jsonCommand) {
         // validation
         this.transfersDataValidator.validateForRejectClientTransfer(jsonCommand.json());
-        final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId);
+        final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId);
         handleClientTransferLifecycleEvent(client, client.getOffice(), TransferEventType.REJECTION, jsonCommand);
-        this.clientRepository.save(client);
+        this.clientRepositoryWrapper.save(client);
 
         return new CommandProcessingResultBuilder() //
                 .withClientId(clientId) //
@@ -379,9 +379,9 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr
         }
 
         /*** Handle Active Loans ***/
-        if (this.loanRepository.doNonClosedLoanAccountsExistForClient(client.getId())) {
+        if (this.loanRepositoryWrapper.doNonClosedLoanAccountsExistForClient(client.getId())) {
             // get each individual loan for the client
-            for (final Loan loan : this.loanRepository.findLoanByClientId(client.getId())) {
+            for (final Loan loan : this.loanRepositoryWrapper.findLoanByClientId(client.getId())) {
                 /**
                  * We need to create transactions etc only for loans which are
                  * disbursed and not yet closed
@@ -389,41 +389,41 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr
                 if (loan.isDisbursed() && !loan.isClosed()) {
                     switch (transferEventType) {
                         case ACCEPTANCE:
-                            this.loanWritePlatformService.acceptLoanTransfer(loan.getId(), DateUtils.getLocalDateOfTenant(),
+                            this.loanWritePlatformService.acceptLoanTransfer(loan, DateUtils.getLocalDateOfTenant(),
                                     destinationOffice, staff);
                         break;
                         case PROPOSAL:
-                            this.loanWritePlatformService.initiateLoanTransfer(loan.getId(), DateUtils.getLocalDateOfTenant());
+                            this.loanWritePlatformService.initiateLoanTransfer(loan, DateUtils.getLocalDateOfTenant());
                         break;
                         case REJECTION:
-                            this.loanWritePlatformService.rejectLoanTransfer(loan.getId());
+                            this.loanWritePlatformService.rejectLoanTransfer(loan);
                         break;
                         case WITHDRAWAL:
-                            this.loanWritePlatformService.withdrawLoanTransfer(loan.getId(), DateUtils.getLocalDateOfTenant());
+                            this.loanWritePlatformService.withdrawLoanTransfer(loan, DateUtils.getLocalDateOfTenant());
                     }
                 }
             }
         }
 
         /*** Handle Active Savings (Currently throw and exception) ***/
-        if (this.savingsAccountRepository.doNonClosedSavingAccountsExistForClient(client.getId())) {
+        if (this.savingsAccountRepositoryWrapper.doNonClosedSavingAccountsExistForClient(client.getId())) {
             // get each individual saving account for the client
-            for (final SavingsAccount savingsAccount : this.savingsAccountRepository.findSavingAccountByClientId(client.getId())) {
+            for (final SavingsAccount savingsAccount : this.savingsAccountRepositoryWrapper.findSavingAccountByClientId(client.getId())) {
                 if (savingsAccount.isActivated() && !savingsAccount.isClosed()) {
                     switch (transferEventType) {
                         case ACCEPTANCE:
-                            this.savingsAccountWritePlatformService.acceptSavingsTransfer(savingsAccount.getId(),
+                            this.savingsAccountWritePlatformService.acceptSavingsTransfer(savingsAccount,
                                     DateUtils.getLocalDateOfTenant(), destinationOffice, staff);
                         break;
                         case PROPOSAL:
-                            this.savingsAccountWritePlatformService.initiateSavingsTransfer(savingsAccount.getId(),
+                            this.savingsAccountWritePlatformService.initiateSavingsTransfer(savingsAccount,
                                     DateUtils.getLocalDateOfTenant());
                         break;
                         case REJECTION:
-                            this.savingsAccountWritePlatformService.rejectSavingsTransfer(savingsAccount.getId());
+                            this.savingsAccountWritePlatformService.rejectSavingsTransfer(savingsAccount);
                         break;
                         case WITHDRAWAL:
-                            this.savingsAccountWritePlatformService.withdrawSavingsTransfer(savingsAccount.getId(),
+                            this.savingsAccountWritePlatformService.withdrawSavingsTransfer(savingsAccount,
                                     DateUtils.getLocalDateOfTenant());
                     }
                 }
@@ -480,7 +480,7 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr
                     final JsonObject jsonObject = clientsArray.get(i).getAsJsonObject();
                     if (jsonObject.has(TransferApiConstants.idParamName)) {
                         final Long id = jsonObject.get(TransferApiConstants.idParamName).getAsLong();
-                        final Client client = this.clientRepository.findOneWithNotFoundDetection(id);
+                        final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(id);
                         clients.add(client);
                     }
                 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/spm/api/ScorecardApiResource.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/api/ScorecardApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/spm/api/ScorecardApiResource.java
index b1e0fa5..9c4ed7d 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/spm/api/ScorecardApiResource.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/spm/api/ScorecardApiResource.java
@@ -18,10 +18,20 @@
  */
 package org.apache.fineract.spm.api;
 
+import java.util.Collections;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
 import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
 import org.apache.fineract.portfolio.client.domain.Client;
-import org.apache.fineract.portfolio.client.domain.ClientRepository;
-import org.apache.fineract.portfolio.client.exception.ClientNotFoundException;
+import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
 import org.apache.fineract.spm.data.ScorecardData;
 import org.apache.fineract.spm.domain.Scorecard;
 import org.apache.fineract.spm.domain.Survey;
@@ -35,11 +45,6 @@ import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 
-import javax.ws.rs.*;
-import javax.ws.rs.core.MediaType;
-import java.util.Collections;
-import java.util.List;
-
 @Path("/surveys/{surveyId}/scorecards")
 @Component
 @Scope("singleton")
@@ -48,16 +53,16 @@ public class ScorecardApiResource {
     private final PlatformSecurityContext securityContext;
     private final SpmService spmService;
     private final ScorecardService scorecardService;
-    private final ClientRepository clientRepository;
+    private final ClientRepositoryWrapper clientRepositoryWrapper;
 
     @Autowired
     public ScorecardApiResource(final PlatformSecurityContext securityContext, final SpmService spmService,
-                                final ScorecardService scorecardService, final ClientRepository clientRepository) {
+                                final ScorecardService scorecardService, final ClientRepositoryWrapper clientRepositoryWrapper) {
         super();
         this.securityContext = securityContext;
         this.spmService = spmService;
         this.scorecardService = scorecardService;
-        this.clientRepository = clientRepository;
+        this.clientRepositoryWrapper = clientRepositoryWrapper;
     }
 
     @GET
@@ -84,15 +89,8 @@ public class ScorecardApiResource {
     @Transactional
     public void createScorecard(@PathParam("surveyId") final Long surveyId, final ScorecardData scorecardData) {
         final AppUser appUser = this.securityContext.authenticatedUser();
-
         final Survey survey = findSurvey(surveyId);
-
-        final Client client = this.clientRepository.findOne(scorecardData.getClientId());
-
-        if (client == null) {
-            throw new ClientNotFoundException(scorecardData.getClientId());
-        }
-
+        final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(scorecardData.getClientId());
         this.scorecardService.createScorecard(ScorecardMapper.map(scorecardData, survey, appUser, client));
     }
 
@@ -104,21 +102,12 @@ public class ScorecardApiResource {
     public List<ScorecardData> findBySurveyClient(@PathParam("surveyId") final Long surveyId,
                                                   @PathParam("clientId") final Long clientId) {
         this.securityContext.authenticatedUser();
-
         final Survey survey = findSurvey(surveyId);
-
-        final Client client = this.clientRepository.findOne(clientId);
-
-        if (client == null) {
-            throw new ClientNotFoundException(clientId);
-        }
-
+        final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId);
         final List<Scorecard> scorecards = this.scorecardService.findBySurveyAndClient(survey, client);
-
         if (scorecards == null) {
             return ScorecardMapper.map(scorecards);
         }
-
         return Collections.EMPTY_LIST;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/025ff9c7/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java
index 0b4a0db..a0089fb 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java
@@ -36,12 +36,11 @@ import org.apache.fineract.infrastructure.core.service.PlatformEmailSendExceptio
 import org.apache.fineract.infrastructure.security.service.PlatformPasswordEncoder;
 import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
 import org.apache.fineract.organisation.office.domain.Office;
-import org.apache.fineract.organisation.office.domain.OfficeRepository;
-import org.apache.fineract.organisation.office.exception.OfficeNotFoundException;
+import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
 import org.apache.fineract.organisation.staff.domain.Staff;
 import org.apache.fineract.organisation.staff.domain.StaffRepositoryWrapper;
 import org.apache.fineract.portfolio.client.domain.Client;
-import org.apache.fineract.portfolio.client.domain.ClientRepository;
+import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
 import org.apache.fineract.useradministration.api.AppUserApiConstant;
 import org.apache.fineract.useradministration.domain.AppUser;
 import org.apache.fineract.useradministration.domain.AppUserPreviousPassword;
@@ -77,29 +76,29 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
     private final UserDomainService userDomainService;
     private final PlatformPasswordEncoder platformPasswordEncoder;
     private final AppUserRepository appUserRepository;
-    private final OfficeRepository officeRepository;
+    private final OfficeRepositoryWrapper officeRepositoryWrapper;
     private final RoleRepository roleRepository;
     private final UserDataValidator fromApiJsonDeserializer;
     private final AppUserPreviousPasswordRepository appUserPreviewPasswordRepository;
     private final StaffRepositoryWrapper staffRepositoryWrapper;
-    private final ClientRepository clientRepository;
+    private final ClientRepositoryWrapper clientRepositoryWrapper;
 
     @Autowired
     public AppUserWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final AppUserRepository appUserRepository,
-            final UserDomainService userDomainService, final OfficeRepository officeRepository, final RoleRepository roleRepository,
+            final UserDomainService userDomainService, final OfficeRepositoryWrapper officeRepositoryWrapper, final RoleRepository roleRepository,
             final PlatformPasswordEncoder platformPasswordEncoder, final UserDataValidator fromApiJsonDeserializer,
             final AppUserPreviousPasswordRepository appUserPreviewPasswordRepository, final StaffRepositoryWrapper staffRepositoryWrapper,
-            final ClientRepository clientRepository) {
+            final ClientRepositoryWrapper clientRepositoryWrapper) {
         this.context = context;
         this.appUserRepository = appUserRepository;
         this.userDomainService = userDomainService;
-        this.officeRepository = officeRepository;
+        this.officeRepositoryWrapper = officeRepositoryWrapper;
         this.roleRepository = roleRepository;
         this.platformPasswordEncoder = platformPasswordEncoder;
         this.fromApiJsonDeserializer = fromApiJsonDeserializer;
         this.appUserPreviewPasswordRepository = appUserPreviewPasswordRepository;
         this.staffRepositoryWrapper = staffRepositoryWrapper;
-        this.clientRepository = clientRepository;
+        this.clientRepositoryWrapper = clientRepositoryWrapper;
     }
 
     @Transactional
@@ -115,8 +114,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
             final String officeIdParamName = "officeId";
             final Long officeId = command.longValueOfParameterNamed(officeIdParamName);
 
-            final Office userOffice = this.officeRepository.findOne(officeId);
-            if (userOffice == null) { throw new OfficeNotFoundException(officeId); }
+            final Office userOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
 
             final String[] roles = command.arrayValueOfParameterNamed("roles");
             final Set<Role> allRoles = assembleSetOfRoles(roles);
@@ -140,7 +138,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
             	for(JsonElement clientElement : clientsArray){
             		clientIds.add(clientElement.getAsLong());
             	}
-            	clients = this.clientRepository.findAll(clientIds);
+            	clients = this.clientRepositoryWrapper.findAll(clientIds);
             }
 
             appUser = AppUser.fromJson(userOffice, linkedStaff, allRoles, clients, command);
@@ -199,16 +197,14 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
             	for(JsonElement clientElement : clientsArray){
             		clientIds.add(clientElement.getAsLong());
             	}
-            	clients = this.clientRepository.findAll(clientIds);
+            	clients = this.clientRepositoryWrapper.findAll(clientIds);
             }
 
             final Map<String, Object> changes = userToUpdate.update(command, this.platformPasswordEncoder, clients);
 
             if (changes.containsKey("officeId")) {
                 final Long officeId = (Long) changes.get("officeId");
-                final Office office = this.officeRepository.findOne(officeId);
-                if (office == null) { throw new OfficeNotFoundException(officeId); }
-
+                final Office office = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
                 userToUpdate.changeOffice(office);
             }
 


Mime
View raw message