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.domain.CurricularCourse; import net.sourceforge.fenixedu.domain.DomainReference; import net.sourceforge.fenixedu.domain.Enrolment; import net.sourceforge.fenixedu.domain.ExecutionSemester; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.student.Student; import org.apache.commons.beanutils.BeanComparator; import org.apache.commons.collections.comparators.ComparatorChain; public class DelegateCurricularCourseBean implements Serializable { private DomainReference curricularCourse; private DomainReference executionYear; private DomainReference executionSemester; 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 BeanComparator("curricularYear")); ((ComparatorChain) CURRICULAR_COURSE_COMPARATOR_BY_CURRICULAR_YEAR_AND_CURRICULAR_SEMESTER) .addComparator(new BeanComparator("curricularSemester")); } public DelegateCurricularCourseBean(CurricularCourse curricularCourse, ExecutionYear executionYear, Integer curricularYear, ExecutionSemester executionSemester) { setCurricularCourse(curricularCourse); setExecutionYear(executionYear); setCurricularYear(curricularYear); setExecutionPeriod(executionSemester); } 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 ExecutionSemester getExecutionPeriod() { return (executionSemester == null ? null : executionSemester.getObject()); } public void setExecutionPeriod(ExecutionSemester executionSemester) { this.executionSemester = new DomainReference(executionSemester); } 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())) { enrolledStudents.add(enrolment.getRegistration().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; } @Override public boolean equals(Object obj) { return obj instanceof DelegateCurricularCourseBean ? equals((DelegateCurricularCourseBean) obj) : false; } public boolean equals(DelegateCurricularCourseBean delegateCurricularCourseBean) { return getCurricularCourse().equals(delegateCurricularCourseBean.getCurricularCourse()) && getCurricularYear().equals(delegateCurricularCourseBean.getCurricularYear()) && getExecutionPeriod().equals(delegateCurricularCourseBean.getExecutionPeriod()) && getExecutionYear().equals(delegateCurricularCourseBean.getExecutionYear()); } @Override public int hashCode() { return getCurricularCourse().hashCode() + getCurricularYear().hashCode() + getExecutionPeriod().hashCode() + getExecutionYear().hashCode(); } }