Search in sources :

Example 1 with StateBasedNode

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

the class ProcessHandler method linkBoundaryEvents.

public void linkBoundaryEvents(NodeContainer nodeContainer) {
    for (Node node : nodeContainer.getNodes()) {
        if (node instanceof EventNode) {
            final String attachedTo = (String) node.getMetaData().get("AttachedTo");
            if (attachedTo != null) {
                for (EventFilter filter : ((EventNode) node).getEventFilters()) {
                    String type = ((EventTypeFilter) filter).getType();
                    Node attachedNode = findNodeByIdOrUniqueIdInMetadata(nodeContainer, attachedTo, "Could not find node to attach to: " + attachedTo);
                    // 
                    if (!(attachedNode instanceof StateBasedNode) && !type.equals("Compensation")) {
                        throw new IllegalArgumentException("Boundary events are supported only on StateBasedNode, found node: " + attachedNode.getClass().getName() + " [" + attachedNode.getMetaData().get("UniqueId") + "]");
                    }
                    if (type.startsWith("Escalation")) {
                        linkBoundaryEscalationEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (type.startsWith("Error-")) {
                        linkBoundaryErrorEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (type.startsWith("Timer-")) {
                        linkBoundaryTimerEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (type.equals("Compensation")) {
                        linkBoundaryCompensationEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (node.getMetaData().get("SignalName") != null || type.startsWith("Message-")) {
                        linkBoundarySignalEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (type.startsWith("Condition-")) {
                        linkBoundaryConditionEvent(nodeContainer, node, attachedTo, attachedNode);
                    }
                }
            }
        }
    }
}
Also used : StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) 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) 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) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter)

Example 2 with StateBasedNode

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

the class TimerHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    Element element = parser.endElementBuilder();
    StateBasedNode parent = (StateBasedNode) parser.getParent();
    String id = element.getAttribute("id");
    emptyAttributeCheck(localName, "id", id, parser);
    String delay = element.getAttribute("delay");
    String period = element.getAttribute("period");
    Timer timer = new Timer();
    timer.setId(new Long(id));
    if (delay != null && delay.length() != 0) {
        timer.setDelay(delay);
    }
    if (period != null && period.length() != 0) {
        timer.setPeriod(period);
    }
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    ProcessAction action = null;
    if (xmlNode instanceof Element) {
        Element actionXml = (Element) xmlNode;
        action = AbstractNodeHandler.extractAction(actionXml);
    }
    parent.addTimer(timer, action);
    return null;
}
Also used : StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) Element(org.w3c.dom.Element)

Example 3 with StateBasedNode

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

the class ProcessHandler method linkBoundaryTimerEvent.

protected void linkBoundaryTimerEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) {
    boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity");
    StateBasedNode compositeNode = (StateBasedNode) attachedNode;
    String timeDuration = (String) node.getMetaData().get("TimeDuration");
    String timeCycle = (String) node.getMetaData().get("TimeCycle");
    String timeDate = (String) node.getMetaData().get("TimeDate");
    Timer timer = new Timer();
    if (timeDuration != null) {
        timer.setDelay(timeDuration);
        timer.setTimeType(Timer.TIME_DURATION);
        ConsequenceAction consequenceAction = createJavaAction(new SignalProcessInstanceAction("Timer-" + attachedTo + "-" + timeDuration + "-" + node.getId(), kcontext -> kcontext.getNodeInstance().getId(), SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
        compositeNode.addTimer(timer, consequenceAction);
    } else if (timeCycle != null) {
        int index = timeCycle.indexOf("###");
        if (index != -1) {
            String period = timeCycle.substring(index + 3);
            timeCycle = timeCycle.substring(0, index);
            timer.setPeriod(period);
        }
        timer.setDelay(timeCycle);
        timer.setTimeType(Timer.TIME_CYCLE);
        String finalTimeCycle = timeCycle;
        ConsequenceAction action = createJavaAction(new SignalProcessInstanceAction("Timer-" + attachedTo + "-" + finalTimeCycle + (timer.getPeriod() == null ? "" : "###" + timer.getPeriod()) + "-" + node.getId(), kcontext -> kcontext.getNodeInstance().getId(), SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
        compositeNode.addTimer(timer, action);
    } else if (timeDate != null) {
        timer.setDate(timeDate);
        timer.setTimeType(Timer.TIME_DATE);
        ConsequenceAction action = createJavaAction(new SignalProcessInstanceAction("Timer-" + attachedTo + "-" + timeDate + "-" + node.getId(), kcontext -> kcontext.getNodeInstance().getId(), SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
        compositeNode.addTimer(timer, action);
    }
    if (cancelActivity) {
        List<ProcessAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT);
        if (actions == null) {
            actions = new ArrayList<ProcessAction>();
        }
        ConsequenceAction action = createJavaAction(new CancelNodeInstanceAction(attachedTo));
        actions.add(action);
        ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions);
    }
}
Also used : Handler(io.automatiko.engine.workflow.compiler.xml.Handler) CompensationHandler(io.automatiko.engine.workflow.base.core.context.exception.CompensationHandler) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) Constraint(io.automatiko.engine.workflow.process.core.Constraint) ExecutableProcessValidator(io.automatiko.engine.workflow.process.executable.core.validation.ExecutableProcessValidator) LoggerFactory(org.slf4j.LoggerFactory) Definitions(io.automatiko.engine.workflow.bpmn2.core.Definitions) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) FunctionTagDefinition(io.automatiko.engine.workflow.base.core.FunctionTagDefinition) Error(io.automatiko.engine.workflow.bpmn2.core.Error) Action(io.automatiko.engine.workflow.base.instance.impl.Action) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) Matcher(java.util.regex.Matcher) ConstraintImpl(io.automatiko.engine.workflow.process.core.impl.ConstraintImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) DataStore(io.automatiko.engine.workflow.bpmn2.core.DataStore) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) Map(java.util.Map) TagDefinition(io.automatiko.engine.workflow.base.core.TagDefinition) Swimlane(io.automatiko.engine.workflow.base.core.context.swimlane.Swimlane) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) ExceptionScope(io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) List(java.util.List) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) ProcessInstanceCompensationAction(io.automatiko.engine.workflow.base.instance.impl.actions.ProcessInstanceCompensationAction) PatternConstants(io.automatiko.engine.workflow.util.PatternConstants) ExtensibleXmlParser(io.automatiko.engine.workflow.compiler.xml.ExtensibleXmlParser) SAXException(org.xml.sax.SAXException) SignalProcessInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) BaseAbstractHandler(io.automatiko.engine.workflow.compiler.xml.BaseAbstractHandler) StaticTagDefinition(io.automatiko.engine.workflow.base.core.StaticTagDefinition) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) Interface(io.automatiko.engine.workflow.bpmn2.core.Interface) Lane(io.automatiko.engine.workflow.bpmn2.core.Lane) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) IntermediateLink(io.automatiko.engine.workflow.bpmn2.core.IntermediateLink) Resource(io.automatiko.engine.workflow.bpmn2.core.Resource) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Split(io.automatiko.engine.workflow.process.core.node.Split) HashMap(java.util.HashMap) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) Node(io.automatiko.engine.api.definition.process.Node) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) CancelNodeInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.CancelNodeInstanceAction) ActionExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler) Escalation(io.automatiko.engine.workflow.bpmn2.core.Escalation) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) Attributes(org.xml.sax.Attributes) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) Association(io.automatiko.engine.workflow.bpmn2.core.Association) Logger(org.slf4j.Logger) Signal(io.automatiko.engine.workflow.bpmn2.core.Signal) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) Connection(io.automatiko.engine.workflow.process.core.Connection) ExtendedNodeImpl(io.automatiko.engine.workflow.process.core.impl.ExtendedNodeImpl) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) SequenceFlow(io.automatiko.engine.workflow.bpmn2.core.SequenceFlow) ConnectionRef(io.automatiko.engine.workflow.process.core.impl.ConnectionRef) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Process(io.automatiko.engine.workflow.base.core.Process) CompensationScope(io.automatiko.engine.workflow.base.core.context.exception.CompensationScope) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) MVEL(org.mvel2.MVEL) Message(io.automatiko.engine.workflow.bpmn2.core.Message) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) SignalProcessInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction) CancelNodeInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.CancelNodeInstanceAction) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) Timer(io.automatiko.engine.workflow.base.core.timer.Timer)

Example 4 with StateBasedNode

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

the class ExecutableProcessFactory method linkBoundaryTimerEvent.

protected void linkBoundaryTimerEvent(Node node, String attachedTo, Node attachedNode) {
    boolean cancelActivity = (Boolean) node.getMetaData().get(CANCEL_ACTIVITY);
    StateBasedNode compositeNode = (StateBasedNode) attachedNode;
    String timeDuration = (String) node.getMetaData().get(TIME_DURATION);
    String timeCycle = (String) node.getMetaData().get(TIME_CYCLE);
    String timeDate = (String) node.getMetaData().get(TIME_DATE);
    Timer timer = new Timer();
    if (timeDuration != null) {
        timer.setDelay(timeDuration);
        timer.setTimeType(Timer.TIME_DURATION);
        compositeNode.addTimer(timer, timerAction("Timer-" + attachedTo + "-" + timeDuration + "-" + node.getId()));
    } else if (timeCycle != null) {
        int index = timeCycle.indexOf("###");
        if (index != -1) {
            String period = timeCycle.substring(index + 3);
            timeCycle = timeCycle.substring(0, index);
            timer.setPeriod(period);
        }
        timer.setDelay(timeCycle);
        timer.setTimeType(Timer.TIME_CYCLE);
        compositeNode.addTimer(timer, timerAction("Timer-" + attachedTo + "-" + timeCycle + (timer.getPeriod() == null ? "" : "###" + timer.getPeriod()) + "-" + node.getId()));
    } else if (timeDate != null) {
        timer.setDate(timeDate);
        timer.setTimeType(Timer.TIME_DATE);
        compositeNode.addTimer(timer, timerAction("Timer-" + attachedTo + "-" + timeDate + "-" + node.getId()));
    }
    if (cancelActivity) {
        List<ProcessAction> actions = ((EventNode) node).getActions(EVENT_NODE_EXIT);
        if (actions == null) {
            actions = new ArrayList<>();
        }
        ConsequenceAction cancelAction = new ConsequenceAction("java", null);
        cancelAction.setMetaData(ACTION, new CancelNodeInstanceAction(attachedTo));
        actions.add(cancelAction);
        ((EventNode) node).setActions(EVENT_NODE_EXIT, actions);
    }
}
Also used : StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) CancelNodeInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.CancelNodeInstanceAction) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)

Aggregations

StateBasedNode (io.automatiko.engine.workflow.process.core.node.StateBasedNode)4 Timer (io.automatiko.engine.workflow.base.core.timer.Timer)3 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)3 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)3 Node (io.automatiko.engine.api.definition.process.Node)2 EventFilter (io.automatiko.engine.workflow.base.core.event.EventFilter)2 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)2 CancelNodeInstanceAction (io.automatiko.engine.workflow.base.instance.impl.actions.CancelNodeInstanceAction)2 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)2 NodeContainer (io.automatiko.engine.api.definition.process.NodeContainer)1 WorkflowProcess (io.automatiko.engine.api.definition.process.WorkflowProcess)1 ContextContainer (io.automatiko.engine.workflow.base.core.ContextContainer)1 FunctionTagDefinition (io.automatiko.engine.workflow.base.core.FunctionTagDefinition)1 Process (io.automatiko.engine.workflow.base.core.Process)1 StaticTagDefinition (io.automatiko.engine.workflow.base.core.StaticTagDefinition)1 TagDefinition (io.automatiko.engine.workflow.base.core.TagDefinition)1 ActionExceptionHandler (io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler)1 CompensationHandler (io.automatiko.engine.workflow.base.core.context.exception.CompensationHandler)1 CompensationScope (io.automatiko.engine.workflow.base.core.context.exception.CompensationScope)1 ExceptionScope (io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope)1