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