Package org.fenixedu.academic.ui.spring.controller.teacher

Source Code of org.fenixedu.academic.ui.spring.controller.teacher.ExecutionCourseController

/**
* 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.spring.controller.teacher;

import java.util.Optional;

import org.fenixedu.academic.domain.ExecutionCourse;
import org.fenixedu.academic.domain.Person;
import org.fenixedu.academic.domain.Professorship;
import org.fenixedu.academic.predicate.AccessControl;
import org.fenixedu.academic.ui.spring.StrutsFunctionalityController;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;

public abstract class ExecutionCourseController extends StrutsFunctionalityController {

    ExecutionCourse executionCourse;

    public ExecutionCourseController() {
        super();
    }

    private static Professorship findProfessorship(final ExecutionCourse executionCourse) {
        final Person person = AccessControl.getPerson();
        if (person != null) {
            Optional<Professorship> professorshipOpt =
                    person.getProfessorshipsSet().stream()
                            .filter(professorship -> professorship.getExecutionCourse().equals(executionCourse)).findFirst();
            if (professorshipOpt.isPresent()) {
                Professorship prof = professorshipOpt.get();
                if (!prof.getPermissions().getGroups()) {
                    throw new RuntimeException("Professor is not authorized to manage the student groups");
                } else {
                    return prof;
                }
            }
        }
        throw new RuntimeException("User is not authorized to manage the selected course!");
    }

    @ModelAttribute("projectGroup")
    public ProjectGroupBean setProjectGroup() {
        return new ProjectGroupBean();
    }

    @ModelAttribute("professorship")
    public Professorship setProfessorship(@PathVariable ExecutionCourse executionCourse) {
        return findProfessorship(executionCourse);
    }

    @ModelAttribute("executionCourse")
    public ExecutionCourse getExecutionCourse(@PathVariable ExecutionCourse executionCourse) {
        this.executionCourse = executionCourse;
        return executionCourse;
    }
}
TOP

Related Classes of org.fenixedu.academic.ui.spring.controller.teacher.ExecutionCourseController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.