Search in sources :

Example 16 with Association

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

the class AbstractCompositeNodeHandler method visitConnectionsAndAssociations.

protected void visitConnectionsAndAssociations(Node node, StringBuilder xmlDump, int metaDataType) {
    // add associations
    List<Connection> connections = getSubConnections((CompositeNode) node);
    xmlDump.append("    <!-- connections -->" + EOL);
    for (Connection connection : connections) {
        XmlBPMNProcessDumper.INSTANCE.visitConnection(connection, xmlDump, metaDataType);
    }
    // add associations
    List<Association> associations = (List<Association>) node.getMetaData().get(ProcessHandler.ASSOCIATIONS);
    if (associations != null) {
        for (Association association : associations) {
            XmlBPMNProcessDumper.INSTANCE.visitAssociation(association, xmlDump);
        }
    }
}
Also used : Association(org.jbpm.bpmn2.core.Association) Connection(org.kie.api.definition.process.Connection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 17 with Association

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

the class ProcessHandler method linkAssociations.

public static void linkAssociations(Definitions definitions, NodeContainer nodeContainer, List<Association> associations) {
    if (associations != null) {
        for (Association association : associations) {
            String sourceRef = association.getSourceRef();
            Object source = null;
            try {
                source = findNodeOrDataStoreByUniqueId(definitions, nodeContainer, sourceRef, "Could not find source [" + sourceRef + "] for association " + association.getId() + "]");
            } catch (IllegalArgumentException e) {
            // source not found
            }
            String targetRef = association.getTargetRef();
            Object target = null;
            try {
                target = findNodeOrDataStoreByUniqueId(definitions, nodeContainer, targetRef, "Could not find target [" + targetRef + "] for association [" + association.getId() + "]");
            } catch (IllegalArgumentException e) {
            // target not found
            }
            if (source == null || target == null) {
            // TODO: ignoring this association for now
            } else if (target instanceof DataStore || source instanceof DataStore) {
            // TODO: ignoring data store associations for now
            } else if (source instanceof EventNode) {
                EventNode sourceNode = (EventNode) source;
                KogitoNode targetNode = (KogitoNode) target;
                checkBoundaryEventCompensationHandler(association, sourceNode, targetNode);
                // make sure IsForCompensation is set to true on target
                NodeImpl targetNodeImpl = (NodeImpl) target;
                String isForCompensation = "isForCompensation";
                Object compensationObject = targetNodeImpl.getMetaData(isForCompensation);
                if (compensationObject == null) {
                    targetNodeImpl.setMetaData(isForCompensation, true);
                    logger.warn("Setting {} attribute to true for node {}", isForCompensation, targetRef);
                } else if (!Boolean.parseBoolean(compensationObject.toString())) {
                    throw new ProcessParsingValidationException(isForCompensation + " attribute [" + compensationObject + "] should be true for Compensation Activity [" + targetRef + "]");
                }
                // put Compensation Handler in CompensationHandlerNode
                NodeContainer sourceParent = sourceNode.getParentContainer();
                NodeContainer targetParent = targetNode.getParentContainer();
                if (!sourceParent.equals(targetParent)) {
                    throw new ProcessParsingValidationException("Compensation Associations may not cross (sub-)process boundaries,");
                }
                // connect boundary event to compensation activity
                ConnectionImpl connection = new ConnectionImpl(sourceNode, NodeImpl.CONNECTION_DEFAULT_TYPE, targetNode, NodeImpl.CONNECTION_DEFAULT_TYPE);
                connection.setMetaData("UniqueId", null);
                connection.setMetaData("hidden", true);
                connection.setMetaData("association", true);
            // Compensation use cases:
            // - boundary event --associated-> activity
            // - implicit sub process compensation handler + recursive?
            /**
             * BPMN2 spec, p.442:
             * "A Compensation Event Sub-process becomes enabled when its parent Activity transitions into state
             * Completed. At that time, a snapshot of the data associated with the parent Acitivity is taken and kept for
             * later usage by the Compensation Event Sub-Process."
             */
            }
        }
    }
}
Also used : BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) Association(org.jbpm.bpmn2.core.Association) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) DataStore(org.jbpm.bpmn2.core.DataStore) KogitoNode(org.kie.kogito.internal.process.runtime.KogitoNode) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) NodeContainer(org.kie.api.definition.process.NodeContainer)

Example 18 with Association

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

the class AbstractCompositeNodeHandler method visitConnectionsAndAssociations.

protected void visitConnectionsAndAssociations(Node node, StringBuilder xmlDump, int metaDataType) {
    // add associations
    List<Connection> connections = getSubConnections((CompositeNode) node);
    xmlDump.append("    <!-- connections -->" + EOL);
    for (Connection connection : connections) {
        XmlBPMNProcessDumper.INSTANCE.visitConnection(connection, xmlDump, metaDataType);
    }
    // add associations
    List<Association> associations = (List<Association>) node.getMetaData().get(ProcessHandler.ASSOCIATIONS);
    if (associations != null) {
        for (Association association : associations) {
            XmlBPMNProcessDumper.INSTANCE.visitAssociation(association, xmlDump);
        }
    }
}
Also used : Association(org.jbpm.bpmn2.core.Association) Connection(org.kie.api.definition.process.Connection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 19 with Association

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

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) {
        ExecutableProcess process = (ExecutableProcess) 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 : CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) ArrayList(java.util.ArrayList) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) Process(io.automatiko.engine.api.definition.process.Process) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Association(io.automatiko.engine.workflow.bpmn2.core.Association) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with Association

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

the class AbstractCompositeNodeHandler method visitConnectionsAndAssociations.

protected void visitConnectionsAndAssociations(Node node, StringBuilder xmlDump, int metaDataType) {
    // add associations
    List<Connection> connections = getSubConnections((CompositeNode) node);
    xmlDump.append("    <!-- connections -->" + EOL);
    for (Connection connection : connections) {
        XmlBPMNProcessDumper.INSTANCE.visitConnection(connection, xmlDump, metaDataType);
    }
    // add associations
    List<Association> associations = (List<Association>) node.getMetaData().get(ProcessHandler.ASSOCIATIONS);
    if (associations != null) {
        for (Association association : associations) {
            XmlBPMNProcessDumper.INSTANCE.visitAssociation(association, xmlDump);
        }
    }
}
Also used : Association(io.automatiko.engine.workflow.bpmn2.core.Association) Connection(io.automatiko.engine.api.definition.process.Connection) List(java.util.List) ArrayList(java.util.ArrayList)

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