public String modifyAccount()

in service/src/main/java/org/apache/fineract/cn/accounting/service/internal/command/handler/AccountCommandHandler.java [162:222]


  public String modifyAccount(final ModifyAccountCommand modifyAccountCommand) {
    final Account account = modifyAccountCommand.account();
    final AccountEntity accountEntity = this.accountRepository.findByIdentifier(account.getIdentifier());

    if (account.getName() != null) {
      accountEntity.setName(account.getName());
    }

    LedgerEntity ledger = null;
    if (!account.getLedger().equals(accountEntity.getLedger().getIdentifier())) {
      ledger = this.ledgerRepository.findByIdentifier(account.getLedger());
      accountEntity.setLedger(ledger);
    }

    AccountEntity referenceAccount = null;
    if (account.getReferenceAccount() != null) {
      if (!account.getReferenceAccount().equals(accountEntity.getReferenceAccount().getIdentifier())) {
        referenceAccount = this.accountRepository.findByIdentifier(account.getReferenceAccount());
        accountEntity.setReferenceAccount(referenceAccount);
      }
    } else {
      accountEntity.setReferenceAccount(null);
    }

    if (account.getHolders() != null) {
      accountEntity.setHolders(
              account.getHolders()
                      .stream()
                      .collect(Collectors.joining(","))
      );
    } else {
      accountEntity.setHolders(null);
    }

    if (account.getSignatureAuthorities() != null) {
      accountEntity.setSignatureAuthorities(
          account.getSignatureAuthorities()
              .stream()
              .collect(Collectors.joining(","))
      );
    } else {
      accountEntity.setSignatureAuthorities(null);
    }

    accountEntity.setLastModifiedBy(UserContextHolder.checkedGetUser());
    accountEntity.setLastModifiedOn(LocalDateTime.now(Clock.systemUTC()));

    this.accountRepository.save(accountEntity);

    if (referenceAccount != null) {
      referenceAccount.setLastModifiedBy(UserContextHolder.checkedGetUser());
      referenceAccount.setLastModifiedOn(LocalDateTime.now(Clock.systemUTC()));
      this.accountRepository.save(referenceAccount);
    }

    if (ledger != null) {
      this.ledgerRepository.save(ledger);
    }

    return account.getIdentifier();
  }