protected void saveDocument() { getSession().saveDocument(document); }
@Override public String getSubRouteModelId() throws DocumentRouteException { String subRouteModelExpr = (String) getProperty(PROP_SUB_ROUTE_MODEL_EXPR); if (StringUtils.isBlank(subRouteModelExpr)) { return null; } try (OperationContext context = getExecutionContext(getSession())) { String res = valueOrExpression(String.class, subRouteModelExpr, context, "Sub-workflow id expression"); return StringUtils.defaultIfBlank(res, null); } }
@Override public void cancelSubRoute() throws DocumentRouteException { String subRouteInstanceId = getSubRouteInstanceId(); if (!StringUtils.isEmpty(subRouteInstanceId)) { DocumentModel subRouteDoc = getSession().getDocument(new IdRef(subRouteInstanceId)); DocumentRoute subRoute = subRouteDoc.getAdapter(DocumentRoute.class); subRoute.cancel(getSession()); } }
return taskAssignees; try (OperationContext context = getExecutionContext(getSession())) { Expression expr = Scripting.newExpression(taskAssigneesVar); Object res = expr.eval(context);
@Override public void cancelTasks() { CoreSession session = getSession(); List<TaskInfo> tasks = getTasksInfo(); for (TaskInfo task : tasks) { if (!task.isEnded()) { cancelTask(session, task.getTaskDocId()); } } }
@Override public void starting() { // Allow input transitions reevaluation (needed for loop case) for (Transition t : inputTransitions) { t.setResult(false); getSession().saveDocument(t.source.getDocument()); } // Increment node counter incrementProp(PROP_COUNT); document.setPropertyValue(PROP_NODE_START_DATE, Calendar.getInstance()); // reset taskInfo property tasksInfo = null; document.setPropertyValue(PROP_TASKS_INFO, new ArrayList<TaskInfo>()); saveDocument(); }
protected Map<String, Serializable> getSubRouteInitialVariables() { ListProperty props = (ListProperty) document.getProperty(PROP_SUB_ROUTE_VARS); Map<String, Serializable> map = new HashMap<>(); try (OperationContext context = getExecutionContext(getSession())) { for (Property p : props) { MapProperty prop = (MapProperty) p; String key = (String) prop.get(PROP_KEYVALUE_KEY).getValue(); String v = (String) prop.get(PROP_KEYVALUE_VALUE).getValue(); Serializable value = valueOrExpression(Serializable.class, v, context, "Sub-workflow variable expression"); map.put(key, value); } } return map; }
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 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; }
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); } }
@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; }
List<Transition> trueTrans = new ArrayList<>(); for (Transition t : getOutputTransitions()) { try (OperationContext context = getExecutionContext(getSession())) { context.put("transition", t.id); Expression expr = new RoutingScriptingExpression(t.condition, new RoutingScriptingFunctions(context));