001/* 002 * (C) Copyright 2006-2012 Nuxeo SA (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 */ 018 019package org.nuxeo.connect.client.we; 020 021import javax.ws.rs.GET; 022import javax.ws.rs.Path; 023import javax.ws.rs.Produces; 024import javax.ws.rs.QueryParam; 025import javax.ws.rs.core.Response; 026 027import org.nuxeo.ecm.admin.NuxeoCtlManager; 028import org.nuxeo.ecm.core.api.NuxeoPrincipal; 029import org.nuxeo.ecm.webengine.model.Access; 030import org.nuxeo.ecm.webengine.model.Resource; 031import org.nuxeo.ecm.webengine.model.WebObject; 032import org.nuxeo.ecm.webengine.model.impl.ModuleRoot; 033 034/** 035 * Root object: mainly acts as a router. 036 * 037 * @author <a href="mailto:td@nuxeo.com">Thierry Delprat</a> 038 */ 039@Path("/connectClient") 040@WebObject(type = "connectClientRoot", administrator = Access.GRANT) 041public class ConnectClientRoot extends ModuleRoot { 042 043 @Path(value = "packages") 044 public Resource listPackages() { 045 return ctx.newObject("packageListingProvider"); 046 } 047 048 @Path(value = "download") 049 public Resource download() { 050 return ctx.newObject("downloadHandler"); 051 } 052 053 @Path(value = "install") 054 public Resource install() { 055 return ctx.newObject("installHandler"); 056 } 057 058 @Path(value = "uninstall") 059 public Resource uninstall() { 060 return ctx.newObject("uninstallHandler"); 061 } 062 063 @Path(value = "remove") 064 public Resource remove() { 065 return ctx.newObject("removeHandler"); 066 } 067 068 @GET 069 @Produces("text/html") 070 @Path(value = "restartView") 071 public Object restartServerView() { 072 if (((NuxeoPrincipal) getContext().getPrincipal()).isAdministrator()) { 073 return getView("serverRestart").arg("nuxeoctl", new NuxeoCtlManager()); 074 } else { 075 return Response.status(Response.Status.UNAUTHORIZED).build(); 076 } 077 } 078 079 @GET 080 @Produces("text/html") 081 @Path(value = "registerInstanceCallback") 082 public Object registerInstanceCallback(@QueryParam("ConnectRegistrationToken") String token) { 083 return getView("registerInstanceCallback").arg("token", token); 084 } 085}