fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From my...@apache.org
Subject [fineract-cn-deposit-account-management] 07/23: edited after first UI impl
Date Mon, 22 Jan 2018 15:28:40 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-deposit-account-management.git

commit e880f9b6b2ba6e819d58417c318fb425918f2d9c
Author: mgeiss <mgeiss@mifos.org>
AuthorDate: Mon May 29 20:19:42 2017 +0700

    edited after first UI impl
---
 .../api/v1/client/DepositAccountManager.java       | 11 +++++
 .../definition/ActionAlreadyExistsException.java   | 21 +--------
 .../ProductDefinitionAlreadyExistsException.java   | 21 +--------
 .../AbstractDepositAccountManagementTest.java      |  3 +-
 .../src/main/java/io/mifos/deposit/Fixture.java    | 10 ++++
 .../main/java/io/mifos/deposit/TestActions.java    | 23 +++++++++-
 .../io/mifos/deposit/TestProductDefinition.java    | 33 ++++++++++++++
 .../java/io/mifos/deposit/TestProductInstance.java |  1 -
 .../deposit/listener/ActionEventListener.java      | 53 ++++++++++++++++++++++
 .../internal/command/handler/ActionAggregate.java  |  1 +
 .../command/handler/ProductInstanceAggregate.java  |  5 ++
 .../rest/ProductDefinitionRestController.java      |  8 +++-
 .../db/migrations/mariadb/V1__initial_setup.sql    |  2 +-
 13 files changed, 148 insertions(+), 44 deletions(-)

diff --git a/api/src/main/java/io/mifos/deposit/api/v1/client/DepositAccountManager.java b/api/src/main/java/io/mifos/deposit/api/v1/client/DepositAccountManager.java
index 516e4e2..2cc93d4 100644
--- a/api/src/main/java/io/mifos/deposit/api/v1/client/DepositAccountManager.java
+++ b/api/src/main/java/io/mifos/deposit/api/v1/client/DepositAccountManager.java
@@ -15,12 +15,17 @@
  */
 package io.mifos.deposit.api.v1.client;
 
+import io.mifos.core.api.annotation.ThrowsException;
+import io.mifos.core.api.annotation.ThrowsExceptions;
 import io.mifos.core.api.util.CustomFeignClientsConfiguration;
+import io.mifos.deposit.api.v1.definition.ActionAlreadyExistsException;
+import io.mifos.deposit.api.v1.definition.ProductDefinitionAlreadyExistsException;
 import io.mifos.deposit.api.v1.definition.domain.Action;
 import io.mifos.deposit.api.v1.definition.domain.ProductDefinition;
 import io.mifos.deposit.api.v1.definition.domain.ProductDefinitionCommand;
 import io.mifos.deposit.api.v1.instance.domain.ProductInstance;
 import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -41,6 +46,9 @@ public interface DepositAccountManager {
       consumes = MediaType.APPLICATION_JSON_VALUE,
       produces = MediaType.APPLICATION_JSON_VALUE
   )
+  @ThrowsExceptions(
+      @ThrowsException(status = HttpStatus.CONFLICT, exception = ActionAlreadyExistsException.class)
+  )
   void create(@RequestBody @Valid final Action action);
 
   @RequestMapping(
@@ -57,6 +65,9 @@ public interface DepositAccountManager {
       consumes = MediaType.APPLICATION_JSON_VALUE,
       produces = MediaType.APPLICATION_JSON_VALUE
   )
+  @ThrowsExceptions(
+      @ThrowsException(status = HttpStatus.CONFLICT, exception = ProductDefinitionAlreadyExistsException.class)
+  )
   void create(@RequestBody @Valid final ProductDefinition productDefinition);
 
   @RequestMapping(
diff --git a/component-test/src/main/java/io/mifos/deposit/TestActions.java b/api/src/main/java/io/mifos/deposit/api/v1/definition/ActionAlreadyExistsException.java
similarity index 57%
copy from component-test/src/main/java/io/mifos/deposit/TestActions.java
copy to api/src/main/java/io/mifos/deposit/api/v1/definition/ActionAlreadyExistsException.java
index 4d34f83..8d9277b 100644
--- a/component-test/src/main/java/io/mifos/deposit/TestActions.java
+++ b/api/src/main/java/io/mifos/deposit/api/v1/definition/ActionAlreadyExistsException.java
@@ -13,24 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package io.mifos.deposit;
+package io.mifos.deposit.api.v1.definition;
 
-import io.mifos.deposit.api.v1.definition.domain.Action;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.List;
-
-public class TestActions extends AbstractDepositAccountManagementTest {
-
-  public TestActions() {
-    super();
-  }
-
-  @Test
-  public void shouldFetchDefaultActions() {
-    final List<Action> actions = super.depositAccountManager.fetchActions();
-
-    Assert.assertEquals(5, actions.size());
-  }
+public class ActionAlreadyExistsException extends RuntimeException {
 }
diff --git a/component-test/src/main/java/io/mifos/deposit/TestActions.java b/api/src/main/java/io/mifos/deposit/api/v1/definition/ProductDefinitionAlreadyExistsException.java
similarity index 57%
copy from component-test/src/main/java/io/mifos/deposit/TestActions.java
copy to api/src/main/java/io/mifos/deposit/api/v1/definition/ProductDefinitionAlreadyExistsException.java
index 4d34f83..08f429e 100644
--- a/component-test/src/main/java/io/mifos/deposit/TestActions.java
+++ b/api/src/main/java/io/mifos/deposit/api/v1/definition/ProductDefinitionAlreadyExistsException.java
@@ -13,24 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package io.mifos.deposit;
+package io.mifos.deposit.api.v1.definition;
 
-import io.mifos.deposit.api.v1.definition.domain.Action;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.List;
-
-public class TestActions extends AbstractDepositAccountManagementTest {
-
-  public TestActions() {
-    super();
-  }
-
-  @Test
-  public void shouldFetchDefaultActions() {
-    final List<Action> actions = super.depositAccountManager.fetchActions();
-
-    Assert.assertEquals(5, actions.size());
-  }
+public class ProductDefinitionAlreadyExistsException extends RuntimeException {
 }
diff --git a/component-test/src/main/java/io/mifos/deposit/AbstractDepositAccountManagementTest.java
b/component-test/src/main/java/io/mifos/deposit/AbstractDepositAccountManagementTest.java
index fa16c72..3dad546 100644
--- a/component-test/src/main/java/io/mifos/deposit/AbstractDepositAccountManagementTest.java
+++ b/component-test/src/main/java/io/mifos/deposit/AbstractDepositAccountManagementTest.java
@@ -50,7 +50,8 @@ import org.springframework.test.context.junit4.SpringRunner;
 @RunWith(SpringRunner.class)
 @SpringBootTest(
     webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
-    classes = {AbstractDepositAccountManagementTest.TestConfiguration.class})
+    classes = {AbstractDepositAccountManagementTest.TestConfiguration.class}
+)
 public abstract class AbstractDepositAccountManagementTest {
 
   private static final String APP_NAME = "deposit-v1";
diff --git a/component-test/src/main/java/io/mifos/deposit/Fixture.java b/component-test/src/main/java/io/mifos/deposit/Fixture.java
index 21cee88..5e08d7b 100644
--- a/component-test/src/main/java/io/mifos/deposit/Fixture.java
+++ b/component-test/src/main/java/io/mifos/deposit/Fixture.java
@@ -15,6 +15,7 @@
  */
 package io.mifos.deposit;
 
+import io.mifos.deposit.api.v1.definition.domain.Action;
 import io.mifos.deposit.api.v1.definition.domain.Charge;
 import io.mifos.deposit.api.v1.definition.domain.Currency;
 import io.mifos.deposit.api.v1.definition.domain.ProductDefinition;
@@ -75,4 +76,13 @@ public class Fixture {
     return productDefinition;
   }
 
+  public static Action action() {
+    final Action action = new Action();
+    action.setIdentifier(RandomStringUtils.randomAlphanumeric(32));
+    action.setName(RandomStringUtils.randomAlphanumeric(256));
+    action.setDescription(RandomStringUtils.randomAlphanumeric(2048));
+    action.setTransactionType("ACCO");
+
+    return action;
+  }
 }
diff --git a/component-test/src/main/java/io/mifos/deposit/TestActions.java b/component-test/src/main/java/io/mifos/deposit/TestActions.java
index 4d34f83..fe3b79f 100644
--- a/component-test/src/main/java/io/mifos/deposit/TestActions.java
+++ b/component-test/src/main/java/io/mifos/deposit/TestActions.java
@@ -15,6 +15,8 @@
  */
 package io.mifos.deposit;
 
+import io.mifos.deposit.api.v1.EventConstants;
+import io.mifos.deposit.api.v1.definition.ActionAlreadyExistsException;
 import io.mifos.deposit.api.v1.definition.domain.Action;
 import org.junit.Assert;
 import org.junit.Test;
@@ -31,6 +33,25 @@ public class TestActions extends AbstractDepositAccountManagementTest {
   public void shouldFetchDefaultActions() {
     final List<Action> actions = super.depositAccountManager.fetchActions();
 
-    Assert.assertEquals(5, actions.size());
+    Assert.assertTrue(actions.size() >= 5);
+  }
+
+  @Test
+  public void shouldCreateAction() throws Exception {
+    final Action action = Fixture.action();
+
+    super.depositAccountManager.create(action);
+
+    super.eventRecorder.wait(EventConstants.POST_PRODUCT_ACTION, action.getIdentifier());
+  }
+
+  @Test(expected = ActionAlreadyExistsException.class)
+  public void shouldNoCreateActionAlreadyExists() throws Exception {
+    final Action action = Fixture.action();
+    super.depositAccountManager.create(action);
+
+    super.eventRecorder.wait(EventConstants.POST_PRODUCT_ACTION, action.getIdentifier());
+
+    super.depositAccountManager.create(action);
   }
 }
diff --git a/component-test/src/main/java/io/mifos/deposit/TestProductDefinition.java b/component-test/src/main/java/io/mifos/deposit/TestProductDefinition.java
index f7011a9..b48c67b 100644
--- a/component-test/src/main/java/io/mifos/deposit/TestProductDefinition.java
+++ b/component-test/src/main/java/io/mifos/deposit/TestProductDefinition.java
@@ -16,6 +16,7 @@
 package io.mifos.deposit;
 
 import io.mifos.deposit.api.v1.EventConstants;
+import io.mifos.deposit.api.v1.definition.ProductDefinitionAlreadyExistsException;
 import io.mifos.deposit.api.v1.definition.domain.ProductDefinition;
 import io.mifos.deposit.api.v1.definition.domain.ProductDefinitionCommand;
 import org.apache.commons.lang3.RandomStringUtils;
@@ -37,6 +38,18 @@ public class TestProductDefinition extends AbstractDepositAccountManagementTest
     super.eventRecorder.wait(EventConstants.POST_PRODUCT_DEFINITION, productDefinition.getIdentifier());
   }
 
+
+  @Test(expected = ProductDefinitionAlreadyExistsException.class)
+  public void shouldNotCreateProductDefinitionAlreadyExists() throws Exception {
+    final ProductDefinition productDefinition = Fixture.productDefinition();
+
+    super.depositAccountManager.create(productDefinition);
+
+    super.eventRecorder.wait(EventConstants.POST_PRODUCT_DEFINITION, productDefinition.getIdentifier());
+
+    super.depositAccountManager.create(productDefinition);
+  }
+
   @Test
   public void shouldFindProductDefinition() throws Exception {
     final ProductDefinition productDefinition = Fixture.productDefinition();
@@ -96,4 +109,24 @@ public class TestProductDefinition extends AbstractDepositAccountManagementTest
 
     Assert.assertFalse(fetchProductDefinition.getActive());
   }
+
+  @Test
+  public void shouldAllowCommandWithNullNote() throws Exception {
+    final ProductDefinition productDefinition = Fixture.productDefinition();
+
+    super.depositAccountManager.create(productDefinition);
+
+    super.eventRecorder.wait(EventConstants.POST_PRODUCT_DEFINITION, productDefinition.getIdentifier());
+
+    final ProductDefinitionCommand productDefinitionCommand = new ProductDefinitionCommand();
+    productDefinitionCommand.setAction(ProductDefinitionCommand.Action.DEACTIVATE.name());
+
+    super.depositAccountManager.process(productDefinition.getIdentifier(), productDefinitionCommand);
+
+    super.eventRecorder.wait(EventConstants.POST_PRODUCT_DEFINITION_COMMAND, productDefinition.getIdentifier());
+
+    final ProductDefinition fetchProductDefinition = super.depositAccountManager.findProductDefinition(productDefinition.getIdentifier());
+
+    Assert.assertFalse(fetchProductDefinition.getActive());
+  }
 }
diff --git a/component-test/src/main/java/io/mifos/deposit/TestProductInstance.java b/component-test/src/main/java/io/mifos/deposit/TestProductInstance.java
index f6c6224..59454b3 100644
--- a/component-test/src/main/java/io/mifos/deposit/TestProductInstance.java
+++ b/component-test/src/main/java/io/mifos/deposit/TestProductInstance.java
@@ -41,7 +41,6 @@ public class TestProductInstance extends AbstractDepositAccountManagementTest
{
     final ProductInstance productInstance = new ProductInstance();
     productInstance.setProductIdentifier(productDefinition.getIdentifier());
     productInstance.setCustomerIdentifier(customerIdentifier);
-    productInstance.setAccountIdentifier("60606");
 
     super.depositAccountManager.create(productInstance);
 
diff --git a/component-test/src/main/java/io/mifos/deposit/listener/ActionEventListener.java
b/component-test/src/main/java/io/mifos/deposit/listener/ActionEventListener.java
new file mode 100644
index 0000000..20409b6
--- /dev/null
+++ b/component-test/src/main/java/io/mifos/deposit/listener/ActionEventListener.java
@@ -0,0 +1,53 @@
+/*
+ * 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.deposit.listener;
+
+import io.mifos.core.lang.config.TenantHeaderFilter;
+import io.mifos.core.test.listener.EventRecorder;
+import io.mifos.deposit.AbstractDepositAccountManagementTest;
+import io.mifos.deposit.api.v1.EventConstants;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.jms.annotation.JmsListener;
+import org.springframework.messaging.handler.annotation.Header;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ActionEventListener {
+
+  private final Logger logger;
+  private final EventRecorder eventRecorder;
+
+  @Autowired
+  public ActionEventListener(@Qualifier(AbstractDepositAccountManagementTest.TEST_LOGGER)
final Logger logger,
+                             final EventRecorder eventRecorder) {
+    super();
+    this.logger = logger;
+    this.eventRecorder = eventRecorder;
+  }
+
+  @JmsListener(
+      destination = EventConstants.DESTINATION,
+      selector = EventConstants.SELECTOR_POST_PRODUCT_ACTION,
+      subscription = EventConstants.DESTINATION
+  )
+  public void onCreateAction(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
+                             final String payload) {
+    this.logger.debug("Action created.");
+    this.eventRecorder.event(tenant, EventConstants.POST_PRODUCT_ACTION, payload, String.class);
+  }
+}
diff --git a/service/src/main/java/io/mifos/deposit/service/internal/command/handler/ActionAggregate.java
b/service/src/main/java/io/mifos/deposit/service/internal/command/handler/ActionAggregate.java
index 8dcde7c..f2d9dbd 100644
--- a/service/src/main/java/io/mifos/deposit/service/internal/command/handler/ActionAggregate.java
+++ b/service/src/main/java/io/mifos/deposit/service/internal/command/handler/ActionAggregate.java
@@ -48,6 +48,7 @@ public class ActionAggregate {
   public String createAction(final CreateActionCommand createActionCommand) {
     final Action action = createActionCommand.action();
     this.actionRepository.save(ActionMapper.map(action));
+    this.logger.debug("Action {} created.", action.getIdentifier());
     return action.getIdentifier();
   }
 }
diff --git a/service/src/main/java/io/mifos/deposit/service/internal/command/handler/ProductInstanceAggregate.java
b/service/src/main/java/io/mifos/deposit/service/internal/command/handler/ProductInstanceAggregate.java
index edcfbba..33743d1 100644
--- a/service/src/main/java/io/mifos/deposit/service/internal/command/handler/ProductInstanceAggregate.java
+++ b/service/src/main/java/io/mifos/deposit/service/internal/command/handler/ProductInstanceAggregate.java
@@ -27,6 +27,7 @@ import io.mifos.deposit.service.internal.mapper.ProductInstanceMapper;
 import io.mifos.deposit.service.internal.repository.ProductDefinitionRepository;
 import io.mifos.deposit.service.internal.repository.ProductInstanceEntity;
 import io.mifos.deposit.service.internal.repository.ProductInstanceRepository;
+import org.apache.commons.lang.RandomStringUtils;
 import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
@@ -60,6 +61,10 @@ public class ProductInstanceAggregate {
     final ProductInstanceEntity productInstanceEntity =
         ProductInstanceMapper.map(productInstance, this.productDefinitionRepository);
 
+    if (productInstance.getAccountIdentifier() == null) {
+      productInstanceEntity.setAccountIdentifier(RandomStringUtils.randomNumeric(32));
+    }
+
     productInstanceEntity.setCreatedBy(UserContextHolder.checkedGetUser());
     productInstanceEntity.setCreatedOn(LocalDateTime.now(Clock.systemUTC()));
     productInstanceEntity.setState("PENDING");
diff --git a/service/src/main/java/io/mifos/deposit/service/rest/ProductDefinitionRestController.java
b/service/src/main/java/io/mifos/deposit/service/rest/ProductDefinitionRestController.java
index 3a828d8..785d4ee 100644
--- a/service/src/main/java/io/mifos/deposit/service/rest/ProductDefinitionRestController.java
+++ b/service/src/main/java/io/mifos/deposit/service/rest/ProductDefinitionRestController.java
@@ -75,8 +75,12 @@ public class ProductDefinitionRestController {
   )
   @ResponseBody
   public ResponseEntity<Void> create(@RequestBody @Valid final ProductDefinition productDefinition)
{
-    this.commandGateway.process(new CreateProductDefinitionCommand(productDefinition));
-    return ResponseEntity.accepted().build();
+    if (this.productDefinitionService.findProductDefinition(productDefinition.getIdentifier()).isPresent())
{
+      throw ServiceException.conflict("Product definition{0} already exists.", productDefinition.getIdentifier());
+    } else {
+      this.commandGateway.process(new CreateProductDefinitionCommand(productDefinition));
+      return ResponseEntity.accepted().build();
+    }
   }
 
   @Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.DEFINITION_MANAGEMENT)
diff --git a/service/src/main/resources/db/migrations/mariadb/V1__initial_setup.sql b/service/src/main/resources/db/migrations/mariadb/V1__initial_setup.sql
index c7ac510..530c179 100644
--- a/service/src/main/resources/db/migrations/mariadb/V1__initial_setup.sql
+++ b/service/src/main/resources/db/migrations/mariadb/V1__initial_setup.sql
@@ -108,7 +108,7 @@ CREATE TABLE shed_commands (
   id                    BIGINT        NOT NULL AUTO_INCREMENT,
   product_definition_id BIGINT        NOT NULL,
   a_action              VARCHAR(256)  NOT NULL,
-  note                  VARCHAR(2048) NOT NULL,
+  note                  VARCHAR(2048) NULL,
   created_on            TIMESTAMP(3)  NOT NULL,
   created_by            VARCHAR(32)   NOT NULL,
   CONSTRAINT shed_commands PRIMARY KEY (id),

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

Mime
View raw message