/** * Copyright © 2002 Instituto Superior Técnico * * This file is part of FenixEdu Academic. * * FenixEdu Academic is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * FenixEdu Academic is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with FenixEdu Academic. If not, see <http://www.gnu.org/licenses/>. */ package org.fenixedu.academic.ui.struts.action.coordinator; import java.util.Set; import java.util.TreeSet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.fenixedu.academic.domain.Coordinator; import org.fenixedu.academic.domain.DegreeCurricularPlan; import org.fenixedu.academic.domain.ExecutionDegree; import org.fenixedu.academic.domain.Person; import org.fenixedu.academic.domain.ScientificCommission; import org.fenixedu.academic.domain.degree.degreeCurricularPlan.DegreeCurricularPlanState; import org.fenixedu.academic.predicate.AccessControl; import org.fenixedu.academic.service.services.exceptions.FenixServiceException; import org.fenixedu.academic.ui.struts.action.base.FenixAction; import org.fenixedu.academic.ui.struts.action.coordinator.CoordinatorApplication.CoordinatorManagementApp; import org.fenixedu.bennu.struts.annotations.Forward; import org.fenixedu.bennu.struts.annotations.Forwards; import org.fenixedu.bennu.struts.annotations.Mapping; import org.fenixedu.bennu.struts.portal.StrutsFunctionality; @StrutsFunctionality(app = CoordinatorManagementApp.class, path = "choose-degree", titleKey = "label.degrees") @Mapping(path = "/index", module = "coordinator") @Forwards(@Forward(name = "ChooseDegree", path = "/coordinator/chooseDegreePage.jsp")) public class CoordinatorDegreeManagement extends FenixAction { @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { request.setAttribute("degrees", readCoordinatedDegrees()); return mapping.findForward("ChooseDegree"); } public static Set<DegreeCurricularPlan> readCoordinatedDegrees() throws FenixServiceException { final Person person = AccessControl.getPerson(); final Set<DegreeCurricularPlan> activeDegreeCurricularPlans = new TreeSet<DegreeCurricularPlan>( DegreeCurricularPlan.DEGREE_CURRICULAR_PLAN_COMPARATOR_BY_DEGREE_TYPE_AND_EXECUTION_DEGREE_AND_DEGREE_CODE); for (final Coordinator coordinator : person.getCoordinatorsSet()) { final ExecutionDegree executionDegree = coordinator.getExecutionDegree(); final DegreeCurricularPlan degreeCurricularPlan = executionDegree.getDegreeCurricularPlan(); if (degreeCurricularPlan.getState() == DegreeCurricularPlanState.ACTIVE) { activeDegreeCurricularPlans.add(degreeCurricularPlan); } } for (ScientificCommission commission : person.getScientificCommissionsSet()) { ExecutionDegree executionDegree = commission.getExecutionDegree(); DegreeCurricularPlan degreeCurricularPlan = executionDegree.getDegreeCurricularPlan(); if (degreeCurricularPlan.getState() == DegreeCurricularPlanState.ACTIVE) { activeDegreeCurricularPlans.add(degreeCurricularPlan); } } return activeDegreeCurricularPlans; } }