List students = exam.getStudentsEnrolled(); if (students == null) {
List examStudentRoomList = persistentExamStudentRoom.readBy(exam); Iterator iterExamStudentRoomList = examStudentRoomList.iterator(); List students = new ArrayList(); while(iterExamStudentRoomList.hasNext()){ students.add(((IExamStudentRoom)iterExamStudentRoomList.next()).getStudent()); }  if (students.isEmpty()) {
	public Boolean run(Integer executionCourseCode, Integer examCode, List roomsIds, Boolean sms)		throws FenixServiceException {		Boolean result = new Boolean(false);		try {			ISuportePersistente sp = SuportePersistenteOJB.getInstance();			IPersistentExam persistentExam = sp.getIPersistentExam();			ISalaPersistente persistentRoom = sp.getISalaPersistente();			IFrequentaPersistente persistentAttends =				sp.getIFrequentaPersistente();			IPersistentExamStudentRoom persistentExamStudentRoom =				sp.getIPersistentExamStudentRoom();			IExam exam =				(IExam) persistentExam.readByOId(new Exam(examCode), false);			if (exam == null) {				throw new InvalidArgumentsServiceException("exam");			}					Calendar endEnrollmentDay = exam.getEnrollmentEndDay();			if (endEnrollmentDay == null) {				throw new FenixServiceException(ExamRoomDistribution.NON_DEFINED_ENROLLMENT_PERIOD);			}									Calendar endHourDay = exam.getEnrollmentEndTime();						endEnrollmentDay.set(Calendar.HOUR_OF_DAY, 0);			endEnrollmentDay.set(Calendar.MINUTE, 0);			endEnrollmentDay.roll(Calendar.HOUR_OF_DAY, endHourDay.get(Calendar.HOUR_OF_DAY));			endEnrollmentDay.roll(Calendar.MINUTE, endHourDay.get(Calendar.MINUTE));						Calendar examDay = exam.getDay();			Calendar today = Calendar.getInstance();						if ( today.after(examDay) || today.before(endEnrollmentDay) ) {				throw new FenixServiceException(ExamRoomDistribution.OUT_OF_ENROLLMENT_PERIOD);					}			List students = exam.getStudentsEnrolled();			if (students == null) {				List executionCourses = exam.getAssociatedExecutionCourses();				Iterator iterCourse = executionCourses.iterator();				while (iterCourse.hasNext()) {					students.addAll(						persistentAttends.readByExecutionCourse(							(IDisciplinaExecucao) iterCourse.next()));				}			}			Iterator iterRoom = roomsIds.iterator();			List rooms = new ArrayList();			while (iterRoom.hasNext()) {				ISala room =					(ISala) persistentRoom.readByOId(						new Sala((Integer) iterRoom.next()),						true);				if (room == null) {					throw new InvalidArgumentsServiceException("room");				}				rooms.add(room);			}			if (!exam.getAssociatedRooms().containsAll(rooms)) {				throw new InvalidArgumentsServiceException("rooms");			}			Iterator iter = rooms.iterator();			while (iter.hasNext()) {				ISala room = (ISala) iter.next();				int i = 0;				while (i <= room.getCapacidadeExame().intValue()) {					if (students.size() > 0) {						IStudent student =							(IStudent) getRandomObjectFromList(students);						IExamStudentRoom examStudentRoom =							persistentExamStudentRoom.readBy(exam, student);						if (examStudentRoom == null) {							examStudentRoom =								new ExamStudentRoom();							persistentExamStudentRoom.simpleLockWrite(examStudentRoom);							examStudentRoom.setExam(exam);							examStudentRoom.setRoom(room);							examStudentRoom.setStudent(student);						} else {							persistentExamStudentRoom.lockWrite(examStudentRoom);							examStudentRoom.setRoom(room);						}											if (sms.booleanValue()) {							sendSMSToStudent(examStudentRoom);						}					}else {						break;					}					i++;				}			}			if (students.size() > 0) {				throw new InvalidArgumentsServiceException("students");			}		} catch (ExcepcaoPersistencia e) {			throw new FenixServiceException(e);		}		return result;	}