Search in sources :

Example 21 with VariableScope

use of org.jbpm.process.core.context.variable.VariableScope in project jbpm by kiegroup.

the class SubProcessHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Node node = (Node) parser.getCurrent();
    // determine type of event definition, so the correct type of node can be generated
    boolean found = false;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
            Boolean isAsync = Boolean.parseBoolean((String) node.getMetaData().get("customAsync"));
            // create new timerNode
            ForEachNode forEachNode = new ForEachNode();
            forEachNode.setId(node.getId());
            forEachNode.setName(node.getName());
            forEachNode.setAutoComplete(((CompositeContextNode) node).isAutoComplete());
            for (org.kie.api.definition.process.Node subNode : ((CompositeContextNode) node).getNodes()) {
                forEachNode.addNode(subNode);
            }
            forEachNode.setMetaData("UniqueId", ((CompositeContextNode) node).getMetaData("UniqueId"));
            forEachNode.setMetaData(ProcessHandler.CONNECTIONS, ((CompositeContextNode) node).getMetaData(ProcessHandler.CONNECTIONS));
            VariableScope v = (VariableScope) ((CompositeContextNode) node).getDefaultContext(VariableScope.VARIABLE_SCOPE);
            ((VariableScope) ((CompositeContextNode) forEachNode.internalGetNode(2)).getDefaultContext(VariableScope.VARIABLE_SCOPE)).setVariables(v.getVariables());
            node = forEachNode;
            handleForEachNode(node, element, uri, localName, parser, isAsync);
            found = true;
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    if (!found) {
        handleCompositeContextNode(node, element, uri, localName, parser);
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Element(org.w3c.dom.Element) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) StartNode(org.jbpm.workflow.core.node.StartNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) Node(org.jbpm.workflow.core.Node) NodeContainer(org.jbpm.workflow.core.NodeContainer) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 22 with VariableScope

use of org.jbpm.process.core.context.variable.VariableScope in project jbpm by kiegroup.

the class XmlBPMNProcessDumper method visitHeader.

protected void visitHeader(WorkflowProcess process, StringBuilder xmlDump, int metaDataType) {
    Map<String, Object> metaData = getMetaData(process.getMetaData());
    Set<String> imports = ((org.jbpm.process.core.Process) process).getImports();
    Map<String, String> globals = ((org.jbpm.process.core.Process) process).getGlobals();
    if ((imports != null && !imports.isEmpty()) || (globals != null && globals.size() > 0) || !metaData.isEmpty()) {
        xmlDump.append("    <extensionElements>" + EOL);
        if (imports != null) {
            for (String s : imports) {
                xmlDump.append("     <tns:import name=\"" + s + "\" />" + EOL);
            }
        }
        if (globals != null) {
            for (Map.Entry<String, String> global : globals.entrySet()) {
                xmlDump.append("     <tns:global identifier=\"" + global.getKey() + "\" type=\"" + global.getValue() + "\" />" + EOL);
            }
        }
        writeMetaData(getMetaData(process.getMetaData()), xmlDump);
        xmlDump.append("    </extensionElements>" + EOL);
    }
    // TODO: function imports
    // TODO: exception handlers
    VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    if (variableScope != null) {
        visitVariables(variableScope.getVariables(), xmlDump);
    }
    visitLanes(process, xmlDump);
}
Also used : Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess) Map(java.util.Map) HashMap(java.util.HashMap) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 23 with VariableScope

use of org.jbpm.process.core.context.variable.VariableScope in project jbpm by kiegroup.

the class XmlBPMNProcessDumper method visitProcess.

protected void visitProcess(WorkflowProcess process, StringBuilder xmlDump, int metaDataType) {
    String targetNamespace = (String) process.getMetaData().get("TargetNamespace");
    if (targetNamespace == null) {
        targetNamespace = "http://www.jboss.org/drools";
    }
    xmlDump.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + EOL + "<definitions id=\"Definition\"" + EOL + "             targetNamespace=\"" + targetNamespace + "\"" + EOL + "             typeLanguage=\"http://www.java.com/javaTypes\"" + EOL + "             expressionLanguage=\"http://www.mvel.org/2.0\"" + EOL + "             xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\"" + EOL + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + EOL + "             xsi:schemaLocation=\"http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd\"" + EOL + "             xmlns:g=\"http://www.jboss.org/drools/flow/gpd\"" + EOL + (metaDataType == META_DATA_USING_DI ? "             xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\"" + EOL + "             xmlns:dc=\"http://www.omg.org/spec/DD/20100524/DC\"" + EOL + "             xmlns:di=\"http://www.omg.org/spec/DD/20100524/DI\"" + EOL : "") + "             xmlns:tns=\"http://www.jboss.org/drools\">" + EOL + EOL);
    // item definitions
    this.visitedVariables = new HashSet<String>();
    VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    Set<String> dumpedItemDefs = new HashSet<String>();
    Map<String, ItemDefinition> itemDefs = (Map<String, ItemDefinition>) process.getMetaData().get("ItemDefinitions");
    if (itemDefs != null) {
        for (ItemDefinition def : itemDefs.values()) {
            xmlDump.append("  <itemDefinition id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(def.getId()) + "\" ");
            if (def.getStructureRef() != null && !"java.lang.Object".equals(def.getStructureRef())) {
                xmlDump.append("structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(def.getStructureRef()) + "\" ");
            }
            xmlDump.append("/>" + EOL);
            dumpedItemDefs.add(def.getId().intern());
        }
    }
    visitVariableScope(variableScope, "_", xmlDump, dumpedItemDefs);
    visitSubVariableScopes(process.getNodes(), xmlDump, dumpedItemDefs);
    visitInterfaces(process.getNodes(), xmlDump);
    visitEscalations(process.getNodes(), xmlDump, new ArrayList<String>());
    Definitions def = (Definitions) process.getMetaData().get("Definitions");
    visitErrors(def, xmlDump);
    // data stores
    if (def != null && def.getDataStores() != null) {
        for (DataStore dataStore : def.getDataStores()) {
            visitDataStore(dataStore, xmlDump);
        }
    }
    // the process itself
    xmlDump.append("  <process processType=\"Private\" isExecutable=\"true\" ");
    if (process.getId() == null || process.getId().trim().length() == 0) {
        ((ProcessImpl) process).setId("com.sample.bpmn2");
    }
    xmlDump.append("id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(process.getId()) + "\" ");
    if (process.getName() != null) {
        xmlDump.append("name=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(process.getName()) + "\" ");
    }
    String packageName = process.getPackageName();
    if (packageName != null && !"org.drools.bpmn2".equals(packageName)) {
        xmlDump.append("tns:packageName=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(packageName) + "\" ");
    }
    if (((org.jbpm.workflow.core.WorkflowProcess) process).isDynamic()) {
        xmlDump.append("tns:adHoc=\"true\" ");
    }
    String version = process.getVersion();
    if (version != null && !"".equals(version)) {
        xmlDump.append("tns:version=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(version) + "\" ");
    }
    // TODO: package, version
    xmlDump.append(">" + EOL + EOL);
    visitHeader(process, xmlDump, metaDataType);
    List<org.jbpm.workflow.core.Node> processNodes = new ArrayList<org.jbpm.workflow.core.Node>();
    for (Node procNode : process.getNodes()) {
        processNodes.add((org.jbpm.workflow.core.Node) procNode);
    }
    visitNodes(processNodes, xmlDump, metaDataType);
    visitConnections(process.getNodes(), xmlDump, metaDataType);
    // add associations
    List<Association> associations = (List<Association>) process.getMetaData().get(ProcessHandler.ASSOCIATIONS);
    if (associations != null) {
        for (Association association : associations) {
            visitAssociation(association, xmlDump);
        }
    }
    xmlDump.append("  </process>" + EOL + EOL);
    if (metaDataType == META_DATA_USING_DI) {
        xmlDump.append("  <bpmndi:BPMNDiagram>" + EOL + "    <bpmndi:BPMNPlane bpmnElement=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(process.getId()) + "\" >" + EOL);
        visitNodesDi(process.getNodes(), xmlDump);
        visitConnectionsDi(process.getNodes(), xmlDump);
        xmlDump.append("    </bpmndi:BPMNPlane>" + EOL + "  </bpmndi:BPMNDiagram>" + EOL + EOL);
    }
    xmlDump.append("</definitions>");
}
Also used : Definitions(org.jbpm.bpmn2.core.Definitions) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) FaultNode(org.jbpm.workflow.core.node.FaultNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.kie.api.definition.process.Node) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) ArrayList(java.util.ArrayList) Association(org.jbpm.bpmn2.core.Association) DataStore(org.jbpm.bpmn2.core.DataStore) ProcessImpl(org.jbpm.process.core.impl.ProcessImpl) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess) VariableScope(org.jbpm.process.core.context.variable.VariableScope) HashSet(java.util.HashSet)

Example 24 with VariableScope

use of org.jbpm.process.core.context.variable.VariableScope in project jbpm by kiegroup.

the class AbstractProcessInstanceFactory method createProcessInstance.

public ProcessInstance createProcessInstance(Process process, CorrelationKey correlationKey, InternalKnowledgeRuntime kruntime, Map<String, Object> parameters) {
    ProcessInstance processInstance = (ProcessInstance) createProcessInstance();
    processInstance.setKnowledgeRuntime(kruntime);
    processInstance.setProcess(process);
    if (correlationKey != null) {
        processInstance.getMetaData().put("CorrelationKey", correlationKey);
    }
    InternalRuntimeManager manager = (InternalRuntimeManager) kruntime.getEnvironment().get("RuntimeManager");
    if (manager != null) {
        processInstance.setDeploymentId(manager.getIdentifier());
    }
    ((InternalProcessRuntime) kruntime.getProcessRuntime()).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!");
        }
    }
    return processInstance;
}
Also used : InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) Map(java.util.Map) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Aggregations

VariableScope (org.jbpm.process.core.context.variable.VariableScope)24 Variable (org.jbpm.process.core.context.variable.Variable)11 Map (java.util.Map)7 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)6 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ContextContainer (org.jbpm.process.core.ContextContainer)3 ExceptionScope (org.jbpm.process.core.context.exception.ExceptionScope)3 VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)3 Node (org.jbpm.workflow.core.Node)3 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)3 HashSet (java.util.HashSet)2 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)2 MVELCompilationUnit (org.drools.core.base.mvel.MVELCompilationUnit)2 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)2 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)2 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)2 IntegerDataType (org.jbpm.process.core.datatype.impl.type.IntegerDataType)2 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)2