fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From my...@apache.org
Subject [fineract-cn-customer] 36/46: Adding change document description functionality.
Date Mon, 22 Jan 2018 15:47:37 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-customer.git

commit 683ba372d7da2948ffd0650dfd16d1db83d3fa0d
Author: Myrle Krantz <myrle@apache.org>
AuthorDate: Fri Oct 20 11:40:50 2017 +0200

    Adding change document description functionality.
---
 .../customer/api/v1/CustomerEventConstants.java    |  2 +
 .../api/v1/client/CustomerDocumentsManager.java    | 15 +++++++
 .../main/java/io/mifos/customer/TestDocuments.java | 12 ++++++
 .../customer/listener/DocumentEventListener.java   | 10 +++++
 .../internal/command/ChangeDocumentCommand.java    | 49 ++++++++++++++++++++++
 .../command/handler/DocumentCommandHandler.java    | 23 ++++++++--
 .../rest/controller/DocumentsRestController.java   | 29 +++++++++++--
 7 files changed, 132 insertions(+), 8 deletions(-)

diff --git a/api/src/main/java/io/mifos/customer/api/v1/CustomerEventConstants.java b/api/src/main/java/io/mifos/customer/api/v1/CustomerEventConstants.java
index 03854ad..7a47b73 100644
--- a/api/src/main/java/io/mifos/customer/api/v1/CustomerEventConstants.java
+++ b/api/src/main/java/io/mifos/customer/api/v1/CustomerEventConstants.java
@@ -48,6 +48,7 @@ public interface CustomerEventConstants {
   String DELETE_PORTRAIT = "delete-portrait";
 
   String POST_DOCUMENT = "post-document";
+  String PUT_DOCUMENT = "put-document";
   String POST_DOCUMENT_PAGE = "post-document-page";
   String DELETE_DOCUMENT_PAGE = "delete-document-page";
   String POST_DOCUMENT_COMPLETE = "post-document-complete";
@@ -79,6 +80,7 @@ public interface CustomerEventConstants {
   String SELECTOR_DELETE_PORTRAIT = SELECTOR_NAME + " = '" + DELETE_PORTRAIT + "'";
 
   String SELECTOR_POST_DOCUMENT = SELECTOR_NAME + " = '" + POST_DOCUMENT + "'";
+  String SELECTOR_PUT_DOCUMENT = SELECTOR_NAME + " = '" + PUT_DOCUMENT + "'";
   String SELECTOR_POST_DOCUMENT_PAGE = SELECTOR_NAME + " = '" + POST_DOCUMENT_PAGE + "'";
   String SELECTOR_DELETE_DOCUMENT_PAGE = SELECTOR_NAME + " = '" + DELETE_DOCUMENT_PAGE +
"'";
   String SELECTOR_POST_DOCUMENT_COMPLETE = SELECTOR_NAME + " = '" + POST_DOCUMENT_COMPLETE
+ "'";
diff --git a/api/src/main/java/io/mifos/customer/api/v1/client/CustomerDocumentsManager.java
b/api/src/main/java/io/mifos/customer/api/v1/client/CustomerDocumentsManager.java
index 35b9be9..96fdf02 100644
--- a/api/src/main/java/io/mifos/customer/api/v1/client/CustomerDocumentsManager.java
+++ b/api/src/main/java/io/mifos/customer/api/v1/client/CustomerDocumentsManager.java
@@ -71,6 +71,21 @@ public interface CustomerDocumentsManager {
       @RequestBody final CustomerDocument customerDocument);
 
 
+  @RequestMapping(
+      value = "/customers/{customeridentifier}/documents/{documentidentifier}",
+      method = RequestMethod.PUT,
+      produces = MediaType.APPLICATION_JSON_VALUE,
+      consumes = MediaType.APPLICATION_JSON_VALUE
+  )
+  @ThrowsExceptions({
+      @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = DocumentValidationException.class)
+  })
+  void changeDocument(
+      @PathVariable("customeridentifier") final String customerIdentifier,
+      @PathVariable("documentidentifier") final String documentIdentifier,
+      @RequestBody final CustomerDocument customerDocument);
+
+
   /**
    * Once a document is "completed" its name and images cannot be changed again.  Only completed
    * documents should be referenced by other services.
diff --git a/component-test/src/main/java/io/mifos/customer/TestDocuments.java b/component-test/src/main/java/io/mifos/customer/TestDocuments.java
index fa44409..071f247 100644
--- a/component-test/src/main/java/io/mifos/customer/TestDocuments.java
+++ b/component-test/src/main/java/io/mifos/customer/TestDocuments.java
@@ -104,6 +104,18 @@ public class TestDocuments extends AbstractCustomerTest {
     createDocumentPage(customer.getIdentifier(), customerDocument.getIdentifier(), 2);
 
 
+    logger.info("Check that a document's description can be changed.");
+    customerDocument.setDescription("new description");
+    customerDocumentsManager.changeDocument(customer.getIdentifier(), customerDocument.getIdentifier(),
customerDocument);
+    Assert.assertTrue(eventRecorder.wait(CustomerEventConstants.PUT_DOCUMENT,
+        new DocumentEvent(customer.getIdentifier(), customerDocument.getIdentifier())));
+
+    {
+      final CustomerDocument changedCustomerDocument = customerDocumentsManager.getDocument(customer.getIdentifier(),
customerDocument.getIdentifier());
+      Assert.assertEquals(customerDocument, changedCustomerDocument);
+    }
+
+
     logger.info("Check that a valid document can be completed");
     final TimeStampChecker timeStampChecker = TimeStampChecker.roughlyNow();
     customerDocumentsManager.completeDocument(customer.getIdentifier(), customerDocument.getIdentifier(),
true);
diff --git a/component-test/src/main/java/io/mifos/customer/listener/DocumentEventListener.java
b/component-test/src/main/java/io/mifos/customer/listener/DocumentEventListener.java
index 6875afd..346df99 100644
--- a/component-test/src/main/java/io/mifos/customer/listener/DocumentEventListener.java
+++ b/component-test/src/main/java/io/mifos/customer/listener/DocumentEventListener.java
@@ -51,6 +51,16 @@ public class DocumentEventListener {
 
   @JmsListener(
       destination = CustomerEventConstants.DESTINATION,
+      selector = CustomerEventConstants.SELECTOR_PUT_DOCUMENT
+  )
+  public void putDocumentEvent(
+      @Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
+      final String payload) {
+    this.eventRecorder.event(tenant, CustomerEventConstants.PUT_DOCUMENT, payload, DocumentEvent.class);
+  }
+
+  @JmsListener(
+      destination = CustomerEventConstants.DESTINATION,
       selector = CustomerEventConstants.SELECTOR_POST_DOCUMENT_PAGE
   )
   public void postDocumentPageEvent(
diff --git a/service/src/main/java/io/mifos/customer/service/internal/command/ChangeDocumentCommand.java
b/service/src/main/java/io/mifos/customer/service/internal/command/ChangeDocumentCommand.java
new file mode 100644
index 0000000..6684818
--- /dev/null
+++ b/service/src/main/java/io/mifos/customer/service/internal/command/ChangeDocumentCommand.java
@@ -0,0 +1,49 @@
+/*
+ * 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.service.internal.command;
+
+import io.mifos.customer.api.v1.domain.CustomerDocument;
+
+/**
+ * @author Myrle Krantz
+ */
+public class ChangeDocumentCommand {
+  private final String customerIdentifier;
+  private final CustomerDocument customerDocument;
+
+  public ChangeDocumentCommand(
+      final String customerIdentifier,
+      final CustomerDocument customerDocument) {
+    this.customerIdentifier = customerIdentifier;
+    this.customerDocument = customerDocument;
+  }
+
+  public String getCustomerIdentifier() {
+    return customerIdentifier;
+  }
+
+  public CustomerDocument getCustomerDocument() {
+    return customerDocument;
+  }
+
+  @Override
+  public String toString() {
+    return "ChangeDocumentCommand{" +
+        "customerIdentifier='" + customerIdentifier + '\'' +
+        ", customerDocument=" + customerDocument.getIdentifier() +
+        '}';
+  }
+}
diff --git a/service/src/main/java/io/mifos/customer/service/internal/command/handler/DocumentCommandHandler.java
b/service/src/main/java/io/mifos/customer/service/internal/command/handler/DocumentCommandHandler.java
index 2ee4498..5be492e 100644
--- a/service/src/main/java/io/mifos/customer/service/internal/command/handler/DocumentCommandHandler.java
+++ b/service/src/main/java/io/mifos/customer/service/internal/command/handler/DocumentCommandHandler.java
@@ -23,10 +23,7 @@ import io.mifos.core.lang.ServiceException;
 import io.mifos.customer.api.v1.CustomerEventConstants;
 import io.mifos.customer.api.v1.events.DocumentEvent;
 import io.mifos.customer.api.v1.events.DocumentPageEvent;
-import io.mifos.customer.service.internal.command.CompleteDocumentCommand;
-import io.mifos.customer.service.internal.command.CreateDocumentCommand;
-import io.mifos.customer.service.internal.command.CreateDocumentPageCommand;
-import io.mifos.customer.service.internal.command.DeleteDocumentPageCommand;
+import io.mifos.customer.service.internal.command.*;
 import io.mifos.customer.service.internal.mapper.DocumentMapper;
 import io.mifos.customer.service.internal.repository.*;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -85,6 +82,24 @@ public class DocumentCommandHandler {
 
   @Transactional
   @CommandHandler
+  @EventEmitter(selectorName = CustomerEventConstants.SELECTOR_NAME, selectorValue = CustomerEventConstants.PUT_DOCUMENT)
+  public DocumentEvent process(final ChangeDocumentCommand command) throws IOException {
+    final DocumentEntity existingDocument = documentRepository.findByCustomerIdAndDocumentIdentifier(
+        command.getCustomerIdentifier(), command.getCustomerDocument().getIdentifier())
+        .orElseThrow(() ->
+            ServiceException.notFound("Document ''{0}'' for customer ''{1}'' not found",
+                command.getCustomerDocument().getIdentifier(), command.getCustomerIdentifier()));
+
+    final CustomerEntity customerEntity = customerRepository.findByIdentifier(command.getCustomerIdentifier());
+    final DocumentEntity documentEntity = DocumentMapper.map(command.getCustomerDocument(),
customerEntity);
+    documentEntity.setId(existingDocument.getId());
+    documentRepository.save(documentEntity);
+
+    return new DocumentEvent(command.getCustomerIdentifier(), command.getCustomerDocument().getIdentifier());
+  }
+
+  @Transactional
+  @CommandHandler
   @EventEmitter(selectorName = CustomerEventConstants.SELECTOR_NAME, selectorValue = CustomerEventConstants.POST_DOCUMENT_COMPLETE)
   public DocumentEvent process(final CompleteDocumentCommand command) throws IOException
{
     final DocumentEntity documentEntity = documentRepository.findByCustomerIdAndDocumentIdentifier(
diff --git a/service/src/main/java/io/mifos/customer/service/rest/controller/DocumentsRestController.java
b/service/src/main/java/io/mifos/customer/service/rest/controller/DocumentsRestController.java
index 8cd97d8..79c6aae 100644
--- a/service/src/main/java/io/mifos/customer/service/rest/controller/DocumentsRestController.java
+++ b/service/src/main/java/io/mifos/customer/service/rest/controller/DocumentsRestController.java
@@ -21,10 +21,7 @@ import io.mifos.core.command.gateway.CommandGateway;
 import io.mifos.core.lang.ServiceException;
 import io.mifos.customer.PermittableGroupIds;
 import io.mifos.customer.api.v1.domain.CustomerDocument;
-import io.mifos.customer.service.internal.command.CompleteDocumentCommand;
-import io.mifos.customer.service.internal.command.CreateDocumentCommand;
-import io.mifos.customer.service.internal.command.CreateDocumentPageCommand;
-import io.mifos.customer.service.internal.command.DeleteDocumentPageCommand;
+import io.mifos.customer.service.internal.command.*;
 import io.mifos.customer.service.internal.repository.DocumentPageEntity;
 import io.mifos.customer.service.internal.service.CustomerService;
 import io.mifos.customer.service.internal.service.DocumentService;
@@ -115,6 +112,30 @@ public class DocumentsRestController {
 
   @Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.DOCUMENTS)
   @RequestMapping(
+      value = "/{documentidentifier}",
+      method = RequestMethod.PUT,
+      produces = MediaType.APPLICATION_JSON_VALUE,
+      consumes = MediaType.APPLICATION_JSON_VALUE
+  )
+  public @ResponseBody
+  ResponseEntity<Void> changeDocument(
+      @PathVariable("customeridentifier") final String customerIdentifier,
+      @PathVariable("documentidentifier") final String documentIdentifier,
+      @RequestBody final @Valid CustomerDocument instance) {
+    throwIfCustomerNotExists(customerIdentifier);
+    throwIfCustomerDocumentNotExists(customerIdentifier, documentIdentifier);
+
+    if (!instance.getIdentifier().equals(documentIdentifier))
+      throw ServiceException.badRequest("Document identifier in request body must match document
identifier in request path.");
+
+    commandGateway.process(new ChangeDocumentCommand(customerIdentifier, instance));
+
+    return ResponseEntity.accepted().build();
+  }
+
+
+  @Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.DOCUMENTS)
+  @RequestMapping(
       value = "/{documentidentifier}/completed",
       method = RequestMethod.POST,
       produces = MediaType.APPLICATION_JSON_VALUE,

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

Mime
View raw message