in service/src/main/java/org/apache/fineract/cn/customer/rest/controller/CustomerRestController.java [290:332]
ResponseEntity<Void> customerCommand(@PathVariable("identifier") final String identifier,
@RequestBody final Command command) {
final Optional<Customer> customerOptional = this.customerService.findCustomer(identifier);
if (customerOptional.isPresent()) {
final Customer customer = customerOptional.get();
final Command.Action action = Command.Action.valueOf(command.getAction());
final String currentState = customer.getCurrentState();
switch (action) {
case ACTIVATE:
if (Customer.State.PENDING.name().equals(currentState)) {
this.commandGateway.process(new ActivateCustomerCommand(identifier, command.getComment()));
}
break;
case LOCK:
if (Customer.State.ACTIVE.name().equals(currentState)) {
this.commandGateway.process(new LockCustomerCommand(identifier, command.getComment()));
}
break;
case UNLOCK:
if (Customer.State.LOCKED.name().equals(currentState)) {
this.commandGateway.process(new UnlockCustomerCommand(identifier, command.getComment()));
}
break;
case CLOSE:
if (Customer.State.ACTIVE.name().equals(currentState)
|| Customer.State.LOCKED.name().equals(currentState)
|| Customer.State.PENDING.name().equals(currentState)) {
this.commandGateway.process(new CloseCustomerCommand(identifier, command.getComment()));
}
break;
case REOPEN:
if (Customer.State.CLOSED.name().equals(currentState)) {
this.commandGateway.process(new ReopenCustomerCommand(identifier, command.getComment()));
}
break;
default:
throw ServiceException.badRequest("Unsupported action {0}.", command.getAction());
}
} else {
throw ServiceException.notFound("Customer {0} not found.", identifier);
}
return ResponseEntity.accepted().build();
}