package net.sourceforge.fenixedu.presentationTier.backBeans.departmentAdmOffice; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.faces.event.ActionEvent; import javax.faces.model.SelectItem; import net.sourceforge.fenixedu.applicationTier.Filtro.exception.FenixFilterException; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.FenixServiceException; import net.sourceforge.fenixedu.dataTransferObject.comparators.IscteBeanComparator; import net.sourceforge.fenixedu.domain.Department; import net.sourceforge.fenixedu.domain.Employee; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.accessControl.Group; import net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.utils.ServiceUtils; import net.sourceforge.fenixedu.presentationTier.backBeans.base.FenixBackingBean; import org.apache.commons.collections.comparators.ComparatorChain; public class ManagementGroupsBackingBean extends FenixBackingBean { private List employees = getEmployees(); private Integer[] selectedPersonsIDsToAdd; private Integer[] selectedPersonsIDsToRemove; public Department getDepartment() { return (getUserView().getPerson().getEmployee() != null) ? getUserView().getPerson() .getEmployee().getCurrentDepartmentWorkingPlace() : null; } public List getEmployees() { List result = (getDepartment() != null) ? new ArrayList(getDepartment().getAllCurrentActiveWorkingEmployees()) : null; if (result != null) { ComparatorChain chainComparator = new ComparatorChain(); chainComparator.addComparator(new IscteBeanComparator("person.name"), false); chainComparator.addComparator(new IscteBeanComparator("employeeNumber"), false); Collections.sort(result, chainComparator); } return result; } public List getDepartmentEmployeesSelectItems() { Group competenceCoursesManagementGroup = getDepartment().getCompetenceCourseMembersGroup(); List result = new ArrayList(employees.size()); for (Employee departmentEmployee : employees) { Person person = departmentEmployee.getPerson(); if (competenceCoursesManagementGroup == null || !competenceCoursesManagementGroup.isMember(person)) { result.add(new SelectItem(person.getIdInternal(), person.getName() + " (" + person.getUsername() + ")")); } } return result; } public int getDepartmentEmployeesSize() { return employees.size(); } public List getSelectedDepartmentEmployeesSelectItems() throws FenixFilterException, FenixServiceException { List result = new ArrayList(); Group competenceCoursesManagementGroup = getDepartment().getCompetenceCourseMembersGroup(); if (competenceCoursesManagementGroup != null) { for(Person person: competenceCoursesManagementGroup.getElements()) { result.add(new SelectItem(person.getIdInternal(), person.getName() + " (" + person.getUsername() + ")")); } } return result; } public void setSelectedPersonsIDsToAdd(Integer[] selectedPersonsIDs) { this.selectedPersonsIDsToAdd = selectedPersonsIDs; } public Integer[] getSelectedPersonsIDsToAdd() { return selectedPersonsIDsToAdd; } public void setSelectedPersonsIDsToRemove(Integer[] selectedPersonsIDsToRemove) { this.selectedPersonsIDsToRemove = selectedPersonsIDsToRemove; } public Integer[] getSelectedPersonsIDsToRemove() { return selectedPersonsIDsToRemove; } public void addMembers(ActionEvent event) throws FenixFilterException, FenixServiceException { if (selectedPersonsIDsToAdd != null) { Object[] args = { getDepartment(), selectedPersonsIDsToAdd, null }; ServiceUtils.executeService( "UpdateDepartmentsCompetenceCourseManagementGroup", args); } // avoid preset check-boxes after action selectedPersonsIDsToAdd = null; selectedPersonsIDsToRemove = null; } public void removeMembers(ActionEvent event) throws FenixFilterException, FenixServiceException { if (selectedPersonsIDsToRemove != null) { Object[] args = { getDepartment(), null, selectedPersonsIDsToRemove }; ServiceUtils.executeService( "UpdateDepartmentsCompetenceCourseManagementGroup", args); } // avoid preset check-boxes after action selectedPersonsIDsToAdd = null; selectedPersonsIDsToRemove = null; } }