Search in sources :

Example 21 with ConnectionImpl

use of io.automatiko.engine.workflow.process.core.impl.ConnectionImpl in project automatiko-engine by automatiko-io.

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;
                Node targetNode = (Node) 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 IllegalArgumentException(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 IllegalArgumentException("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", association.getId());
                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(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) Association(io.automatiko.engine.workflow.bpmn2.core.Association) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) ExtendedNodeImpl(io.automatiko.engine.workflow.process.core.impl.ExtendedNodeImpl) DataStore(io.automatiko.engine.workflow.bpmn2.core.DataStore) 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) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer)

Example 22 with ConnectionImpl

use of io.automatiko.engine.workflow.process.core.impl.ConnectionImpl in project automatiko-engine by automatiko-io.

the class XmlBPMNProcessDumper method visitConnection.

public void visitConnection(Connection connection, StringBuilder xmlDump, int metaDataType) {
    // if the connection was generated by a link event, don't dump.
    if (isConnectionRepresentingLinkEvent(connection)) {
        return;
    }
    // if the connection is a hidden one (compensations), don't dump
    Object hidden = ((ConnectionImpl) connection).getMetaData("hidden");
    if (hidden != null && ((Boolean) hidden)) {
        return;
    }
    xmlDump.append("    <sequenceFlow id=\"" + getUniqueNodeId(connection.getFrom()) + "-" + getUniqueNodeId(connection.getTo()) + "\" sourceRef=\"" + getUniqueNodeId(connection.getFrom()) + "\" ");
    // TODO fromType, toType
    xmlDump.append("targetRef=\"" + getUniqueNodeId(connection.getTo()) + "\" ");
    if (metaDataType == META_DATA_AS_NODE_PROPERTY) {
        String bendpoints = (String) connection.getMetaData().get("bendpoints");
        if (bendpoints != null) {
            xmlDump.append("g:bendpoints=\"" + bendpoints + "\" ");
        }
    }
    if (connection.getFrom() instanceof Split) {
        Split split = (Split) connection.getFrom();
        if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR) {
            Constraint constraint = split.getConstraint(connection);
            if (constraint == null) {
                xmlDump.append(">" + EOL + "      <conditionExpression xsi:type=\"tFormalExpression\" />");
            } else {
                if (constraint.getName() != null && constraint.getName().trim().length() > 0) {
                    xmlDump.append("name=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(constraint.getName()) + "\" ");
                }
                if (constraint.getPriority() != 0) {
                    xmlDump.append("tns:priority=\"" + constraint.getPriority() + "\" ");
                }
                xmlDump.append(">" + EOL + "      <conditionExpression xsi:type=\"tFormalExpression\" ");
                if ("code".equals(constraint.getType())) {
                    if ("java".equals(constraint.getDialect())) {
                        xmlDump.append("language=\"" + JAVA_LANGUAGE + "\" ");
                    } else if ("XPath".equals(constraint.getDialect())) {
                        xmlDump.append("language=\"" + XPATH_LANGUAGE + "\" ");
                    } else if ("JavaScript".equals(constraint.getDialect())) {
                        xmlDump.append("language=\"" + JAVASCRIPT_LANGUAGE + "\" ");
                    } else if ("FEEL".equals(constraint.getDialect())) {
                        xmlDump.append("language=\"" + FEEL_LANGUAGE + "\" ");
                    }
                } else {
                    xmlDump.append("language=\"" + RULE_LANGUAGE + "\" ");
                }
                String constraintString = constraint.getConstraint();
                if (constraintString == null) {
                    constraintString = "";
                }
                xmlDump.append(">" + XmlDumper.replaceIllegalChars(constraintString) + "</conditionExpression>");
            }
            xmlDump.append(EOL + "    </sequenceFlow>" + EOL);
        } else {
            xmlDump.append("/>" + EOL);
        }
    } else {
        xmlDump.append("/>" + EOL);
    }
}
Also used : Constraint(io.automatiko.engine.workflow.process.core.Constraint) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) Split(io.automatiko.engine.workflow.process.core.node.Split)

Aggregations

ConnectionImpl (io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)22 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)11 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)11 Node (io.automatiko.engine.api.definition.process.Node)10 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)10 ArrayList (java.util.ArrayList)9 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)7 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)7 AbstractBaseTest (io.automatiko.engine.workflow.test.util.AbstractBaseTest)7 Test (org.junit.jupiter.api.Test)7 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)6 Connection (io.automatiko.engine.api.definition.process.Connection)5 ProcessCompletedEvent (io.automatiko.engine.api.event.process.ProcessCompletedEvent)5 ProcessEventListener (io.automatiko.engine.api.event.process.ProcessEventListener)5 ProcessNodeLeftEvent (io.automatiko.engine.api.event.process.ProcessNodeLeftEvent)5 ProcessNodeTriggeredEvent (io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent)5 ProcessStartedEvent (io.automatiko.engine.api.event.process.ProcessStartedEvent)5 ProcessVariableChangedEvent (io.automatiko.engine.api.event.process.ProcessVariableChangedEvent)5 ProcessContext (io.automatiko.engine.api.runtime.process.ProcessContext)5 ProcessRuntimeImpl (io.automatiko.engine.workflow.base.instance.ProcessRuntimeImpl)5