mark.setPublishedMark(mark.getMark());
    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>();        ISuportePersistente persistentSuport = PersistenceSupportFactory.getDefaultPersistenceSupport();        Question oldQuestion = (Question) persistentSuport.getIPersistentQuestion().readByOID(Question.class, oldQuestionId);        if (oldQuestion == null)            throw new InvalidArgumentsServiceException();        IPersistentMetadata persistentMetadata = persistentSuport.getIPersistentMetadata();        Metadata metadata = null;        List<Question> availableQuestions = new ArrayList<Question>();        if (newMetadataId != null) {            metadata = (Metadata) persistentMetadata.readByOID(Metadata.class, newMetadataId);            if (metadata == null)                throw new InvalidArgumentsServiceException();            availableQuestions.addAll(metadata.getVisibleQuestions());        } else {            availableQuestions.addAll(oldQuestion.getMetadata().getVisibleQuestions());            availableQuestions.remove(oldQuestion);        }        IPersistentStudentTestQuestion persistentStudentTestQuestion = persistentSuport.getIPersistentStudentTestQuestion();        List<DistributedTest> distributedTestList = new ArrayList<DistributedTest>();        if (studentsType.getType().intValue() == TestQuestionStudentsChangesType.ALL_STUDENTS)            distributedTestList = persistentStudentTestQuestion.readDistributedTestsByTestQuestion(oldQuestion.getIdInternal());        else {            DistributedTest distributedTest = (DistributedTest) persistentSuport.getIPersistentDistributedTest().readByOID(DistributedTest.class,                    distributedTestId);            if (distributedTest == null)                throw new InvalidArgumentsServiceException();            distributedTestList.add(distributedTest);        }        boolean canDelete = true;        for (DistributedTest distributedTest : distributedTestList) {            List<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 = (Student) persistentSuport.getIPersistentStudent().readByOID(Student.class, studentId);                if (student == null)                    throw new InvalidArgumentsServiceException();                studentsTestQuestionList.add(persistentStudentTestQuestion.readByQuestionAndStudentAndDistributedTest(oldQuestion.getIdInternal(),                        student.getIdInternal(), distributedTest.getIdInternal()));            } else if (studentsType.getType().intValue() == TestQuestionStudentsChangesType.STUDENTS_FROM_TEST) {                Student student = (Student) persistentSuport.getIPersistentStudent().readByOID(Student.class, studentId);                if (student == null)                    throw new InvalidArgumentsServiceException();                Integer order = persistentStudentTestQuestion.readByQuestionAndStudentAndDistributedTest(oldQuestion.getIdInternal(),                        student.getIdInternal(), distributedTest.getIdInternal()).getTestQuestionOrder();                studentsTestQuestionList = persistentStudentTestQuestion.readByOrderAndDistributedTest(order, distributedTest.getIdInternal());            } else                studentsTestQuestionList = persistentStudentTestQuestion.readByQuestionAndDistributedTest(oldQuestion.getIdInternal(),                        distributedTest.getIdInternal());            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 = (OnlineTest) persistentSuport.getIPersistentOnlineTest().readByDistributedTest(                                studentTestQuestion.getDistributedTest().getIdInternal());                        Attends attend = persistentSuport.getIFrequentaPersistente().readByAlunoAndDisciplinaExecucao(                                studentTestQuestion.getStudent().getIdInternal(),                                ((ExecutionCourse) distributedTest.getTestScope().getDomainObject()).getIdInternal());                        Mark mark = persistentSuport.getIPersistentMark().readBy(onlineTest, attend);                        if (mark != null) {                            mark.setMark(getNewStudentMark(persistentSuport, studentTestQuestion.getDistributedTest(), studentTestQuestion                                    .getStudent(), oldMark));                            mark.setPublishedMark(mark.getMark());                        }                    }                    StudentTestLog studentTestLog = DomainFactory.makeStudentTestLog();                    studentTestLog.setDistributedTest(studentTestQuestion.getDistributedTest());                    studentTestLog.setStudent(studentTestQuestion.getStudent());                    studentTestLog.setDate(Calendar.getInstance().getTime());                    ResourceBundle bundle = ResourceBundle.getBundle("ServidorApresentacao.ApplicationResources");                    studentTestLog.setEvent(MessageFormat.format(bundle.getString("message.changeStudentQuestionLogMessage"),                            new Object[] { studentTestQuestion.getTestQuestionOrder() }));                }            }            infoSiteDistributedTestAdvisory.setInfoStudentList(group);            infoSiteDistributedTestAdvisoryList.add(infoSiteDistributedTestAdvisory);        }        if (delete.booleanValue()) {            metadata = (Metadata) persistentMetadata.readByOID(Metadata.class, oldQuestion.getKeyMetadata());            if (metadata == null)                throw new InvalidArgumentsServiceException();            removeOldTestQuestion(persistentSuport, oldQuestion);            List metadataQuestions = metadata.getVisibleQuestions();            if (metadataQuestions != null && metadataQuestions.size() <= 1)                metadata.setVisibility(new Boolean(false));            if (canDelete) {                int metadataNumberOfQuestions = persistentMetadata.getNumberOfQuestions(metadata);                oldQuestion.delete();                if (metadataNumberOfQuestions <= 1) {                    metadata.removeExecutionCourse();                    persistentMetadata.deleteByOID(Metadata.class, metadata.getIdInternal());                }            } else {                oldQuestion.setVisibility(new Boolean(false));            }        }        return infoSiteDistributedTestAdvisoryList;    }