public String process()

in service/src/main/java/org/apache/fineract/cn/cheque/service/internal/command/handler/ChequeAggregate.java [91:130]


  public String process(final IssueChequesCommand issueChequesCommand) {

    final Optional<IssuedChequeEntity> optionalIssuedCheque =
        this.issuedChequeRepository.findByAccountIdentifier(issueChequesCommand.accountIdentifer());

    final IssuedChequeEntity issuedChequeEntity = optionalIssuedCheque.orElseGet(() -> {
      final IssuedChequeEntity toCreate = new IssuedChequeEntity();
      toCreate.setAccountIdentifier(issueChequesCommand.accountIdentifer());
      toCreate.setCreatedBy(UserContextHolder.checkedGetUser());
      toCreate.setCreatedOn(LocalDateTime.now(Clock.systemUTC()));
      return toCreate;
    });

    final Integer lastIssuedNumber;
    if (issuedChequeEntity.getLastIssuedNumber() == null) {
      lastIssuedNumber = issueChequesCommand.startSequence() != null
          ? (issueChequesCommand.startSequence() - 1) + issueChequesCommand.issueCount()
          : issueChequesCommand.issueCount();
    } else {
      lastIssuedNumber = issuedChequeEntity.getLastIssuedNumber() + issueChequesCommand.issueCount();
    }

    issuedChequeEntity.setLastIssuedNumber(lastIssuedNumber);
    issuedChequeEntity.setLastModifiedBy(UserContextHolder.checkedGetUser());
    issuedChequeEntity.setLastModifiedOn(LocalDateTime.now(Clock.systemUTC()));

    this.issuedChequeRepository.save(issuedChequeEntity);

    try {
      final List<Charge> issueChequeCharges =
          this.depositService.getIssueChequeCharges(issueChequesCommand.accountIdentifer());
      if (!issueChequeCharges.isEmpty()) {
        this.accountingService.bookCharges(issueChequesCommand.accountIdentifer(), issueChequeCharges);
      }
    } catch (final ProductInstanceNotFoundException | AccountNotFoundException ex) {
      throw ServiceException.notFound("Account {0} not found", issueChequesCommand.accountIdentifer());
    }

    return issueChequesCommand.accountIdentifer();
  }