package net.sourceforge.fenixedu.dataTransferObject.teacherServiceDistribution; import java.util.ArrayList; import java.util.Comparator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import net.sourceforge.fenixedu.dataTransferObject.DataTranferObject; import net.sourceforge.fenixedu.domain.CurricularCourse; import net.sourceforge.fenixedu.domain.DegreeModuleScope; import net.sourceforge.fenixedu.domain.ExecutionSemester; import net.sourceforge.fenixedu.domain.teacherServiceDistribution.TSDCourse; import net.sourceforge.fenixedu.domain.teacherServiceDistribution.TSDTeacher; import pt.utl.ist.fenix.tools.util.Pair; public class TSDCourseDTOEntry extends DataTranferObject { public static final Comparator COMPARATOR_BY_NAME = new Comparator() { @Override public int compare(TSDCourseDTOEntry o1, TSDCourseDTOEntry o2) { return o1.getTSDCourse().getName().compareTo(o2.getTSDCourse().getName()); } }; private TSDCourse tsdCourse; private List executionPeriodList = null; public TSDCourseDTOEntry(TSDCourse _tsdCourse, List executionPeriodList) { this.tsdCourse = _tsdCourse; this.executionPeriodList = executionPeriodList; } public List getTSDProfessorshipDTOEntries() { List tsdProfessorshipDTOEntryList = new ArrayList(); for (TSDTeacher teacher : tsdCourse.getAssociatedTSDTeachers()) { tsdProfessorshipDTOEntryList.add(new TSDProfessorshipDTOEntry(tsdCourse.getTSDProfessorshipByTSDTeacher(teacher), executionPeriodList)); } return tsdProfessorshipDTOEntryList; } public TSDCourse getTSDCourse() { return tsdCourse; } public List>> getCurricularCoursesInformation() { List>> curricularCourseInformation = new ArrayList>>(); List tsdCurricularCourseList = tsdCourse.getAssociatedCurricularCourses(); for (CurricularCourse tsdCurricularCourse : tsdCurricularCourseList) { Set curricularYearsSet = buildCurricularYearsSet(tsdCurricularCourse, tsdCourse.getExecutionPeriod()); List curricularYearsList = new ArrayList(); curricularYearsList.addAll(curricularYearsSet); curricularCourseInformation.add(new Pair>(tsdCurricularCourse.getDegreeCurricularPlan() .getDegree().getSigla(), curricularYearsList)); } return curricularCourseInformation; } public String getAcronym() { CurricularCourse tsdCurricularCourse = null; if (!tsdCourse.getAssociatedCurricularCourses().isEmpty()) { tsdCurricularCourse = tsdCourse.getAssociatedCurricularCourses().get(0); } if (tsdCurricularCourse != null) { return tsdCurricularCourse.getAcronym(); } else { return tsdCourse.getCompetenceName(); } } private Set buildCurricularYearsSet(CurricularCourse tsdCurricularCourseEntry, ExecutionSemester executionPeriodEntry) { Set curricularYearsSet = new LinkedHashSet(); for (Integer year : getCurricularIntYears(tsdCurricularCourseEntry)) { curricularYearsSet.add(year.toString()); } return curricularYearsSet; } private List getCurricularIntYears(CurricularCourse course) { List curricularYearList = new ArrayList(); for (DegreeModuleScope degreeModuleScope : course.getDegreeModuleScopes()) { curricularYearList.add(degreeModuleScope.getCurricularYear()); } return curricularYearList; } }