studentsTestQuestionList = StudentTestQuestion.findStudentTestQuestions(oldQuestion, distributedTest);
studentsTestQuestionList = StudentTestQuestion.findStudentTestQuestions(oldQuestion, currentDistributedTest);
    public List<InfoSiteDistributedTestAdvisory> run(Integer executionCourseId,            Integer distributedTestId, Integer oldQuestionId, Integer newMetadataId, Integer studentId,            TestQuestionChangesType changesType, Boolean delete,            TestQuestionStudentsChangesType studentsType, String path) throws FenixServiceException,            ExcepcaoPersistencia {        List<InfoSiteDistributedTestAdvisory> infoSiteDistributedTestAdvisoryList = new ArrayList<InfoSiteDistributedTestAdvisory>();        Question oldQuestion = rootDomainObject.readQuestionByOID(oldQuestionId);        if (oldQuestion == null)            throw new InvalidArgumentsServiceException();        Metadata metadata = null;        List<Question> availableQuestions = new ArrayList<Question>();        if (newMetadataId != null) {            metadata = rootDomainObject.readMetadataByOID(newMetadataId);            if (metadata == null)                throw new InvalidArgumentsServiceException();            availableQuestions.addAll(metadata.getVisibleQuestions());        } else {            availableQuestions.addAll(oldQuestion.getMetadata().getVisibleQuestions());            availableQuestions.remove(oldQuestion);        }        final Set<DistributedTest> distributedTestList;        if (studentsType.getType().intValue() == TestQuestionStudentsChangesType.ALL_STUDENTS)            distributedTestList = oldQuestion.findDistributedTests();        else {            distributedTestList = new HashSet<DistributedTest>();            DistributedTest distributedTest = rootDomainObject                    .readDistributedTestByOID(distributedTestId);            if (distributedTest == null)                throw new InvalidArgumentsServiceException();            distributedTestList.add(distributedTest);        }        boolean canDelete = true;        for (DistributedTest distributedTest : distributedTestList) {            Collection<StudentTestQuestion> studentsTestQuestionList = new ArrayList<StudentTestQuestion>();            InfoSiteDistributedTestAdvisory infoSiteDistributedTestAdvisory = new InfoSiteDistributedTestAdvisory();            infoSiteDistributedTestAdvisory.setInfoDistributedTest(InfoDistributedTest                    .newInfoFromDomain(distributedTest));            infoSiteDistributedTestAdvisory.setInfoAdvisory(InfoAdvisory.newInfoFromDomain(getAdvisory(                    distributedTest, path.replace('\\', '/'))));            if (studentsType.getType().intValue() == TestQuestionStudentsChangesType.THIS_STUDENT) {                Student student = rootDomainObject.readStudentByOID(studentId);                if (student == null)                    throw new InvalidArgumentsServiceException();            	studentsTestQuestionList.add(StudentTestQuestion.findStudentTestQuestion(oldQuestion, student, distributedTest));            } else if (studentsType.getType().intValue() == TestQuestionStudentsChangesType.STUDENTS_FROM_TEST) {                Student student = rootDomainObject.readStudentByOID(studentId);                if (student == null)                    throw new InvalidArgumentsServiceException();                Integer order = StudentTestQuestion.findStudentTestQuestion(oldQuestion, student, distributedTest).getTestQuestionOrder();                studentsTestQuestionList = distributedTest.findStudentTestQuestionsByTestQuestionOrder(order);            } else                studentsTestQuestionList = StudentTestQuestion.findStudentTestQuestions(oldQuestion, distributedTest);            List<InfoStudent> group = new ArrayList<InfoStudent>();            for (StudentTestQuestion studentTestQuestion : studentsTestQuestionList) {                if (!compareDates(studentTestQuestion.getDistributedTest().getEndDate(),                        studentTestQuestion.getDistributedTest().getEndHour())) {                    canDelete = false;                } else {                    if (availableQuestions.size() == 0)                        availableQuestions.addAll(getNewQuestionList(metadata, oldQuestion));                    Question newQuestion = getNewQuestion(availableQuestions);                    if (newMetadataId == null                            && (newQuestion == null || newQuestion.equals(oldQuestion)))                        return null;                    else if (newQuestion == null)                        throw new InvalidArgumentsServiceException();                    studentTestQuestion.setQuestion(newQuestion);                    studentTestQuestion.setResponse(null);                    studentTestQuestion.setOptionShuffle(null);                    availableQuestions.remove(newQuestion);                    double oldMark = studentTestQuestion.getTestQuestionMark().doubleValue();                    studentTestQuestion.setTestQuestionMark(new Double(0));                    if (!group.contains(studentTestQuestion.getStudent().getPerson()))                        group.add(InfoStudent.newInfoFromDomain(studentTestQuestion.getStudent()));                    if (studentTestQuestion.getDistributedTest().getTestType().equals(                            new TestType(TestType.EVALUATION))) {                        OnlineTest onlineTest = studentTestQuestion.getDistributedTest().getOnlineTest();                        Attends attend = studentTestQuestion.getStudent().readAttendByExecutionCourse(                                ((ExecutionCourse) distributedTest.getTestScope().getDomainObject()));                        Mark mark = onlineTest.getMarkByAttend(attend);                        if (mark != null) {                            mark.setMark(getNewStudentMark(studentTestQuestion.getDistributedTest(),                                    studentTestQuestion.getStudent(), oldMark));                        }                    }                    StudentTestLog studentTestLog = DomainFactory.makeStudentTestLog();                    studentTestLog.setDistributedTest(studentTestQuestion.getDistributedTest());                    studentTestLog.setStudent(studentTestQuestion.getStudent());                    studentTestLog.setDate(Calendar.getInstance().getTime());                    ResourceBundle bundle = ResourceBundle.getBundle("resources.ApplicationResources");                    studentTestLog.setEvent(MessageFormat.format(bundle                            .getString("message.changeStudentQuestionLogMessage"),                            new Object[] { studentTestQuestion.getTestQuestionOrder() }));                }            }            infoSiteDistributedTestAdvisory.setInfoStudentList(group);            infoSiteDistributedTestAdvisoryList.add(infoSiteDistributedTestAdvisory);        }        if (delete.booleanValue()) {            metadata = oldQuestion.getMetadata();            if (metadata == null)                throw new InvalidArgumentsServiceException();            removeOldTestQuestion(oldQuestion);            List metadataQuestions = metadata.getVisibleQuestions();            if (metadataQuestions != null && metadataQuestions.size() <= 1)                metadata.setVisibility(Boolean.FALSE);            if (canDelete) {                oldQuestion.delete();                if (metadata.getQuestionsCount() <= 1) {                    metadata.delete();                }            } else {                oldQuestion.setVisibility(Boolean.FALSE);            }        }        return infoSiteDistributedTestAdvisoryList;    }