Search in sources :

Example 1 with NodeImpl

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

the class CompensationScopeInstance method handleException.

public void handleException(io.automatiko.engine.api.runtime.process.NodeInstance nodeInstance, ExceptionHandler handler, String compensationActivityRef, Object dunno) {
    WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) getProcessInstance();
    NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getContextInstanceContainer();
    if (handler instanceof CompensationHandler) {
        CompensationHandler compensationHandler = (CompensationHandler) handler;
        try {
            Node handlerNode = compensationHandler.getnode();
            if (handlerNode instanceof BoundaryEventNode) {
                NodeInstance compensationHandlerNodeInstance = nodeInstanceContainer.getNodeInstance(handlerNode);
                compensationInstances.add(compensationHandlerNodeInstance);
                // The BoundaryEventNodeInstance.signalEvent() contains the necessary logic
                // to check whether or not compensation may proceed (? : (not-active +
                // completed))
                EventNodeInstance eventNodeInstance = (EventNodeInstance) compensationHandlerNodeInstance;
                eventNodeInstance.signalEvent("Compensation", compensationActivityRef);
            } else if (handlerNode instanceof EventSubProcessNode) {
                // Check that subprocess parent has completed.
                List<String> completedIds = processInstance.getCompletedNodeIds();
                if (completedIds.contains(((NodeImpl) handlerNode.getParentContainer()).getMetaData("UniqueId"))) {
                    NodeInstance subProcessNodeInstance = ((NodeInstanceContainer) nodeInstanceContainer).getNodeInstance((Node) handlerNode.getParentContainer());
                    compensationInstances.add(subProcessNodeInstance);
                    NodeInstance compensationHandlerNodeInstance = ((NodeInstanceContainer) subProcessNodeInstance).getNodeInstance(handlerNode);
                    compensationInstances.add(compensationHandlerNodeInstance);
                    EventSubProcessNodeInstance eventNodeInstance = (EventSubProcessNodeInstance) compensationHandlerNodeInstance;
                    eventNodeInstance.signalEvent("Compensation", compensationActivityRef);
                }
            }
            assert handlerNode instanceof BoundaryEventNode || handlerNode instanceof EventSubProcessNode : "Unexpected compensation handler node type : " + handlerNode.getClass().getSimpleName();
        } catch (Exception e) {
            throwWorkflowRuntimeException(nodeInstanceContainer, processInstance, "Unable to execute compensation.", e);
        }
    } else {
        Exception e = new IllegalArgumentException("Unsupported compensation handler: " + handler);
        throwWorkflowRuntimeException(nodeInstanceContainer, processInstance, e.getMessage(), e);
    }
}
Also used : NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) Node(io.automatiko.engine.api.definition.process.Node) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) CompensationHandler(io.automatiko.engine.workflow.base.core.context.exception.CompensationHandler) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) List(java.util.List) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)

Example 2 with NodeImpl

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

the class DocumentationHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    Element element = parser.endElementBuilder();
    Object parent = parser.getParent();
    if (parent instanceof NodeImpl) {
        ((NodeImpl) parent).getMetaData().put("Documentation", extractDocumentationText(element));
    } else if (parent instanceof io.automatiko.engine.workflow.base.core.Process) {
        ((io.automatiko.engine.workflow.base.core.Process) parent).getMetaData().put("Documentation", extractDocumentationText(element));
    } else if (parent instanceof Variable) {
        ((Variable) parent).getMetaData().put("Documentation", extractDocumentationText(element));
    }
    return parser.getCurrent();
}
Also used : Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) Element(org.w3c.dom.Element)

Example 3 with NodeImpl

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

the class CompositeNode method addOutgoingConnection.

public void addOutgoingConnection(String type, Connection connection) {
    if (connection.getTo().getParentContainer() == this) {
        linkIncomingConnections(io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE, connection.getTo().getId(), connection.getToType());
    } else {
        super.addOutgoingConnection(type, connection);
        CompositeNode.NodeAndType outNode = internalGetLinkedOutgoingNode(type);
        if (outNode != null) {
            CompositeNodeEnd end = new CompositeNodeEnd(this, connection.getTo(), type);
            internalAddNode(end);
            NodeImpl node = (NodeImpl) outNode.getNode();
            if (node != null) {
                new ConnectionImpl(outNode.getNode(), outNode.getType(), end, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
            }
        }
    }
}
Also used : NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)

Example 4 with NodeImpl

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

the class ProcessHandler method checkBoundaryEventCompensationHandler.

/**
 * This logic belongs in {@link ExecutableProcessValidator} -- except that
 * {@link Association}s are a jbpm-bpmn2 class, and
 * {@link ExecutableProcessValidator} is a jbpm-flow class..
 * </p>
 * Maybe we should have a BPMNProcessValidator class?
 *
 * @param association The association to check.
 * @param source The source of the association.
 * @param target The target of the association.
 */
private static void checkBoundaryEventCompensationHandler(Association association, Node source, Node target) {
    // - event node is boundary event node
    if (!(source instanceof BoundaryEventNode)) {
        throw new IllegalArgumentException("(Compensation) activities may only be associated with Boundary Event Nodes (not with" + source.getClass().getSimpleName() + " nodes [node " + ((String) source.getMetaData().get("UniqueId")) + "].");
    }
    BoundaryEventNode eventNode = (BoundaryEventNode) source;
    // - event node has compensationEvent
    List<EventFilter> eventFilters = eventNode.getEventFilters();
    boolean compensationCheckPassed = false;
    if (eventFilters != null) {
        for (EventFilter filter : eventFilters) {
            if (filter instanceof EventTypeFilter) {
                String type = ((EventTypeFilter) filter).getType();
                if (type != null && type.equals("Compensation")) {
                    compensationCheckPassed = true;
                }
            }
        }
    }
    if (!compensationCheckPassed) {
        throw new IllegalArgumentException("An Event [" + ((String) eventNode.getMetaData("UniqueId")) + "] linked from an association [" + association.getId() + "] must be a (Boundary) Compensation Event.");
    }
    // - boundary event node is attached to the correct type of node?
    /**
     * Tasks: business: RuleSetNode manual: WorkItemNode receive: WorkItemNode
     * script: ActionNode send: WorkItemNode service: WorkItemNode task:
     * WorkItemNode user: HumanTaskNode
     */
    String attachedToId = eventNode.getAttachedToNodeId();
    Node attachedToNode = null;
    for (Node node : eventNode.getParentContainer().getNodes()) {
        if (attachedToId.equals(node.getMetaData().get("UniqueId"))) {
            attachedToNode = node;
            break;
        }
    }
    if (attachedToNode == null) {
        throw new IllegalArgumentException("Boundary Event [" + ((String) eventNode.getMetaData("UniqueId")) + "] is not attached to a node [" + attachedToId + "] that can be found.");
    }
    if (!(attachedToNode instanceof RuleSetNode || attachedToNode instanceof WorkItemNode || attachedToNode instanceof ActionNode || attachedToNode instanceof HumanTaskNode || attachedToNode instanceof CompositeNode || attachedToNode instanceof SubProcessNode)) {
        throw new IllegalArgumentException("Compensation Boundary Event [" + ((String) eventNode.getMetaData("UniqueId")) + "] must be attached to a task or sub-process.");
    }
    // - associated node is a task or subProcess
    compensationCheckPassed = false;
    if (target instanceof WorkItemNode || target instanceof HumanTaskNode || target instanceof CompositeContextNode || target instanceof SubProcessNode) {
        compensationCheckPassed = true;
    } else if (target instanceof ActionNode) {
        Object nodeTypeObj = ((ActionNode) target).getMetaData("NodeType");
        if (nodeTypeObj != null && nodeTypeObj.equals("ScriptTask")) {
            compensationCheckPassed = true;
        }
    }
    if (!compensationCheckPassed) {
        throw new IllegalArgumentException("An Activity [" + ((String) ((NodeImpl) target).getMetaData("UniqueId")) + "] associated with a Boundary Compensation Event must be a Task or a (non-Event) Sub-Process");
    }
    // - associated node does not have outgoingConnections of it's own
    compensationCheckPassed = true;
    NodeImpl targetNode = (NodeImpl) target;
    Map<String, List<io.automatiko.engine.api.definition.process.Connection>> connectionsMap = targetNode.getOutgoingConnections();
    ConnectionImpl outgoingConnection = null;
    for (String connectionType : connectionsMap.keySet()) {
        List<io.automatiko.engine.api.definition.process.Connection> connections = connectionsMap.get(connectionType);
        if (connections != null && !connections.isEmpty()) {
            for (io.automatiko.engine.api.definition.process.Connection connection : connections) {
                Object hiddenObj = connection.getMetaData().get("hidden");
                if (hiddenObj != null && ((Boolean) hiddenObj)) {
                    continue;
                }
                outgoingConnection = (ConnectionImpl) connection;
                compensationCheckPassed = false;
                break;
            }
        }
    }
    if (!compensationCheckPassed) {
        throw new IllegalArgumentException("A Compensation Activity [" + ((String) targetNode.getMetaData("UniqueId")) + "] may not have any outgoing connection [" + (String) outgoingConnection.getMetaData("UniqueId") + "]");
    }
}
Also used : RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) 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) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) List(java.util.List) ArrayList(java.util.ArrayList) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) ExtendedNodeImpl(io.automatiko.engine.workflow.process.core.impl.ExtendedNodeImpl) Connection(io.automatiko.engine.workflow.process.core.Connection) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode)

Example 5 with NodeImpl

use of io.automatiko.engine.workflow.process.core.impl.NodeImpl 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

NodeImpl (io.automatiko.engine.workflow.process.core.impl.NodeImpl)10 Node (io.automatiko.engine.api.definition.process.Node)6 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)6 ConnectionImpl (io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)5 ExtendedNodeImpl (io.automatiko.engine.workflow.process.core.impl.ExtendedNodeImpl)5 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)5 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)5 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)5 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)4 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)4 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)4 FaultNode (io.automatiko.engine.workflow.process.core.node.FaultNode)4 HumanTaskNode (io.automatiko.engine.workflow.process.core.node.HumanTaskNode)4 RuleSetNode (io.automatiko.engine.workflow.process.core.node.RuleSetNode)4 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)4 StateBasedNode (io.automatiko.engine.workflow.process.core.node.StateBasedNode)4 StateNode (io.automatiko.engine.workflow.process.core.node.StateNode)4 SubProcessNode (io.automatiko.engine.workflow.process.core.node.SubProcessNode)4 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)4 NodeContainer (io.automatiko.engine.api.definition.process.NodeContainer)3