fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From my...@apache.org
Subject [fineract-cn-office] 07/14: Add check if duplicate identifier is used when creating a branch office
Date Mon, 22 Jan 2018 15:24:05 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-office.git

commit 346a8a1d68bf63aa42655daff56524e8a11da52e
Author: Mark <mark.vanveen@gmail.com>
AuthorDate: Wed Apr 12 17:31:53 2017 +0200

    Add check if duplicate identifier is used when creating a branch office
---
 .../mifos/office/api/v1/client/OrganizationManager.java  |  5 ++++-
 .../src/main/java/io/mifos/office/TestOffice.java        | 16 ++++++++++++++++
 .../office/rest/controller/OfficeRestController.java     |  8 ++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/api/src/main/java/io/mifos/office/api/v1/client/OrganizationManager.java b/api/src/main/java/io/mifos/office/api/v1/client/OrganizationManager.java
index 3ef36b2..27831ac 100644
--- a/api/src/main/java/io/mifos/office/api/v1/client/OrganizationManager.java
+++ b/api/src/main/java/io/mifos/office/api/v1/client/OrganizationManager.java
@@ -90,7 +90,10 @@ public interface OrganizationManager {
       consumes = MediaType.APPLICATION_JSON_VALUE,
       produces = MediaType.APPLICATION_JSON_VALUE
   )
-  @ThrowsException(status = HttpStatus.NOT_FOUND, exception = NotFoundException.class)
+  @ThrowsExceptions({
+          @ThrowsException(status = HttpStatus.NOT_FOUND, exception = NotFoundException.class),
+          @ThrowsException(status = HttpStatus.CONFLICT, exception = AlreadyExistsException.class)
+  })
   void addBranch(@PathVariable("identifier") final String identifier, @RequestBody final
Office office);
 
   @RequestMapping(
diff --git a/component-test/src/main/java/io/mifos/office/TestOffice.java b/component-test/src/main/java/io/mifos/office/TestOffice.java
index 6399eef..97f1b66 100644
--- a/component-test/src/main/java/io/mifos/office/TestOffice.java
+++ b/component-test/src/main/java/io/mifos/office/TestOffice.java
@@ -202,6 +202,22 @@ public class TestOffice {
   }
 
   @Test
+  public void shouldNotAddBranchDuplicate() throws Exception {
+    final Office office = OfficeFactory.createRandomOffice();
+    this.organizationManager.createOffice(office);
+    this.eventRecorder.wait(EventConstants.OPERATION_POST_OFFICE, office.getIdentifier());
+    try {
+      this.organizationManager.addBranch(office.getIdentifier(), office);
+      Assert.fail();
+    } catch (final AlreadyExistsException ex) {
+      // do nothing, expected
+    }
+
+    this.organizationManager.deleteOffice(office.getIdentifier());
+    this.eventRecorder.wait(EventConstants.OPERATION_DELETE_OFFICE, office.getIdentifier());
+  }
+
+  @Test
   public void shouldSetAddressOfOffice() throws Exception {
     final Office office = OfficeFactory.createRandomOffice();
     this.organizationManager.createOffice(office);
diff --git a/service/src/main/java/io/mifos/office/rest/controller/OfficeRestController.java
b/service/src/main/java/io/mifos/office/rest/controller/OfficeRestController.java
index ab30f63..70162fe 100644
--- a/service/src/main/java/io/mifos/office/rest/controller/OfficeRestController.java
+++ b/service/src/main/java/io/mifos/office/rest/controller/OfficeRestController.java
@@ -173,6 +173,14 @@ public class OfficeRestController {
       throw ServiceException.notFound("Parent office {0} not found.", identifier);
     }
 
+    if (office == null) {
+      throw ServiceException.badRequest("An office must be given.");
+    }
+
+    if (this.officeService.officeExists(office.getIdentifier())) {
+      throw ServiceException.conflict("Office {0} already exists.", office.getIdentifier());
+    }
+
     this.commandGateway.process(new AddBranchCommand(identifier, office));
     return ResponseEntity.accepted().build();
   }

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

Mime
View raw message