@Override public Collection<GraphNode> getNodes() { if (nodes == null) { compute(); } return nodes; }
protected void compute() { String startNodeId = computeNodes(); computeTransitions(); computeLoopTransitions(startNodeId); }
protected Calendar getWorkflowStartTime() { return (Calendar) graph.getDocument().getPropertyValue("dc:created"); }
Map<String, Serializable> context = new HashMap<>(); context.put("WorkflowVariables", (Serializable) graph.getVariables()); context.put("workflowInitiator", getWorkflowInitiator()); context.put("workflowStartTime", getWorkflowStartTime()); context.put("workflowParent", getWorkflowParentRouteId()); context.put("workflowParentNode", getWorkflowParentNodeId()); context.put("workflowInstanceId", graph.getDocument().getId()); context.put("taskDueTime", (Calendar) getProperty(PROP_TASK_DUE_DATE)); DocumentModelList documents = graph.getAttachedDocuments(session); if (detached) { for (DocumentModel documentModel : documents) {
Map<String, Serializable> graphVariables = mapToJSON ? graph.getJsonVariables() : graph.getVariables(); Map<String, Serializable> nodeVariables = mapToJSON ? getJsonVariables() : getVariables(); Map<String, Serializable> changedGraphVariables = new HashMap<>(); graph.setVariables(changedGraphVariables);
@Override public String toString() { return new ToStringBuilder(this).append(getName()).toString(); }
protected OperationContext getExecutionContext(CoreSession session) { OperationContext context = new OperationContext(session); context.putAll(getWorkflowContextualInfo(session, true)); context.setCommit(false); // no session save at end DocumentModelList documents = graph.getAttachedDocuments(session); // associated docs context.setInput(documents); return context; }
protected void cancelTask(CoreSession session, final String taskId) throws DocumentRouteException { DocumentRef taskRef = new IdRef(taskId); if (!session.exists(taskRef)) { log.info(String.format("Task with id %s does not exist anymore", taskId)); DocumentModelList docs = graph.getAttachedDocumentModels(); Framework.getService(DocumentRoutingService.class).removePermissionsForTaskActors(session, docs, taskId); NuxeoPrincipal principal = session.getPrincipal(); String actor = principal.getActingUser(); updateTaskInfo(taskId, true, null, actor, null); return; } DocumentModel taskDoc = session.getDocument(new IdRef(taskId)); Task task = taskDoc.getAdapter(Task.class); if (task == null) { throw new DocumentRouteException("Invalid taskId: " + taskId); } DocumentModelList docs = graph.getAttachedDocumentModels(); Framework.getService(DocumentRoutingService.class).removePermissionsForTaskActors(session, docs, task); if (task.isOpened()) { task.cancel(session); } session.saveDocument(task.getDocument()); // task is considered processed with the status "null" when is // canceled // actor NuxeoPrincipal principal = session.getPrincipal(); String actor = principal.getActingUser(); updateTaskInfo(taskId, true, null, actor, null); }
return new DocumentRouteImpl(doc, new ParallelRunner()); case graph: return new GraphRouteImpl(doc);
protected <T> T valueOrExpression(Class<T> klass, String v, OperationContext context, String kind) throws DocumentRouteException { if (!v.startsWith(EXPR_PREFIX)) { return (T) v; } v = v.substring(EXPR_PREFIX.length()).trim(); Expression expr; if (v.contains(TEMPLATE_START)) { expr = Scripting.newTemplate(v); } else { expr = Scripting.newExpression(v); } Object res = null; try { res = expr.eval(context); // stupid eval() method throws generic Exception } catch (RuntimeException e) { throw new DocumentRouteException("Error evaluating expression: " + v, e); } if (!(klass.isAssignableFrom(res.getClass()))) { throw new DocumentRouteException( kind + " of node '" + getId() + "' of graph '" + graph.getName() + "' does not evaluate to " + klass.getSimpleName() + " but " + res.getClass().getName() + ": " + v); } return (T) res; }
@Override public DocumentRoute startSubRoute() throws DocumentRouteException { String subRouteModelId = getSubRouteModelId(); // create the instance without starting it DocumentRoutingService service = Framework.getService(DocumentRoutingService.class); List<String> docs = graph.getAttachedDocuments(); String subRouteInstanceId = service.createNewInstance(subRouteModelId, docs, getSession(), false); // set info about parent in subroute DocumentModel subRouteInstance = getSession().getDocument(new IdRef(subRouteInstanceId)); subRouteInstance.setPropertyValue(GraphRoute.PROP_PARENT_ROUTE, getDocument().getParentRef().toString()); subRouteInstance.setPropertyValue(GraphRoute.PROP_PARENT_NODE, getDocument().getName()); subRouteInstance = getSession().saveDocument(subRouteInstance); // set info about subroute in parent document.setPropertyValue(PROP_SUB_ROUTE_INSTANCE_ID, subRouteInstanceId); saveDocument(); // start the sub-route Map<String, Serializable> map = getSubRouteInitialVariables(); service.startInstance(subRouteInstanceId, docs, map, getSession()); // return the sub-route // subRouteInstance.refresh(); DocumentRoute subRoute = subRouteInstance.getAdapter(DocumentRoute.class); return subRoute; }
@Override public List<EscalationRule> evaluateEscalationRules() { List<EscalationRule> rulesToExecute = new ArrayList<>(); // add specific helpers for escalation for (EscalationRule rule : getEscalationRules()) { try (OperationContext context = getExecutionContext(getSession())) { Expression expr = new RoutingScriptingExpression(rule.condition, new RoutingScriptingFunctions(context, rule)); Object res = expr.eval(context); if (!(res instanceof Boolean)) { throw new DocumentRouteException("Condition for rule " + rule + " of node '" + getId() + "' of graph '" + graph.getName() + "' does not evaluate to a boolean: " + rule.condition); } boolean bool = Boolean.TRUE.equals(res); if ((!rule.isExecuted() || rule.isMultipleExecution()) && bool) { rulesToExecute.add(rule); } } catch (DocumentRouteException e) { throw e; } catch (RuntimeException e) { throw new DocumentRouteException("Error evaluating condition: " + rule.condition, e); } } saveDocument(); return rulesToExecute; }
protected String getWorkflowParentNodeId() { return (String) graph.getDocument().getPropertyValue(GraphRoute.PROP_PARENT_NODE); }
+ "' of graph '" + graph.getName() + "' does not evaluate to a boolean: " + t.condition);
protected String getWorkflowInitiator() { return (String) graph.getDocument().getPropertyValue(DocumentRoutingConstants.INITIATOR); }
protected String getWorkflowParentRouteId() { return (String) graph.getDocument().getPropertyValue(GraphRoute.PROP_PARENT_ROUTE); }