Search in sources :

Example 1 with EventSubProcessNode

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

use of io.automatiko.engine.workflow.process.core.node.EventSubProcessNode in project automatiko-engine by automatiko-io.

the class CompositeContextNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    CompositeContextNode compositeNode = (CompositeContextNode) node;
    String nodeType = "subProcess";
    if (node.getMetaData().get("Transaction") != null) {
        nodeType = "transaction";
    }
    writeNode(nodeType, compositeNode, xmlDump, metaDataType);
    if (compositeNode instanceof EventSubProcessNode) {
        xmlDump.append(" triggeredByEvent=\"true\" ");
    }
    Object isForCompensationObject = compositeNode.getMetaData("isForCompensation");
    if (isForCompensationObject != null && ((Boolean) isForCompensationObject)) {
        xmlDump.append("isForCompensation=\"true\" ");
    }
    xmlDump.append(">" + EOL);
    writeExtensionElements(compositeNode, xmlDump);
    // variables
    VariableScope variableScope = (VariableScope) compositeNode.getDefaultContext(VariableScope.VARIABLE_SCOPE);
    if (variableScope != null && !variableScope.getVariables().isEmpty()) {
        xmlDump.append("    <!-- variables -->" + EOL);
        for (Variable variable : variableScope.getVariables()) {
            xmlDump.append("    <property id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "\" ");
            if (variable.getType() != null) {
                xmlDump.append("itemSubjectRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(compositeNode) + "-" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "Item\"");
            }
            // TODO: value
            xmlDump.append("/>" + EOL);
        }
    }
    // nodes
    List<Node> subNodes = getSubNodes(compositeNode);
    XmlBPMNProcessDumper.INSTANCE.visitNodes(subNodes, xmlDump, metaDataType);
    // connections
    visitConnectionsAndAssociations(compositeNode, xmlDump, metaDataType);
    endNode(nodeType, xmlDump);
}
Also used : Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.workflow.process.core.Node) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Example 3 with EventSubProcessNode

use of io.automatiko.engine.workflow.process.core.node.EventSubProcessNode in project automatiko-engine by automatiko-io.

the class ServiceTaskDescriptor method collectHandledErrorCodes.

private Set<String> collectHandledErrorCodes() {
    Set<String> errorCodes = new HashSet<>();
    NodeContainer container = workItemNode.getParentContainer();
    String thisNodeId = (String) workItemNode.getMetaData("UniqueId");
    for (Node node : container.getNodes()) {
        if (node instanceof BoundaryEventNode) {
            String errorCode = (String) node.getMetaData().get("ErrorEvent");
            if (errorCode != null && ((BoundaryEventNode) node).getAttachedToNodeId().equals(thisNodeId)) {
                errorCodes.add(errorCode);
            }
        }
    }
    // next collect event subprocess node with error start event from this level and to all parents
    String replaceRegExp = "Error-|Escalation-";
    for (Node node : container.getNodes()) {
        if (node instanceof EventSubProcessNode) {
            EventSubProcessNode eventSubProcessNode = (EventSubProcessNode) node;
            Node[] nodes = eventSubProcessNode.getNodes();
            for (Node subNode : nodes) {
                // avoids cyclomatic complexity
                if (subNode == null || !(subNode instanceof StartNode)) {
                    continue;
                }
                List<Trigger> triggers = ((StartNode) subNode).getTriggers();
                if (triggers == null) {
                    continue;
                }
                for (Trigger trigger : triggers) {
                    if (trigger instanceof EventTrigger) {
                        final List<EventFilter> filters = ((EventTrigger) trigger).getEventFilters();
                        for (EventFilter filter : filters) {
                            if (filter instanceof EventTypeFilter) {
                                eventSubProcessNode.addEvent((EventTypeFilter) filter);
                                String type = ((EventTypeFilter) filter).getType();
                                if (type.startsWith("Error-")) {
                                    String trimmedType = type.replaceFirst(replaceRegExp, "");
                                    for (String error : trimmedType.split(",")) {
                                        errorCodes.add(error);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return errorCodes;
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Node(io.automatiko.engine.api.definition.process.Node) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) HashSet(java.util.HashSet) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Example 4 with EventSubProcessNode

use of io.automatiko.engine.workflow.process.core.node.EventSubProcessNode in project automatiko-engine by automatiko-io.

the class CompositeNodeInstance method signalEvent.

@Override
public void signalEvent(String type, Object event) {
    List<NodeInstance> currentView = new ArrayList<>(this.nodeInstances);
    super.signalEvent(type, event);
    for (Node node : getCompositeNode().internalGetNodes()) {
        if (node instanceof EventNodeInterface && ((EventNodeInterface) node).acceptsEvent(type, event)) {
            if (node instanceof EventNode && ((EventNode) node).getFrom() == null || node instanceof EventSubProcessNode) {
                EventNodeInstanceInterface eventNodeInstance = (EventNodeInstanceInterface) getNodeInstance(node);
                eventNodeInstance.signalEvent(type, event);
            } else {
                List<NodeInstance> nodeInstances = getNodeInstances(node.getId(), currentView);
                if (nodeInstances != null && !nodeInstances.isEmpty()) {
                    for (NodeInstance nodeInstance : nodeInstances) {
                        ((EventNodeInstanceInterface) nodeInstance).signalEvent(type, event);
                    }
                }
            }
        }
        if (type.equals(node.getName()) && node.getIncomingConnections().isEmpty()) {
            NodeInstance nodeInstance = getNodeInstance(node);
            if (nodeInstance != null) {
                if (event != null) {
                    Map<String, Object> dynamicParams = new HashMap<>(getProcessInstance().getVariables());
                    if (event instanceof Map) {
                        dynamicParams.putAll((Map<String, Object>) event);
                    } else if (event instanceof WorkflowProcessInstance) {
                    // ignore variables of process instance type
                    } else {
                        dynamicParams.put("Data", event);
                    }
                    nodeInstance.setDynamicParameters(dynamicParams);
                }
                nodeInstance.trigger(null, null);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) EventNodeInterface(io.automatiko.engine.workflow.process.core.node.EventNodeInterface) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) 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) ArrayList(java.util.ArrayList) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) HashMap(java.util.HashMap) Map(java.util.Map) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)

Example 5 with EventSubProcessNode

use of io.automatiko.engine.workflow.process.core.node.EventSubProcessNode in project automatiko-engine by automatiko-io.

the class ExecutableProcessFactory method postProcessNodes.

private void postProcessNodes(ExecutableProcess process, NodeContainer container) {
    List<String> eventSubProcessHandlers = new ArrayList<String>();
    for (Node node : container.getNodes()) {
        if (node instanceof NodeContainer) {
            // prepare event sub process
            if (node instanceof EventSubProcessNode) {
                EventSubProcessNode eventSubProcessNode = (EventSubProcessNode) node;
                Node[] nodes = eventSubProcessNode.getNodes();
                for (Node subNode : nodes) {
                    // avoids cyclomatic complexity
                    if (subNode instanceof StartNode) {
                        processEventSubprocessStartNode(process, ((StartNode) subNode), eventSubProcessNode, eventSubProcessHandlers);
                    }
                }
            }
            postProcessNodes(process, (NodeContainer) node);
        }
    }
    // process fault node to disable termnate parent if there is event subprocess handler
    for (Node node : container.getNodes()) {
        if (node instanceof FaultNode) {
            FaultNode faultNode = (FaultNode) node;
            if (eventSubProcessHandlers.contains(faultNode.getFaultName())) {
                faultNode.setTerminateParent(false);
            }
        }
    }
}
Also used : FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) 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) ArrayList(java.util.ArrayList) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer)

Aggregations

EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)20 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)13 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)12 Node (io.automatiko.engine.api.definition.process.Node)11 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)11 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)10 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)9 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)8 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)8 ArrayList (java.util.ArrayList)8 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)7 StateBasedNode (io.automatiko.engine.workflow.process.core.node.StateBasedNode)7 NodeContainer (io.automatiko.engine.api.definition.process.NodeContainer)6 Timer (io.automatiko.engine.workflow.base.core.timer.Timer)6 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)6 EventTrigger (io.automatiko.engine.workflow.process.core.node.EventTrigger)6 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)6 HashMap (java.util.HashMap)6 List (java.util.List)6 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)5