From commits-return-1602-archive-asf-public=cust-asf.ponee.io@fineract.apache.org Mon Jan 22 16:43:42 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 81D9C180609 for ; Mon, 22 Jan 2018 16:43:41 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 712AD160C54; Mon, 22 Jan 2018 15:43:41 +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 31A55160C3A for ; Mon, 22 Jan 2018 16:43:40 +0100 (CET) Received: (qmail 77791 invoked by uid 500); 22 Jan 2018 15:43:39 -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 77686 invoked by uid 99); 22 Jan 2018 15:43:39 -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:43:39 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 21723820A7; Mon, 22 Jan 2018 15:43:36 +0000 (UTC) Date: Mon, 22 Jan 2018 15:43:52 +0000 To: "commits@fineract.apache.org" Subject: [fineract-cn-accounting] 16/36: added already exists check to journal entry creation MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: myrle@apache.org In-Reply-To: <151663581632.2879.11350121205008453232@gitbox.apache.org> References: <151663581632.2879.11350121205008453232@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: fineract-cn-accounting X-Git-Refname: refs/heads/develop X-Git-Reftype: branch X-Git-Rev: 73e49f963114f7cfb4fb3b2f1743400a9dd21256 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20180122154337.21723820A7@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-accounting.git commit 73e49f963114f7cfb4fb3b2f1743400a9dd21256 Author: mgeiss AuthorDate: Tue Sep 26 10:59:37 2017 +0200 added already exists check to journal entry creation --- .../client/JournalEntryAlreadyExistsException.java | 4 +++ .../accounting/api/v1/client/LedgerManager.java | 5 +++- .../java/io/mifos/accounting/TestJournalEntry.java | 33 ++++++++++++++++++++++ .../service/rest/JournalRestController.java | 4 +++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/io/mifos/accounting/api/v1/client/JournalEntryAlreadyExistsException.java b/api/src/main/java/io/mifos/accounting/api/v1/client/JournalEntryAlreadyExistsException.java new file mode 100644 index 0000000..c79b69b --- /dev/null +++ b/api/src/main/java/io/mifos/accounting/api/v1/client/JournalEntryAlreadyExistsException.java @@ -0,0 +1,4 @@ +package io.mifos.accounting.api.v1.client; + +public class JournalEntryAlreadyExistsException extends RuntimeException { +} diff --git a/api/src/main/java/io/mifos/accounting/api/v1/client/LedgerManager.java b/api/src/main/java/io/mifos/accounting/api/v1/client/LedgerManager.java index 34f7290..93fe6ce 100644 --- a/api/src/main/java/io/mifos/accounting/api/v1/client/LedgerManager.java +++ b/api/src/main/java/io/mifos/accounting/api/v1/client/LedgerManager.java @@ -282,7 +282,10 @@ public interface LedgerManager { produces = {MediaType.APPLICATION_JSON_VALUE}, consumes = {MediaType.APPLICATION_JSON_VALUE} ) - @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = JournalEntryValidationException.class) + @ThrowsExceptions({ + @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = JournalEntryValidationException.class), + @ThrowsException(status = HttpStatus.CONFLICT, exception = JournalEntryAlreadyExistsException.class) + }) void createJournalEntry(@RequestBody final JournalEntry journalEntry); @RequestMapping( diff --git a/component-test/src/main/java/io/mifos/accounting/TestJournalEntry.java b/component-test/src/main/java/io/mifos/accounting/TestJournalEntry.java index 2f49c4f..f2654dd 100644 --- a/component-test/src/main/java/io/mifos/accounting/TestJournalEntry.java +++ b/component-test/src/main/java/io/mifos/accounting/TestJournalEntry.java @@ -16,6 +16,7 @@ package io.mifos.accounting; import io.mifos.accounting.api.v1.EventConstants; +import io.mifos.accounting.api.v1.client.JournalEntryAlreadyExistsException; import io.mifos.accounting.api.v1.client.JournalEntryValidationException; import io.mifos.accounting.api.v1.domain.Account; import io.mifos.accounting.api.v1.domain.AccountEntryPage; @@ -323,6 +324,38 @@ public class TestJournalEntry extends AbstractAccountingTest { this.testSubject.createJournalEntry(journalEntry); } + @Test(expected = JournalEntryAlreadyExistsException.class) + public void shouldNotCreateJournalAlreadyExists() throws Exception { + final Ledger assetLedger = LedgerGenerator.createRandomLedger(); + assetLedger.setType(AccountType.ASSET.name()); + this.testSubject.createLedger(assetLedger); + this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier()); + + final Account debtorAccount = AccountGenerator.createRandomAccount(assetLedger.getIdentifier()); + debtorAccount.setType(AccountType.ASSET.name()); + debtorAccount.setBalance(100.00D); + this.testSubject.createAccount(debtorAccount); + this.eventRecorder.wait(EventConstants.POST_ACCOUNT, debtorAccount.getIdentifier()); + + final Ledger liabilityLedger = LedgerGenerator.createRandomLedger(); + liabilityLedger.setType(AccountType.LIABILITY.name()); + this.testSubject.createLedger(liabilityLedger); + this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier()); + + final Account creditorAccount = AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier()); + creditorAccount.setType(AccountType.LIABILITY.name()); + creditorAccount.setBalance(100.00D); + this.testSubject.createAccount(creditorAccount); + this.eventRecorder.wait(EventConstants.POST_ACCOUNT, creditorAccount.getIdentifier()); + + final JournalEntry journalEntry = JournalEntryGenerator.createRandomJournalEntry(creditorAccount, "50.00", + creditorAccount, "50.00"); + this.testSubject.createJournalEntry(journalEntry); + this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntry.getTransactionIdentifier()); + + this.testSubject.createJournalEntry(journalEntry); + } + @Test(expected = JournalEntryValidationException.class) public void shouldNotCreateJournalEntryMissingCreditors() throws Exception { final Ledger assetLedger = LedgerGenerator.createRandomLedger(); diff --git a/service/src/main/java/io/mifos/accounting/service/rest/JournalRestController.java b/service/src/main/java/io/mifos/accounting/service/rest/JournalRestController.java index 56648ce..ef3e32f 100644 --- a/service/src/main/java/io/mifos/accounting/service/rest/JournalRestController.java +++ b/service/src/main/java/io/mifos/accounting/service/rest/JournalRestController.java @@ -69,6 +69,10 @@ public class JournalRestController { ) @ResponseBody ResponseEntity createJournalEntry(@RequestBody @Valid final JournalEntry journalEntry) { + if (this.journalEntryService.findJournalEntry(journalEntry.getTransactionIdentifier()).isPresent()) { + throw ServiceException.conflict("Journal entry {0} already exists.", journalEntry.getTransactionIdentifier()); + } + if (journalEntry.getDebtors().size() == 0) { throw ServiceException.badRequest("Debtors must be given."); } -- To stop receiving notification emails like this one, please contact myrle@apache.org.