package net.sourceforge.fenixedu.domain.accessControl; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import net.sourceforge.fenixedu.domain.CurricularCourse; import net.sourceforge.fenixedu.domain.DomainReference; import net.sourceforge.fenixedu.domain.Enrolment; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.accessControl.groups.language.Argument; import net.sourceforge.fenixedu.domain.student.Registration; import net.sourceforge.fenixedu.domain.student.Student; import pt.ist.fenixWebFramework.renderers.utils.RenderUtils; public class DelegateCurricularCourseStudentsGroup extends LeafGroup { private static final long serialVersionUID = 1L; private final DomainReference curricularCourse; private final DomainReference executionYear; private final List> enrolledStudents; public DelegateCurricularCourseStudentsGroup(CurricularCourse curricularCourse, ExecutionYear executionYear) { this.curricularCourse = new DomainReference(curricularCourse); this.executionYear = new DomainReference(executionYear); this.enrolledStudents = new ArrayList>(); for (Student student : getStudentsEnrolledIn(getCurricularCourse(), getExecutionYear())) { this.enrolledStudents.add(new DomainReference(student.getPerson())); } } @Override public Set getElements() { Set people = new HashSet(); for (Student student : getStudentsEnrolledIn(getCurricularCourse(), getExecutionYear())) { people.add(student.getPerson()); } return people; } @Override protected Argument[] getExpressionArguments() { return new Argument[] {}; } @Override public boolean isMember(Person person) { if (person.hasStudent()) { if (getElements().contains(person.getStudent())) { return true; } } return false; } @Override public String getName() { return getCurricularCourse().getName() + " - " + getNumberOfEnrolledStudents() + " " + RenderUtils.getResourceString("DELEGATES_RESOURCES", "label.enrolledStudents"); } public ExecutionYear getExecutionYear() { return (executionYear != null ? executionYear.getObject() : null); } public CurricularCourse getCurricularCourse() { return (curricularCourse != null ? curricularCourse.getObject() : null); } private int getNumberOfEnrolledStudents() { if (this.enrolledStudents != null) { return this.enrolledStudents.size(); } else { return 0; } } private List getStudentsEnrolledIn(CurricularCourse curricularCourse, ExecutionYear executionYear) { List result = new ArrayList(); for (Enrolment enrolment : curricularCourse.getEnrolmentsByExecutionYear(executionYear)) { Registration registration = enrolment.getRegistration(); result.add(registration.getStudent()); } return result; } }