package net.sourceforge.fenixedu.domain.accessControl; import java.util.Collection; import java.util.Set; import net.sourceforge.fenixedu.domain.Department; import net.sourceforge.fenixedu.domain.Employee; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.Person; public class DepartmentEmployeesByExecutionYearGroup extends DepartmentByExecutionYearGroup { /** * */ private static final long serialVersionUID = 8466471514890333054L; public DepartmentEmployeesByExecutionYearGroup(ExecutionYear executionYear, Department department) { super(executionYear, department); } public DepartmentEmployeesByExecutionYearGroup(String executionYear, String department) { super(executionYear, department); } @Override public Set getElements() { Set elements = super.buildSet(); Collection departmentEmployees = getDepartment().getAllWorkingEmployees( getExecutionYear().getBeginDateYearMonthDay(), getExecutionYear().getEndDateYearMonthDay()); for (Employee employee : departmentEmployees) { elements.add(employee.getPerson()); } return super.freezeSet(elements); } @Override public boolean isMember(Person person) { if (person != null && person.hasEmployee()) { final Department lastDepartmentWorkingPlace = person.getEmployee().getLastDepartmentWorkingPlace( getExecutionYear().getBeginDateYearMonthDay(), getExecutionYear().getEndDateYearMonthDay()); return (lastDepartmentWorkingPlace != null && lastDepartmentWorkingPlace.equals(getDepartment())); } return false; } public static class Builder extends DepartmentByExecutionYearGroup.Builder { @Override protected DepartmentByExecutionYearGroup buildConcreteGroup(String year, String department) { return new DepartmentEmployeesByExecutionYearGroup(year, department); } } }