001/* 002 * Copyright 2018 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.linkdirectory.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.linkdirectory.Link; 029import org.ametys.plugins.linkdirectory.link.LinkDAO; 030import org.ametys.plugins.repository.AmetysObjectResolver; 031 032/** 033 * {@link RightAssignmentContext} for assign rights to a {@link Link} 034 */ 035public class LinkDirectoryRightAssignmentContext extends AbstractStaticRightAssignmentContext 036{ 037 /** The id if this right context */ 038 public static final String ID = "right.assignment.context.linkdirectoryaccess"; 039 040 /** The Ametys object resolver */ 041 protected AmetysObjectResolver _resolver; 042 /** the link DAO */ 043 protected LinkDAO _linkDAO; 044 045 @Override 046 public void service(ServiceManager smanager) throws ServiceException 047 { 048 super.service(smanager); 049 _linkDAO = (LinkDAO) smanager.lookup(LinkDAO.ROLE); 050 _resolver = (AmetysObjectResolver) smanager.lookup(AmetysObjectResolver.ROLE); 051 } 052 053 @Override 054 public Object convertJSContext(Object context) 055 { 056 if (context instanceof String) 057 { 058 return _resolver.resolveById((String) context); 059 } 060 return null; 061 } 062 063 @Override 064 public String getContextIdentifier(Object context) 065 { 066 if (context instanceof Link) 067 { 068 return ((Link) context).getTitle(); 069 } 070 return null; 071 } 072 073 @Override 074 public Set<Object> getParentContexts(Object context) 075 { 076 return null; 077 } 078 079 @Override 080 public List<Object> getRootContexts(Map<String, Object> contextParameters) 081 { 082 return new ArrayList<>(); 083 } 084}