Search in sources :

Example 11 with SubProcessNode

use of io.automatiko.engine.workflow.process.core.node.SubProcessNode in project automatiko-engine by automatiko-io.

the class AbstractProcessInstance method image.

@Override
public String image(String path) {
    if (process().image() == null) {
        return null;
    }
    StringBuilder script = new StringBuilder();
    String image = process().image();
    List<String> completedNodes = ((WorkflowProcessInstanceImpl) processInstance()).getCompletedNodeIds();
    Collection<NodeInstance> activeInstances = ((WorkflowProcessInstanceImpl) processInstance()).getNodeInstances(true);
    if (!activeInstances.isEmpty() || !completedNodes.isEmpty() || status == STATE_ERROR) {
        script.append("<script>");
        script.append("function remove(item) {if (item != null) {var parent = item.parentNode; parent.removeChild(item);}}");
        script.append("function linkSet(item, link) {if (item != null) {item.setAttribute('xlink:href', link);}}");
        script.append("function urlSet(item, url) {if (item != null) {item.onclick=function (e) {openInNewTab(url);};}}");
        script.append("function fill(item, rgb) {if (item != null) {item.style['fill']=rgb;}}");
        script.append("function highlight(item) {if (item != null) {item.style['stroke']='rgb(255, 0, 0)';item.style['stroke-width']='2';}}");
        script.append("var warnIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABz0lEQVQ4y2NgoBAwYhNsK7HVdbOWCpCX5FJjYGRgePzi+63dR59tKO86dBmvAQlB2kJT6ixncLN+CWH4/xvVcEbW/9//8q4taDuZPmvFpXcYBsQFagktaDM7zPj3sxZM7Or93wwMDAwM2oqscHP+M/Ney2g8aztrxeV3KAZ8Phe/moftSwiypfVzPjEwMDAwNKbwoTjm+x/e1VwGC8IYGBgYWBgYGBga88x1edi+BhMbcJwsX0I6S610y7uPXWZhYGBgcLUUDmBg+M9IfNj/Z3SxEA5gYGCAGCArzqpGavTJSUD0sDAwMDC8ef+VUUaMnyQDXr/9wgg34Oi5N3cM1DENkBfH7avDZ1/fgceCpb6Q8dElDqcZGRlRdPz//x8S16jCDP////9vF3/Q9Mi5t2dZGBgYGI5ffHd2475nWwOcpX2QFTbO+8zAwMDA0JCMGo2b9j/feuTc27Mo6UBUkE3q0EKHQxpKvMowsZNXvzMwMDAwmGtzwjXfuP/5rn38QbtX734+w0jKwgJsMjPrjWYHuUi5Y/HO/3V7nu3MaDyX+ubDryf4MhOzvjq/lb+TVIC6Ao86AwMDw80HX25u3Pds48WbH48xMDD8YaAmAAAYL5tXiXxXawAAAABJRU5ErkJggg==';");
        script.append("var errorIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAC80lEQVR42m2TD0yMYRzHP897d65y0akzUTYjVEKnMNQw2RqbzVrzd2wopkwrFrMw//8sDBtbNmZj5k9tDYXMbEYRM8oiSwqp6E53qbvu8uuG5c+zvXv37v09n+f3+36/j+I/azkERsJsM4zVg74D3tfC3ePw4e9a1fdjLvgnQJ5Z0zKGx8ebQqKi0BkM2OrqqH/wwGPr6LjaDDmHoeEfQDxY5kNJZHi4NTYzE1NY2B90l8NBVUEBNRUVLe9g3lF4/BswWNpcAWXxZnNibMZadCYjOk1D9Sh6usHrgW6PB6UUtZcuUVVd3XwPYovhow8wB1YthoKY5NkYJ0czKi2HugsnMdqbUN0aNqdi9IYt1F+5iquykprCQso9nnPHYKXqB1oWVEzVaZNGpE6he1oS1vU7cDu+Ub43DVfLJ2JzTzNoVCS114tp2LUbd81r3thsXUdgmDJBiMzzOdwfLTTBiNMcgHtaOjMy99L5zUZ78wcGR4zjVUkRb/LWYGn5juO9kyYvnIEFahhMPADPhgaJipPBbyi+n/bxeczL3ukT8EXZLar2zCfaz01XIzhExeZ2OA8ZSgSMFn9fWgIhOA76CfGVaxBx224THmP1AZxtX7mRlcSYzqfSq8CroUX8PAXpSoOBZ8XXED2BQePhi0U2599mSJSV+ofXaH1bjnXpfhmnjfubkghueIr9kUBssBUSe10wbITLM2UezQKhm3OJy9nHR9nceHERpgFu9DHZRKQe4vPjUp5nJtP1RBrx0rhWkuqzcTjMOgGl4pjBG6oYmbYaW8VZgkLcGPpLiCQL/Scso6msmLYyO3o7nJRE3oT8X2EzLoTt6ZBrV5IfuQT+oSKovHsBvXN2tkK7zB7gBGmgdAek9IiefdM6IEUA6yDbIVo6ZZNHQqJ0EhSXwNwgvJ47UHQQ1rl9cv51mWQFhMH0JVIghiRIRoLlFCUTOOTwyitifaUApK79v7fx59J6QfKY/QQgDeikaxmANnmkObx9i38AhmwGt8LiZCUAAAAASUVORK5CYII=';");
        script.append("function openInNewTab(url) {var win = window.open(url, '_blank');win.focus();}");
        for (NodeInstance nodeInstance : activeInstances) {
            if (((NodeInstanceImpl) nodeInstance).getNode().getMetaData().containsKey("hidden_node") || nodeInstance.getNodeDefinitionId().startsWith("_jbpm-unique")) {
                continue;
            }
            script.append("highlight(document.getElementById('").append(nodeInstance.getNodeDefinitionId()).append("'));\n");
            if (nodeInstance instanceof LambdaSubProcessNodeInstance) {
                // add links for call activity
                LambdaSubProcessNodeInstance subprocess = (LambdaSubProcessNodeInstance) nodeInstance;
                String url = path + "/" + ((SubProcessNode) subprocess.getNode()).getProcessId() + "/" + subprocess.getProcessInstanceId() + "/image";
                script.append("urlSet(document.getElementById('").append(nodeInstance.getNodeDefinitionId()).append("_image'), '" + url + "');\n");
            }
            if (nodeInstance instanceof EventSubProcessNodeInstance) {
                if (((EventSubProcessNodeInstance) nodeInstance).getTimerInstances() != null && !((EventSubProcessNodeInstance) nodeInstance).getTimerInstances().isEmpty()) {
                    String nodeDefId = (String) ((EventSubProcessNode) ((EventSubProcessNodeInstance) nodeInstance).getEventBasedNode()).findStartNode().getMetaData("UniqueId");
                    if (nodeDefId != null) {
                        script.append("highlight(document.getElementById('").append(nodeDefId).append("'));\n");
                    }
                }
            }
            if (nodeInstance.getNodeInstanceState().equals(NodeInstanceState.Retrying)) {
                script.append("linkSet(document.getElementById('").append(nodeInstance.getNodeDefinitionId()).append("_warn_image'), warnIcon);\n");
            } else if (nodeInstance.getNodeInstanceState().equals(NodeInstanceState.Failed)) {
                script.append("linkSet(document.getElementById('").append(nodeInstance.getNodeDefinitionId()).append("_warn_image'), errorIcon);\n");
            } else {
                script.append("remove(document.getElementById('").append(nodeInstance.getNodeDefinitionId()).append("_warn_image'));\n");
            }
        }
        for (String nodeInstanceId : completedNodes) {
            script.append("remove(document.getElementById('").append(nodeInstanceId).append("_warn_image'));\n");
            script.append("fill(document.getElementById('").append(nodeInstanceId).append("'), 'rgb(160, 160, 160)');\n");
        }
        if (status == STATE_ERROR) {
            for (ProcessError error : errors().get().errors()) {
                String failedNodeId = error.failedNodeId();
                script.append("highlight(document.getElementById('").append(failedNodeId).append("'));\n");
                script.append("linkSet(document.getElementById('").append(failedNodeId).append("_warn_image'), errorIcon);\n");
            }
        }
        script.append("</script></svg>");
        image = image.replaceAll("</svg>", script.toString());
    }
    return image;
}
Also used : LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) ProcessError(io.automatiko.engine.api.workflow.ProcessError) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)

Example 12 with SubProcessNode

use of io.automatiko.engine.workflow.process.core.node.SubProcessNode in project automatiko-engine by automatiko-io.

the class SubProcessNodeInstance method handleOutMappings.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void handleOutMappings(ProcessInstance processInstance) {
    VariableScopeInstance subProcessVariableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
    SubProcessNode subProcessNode = getSubProcessNode();
    if (subProcessNode != null) {
        for (Iterator<io.automatiko.engine.workflow.process.core.node.DataAssociation> iterator = subProcessNode.getOutAssociations().iterator(); iterator.hasNext(); ) {
            io.automatiko.engine.workflow.process.core.node.DataAssociation mapping = iterator.next();
            if (mapping.getTransformation() != null) {
                Transformation transformation = mapping.getTransformation();
                DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
                if (transformer != null) {
                    Map<String, Object> dataSet = new HashMap<String, Object>();
                    if (getNodeInstanceContainer() instanceof CompositeContextNodeInstance) {
                        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) getNodeInstanceContainer()).getContextInstance(VariableScope.VARIABLE_SCOPE);
                        if (variableScopeInstance != null) {
                            dataSet.putAll(variableScopeInstance.getVariables());
                        }
                    }
                    dataSet.putAll(subProcessVariableScopeInstance.getVariables());
                    Object parameterValue = transformer.transform(transformation.getCompiledExpression(), dataSet);
                    VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, mapping.getTarget());
                    if (variableScopeInstance != null && parameterValue != null) {
                        variableScopeInstance.setVariable(this, mapping.getTarget(), parameterValue);
                    } else {
                        logger.warn("Could not find variable scope for variable {}", mapping.getTarget());
                        logger.warn("Continuing without setting variable.");
                    }
                }
            } else {
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, mapping.getTarget());
                if (variableScopeInstance != null) {
                    Object value = subProcessVariableScopeInstance.getVariable(mapping.getSources().get(0));
                    if (value == null) {
                        try {
                            ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
                            value = evaluator.evaluate(mapping.getSources().get(0), new VariableScopeResolverFactory(subProcessVariableScopeInstance));
                        } catch (Throwable t) {
                        // do nothing
                        }
                    }
                    variableScopeInstance.setVariable(this, mapping.getTarget(), value);
                } else {
                    String output = mapping.getSources().get(0);
                    String target = mapping.getTarget();
                    Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(target);
                    if (matcher.find()) {
                        String paramName = matcher.group(1);
                        String expression = paramName + " = " + output;
                        VariableScopeResolverFactory resolver = new VariableScopeResolverFactory(subProcessVariableScopeInstance);
                        resolver.addExtraParameters(((VariableScopeInstance) getProcessInstance().getContextInstance(VariableScope.VARIABLE_SCOPE)).getVariables());
                        Serializable compiled = MVEL.compileExpression(expression);
                        MVEL.executeExpression(compiled, resolver);
                    } else {
                        logger.error("Could not find variable scope for variable {}", mapping.getTarget());
                        logger.error("when trying to complete SubProcess node {}", getSubProcessNode().getName());
                        logger.error("Continuing without setting variable.");
                    }
                }
            }
        }
    } else {
        // handle dynamic sub processes without data output mapping
        mapDynamicOutputData(subProcessVariableScopeInstance.getVariables());
    }
}
Also used : Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) Serializable(java.io.Serializable) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) VariableScopeResolverFactory(io.automatiko.engine.workflow.process.instance.impl.VariableScopeResolverFactory) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode)

Example 13 with SubProcessNode

use of io.automatiko.engine.workflow.process.core.node.SubProcessNode in project automatiko-engine by automatiko-io.

the class SubProcessNodeHandler method handleNode.

public void handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    SubProcessNode subProcessNode = (SubProcessNode) node;
    String processId = element.getAttribute("processId");
    if (processId != null && processId.length() > 0) {
        subProcessNode.setProcessId(processId);
    }
    String waitForCompletion = element.getAttribute("waitForCompletion");
    subProcessNode.setWaitForCompletion(!"false".equals(waitForCompletion));
    String independent = element.getAttribute("independent");
    subProcessNode.setIndependent(!"false".equals(independent));
    for (String eventType : subProcessNode.getActionTypes()) {
        handleAction(subProcessNode, element, eventType);
    }
}
Also used : SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode)

Example 14 with SubProcessNode

use of io.automatiko.engine.workflow.process.core.node.SubProcessNode in project automatiko-engine by automatiko-io.

the class SubProcessNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    SubProcessNode subProcessNode = (SubProcessNode) node;
    writeNode("subProcess", subProcessNode, xmlDump, includeMeta);
    String processId = subProcessNode.getProcessId();
    if (processId != null) {
        xmlDump.append("processId=\"" + processId + "\" ");
    }
    if (!subProcessNode.isWaitForCompletion()) {
        xmlDump.append("waitForCompletion=\"false\" ");
    }
    if (!subProcessNode.isIndependent()) {
        xmlDump.append("independent=\"false\" ");
    }
    xmlDump.append(">" + EOL);
    if (includeMeta) {
        writeMetaData(subProcessNode, xmlDump);
    }
    Map<String, String> inMappings = subProcessNode.getInMappings();
    for (Map.Entry<String, String> inMapping : inMappings.entrySet()) {
        xmlDump.append("      <mapping type=\"in\" " + "from=\"" + inMapping.getValue() + "\" " + "to=\"" + inMapping.getKey() + "\" />" + EOL);
    }
    Map<String, String> outMappings = subProcessNode.getOutMappings();
    for (Map.Entry<String, String> outMapping : outMappings.entrySet()) {
        xmlDump.append("      <mapping type=\"out\" " + "from=\"" + outMapping.getKey() + "\" " + "to=\"" + outMapping.getValue() + "\" />" + EOL);
    }
    for (String eventType : subProcessNode.getActionTypes()) {
        writeActions(eventType, subProcessNode.getActions(eventType), xmlDump);
    }
    writeTimers(subProcessNode.getTimers(), xmlDump);
    endNode("subProcess", xmlDump);
}
Also used : SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) Map(java.util.Map)

Example 15 with SubProcessNode

use of io.automatiko.engine.workflow.process.core.node.SubProcessNode in project automatiko-engine by automatiko-io.

the class CallActivityHandler method end.

@SuppressWarnings("unchecked")
@Override
public Object end(String uri, String localName, ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Node node = (Node) parser.getCurrent();
    handleNode(node, element, uri, localName, parser);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    int uniqueIdGen = 1;
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
            // create new timerNode
            ForEachNode forEachNode = new ForEachNode();
            forEachNode.setId(node.getId());
            String uniqueId = (String) node.getMetaData().get("UniqueId");
            forEachNode.setMetaData("UniqueId", uniqueId);
            node.setMetaData("UniqueId", uniqueId + ":" + uniqueIdGen++);
            node.setMetaData("hidden", true);
            forEachNode.addNode(node);
            forEachNode.linkIncomingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE, node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE);
            forEachNode.linkOutgoingConnections(node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE, NodeImpl.CONNECTION_DEFAULT_TYPE);
            forEachNode.setSequential(Boolean.parseBoolean(((Element) xmlNode).getAttribute("isSequential")));
            Node orignalNode = node;
            node = forEachNode;
            handleForEachNode(node, element, uri, localName, parser);
            // running in variable strict mode
            if (orignalNode instanceof SubProcessNode) {
                adjustNodeConfiguration(orignalNode, forEachNode);
            }
            Map<String, String> dataInputs = (Map<String, String>) orignalNode.getMetaData().remove("DataInputs");
            Map<String, String> dataOutputs = (Map<String, String>) orignalNode.getMetaData().remove("DataOutputs");
            orignalNode.setMetaData("MICollectionOutput", dataOutputs.get(((ForEachNode) node).getMetaData("MICollectionOutput")));
            orignalNode.setMetaData("MICollectionInput", dataInputs.get(((ForEachNode) node).getMetaData("MICollectionInput")));
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : Element(org.w3c.dom.Element) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) Node(io.automatiko.engine.workflow.process.core.Node) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

SubProcessNode (io.automatiko.engine.workflow.process.core.node.SubProcessNode)17 Map (java.util.Map)6 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)5 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)4 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)4 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)4 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)4 Node (io.automatiko.engine.api.definition.process.Node)3 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)3 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)3 FaultNode (io.automatiko.engine.workflow.process.core.node.FaultNode)3 Join (io.automatiko.engine.workflow.process.core.node.Join)3 RuleSetNode (io.automatiko.engine.workflow.process.core.node.RuleSetNode)3 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)3 Optional (java.util.Optional)3 StaticJavaParser.parse (com.github.javaparser.StaticJavaParser.parse)2 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)2