Search in sources :

Example 1 with CancelNodeInstanceAction

use of org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction in project kogito-runtimes by kiegroup.

the class ProcessHandler method linkBoundaryConditionEvent.

private static void linkBoundaryConditionEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) {
    String processId = ((RuleFlowProcess) nodeContainer).getId();
    String eventType = "RuleFlowStateEvent-" + processId + "-" + ((EventNode) node).getUniqueId() + "-" + attachedTo;
    ((EventTypeFilter) ((EventNode) node).getEventFilters().get(0)).setType(eventType);
    boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity");
    if (cancelActivity) {
        List<DroolsAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT);
        if (actions == null) {
            actions = new ArrayList<DroolsAction>();
        }
        DroolsConsequenceAction action = createJavaAction(new CancelNodeInstanceAction(attachedTo));
        actions.add(action);
        ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions);
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) CancelNodeInstanceAction(org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction)

Example 2 with CancelNodeInstanceAction

use of org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction in project kogito-runtimes by kiegroup.

the class ProcessHandler method linkBoundaryTimerEvent.

private static 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);
        DroolsConsequenceAction consequenceAction = createJavaAction(new SignalProcessInstanceAction("Timer-" + attachedTo + "-" + timeDuration + "-" + node.getId(), kcontext -> kcontext.getNodeInstance().getStringId(), 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;
        DroolsConsequenceAction action = createJavaAction(new SignalProcessInstanceAction("Timer-" + attachedTo + "-" + finalTimeCycle + (timer.getPeriod() == null ? "" : "###" + timer.getPeriod()) + "-" + node.getId(), kcontext -> kcontext.getNodeInstance().getStringId(), SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
        compositeNode.addTimer(timer, action);
    } else if (timeDate != null) {
        timer.setDate(timeDate);
        timer.setTimeType(Timer.TIME_DATE);
        DroolsConsequenceAction action = createJavaAction(new SignalProcessInstanceAction("Timer-" + attachedTo + "-" + timeDate + "-" + node.getId(), kcontext -> kcontext.getNodeInstance().getStringId(), SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
        compositeNode.addTimer(timer, action);
    }
    if (cancelActivity) {
        List<DroolsAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT);
        if (actions == null) {
            actions = new ArrayList<DroolsAction>();
        }
        DroolsConsequenceAction action = createJavaAction(new CancelNodeInstanceAction(attachedTo));
        actions.add(action);
        ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions);
    }
}
Also used : EventFilter(org.jbpm.process.core.event.EventFilter) ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) CorrelationManager(org.jbpm.process.core.correlation.CorrelationManager) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) SequenceFlow(org.jbpm.bpmn2.core.SequenceFlow) LoggerFactory(org.slf4j.LoggerFactory) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) StartNode(org.jbpm.workflow.core.node.StartNode) CorrelationProperty(org.jbpm.bpmn2.core.CorrelationProperty) RuleFlowProcessValidator(org.jbpm.ruleflow.core.validation.RuleFlowProcessValidator) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) Constraint(org.jbpm.workflow.core.Constraint) ExtensibleXmlParser(org.drools.core.xml.ExtensibleXmlParser) Association(org.jbpm.bpmn2.core.Association) Connection(org.jbpm.workflow.core.Connection) StateNode(org.jbpm.workflow.core.node.StateNode) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Signal(org.jbpm.bpmn2.core.Signal) CancelNodeInstanceAction(org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Collaboration(org.jbpm.bpmn2.core.Collaboration) Collection(java.util.Collection) Process(org.kie.api.definition.process.Process) VariableScope(org.jbpm.process.core.context.variable.VariableScope) KogitoNode(org.kie.kogito.internal.process.runtime.KogitoNode) Collectors(java.util.stream.Collectors) IntermediateLink(org.jbpm.bpmn2.core.IntermediateLink) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler) Message(org.jbpm.bpmn2.core.Message) List(java.util.List) Error(org.jbpm.bpmn2.core.Error) Stream(java.util.stream.Stream) ContextContainer(org.jbpm.process.core.ContextContainer) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) SAXException(org.xml.sax.SAXException) CorrelationKey(org.jbpm.bpmn2.core.CorrelationKey) ProcessInstanceCompensationAction(org.jbpm.process.instance.impl.actions.ProcessInstanceCompensationAction) Trigger(org.jbpm.workflow.core.node.Trigger) NodeContainer(org.kie.api.definition.process.NodeContainer) DataStore(org.jbpm.bpmn2.core.DataStore) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) SignalProcessInstanceAction(org.jbpm.process.instance.impl.actions.SignalProcessInstanceAction) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) CompensationScope(org.jbpm.process.core.context.exception.CompensationScope) Escalation(org.jbpm.bpmn2.core.Escalation) Split(org.jbpm.workflow.core.node.Split) HashMap(java.util.HashMap) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ArrayList(java.util.ArrayList) Lane(org.jbpm.bpmn2.core.Lane) Timer(org.jbpm.process.core.timer.Timer) HashSet(java.util.HashSet) Expression(org.jbpm.bpmn2.core.Expression) Swimlane(org.jbpm.process.core.context.swimlane.Swimlane) Attributes(org.xml.sax.Attributes) BaseAbstractHandler(org.drools.core.xml.BaseAbstractHandler) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) FaultNode(org.jbpm.workflow.core.node.FaultNode) DroolsAction(org.jbpm.workflow.core.DroolsAction) LinkedHashSet(java.util.LinkedHashSet) CorrelationSubscription(org.jbpm.bpmn2.core.CorrelationSubscription) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Interface(org.jbpm.bpmn2.core.Interface) ConnectionRef(org.jbpm.workflow.core.impl.ConnectionRef) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) Logger(org.slf4j.Logger) Metadata(org.jbpm.ruleflow.core.Metadata) EventNode(org.jbpm.workflow.core.node.EventNode) ConstraintImpl(org.jbpm.workflow.core.impl.ConstraintImpl) Handler(org.drools.core.xml.Handler) MVELMessageExpressionEvaluator(org.jbpm.process.core.event.MVELMessageExpressionEvaluator) Node(org.kie.api.definition.process.Node) CompensationHandler(org.jbpm.process.core.context.exception.CompensationHandler) Definitions(org.jbpm.bpmn2.core.Definitions) Action(org.jbpm.process.instance.impl.Action) KogitoWorkflowProcess(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) DroolsAction(org.jbpm.workflow.core.DroolsAction) SignalProcessInstanceAction(org.jbpm.process.instance.impl.actions.SignalProcessInstanceAction) CancelNodeInstanceAction(org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) Timer(org.jbpm.process.core.timer.Timer)

Example 3 with CancelNodeInstanceAction

use of org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction in project kogito-runtimes by kiegroup.

the class RuleFlowProcessFactory 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_TYPE_PREFIX + 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_TYPE_PREFIX + 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_TYPE_PREFIX + attachedTo + "-" + timeDate + "-" + node.getId()));
    }
    if (cancelActivity) {
        List<DroolsAction> actions = ((EventNode) node).getActions(EVENT_NODE_EXIT);
        if (actions == null) {
            actions = new ArrayList<>();
        }
        DroolsConsequenceAction cancelAction = new DroolsConsequenceAction("java", null);
        cancelAction.setMetaData(ACTION, new CancelNodeInstanceAction(attachedTo));
        actions.add(cancelAction);
        ((EventNode) node).setActions(EVENT_NODE_EXIT, actions);
    }
}
Also used : StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) DroolsAction(org.jbpm.workflow.core.DroolsAction) EventNode(org.jbpm.workflow.core.node.EventNode) CancelNodeInstanceAction(org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction) Timer(org.jbpm.process.core.timer.Timer) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction)

Example 4 with CancelNodeInstanceAction

use of org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction in project kogito-runtimes by kiegroup.

the class ProcessHandler method linkBoundaryEscalationEvent.

private static void linkBoundaryEscalationEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) {
    boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity");
    String escalationCode = (String) node.getMetaData().get("EscalationEvent");
    String escalationStructureRef = (String) node.getMetaData().get("EscalationStructureRef");
    ContextContainer compositeNode = (ContextContainer) attachedNode;
    ExceptionScope exceptionScope = (ExceptionScope) compositeNode.getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
    if (exceptionScope == null) {
        exceptionScope = new ExceptionScope();
        compositeNode.addContext(exceptionScope);
        compositeNode.setDefaultContext(exceptionScope);
    }
    String variable = ((EventNode) node).getVariableName();
    ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
    DroolsConsequenceAction action = createJavaAction(new SignalProcessInstanceAction("Escalation-" + attachedTo + "-" + escalationCode, variable, null, SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
    exceptionHandler.setAction(action);
    exceptionHandler.setFaultVariable(variable);
    exceptionScope.setExceptionHandler(escalationCode, exceptionHandler);
    if (escalationStructureRef != null) {
        exceptionScope.setExceptionHandler(escalationStructureRef, exceptionHandler);
    }
    if (cancelActivity) {
        List<DroolsAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT);
        if (actions == null) {
            actions = new ArrayList<DroolsAction>();
        }
        DroolsConsequenceAction cancelAction = new DroolsConsequenceAction("java", "");
        cancelAction.setMetaData("Action", new CancelNodeInstanceAction(attachedTo));
        actions.add(cancelAction);
        ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions);
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) SignalProcessInstanceAction(org.jbpm.process.instance.impl.actions.SignalProcessInstanceAction) CancelNodeInstanceAction(org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler) ContextContainer(org.jbpm.process.core.ContextContainer) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode)

Example 5 with CancelNodeInstanceAction

use of org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction in project kogito-runtimes by kiegroup.

the class ProcessHandler method linkBoundaryErrorEvent.

private static void linkBoundaryErrorEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) {
    ContextContainer compositeNode = (ContextContainer) attachedNode;
    ExceptionScope exceptionScope = (ExceptionScope) compositeNode.getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
    if (exceptionScope == null) {
        exceptionScope = new ExceptionScope();
        compositeNode.addContext(exceptionScope);
        compositeNode.setDefaultContext(exceptionScope);
    }
    String errorCode = (String) node.getMetaData().get("ErrorEvent");
    boolean hasErrorCode = (Boolean) node.getMetaData().get("HasErrorEvent");
    String errorStructureRef = (String) node.getMetaData().get("ErrorStructureRef");
    ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
    String variable = ((EventNode) node).getVariableName();
    SignalProcessInstanceAction signalAction = new SignalProcessInstanceAction("Error-" + attachedTo + "-" + errorCode, variable, null, SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE);
    DroolsConsequenceAction action = createJavaAction(signalAction);
    exceptionHandler.setAction(action);
    exceptionHandler.setFaultVariable(variable);
    exceptionScope.setExceptionHandler(hasErrorCode ? errorCode : null, exceptionHandler);
    if (errorStructureRef != null) {
        exceptionScope.setExceptionHandler(errorStructureRef, exceptionHandler);
    }
    List<DroolsAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT);
    if (actions == null) {
        actions = new ArrayList<DroolsAction>();
    }
    DroolsConsequenceAction cancelAction = new DroolsConsequenceAction("java", null);
    cancelAction.setMetaData("Action", new CancelNodeInstanceAction(attachedTo));
    actions.add(cancelAction);
    ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions);
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) SignalProcessInstanceAction(org.jbpm.process.instance.impl.actions.SignalProcessInstanceAction) CancelNodeInstanceAction(org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler) ContextContainer(org.jbpm.process.core.ContextContainer) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode)

Aggregations

CancelNodeInstanceAction (org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction)8 DroolsAction (org.jbpm.workflow.core.DroolsAction)8 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)8 EventNode (org.jbpm.workflow.core.node.EventNode)8 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)5 ContextContainer (org.jbpm.process.core.ContextContainer)3 ActionExceptionHandler (org.jbpm.process.core.context.exception.ActionExceptionHandler)3 ExceptionScope (org.jbpm.process.core.context.exception.ExceptionScope)3 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)3 Timer (org.jbpm.process.core.timer.Timer)3 SignalProcessInstanceAction (org.jbpm.process.instance.impl.actions.SignalProcessInstanceAction)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)2 StateBasedNode (org.jbpm.workflow.core.node.StateBasedNode)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1