From commits-return-1466-archive-asf-public=cust-asf.ponee.io@fineract.apache.org Mon Jan 22 16:27:48 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id 5BC43180609 for ; Mon, 22 Jan 2018 16:27:47 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 4B22B160C4B; Mon, 22 Jan 2018 15:27:47 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 34816160C4F for ; Mon, 22 Jan 2018 16:27:46 +0100 (CET) Received: (qmail 32753 invoked by uid 500); 22 Jan 2018 15:27:45 -0000 Mailing-List: contact commits-help@fineract.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@fineract.apache.org Delivered-To: mailing list commits@fineract.apache.org Received: (qmail 32743 invoked by uid 99); 22 Jan 2018 15:27:45 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Jan 2018 15:27:45 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 1499C82038; Mon, 22 Jan 2018 15:27:43 +0000 (UTC) Date: Mon, 22 Jan 2018 15:27:59 +0000 To: "commits@fineract.apache.org" Subject: [fineract-cn-cheques] 17/18: added ability to handle legacy account numbers MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: myrle@apache.org In-Reply-To: <151663486247.16826.16468005950736492871@gitbox.apache.org> References: <151663486247.16826.16468005950736492871@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: fineract-cn-cheques X-Git-Refname: refs/heads/develop X-Git-Reftype: branch X-Git-Rev: b0bb0e8269578f3e9f6dfe7d883d7d6f1f03d4da X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20180122152743.1499C82038@gitbox.apache.org> 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 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.