@Transactional
  @Override
  public EntityIdentifier approveDepositApplication(
      final DepositStateTransitionApprovalCommand command) {

    // AppUser currentUser = context.authenticatedUser();

    DepositStateTransitionApprovalCommandValidator validator =
        new DepositStateTransitionApprovalCommandValidator(command);
    validator.validate();

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

    // FIXME - madhukar - you are checking for loan permission here instead
    // of some specific deposit account permission.
    // removing check for now until rules dealing with creating and
    // maintaining deposit accounts in the past is clarified
    LocalDate eventDate = command.getEventDate();
    // if (this.isBeforeToday(eventDate) &&
    // currentUser.canNotApproveLoanInPast()) {
    // throw new
    // NoAuthorizationException("User has no authority to approve deposit with a date in the
    // past.");
    // }

    account.approve(
        eventDate,
        defaultDepositLifecycleStateMachine(),
        command,
        this.fixedTermDepositInterestCalculator);

    this.depositAccountRepository.save(account);

    String noteText = command.getNote();
    if (StringUtils.isNotBlank(noteText)) {
      Note note = Note.depositNote(account, noteText);
      this.noteRepository.save(note);
    }

    return new EntityIdentifier(account.getId());
  }
  @Transactional
  @Override
  public EntityIdentifier withdrawDepositAccountMoney(
      final DepositAccountWithdrawalCommand command) {

    context.authenticatedUser();

    DepositAccountWithdrawalCommandValidator validator =
        new DepositAccountWithdrawalCommandValidator(command);
    validator.validate();

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

    LocalDate eventDate = command.getMaturesOnDate();

    Integer lockinPeriod = account.getLockinPeriod();
    LocalDate lockinPeriodExpDate =
        account.getActualCommencementDate().plusMonths(Integer.valueOf(lockinPeriod));
    if (account.isLockinPeriodAllowed()) {
      if (eventDate.isBefore(lockinPeriodExpDate)) {
        throw new DepositAccountTransactionsException(
            "deposit.transaction.canot.withdraw.before.lockinperiod.reached",
            "You can not withdraw your application before maturity date reached");
      }
    }
    // if (eventDate.isBefore(account.maturesOnDate())) {
    // this.depositAccountAssembler.adjustTotalAmountForPreclosureInterest(account,
    // eventDate);
    // }
    account.withdrawDepositAccountMoney(
        defaultDepositLifecycleStateMachine(), fixedTermDepositInterestCalculator, eventDate);
    this.depositAccountRepository.save(account);
    String noteText = command.getNote();
    if (StringUtils.isNotBlank(noteText)) {
      Note note = Note.depositNote(account, noteText);
      this.noteRepository.save(note);
    }

    return new EntityIdentifier(account.getId());
  }
  @Transactional
  @Override
  public EntityIdentifier undoDepositApproval(UndoStateTransitionCommand command) {

    context.authenticatedUser();

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

    account.undoDepositApproval(defaultDepositLifecycleStateMachine());
    this.depositAccountRepository.save(account);

    String noteText = command.getNote();
    if (StringUtils.isNotBlank(noteText)) {
      Note note = Note.depositNote(account, noteText);
      this.noteRepository.save(note);
    }
    return new EntityIdentifier(account.getId());
  }
  @Transactional
  @Override
  public EntityIdentifier withdrawDepositApplication(DepositStateTransitionCommand command) {

    // AppUser currentUser = context.authenticatedUser();

    DepositStateTransitionCommandValidator validator =
        new DepositStateTransitionCommandValidator(command);
    validator.validate();

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

    // removing check for now until rules dealing with creating and
    // maintaining deposit accounts in the past is clarified
    LocalDate eventDate = command.getEventDate();
    // if (this.isBeforeToday(eventDate) &&
    // currentUser.canNotApproveLoanInPast()) {
    // throw new
    // NoAuthorizationException("User has no authority to approve deposit with a date in the
    // past.");
    // }

    account.withdrawnByApplicant(eventDate, defaultDepositLifecycleStateMachine());
    this.depositAccountRepository.save(account);

    String noteText = command.getNote();
    if (StringUtils.isNotBlank(noteText)) {
      Note note = Note.depositNote(account, noteText);
      this.noteRepository.save(note);
    }

    return new EntityIdentifier(account.getId());
  }