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 Ametys object resolver */
037    protected AmetysObjectResolver _resolver;
038
039    @Override
040    public void service(ServiceManager smanager) throws ServiceException
041    {
042        super.service(smanager);
043        _resolver = (AmetysObjectResolver) smanager.lookup(AmetysObjectResolver.ROLE);
044    }
045    
046    @Override
047    public Object convertJSContext(Object context)
048    {
049        if (context instanceof String)
050        {
051            return _resolver.resolveById((String) context);
052        }
053        return null;
054    }
055    
056    @Override
057    public String getContextIdentifier(Object context)
058    {
059        if (context instanceof Survey)
060        {
061            return ((Survey) context).getId();
062        }
063        return null;
064    }
065    
066    @Override
067    public Set<Object> getParentContexts(Object context)
068    {
069        return null;
070    }
071    
072    @Override
073    public List<Object> getRootContexts(Map<String, Object> contextParameters)
074    {
075        return new ArrayList<>();
076    }
077}