/* * ExecutionDegree.java * * Created on 2 de Novembro de 2002, 20:53 */ package net.sourceforge.fenixedu.domain; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; import net.sourceforge.fenixedu.domain.candidacy.CandidacySituationType; import net.sourceforge.fenixedu.domain.candidacy.DFACandidacy; import net.sourceforge.fenixedu.domain.candidacy.DegreeCandidacy; import net.sourceforge.fenixedu.domain.candidacy.IMDCandidacy; import net.sourceforge.fenixedu.domain.candidacy.StudentCandidacy; import net.sourceforge.fenixedu.domain.candidacy.degree.ShiftDistributionEntry; import net.sourceforge.fenixedu.domain.degree.DegreeType; import net.sourceforge.fenixedu.domain.degreeStructure.CurricularStage; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.interfaces.HasExecutionYear; import net.sourceforge.fenixedu.domain.space.Campus; import net.sourceforge.fenixedu.domain.student.Registration; import net.sourceforge.fenixedu.domain.studentCurricularPlan.Specialization; import net.sourceforge.fenixedu.domain.time.calendarStructure.AcademicCalendarEntry; import net.sourceforge.fenixedu.domain.time.calendarStructure.AcademicCalendarRootEntry; import net.sourceforge.fenixedu.domain.time.calendarStructure.AcademicInterval; import net.sourceforge.fenixedu.domain.time.calendarStructure.AcademicYearCE; import net.sourceforge.fenixedu.domain.util.FactoryExecutor; import net.sourceforge.fenixedu.injectionCode.AccessControl; import net.sourceforge.fenixedu.util.SituationName; import net.sourceforge.fenixedu.util.State; import org.apache.commons.collections.comparators.ComparatorChain; import org.joda.time.YearMonthDay; import com.linkare.commons.metainfo.Linkare; /** * * @author rpfi */ public class ExecutionDegree extends ExecutionDegree_Base implements Comparable { public static final Comparator COMPARATOR_BY_DEGREE_NAME = new Comparator() { @Override public int compare(ExecutionDegree o1, ExecutionDegree o2) { return o1.getDegree().getName().compareTo(o2.getDegree().getName()); } }; static final public Comparator EXECUTION_DEGREE_COMPARATORY_BY_YEAR = new Comparator() { public int compare(ExecutionDegree o1, ExecutionDegree o2) { return o1.getExecutionYear().compareTo(o2.getExecutionYear()); } }; static final public Comparator REVERSE_EXECUTION_DEGREE_COMPARATORY_BY_YEAR = new Comparator() { public int compare(ExecutionDegree o1, ExecutionDegree o2) { return o1.getExecutionYear().compareTo(o2.getExecutionYear()); } }; static final public Comparator EXECUTION_DEGREE_COMPARATORY_BY_DEGREE_TYPE_AND_NAME = new Comparator() { public int compare(ExecutionDegree o1, ExecutionDegree o2) { return Degree.COMPARATOR_BY_DEGREE_TYPE_AND_NAME_AND_ID.compare(o1.getDegree(), o2.getDegree()); } }; static final public Comparator EXECUTION_DEGREE_COMPARATORY_BY_DEGREE_TYPE_AND_NAME_AND_EXECUTION_YEAR = new Comparator() { public int compare(ExecutionDegree o1, ExecutionDegree o2) { final ComparatorChain comparatorChain = new ComparatorChain(); comparatorChain.addComparator(EXECUTION_DEGREE_COMPARATORY_BY_DEGREE_TYPE_AND_NAME); comparatorChain.addComparator(EXECUTION_DEGREE_COMPARATORY_BY_YEAR); return comparatorChain.compare(o1, o2); } }; private ExecutionDegree() { super(); setRootDomainObject(RootDomainObject.getInstance()); } protected ExecutionDegree(DegreeCurricularPlan degreeCurricularPlan, ExecutionYear executionYear, Campus campus, Boolean temporaryExamMap) { this(); if (degreeCurricularPlan == null || executionYear == null || campus == null) { throw new DomainException("execution.degree.null.args.to.constructor"); } setDegreeCurricularPlan(degreeCurricularPlan); setExecutionYear(executionYear); setCampus(campus); setTemporaryExamMap(temporaryExamMap); } public boolean canBeDeleted() { return !hasAnySchoolClasses() && !hasAnyMasterDegreeCandidates() && !hasAnyGuides() && !hasScheduling() && !hasAnyAssociatedFinalDegreeWorkGroups() && !hasAnyAssociatedInquiriesCoursesByCourse() && !hasAnyAssociatedInquiriesCoursesByStudent() && !hasAnyStudentCandidacies() && !hasAnyShiftDistributionEntries(); } public void delete() { if (canBeDeleted()) { for (; hasAnyCoordinatorsList(); getCoordinatorsList().get(0).delete()) ; for (; hasAnyScientificCommissionMembers(); getScientificCommissionMembers().get(0).delete()) ; if (hasGratuityValues()) { getGratuityValues().delete(); } deletePeriodLessonsFirstSemester(); deletePeriodLessonsSecondSemester(); deletePeriodExamsFirstSemester(); deletePeriodExamsSecondSemester(); deletePeriodExamsSpecialSeason(); deletePeriodGradeSubmissionNormalSeasonFirstSemester(); deletePeriodGradeSubmissionNormalSeasonSecondSemester(); deletePeriodGradeSubmissionSpecialSeason(); removeExecutionYear(); removeDegreeCurricularPlan(); removeCampus(); removeRootDomainObject(); deleteDomainObject(); } else { throw new DomainException("execution.degree.cannot.be.deleted"); } } private void deletePeriodGradeSubmissionSpecialSeason() { OccupationPeriod occupationPeriodReference = getPeriodGradeSubmissionSpecialSeason(); if (occupationPeriodReference != null) { removePeriodGradeSubmissionSpecialSeason(); occupationPeriodReference.delete(); } } private void deletePeriodGradeSubmissionNormalSeasonSecondSemester() { OccupationPeriod occupationPeriodReference = getPeriodGradeSubmissionNormalSeasonSecondSemester(); if (occupationPeriodReference != null) { removePeriodGradeSubmissionNormalSeasonSecondSemester(); occupationPeriodReference.delete(); } } private void deletePeriodGradeSubmissionNormalSeasonFirstSemester() { OccupationPeriod occupationPeriodReference = getPeriodGradeSubmissionNormalSeasonFirstSemester(); if (occupationPeriodReference != null) { removePeriodGradeSubmissionNormalSeasonFirstSemester(); occupationPeriodReference.delete(); } } private void deletePeriodExamsSpecialSeason() { OccupationPeriod occupationPeriodReference = getPeriodExamsSpecialSeason(); if (occupationPeriodReference != null) { removePeriodExamsSpecialSeason(); occupationPeriodReference.delete(); } } private void deletePeriodExamsSecondSemester() { OccupationPeriod occupationPeriodReference = getPeriodExamsSecondSemester(); if (occupationPeriodReference != null) { removePeriodExamsSecondSemester(); occupationPeriodReference.delete(); } } private void deletePeriodExamsFirstSemester() { OccupationPeriod occupationPeriodReference = getPeriodExamsFirstSemester(); if (occupationPeriodReference != null) { removePeriodExamsFirstSemester(); occupationPeriodReference.delete(); } } private void deletePeriodLessonsSecondSemester() { OccupationPeriod occupationPeriodReference = getPeriodLessonsSecondSemester(); if (occupationPeriodReference != null) { removePeriodLessonsSecondSemester(); occupationPeriodReference.delete(); } } private void deletePeriodLessonsFirstSemester() { OccupationPeriod occupationPeriodReference = getPeriodLessonsFirstSemester(); if (occupationPeriodReference != null) { removePeriodLessonsFirstSemester(); occupationPeriodReference.delete(); } } public void edit(ExecutionYear executionYear, Campus campus, Boolean temporaryExamMap, OccupationPeriod periodLessonsFirstSemester, OccupationPeriod periodExamsFirstSemester, OccupationPeriod periodLessonsSecondSemester, OccupationPeriod periodExamsSecondSemester, OccupationPeriod periodExamsSpecialSeason, OccupationPeriod gradeSubmissionNormalSeasonFirstSemester, OccupationPeriod gradeSubmissionNormalSeasonSecondSemester, OccupationPeriod gradeSubmissionSpecialSeason) { setExecutionYear(executionYear); setCampus(campus); setTemporaryExamMap(temporaryExamMap); if (periodLessonsFirstSemester != getPeriodLessonsFirstSemester()) { deletePeriodLessonsFirstSemester(); setPeriodLessonsFirstSemester(periodLessonsFirstSemester); } if (periodExamsFirstSemester != getPeriodExamsFirstSemester()) { deletePeriodExamsFirstSemester(); setPeriodExamsFirstSemester(periodExamsFirstSemester); } if (periodLessonsSecondSemester != getPeriodLessonsSecondSemester()) { deletePeriodLessonsSecondSemester(); setPeriodLessonsSecondSemester(periodLessonsSecondSemester); } if (periodExamsSecondSemester != getPeriodExamsSecondSemester()) { deletePeriodExamsSecondSemester(); setPeriodExamsSecondSemester(periodExamsSecondSemester); } if (periodExamsSpecialSeason != getPeriodExamsSpecialSeason()) { deletePeriodExamsSpecialSeason(); setPeriodExamsSpecialSeason(periodExamsSpecialSeason); } if (gradeSubmissionNormalSeasonFirstSemester != getPeriodGradeSubmissionNormalSeasonFirstSemester()) { deletePeriodGradeSubmissionNormalSeasonFirstSemester(); setPeriodGradeSubmissionNormalSeasonFirstSemester(gradeSubmissionNormalSeasonFirstSemester); } if (gradeSubmissionNormalSeasonSecondSemester != getPeriodGradeSubmissionNormalSeasonSecondSemester()) { deletePeriodGradeSubmissionNormalSeasonSecondSemester(); setPeriodGradeSubmissionNormalSeasonSecondSemester(gradeSubmissionNormalSeasonSecondSemester); } if (gradeSubmissionSpecialSeason != getPeriodGradeSubmissionSpecialSeason()) { deletePeriodGradeSubmissionSpecialSeason(); setPeriodGradeSubmissionSpecialSeason(gradeSubmissionSpecialSeason); } } public boolean isBolonhaDegree() { return this.getDegreeCurricularPlan().isBolonhaDegree(); } public int compareTo(ExecutionDegree executionDegree) { final ExecutionYear executionYear = executionDegree.getExecutionYear(); return getExecutionYear().compareTo(executionYear); } public boolean isAfter(ExecutionDegree executionDegree) { return this.compareTo(executionDegree) > 0; } public boolean isBefore(ExecutionDegree executionDegree) { return this.compareTo(executionDegree) < 0; } public boolean isFirstYear() { final List executionDegrees = this.getDegreeCurricularPlan().getExecutionDegrees(); return this == Collections.min(executionDegrees, EXECUTION_DEGREE_COMPARATORY_BY_YEAR); } public Set findAvailableShifts(final CurricularYear curricularYear, final ExecutionSemester executionSemester) { final DegreeCurricularPlan degreeCurricularPlan = getDegreeCurricularPlan(); final Set shifts = new HashSet(); for (final CurricularCourse curricularCourse : degreeCurricularPlan.getCurricularCourses()) { if (curricularCourse.hasScopeInGivenSemesterAndCurricularYearInDCP(curricularYear, degreeCurricularPlan, executionSemester)) { for (final ExecutionCourse executionCourse : curricularCourse.getAssociatedExecutionCourses()) { if (executionCourse.getExecutionPeriod() == executionSemester) { shifts.addAll(executionCourse.getAssociatedShifts()); } } } } return shifts; } @Deprecated public Set findSchoolClassesByExecutionPeriod(final ExecutionSemester executionSemester) { final Set schoolClasses = new HashSet(); for (final SchoolClass schoolClass : getSchoolClasses()) { if (schoolClass.getExecutionPeriod() == executionSemester) { schoolClasses.add(schoolClass); } } return schoolClasses; } public Set findSchoolClassesByAcademicInterval(final AcademicInterval academicInterval) { final Set schoolClasses = new HashSet(); for (final SchoolClass schoolClass : getSchoolClasses()) { if (schoolClass.getExecutionPeriod().getAcademicInterval().equals(academicInterval)) { schoolClasses.add(schoolClass); } } return schoolClasses; } @Deprecated public Set findSchoolClassesByExecutionPeriodAndCurricularYear(final ExecutionSemester executionSemester, final Integer curricularYear) { final Set schoolClasses = new HashSet(); for (final SchoolClass schoolClass : getSchoolClasses()) { if (schoolClass.getExecutionPeriod() == executionSemester && schoolClass.getAnoCurricular().equals(curricularYear)) { schoolClasses.add(schoolClass); } } return schoolClasses; } public Set findSchoolClassesByAcademicIntervalAndCurricularYear(final AcademicInterval academicInterval, final Integer curricularYear) { final Set schoolClasses = new HashSet(); for (final SchoolClass schoolClass : getSchoolClasses()) { if (schoolClass.getExecutionPeriod().getAcademicInterval().equals(academicInterval) && schoolClass.getAnoCurricular().equals(curricularYear)) { schoolClasses.add(schoolClass); } } return schoolClasses; } public SchoolClass findSchoolClassesByExecutionPeriodAndName(final ExecutionSemester executionSemester, final String name) { for (final SchoolClass schoolClass : getSchoolClasses()) { if (schoolClass.getExecutionPeriod() == executionSemester && schoolClass.getNome().equalsIgnoreCase(name)) { return schoolClass; } } return null; } public List getCandidateSituationsInSituation(List situationNames) { List result = new ArrayList(); for (MasterDegreeCandidate candidate : getMasterDegreeCandidates()) { for (CandidateSituation situation : candidate.getSituations()) { if (situation.getValidation().getState() == null || situation.getValidation().getState() != State.ACTIVE) { continue; } if (situationNames != null && !situationNames.contains(situation.getSituation())) { continue; } result.add(situation); } } return result; } public Coordinator getCoordinatorByTeacher(Person person) { for (Coordinator coordinator : getCoordinatorsList()) { if (coordinator.getPerson() == person) { return coordinator; } } return null; } public MasterDegreeCandidate getMasterDegreeCandidateBySpecializationAndCandidateNumber(Specialization specialization, Integer candidateNumber) { for (final MasterDegreeCandidate masterDegreeCandidate : this.getMasterDegreeCandidatesSet()) { if (masterDegreeCandidate.getSpecialization() == specialization && masterDegreeCandidate.getCandidateNumber().equals(candidateNumber)) { return masterDegreeCandidate; } } return null; } public Integer generateCandidateNumberForSpecialization(Specialization specialization) { int maxCandidateNumber = 0; for (final MasterDegreeCandidate masterDegreeCandidate : this.getMasterDegreeCandidatesSet()) { if (masterDegreeCandidate.getSpecialization() == specialization && masterDegreeCandidate.getCandidateNumber() != null) { maxCandidateNumber = Math.max(maxCandidateNumber, masterDegreeCandidate.getCandidateNumber()); } } return Integer.valueOf(++maxCandidateNumber); } private static Comparator COMPARATOR_BY_DEGREE_CURRICULAR_PLAN_ID_INTERNAL_DESC = new Comparator() { public int compare(ExecutionDegree o1, ExecutionDegree o2) { return o2.getDegreeCurricularPlan().getIdInternal().compareTo(o1.getDegreeCurricularPlan().getIdInternal()); } }; public static List getAllByExecutionYear(String year) { if (year == null) { return Collections.EMPTY_LIST; } final List result = new ArrayList(); for (ExecutionDegree executionDegree : RootDomainObject.getInstance().getExecutionDegrees()) { if (year.equals(executionDegree.getExecutionYear().getYear())) { result.add(executionDegree); } } Collections.sort(result, COMPARATOR_BY_DEGREE_CURRICULAR_PLAN_ID_INTERNAL_DESC); return result; } public static List getAllByExecutionYear(ExecutionYear executionYear) { if (executionYear == null) { return Collections.EMPTY_LIST; } final List result = new ArrayList(); for (final ExecutionDegree executionDegree : RootDomainObject.getInstance().getExecutionDegrees()) { if (executionDegree.getExecutionYear() == executionYear) { result.add(executionDegree); } } Collections.sort(result, COMPARATOR_BY_DEGREE_CURRICULAR_PLAN_ID_INTERNAL_DESC); return result; } public static List getAllByExecutionCourseAndTeacher(ExecutionCourse executionCourse, Person person) { List result = new ArrayList(); for (ExecutionDegree executionDegree : RootDomainObject.getInstance().getExecutionDegrees()) { boolean matchExecutionCourse = false; for (CurricularCourse curricularCourse : executionDegree.getDegreeCurricularPlan().getCurricularCourses()) { if (curricularCourse.getAssociatedExecutionCourses().contains(executionCourse)) { matchExecutionCourse = true; break; } } if (!matchExecutionCourse) { continue; } // if teacher is not a coordinator of the executionDegree if (executionDegree.getCoordinatorByTeacher(person) == null) { continue; } result.add(executionDegree); } return result; } public static List getAllCoordinatedByTeacher(Person person) { List result = new ArrayList(); if (person == null) { return result; } for (Coordinator coordinator : person.getCoordinators()) { result.add(coordinator.getExecutionDegree()); } Comparator degreNameComparator = new Comparator() { public int compare(ExecutionDegree o1, ExecutionDegree o2) { String name1 = o1.getDegreeCurricularPlan().getDegree().getName(); String name2 = o2.getDegreeCurricularPlan().getDegree().getName(); return String.CASE_INSENSITIVE_ORDER.compare(name1, name2); } }; Comparator yearComparator = new Comparator() { public int compare(ExecutionDegree o1, ExecutionDegree o2) { String year1 = o1.getExecutionYear().getYear(); String year2 = o2.getExecutionYear().getYear(); return String.CASE_INSENSITIVE_ORDER.compare(year1, year2); } }; // sort by degreeCurricularPlan.degree.nome ascending, // executionYear.year descending ComparatorChain comparatorChain = new ComparatorChain(); comparatorChain.addComparator(degreNameComparator, false); comparatorChain.addComparator(yearComparator, true); Collections.sort(result, comparatorChain); return result; } public static List getAllByExecutionYearAndDegreeType(String year, DegreeType typeOfCourse) { if (year == null || typeOfCourse == null) { return Collections.EMPTY_LIST; } final ExecutionYear executionYear = ExecutionYear.readExecutionYearByName(year); return getAllByExecutionYearAndDegreeType(executionYear, typeOfCourse); } public static List getAllByExecutionYearAndDegreeType(ExecutionYear executionYear, DegreeType typeOfCourse) { if (executionYear == null || typeOfCourse == null) { return Collections.EMPTY_LIST; } final List result = new ArrayList(); for (final ExecutionDegree executionDegree : executionYear.getExecutionDegreesSet()) { if (!typeOfCourse.equals(executionDegree.getDegreeType())) { continue; } result.add(executionDegree); } Collections.sort(result, COMPARATOR_BY_DEGREE_CURRICULAR_PLAN_ID_INTERNAL_DESC); return result; } public static List getAllByDegreeAndExecutionYear(Degree degree, String year) { List result = new ArrayList(); if (degree == null || year == null) { return result; } ExecutionYear executionYear = ExecutionYear.readExecutionYearByName(year); if (executionYear == null) { return result; } for (ExecutionDegree executionDegree : executionYear.getExecutionDegrees()) { if (degree.equals(executionDegree.getDegreeCurricularPlan().getDegree())) { result.add(executionDegree); } } return result; } public static List getAllByDegreeAndCurricularStage(Degree degree, CurricularStage stage) { List result = new ArrayList(); if (degree == null) { return result; } if (stage == null) { return result; } for (ExecutionDegree executionDegree : RootDomainObject.getInstance().getExecutionDegrees()) { if (!degree.equals(executionDegree.getDegreeCurricularPlan().getDegree())) { continue; } if (!stage.equals(executionDegree.getDegreeCurricularPlan().getCurricularStage())) { continue; } result.add(executionDegree); } return result; } public static ExecutionDegree getByDegreeCurricularPlanAndExecutionYear(DegreeCurricularPlan degreeCurricularPlan, ExecutionYear executionYear) { if (degreeCurricularPlan == null || executionYear == null) { return null; } for (ExecutionDegree executionDegree : degreeCurricularPlan.getExecutionDegrees()) { if (executionYear == executionDegree.getExecutionYear()) { return executionDegree; } } return null; } public static ExecutionDegree getByDegreeCurricularPlanAndExecutionYear(DegreeCurricularPlan degreeCurricularPlan, String executionYear) { if (degreeCurricularPlan == null) { return null; } if (executionYear == null) { return null; } for (ExecutionDegree executionDegree : degreeCurricularPlan.getExecutionDegrees()) { if (executionYear.equalsIgnoreCase(executionDegree.getExecutionYear().getYear())) { return executionDegree; } } return null; } public static ExecutionDegree getByDegreeCurricularPlanNameAndExecutionYear(String degreeName, ExecutionYear executionYear) { if (degreeName == null) { return null; } if (executionYear == null) { return null; } for (ExecutionDegree executionDegree : executionYear.getExecutionDegrees()) { if (degreeName.equalsIgnoreCase(executionDegree.getDegreeCurricularPlan().getName())) { return executionDegree; } } return null; } public static ExecutionDegree readByDegreeCodeAndExecutionYearAndCampus(String degreeCode, ExecutionYear executionYear, Campus campus) { for (final Degree degree : Degree.readAllByDegreeCode(degreeCode)) { final ExecutionDegree executionDegree = degree.getMostRecentDegreeCurricularPlan().getExecutionDegreeByYear( executionYear); if (executionDegree.getCampus() == campus) { return executionDegree; } } return null; } public boolean isEvaluationDateInExamPeriod(Date evaluationDate, ExecutionSemester executionSemester, MarkSheetType markSheetType) { return isSpecialAuthorization(markSheetType, executionSemester, evaluationDate) || checkOccupationPeriod(evaluationDate, executionSemester, markSheetType); } private boolean isSpecialAuthorization(MarkSheetType markSheetType, ExecutionSemester executionSemester, Date evaluationDate) { return (markSheetType == MarkSheetType.SPECIAL_AUTHORIZATION); } private boolean checkOccupationPeriod(Date evaluationDate, ExecutionSemester executionSemester, MarkSheetType markSheetType) { OccupationPeriod occupationPeriod = getOccupationPeriodFor(executionSemester, markSheetType); return (evaluationDate != null && occupationPeriod != null && occupationPeriod .nestedOccupationPeriodsContainsDay(YearMonthDay.fromDateFields(evaluationDate))); } @Linkare(author = "Paulo Zenida", comments = "Included the cases EXAM and SPECIAL_SITUATION") public OccupationPeriod getOccupationPeriodFor(ExecutionSemester executionSemester, MarkSheetType markSheetType) { OccupationPeriod occupationPeriod = null; switch (markSheetType) { case NORMAL: case EXAM: case IMPROVEMENT: if (executionSemester.getSemester().equals(Integer.valueOf(1))) { occupationPeriod = this.getPeriodExamsFirstSemester(); } else { occupationPeriod = this.getPeriodExamsSecondSemester(); } break; case APPEAL: case SPECIAL_SEASON: case SPECIAL_SITUATION: occupationPeriod = this.getPeriodExamsSpecialSeason(); break; default: } return occupationPeriod; } public List getResponsibleCoordinators() { List result = new ArrayList(); for (final Coordinator coordinator : getCoordinatorsList()) { if (coordinator.getResponsible()) { result.add(coordinator); } } return result; } public boolean isDateInFirstSemesterNormalSeasonOfGradeSubmission(YearMonthDay date) { return (getPeriodGradeSubmissionNormalSeasonFirstSemester() != null && getPeriodGradeSubmissionNormalSeasonFirstSemester() .nestedOccupationPeriodsContainsDay(date)); } public boolean isDateInSecondSemesterNormalSeasonOfGradeSubmission(YearMonthDay date) { return (getPeriodGradeSubmissionNormalSeasonSecondSemester() != null && getPeriodGradeSubmissionNormalSeasonSecondSemester() .nestedOccupationPeriodsContainsDay(date)); } public boolean isDateInSpecialSeasonOfGradeSubmission(YearMonthDay date) { return (getPeriodGradeSubmissionSpecialSeason() != null && getPeriodGradeSubmissionSpecialSeason() .nestedOccupationPeriodsContainsDay(date)); } final public String getPresentationName() { return getDegreeCurricularPlan().getPresentationName(); } public String getDegreeName() { return getDegree().getNameFor(getExecutionYear()).getContent(); } public Degree getDegree() { return getDegreeCurricularPlan().getDegree(); } public DegreeType getDegreeType() { return getDegree().getDegreeType(); } public Set getDfaCandidacies() { return getDFACandidacies(); } public Set getDegreeCandidacies() { final Set result = new HashSet(); for (final StudentCandidacy studentCandidacy : getStudentCandidacies()) { if (studentCandidacy instanceof DegreeCandidacy) { result.add((DegreeCandidacy) studentCandidacy); } } return result; } public Set getFirstCycleCandidacies() { final Set result = new HashSet(); for (final StudentCandidacy studentCandidacy : getStudentCandidacies()) { if (studentCandidacy instanceof DegreeCandidacy || studentCandidacy instanceof IMDCandidacy) { result.add(studentCandidacy); } } return result; } public Collection getFirstCycleCandidacies(final CandidacySituationType candidacySituationType) { final Collection result = new HashSet(); for (final StudentCandidacy studentCandidacy : getStudentCandidaciesSet()) { if ((studentCandidacy instanceof DegreeCandidacy || studentCandidacy instanceof IMDCandidacy) && studentCandidacy.getActiveCandidacySituationType() == candidacySituationType) { result.add(studentCandidacy); } } return result; } public List getRegistrationsForDegreeCandidacies() { final List result = new ArrayList(); for (final DegreeCandidacy degreeCandidacy : getDegreeCandidacies()) { if (degreeCandidacy.hasRegistration()) { result.add(degreeCandidacy.getRegistration()); } } return result; } public List getRegistrationsForFirstCycleCandidacies() { final List result = new ArrayList(); for (final StudentCandidacy studentCandidacy : getFirstCycleCandidacies()) { if (studentCandidacy.hasRegistration()) { result.add(studentCandidacy.getRegistration()); } } return result; } public Set getDFACandidacies() { final Set result = new HashSet(); for (final StudentCandidacy studentCandidacy : getStudentCandidacies()) { if (studentCandidacy instanceof DFACandidacy) { result.add((DFACandidacy) studentCandidacy); } } return result; } public List getNextFreeShiftDistributions() { final ArrayList entries = new ArrayList(getShiftDistributionEntriesSet()); Collections.sort(entries, ShiftDistributionEntry.NUMBER_COMPARATOR); for (final ShiftDistributionEntry shiftDistributionEntry : entries) { if (!shiftDistributionEntry.getDistributed()) { return ShiftDistributionEntry.readByAbstractNumber(shiftDistributionEntry.getAbstractStudentNumber(), getExecutionYear()); } } return Collections.EMPTY_LIST; } public Integer getStudentNumberForShiftDistributionBasedOn(Integer studentNumberPosition) { final List abstractStudentNumbers = new ArrayList(); for (final ShiftDistributionEntry shiftDistributionEntry : getShiftDistributionEntriesSet()) { if (!abstractStudentNumbers.contains(shiftDistributionEntry.getAbstractStudentNumber())) { abstractStudentNumbers.add(shiftDistributionEntry.getAbstractStudentNumber()); } } Collections.sort(abstractStudentNumbers); return (!abstractStudentNumbers.isEmpty()) ? abstractStudentNumbers.get(studentNumberPosition) : null; } public List getDistributedShiftsFor(Integer studentNumber) { return getShiftsFor(studentNumber, true); } private List getShiftsFor(Integer studentNumber, boolean alreadyDistributed) { final List result = new ArrayList(); for (final ShiftDistributionEntry shiftDistributionEntry : getShiftDistributionEntriesSet()) { if (shiftDistributionEntry.getDistributed().booleanValue() == alreadyDistributed && shiftDistributionEntry.getAbstractStudentNumber().equals(studentNumber)) { result.add(shiftDistributionEntry); } } return result; } public List getDegreeCandidaciesBy(CandidacySituationType candidacySituationType) { final List result = new ArrayList(); for (final DegreeCandidacy candidacy : getDegreeCandidacies()) { if (candidacy.getActiveCandidacySituation().getCandidacySituationType() == candidacySituationType) { result.add(candidacy); } } return result; } public List getFirstCycleCandidaciesBy(CandidacySituationType candidacySituationType) { final List result = new ArrayList(); for (final StudentCandidacy candidacy : getFirstCycleCandidacies()) { if (candidacy.getActiveCandidacySituation().getCandidacySituationType() == candidacySituationType) { result.add(candidacy); } } return result; } public List getNotConcludedDegreeCandidacies() { final List result = new ArrayList(); for (final DegreeCandidacy degreeCandidacy : getDegreeCandidacies()) { if (!degreeCandidacy.isConcluded()) { result.add(degreeCandidacy); } } return result; } public boolean isPersonInScientificCommission(Person person) { for (ScientificCommission commission : getScientificCommissionMembers()) { if (commission.getPerson() == person) { return true; } } return false; } /* * Returns a list of teachers from the coordinator department that can be * tutors of a student from the given execution degree */ public List getPossibleTutorsFromExecutionDegreeDepartments() { List departments = this.getDegree().getDepartments(); ArrayList possibleTeachers = new ArrayList(); for (Department department : departments) { possibleTeachers.addAll(department.getPossibleTutors()); } return possibleTeachers; } public static class ThesisCreationPeriodFactoryExecutor implements FactoryExecutor, HasExecutionYear, Serializable { private DomainReference executionYear; private DomainReference executionDegree; private YearMonthDay beginThesisCreationPeriod; private YearMonthDay endThesisCreationPeriod; public Object execute() { final ExecutionDegree executionDegree = getExecutionDegree(); if (executionDegree == null) { final ExecutionYear executionYear = getExecutionYear(); if (executionYear != null) { for (final ExecutionDegree otherExecutionDegree : executionYear.getExecutionDegreesSet()) { execute(otherExecutionDegree); } } } else { execute(executionDegree); } return null; } private void execute(final ExecutionDegree executionDegree) { executionDegree.setBeginThesisCreationPeriod(beginThesisCreationPeriod); executionDegree.setEndThesisCreationPeriod(endThesisCreationPeriod); } public ExecutionYear getExecutionYear() { return executionYear == null ? null : executionYear.getObject(); } public void setExecutionYear(final ExecutionYear executionYear) { this.executionYear = executionYear == null ? null : new DomainReference(executionYear); } public ExecutionDegree getExecutionDegree() { return executionDegree == null ? null : executionDegree.getObject(); } public void setExecutionDegree(final ExecutionDegree executionDegree) { this.executionDegree = executionDegree == null ? null : new DomainReference(executionDegree); } public YearMonthDay getBeginThesisCreationPeriod() { return beginThesisCreationPeriod; } public void setBeginThesisCreationPeriod(YearMonthDay beginThesisCreationPeriod) { this.beginThesisCreationPeriod = beginThesisCreationPeriod; } public YearMonthDay getEndThesisCreationPeriod() { return endThesisCreationPeriod; } public void setEndThesisCreationPeriod(YearMonthDay endThesisCreationPeriod) { this.endThesisCreationPeriod = endThesisCreationPeriod; } public boolean hasExecutionYear() { return getExecutionYear() != null; } } public boolean isScientificCommissionMember() { final Person person = AccessControl.getPerson(); return isScientificCommissionMember(person); } public boolean isScientificCommissionMember(final Person person) { for (final ScientificCommission scientificCommission : getScientificCommissionMembersSet()) { if (person == scientificCommission.getPerson()) { return true; } } return false; } public static List filterByAcademicInterval(AcademicInterval academicInterval) { AcademicCalendarEntry academicCalendarEntry = academicInterval.getAcademicCalendarEntry(); while (!(academicCalendarEntry instanceof AcademicCalendarRootEntry)) { if (academicCalendarEntry instanceof AcademicYearCE) { ExecutionYear year = ExecutionYear.getExecutionYear((AcademicYearCE) academicCalendarEntry); List result = new ArrayList(); result.addAll(year.getExecutionDegrees()); return result; } else academicCalendarEntry = academicCalendarEntry.getParentEntry(); } return Collections.EMPTY_LIST; } public AcademicInterval getAcademicInterval() { return getExecutionYear().getAcademicInterval(); } public CoordinatorExecutionDegreeCoursesReport getExecutionDegreeCoursesReports(final ExecutionInterval executionInterval) { for (final CoordinatorExecutionDegreeCoursesReport coordinatorExecutionDegreeCoursesReport : getExecutionDegreeCoursesReports()) { if (coordinatorExecutionDegreeCoursesReport.getExecutionInterval() == executionInterval) { return coordinatorExecutionDegreeCoursesReport; } } return null; } }