From 6c1d74a1542a4123329038339c85e01b9969a5fe Mon Sep 17 00:00:00 2001 From: fynmanoj Date: Tue, 7 Sep 2021 15:25:31 +0530 Subject: [PATCH] activate-by-default-person-non-person --- .../api/v1/client/CustomerManager.java | 35 ++++++++++++++----- .../cn/customer/api/v1/domain/NonPerson.java | 2 +- .../command/handler/CustomerAggregate.java | 4 ++- .../controller/CustomerRestController.java | 32 ++++++++++------- 4 files changed, 49 insertions(+), 24 deletions(-) diff --git a/api/src/main/java/org/apache/fineract/cn/customer/api/v1/client/CustomerManager.java b/api/src/main/java/org/apache/fineract/cn/customer/api/v1/client/CustomerManager.java index f6f60a2..84b7a26 100644 --- a/api/src/main/java/org/apache/fineract/cn/customer/api/v1/client/CustomerManager.java +++ b/api/src/main/java/org/apache/fineract/cn/customer/api/v1/client/CustomerManager.java @@ -19,15 +19,8 @@ package org.apache.fineract.cn.customer.api.v1.client; import org.apache.fineract.cn.customer.api.v1.config.CustomerFeignClientConfig; -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 java.util.List; import javax.validation.constraints.Size; import org.apache.fineract.cn.api.annotation.ThrowsException; @@ -59,6 +52,30 @@ public interface CustomerManager { }) void createCustomer(@RequestBody final Customer customer); + @RequestMapping( + value = "/person", + method = RequestMethod.POST, + produces = MediaType.APPLICATION_JSON_VALUE, + consumes = MediaType.APPLICATION_JSON_VALUE + ) + @ThrowsExceptions({ + @ThrowsException(status = HttpStatus.CONFLICT, exception = CustomerAlreadyExistsException.class), + @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = CustomerValidationException.class) + }) + void createPerson(@RequestBody final NonPerson nonPerson); + + @RequestMapping( + value = "/nonperson", + method = RequestMethod.POST, + produces = MediaType.APPLICATION_JSON_VALUE, + consumes = MediaType.APPLICATION_JSON_VALUE + ) + @ThrowsExceptions({ + @ThrowsException(status = HttpStatus.CONFLICT, exception = CustomerAlreadyExistsException.class), + @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = CustomerValidationException.class) + }) + void createNonPerson(@RequestBody final NonPerson nonPerson); + @RequestMapping( value = "/customers", method = RequestMethod.GET, 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 index 7b21b63..82d48b5 100644 --- 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 @@ -51,7 +51,7 @@ public Boolean isActive() { return isActive == null ? false: isActive; } - public void setActive(Boolean active) { + public void setIsActive(Boolean active) { isActive = active; } } 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 adad9f6..8e9adbb 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 @@ -18,6 +18,7 @@ */ package org.apache.fineract.cn.customer.internal.command.handler; +import org.apache.commons.lang.StringUtils; import org.apache.fineract.cn.customer.api.v1.CustomerEventConstants; import org.apache.fineract.cn.customer.api.v1.domain.Command; import org.apache.fineract.cn.customer.api.v1.domain.Customer; @@ -130,7 +131,8 @@ public CustomerAggregate(final AddressRepository addressRepository, public String createCustomer(final CreateCustomerCommand createCustomerCommand) { final Customer customer = createCustomerCommand.customer(); final CustomerEntity customerEntity = CustomerMapper.map(customer); - customerEntity.setCurrentState(Customer.State.PENDING.name()); + if(StringUtils.isBlank(customerEntity.getCurrentState())) + customerEntity.setCurrentState(Customer.State.PENDING.name()); if(customer.getAddress() !=null) { final AddressEntity savedAddress = this.addressRepository.save(AddressMapper.map(customer.getAddress())); customerEntity.setAddress(savedAddress); 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 dfe8baa..0ac2aa5 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 @@ -69,6 +69,7 @@ import org.springframework.data.domain.Sort; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -152,13 +153,18 @@ ResponseEntity createCustomer(@RequestBody @Valid final Customer customer) produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE ) + @Transactional public @ResponseBody ResponseEntity 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()); + if(nonPerson.isActive()) { + customer.setCurrentState(Customer.State.ACTIVE.name()); + } else { + customer.setCurrentState(Customer.State.PENDING.name()); + } customer.setMember(false); if (this.customerService.customerExists(customer.getIdentifier())) { throw ServiceException.conflict("Customer {0} already exists.", customer.getIdentifier()); @@ -170,15 +176,12 @@ ResponseEntity createPerson(@RequestBody @Valid final NonPerson nonPerson) productInstance.setProductIdentifier(nonPerson.getProductIdentifier()); productInstance.setCustomerIdentifier(customer.getIdentifier()); productInstance.setAccountIdentifier(customer.getIdentifier()); + if(nonPerson.isActive()) { + productInstance.setState(Customer.State.ACTIVE.name()); + } //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(); } @@ -196,7 +199,11 @@ ResponseEntity createNonPerson(@RequestBody @Valid final NonPerson nonPers Customer customer = new Customer(); customer.setIdentifier(nonPerson.getAccountNumber()); customer.setType(Customer.Type.BUSINESS.name()); - customer.setCurrentState(Customer.State.PENDING.name()); + if(nonPerson.isActive()) { + customer.setCurrentState(Customer.State.ACTIVE.name()); + } else { + customer.setCurrentState(Customer.State.PENDING.name()); + } customer.setMember(false); if (this.customerService.customerExists(customer.getIdentifier())) { throw ServiceException.conflict("Customer {0} already exists.", customer.getIdentifier()); @@ -208,13 +215,12 @@ ResponseEntity createNonPerson(@RequestBody @Valid final NonPerson nonPers productInstance.setProductIdentifier(nonPerson.getProductIdentifier()); productInstance.setCustomerIdentifier(customer.getIdentifier()); productInstance.setAccountIdentifier(customer.getIdentifier()); + if(nonPerson.isActive()) { + productInstance.setState(Customer.State.ACTIVE.name()); + } //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(); }