package net.sourceforge.fenixedu.dataTransferObject.delegate; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import net.sourceforge.fenixedu.dataTransferObject.comparators.IscteBeanComparator; import net.sourceforge.fenixedu.domain.CurricularCourse; import net.sourceforge.fenixedu.domain.DomainReference; import net.sourceforge.fenixedu.domain.Enrolment; import net.sourceforge.fenixedu.domain.ExecutionPeriod; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.student.Registration; import net.sourceforge.fenixedu.domain.student.Student; import org.apache.commons.collections.comparators.ComparatorChain; public class DelegateCurricularCourseBean implements Serializable { private DomainReference curricularCourse; private DomainReference executionYear; private DomainReference executionPeriod; private List> enrolledStudents; private Integer curricularYear; static final public Comparator CURRICULAR_COURSE_COMPARATOR_BY_CURRICULAR_YEAR_AND_CURRICULAR_SEMESTER = new ComparatorChain(); static { ((ComparatorChain) CURRICULAR_COURSE_COMPARATOR_BY_CURRICULAR_YEAR_AND_CURRICULAR_SEMESTER) .addComparator(new IscteBeanComparator("curricularYear")); ((ComparatorChain) CURRICULAR_COURSE_COMPARATOR_BY_CURRICULAR_YEAR_AND_CURRICULAR_SEMESTER) .addComparator(new IscteBeanComparator("curricularSemester")); } public DelegateCurricularCourseBean(CurricularCourse curricularCourse, ExecutionYear executionYear, Integer curricularYear, ExecutionPeriod executionPeriod) { setCurricularCourse(curricularCourse); setExecutionYear(executionYear); setCurricularYear(curricularYear); setExecutionPeriod(executionPeriod); } public CurricularCourse getCurricularCourse() { return (curricularCourse == null ? null : curricularCourse.getObject()); } public void setCurricularCourse(CurricularCourse curricularCourse) { this.curricularCourse = new DomainReference(curricularCourse); } public ExecutionYear getExecutionYear() { return (executionYear == null ? null : executionYear.getObject()); } public void setExecutionYear(ExecutionYear executionYear) { this.executionYear = new DomainReference(executionYear); } public ExecutionPeriod getExecutionPeriod() { return (executionPeriod == null ? null : executionPeriod.getObject()); } public void setExecutionPeriod(ExecutionPeriod executionPeriod) { this.executionPeriod = new DomainReference(executionPeriod); } public List getEnrolledStudents() { List result = new ArrayList(); for(DomainReference studentDR : this.enrolledStudents) { result.add(studentDR.getObject()); } return result; } public void setEnrolledStudents (List students) { this.enrolledStudents = new ArrayList>(); for(Student student : students) { this.enrolledStudents.add(new DomainReference(student)); } } public void calculateEnrolledStudents() { List enrolledStudents = new ArrayList(); for(Enrolment enrolment : getCurricularCourse().getEnrolmentsByExecutionPeriod(getExecutionPeriod())) { Registration registration = enrolment.getRegistration(); if(registration.getCurricularYear(getExecutionYear()) == getCurricularYear()) { enrolledStudents.add(registration.getStudent()); } } Collections.sort(enrolledStudents,Student.NUMBER_COMPARATOR); setEnrolledStudents(enrolledStudents); } public Integer getSemester() { return getCurricularSemester(); } public Integer getCurricularSemester() { return getExecutionPeriod().getSemester(); } public Integer getCurricularYear() { return curricularYear; } public void setCurricularYear(Integer curricularYear) { this.curricularYear = curricularYear; } public Integer getEnrolledStudentsNumber() { if (this.enrolledStudents != null) { return this.enrolledStudents.size(); } return 0; } }