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 <[email protected]> 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<Void> 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 [email protected].
