CaseStudy caseStudy1 = case1Id.intValue() == -1 ? null : rootDomainObject.readCaseStudyByOID(case1Id); CaseStudy caseStudy2 = case2Id.intValue() == -1 ? null : rootDomainObject.readCaseStudyByOID(case2Id); CaseStudy caseStudy3 = case3Id.intValue() == -1 ? null : rootDomainObject.readCaseStudyByOID(case3Id); CaseStudy caseStudy4 = case4Id.intValue() == -1 ? null : rootDomainObject.readCaseStudyByOID(case4Id); CaseStudy caseStudy5 = case5Id.intValue() == -1 ? null : rootDomainObject.readCaseStudyByOID(case5Id);  List<SeminaryCandidacy> filteredCandidacies = new ArrayList<SeminaryCandidacy>();  outter: for (SeminaryCandidacy candidacy : SeminaryCandidacy.getAllCandidacies()) { if (modality != null && !candidacy.getModality().equals(modality)) { continue; }  if (seminary != null && !candidacy.getSeminary().equals(seminary)) { continue; }  if (curricularCourseID != null && !candidacy.getCurricularCourse().equals(curricularCourse)) { continue; }   if (theme != null) { if (!candidacy.getTheme().equals(theme) && !(candidacy.getModality().getIdInternal().intValue() == 1)) { continue; } }  if (approved != null && !candidacy.getApproved().equals(approved)) { continue; }  if (degreeCurricularPlan != null && !degreeCurricularPlan.getCurricularCourses().contains(candidacy.getCurricularCourse())) { continue; }  CaseStudy choices[] = { caseStudy1, caseStudy2, caseStudy3, caseStudy4, caseStudy5 }; for (int i = 0; i < choices.length; i++) { CaseStudy caseStudy = choices[i];
Modality modality = modalityID.intValue() == -1 ? null : rootDomainObject .readModalityByOID(modalityID); Seminary seminary = seminaryID.intValue() == -1 ? null : rootDomainObject .readSeminaryByOID(seminaryID); Theme theme = themeID.intValue() == -1 ? null : rootDomainObject.readThemeByOID(themeID);
	public List run(Integer modalityID, Integer seminaryID, Integer themeID, Integer case1Id,			Integer case2Id, Integer case3Id, Integer case4Id, Integer case5Id,			Integer curricularCourseID, Integer degreeCurricularPlanID, Boolean approved) throws BDException, ExcepcaoPersistencia {                // IDs == -1 => not selected        // approved == nulll => not selected        //        // case[1-5]Id => case study ids in the desired order                Modality modality = modalityID.intValue() == -1 ? null : rootDomainObject.readModalityByOID(modalityID);        Seminary seminary = seminaryID.intValue() == -1 ? null : rootDomainObject.readSeminaryByOID(seminaryID);        Theme theme       = themeID.intValue() == -1 ? null : rootDomainObject.readThemeByOID(themeID);                DegreeCurricularPlan degreeCurricularPlan = degreeCurricularPlanID.intValue() == -1 ? null : rootDomainObject.readDegreeCurricularPlanByOID(degreeCurricularPlanID);        CurricularCourse curricularCourse = curricularCourseID.intValue() == -1 ? null : (CurricularCourse) rootDomainObject.readDegreeModuleByOID(curricularCourseID);        CaseStudy caseStudy1 = case1Id.intValue() == -1 ? null : rootDomainObject.readCaseStudyByOID(case1Id);        CaseStudy caseStudy2 = case2Id.intValue() == -1 ? null : rootDomainObject.readCaseStudyByOID(case2Id);        CaseStudy caseStudy3 = case3Id.intValue() == -1 ? null : rootDomainObject.readCaseStudyByOID(case3Id);        CaseStudy caseStudy4 = case4Id.intValue() == -1 ? null : rootDomainObject.readCaseStudyByOID(case4Id);        CaseStudy caseStudy5 = case5Id.intValue() == -1 ? null : rootDomainObject.readCaseStudyByOID(case5Id);                List<SeminaryCandidacy> filteredCandidacies = new ArrayList<SeminaryCandidacy>();                outter:         for (SeminaryCandidacy candidacy : SeminaryCandidacy.getAllCandidacies()) {            if (modality != null && !candidacy.getModality().equals(modality)) {                continue;            }                        if (seminary != null && !candidacy.getSeminary().equals(seminary)) {                continue;            }                        if (curricularCourseID != null && !candidacy.getCurricularCourse().equals(curricularCourse)) {                continue;            }                        // TODO: converte Modality into a enumeration            if (theme != null) {                if (!candidacy.getTheme().equals(theme) && !(candidacy.getModality().getIdInternal().intValue() == 1)) {                    continue;                }            }                        if (approved != null && !candidacy.getApproved().equals(approved)) {                continue;            }                        if (degreeCurricularPlan != null && !degreeCurricularPlan.getCurricularCourses().contains(candidacy.getCurricularCourse())) {                continue;            }                     CaseStudy choices[] = { caseStudy1, caseStudy2, caseStudy3, caseStudy4, caseStudy5 };            for (int i = 0; i < choices.length; i++) {                CaseStudy caseStudy = choices[i];                if (caseStudy == null) {                    continue;                }                                for (CaseStudyChoice choice : candidacy.getCaseStudyChoices()) {                    if (choice.getOrder() != null) {                        if (choice.getOrder() == i && !choice.getCaseStudy().equals(caseStudy)) {                            continue outter; // the case study in that order is not what the user requested                        }                    }                }            }                        filteredCandidacies.add(candidacy);        }                List infoCandidacies = new LinkedList();                for (SeminaryCandidacy candidacy : filteredCandidacies) {			Registration registration = candidacy.getStudent();			StudentCurricularPlan studentCurricularPlan = registration.getActiveStudentCurricularPlan();			List enrollments = studentCurricularPlan.getEnrolments();			InfoCandidacyDetails candidacyDTO = new InfoCandidacyDetails();			candidacyDTO.setCurricularCourse(InfoCurricularCourse					.newInfoFromDomain(candidacy.getCurricularCourse()));			candidacyDTO.setIdInternal(candidacy.getIdInternal());			candidacyDTO.setInfoClassification(getInfoClassification(enrollments));			candidacyDTO.setModality(InfoModality.newInfoFromDomain(candidacy.getModality()));			candidacyDTO.setMotivation(candidacy.getMotivation());			candidacyDTO.setSeminary(InfoSeminaryWithEquivalencies.newInfoFromDomain(candidacy					.getSeminary()));			candidacyDTO.setStudent(InfoStudent.newInfoFromDomain(registration));			candidacyDTO.setTheme(InfoTheme.newInfoFromDomain(candidacy.getTheme()));			List<InfoCaseStudyChoice> infos = new ArrayList<InfoCaseStudyChoice>();			for (Iterator iter = candidacy.getCaseStudyChoices().iterator(); iter.hasNext();) {				CaseStudyChoice element = (CaseStudyChoice) iter.next();				infos.add(InfoCaseStudyChoice.newInfoFromDomain(element));			}			candidacyDTO.setCases(infos);			if (candidacy.getApproved() != null) {				candidacyDTO.setApproved(candidacy.getApproved());			} else {				candidacyDTO.setApproved(Boolean.FALSE);			}			infoCandidacies.add(candidacyDTO);		}		return infoCandidacies;	}