in service/src/main/java/org/apache/fineract/cn/accounting/service/rest/AccountRestController.java [227:265]
ResponseEntity<Void> accountCommand(@PathVariable("identifier") final String identifier,
@RequestBody @Valid final AccountCommand accountCommand) {
final Optional<Account> optionalAccount = this.accountService.findAccount(identifier);
if (optionalAccount.isPresent()) {
final Account account = optionalAccount.get();
final Account.State state = Account.State.valueOf(account.getState());
switch (AccountCommand.Action.valueOf(accountCommand.getAction())) {
case CLOSE:
if (account.getBalance() != 0.00D) {
throw ServiceException.conflict("Account {0} has remaining balance.", identifier);
}
if (state.equals(Account.State.OPEN) || state.equals(Account.State.LOCKED)) {
this.commandGateway.process(new CloseAccountCommand(identifier, accountCommand.getComment()));
}
break;
case LOCK:
if (state.equals(Account.State.OPEN)) {
this.commandGateway.process(new LockAccountCommand(identifier, accountCommand.getComment()));
}
break;
case UNLOCK:
if (state.equals(Account.State.LOCKED)) {
this.commandGateway.process(new UnlockAccountCommand(identifier, accountCommand.getComment()));
}
break;
case REOPEN:
if (state.equals(Account.State.CLOSED)) {
this.commandGateway.process(new ReopenAccountCommand(identifier, accountCommand.getComment()));
}
break;
default:
throw ServiceException.badRequest("Invalid state change.");
}
return ResponseEntity.accepted().build();
} else {
throw ServiceException.notFound("Account {0} not found.", identifier);
}
}