@Override public List<DocumentModel> getWorkflowInputDocuments(CoreSession session, Task task) { String routeInstanceId; try { routeInstanceId = task.getProcessId(); } catch (PropertyException e) { throw new DocumentRouteException("Can not get the related workflow instance"); } if (StringUtils.isEmpty(routeInstanceId)) { throw new DocumentRouteException("Can not get the related workflow instance"); } DocumentModel routeDoc; try { routeDoc = session.getDocument(new IdRef(routeInstanceId)); } catch (DocumentNotFoundException e) { throw new DocumentRouteException("No workflow with the id:" + routeInstanceId); } DocumentRoute route = routeDoc.getAdapter(DocumentRoute.class); return route.getAttachedDocuments(session); }
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 void endTask(CoreSession session, Task task, Map<String, Object> data, String status) { String comment = (String) data.get(GraphNode.NODE_VARIABLE_COMMENT); TaskService taskService = Framework.getService(TaskService.class); taskService.endTask(session, session.getPrincipal(), task, comment, null, false); Map<String, String> taskVariables = task.getVariables(); String routeInstanceId = taskVariables.get(DocumentRoutingConstants.TASK_ROUTE_INSTANCE_DOCUMENT_ID_KEY); if (StringUtils.isEmpty(routeInstanceId)) { throw new DocumentRouteException("Can not resume workflow, no related route"); } completeTask(routeInstanceId, null, task, data, status, session); }
throw new DocumentRouteException("Can not evaluate task assignees from " + taskAssigneesVar); throw e; } catch (RuntimeException e) { throw new DocumentRouteException("Error evaluating task assignees: " + taskAssigneesVar, e);
@Override public GraphNode getStartNode() throws DocumentRouteException { for (GraphNode node : getNodes()) { if (node.isStart()) { return node; } } throw new DocumentRouteException("No start node for graph: " + getName()); }
protected String computeNodes() { CoreSession session = document.getCoreSession(); DocumentModelList children = session.getChildren(document.getRef()); nodes = new ArrayList<>(children.size()); nodesById = new HashMap<>(); String startNodeId = null; for (DocumentModel doc : children) { // TODO use adapters if (doc.getType().equals("RouteNode")) { GraphNode node = new GraphNodeImpl(doc, this); String id = node.getId(); if (nodesById.put(id, node) != null) { throw new DocumentRouteException("Duplicate nodes with id: " + id); } nodes.add(node); if (node.isStart()) { if (startNodeId != null) { throw new DocumentRouteException("Duplicate start nodes: " + startNodeId + " and " + id); } startNodeId = id; } } } return startNodeId; }
protected Date evaluateDueDate() throws DocumentRouteException { String taskDueDateExpr = getTaskDueDateExpr(); if (StringUtils.isEmpty(taskDueDateExpr)) { return new Date(); } try (OperationContext context = getExecutionContext(getSession())) { Expression expr = Scripting.newExpression(taskDueDateExpr); Object res = expr.eval(context); if (res instanceof DateWrapper) { return ((DateWrapper) res).getDate(); } else if (res instanceof Date) { return (Date) res; } else if (res instanceof Calendar) { return ((Calendar) res).getTime(); } else if (res instanceof String) { return DateParser.parseW3CDateTime((String) res); } else { throw new DocumentRouteException( "The following expression can not be evaluated to a date: " + taskDueDateExpr); } } catch (DocumentRouteException e) { throw e; } catch (RuntimeException e) { throw new DocumentRouteException("Error evaluating task due date: " + taskDueDateExpr, e); } }
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); }
public void executeChain(String chainId, String transitionId) throws DocumentRouteException { // TODO events if (StringUtils.isEmpty(chainId)) { return; } // get base context try (OperationContext context = getExecutionContext(getSession())) { if (transitionId != null) { context.put("transition", transitionId); } AutomationService automationService = Framework.getService(AutomationService.class); automationService.run(context, chainId); setAllVariables(context); } catch (OperationException e) { throw new DocumentRouteException("Error running chain: " + chainId, e); } }
@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; }
@Override public void finishTask(CoreSession session, DocumentRoute route, Task task, boolean delete) throws DocumentRouteException { DocumentModelList docs = route.getAttachedDocuments(session); try { removePermissionsForTaskActors(session, docs, task); // delete task if (delete) { session.removeDocument(new IdRef(task.getId())); } } catch (DocumentNotFoundException e) { throw new DocumentRouteException("Cannot finish task", e); } }
if (!allowGlobalVariablesAssignement && (transientSchema == null || !transientSchema.hasField(key))) { throw new DocumentRouteException(String.format( "You don't have the permission to set the workflow variable %s", key));
if (taskId == null) { if (nodeId == null) { throw new DocumentRouteException("nodeId and taskId both missing"); task = taskDoc.getAdapter(Task.class); if (task == null) { throw new DocumentRouteException("Invalid taskId: " + taskId); throw new DocumentRouteException("No nodeId found on task: " + taskId); throw new DocumentRouteException("Invalid nodeId: " + nodeId); throw new DocumentRouteException("Cannot force resume on non-suspended or non-waiting node: " + node); throw new DocumentRouteException("Cannot resume on non-suspended node: " + node);
throw new DocumentRouteException("Condition for transition " + t + " of node '" + getId() + "' of graph '" + graph.getName() + "' does not evaluate to a boolean: " + t.condition); throw e; } catch (RuntimeException e) { throw new DocumentRouteException("Error evaluating condition: " + t.condition, e);
count++; if (count > MAX_LOOPS) { throw new DocumentRouteException("Execution is looping, node: " + node); case SUSPENDED: if (node != initialNode) { throw new DocumentRouteException("Executing unexpected SUSPENDED state"); if (node.isStop()) { if (!pendingNodes.isEmpty()) { throw new DocumentRouteException(String.format("Route %s stopped with still pending nodes: %s", graph, pendingNodes)); } else { if (trueTrans.isEmpty()) { throw new DocumentRouteException("No transition evaluated to true from node " + node);
Task task = taskDoc.getAdapter(Task.class); if (task == null) { throw new DocumentRouteException("Invalid taskId: " + taskId); throw new DocumentRouteException("Task " + taskId + " is not opened, can not reassign it"); GraphRoute routeInstance = routeDoc.getAdapter(GraphRoute.class); if (routeInstance == null) { throw new DocumentRouteException( "Invalid routeInstanceId: " + routeId + " referenced by the task " + taskId); throw new DocumentRouteException( "Invalid node " + routeId + " referenced by the task " + taskId); throw new DocumentRouteException("Task " + taskId + " can not be reassigned. Node " + node.getId() + " doesn't allow reassignment.");
Task task = taskDoc.getAdapter(Task.class); if (task == null) { throw new DocumentRouteException("Invalid taskId: " + taskId); GraphRoute routeInstance = routeDoc.getAdapter(GraphRoute.class); if (routeInstance == null) { throw new DocumentRouteException( "Invalid routeInstanceId: " + routeId + " referenced by the task " + taskId); throw new DocumentRouteException( "Invalid node " + routeId + " referenced by the task " + taskId);
Task task = taskDoc.getAdapter(Task.class); if (task == null) { throw new DocumentRouteException("Invalid taskId: " + taskId); GraphRoute routeInstance = routeDoc.getAdapter(GraphRoute.class); if (routeInstance == null) { throw new DocumentRouteException("Invalid routeInstanceId: " + routeId);
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); }