Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Boolean isActive() {
return isActive == null ? false: isActive;
}

public void setActive(Boolean active) {
public void setIsActive(Boolean active) {
isActive = active;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -152,13 +153,18 @@ ResponseEntity<Void> createCustomer(@RequestBody @Valid final Customer customer)
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
@Transactional
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());
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());
Expand All @@ -170,15 +176,12 @@ ResponseEntity<Void> 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();
}

Expand All @@ -196,7 +199,11 @@ ResponseEntity<Void> 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());
Expand All @@ -208,13 +215,12 @@ ResponseEntity<Void> 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();
}

Expand Down