fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From my...@apache.org
Subject [fineract-cn-cheques] 17/18: added ability to handle legacy account numbers
Date Mon, 22 Jan 2018 15:27:59 GMT
This is an automated email from the ASF dual-hosted git repository.

myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-cheques.git

commit b0bb0e8269578f3e9f6dfe7d883d7d6f1f03d4da
Author: mgeiss <mgeiss@mifos.org>
AuthorDate: Tue Oct 3 11:15:45 2017 +0200

    added ability to handle legacy account numbers
---
 api/src/main/java/io/mifos/cheque/api/v1/domain/Cheque.java |  1 -
 .../io/mifos/cheque/api/v1/domain/ChequeTransaction.java    |  1 -
 .../src/main/java/io/mifos/cheque/TestCheques.java          | 12 ++++++++----
 component-test/src/main/java/io/mifos/cheque/TestMICR.java  |  7 +++++++
 .../service/internal/command/handler/ChequeAggregate.java   |  4 ++--
 .../service/internal/service/helper/AccountingService.java  | 13 ++++++++++---
 6 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/api/src/main/java/io/mifos/cheque/api/v1/domain/Cheque.java b/api/src/main/java/io/mifos/cheque/api/v1/domain/Cheque.java
index a14a968..e50172b 100644
--- a/api/src/main/java/io/mifos/cheque/api/v1/domain/Cheque.java
+++ b/api/src/main/java/io/mifos/cheque/api/v1/domain/Cheque.java
@@ -18,7 +18,6 @@ package io.mifos.cheque.api.v1.domain;
 import org.hibernate.validator.constraints.NotEmpty;
 
 import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
 
 public class Cheque {
 
diff --git a/api/src/main/java/io/mifos/cheque/api/v1/domain/ChequeTransaction.java b/api/src/main/java/io/mifos/cheque/api/v1/domain/ChequeTransaction.java
index 43507bb..1129613 100644
--- a/api/src/main/java/io/mifos/cheque/api/v1/domain/ChequeTransaction.java
+++ b/api/src/main/java/io/mifos/cheque/api/v1/domain/ChequeTransaction.java
@@ -16,7 +16,6 @@
 package io.mifos.cheque.api.v1.domain;
 
 import io.mifos.core.lang.validation.constraints.ValidIdentifier;
-import org.hibernate.validator.constraints.NotEmpty;
 
 import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
diff --git a/component-test/src/main/java/io/mifos/cheque/TestCheques.java b/component-test/src/main/java/io/mifos/cheque/TestCheques.java
index 0acbd3b..f0b8183 100644
--- a/component-test/src/main/java/io/mifos/cheque/TestCheques.java
+++ b/component-test/src/main/java/io/mifos/cheque/TestCheques.java
@@ -16,6 +16,7 @@
 package io.mifos.cheque;
 
 import com.google.common.collect.Sets;
+import io.mifos.accounting.api.v1.domain.Account;
 import io.mifos.accounting.api.v1.domain.Creditor;
 import io.mifos.accounting.api.v1.domain.Debtor;
 import io.mifos.accounting.api.v1.domain.JournalEntry;
@@ -37,14 +38,11 @@ import org.mockito.Matchers;
 import org.mockito.Mockito;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.mock.mockito.MockBean;
-import org.springframework.validation.AbstractErrors;
 import org.springframework.validation.BeanPropertyBindingResult;
-import org.springframework.validation.BindingResult;
-import org.springframework.validation.Errors;
 import org.springframework.validation.Validator;
-import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
 
 import java.util.Collections;
+import java.util.Optional;
 import java.util.UUID;
 
 public class TestCheques extends AbstractChequeTest {
@@ -91,6 +89,12 @@ public class TestCheques extends AbstractChequeTest {
         .doAnswer(invocation -> true)
         .when(this.accountingServiceSpy).accountExists(randomCheque.getMicr().getAccountNumber());
 
+    final Account mockedAccount = new Account();
+    mockedAccount.setIdentifier(randomCheque.getMicr().getAccountNumber());
+    Mockito
+        .doAnswer(invocation -> Optional.of(mockedAccount))
+        .when(this.accountingServiceSpy).findAccount(randomCheque.getMicr().getAccountNumber());
+
     final ChequeTransaction chequeTransaction = new ChequeTransaction();
     chequeTransaction.setCheque(randomCheque);
     chequeTransaction.setChequesReceivableAccount(RandomStringUtils.randomAlphabetic(34));
diff --git a/component-test/src/main/java/io/mifos/cheque/TestMICR.java b/component-test/src/main/java/io/mifos/cheque/TestMICR.java
index 197c235..ea96c7b 100644
--- a/component-test/src/main/java/io/mifos/cheque/TestMICR.java
+++ b/component-test/src/main/java/io/mifos/cheque/TestMICR.java
@@ -15,6 +15,7 @@
  */
 package io.mifos.cheque;
 
+import io.mifos.accounting.api.v1.domain.Account;
 import io.mifos.cheque.api.v1.EventConstants;
 import io.mifos.cheque.api.v1.client.DependingResourceNotValidException;
 import io.mifos.cheque.api.v1.client.InvalidChequeNumberException;
@@ -150,6 +151,12 @@ public class TestMICR extends AbstractChequeTest {
         .doAnswer(invocation -> true)
         .when(this.accountingServiceSpy).accountExists(randomCheque.getMicr().getAccountNumber());
 
+    final Account mockedAccount = new Account();
+    mockedAccount.setIdentifier(randomCheque.getMicr().getAccountNumber());
+    Mockito
+        .doAnswer(invocation -> Optional.of(mockedAccount))
+        .when(this.accountingServiceSpy).findAccount(randomCheque.getMicr().getAccountNumber());
+
     final ChequeTransaction chequeTransaction = new ChequeTransaction();
     chequeTransaction.setCheque(randomCheque);
     chequeTransaction.setCreditorAccountNumber(RandomStringUtils.randomAlphanumeric(34));
diff --git a/service/src/main/java/io/mifos/cheque/service/internal/command/handler/ChequeAggregate.java
b/service/src/main/java/io/mifos/cheque/service/internal/command/handler/ChequeAggregate.java
index 3bb746a..666742f 100644
--- a/service/src/main/java/io/mifos/cheque/service/internal/command/handler/ChequeAggregate.java
+++ b/service/src/main/java/io/mifos/cheque/service/internal/command/handler/ChequeAggregate.java
@@ -158,8 +158,8 @@ public class ChequeAggregate {
       } else {
         throw ServiceException.conflict("Account {0} never issued cheques.", micr.getAccountNumber());
       }
-
-      debtor.setAccountNumber(micr.getAccountNumber());
+      this.accountingService.findAccount(micr.getAccountNumber())
+          .ifPresent(account -> debtor.setAccountNumber(account.getIdentifier()));
       chequeEntity.setState(State.PROCESSED.name());
     } else {
       debtor.setAccountNumber(chequeTransactionCommand.chequesReceivableAccount());
diff --git a/service/src/main/java/io/mifos/cheque/service/internal/service/helper/AccountingService.java
b/service/src/main/java/io/mifos/cheque/service/internal/service/helper/AccountingService.java
index 4667c04..46bb20a 100644
--- a/service/src/main/java/io/mifos/cheque/service/internal/service/helper/AccountingService.java
+++ b/service/src/main/java/io/mifos/cheque/service/internal/service/helper/AccountingService.java
@@ -19,6 +19,7 @@ import com.google.common.collect.Sets;
 import io.mifos.accounting.api.v1.client.AccountNotFoundException;
 import io.mifos.accounting.api.v1.client.LedgerManager;
 import io.mifos.accounting.api.v1.domain.Account;
+import io.mifos.accounting.api.v1.domain.AccountPage;
 import io.mifos.accounting.api.v1.domain.Creditor;
 import io.mifos.accounting.api.v1.domain.Debtor;
 import io.mifos.accounting.api.v1.domain.JournalEntry;
@@ -67,7 +68,7 @@ public class AccountingService {
       return;
     }
 
-    final Account account = this.ledgerManager.findAccount(sourceAccount);
+    final Account account = this.findAccount(sourceAccount).orElseThrow(AccountNotFoundException::new);
     if (account.getBalance() < totalCharges) {
       throw ServiceException.conflict("Insufficient account balance.");
     }
@@ -80,7 +81,7 @@ public class AccountingService {
     journalEntry.setClerk(UserContextHolder.checkedGetUser());
 
     final Debtor debtor = new Debtor();
-    debtor.setAccountNumber(sourceAccount);
+    debtor.setAccountNumber(account.getIdentifier());
     debtor.setAmount(totalCharges.toString());
     journalEntry.setDebtors(Sets.newHashSet(debtor));
 
@@ -115,7 +116,13 @@ public class AccountingService {
     try {
       return Optional.of(this.ledgerManager.findAccount(accountNumber));
     } catch (final AccountNotFoundException anfex) {
-      return Optional.empty();
+      final AccountPage accountPage = this.ledgerManager.fetchAccounts(true, accountNumber,
null, true,
+          0, 10, null, null);
+
+      return accountPage.getAccounts()
+          .stream()
+          .filter(account -> account.getAlternativeAccountNumber().equals(accountNumber))
+          .findFirst();
     }
   }
 }

-- 
To stop receiving notification emails like this one, please contact
myrle@apache.org.

Mime
View raw message