ResponseEntity post()

in service/src/main/java/org/apache/fineract/cn/teller/service/rest/TellerManagementRestController.java [179:213]


  ResponseEntity<Void> post(@PathVariable("officeIdentifier") final String officeIdentifier,
                            @PathVariable("tellerCode") final String tellerCode,
                            @RequestBody @Valid final TellerManagementCommand tellerManagementCommand) {
    this.verifyOffice(officeIdentifier);
    final Teller teller = this.verifyTeller(tellerCode);

    final TellerManagementCommand.Action action = TellerManagementCommand.Action.valueOf(tellerManagementCommand.getAction());
    switch (action) {
      case OPEN:
        if (!teller.getState().equals(Teller.State.CLOSED.name())) {
          throw ServiceException.badRequest("Teller {0} is already active.", tellerCode);
        }
        this.verifyEmployee(tellerManagementCommand.getAssignedEmployeeIdentifier());
        this.commandGateway.process(new OpenTellerCommand(tellerCode, tellerManagementCommand));
        break;
      case CLOSE:
        if (teller.getState().equals(Teller.State.CLOSED.name())) {
          throw ServiceException.badRequest("Teller {0} is already closed.", tellerCode);
        }
        if (teller.getDenominationRequired()) {
          final LocalDateTime lastOpenedOn = DateConverter.fromIsoString(teller.getLastOpenedOn());
          if (this.tellerManagementService
              .fetchTellerDenominations(tellerCode, lastOpenedOn, LocalDateTime.now(Clock.systemUTC()))
              .isEmpty()) {
            throw ServiceException.conflict("Denomination for teller {0} required.", tellerCode);
          }
        }
        this.commandGateway.process(new CloseTellerCommand(tellerCode, tellerManagementCommand));
        break;
      default:
        throw ServiceException.badRequest("Unsupported teller command {0}.", action.name());
    }

    return ResponseEntity.accepted().build();
  }