@Override
  public EntityIdentifier updateDepositAccount(DepositAccountCommand command) {

    try {
      this.context.authenticatedUser();

      DepositAccountCommandValidator validator = new DepositAccountCommandValidator(command);
      validator.validateForUpdate();

      final DepositAccount account = this.depositAccountRepository.findOne(command.getId());
      if (account == null || account.isDeleted()) {
        throw new DepositAccountNotFoundException(command.getId());
      }

      if (account.isSubmittedAndPendingApproval()) {
        this.depositAccountAssembler.assembleUpdatedDepositAccount(account, command);
      } else if (account.isActive()) {
        this.depositAccountAssembler.updateApprovedDepositAccount(account, command);
      }

      this.depositAccountRepository.save(account);

      return new EntityIdentifier(account.getId());
    } catch (DataIntegrityViolationException dve) {
      handleDataIntegrityIssues(command, dve);
      return new EntityIdentifier(Long.valueOf(-1));
    }
  }
  @Transactional
  @Override
  public EntityIdentifier renewDepositAccount(DepositAccountCommand command) {

    this.context.authenticatedUser();

    RenewDepositAccountCommandValidator validator =
        new RenewDepositAccountCommandValidator(command);
    validator.validateForCreate();

    DepositAccount account = this.depositAccountRepository.findOne(command.getId());
    if (account == null || account.isDeleted()) {
      throw new DepositAccountNotFoundException(command.getId());
    }

    // FIXME - KW - extract whats in this if into a method that naturally
    // describes what you are checking.
    if (account.isRenewalAllowed()
        && (new LocalDate().isAfter(account.maturesOnDate())
            || new LocalDate().isEqual(account.maturesOnDate()))) {

      if (account.isActive()) {
        final DepositAccount renewedAccount =
            this.depositAccountAssembler.assembleFrom(account, command);
        this.depositAccountRepository.save(renewedAccount);
        account.closeDepositAccount(defaultDepositLifecycleStateMachine());
        this.depositAccountRepository.save(account);
        return new EntityIdentifier(renewedAccount.getId());
      }

      throw new DepositAccountReopenException(account.getMaturityDate());
    }

    throw new DepositAccountReopenException(account.getMaturityDate());
  }