Search in sources :

Example 6 with Association

use of io.automatiko.engine.workflow.bpmn2.core.Association in project kogito-runtimes 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 ProcessParsingValidationException("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)

Example 7 with Association

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

the class SubProcessHandler method handleNode.

@Override
protected Node handleNode(Node node, Element element, String uri, String localName, ExtensibleXmlParser parser) throws SAXException {
    CompositeContextNode compositeNode = (CompositeContextNode) node;
    super.handleNode(node, element, uri, localName, parser);
    handleScript(compositeNode, element, "onEntry");
    handleScript(compositeNode, element, "onExit");
    compositeNode.setIoSpecification(readIOEspecification(parser, element));
    compositeNode.setMultiInstanceSpecification(readMultiInstanceSpecification(parser, element, compositeNode.getIoSpecification()));
    Node outcome = compositeNode;
    if (compositeNode.getMultiInstanceSpecification().hasMultiInstanceInput()) {
        ForEachNode forEachNode = (ForEachNode) decorateMultiInstanceSpecificationSubProcess(compositeNode, compositeNode.getMultiInstanceSpecification());
        handleScript(forEachNode, element, "onEntry");
        handleScript(forEachNode, element, "onExit");
        List<SequenceFlow> connections = (List<SequenceFlow>) forEachNode.getMetaData(ProcessHandler.CONNECTIONS);
        ProcessHandler.linkConnections(forEachNode, connections);
        ProcessHandler.linkBoundaryEvents(forEachNode);
        // 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, Boolean.parseBoolean((String) compositeNode.getMetaData().get("customAsync")));
        outcome = forEachNode;
    } else {
        handleCompositeContextNode(compositeNode);
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(outcome);
    return outcome;
}
Also used : Association(org.jbpm.bpmn2.core.Association) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) SequenceFlow(org.jbpm.bpmn2.core.SequenceFlow) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) 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) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) List(java.util.List) NodeContainer(org.jbpm.workflow.core.NodeContainer)

Example 8 with Association

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

the class DataTest method testAssociation.

@Test
public void testAssociation() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-Association.bpmn2");
    KogitoProcessInstance processInstance = kruntime.startProcess("Evaluation");
    List<Association> associations = (List<Association>) processInstance.getProcess().getMetaData().get(ProcessHandler.ASSOCIATIONS);
    assertNotNull(associations);
    assertEquals(1, associations.size());
    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) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 9 with Association

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

the class ProcessHandler method end.

@SuppressWarnings("unchecked")
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    parser.endElementBuilder();
    ExecutableProcess process = (ExecutableProcess) 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);
    // process tags if any defined
    processTags(process);
    return process;
}
Also used : DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) Association(io.automatiko.engine.workflow.bpmn2.core.Association) SequenceFlow(io.automatiko.engine.workflow.bpmn2.core.SequenceFlow) Lane(io.automatiko.engine.workflow.bpmn2.core.Lane) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) List(java.util.List) ArrayList(java.util.ArrayList) IntermediateLink(io.automatiko.engine.workflow.bpmn2.core.IntermediateLink)

Example 10 with Association

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

the class ProcessHandler method linkConnections.

public void linkConnections(NodeContainer nodeContainer, List<SequenceFlow> connections) {
    if (connections != null) {
        for (SequenceFlow connection : connections) {
            String sourceRef = connection.getSourceRef();
            Node source = findNodeByIdOrUniqueIdInMetadata(nodeContainer, sourceRef, "Could not find source node for connection:" + sourceRef);
            if (source instanceof EventNode) {
                for (EventFilter eventFilter : ((EventNode) source).getEventFilters()) {
                    if (eventFilter instanceof EventTypeFilter) {
                        if ("Compensation".equals(((EventTypeFilter) eventFilter).getType())) {
                            // BPMN Method & Style, 2nd Ed. (Silver), states this on P. 131
                            throw new IllegalArgumentException("A Compensation Boundary Event can only be *associated* with a compensation activity via an Association, not via a Sequence Flow element.");
                        }
                    }
                }
            }
            String targetRef = connection.getTargetRef();
            Node target = findNodeByIdOrUniqueIdInMetadata(nodeContainer, targetRef, "Could not find target node for connection:" + targetRef);
            Connection result = new ConnectionImpl(source, NodeImpl.CONNECTION_DEFAULT_TYPE, target, NodeImpl.CONNECTION_DEFAULT_TYPE);
            result.setMetaData("bendpoints", connection.getBendpoints());
            result.setMetaData("UniqueId", connection.getId());
            if ("true".equals(System.getProperty("jbpm.enable.multi.con"))) {
                NodeImpl nodeImpl = (NodeImpl) source;
                Constraint constraint = buildConstraint(connection, nodeImpl);
                if (constraint != null) {
                    nodeImpl.addConstraint(new ConnectionRef(connection.getId(), target.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE), constraint);
                }
            } else if (source instanceof Split) {
                Split split = (Split) source;
                Constraint constraint = buildConstraint(connection, split);
                split.addConstraint(new ConnectionRef(connection.getId(), target.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE), constraint);
            }
        }
    }
}
Also used : NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) ExtendedNodeImpl(io.automatiko.engine.workflow.process.core.impl.ExtendedNodeImpl) Constraint(io.automatiko.engine.workflow.process.core.Constraint) SequenceFlow(io.automatiko.engine.workflow.bpmn2.core.SequenceFlow) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) Connection(io.automatiko.engine.workflow.process.core.Connection) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Split(io.automatiko.engine.workflow.process.core.node.Split) ConnectionRef(io.automatiko.engine.workflow.process.core.impl.ConnectionRef)

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