Search in sources :

Example 1 with DroolsAction

use of org.jbpm.workflow.core.DroolsAction in project jbpm by kiegroup.

the class ActionNodeHandler method handleNode.

public void handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    ActionNode actionNode = (ActionNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    if (xmlNode instanceof Element) {
        Element actionXml = (Element) xmlNode;
        DroolsAction action = extractAction(actionXml);
        actionNode.setAction(action);
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) Element(org.w3c.dom.Element) ActionNode(org.jbpm.workflow.core.node.ActionNode)

Example 2 with DroolsAction

use of org.jbpm.workflow.core.DroolsAction in project jbpm by kiegroup.

the class VariablePersistenceStrategyTest method getKnowledgeBaseForExtendingInterfaceVariablePersistence.

private KieBase getKnowledgeBaseForExtendingInterfaceVariablePersistence(String processId, final String variableText) {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId(processId);
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("x");
    ObjectDataType extendingSerializableDataType = new ObjectDataType();
    extendingSerializableDataType.setClassName(MyVariableExtendingSerializable.class.getName());
    variable.setType(extendingSerializableDataType);
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    WorkItemNode workItemNode = new WorkItemNode();
    workItemNode.setName("workItemNode");
    workItemNode.setId(2);
    Work work = new WorkImpl();
    work.setName("MyWork");
    workItemNode.setWork(work);
    ActionNode actionNode = new ActionNode();
    actionNode.setName("Print");
    DroolsAction action = new DroolsConsequenceAction("java", null);
    action.setMetaData("Action", new Action() {

        public void execute(ProcessContext context) throws Exception {
            Assert.assertEquals(variableText, ((MyVariableExtendingSerializable) context.getVariable("x")).getText());
            ;
        }
    });
    actionNode.setAction(action);
    actionNode.setId(3);
    EndNode endNode = new EndNode();
    endNode.setName("EndNode");
    endNode.setId(4);
    connect(startNode, workItemNode);
    connect(workItemNode, actionNode);
    connect(actionNode, endNode);
    process.addNode(startNode);
    process.addNode(workItemNode);
    process.addNode(actionNode);
    process.addNode(endNode);
    KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    ((KnowledgeBaseImpl) kbase).addProcess(process);
    return kbase;
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) DroolsAction(org.jbpm.workflow.core.DroolsAction) Action(org.jbpm.process.instance.impl.Action) Variable(org.jbpm.process.core.context.variable.Variable) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ArrayList(java.util.ArrayList) ActionNode(org.jbpm.workflow.core.node.ActionNode) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) ProcessContext(org.kie.api.runtime.process.ProcessContext) NamingException(javax.naming.NamingException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) HeuristicMixedException(javax.transaction.HeuristicMixedException) RollbackException(javax.transaction.RollbackException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) MyVariableExtendingSerializable(org.jbpm.persistence.session.objects.MyVariableExtendingSerializable) EndNode(org.jbpm.workflow.core.node.EndNode) KieBase(org.kie.api.KieBase) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl)

Example 3 with DroolsAction

use of org.jbpm.workflow.core.DroolsAction in project jbpm 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 = new DroolsConsequenceAction("java", null);
        action.setMetaData("Action", 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.CancelNodeInstanceAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction)

Example 4 with DroolsAction

use of org.jbpm.workflow.core.DroolsAction in project jbpm 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);
        compositeNode.addTimer(timer, new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Timer-" + attachedTo + "-" + timeDuration + "-" + node.getId() + "\", kcontext.getNodeInstance().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, new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Timer-" + attachedTo + "-" + timeCycle + (timer.getPeriod() == null ? "" : "###" + timer.getPeriod()) + "-" + node.getId() + "\", kcontext.getNodeInstance().getId());"));
    } else if (timeDate != null) {
        timer.setDate(timeDate);
        timer.setTimeType(Timer.TIME_DATE);
        compositeNode.addTimer(timer, new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Timer-" + attachedTo + "-" + timeDate + "-" + node.getId() + "\", kcontext.getNodeInstance().getId());"));
    }
    if (cancelActivity) {
        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 : StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) DroolsAction(org.jbpm.workflow.core.DroolsAction) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) CancelNodeInstanceAction(org.jbpm.process.instance.impl.CancelNodeInstanceAction) Timer(org.jbpm.process.core.timer.Timer) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction)

Example 5 with DroolsAction

use of org.jbpm.workflow.core.DroolsAction in project jbpm by kiegroup.

the class ProcessHandler method handleIntermediateOrEndThrowCompensationEvent.

protected void handleIntermediateOrEndThrowCompensationEvent(ExtendedNodeImpl throwEventNode) {
    if (throwEventNode.getMetaData("compensation-activityRef") != null) {
        String activityRef = (String) throwEventNode.getMetaData().remove("compensation-activityRef");
        NodeContainer nodeParent = (NodeContainer) throwEventNode.getNodeContainer();
        if (nodeParent instanceof EventSubProcessNode) {
            boolean compensationEventSubProcess = false;
            List<Trigger> startTriggers = ((EventSubProcessNode) nodeParent).findStartNode().getTriggers();
            CESP_CHECK: for (Trigger trigger : startTriggers) {
                if (trigger instanceof EventTrigger) {
                    for (EventFilter filter : ((EventTrigger) trigger).getEventFilters()) {
                        if (((EventTypeFilter) filter).getType().equals("Compensation")) {
                            compensationEventSubProcess = true;
                            break CESP_CHECK;
                        }
                    }
                }
            }
            if (compensationEventSubProcess) {
                // BPMN2 spec, p. 252, p. 248: intermediate and end compensation event visibility scope
                nodeParent = (NodeContainer) ((NodeImpl) nodeParent).getNodeContainer();
            }
        }
        String parentId;
        if (nodeParent instanceof RuleFlowProcess) {
            parentId = ((RuleFlowProcess) nodeParent).getId();
        } else {
            parentId = (String) ((NodeImpl) nodeParent).getMetaData("UniqueId");
        }
        String compensationEvent;
        if (activityRef.length() == 0) {
            // general/implicit compensation
            compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + parentId;
        } else {
            // specific compensation
            compensationEvent = activityRef;
        }
        DroolsConsequenceAction compensationAction = new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Compensation\", \"" + compensationEvent + "\");");
        if (throwEventNode instanceof ActionNode) {
            ((ActionNode) throwEventNode).setAction(compensationAction);
        } else if (throwEventNode instanceof EndNode) {
            List<DroolsAction> actions = new ArrayList<DroolsAction>();
            actions.add(compensationAction);
            ((EndNode) throwEventNode).setActions(EndNode.EVENT_NODE_ENTER, actions);
        }
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) NodeContainer(org.kie.api.definition.process.NodeContainer) EventFilter(org.jbpm.process.core.event.EventFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) Trigger(org.jbpm.workflow.core.node.Trigger) EndNode(org.jbpm.workflow.core.node.EndNode) List(java.util.List) ArrayList(java.util.ArrayList) EventTrigger(org.jbpm.workflow.core.node.EventTrigger)

Aggregations

DroolsAction (org.jbpm.workflow.core.DroolsAction)53 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)40 ArrayList (java.util.ArrayList)30 ActionNode (org.jbpm.workflow.core.node.ActionNode)25 Action (org.jbpm.process.instance.impl.Action)22 EndNode (org.jbpm.workflow.core.node.EndNode)22 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)19 Test (org.junit.Test)18 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)17 StartNode (org.jbpm.workflow.core.node.StartNode)17 KieSession (org.kie.api.runtime.KieSession)17 ProcessContext (org.kie.api.runtime.process.ProcessContext)17 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)15 EventNode (org.jbpm.workflow.core.node.EventNode)14 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)13 Variable (org.jbpm.process.core.context.variable.Variable)10 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)10 TestProcessEventListener (org.jbpm.process.test.TestProcessEventListener)9 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)8 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)8