if (shiftIdsToEnroll != null && !shiftIdsToEnroll.isEmpty()) { IStudent student = (IStudent) persistentStudent.readByOID(Student.class, studentId); if (student == null) { throw new StudentNotFoundServiceException();
final ISuportePersistente sp = PersistenceSupportFactory.getDefaultPersistenceSupport(); final IPersistentStudent persistentStudent = sp.getIPersistentStudent(); final ITurnoPersistente persistentShift = sp.getITurnoPersistente(); final IPersistentExecutionPeriod persistentExecutionPeriod = sp.getIPersistentExecutionPeriod();  final ShiftEnrollmentErrorReport errorReport = new ShiftEnrollmentErrorReport();  final IStudent student = (IStudent) persistentStudent.readByOID(Student.class, studentId); if (student == null) { throw new StudentNotFoundServiceException(); }  if (student.getPayedTuition() == null || student.getPayedTuition().equals(Boolean.FALSE)) { throw new FenixServiceException("error.exception.notAuthorized.student.warningTuition"); }  final IExecutionPeriod executionPeriod = persistentExecutionPeriod.readActualExecutionPeriod();  final IShift shift = (IShift) persistentShift.readByOID(Shift.class, shiftId); if (shift == null) { errorReport.getUnExistingShifts().add(shiftId); }  final IShift shiftFromStudent = findShiftOfSameTypeForSameExecutionCourse(student, shift); if (shift != shiftFromStudent) {  if (reserveShiftForStudent(student, shift)) { if (shiftFromStudent != null) { shiftFromStudent.removeStudents(student);
    public ShiftEnrollmentErrorReport run(Integer studentId, List shiftIdsToEnroll)            throws StudentNotFoundServiceException, FenixServiceException {        try {            ISuportePersistente sp = PersistenceSupportFactory.getDefaultPersistenceSupport();            IPersistentStudent persistentStudent = sp.getIPersistentStudent();            ITurnoPersistente persistentShift = sp.getITurnoPersistente();            IPersistentExecutionPeriod persistentExecutionPeriod = sp.getIPersistentExecutionPeriod();            ShiftEnrollmentErrorReport errorReport = new ShiftEnrollmentErrorReport();            if (shiftIdsToEnroll != null && !shiftIdsToEnroll.isEmpty()) {                IStudent student = (IStudent) persistentStudent.readByOID(Student.class, studentId);                if (student == null) {                    throw new StudentNotFoundServiceException();                }                if (student.getPayedTuition() == null || student.getPayedTuition().equals(Boolean.FALSE)) {                    throw new FenixServiceException(                            "error.exception.notAuthorized.student.warningTuition");                }                persistentStudent.simpleLockWrite(student);                IExecutionPeriod executionPeriod = persistentExecutionPeriod.readActualExecutionPeriod();                List<IShift> shifts = student.getShifts();                List shiftEnrollments = new ArrayList();                for (IShift shift : shifts) {                    if (shift.getDisciplinaExecucao().getExecutionPeriod().getIdInternal().equals(                            executionPeriod.getIdInternal()))                        shiftEnrollments.add(shift);                }                List shiftsToUnEnroll = new ArrayList();                List filteredShiftsIdsToEnroll = new ArrayList();                filteredShiftsIdsToEnroll = calculateShiftsToEnroll(shiftIdsToEnroll, shiftEnrollments);                shiftsToUnEnroll = enrollStudentsInShiftsAndCalculateShiftsToUnEnroll(student,                        filteredShiftsIdsToEnroll, errorReport, persistentShift);                unEnrollStudentsInShifts(shiftsToUnEnroll, student);            }            return errorReport;        } catch (ExcepcaoPersistencia e) {            e.printStackTrace();            throw new FenixServiceException(e);        }    }