001package org.nuxeo.template.jaxrs;
002
003import javax.ws.rs.GET;
004import javax.ws.rs.Path;
005import javax.ws.rs.PathParam;
006
007import org.nuxeo.ecm.core.api.CoreSession;
008import org.nuxeo.ecm.webengine.model.WebObject;
009import org.nuxeo.ecm.webengine.model.impl.ModuleRoot;
010import org.nuxeo.runtime.transaction.TransactionHelper;
011
012/**
013 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a>
014 */
015@WebObject(type = "templateRoot")
016@Path("/templates")
017public class RootResource extends ModuleRoot {
018
019    @GET
020    public String index() {
021        String sid = getContext().getCoreSession().getSessionId();
022        return "ok :sid =" + sid;
023    }
024
025    protected CoreSession getCoreSession() {
026        TransactionHelper.startTransaction();
027
028        return getContext().getCoreSession();
029    }
030
031    @GET
032    @Path("ping")
033    public String getPong() {
034        return "pong";
035    }
036
037    @Path("templates")
038    public Object getTemplates() {
039        return getContext().newObject("templateResource");
040    }
041
042    @Path("docs")
043    public Object getDocs() {
044        return getContext().newObject("templateBasedResource");
045    }
046
047    @Path("template/{id}")
048    public Object getTemplates(@PathParam(value = "id") String id) {
049        return getContext().newObject("templateResource", id);
050    }
051
052    @Path("doc/{id}")
053    public Object getDocs(@PathParam(value = "id") String id) {
054        return getContext().newObject("templateBasedResource", id);
055    }
056
057}