001/* 002 * (C) Copyright 2014 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-2.1.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 * <a href="mailto:grenard@nuxeo.com">Guillaume Renard</a> 016 * 017 */ 018 019package org.nuxeo.ecm.restapi.server.jaxrs.routing; 020 021import java.util.List; 022 023import javax.ws.rs.GET; 024import javax.ws.rs.Path; 025import javax.ws.rs.PathParam; 026import javax.ws.rs.Produces; 027import javax.ws.rs.core.Context; 028import javax.ws.rs.core.MediaType; 029import javax.ws.rs.core.UriInfo; 030 031import org.nuxeo.ecm.core.api.NuxeoException; 032import org.nuxeo.ecm.platform.routing.api.DocumentRoute; 033import org.nuxeo.ecm.platform.routing.api.DocumentRoutingService; 034import org.nuxeo.ecm.platform.routing.core.impl.jsongraph.JsonGraphRoute; 035import org.nuxeo.ecm.webengine.model.WebObject; 036import org.nuxeo.ecm.webengine.model.impl.DefaultObject; 037import org.nuxeo.runtime.api.Framework; 038 039/** 040 * @since 7.2 041 */ 042@WebObject(type = "workflowModel") 043@Produces(MediaType.APPLICATION_JSON) 044public class WorkflowModelObject extends DefaultObject { 045 046 @GET 047 public List<DocumentRoute> getWorkflowModels(@Context UriInfo uriInfo) { 048 return Framework.getService(DocumentRoutingService.class).getAvailableDocumentRouteModel( 049 getContext().getCoreSession()); 050 } 051 052 @GET 053 @Path("{modelName}") 054 public DocumentRoute getWorkflowModel(@PathParam("modelName") String modelName) { 055 DocumentRoute result = Framework.getService(DocumentRoutingService.class).getRouteModelWithId( 056 getContext().getCoreSession(), modelName); 057 return result; 058 } 059 060 @GET 061 @Path("{modelName}/graph") 062 public JsonGraphRoute getWorkflowModelGraph(@PathParam("modelName") String modelName) { 063 try { 064 final String id = Framework.getService(DocumentRoutingService.class).getRouteModelDocIdWithId( 065 getContext().getCoreSession(), modelName); 066 return new JsonGraphRoute(getContext().getCoreSession(), id, getContext().getLocale()); 067 } catch (NuxeoException e) { 068 e.addInfo("Can not get workflow model graph with name: " + modelName); 069 throw e; 070 } 071 } 072 073}