ResponseEntity createPerson()

in service/src/main/java/org/apache/fineract/cn/customer/rest/controller/CustomerRestController.java [157:183]


  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();
  }