/* * Created on 12/Nov/2003 */ package net.sourceforge.fenixedu.dataTransferObject.gesdis; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import net.sourceforge.fenixedu.dataTransferObject.DataTranferObject; import net.sourceforge.fenixedu.dataTransferObject.ISiteComponent; import net.sourceforge.fenixedu.dataTransferObject.InfoCurricularCourse; import net.sourceforge.fenixedu.dataTransferObject.InfoCurricularCourseScope; import net.sourceforge.fenixedu.dataTransferObject.InfoCurriculum; import net.sourceforge.fenixedu.dataTransferObject.InfoDepartment; import net.sourceforge.fenixedu.dataTransferObject.InfoExecutionCourse; import net.sourceforge.fenixedu.dataTransferObject.InfoExecutionPeriod; import net.sourceforge.fenixedu.dataTransferObject.InfoLesson; import net.sourceforge.fenixedu.dataTransferObject.InfoTeacher; import net.sourceforge.fenixedu.domain.BibliographicReference; import net.sourceforge.fenixedu.domain.CompetenceCourse; import net.sourceforge.fenixedu.domain.CurricularCourse; import net.sourceforge.fenixedu.domain.CurricularCourseScope; import net.sourceforge.fenixedu.domain.Curriculum; import net.sourceforge.fenixedu.domain.DomainReference; import net.sourceforge.fenixedu.domain.Enrolment; import net.sourceforge.fenixedu.domain.ExecutionCourse; import net.sourceforge.fenixedu.domain.ExecutionSemester; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.Lesson; import net.sourceforge.fenixedu.domain.Professorship; import net.sourceforge.fenixedu.domain.Shift; import net.sourceforge.fenixedu.domain.ShiftType; import net.sourceforge.fenixedu.domain.Teacher; import net.sourceforge.fenixedu.domain.degreeStructure.CompetenceCourseInformation; import org.apache.commons.beanutils.BeanComparator; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; import org.apache.commons.collections.comparators.ReverseComparator; import org.joda.time.DateTime; import pt.utl.ist.fenix.tools.util.i18n.Language; /** * @author Leonor Almeida * @author Sergio Montelobo */ public class InfoSiteCourseInformation extends DataTranferObject implements ISiteComponent { private DomainReference executionCourseDomainReference; private DomainReference executionYearDomainReference; public InfoSiteCourseInformation(final ExecutionCourse executionCourse) { executionCourseDomainReference = new DomainReference(executionCourse); } public InfoSiteCourseInformation(final ExecutionCourse executionCourse, final ExecutionYear executionYear) { this(executionCourse); executionYearDomainReference = new DomainReference(executionYear); } public ExecutionCourse getExecutionCourse() { return this.executionCourseDomainReference == null ? null : this.executionCourseDomainReference.getObject(); } private ExecutionYear getExecutionYear() { return this.executionYearDomainReference == null ? null : this.executionYearDomainReference.getObject(); } // =================== FIELDS RETRIEVED BY DOMAIN LOGIC // ======================= public InfoExecutionCourse getInfoExecutionCourse() { return InfoExecutionCourse.newInfoFromDomain(getExecutionCourse()); } public InfoCourseReport getInfoCourseReport() { return getInfoExecutionCourse().getInfoCourseReport(); } public List getInfoCurricularCourses() { return getExecutionYear() == null ? getInfoExecutionCourse().getAssociatedInfoCurricularCourses() : getInfoExecutionCourse().getAssociatedInfoCurricularCourses(getExecutionYear()); } public List getInfoLecturingTeachers() { final List result = new ArrayList(); for (final Professorship professorship : getExecutionCourse().getProfessorships()) { result.add(InfoTeacher.newInfoFromDomain(professorship.getTeacher())); } return result; } public List getInfoResponsibleTeachers() { final List result = new ArrayList(); for (final Professorship responsibleFor : getExecutionCourse().responsibleFors()) { result.add(InfoTeacher.newInfoFromDomain(responsibleFor.getTeacher())); } return result; } // =================== FIELDS NOT RETRIEVED BY DOMAIN LOGIC // ======================= public Integer getNumberOfTheoLessons() { return getNumberOfLessons(getExecutionCourse().getShiftsByTypeOrderedByShiftName(ShiftType.TEORICA)); } public Integer getNumberOfPratLessons() { return getNumberOfLessons(getExecutionCourse().getShiftsByTypeOrderedByShiftName(ShiftType.PRATICA)); } public Integer getNumberOfTheoPratLessons() { return getNumberOfLessons(getExecutionCourse().getShiftsByTypeOrderedByShiftName(ShiftType.TEORICO_PRATICA)); } public Integer getNumberOfLabLessons() { return getNumberOfLessons(getExecutionCourse().getShiftsByTypeOrderedByShiftName(ShiftType.LABORATORIAL)); } private Integer getNumberOfLessons(final Collection shifts) { int result = 0; for (final Shift shift : shifts) { result += shift.getAssociatedLessonsCount(); } return result; } static final private int MIN_LENGTH = 10; public Integer getNumberOfFieldsFilled() { int result = 0; if (!getInfoLecturingTeachers().isEmpty()) { result++; } Iterator iter = getExecutionCourse().getAssociatedBibliographicReferencesIterator(); while (iter.hasNext()) { BibliographicReference bibliographicReference = (BibliographicReference) iter.next(); if (bibliographicReference.getTitle() != null && bibliographicReference.getTitle().length() > MIN_LENGTH) { result++; break; } } if (getExecutionCourse().getEvaluationMethod() != null && getExecutionCourse().getEvaluationMethod().getEvaluationElements() != null && getExecutionCourse().getEvaluationMethod().getEvaluationElements().getContent(Language.pt) != null && getExecutionCourse().getEvaluationMethod().getEvaluationElements().getContent(Language.pt).length() > MIN_LENGTH) { result++; } iter = getInfoCurriculums().iterator(); while (iter.hasNext()) { InfoCurriculum infoCurriculum = (InfoCurriculum) iter.next(); if (infoCurriculum.getGeneralObjectives() != null && infoCurriculum.getGeneralObjectives().length() > MIN_LENGTH) { result++; break; } } iter = getInfoCurriculums().iterator(); while (iter.hasNext()) { InfoCurriculum infoCurriculum = (InfoCurriculum) iter.next(); if (infoCurriculum.getProgram() != null && infoCurriculum.getProgram().length() > MIN_LENGTH) { result++; break; } } return Integer.valueOf(result); } public Integer getNumberOfFieldsFilledEn() { int numberOfFieldsFilled = 0; if (!getInfoLecturingTeachers().isEmpty()) { numberOfFieldsFilled++; } Iterator iter = getExecutionCourse().getAssociatedBibliographicReferencesIterator(); while (iter.hasNext()) { BibliographicReference bibliographicReference = (BibliographicReference) iter.next(); if (bibliographicReference.getTitle().length() > MIN_LENGTH) { numberOfFieldsFilled++; break; } } if (getExecutionCourse().getEvaluationMethod() != null && getExecutionCourse().getEvaluationMethod().getEvaluationElements() != null && getExecutionCourse().getEvaluationMethod().getEvaluationElements().getContent(Language.en) != null && getExecutionCourse().getEvaluationMethod().getEvaluationElements().getContent(Language.en).length() > MIN_LENGTH) { numberOfFieldsFilled++; } iter = getInfoCurriculums().iterator(); while (iter.hasNext()) { InfoCurriculum infoCurriculum = (InfoCurriculum) iter.next(); if (infoCurriculum.getGeneralObjectivesEn() != null && infoCurriculum.getGeneralObjectivesEn().length() > MIN_LENGTH) { numberOfFieldsFilled++; break; } } iter = getInfoCurriculums().iterator(); while (iter.hasNext()) { InfoCurriculum infoCurriculum = (InfoCurriculum) iter.next(); if (infoCurriculum.getOperacionalObjectivesEn() != null && infoCurriculum.getOperacionalObjectivesEn().length() > MIN_LENGTH) { numberOfFieldsFilled++; break; } } iter = getInfoCurriculums().iterator(); while (iter.hasNext()) { InfoCurriculum infoCurriculum = (InfoCurriculum) iter.next(); if (infoCurriculum.getProgramEn() != null && infoCurriculum.getProgramEn().length() > MIN_LENGTH) { numberOfFieldsFilled++; break; } } return Integer.valueOf(numberOfFieldsFilled); } public Date getLastModificationDate() { final Set dates = new HashSet(); if (getExecutionCourse().hasCourseReport()) { dates.add(getExecutionCourse().getCourseReport().getLastModificationDateDateTime()); } for (final Curriculum curriculum : getExecutionCourse().getCurriculums(getExecutionYear())) { dates.add(curriculum.getLastModificationDateDateTime()); } return dates.isEmpty() ? null : Collections. max(dates).toDate(); } public List getInfoDepartments() { final Set responsibleForTeachers = new HashSet(); for (final Professorship responsibleFor : getExecutionCourse().responsibleFors()) { responsibleForTeachers.add(responsibleFor.getTeacher()); } final List result = new ArrayList(); for (final Teacher teacher : responsibleForTeachers) { result.add(InfoDepartment.newInfoFromDomain(teacher.getCurrentWorkingDepartment())); } return result; } public List getInfoCurriculums() { final List result = new ArrayList(); for (final Curriculum curriculum : getExecutionCourse().getCurriculums(getExecutionYear())) { final InfoCurriculum infoCurriculum = InfoCurriculum.newInfoFromDomain(curriculum); final InfoCurricularCourse infoCurricularCourse = InfoCurricularCourse.newInfoFromDomain(curriculum .getCurricularCourse()); infoCurricularCourse.setInfoScopes(getInfoScopes(curriculum.getCurricularCourse())); infoCurriculum.setInfoCurricularCourse(infoCurricularCourse); result.add(infoCurriculum); } return result; } private List getInfoScopes(final CurricularCourse curricularCourse) { final List result = new ArrayList(); for (final CurricularCourseScope curricularCourseScope : curricularCourse.getScopesSet()) { result.add(InfoCurricularCourseScope.newInfoFromDomain(curricularCourseScope)); } return result; } public List getInfoLessons() { final List result = new ArrayList(); for (final Lesson lesson : getExecutionCourse().getLessons()) { result.add(InfoLesson.newInfoFromDomain(lesson)); } return getFilteredInfoLessons(result); } private List getFilteredInfoLessons(final List infoLessons) { final List result = new ArrayList(); InfoLesson infoLesson = getFilteredInfoLessonByType(infoLessons, ShiftType.TEORICA); if (infoLesson != null) { result.add(infoLesson); } infoLesson = getFilteredInfoLessonByType(infoLessons, ShiftType.PRATICA); if (infoLesson != null) { result.add(infoLesson); } infoLesson = getFilteredInfoLessonByType(infoLessons, ShiftType.LABORATORIAL); if (infoLesson != null) { result.add(infoLesson); } infoLesson = getFilteredInfoLessonByType(infoLessons, ShiftType.TEORICO_PRATICA); if (infoLesson != null) { result.add(infoLesson); } return result; } private InfoLesson getFilteredInfoLessonByType(List infoLessons, ShiftType type) { final ShiftType lessonType = type; InfoLesson infoLesson = (InfoLesson) CollectionUtils.find(infoLessons, new Predicate() { public boolean evaluate(Object o) { InfoLesson infoLesson = (InfoLesson) o; if (infoLesson.getInfoShift().getShift().getCourseLoadsCount() == 1) { return infoLesson.getInfoShift().getShift().containsType(lessonType); } return false; } }); return infoLesson; } public List getInfoSiteEvaluationInformations() { final List result = new ArrayList(); final ExecutionSemester executionSemester = getExecutionCourse().getExecutionPeriod(); for (final CurricularCourse curricularCourse : getExecutionCourse().getAssociatedCurricularCoursesSet()) { final InfoSiteEvaluationInformation infoSiteEvaluationInformation = new InfoSiteEvaluationInformation(); final InfoSiteEvaluationStatistics infoSiteEvaluationStatistics = new InfoSiteEvaluationStatistics(); final List enrolled = curricularCourse.getEnrolmentsByExecutionPeriod(executionSemester); infoSiteEvaluationStatistics.setEnrolled(enrolled.size()); infoSiteEvaluationStatistics.setEvaluated(Enrolment.countEvaluated(enrolled)); infoSiteEvaluationStatistics.setApproved(Enrolment.countApproved(enrolled)); infoSiteEvaluationStatistics.setInfoExecutionPeriod(InfoExecutionPeriod.newInfoFromDomain(executionSemester)); infoSiteEvaluationInformation.setInfoSiteEvaluationStatistics(infoSiteEvaluationStatistics); infoSiteEvaluationInformation.setInfoCurricularCourse(InfoCurricularCourse.newInfoFromDomain(curricularCourse)); infoSiteEvaluationInformation.setInfoSiteEvaluationHistory(getInfoSiteEvaluationsHistory(executionSemester, curricularCourse)); result.add(infoSiteEvaluationInformation); } return result; } private List getInfoSiteEvaluationsHistory(final ExecutionSemester executionPeriodToTest, final CurricularCourse curricularCourse) { final List result = new ArrayList(); final Set executionSemesters = new HashSet(); for (final ExecutionCourse executionCourse : curricularCourse.getAssociatedExecutionCoursesSet()) { final ExecutionSemester executionSemester = executionCourse.getExecutionPeriod(); // filter the executionPeriods by semester; // also, information regarding execution years after the course's // execution year must not be shown if (executionSemester.getSemester().equals(executionPeriodToTest.getSemester()) && executionSemester.getExecutionYear().isBefore(executionPeriodToTest.getExecutionYear())) { executionSemesters.add(executionSemester); } } for (final ExecutionSemester executionSemester : executionSemesters) { final InfoSiteEvaluationStatistics infoSiteEvaluationStatistics = new InfoSiteEvaluationStatistics(); infoSiteEvaluationStatistics.setInfoExecutionPeriod(InfoExecutionPeriod.newInfoFromDomain(executionSemester)); final List enrolled = curricularCourse.getEnrolmentsByExecutionPeriod(executionSemester); infoSiteEvaluationStatistics.setEnrolled(enrolled.size()); infoSiteEvaluationStatistics.setEvaluated(Enrolment.countEvaluated(enrolled)); infoSiteEvaluationStatistics.setApproved(Enrolment.countApproved(enrolled)); result.add(infoSiteEvaluationStatistics); } Collections.sort(result, new ReverseComparator(new BeanComparator("infoExecutionPeriod.infoExecutionYear.year"))); return result; } public String getEvaluationMethod() { final ExecutionCourse executionCourse = getExecutionCourse(); if (executionCourse != null) { final ExecutionSemester executionSemester = executionCourse.getExecutionPeriod(); for (final CurricularCourse curricularCourse : executionCourse.getAssociatedCurricularCoursesSet()) { final CompetenceCourse competenceCourse = curricularCourse.getCompetenceCourse(); if (curricularCourse.isActive(executionSemester) && competenceCourse != null) { final CompetenceCourseInformation competenceCourseInformation = competenceCourse .findCompetenceCourseInformationForExecutionPeriod(executionSemester); if (competenceCourseInformation != null) { competenceCourseInformation.getEvaluationMethod(); } } } } return null; } }