001/* 002 * (C) Copyright 2014 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 * <a href="mailto:[email protected]">Guillaume Renard</a> 018 * 019 */ 020 021package org.nuxeo.ecm.restapi.server.jaxrs.routing; 022 023import java.util.List; 024 025import javax.ws.rs.GET; 026import javax.ws.rs.Path; 027import javax.ws.rs.PathParam; 028import javax.ws.rs.core.Context; 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") 043public class WorkflowModelObject extends DefaultObject { 044 045 @GET 046 public List<DocumentRoute> getWorkflowModels(@Context UriInfo uriInfo) { 047 return Framework.getService(DocumentRoutingService.class).getAvailableDocumentRouteModel( 048 getContext().getCoreSession()); 049 } 050 051 @GET 052 @Path("{modelName}") 053 public DocumentRoute getWorkflowModel(@PathParam("modelName") String modelName) { 054 DocumentRoute result = Framework.getService(DocumentRoutingService.class).getRouteModelWithId( 055 getContext().getCoreSession(), modelName); 056 return result; 057 } 058 059 @GET 060 @Path("{modelName}/graph") 061 public JsonGraphRoute getWorkflowModelGraph(@PathParam("modelName") String modelName) { 062 try { 063 final String id = Framework.getService(DocumentRoutingService.class).getRouteModelDocIdWithId( 064 getContext().getCoreSession(), modelName); 065 return new JsonGraphRoute(getContext().getCoreSession(), id, getContext().getLocale()); 066 } catch (NuxeoException e) { 067 e.addInfo("Can not get workflow model graph with name: " + modelName); 068 throw e; 069 } 070 } 071 072}