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-customer.git

commit a280d78da30683843bd0c24f6af4771c0151d69d
Author: Mark <mark.vanv...@gmail.com>
AuthorDate: Fri Sep 29 17:56:34 2017 +0200

    Fix issue not updating fields by flushing field value repository after 
delete
    Throw conflict instead of bad request when field or catalog is in use
    Adapted tests to use new exceptions
---
 .../api/v1/client/CatalogAlreadyInUseException.java   | 19 +++++++++++++++++++
 .../catalog/api/v1/client/CatalogManager.java         |  9 ++++++---
 .../api/v1/client/FieldAlreadyInUseException.java     | 19 +++++++++++++++++++
 .../java/io/mifos/customer/catalog/TestCatalog.java   |  6 ++++--
 .../rest/controller/CatalogRestController.java        |  6 +++---
 .../internal/command/handler/CustomerAggregate.java   |  1 +
 6 files changed, 52 insertions(+), 8 deletions(-)

diff --git 
a/api/src/main/java/io/mifos/customer/catalog/api/v1/client/CatalogAlreadyInUseException.java
 
b/api/src/main/java/io/mifos/customer/catalog/api/v1/client/CatalogAlreadyInUseException.java
new file mode 100644
index 0000000..7136606
--- /dev/null
+++ 
b/api/src/main/java/io/mifos/customer/catalog/api/v1/client/CatalogAlreadyInUseException.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.mifos.customer.catalog.api.v1.client;
+
+public class CatalogAlreadyInUseException extends RuntimeException {
+}
diff --git 
a/api/src/main/java/io/mifos/customer/catalog/api/v1/client/CatalogManager.java 
b/api/src/main/java/io/mifos/customer/catalog/api/v1/client/CatalogManager.java
index edf7341..a434f81 100644
--- 
a/api/src/main/java/io/mifos/customer/catalog/api/v1/client/CatalogManager.java
+++ 
b/api/src/main/java/io/mifos/customer/catalog/api/v1/client/CatalogManager.java
@@ -73,7 +73,8 @@ public interface CatalogManager {
   )
   @ThrowsExceptions({
       @ThrowsException(status = HttpStatus.NOT_FOUND, exception = 
CatalogNotFoundException.class),
-      @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = 
CatalogValidationException.class)
+      @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = 
CatalogValidationException.class),
+      @ThrowsException(status = HttpStatus.CONFLICT, exception = 
CatalogAlreadyInUseException.class)
   })
   void deleteCatalog(@PathVariable("identifier") final String identifier);
 
@@ -85,7 +86,8 @@ public interface CatalogManager {
   )
   @ThrowsExceptions({
       @ThrowsException(status = HttpStatus.NOT_FOUND, exception = 
CatalogNotFoundException.class),
-      @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = 
CatalogValidationException.class)
+      @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = 
CatalogValidationException.class),
+      @ThrowsException(status = HttpStatus.CONFLICT, exception = 
FieldAlreadyInUseException.class)
   })
   void updateField(@PathVariable("catalogIdentifier") final String 
catalogIdentifier,
                    @PathVariable("fieldIdentifier") final String 
fieldIdentifier,
@@ -99,7 +101,8 @@ public interface CatalogManager {
   )
   @ThrowsExceptions({
       @ThrowsException(status = HttpStatus.NOT_FOUND, exception = 
CatalogNotFoundException.class),
-      @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = 
CatalogValidationException.class)
+      @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = 
CatalogValidationException.class),
+      @ThrowsException(status = HttpStatus.CONFLICT, exception = 
FieldAlreadyInUseException.class)
   })
   void deleteField(@PathVariable("catalogIdentifier") final String 
catalogIdentifier,
                    @PathVariable("fieldIdentifier") final String 
fieldIdentifier);
diff --git 
a/api/src/main/java/io/mifos/customer/catalog/api/v1/client/FieldAlreadyInUseException.java
 
b/api/src/main/java/io/mifos/customer/catalog/api/v1/client/FieldAlreadyInUseException.java
new file mode 100644
index 0000000..968e1e7
--- /dev/null
+++ 
b/api/src/main/java/io/mifos/customer/catalog/api/v1/client/FieldAlreadyInUseException.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.mifos.customer.catalog.api.v1.client;
+
+public class FieldAlreadyInUseException extends RuntimeException {
+}
diff --git 
a/component-test/src/main/java/io/mifos/customer/catalog/TestCatalog.java 
b/component-test/src/main/java/io/mifos/customer/catalog/TestCatalog.java
index 4fd679d..c4fdc4d 100644
--- a/component-test/src/main/java/io/mifos/customer/catalog/TestCatalog.java
+++ b/component-test/src/main/java/io/mifos/customer/catalog/TestCatalog.java
@@ -28,8 +28,10 @@ import io.mifos.customer.api.v1.CustomerEventConstants;
 import io.mifos.customer.api.v1.client.CustomerManager;
 import io.mifos.customer.api.v1.domain.Customer;
 import io.mifos.customer.catalog.api.v1.CatalogEventConstants;
+import io.mifos.customer.catalog.api.v1.client.CatalogAlreadyInUseException;
 import io.mifos.customer.catalog.api.v1.client.CatalogManager;
 import io.mifos.customer.catalog.api.v1.client.CatalogValidationException;
+import io.mifos.customer.catalog.api.v1.client.FieldAlreadyInUseException;
 import io.mifos.customer.catalog.api.v1.domain.Catalog;
 import io.mifos.customer.catalog.api.v1.domain.Field;
 import io.mifos.customer.catalog.api.v1.domain.Option;
@@ -219,7 +221,7 @@ public class TestCatalog {
     
Assert.assertTrue(this.eventRecorder.wait(CatalogEventConstants.DELETE_CATALOG, 
catalog.getIdentifier()));
   }
 
-  @Test(expected = CatalogValidationException.class)
+  @Test(expected = CatalogAlreadyInUseException.class)
   public void shouldNotDeleteCatalogUsed() throws Exception {
     final Catalog catalog = CatalogGenerator.createRandomCatalog();
 
@@ -272,7 +274,7 @@ public class TestCatalog {
     Assert.assertEquals(1, savedCatalog.getFields().size());
   }
 
-  @Test(expected = CatalogValidationException.class)
+  @Test(expected = FieldAlreadyInUseException.class)
   public void shouldNotDeleteField() throws Exception {
     final Catalog catalog = CatalogGenerator.createRandomCatalog();
 
diff --git 
a/service/src/main/java/io/mifos/customer/catalog/service/rest/controller/CatalogRestController.java
 
b/service/src/main/java/io/mifos/customer/catalog/service/rest/controller/CatalogRestController.java
index 6b0081e..9f4f744 100644
--- 
a/service/src/main/java/io/mifos/customer/catalog/service/rest/controller/CatalogRestController.java
+++ 
b/service/src/main/java/io/mifos/customer/catalog/service/rest/controller/CatalogRestController.java
@@ -118,7 +118,7 @@ public class CatalogRestController {
   @ResponseBody
   ResponseEntity<Void> deleteCatalog(@PathVariable("identifier") final String 
identifier) {
     if (this.catalogService.catalogInUse(identifier)) {
-      throw ServiceException.badRequest("Catalog {0} in use.", identifier);
+      throw ServiceException.conflict("Catalog {0} in use.", identifier);
     }
 
     this.commandGateway.process(new DeleteCatalogCommand(identifier));
@@ -139,7 +139,7 @@ public class CatalogRestController {
                                    @PathVariable("fieldIdentifier") final 
String fieldIdentifier,
                                    @RequestBody @Valid Field field) {
     if (this.catalogService.fieldInUse(catalogIdentifier, fieldIdentifier)) {
-      throw ServiceException.badRequest("Catalog {0} in use.", 
catalogIdentifier);
+      throw ServiceException.conflict("Field {0} in use.", fieldIdentifier);
     }
 
     this.commandGateway.process(new ChangeFieldCommand(catalogIdentifier, 
field));
@@ -159,7 +159,7 @@ public class CatalogRestController {
   ResponseEntity<Void> deleteField(@PathVariable("catalogIdentifier") final 
String catalogIdentifier,
                                      @PathVariable("fieldIdentifier") final 
String fieldIdentifier) {
     if (this.catalogService.fieldInUse(catalogIdentifier, fieldIdentifier)) {
-      throw ServiceException.badRequest("Catalog {0} in use.", 
catalogIdentifier);
+      throw ServiceException.conflict("Field {0} in use.", fieldIdentifier);
     }
 
     this.commandGateway.process(new DeleteFieldCommand(catalogIdentifier, 
fieldIdentifier));
diff --git 
a/service/src/main/java/io/mifos/customer/service/internal/command/handler/CustomerAggregate.java
 
b/service/src/main/java/io/mifos/customer/service/internal/command/handler/CustomerAggregate.java
index c20252c..fa306a5 100644
--- 
a/service/src/main/java/io/mifos/customer/service/internal/command/handler/CustomerAggregate.java
+++ 
b/service/src/main/java/io/mifos/customer/service/internal/command/handler/CustomerAggregate.java
@@ -196,6 +196,7 @@ public class CustomerAggregate {
 
     if (customer.getCustomValues() != null) {
       this.fieldValueRepository.deleteByCustomer(customerEntity);
+      this.fieldValueRepository.flush();
       this.setCustomValues(customer, customerEntity);
     }
 

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

Reply via email to