001/* 002 * Copyright 2016 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.survey.right; 017 018import java.util.ArrayList; 019import java.util.List; 020import java.util.Map; 021import java.util.Set; 022 023import org.apache.avalon.framework.service.ServiceException; 024import org.apache.avalon.framework.service.ServiceManager; 025 026import org.ametys.core.right.AbstractStaticRightAssignmentContext; 027import org.ametys.core.right.RightAssignmentContext; 028import org.ametys.plugins.repository.AmetysObjectResolver; 029import org.ametys.plugins.survey.repository.Survey; 030 031/** 032 * {@link RightAssignmentContext} for assign rights to a {@link Survey} 033 */ 034public class SurveyRightAssignmentContext extends AbstractStaticRightAssignmentContext 035{ 036 /** The id if this right context */ 037 public static final String ID = "right.assignment.context.surveyaccess"; 038 039 /** The Ametys object resolver */ 040 protected AmetysObjectResolver _resolver; 041 042 @Override 043 public void service(ServiceManager smanager) throws ServiceException 044 { 045 super.service(smanager); 046 _resolver = (AmetysObjectResolver) smanager.lookup(AmetysObjectResolver.ROLE); 047 } 048 049 @Override 050 public Object convertJSContext(Object context) 051 { 052 if (context instanceof String) 053 { 054 return _resolver.resolveById((String) context); 055 } 056 return null; 057 } 058 059 @Override 060 public String getContextIdentifier(Object context) 061 { 062 if (context instanceof Survey) 063 { 064 return ((Survey) context).getId(); 065 } 066 return null; 067 } 068 069 @Override 070 public Set<Object> getParentContexts(Object context) 071 { 072 return null; 073 } 074 075 @Override 076 public List<Object> getRootContexts(Map<String, Object> contextParameters) 077 { 078 return new ArrayList<>(); 079 } 080}