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.workspaces.project;
017
018import java.util.Map;
019
020import org.apache.avalon.framework.service.ServiceException;
021import org.apache.avalon.framework.service.ServiceManager;
022
023import org.ametys.core.ui.Callable;
024import org.ametys.core.user.UserIdentity;
025import org.ametys.plugins.workspaces.members.ProjectMemberManager;
026import org.ametys.web.administration.SuperUserClientSideElement;
027
028/**
029 * This implementation creates a control allowing to affect a super user to a given context of a project.
030 * This implementation does NOT set the super user on project'site.
031 */
032public class ProjectSuperUserClientSideElement extends SuperUserClientSideElement
033{
034    /** The project user manager */
035    protected ProjectMemberManager _projectUserManager;
036    
037    @Override
038    public void service(ServiceManager smanager) throws ServiceException
039    {
040        super.service(smanager);
041        _projectUserManager = (ProjectMemberManager) smanager.lookup(ProjectMemberManager.ROLE);
042    }
043    
044    @Override
045    @Callable
046    public void affectUserToProfile(Map<String, String> user, String profileId, Map<String, Object> jsParameters)
047    {
048        UserIdentity userIdentity = new UserIdentity(user.get("login"), user.get("populationId"));
049        _projectUserManager.setProjectManager((String) jsParameters.get("projectName"), profileId, userIdentity);
050    }
051
052}