001/* 002 * (C) Copyright 2006-2009 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 016 */ 017 018package org.nuxeo.ecm.platform.publisher.remoting.restHandler; 019 020import java.util.Map; 021 022import javax.ws.rs.GET; 023import javax.ws.rs.POST; 024import javax.ws.rs.Path; 025import javax.ws.rs.PathParam; 026import javax.ws.rs.Produces; 027import javax.ws.rs.core.Response; 028 029import org.nuxeo.ecm.core.api.DocumentLocation; 030import org.nuxeo.ecm.core.api.DocumentModel; 031import org.nuxeo.ecm.platform.publisher.api.PublicationNode; 032import org.nuxeo.ecm.platform.publisher.api.PublishedDocument; 033import org.nuxeo.ecm.platform.publisher.api.RemotePublicationTreeManager; 034import org.nuxeo.ecm.webengine.model.impl.DefaultObject; 035import org.nuxeo.runtime.api.Framework; 036 037@Path("remotepublisher") 038@Produces("nuxeo/remotepub;charset=UTF-8") 039public class RestPublishingHandler extends DefaultObject { 040 041 protected RemotePublicationTreeManager getPublisher() { 042 return Framework.getLocalService(RemotePublicationTreeManager.class); 043 } 044 045 @POST 046 @Path("getChildrenDocuments") 047 public RemotePubResult getChildrenDocuments(RemotePubParam param) { 048 return new RemotePubResult(getPublisher().getChildrenDocuments(param.getAsNode())); 049 } 050 051 @POST 052 @Path("getChildrenNodes") 053 public RemotePubResult getChildrenNodes(RemotePubParam param) { 054 return new RemotePubResult(getPublisher().getChildrenNodes(param.getAsNode())); 055 } 056 057 @POST 058 @Path("getParent") 059 public RemotePubResult getParent(RemotePubParam param) { 060 return new RemotePubResult(getPublisher().getParent(param.getAsNode())); 061 } 062 063 @POST 064 @Path("getNodeByPath") 065 public RemotePubResult getNodeByPath(RemotePubParam param) { 066 return new RemotePubResult(getPublisher().getNodeByPath((String) param.getParams().get(0), 067 (String) param.getParams().get(1))); 068 } 069 070 @POST 071 @Path("getExistingPublishedDocument") 072 public RemotePubResult getExistingPublishedDocument(RemotePubParam param) { 073 return new RemotePubResult(getPublisher().getExistingPublishedDocument((String) param.getParams().get(0), 074 (DocumentLocation) param.getParams().get(1))); 075 } 076 077 @POST 078 @Path("getPublishedDocumentInNode") 079 public RemotePubResult getPublishedDocumentInNode(RemotePubParam param) { 080 return new RemotePubResult(getPublisher().getPublishedDocumentInNode(param.getAsNode())); 081 } 082 083 @POST 084 @Path("publish") 085 public RemotePubResult publish(RemotePubParam param) { 086 RemotePubResult result; 087 if (param.getParams().size() == 2) { 088 result = new RemotePubResult(getPublisher().publish((DocumentModel) param.getParams().get(0), 089 (PublicationNode) param.getParams().get(1))); 090 } else { 091 result = new RemotePubResult(getPublisher().publish((DocumentModel) param.getParams().get(0), 092 (PublicationNode) param.getParams().get(1), (Map<String, String>) param.getParams().get(2))); 093 } 094 return result; 095 } 096 097 @POST 098 @Path("unpublish") 099 public void unpublish(RemotePubParam param) { 100 Object object = param.getParams().get(1); 101 if (object instanceof PublicationNode) { 102 getPublisher().unpublish((DocumentModel) param.getParams().get(0), (PublicationNode) object); 103 } else if (object instanceof PublishedDocument) { 104 getPublisher().unpublish((String) param.getParams().get(0), (PublishedDocument) object); 105 } 106 } 107 108 @POST 109 @Path("initRemoteSession") 110 public RemotePubResult initRemoteSession(RemotePubParam param) { 111 return new RemotePubResult(getPublisher().initRemoteSession((String) param.getParams().get(0), 112 (Map<String, String>) param.getParams().get(1))); 113 } 114 115 @POST 116 @Path("release") 117 public Response release(RemotePubParam param) { 118 getPublisher().release((String) param.getParams().get(0)); 119 return Response.ok().build(); 120 } 121 122 @GET 123 @Path("release/{sid}") 124 public Response release(@PathParam("sid") String sid) { 125 getPublisher().release(sid); 126 return Response.ok().build(); 127 } 128 129 @GET 130 @Path("ping") 131 public String ping() { 132 return "pong"; 133 } 134 135 @GET 136 @Path("superPing") 137 public RemotePubResult superPing() { 138 return new RemotePubResult("pong"); 139 } 140 141}