@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 createDepositAccount(final DepositAccountCommand command) { try { this.context.authenticatedUser(); DepositAccountCommandValidator validator = new DepositAccountCommandValidator(command); validator.validateForCreate(); final DepositAccount account = this.depositAccountAssembler.assembleFrom(command); this.depositAccountRepository.save(account); return new EntityIdentifier(account.getId()); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); return new EntityIdentifier(Long.valueOf(-1)); } }