@Override
public CommandProcessingResult assignFieldOfficer(Long savingsAccountId, JsonCommand command) {
this.context.authenticatedUser();
final Map<String, Object> actualChanges = new LinkedHashMap<>(5);
Staff fromSavingsOfficer = null;
Staff toSavingsOfficer = null;
this.fromApiJsonDeserializer.validateForAssignSavingsOfficer(command.json());
final SavingsAccount savingsForUpdate = this.savingsRepository.findOneWithNotFoundDetection(savingsAccountId);
final Long fromSavingsOfficerId = command.longValueOfParameterNamed("fromSavingsOfficerId");
final Long toSavingsOfficerId = command.longValueOfParameterNamed("toSavingsOfficerId");
final LocalDate dateOfSavingsOfficerAssignment = command.localDateValueOfParameterNamed("assignmentDate");
if(fromSavingsOfficerId != null)
{
fromSavingsOfficer = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(fromSavingsOfficerId, savingsForUpdate.office().getHierarchy());
}
if(toSavingsOfficerId != null)
{
toSavingsOfficer = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(toSavingsOfficerId, savingsForUpdate.office().getHierarchy());
}
if (!savingsForUpdate.hasSavingsOfficer(fromSavingsOfficer)) { throw new SavingsOfficerAssignmentException(savingsAccountId, fromSavingsOfficerId); }
savingsForUpdate.reassignSavingsOfficer(toSavingsOfficer,dateOfSavingsOfficerAssignment);
this.savingsRepository.saveAndFlush(savingsForUpdate);
actualChanges.put("toSavingsOfficerId", toSavingsOfficer.getId());
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
.withOfficeId(savingsForUpdate.officeId()) //
.withEntityId(savingsForUpdate.getId()) //