/** * */ package net.sourceforge.fenixedu.predicates; import java.util.ArrayList; import java.util.Collection; import com.linkare.commons.metainfo.Linkare; import net.sourceforge.fenixedu.domain.CompetenceCourse; import net.sourceforge.fenixedu.domain.DegreeCurricularPlan; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.accessControl.Group; import net.sourceforge.fenixedu.domain.accessControl.GroupUnion; import net.sourceforge.fenixedu.domain.person.RoleType; import net.sourceforge.fenixedu.injectionCode.AccessControl; import net.sourceforge.fenixedu.injectionCode.AccessControlPredicate; import net.sourceforge.fenixedu.injectionCode.IGroup; /** * @author - Shezad Anavarali (shezad@ist.utl.pt) * */ public class CompetenceCoursePredicates { public static final AccessControlPredicate readPredicate = new AccessControlPredicate() { public boolean evaluate(CompetenceCourse competenceCourse) { if (!competenceCourse.isBolonha()) { return true; } Person person = AccessControl.getPerson(); if (person.hasRole(RoleType.SCIENTIFIC_COUNCIL)) { return true; } boolean isDegreeCurricularPlansMember = false; isDegreeCurricularPlansMember = isMemberOfDegreeCurricularPlansGroup(person); boolean isCompetenceGroupMember = isMemberOfCompetenceCourseGroup(competenceCourse, person); switch (competenceCourse.getCurricularStage()) { case DRAFT: return isCompetenceGroupMember; case PUBLISHED: return isCompetenceGroupMember || isDegreeCurricularPlansMember; case APPROVED: return true; default: return false; } } }; public static final AccessControlPredicate writePredicate = new AccessControlPredicate() { public boolean evaluate(CompetenceCourse competenceCourse) { if (!competenceCourse.isBolonha()) { return true; } Person person = AccessControl.getPerson(); if (person.hasRole(RoleType.MANAGER)) { return true; } boolean isDegreeCurricularPlansMember = false; isDegreeCurricularPlansMember = isMemberOfDegreeCurricularPlansGroup(person); boolean isCompetenceGroupMember = isMemberOfCompetenceCourseGroup(competenceCourse, person); switch (competenceCourse.getCurricularStage()) { case DRAFT: return isCompetenceGroupMember; case PUBLISHED: return isCompetenceGroupMember || isDegreeCurricularPlansMember; case APPROVED: return person.hasRole(RoleType.SCIENTIFIC_COUNCIL); default: return false; } } }; public static final AccessControlPredicate editCurricularStagePredicate = new AccessControlPredicate() { @Linkare(author = "Paulo Zenida", comments = "Included skip operation for manager roles") public boolean evaluate(CompetenceCourse competenceCourse) { Person person = AccessControl.getPerson(); if (person.hasRole(RoleType.MANAGER)) { return true; } boolean isCompetenceGroupMember = isMemberOfCompetenceCourseGroup(competenceCourse, person); switch (competenceCourse.getCurricularStage()) { case DRAFT: return isCompetenceGroupMember; case PUBLISHED: return isCompetenceGroupMember || person.hasRole(RoleType.SCIENTIFIC_COUNCIL); case APPROVED: return person.hasRole(RoleType.SCIENTIFIC_COUNCIL); default: return false; } } }; private static boolean isMemberOfDegreeCurricularPlansGroup(Person person) { Collection degreeCurricularPlans = DegreeCurricularPlan.readNotEmptyDegreeCurricularPlans(); Collection groups = new ArrayList(); for (DegreeCurricularPlan plan : degreeCurricularPlans) { Group curricularPlanMembersGroup = plan.getCurricularPlanMembersGroup(); if (curricularPlanMembersGroup != null) { groups.add(curricularPlanMembersGroup); } } return new GroupUnion(groups).isMember(person); } private static boolean isMemberOfCompetenceCourseGroup(CompetenceCourse competenceCourse, Person person) { Group competenceCourseMembersGroup = competenceCourse.getDepartmentUnit().getDepartment() .getCompetenceCourseMembersGroup(); if (competenceCourseMembersGroup != null) { return competenceCourseMembersGroup.isMember(person); } return false; } }