final List<String> auxProfessorshipTeacherIDs = new ArrayList<String>(professorShipTeachersIds);
final List<Professorship> professorships = new ArrayList<Professorship>(executionCourse.getProfessorshipsSet());
for (Professorship professorship : professorships) {
final Teacher teacher = professorship.getTeacher();
final String teacherID = teacher.getExternalId();
if (auxProfessorshipTeacherIDs.contains(teacherID)) {
if (responsibleTeachersIds.contains(teacherID) && !professorship.getResponsibleFor()) {
professorship.setResponsibleFor(Boolean.TRUE);
} else if (!responsibleTeachersIds.contains(teacherID) && professorship.getResponsibleFor()) {
professorship.setResponsibleFor(Boolean.FALSE);
}
auxProfessorshipTeacherIDs.remove(teacherID);
} else {
professorship.delete();
}
}
for (final String teacherID : auxProfessorshipTeacherIDs) {
final Teacher teacher = FenixFramework.getDomainObject(teacherID);
final Boolean isResponsible = Boolean.valueOf(responsibleTeachersIds.contains(teacherID));
Professorship.create(isResponsible, executionCourse, teacher, null);
}
return Boolean.TRUE;