Search in sources :

Example 6 with Variable

use of io.automatiko.engine.workflow.base.core.context.variable.Variable in project automatiko-engine by automatiko-io.

the class AbstractProcessInstanceFactory method createProcessInstance.

public ProcessInstance createProcessInstance(Process process, CorrelationKey correlationKey, InternalProcessRuntime runtime, Map<String, Object> parameters, VariableInitializer variableInitializer) {
    ProcessInstance processInstance = createProcessInstance();
    processInstance.setProcessRuntime(runtime);
    processInstance.setProcess(process);
    if (correlationKey != null) {
        processInstance.getMetaData().put("CorrelationKey", correlationKey);
    }
    runtime.getProcessInstanceManager().addProcessInstance(processInstance, correlationKey);
    // set variable default values
    // TODO: should be part of processInstanceImpl?
    VariableScope variableScope = (VariableScope) ((ContextContainer) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
    // set input parameters
    if (parameters != null) {
        if (variableScope != null) {
            for (Map.Entry<String, Object> entry : parameters.entrySet()) {
                variableScope.validateVariable(process.getName(), entry.getKey(), entry.getValue());
                variableScopeInstance.setVariable(entry.getKey(), entry.getValue());
            }
        } else {
            throw new IllegalArgumentException("This process does not support parameters!");
        }
    }
    for (Variable var : variableScope.getVariables()) {
        if ((var.hasTag(Variable.AUTO_INITIALIZED_TAG) || var.getMetaData(Variable.DEFAULT_VALUE) != null) && variableScopeInstance.getVariable(var.getName()) == null) {
            Object value = variableInitializer.initialize(process, var, variableScopeInstance.getVariables());
            variableScope.validateVariable(process.getName(), var.getName(), value);
            variableScopeInstance.setVariable(var.getName(), value);
        }
    }
    variableScopeInstance.enforceRequiredVariables();
    return processInstance;
}
Also used : Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) Map(java.util.Map) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Example 7 with Variable

use of io.automatiko.engine.workflow.base.core.context.variable.Variable in project automatiko-engine by automatiko-io.

the class DefinitionsHandler method postProcessNodes.

protected void postProcessNodes(NodeContainer nodeContainer, List<Variable> parentVariables, ExtensibleXmlParser parser) throws SAXException {
    for (Node node : nodeContainer.getNodes()) {
        List<Variable> variables = new LinkedList<>(parentVariables);
        VariableScope variableScope = (VariableScope) ((ContextContainer) nodeContainer).getDefaultContext(VariableScope.VARIABLE_SCOPE);
        if (variableScope != null) {
            variables.addAll(variableScope.getVariables());
        }
        if (node instanceof NodeContainer) {
            postProcessNodes((NodeContainer) node, variables, parser);
        } else {
            if (node instanceof ActionNode) {
                ActionNode actionNode = (ActionNode) node;
                ProcessAction action = actionNode.getAction();
                if (action instanceof ConsequenceAction) {
                    ConsequenceAction consequenceAction = (ConsequenceAction) action;
                    switch(consequenceAction.getDialect()) {
                        case "java":
                            if (actionNode.getAction().getMetaData("Action") == null) {
                                actionNode.getAction().setMetaData("Action", new MvelAction(actionNode));
                            }
                            break;
                        case "mvel":
                            if (actionNode.getAction().getMetaData("Action") == null) {
                                actionNode.getAction().setMetaData("Action", new MvelAction(actionNode));
                            }
                            break;
                        default:
                    }
                }
            }
        }
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) Node(io.automatiko.engine.api.definition.process.Node) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) LinkedList(java.util.LinkedList) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Example 8 with Variable

use of io.automatiko.engine.workflow.base.core.context.variable.Variable in project automatiko-engine by automatiko-io.

the class DocumentationHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    Element element = parser.endElementBuilder();
    Object parent = parser.getParent();
    if (parent instanceof NodeImpl) {
        ((NodeImpl) parent).getMetaData().put("Documentation", extractDocumentationText(element));
    } else if (parent instanceof io.automatiko.engine.workflow.base.core.Process) {
        ((io.automatiko.engine.workflow.base.core.Process) parent).getMetaData().put("Documentation", extractDocumentationText(element));
    } else if (parent instanceof Variable) {
        ((Variable) parent).getMetaData().put("Documentation", extractDocumentationText(element));
    }
    return parser.getCurrent();
}
Also used : Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) Element(org.w3c.dom.Element)

Example 9 with Variable

use of io.automatiko.engine.workflow.base.core.context.variable.Variable in project automatiko-engine by automatiko-io.

the class IntermediateThrowEventHandler method handleMessageNode.

@SuppressWarnings("unchecked")
public void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    ActionNode actionNode = (ActionNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataInput".equals(nodeName)) {
            String id = ((Element) xmlNode).getAttribute("id");
            String inputName = ((Element) xmlNode).getAttribute("name");
            dataInputs.put(id, inputName);
        } else if ("dataInputAssociation".equals(nodeName)) {
            readDataInputAssociation(xmlNode, actionNode, parser);
        } else if ("messageEventDefinition".equals(nodeName)) {
            String messageRef = ((Element) xmlNode).getAttribute("messageRef");
            Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
            if (messages == null) {
                throw new IllegalArgumentException("No messages found");
            }
            Message message = messages.get(messageRef);
            if (message == null) {
                throw new IllegalArgumentException("Could not find message " + messageRef);
            }
            String variable = (String) actionNode.getMetaData(MAPPING_VARIABLE_KEY);
            Variable v = (Variable) ((ProcessBuildData) parser.getData()).getMetaData("Variable");
            if (v != null) {
                variable = (String) v.getMetaData(variable);
            }
            actionNode.setMetaData("MessageType", message.getType());
            actionNode.setMetaData("TriggerType", "ProduceMessage");
            actionNode.setMetaData("TriggerRef", message.getName());
            for (Entry<String, Object> entry : message.getMetaData().entrySet()) {
                actionNode.setMetaData(entry.getKey(), entry.getValue());
            }
            ConsequenceAction action = createJavaAction(new HandleMessageAction(message.getType(), variable, (Transformation) actionNode.getMetaData().get(TRANSFORMATION_KEY)));
            actionNode.setAction(action);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) Message(io.automatiko.engine.workflow.bpmn2.core.Message) Element(org.w3c.dom.Element) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) HandleMessageAction(io.automatiko.engine.workflow.base.instance.impl.actions.HandleMessageAction) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 10 with Variable

use of io.automatiko.engine.workflow.base.core.context.variable.Variable in project automatiko-engine by automatiko-io.

the class CompositeContextNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    CompositeContextNode compositeNode = (CompositeContextNode) node;
    String nodeType = "subProcess";
    if (node.getMetaData().get("Transaction") != null) {
        nodeType = "transaction";
    }
    writeNode(nodeType, compositeNode, xmlDump, metaDataType);
    if (compositeNode instanceof EventSubProcessNode) {
        xmlDump.append(" triggeredByEvent=\"true\" ");
    }
    Object isForCompensationObject = compositeNode.getMetaData("isForCompensation");
    if (isForCompensationObject != null && ((Boolean) isForCompensationObject)) {
        xmlDump.append("isForCompensation=\"true\" ");
    }
    xmlDump.append(">" + EOL);
    writeExtensionElements(compositeNode, xmlDump);
    // variables
    VariableScope variableScope = (VariableScope) compositeNode.getDefaultContext(VariableScope.VARIABLE_SCOPE);
    if (variableScope != null && !variableScope.getVariables().isEmpty()) {
        xmlDump.append("    <!-- variables -->" + EOL);
        for (Variable variable : variableScope.getVariables()) {
            xmlDump.append("    <property id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "\" ");
            if (variable.getType() != null) {
                xmlDump.append("itemSubjectRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(compositeNode) + "-" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "Item\"");
            }
            // TODO: value
            xmlDump.append("/>" + EOL);
        }
    }
    // nodes
    List<Node> subNodes = getSubNodes(compositeNode);
    XmlBPMNProcessDumper.INSTANCE.visitNodes(subNodes, xmlDump, metaDataType);
    // connections
    visitConnectionsAndAssociations(compositeNode, xmlDump, metaDataType);
    endNode(nodeType, xmlDump);
}
Also used : Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.workflow.process.core.Node) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Aggregations

Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)57 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)27 Map (java.util.Map)22 HashMap (java.util.HashMap)18 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)16 ObjectDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType)16 ArrayList (java.util.ArrayList)14 NameExpr (com.github.javaparser.ast.expr.NameExpr)12 Matcher (java.util.regex.Matcher)12 VariableScopeInstance (io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance)11 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)10 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)9 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)9 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)9 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)9 List (java.util.List)9 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)8 DataAssociation (io.automatiko.engine.workflow.process.core.node.DataAssociation)8 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)8 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)8