if (!oldProfessorShipTeachersIds.contains(id)) { professorShipToWrite = new Professorship(); professorShipToWrite.setExecutionCourse(executionCourse);
if (!oldProfessorShipTeachersIds.contains(id)) {
    public Boolean run(List responsibleTeachersIds, List professorShipTeachersIds,            Integer executionCourseId) throws FenixServiceException, ExcepcaoPersistencia {        boolean result = true;        Integer id;        ISuportePersistente sp = PersistenceSupportFactory.getDefaultPersistenceSupport();        IPersistentProfessorship persistentProfessorship = sp.getIPersistentProfessorship();        IPersistentExecutionCourse persistentExecutionCourse = sp.getIPersistentExecutionCourse();        IExecutionCourse executionCourse = (IExecutionCourse) persistentExecutionCourse.readByOID(                ExecutionCourse.class, executionCourseId);        if (executionCourse == null) {            throw new NonExistingServiceException("message.nonExistingCurricularCourse", null);        }        // RESPONSIBLES MODIFICATIONS        // get the ids of the teachers that used to be responsible        List oldResponsibles = executionCourse.responsibleFors();        List oldResponsibleTeachersIds = new ArrayList();        if (oldResponsibles != null) {            Iterator iterator = oldResponsibles.iterator();            IProfessorship responsibleFor;            while (iterator.hasNext()) {                responsibleFor = (IProfessorship) iterator.next();                id = responsibleFor.getTeacher().getIdInternal();                oldResponsibleTeachersIds.add(id);            }            // remove old responsibles            Iterator oldRespIterator = oldResponsibleTeachersIds.iterator();            while (oldRespIterator.hasNext()) {                id = (Integer) oldRespIterator.next();                if (!responsibleTeachersIds.contains(id))                    ((IProfessorship) oldResponsibles.get(oldResponsibleTeachersIds.indexOf(id)))                            .setResponsibleFor(false);            }        }        // add new responsibles        Iterator newRespIterator = responsibleTeachersIds.iterator();        IProfessorship responsibleForToWrite;        ITeacher teacher;        while (newRespIterator.hasNext()) {            id = (Integer) newRespIterator.next();            if (!oldResponsibleTeachersIds.contains(id)) {                teacher = (ITeacher) sp.getIPersistentTeacher().readByOID(Teacher.class, id);                if (teacher == null)                    result = false;                else {                    responsibleForToWrite = persistentProfessorship.readByTeacherAndExecutionCourse(                            teacher.getIdInternal(), executionCourseId);                    persistentProfessorship.simpleLockWrite(responsibleForToWrite);                    responsibleForToWrite.setResponsibleFor(true);                }            }        }        // PROFESSORSHIPS MODIFICATIONS        // get the ids of the teachers that used to teach the course        IPersistentProfessorship persistentProfessorShip = sp.getIPersistentProfessorship();        List oldProfessorShips = persistentProfessorShip.readByExecutionCourse(executionCourse                .getIdInternal());        List oldProfessorShipTeachersIds = new ArrayList();        if (oldProfessorShips != null && !oldProfessorShips.isEmpty()) {            Iterator profsIterator = oldProfessorShips.iterator();            IProfessorship professorShip;            while (profsIterator.hasNext()) {                professorShip = (IProfessorship) profsIterator.next();                id = professorShip.getTeacher().getIdInternal();                oldProfessorShipTeachersIds.add(id);            }            // remove old professorShips            Iterator oldProfIterator = oldProfessorShipTeachersIds.iterator();            while (oldProfIterator.hasNext()) {                id = (Integer) oldProfIterator.next();                if (!professorShipTeachersIds.contains(id) && !responsibleTeachersIds.contains(id)) {                    IPersistentSummary persistentSummary = sp.getIPersistentSummary();                    IProfessorship professorship2 = persistentProfessorShip                            .readByTeacherAndExecutionCourse(id, executionCourseId);                    List summaryList = persistentSummary.readByTeacher(professorship2                            .getExecutionCourse().getIdInternal(), professorship2.getTeacher()                            .getTeacherNumber());                    if (summaryList != null && !summaryList.isEmpty()) {                        for (Iterator iterator = summaryList.iterator(); iterator.hasNext();) {                            ISummary summary = (ISummary) iterator.next();                            persistentSummary.simpleLockWrite(summary);                            summary.setProfessorship(null);                            summary.setKeyProfessorship(null);                        }                    }                    persistentProfessorShip.deleteByOID(Professorship.class,                            ((IProfessorship) oldProfessorShips.get(oldProfessorShipTeachersIds                                    .indexOf(id))).getIdInternal());                }            }        }        // add new professorShips        Iterator newProfIterator = professorShipTeachersIds.iterator();        IProfessorship professorShipToWrite;        while (newProfIterator.hasNext()) {            id = (Integer) newProfIterator.next();            if (!oldProfessorShipTeachersIds.contains(id)) {                professorShipToWrite = new Professorship();                professorShipToWrite.setExecutionCourse(executionCourse);                teacher = (ITeacher) sp.getIPersistentTeacher().readByOID(Teacher.class, id);                if (teacher == null)                    result = false;                else {                    persistentProfessorShip.simpleLockWrite(professorShipToWrite);                    professorShipToWrite.setTeacher(teacher);                }            }        }        return new Boolean(result);    }