001/*
002 *  Copyright 2021 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.extraction.rights;
017
018import java.util.ArrayList;
019import java.util.HashSet;
020import java.util.List;
021import java.util.Map;
022import java.util.Set;
023
024import org.ametys.core.right.RightAssignmentContext;
025import org.ametys.plugins.core.impl.right.StringRightAssignmentContext;
026import org.ametys.plugins.extraction.execution.Extraction;
027
028/**
029 * {@link RightAssignmentContext} for assign rights to a {@link Extraction}
030 */
031public class ExtractionRightAssignmentContext extends StringRightAssignmentContext
032{
033    @Override
034    public Set<Object> getParentContexts(Object context)
035    {
036        Set<Object> parents = new HashSet<>();
037        if (context instanceof String && !context.equals(ExtractionAccessController.ROOT_CONTEXT))
038        {
039            String contextString = (String) context;
040            String parent = contextString.substring(0, contextString.lastIndexOf('/'));
041            parents.add(parent);
042        }
043        return parents;
044    }
045
046    @Override
047    public List<Object> getRootContexts(Map<String, Object> contextParameters)
048    {
049        List<Object> rootContexts = new ArrayList<>();
050
051        rootContexts.add(ExtractionAccessController.ROOT_CONTEXT);
052        
053        return rootContexts;
054    }
055}