001/*
002 * (C) Copyright 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 *     Thierry Delprat
018 */
019package org.nuxeo.template.xdocreport.jaxrs;
020
021import javax.ws.rs.GET;
022import javax.ws.rs.Path;
023
024import org.nuxeo.ecm.core.api.CoreSession;
025import org.nuxeo.ecm.webengine.model.WebObject;
026import org.nuxeo.ecm.webengine.model.impl.ModuleRoot;
027import org.nuxeo.runtime.transaction.TransactionHelper;
028
029/**
030 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a>
031 */
032@WebObject(type = "xdocRestRoot")
033@Path("/xdoctemplates")
034public class RootResource extends ModuleRoot {
035
036    @GET
037    public String index() {
038        String sid = getContext().getCoreSession().toString();
039        return "ok :sid =" + sid;
040    }
041
042    protected CoreSession getCoreSession() {
043        TransactionHelper.startTransaction();
044
045        return getContext().getCoreSession();
046    }
047
048    @GET
049    @Path("ping")
050    public String getPong() {
051        return "pong";
052    }
053
054    @Path("resources")
055    public ResourceService getResourceService() {
056        return new ResourceService(getContext().getCoreSession());
057    }
058
059    @Path("xdocresources")
060    public XDocReportResourceService getXDocResourceService() {
061        return new XDocReportResourceService(getContext().getCoreSession());
062    }
063
064    @Path("reports")
065    public ReportService getReportService() {
066        return new ReportService();
067    }
068
069}