You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by av...@apache.org on 2021/08/03 13:26:24 UTC

[fineract-cn-customer] branch develop updated: non-person-api-with-account

This is an automated email from the ASF dual-hosted git repository.

avikg pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-customer.git


The following commit(s) were added to refs/heads/develop by this push:
     new 2a3e865  non-person-api-with-account
     new 0189d8b  Merge pull request #20 from fynmanoj/nonperson
2a3e865 is described below

commit 2a3e865352e4ba884517c6fc673a77cc6efb6bc0
Author: Manoj <ma...@fynarfin.io>
AuthorDate: Wed Mar 31 21:51:00 2021 +0530

    non-person-api-with-account
---
 .../cn/customer/api/v1/domain/NonPerson.java       | 57 ++++++++++++++
 service/build.gradle                               |  1 +
 .../catalog/internal/repository/FieldEntity.java   |  2 +-
 .../command/handler/CustomerAggregate.java         |  8 +-
 .../customer/internal/mapper/CustomerMapper.java   |  7 +-
 .../customer/internal/service/CustomerService.java |  3 +-
 .../rest/config/CustomerRestConfiguration.java     |  5 ++
 .../rest/controller/CustomerRestController.java    | 91 +++++++++++++++++++---
 .../postgresql/V10__relax_customer_constraints.sql | 24 ++++++
 shared.gradle                                      |  1 +
 10 files changed, 181 insertions(+), 18 deletions(-)

diff --git a/api/src/main/java/org/apache/fineract/cn/customer/api/v1/domain/NonPerson.java b/api/src/main/java/org/apache/fineract/cn/customer/api/v1/domain/NonPerson.java
new file mode 100644
index 0000000..7b21b63
--- /dev/null
+++ b/api/src/main/java/org/apache/fineract/cn/customer/api/v1/domain/NonPerson.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.fineract.cn.customer.api.v1.domain;
+
+import org.hibernate.validator.constraints.NotBlank;
+
+public class NonPerson {
+    @NotBlank
+    private String productIdentifier;
+    @NotBlank
+    private String accountNumber;
+
+    private Boolean isActive;
+
+    public NonPerson() {
+    }
+
+    public String getProductIdentifier() {
+        return productIdentifier;
+    }
+
+    public void setProductIdentifier(String productIdentifier) {
+        this.productIdentifier = productIdentifier;
+    }
+
+    public String getAccountNumber() {
+        return accountNumber;
+    }
+
+    public void setAccountNumber(String accountNumber) {
+        this.accountNumber = accountNumber;
+    }
+
+    public Boolean isActive() {
+        return isActive == null ? false: isActive;
+    }
+
+    public void setActive(Boolean active) {
+        isActive = active;
+    }
+}
diff --git a/service/build.gradle b/service/build.gradle
index 3b845c1..4f5a50c 100644
--- a/service/build.gradle
+++ b/service/build.gradle
@@ -48,6 +48,7 @@ dependencies {
             [group: 'org.springframework.boot', name: 'spring-boot-starter-jetty'],
             [group: 'org.apache.fineract.cn.customer', name: 'api', version: project.version],
             [group: 'org.apache.fineract.cn.anubis', name: 'library', version: versions.frameworkanubis],
+            [group: 'org.apache.fineract.cn.deposit-account-management', name: 'api', version: project.version],
             [group: 'com.google.code.gson', name: 'gson'],
             [group: 'org.apache.fineract.cn', name: 'lang', version: versions.frameworklang],
             [group: 'org.apache.fineract.cn', name: 'async', version: versions.frameworkasync],
diff --git a/service/src/main/java/org/apache/fineract/cn/customer/catalog/internal/repository/FieldEntity.java b/service/src/main/java/org/apache/fineract/cn/customer/catalog/internal/repository/FieldEntity.java
index 9b77aaa..73d2cc0 100644
--- a/service/src/main/java/org/apache/fineract/cn/customer/catalog/internal/repository/FieldEntity.java
+++ b/service/src/main/java/org/apache/fineract/cn/customer/catalog/internal/repository/FieldEntity.java
@@ -53,7 +53,7 @@ public class FieldEntity {
   private String label;
   @Column(name = "a_hint", length = 512)
   private String hint;
-  @Length(max = 4096)
+  //@Length(max = 4096) Removed to fix Travis issues.
   @JoinColumn(name = "description")
   @OneToMany(mappedBy = "field", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
   private List<OptionEntity> options;
diff --git a/service/src/main/java/org/apache/fineract/cn/customer/internal/command/handler/CustomerAggregate.java b/service/src/main/java/org/apache/fineract/cn/customer/internal/command/handler/CustomerAggregate.java
index 7ac1785..adad9f6 100644
--- a/service/src/main/java/org/apache/fineract/cn/customer/internal/command/handler/CustomerAggregate.java
+++ b/service/src/main/java/org/apache/fineract/cn/customer/internal/command/handler/CustomerAggregate.java
@@ -129,12 +129,12 @@ public class CustomerAggregate {
   @EventEmitter(selectorName = CustomerEventConstants.SELECTOR_NAME, selectorValue = CustomerEventConstants.POST_CUSTOMER)
   public String createCustomer(final CreateCustomerCommand createCustomerCommand) {
     final Customer customer = createCustomerCommand.customer();
-
-    final AddressEntity savedAddress = this.addressRepository.save(AddressMapper.map(customer.getAddress()));
-
     final CustomerEntity customerEntity = CustomerMapper.map(customer);
     customerEntity.setCurrentState(Customer.State.PENDING.name());
-    customerEntity.setAddress(savedAddress);
+    if(customer.getAddress() !=null) {
+      final AddressEntity savedAddress = this.addressRepository.save(AddressMapper.map(customer.getAddress()));
+      customerEntity.setAddress(savedAddress);
+    }
     final CustomerEntity savedCustomerEntity = this.customerRepository.save(customerEntity);
 
     if (customer.getContactDetails() != null) {
diff --git a/service/src/main/java/org/apache/fineract/cn/customer/internal/mapper/CustomerMapper.java b/service/src/main/java/org/apache/fineract/cn/customer/internal/mapper/CustomerMapper.java
index 4d17067..474c67c 100644
--- a/service/src/main/java/org/apache/fineract/cn/customer/internal/mapper/CustomerMapper.java
+++ b/service/src/main/java/org/apache/fineract/cn/customer/internal/mapper/CustomerMapper.java
@@ -40,7 +40,9 @@ public final class CustomerMapper {
     customerEntity.setGivenName(customer.getGivenName());
     customerEntity.setMiddleName(customer.getMiddleName());
     customerEntity.setSurname(customer.getSurname());
-    customerEntity.setDateOfBirth(Date.valueOf(customer.getDateOfBirth().toLocalDate()));
+    if(customer.getDateOfBirth() !=null) {
+      customerEntity.setDateOfBirth(Date.valueOf(customer.getDateOfBirth().toLocalDate()));
+    }
     customerEntity.setMember(customer.getMember());
     customerEntity.setAccountBeneficiary(customer.getAccountBeneficiary());
     customerEntity.setReferenceCustomer(customer.getReferenceCustomer());
@@ -68,7 +70,8 @@ public final class CustomerMapper {
     customer.setGivenName(customerEntity.getGivenName());
     customer.setMiddleName(customerEntity.getMiddleName());
     customer.setSurname(customerEntity.getSurname());
-    customer.setDateOfBirth(DateOfBirth.fromLocalDate(customerEntity.getDateOfBirth().toLocalDate()));
+    if(customerEntity.getDateOfBirth() != null)
+      customer.setDateOfBirth(DateOfBirth.fromLocalDate(customerEntity.getDateOfBirth().toLocalDate()));
     customer.setMember(customerEntity.getMember());
     customer.setAccountBeneficiary(customerEntity.getAccountBeneficiary());
     customer.setReferenceCustomer(customerEntity.getReferenceCustomer());
diff --git a/service/src/main/java/org/apache/fineract/cn/customer/internal/service/CustomerService.java b/service/src/main/java/org/apache/fineract/cn/customer/internal/service/CustomerService.java
index 3f87a1a..38189d8 100644
--- a/service/src/main/java/org/apache/fineract/cn/customer/internal/service/CustomerService.java
+++ b/service/src/main/java/org/apache/fineract/cn/customer/internal/service/CustomerService.java
@@ -90,7 +90,8 @@ public class CustomerService {
     return customerRepository.findByIdentifier(identifier)
         .map(customerEntity -> {
           final Customer customer = CustomerMapper.map(customerEntity);
-          customer.setAddress(AddressMapper.map(customerEntity.getAddress()));
+          if(customerEntity !=null && customerEntity.getAddress() != null)
+            customer.setAddress(AddressMapper.map(customerEntity.getAddress()));
 
           final List<ContactDetailEntity> contactDetailEntities = this.contactDetailRepository.findByCustomer(customerEntity);
           if (contactDetailEntities != null) {
diff --git a/service/src/main/java/org/apache/fineract/cn/customer/rest/config/CustomerRestConfiguration.java b/service/src/main/java/org/apache/fineract/cn/customer/rest/config/CustomerRestConfiguration.java
index 316647e..4b87b26 100644
--- a/service/src/main/java/org/apache/fineract/cn/customer/rest/config/CustomerRestConfiguration.java
+++ b/service/src/main/java/org/apache/fineract/cn/customer/rest/config/CustomerRestConfiguration.java
@@ -25,6 +25,7 @@ import org.apache.fineract.cn.anubis.config.EnableAnubis;
 import org.apache.fineract.cn.async.config.EnableAsync;
 import org.apache.fineract.cn.cassandra.config.EnableCassandra;
 import org.apache.fineract.cn.command.config.EnableCommandProcessing;
+import org.apache.fineract.cn.deposit.api.v1.client.DepositAccountManager;
 import org.apache.fineract.cn.lang.ApplicationName;
 import org.apache.fineract.cn.lang.config.EnableApplicationName;
 import org.apache.fineract.cn.lang.config.EnableServiceException;
@@ -34,6 +35,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.netflix.feign.EnableFeignClients;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
@@ -59,6 +61,9 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
     CustomerServiceConfiguration.class
 })
 @EnableConfigurationProperties({UploadProperties.class})
+@EnableFeignClients(clients = {
+        DepositAccountManager.class
+})
 public class CustomerRestConfiguration extends WebMvcConfigurerAdapter {
 
   public CustomerRestConfiguration() {
diff --git a/service/src/main/java/org/apache/fineract/cn/customer/rest/controller/CustomerRestController.java b/service/src/main/java/org/apache/fineract/cn/customer/rest/controller/CustomerRestController.java
index aac80ca..dfe8baa 100644
--- a/service/src/main/java/org/apache/fineract/cn/customer/rest/controller/CustomerRestController.java
+++ b/service/src/main/java/org/apache/fineract/cn/customer/rest/controller/CustomerRestController.java
@@ -19,15 +19,7 @@
 package org.apache.fineract.cn.customer.rest.controller;
 
 import org.apache.fineract.cn.customer.PermittableGroupIds;
-import org.apache.fineract.cn.customer.api.v1.domain.Address;
-import org.apache.fineract.cn.customer.api.v1.domain.Command;
-import org.apache.fineract.cn.customer.api.v1.domain.ContactDetail;
-import org.apache.fineract.cn.customer.api.v1.domain.Customer;
-import org.apache.fineract.cn.customer.api.v1.domain.CustomerPage;
-import org.apache.fineract.cn.customer.api.v1.domain.IdentificationCard;
-import org.apache.fineract.cn.customer.api.v1.domain.IdentificationCardScan;
-import org.apache.fineract.cn.customer.api.v1.domain.ProcessStep;
-import org.apache.fineract.cn.customer.api.v1.domain.TaskDefinition;
+import org.apache.fineract.cn.customer.api.v1.domain.*;
 import org.apache.fineract.cn.customer.catalog.internal.service.FieldValueValidator;
 import org.apache.fineract.cn.customer.ServiceConstants;
 import org.apache.fineract.cn.customer.internal.command.ActivateCustomerCommand;
@@ -64,6 +56,8 @@ import org.apache.fineract.cn.anubis.annotation.AcceptedTokenType;
 import org.apache.fineract.cn.anubis.annotation.Permittable;
 import org.apache.fineract.cn.api.util.UserContextHolder;
 import org.apache.fineract.cn.command.gateway.CommandGateway;
+import org.apache.fineract.cn.deposit.api.v1.client.DepositAccountManager;
+import org.apache.fineract.cn.deposit.api.v1.instance.domain.ProductInstance;
 import org.apache.fineract.cn.lang.ServiceException;
 import org.apache.fineract.cn.lang.validation.constraints.ValidIdentifier;
 import org.slf4j.Logger;
@@ -94,6 +88,7 @@ public class CustomerRestController {
   private final FieldValueValidator fieldValueValidator;
   private final TaskService taskService;
   private final Environment environment;
+  private final DepositAccountManager depositAccountManager;
 
   @Autowired
   public CustomerRestController(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger logger,
@@ -101,7 +96,8 @@ public class CustomerRestController {
                                 final CustomerService customerService,
                                 final FieldValueValidator fieldValueValidator,
                                 final TaskService taskService,
-                                final Environment environment) {
+                                final Environment environment,
+                                final DepositAccountManager depositAccountManager) {
     super();
     this.logger = logger;
     this.commandGateway = commandGateway;
@@ -109,6 +105,7 @@ public class CustomerRestController {
     this.fieldValueValidator = fieldValueValidator;
     this.taskService = taskService;
     this.environment = environment;
+    this.depositAccountManager = depositAccountManager;
   }
 
   @Permittable(value = AcceptedTokenType.SYSTEM)
@@ -144,6 +141,80 @@ public class CustomerRestController {
     }
 
     this.commandGateway.process(new CreateCustomerCommand(customer));
+
+    return ResponseEntity.accepted().build();
+  }
+
+  @Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.CUSTOMER)
+  @RequestMapping(
+          value = "/person",
+          method = RequestMethod.POST,
+          produces = MediaType.APPLICATION_JSON_VALUE,
+          consumes = MediaType.APPLICATION_JSON_VALUE
+  )
+  public
+  @ResponseBody
+  ResponseEntity<Void> createPerson(@RequestBody @Valid final NonPerson nonPerson) throws InterruptedException {
+    Customer customer = new Customer();
+    customer.setIdentifier(nonPerson.getAccountNumber());
+    customer.setType(Customer.Type.PERSON.name());
+    customer.setCurrentState(Customer.State.PENDING.name());
+    customer.setMember(false);
+    if (this.customerService.customerExists(customer.getIdentifier())) {
+      throw ServiceException.conflict("Customer {0} already exists.", customer.getIdentifier());
+    }
+
+    this.commandGateway.process(new CreateCustomerCommand(customer));
+
+    ProductInstance productInstance = new ProductInstance();
+    productInstance.setProductIdentifier(nonPerson.getProductIdentifier());
+    productInstance.setCustomerIdentifier(customer.getIdentifier());
+    productInstance.setAccountIdentifier(customer.getIdentifier());
+    //create account
+    depositAccountManager.create(productInstance);
+
+    //activate
+    if(nonPerson.isActive()){
+      this.commandGateway.process(new ActivateCustomerCommand(nonPerson.getAccountNumber(), "ACTIVATE"));
+      this.depositAccountManager.postProductInstanceCommand(customer.getIdentifier(), "ACTIVATE");
+    }
+
+    return ResponseEntity.accepted().build();
+  }
+
+
+  @Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.CUSTOMER)
+  @RequestMapping(
+          value = "/nonperson",
+          method = RequestMethod.POST,
+          produces = MediaType.APPLICATION_JSON_VALUE,
+          consumes = MediaType.APPLICATION_JSON_VALUE
+  )
+  public
+  @ResponseBody
+  ResponseEntity<Void> createNonPerson(@RequestBody @Valid final NonPerson nonPerson) throws InterruptedException {
+    Customer customer = new Customer();
+    customer.setIdentifier(nonPerson.getAccountNumber());
+    customer.setType(Customer.Type.BUSINESS.name());
+    customer.setCurrentState(Customer.State.PENDING.name());
+    customer.setMember(false);
+    if (this.customerService.customerExists(customer.getIdentifier())) {
+      throw ServiceException.conflict("Customer {0} already exists.", customer.getIdentifier());
+    }
+
+    this.commandGateway.process(new CreateCustomerCommand(customer));
+
+    ProductInstance productInstance = new ProductInstance();
+    productInstance.setProductIdentifier(nonPerson.getProductIdentifier());
+    productInstance.setCustomerIdentifier(customer.getIdentifier());
+    productInstance.setAccountIdentifier(customer.getIdentifier());
+    //create account
+    depositAccountManager.create(productInstance);
+    //activate
+    if(nonPerson.isActive()){
+      this.commandGateway.process(new ActivateCustomerCommand(customer.getIdentifier(), "ACTIVATE"));
+      this.depositAccountManager.postProductInstanceCommand(customer.getIdentifier(), "ACTIVATE");
+    }
     return ResponseEntity.accepted().build();
   }
 
diff --git a/service/src/main/resources/db/migrations/postgresql/V10__relax_customer_constraints.sql b/service/src/main/resources/db/migrations/postgresql/V10__relax_customer_constraints.sql
new file mode 100644
index 0000000..e52397f
--- /dev/null
+++ b/service/src/main/resources/db/migrations/postgresql/V10__relax_customer_constraints.sql
@@ -0,0 +1,24 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you 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.
+--
+
+
+ALTER TABLE maat_customers ALTER given_name DROP NOT NULL,
+                ALTER surname DROP NOT NULL,
+                ALTER address_id DROP NOT NULL,
+                ALTER date_of_birth DROP NOT NULL;
\ No newline at end of file
diff --git a/shared.gradle b/shared.gradle
index 38f8ac3..5bfedcb 100644
--- a/shared.gradle
+++ b/shared.gradle
@@ -27,6 +27,7 @@ ext.versions = [
         frameworkcommand : '0.1.0-BUILD-SNAPSHOT',
         frameworktest: '0.1.0-BUILD-SNAPSHOT',
         frameworkanubis: '0.1.0-BUILD-SNAPSHOT',
+        frameworkdeposit: '0.1.0-BUILD-SNAPSHOT',
         validator  : '5.3.0.Final'
 ]