in service/src/main/java/org/apache/fineract/cn/office/internal/command/handler/EmployeeAggregate.java [116:150]
public String updateEmployee(final UpdateEmployeeCommand updateEmployeeCommand) {
final Employee employee = updateEmployeeCommand.employee();
final EmployeeEntity employeeEntity = this.employeeRepository.findByIdentifier(employee.getIdentifier());
if (employee.getGivenName() != null) {
employeeEntity.setGivenName(employee.getGivenName());
}
if (employee.getMiddleName() != null) {
employeeEntity.setMiddleName(employee.getMiddleName());
}
if (employee.getSurname() != null) {
employeeEntity.setSurname(employee.getSurname());
}
final OfficeEntity assignedOffice = employeeEntity.getAssignedOffice();
final String currentIdentifier = assignedOffice != null ? assignedOffice.getIdentifier() : null;
if (!Objects.equals(employee.getAssignedOffice(), currentIdentifier)) {
final Optional<OfficeEntity> officeEntity = this.officeRepository.findByIdentifier(employee.getAssignedOffice());
if (officeEntity.isPresent()) {
employeeEntity.setAssignedOffice(officeEntity.get());
} else {
throw ServiceException.notFound("Assigned office {0} not found.", employee.getAssignedOffice());
}
}
employeeEntity.setLastModifiedBy(UserContextHolder.checkedGetUser());
employeeEntity.setLastModifiedOn(Utils.utcNow());
this.employeeRepository.save(employeeEntity);
return updateEmployeeCommand.employee().getIdentifier();
}