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