001/* 002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others. 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 * 016 * Contributors: 017 * dmetzler 018 */ 019package org.nuxeo.ecm.restapi.server.jaxrs.usermanager; 020 021import java.io.Serializable; 022 023import javax.ws.rs.Path; 024import javax.ws.rs.PathParam; 025 026import org.nuxeo.ecm.core.api.DocumentModel; 027import org.nuxeo.ecm.core.api.NuxeoGroup; 028import org.nuxeo.ecm.core.api.NuxeoPrincipal; 029import org.nuxeo.ecm.platform.usermanager.UserManager; 030import org.nuxeo.ecm.webengine.model.WebObject; 031import org.nuxeo.ecm.webengine.model.exceptions.WebResourceNotFoundException; 032import org.nuxeo.runtime.api.Framework; 033 034/** 035 * @since 5.7.3 036 */ 037@WebObject(type = "group") 038public class GroupObject extends AbstractUMObject<NuxeoGroup> { 039 040 @Path("user/{username}") 041 public Object doGetUserToGroup(@PathParam("username") String username) { 042 UserManager um = Framework.getService(UserManager.class); 043 NuxeoPrincipal principal = um.getPrincipal(username); 044 if (principal == null) { 045 throw new WebResourceNotFoundException("User not found"); 046 } 047 return newObject("userToGroup", principal, currentArtifact); 048 } 049 050 @Override 051 protected NuxeoGroup updateArtifact(NuxeoGroup updateGroup) { 052 um.updateGroup(updateGroup.getModel()); 053 return um.getGroup(currentArtifact.getName()); 054 } 055 056 @Override 057 protected void deleteArtifact() { 058 um.deleteGroup(um.getGroupModel(currentArtifact.getName())); 059 } 060 061 @Override 062 protected boolean isAPowerUserEditableArtifact() { 063 return GroupRootObject.isAPowerUserEditableGroup(currentArtifact); 064 } 065}