@Transactional @Override public EntityIdentifier applicantWithdrawsFromLoanApplication( final Long loanId, final JsonCommand command) { final AppUser currentUser = context.authenticatedUser(); final LoanStateTransitionCommand applicantWithdrawsFromLoanApplication = this.loanStateTransitionCommandFromApiJsonDeserializer.commandFromApiJson(command.json()); applicantWithdrawsFromLoanApplication.validate(); final Loan loan = retrieveLoanBy(loanId); final LocalDate eventDate = applicantWithdrawsFromLoanApplication.getWithdrawnOnDate(); if (this.isBeforeToday(eventDate) && currentUser.canNotWithdrawByClientLoanInPast()) { throw new NoAuthorizationException( "User has no authority to mark loan as withdrawn by applicant with a date in the past."); } final Map<String, Object> changes = loan.loanApplicationWithdrawnByApplicant(command, defaultLoanLifecycleStateMachine()); this.loanRepository.save(loan); String noteText = command.stringValueOfParameterNamed("note"); if (StringUtils.isNotBlank(noteText)) { Note note = Note.loanNote(loan, noteText); this.noteRepository.save(note); } return EntityIdentifier.resourceResult(loanId, command.commandId(), changes); }