@Override public void run() throws ClientException { DocumentModel doc = session.getDocument(new IdRef(routeDocId)); GraphRoute route = doc.getAdapter(GraphRoute.class); GraphNode node = route.getNode(nodeId); HashMap<String, Serializable> map = new HashMap<String, Serializable>(); if (getFormVariables) { map.putAll(node.getVariables()); map.putAll(route.getVariables()); } res[0] = new TaskInfo(task.getId(), map, node.getTaskLayout(), node.getTaskButtons(), node.allowTaskReassignment(), task.getName()); } }.runUnrestricted();
/** * @since 5.6 */ public List<DocumentModel> getFilteredRouteModels() throws ClientException { DocumentRoutingService documentRoutingService = Framework.getLocalService(DocumentRoutingService.class); List<DocumentModel> routeModels = documentRoutingService.searchRouteModels( documentManager, ""); for (Iterator<DocumentModel> it = routeModels.iterator(); it.hasNext();) { DocumentModel route = it.next(); Object graphRouteObj = route.getAdapter(GraphRoute.class); if (graphRouteObj instanceof GraphRoute) { String filter = ((GraphRoute) graphRouteObj).getAvailabilityFilter(); if (!StringUtils.isBlank(filter)) { if (!webActions.checkFilter(filter)) { it.remove(); } } } else { // old workflow document => ignore it.remove(); } } return routeModels; }
@Override public void cancel(CoreSession session, DocumentRouteElement element) { GraphRoute graph = element instanceof GraphRoute ? (GraphRoute) element : null; Map<String, Serializable> eventProperties = new HashMap<>(); if (graph != null) { eventProperties.put("modelId", graph.getModelId()); eventProperties.put("modelName", graph.getModelName()); eventProperties.put(RoutingAuditHelper.WORKFLOW_VARIABLES, (Serializable) graph.getVariables()); eventProperties.put(RoutingAuditHelper.WORKFLOW_INITATIOR, graph.getInitiator()); // Get the list of pending node List<String> pendingNodeNames = new ArrayList<>(); for (GraphNode suspendedNode : graph.getSuspendedNodes()) { pendingNodeNames.add(suspendedNode.getId()); } eventProperties.put("pendingNodes", (Serializable) pendingNodeNames); } EventFirer.fireEvent(session, element, eventProperties, DocumentRoutingConstants.Events.beforeWorkflowCanceled.name()); super.cancel(session, element); if (graph == null) { return; } // also cancel tasks // also cancel sub-workflows for (GraphNode node : graph.getNodes()) { node.cancelTasks(); node.cancelSubRoute(); } }
public static Map<String, Object> getGraphElementsAsMap(GraphRoute route, Locale locale) { Map<String, Object> graph = new HashMap<String, Object>(); List<NodeView> nodeViews = new ArrayList<NodeView>(); List<TransitionView> tranViews = new ArrayList<TransitionView>(); for (GraphNode node : route.getNodes()) { nodeViews.add(new NodeView(node, locale)); List<Transition> transitions = node.getOutputTransitions(); for (Transition transition : transitions) { GraphNode targetNode = route.getNode(transition.getTarget()); tranViews.add(new TransitionView(node.getId(), targetNode.getId(), transition, locale)); } } graph.put("nodes", nodeViews); graph.put("transitions", tranViews); return graph; }
@SuppressWarnings("unchecked") @OperationMethod public void run() { // first fill context if (ctx.get(Constants.VAR_WORKFLOW) != null) { ((Map<String, Serializable>) ctx.get(Constants.VAR_WORKFLOW)).put(name, (Serializable) value); } // get workflow instance id from context if not in automation parameters if (workflowInstanceId == null) { workflowInstanceId = (String) ctx.get("workflowInstanceId"); } if (workflowInstanceId == null) { return; } // finally save graph variables DocumentModel workflowInstance = session.getDocument(new IdRef(workflowInstanceId)); GraphRoute graph = workflowInstance.getAdapter(GraphRoute.class); Map<String, Serializable> vars = graph.getVariables(); vars.put(name, (Serializable) value); graph.setVariables(vars); } }
"Invalid routeInstanceId: " + routeId + " referenced by the task " + taskId); GraphNode node = routeInstance.getNode(task.getType()); if (node == null) { throw new DocumentRouteException( "Invalid node " + routeId + " referenced by the task " + taskId); DocumentModelList docs = routeInstance.getAttachedDocumentModels(); Framework.getService(TaskService.class).delegateTask(session, taskId, delegatedActors, comment); eventProperties.put("taskName", task.getName()); eventProperties.put("delegatedActors", (Serializable) delegatedActors); eventProperties.put("modelId", routeInstance.getModelId()); eventProperties.put("modelName", routeInstance.getModelName()); eventProperties.put(RoutingAuditHelper.WORKFLOW_INITATIOR, routeInstance.getInitiator()); eventProperties.put(RoutingAuditHelper.TASK_ACTOR, session.getPrincipal().getActingUser()); eventProperties.put("comment", comment);
GraphNode node = graph.getNode(nodeId); if (node == null) { throw new DocumentRouteException("Invalid nodeId: " + nodeId); eventProperties.put(DocumentEventContext.CATEGORY_PROPERTY_KEY, DocumentRoutingConstants.ROUTING_CATEGORY); eventProperties.put("taskName", task.getName()); eventProperties.put("modelName", graph.getModelName()); eventProperties.put("action", status); eventProperties.put("data", (Serializable) varData); eventProperties.put(RoutingAuditHelper.WORKFLOW_INITATIOR, graph.getInitiator()); eventProperties.put(RoutingAuditHelper.TASK_ACTOR, session.getPrincipal().getActingUser()); eventProperties.put("nodeVariables", (Serializable) node.getVariables()); eventProperties.put("workflowVariables", (Serializable) graph.getVariables());
protected void updateTaskInfo(CoreSession session, GraphRoute graph, Task task, String status) { String nodeId = task.getVariable(DocumentRoutingConstants.TASK_NODE_ID_KEY); if (StringUtils.isEmpty(nodeId)) { throw new DocumentRouteException("No nodeId found on task: " + task.getId()); } GraphNode node = graph.getNode(nodeId); NuxeoPrincipal principal = session.getPrincipal(); String actor = principal.getActingUser(); node.updateTaskInfo(task.getId(), true, status, actor, null); }
DocumentModelList docs = graph.getAttachedDocumentModels(); TaskService taskService = Framework.getService(TaskService.class); DocumentRoutingService routing = Framework.getService(DocumentRoutingService.class); eventProperties.put("taskName", node.getDocument().getTitle()); eventProperties.put("actors", actors); eventProperties.put("modelId", graph.getModelId()); eventProperties.put("modelName", graph.getModelName()); eventProperties.put(RoutingAuditHelper.WORKFLOW_INITATIOR, graph.getInitiator()); eventProperties.put(RoutingAuditHelper.TASK_ACTOR, session.getPrincipal().getOriginatingUser()); eventProperties.put("nodeVariables", (Serializable) node.getVariables()); if (routeInstance instanceof GraphRoute) { eventProperties.put("workflowVariables", (Serializable) ((GraphRoute) routeInstance).getVariables());
jg.writeStringField("workflowInstanceId", workflowInstanceId); if (workflowInstance != null) { jg.writeStringField("workflowModelName", workflowInstance.getModelName()); writeWorkflowInitiator(jg, workflowInstance.getInitiator()); jg.writeStringField("workflowTitle", workflowInstance.getTitle()); jg.writeStringField("workflowLifeCycleState", workflowInstance.getDocument().getCurrentLifeCycleState()); jg.writeStringField("graphResource", DocumentRouteWriter.getGraphResourceURL( workflowInstance.getDocumentRoute(wrapper.getSession()), ctx));
GraphNode target = graph.getNode(t.target); if (!pendingNodes.contains(target)) { pendingNodes.add(target); if (graph.hasParentRoute()) { graph.resumeParentRoute(session);
protected void fireEventAfterWorkflowStarted(DocumentRoute route, CoreSession session) { Map<String, Serializable> eventProperties = new HashMap<>(); eventProperties.put(RoutingAuditHelper.WORKFLOW_INITATIOR, route.getInitiator()); eventProperties.put("modelId", route.getModelId()); eventProperties.put("modelName", route.getModelName()); if (route instanceof GraphRoute) { eventProperties.put(RoutingAuditHelper.WORKFLOW_VARIABLES, (Serializable) ((GraphRoute) route).getVariables()); } fireEvent(DocumentRoutingConstants.Events.afterWorkflowStarted.name(), eventProperties, route, session); }
protected void finishTask(CoreSession session, GraphRoute graph, GraphNode node, Task task, boolean delete, String status) throws DocumentRouteException { DocumentRoutingService routing = Framework.getService(DocumentRoutingService.class); DocumentModelList docs = graph.getAttachedDocumentModels(); routing.removePermissionsForTaskActors(session, docs, task); // delete task if (delete) { session.removeDocument(new IdRef(task.getId())); } // get the last comment on the task, if there are several: // task might have been previously reassigned or delegated List<TaskComment> comments = task.getComments(); String comment = comments.size() > 0 ? comments.get(comments.size() - 1).getText() : ""; // actor NuxeoPrincipal principal = session.getPrincipal(); String actor = principal.getActingUser(); node.updateTaskInfo(task.getId(), true, status, actor, comment); }
/** * @since 7.2 */ @Override public List<DocumentRoute> getRunningWorkflowInstancesLaunchedByCurrentUser(CoreSession session, String worflowModelName) { final String query = String.format( "SELECT * FROM %s WHERE docri:initiator = '%s' AND ecm:currentLifeCycleState = '%s'", DocumentRoutingConstants.DOCUMENT_ROUTE_DOCUMENT_TYPE, session.getPrincipal().getName(), DocumentRouteElement.ElementLifeCycleState.running); DocumentModelList documentModelList = session.query(query); List<DocumentRoute> result = new ArrayList<>(); for (DocumentModel documentModel : documentModelList) { final GraphRoute graphRoute = documentModel.getAdapter(GraphRoute.class); if (StringUtils.isNotBlank(worflowModelName)) { final String modelId = graphRoute.getModelId(); if (StringUtils.isNotBlank(modelId)) { DocumentRoute model = session.getDocument(new IdRef(modelId)).getAdapter(DocumentRoute.class); if (worflowModelName.equals(model.getName())) { result.add(graphRoute); } } } else { result.add(graphRoute); } } return result; }
String workflowSchemaFacet = (String) graphRoute.getDocument().getPropertyValue( GraphRoute.PROP_VARIABLES_FACET); CompositeType type = schemaManager.getFacet(workflowSchemaFacet);
"Invalid routeInstanceId: " + routeId + " referenced by the task " + taskId); GraphNode node = routeInstance.getNode(task.getType()); if (node == null) { throw new DocumentRouteException( + node.getId() + " doesn't allow reassignment."); DocumentModelList docs = routeInstance.getAttachedDocumentModels(); eventProperties.put("taskName", task.getName()); eventProperties.put("actors", (Serializable) actors); eventProperties.put("modelId", routeInstance.getModelId()); eventProperties.put("modelName", routeInstance.getModelName()); eventProperties.put(RoutingAuditHelper.WORKFLOW_INITATIOR, routeInstance.getInitiator()); eventProperties.put(RoutingAuditHelper.TASK_ACTOR, session.getPrincipal().getActingUser()); eventProperties.put("comment", comment);
/** * @param session * @param task * @return GraphNode corresponding to task. */ private GraphNode getGraphNode(CoreSession session, Task task) { final String routeDocId = task.getVariable(DocumentRoutingConstants.TASK_ROUTE_INSTANCE_DOCUMENT_ID_KEY); final String nodeId = task.getVariable(DocumentRoutingConstants.TASK_NODE_ID_KEY); DocumentModel doc = session.getDocument(new IdRef(routeDocId)); GraphRoute route = doc.getAdapter(GraphRoute.class); GraphNode node = route.getNode(nodeId); return node; }
protected void fireWorkflowCompletionEvent(CoreSession session) { EventFirer.fireEvent(session, this, null, DocumentRoutingConstants.Events.afterRouteFinish.name()); Map<String, Serializable> eventProperties = new HashMap<String, Serializable>(); // First compute duration long duration = RoutingAuditHelper.computeDurationSinceWfStarted(getDocument().getId()); if (duration >= 0) { eventProperties.put(RoutingAuditHelper.TIME_SINCE_WF_STARTED, duration); } eventProperties.put(RoutingAuditHelper.WORKFLOW_INITATIOR, this.getInitiator()); // Add common info about workflow if (this instanceof GraphRoute) { eventProperties.put(RoutingAuditHelper.WORKFLOW_VARIABLES, (Serializable) ((GraphRoute) this).getVariables()); } eventProperties.put("modelId", getModelId()); eventProperties.put("modelName", getModelName()); EventFirer.fireEvent(session, this, eventProperties, DocumentRoutingConstants.Events.afterWorkflowFinish.name()); }
DocumentModelList docs = routeInstance.getAttachedDocumentModels(); removePermissionsForTaskActors(session, docs, task);
@Override public void run() { DocumentModel workflowInstanceDoc = session.getDocument(new IdRef(workflowInstanceId)); workflowInstance = workflowInstanceDoc.getAdapter(GraphRoute.class); node = workflowInstance.getNode(nodeId); workflowInstanceDoc.detach(true); node.getDocument().detach(true); }