Search in sources :

Example 11 with Association

use of io.automatiko.engine.workflow.bpmn2.core.Association in project automatiko-engine by automatiko-io.

the class SubProcessHandler method handleForEachNode.

@SuppressWarnings("unchecked")
protected void handleForEachNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, boolean isAsync) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    ForEachNode forEachNode = (ForEachNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("ioSpecification".equals(nodeName)) {
            readIoSpecification(xmlNode, dataInputs, dataOutputs, dataInputTypes, dataOutputTypes);
        } else if ("dataInputAssociation".equals(nodeName)) {
            readDataInputAssociation(xmlNode, inputAssociation);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, outputAssociation);
        } else if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
            readMultiInstanceLoopCharacteristics(xmlNode, forEachNode, parser);
        }
        xmlNode = xmlNode.getNextSibling();
    }
    handleScript(forEachNode, element, "onEntry");
    handleScript(forEachNode, element, "onExit");
    // List<SequenceFlow> connections = (List<SequenceFlow>) ((CompositeNode) node).getMetaData(ProcessHandler.CONNECTIONS);
    // ProcessHandler processHandler = new ProcessHandler();
    // processHandler.linkConnections((io.automatiko.engine.api.definition.process.NodeContainer) node, connections);
    // processHandler.linkBoundaryEvents((io.automatiko.engine.api.definition.process.NodeContainer) node);
    // This must be done *after* linkConnections(process, connections)
    // because it adds hidden connections for compensations
    List<Association> associations = (List<Association>) forEachNode.getMetaData(ProcessHandler.ASSOCIATIONS);
    ProcessHandler.linkAssociations((Definitions) forEachNode.getMetaData("Definitions"), forEachNode, associations);
    applyAsync(node, isAsync);
}
Also used : Association(io.automatiko.engine.workflow.bpmn2.core.Association) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) List(java.util.List)

Example 12 with Association

use of io.automatiko.engine.workflow.bpmn2.core.Association in project jbpm by kiegroup.

the class ProcessHandler method end.

@SuppressWarnings("unchecked")
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    parser.endElementBuilder();
    RuleFlowProcess process = (RuleFlowProcess) parser.getCurrent();
    List<IntermediateLink> throwLinks = (List<IntermediateLink>) process.getMetaData(LINKS);
    linkIntermediateLinks(process, throwLinks);
    List<SequenceFlow> connections = (List<SequenceFlow>) process.getMetaData(CONNECTIONS);
    linkConnections(process, connections);
    linkBoundaryEvents(process);
    // This must be done *after* linkConnections(process, connections)
    // because it adds hidden connections for compensations
    List<Association> associations = (List<Association>) process.getMetaData(ASSOCIATIONS);
    linkAssociations((Definitions) process.getMetaData("Definitions"), process, associations);
    List<Lane> lanes = (List<Lane>) process.getMetaData(LaneHandler.LANES);
    assignLanes(process, lanes);
    postProcessNodes(process, process);
    postProcessCollaborations(process, parser);
    return process;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Association(org.jbpm.bpmn2.core.Association) SequenceFlow(org.jbpm.bpmn2.core.SequenceFlow) Lane(org.jbpm.bpmn2.core.Lane) List(java.util.List) ArrayList(java.util.ArrayList) IntermediateLink(org.jbpm.bpmn2.core.IntermediateLink)

Example 13 with Association

use of io.automatiko.engine.workflow.bpmn2.core.Association 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 14 with Association

use of io.automatiko.engine.workflow.bpmn2.core.Association in project jbpm by kiegroup.

the class DataTest method testAssociation.

@Test
public void testAssociation() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-Association.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ProcessInstance processInstance = ksession.startProcess("Evaluation");
    List<Association> associations = (List<Association>) processInstance.getProcess().getMetaData().get(ProcessHandler.ASSOCIATIONS);
    assertNotNull(associations);
    assertTrue(associations.size() == 1);
    Association assoc = associations.get(0);
    assertEquals("_1234", assoc.getId());
    assertEquals("_1", assoc.getSourceRef());
    assertEquals("_2", assoc.getTargetRef());
}
Also used : Association(org.jbpm.bpmn2.core.Association) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) List(java.util.List) Test(org.junit.Test)

Example 15 with Association

use of io.automatiko.engine.workflow.bpmn2.core.Association in project jbpm by kiegroup.

the class AssociationHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    Association association = new Association();
    association.setId(attrs.getValue("id"));
    association.setSourceRef(attrs.getValue("sourceRef"));
    association.setTargetRef(attrs.getValue("targetRef"));
    String direction = attrs.getValue("associationDirection");
    if (direction != null) {
        boolean acceptableDirection = false;
        direction = direction.toLowerCase();
        String[] possibleDirections = { "none", "one", "both" };
        for (String acceptable : possibleDirections) {
            if (acceptable.equals(direction)) {
                acceptableDirection = true;
                break;
            }
        }
        if (!acceptableDirection) {
            throw new IllegalArgumentException("Unknown direction '" + direction + "' used in Association " + association.getId());
        }
    }
    association.setDirection(direction);
    /**
     * BPMN2 spec, p. 66:
     * "At this point, BPMN provides three standard Artifacts: Associations,
     *  Groups, and Text Annotations.
     * ...
     *  When an Artifact is defined it is contained within a Collaboration
     *  or a FlowElementsContainer (a Process or Choreography)."
     *
     * (In other words: associations must be defined within a process, not outside)
     */
    List<Association> associations = null;
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    if (nodeContainer instanceof Process) {
        RuleFlowProcess process = (RuleFlowProcess) nodeContainer;
        associations = (List<Association>) process.getMetaData(ASSOCIATIONS);
        if (associations == null) {
            associations = new ArrayList<>();
            process.setMetaData(ASSOCIATIONS, associations);
        }
    } else if (nodeContainer instanceof CompositeNode) {
        CompositeContextNode compositeNode = (CompositeContextNode) nodeContainer;
        associations = (List<Association>) compositeNode.getMetaData(ASSOCIATIONS);
        if (associations == null) {
            associations = new ArrayList<>();
            compositeNode.setMetaData(ProcessHandler.ASSOCIATIONS, associations);
        }
    } else {
        associations = new ArrayList<>();
    }
    associations.add(association);
    return association;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) ArrayList(java.util.ArrayList) NodeContainer(org.jbpm.workflow.core.NodeContainer) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) Association(org.jbpm.bpmn2.core.Association) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

List (java.util.List)19 Association (org.jbpm.bpmn2.core.Association)15 ArrayList (java.util.ArrayList)12 Association (io.automatiko.engine.workflow.bpmn2.core.Association)7 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)5 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)4 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)4 DataStore (org.jbpm.bpmn2.core.DataStore)4 SequenceFlow (org.jbpm.bpmn2.core.SequenceFlow)4 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)4 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)4 EventNode (org.jbpm.workflow.core.node.EventNode)4 Node (io.automatiko.engine.api.definition.process.Node)3 SequenceFlow (io.automatiko.engine.workflow.bpmn2.core.SequenceFlow)3 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)3 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)3 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)3 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)3 StartNode (org.jbpm.workflow.core.node.StartNode)3 DataStore (io.automatiko.engine.workflow.bpmn2.core.DataStore)2