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 *     Florent Guillaume
018 */
019package org.nuxeo.ecm.platform.routing.core.impl;
020
021import java.io.Serializable;
022import java.util.Collection;
023import java.util.List;
024import java.util.Map;
025
026import org.nuxeo.ecm.core.api.CoreSession;
027import org.nuxeo.ecm.core.api.DocumentModelList;
028import org.nuxeo.ecm.platform.routing.api.DocumentRoute;
029import org.nuxeo.ecm.platform.routing.api.exception.DocumentRouteException;
030
031/**
032 * A route graph, defining a workflow with arbitrarily complex transitions between nodes.
033 *
034 * @since 5.6
035 */
036public interface GraphRoute extends DocumentRoute {
037
038    String PROP_VARIABLES_FACET = "docri:variablesFacet";
039
040    String PROP_AVAILABILITY_FILTER = "docri:availabilityFilter";
041
042    /**
043     * The id of the parent route instance from which this route was started.
044     *
045     * @since 5.7.2
046     */
047    String PROP_PARENT_ROUTE = "docri:parentRouteInstanceId";
048
049    /**
050     * The id of the node in the parent route from which this route was started.
051     *
052     * @since 5.7.2
053     */
054    String PROP_PARENT_NODE = "docri:parentRouteNodeId";
055
056    /**
057     * Gets the start node for this graph.
058     *
059     * @return the start node
060     */
061    GraphNode getStartNode() throws DocumentRouteException;
062
063    /**
064     * Gets the attached documents.
065     *
066     * @return a list of document
067     */
068    DocumentModelList getAttachedDocumentModels();
069
070    /**
071     * Gets the graph variables.
072     *
073     * @return the map of variables
074     */
075    Map<String, Serializable> getVariables();
076
077    /**
078     * Gets the Json formatted graph variables.
079     *
080     * @return the map of variables
081     * @since 7.2
082     */
083    Map<String, Serializable> getJsonVariables();
084
085    /**
086     * Sets the graph variables.
087     *
088     * @param map the map of variables
089     */
090    void setVariables(Map<String, Serializable> map);
091
092    /**
093     * Sets the variables of the workflow based on their JSON representation (especially for scalar lists). Eg.
094     * Map<String, String> map = new HashMap<String, String>();
095     * map.put("contributors","[\"John Doe\", \"John Smith\"]"); map.put("title","Test Title");
096     *
097     * @param map the map of variables
098     * @since 5.9.3, 5.8.0-HF10
099     */
100    void setJSONVariables(Map<String, String> map);
101
102    /**
103     * Gets the node with the given id.
104     *
105     * @param id
106     * @return the node
107     * @throws IllegalArgumentException if there is no such node
108     */
109    GraphNode getNode(String id) throws IllegalArgumentException;
110
111    /**
112     * Gets a collection of the route nodes
113     *
114     * @return
115     */
116    Collection<GraphNode> getNodes();
117
118    /**
119     * Returns the availability filter name for this graph.
120     */
121    String getAvailabilityFilter();
122
123    /**
124     * Checks if this graph instance has been started from another graph.
125     *
126     * @return {@code true} if this is a sub-route instance
127     * @since 5.7.2
128     */
129    boolean hasParentRoute();
130
131    /**
132     * Resumes execution of the parent route from which this graph was started.
133     *
134     * @param session the session
135     * @since 5.7.2
136     */
137    void resumeParentRoute(CoreSession session);
138
139    /**
140     * Get the list of nodes of which the State is suspended.
141     *
142     * @since 7.4
143     */
144    List<GraphNode> getSuspendedNodes();
145
146}