001/*
002 * (C) Copyright 2006-2009 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.webengine.admin;
021
022import javax.ws.rs.DELETE;
023import javax.ws.rs.GET;
024import javax.ws.rs.POST;
025import javax.ws.rs.PUT;
026import javax.ws.rs.Path;
027import javax.ws.rs.Produces;
028import javax.ws.rs.core.Response;
029
030import org.nuxeo.ecm.core.api.NuxeoGroup;
031import org.nuxeo.ecm.platform.usermanager.UserManager;
032import org.nuxeo.ecm.webengine.model.WebObject;
033import org.nuxeo.ecm.webengine.model.impl.DefaultObject;
034import org.nuxeo.runtime.api.Framework;
035
036@WebObject(type = "Group")
037@Produces("text/html;charset=UTF-8")
038public class Group extends DefaultObject {
039
040    NuxeoGroup group;
041
042    @Override
043    protected void initialize(Object... args) {
044        assert args != null && args.length > 0;
045        group = (NuxeoGroup) args[0];
046    }
047
048    @GET
049    public Object doGet() {
050        return getView("index").arg("group", group);
051    }
052
053    @POST
054    public Response doPost() {
055        return redirect(getPrevious().getPath());
056    }
057
058    @PUT
059    public Response doPut() {
060        return redirect(getPath());
061    }
062
063    @DELETE
064    public Response doDelete() {
065        UserManager userManager = Framework.getService(UserManager.class);
066        userManager.deleteGroup(group);
067        return redirect(getPrevious().getPath());
068    }
069
070    @POST
071    @Path("@put")
072    public Response simulatePut() {
073        return doPut();
074    }
075
076    @GET
077    @Path("@delete")
078    public Response simulateDelete() {
079        return doDelete();
080    }
081
082}