Search in sources :

Example 1 with DroolsConsequenceAction

use of org.jbpm.workflow.core.impl.DroolsConsequenceAction in project jbpm by kiegroup.

the class ActionNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    ActionNode actionNode = (ActionNode) node;
    writeNode("actionNode", actionNode, xmlDump, includeMeta);
    DroolsConsequenceAction action = (DroolsConsequenceAction) actionNode.getAction();
    if (action != null || (includeMeta && containsMetaData(actionNode))) {
        xmlDump.append(">" + EOL);
        if (action != null) {
            writeAction(action, xmlDump);
        }
        if (includeMeta) {
            writeMetaData(actionNode, xmlDump);
        }
        endNode("actionNode", xmlDump);
    } else {
        endNode(xmlDump);
    }
}
Also used : DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ActionNode(org.jbpm.workflow.core.node.ActionNode)

Example 2 with DroolsConsequenceAction

use of org.jbpm.workflow.core.impl.DroolsConsequenceAction in project jbpm by kiegroup.

the class SingleSessionCommandServiceTest method getProcessTimer.

private List<KiePackage> getProcessTimer() {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId("org.drools.test.TestProcess");
    process.setName("TestProcess");
    process.setPackageName("org.drools.test");
    StartNode start = new StartNode();
    start.setId(1);
    start.setName("Start");
    process.addNode(start);
    TimerNode timerNode = new TimerNode();
    timerNode.setId(2);
    timerNode.setName("Timer");
    Timer timer = new Timer();
    timer.setDelay("2000");
    timerNode.setTimer(timer);
    process.addNode(timerNode);
    new ConnectionImpl(start, Node.CONNECTION_DEFAULT_TYPE, timerNode, Node.CONNECTION_DEFAULT_TYPE);
    ActionNode actionNode = new ActionNode();
    actionNode.setId(3);
    actionNode.setName("Action");
    DroolsConsequenceAction action = new DroolsConsequenceAction();
    action.setDialect("java");
    action.setConsequence("System.out.println(\"Executed action\");");
    actionNode.setAction(action);
    process.addNode(actionNode);
    new ConnectionImpl(timerNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
    EndNode end = new EndNode();
    end.setId(6);
    end.setName("End");
    process.addNode(end);
    new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, end, Node.CONNECTION_DEFAULT_TYPE);
    KnowledgeBuilderImpl packageBuilder = new KnowledgeBuilderImpl();
    ProcessBuilderImpl processBuilder = new ProcessBuilderImpl(packageBuilder);
    processBuilder.buildProcess(process, null);
    return Arrays.asList(packageBuilder.getPackages());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) Timer(org.jbpm.process.core.timer.Timer) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) EndNode(org.jbpm.workflow.core.node.EndNode) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) ActionNode(org.jbpm.workflow.core.node.ActionNode) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) TimerNode(org.jbpm.workflow.core.node.TimerNode) ProcessBuilderImpl(org.jbpm.compiler.ProcessBuilderImpl)

Example 3 with DroolsConsequenceAction

use of org.jbpm.workflow.core.impl.DroolsConsequenceAction 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 4 with DroolsConsequenceAction

use of org.jbpm.workflow.core.impl.DroolsConsequenceAction in project jbpm by kiegroup.

the class StartEventHandler method handleTimerNode.

protected void handleTimerNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    StartNode startNode = (StartNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("timerEventDefinition".equals(nodeName)) {
            Timer timer = new Timer();
            org.w3c.dom.Node subNode = xmlNode.getFirstChild();
            while (subNode instanceof Element) {
                String subNodeName = subNode.getNodeName();
                if ("timeCycle".equals(subNodeName)) {
                    String delay = subNode.getTextContent();
                    int index = delay.indexOf("###");
                    if (index != -1) {
                        String period = delay.substring(index + 3);
                        delay = delay.substring(0, index);
                        timer.setPeriod(period);
                    } else {
                        timer.setPeriod(delay);
                    }
                    timer.setTimeType(Timer.TIME_CYCLE);
                    timer.setDelay(delay);
                    break;
                } else if ("timeDuration".equals(subNodeName)) {
                    String delay = subNode.getTextContent();
                    timer.setTimeType(Timer.TIME_DURATION);
                    timer.setDelay(delay);
                    break;
                } else if ("timeDate".equals(subNodeName)) {
                    String date = subNode.getTextContent();
                    timer.setTimeType(Timer.TIME_DATE);
                    timer.setDate(date);
                    break;
                }
                subNode = subNode.getNextSibling();
            }
            startNode.setTimer(timer);
            if (parser.getParent() instanceof EventSubProcessNode) {
                // handle timer on start events like normal (non rule) timers for event sub process
                EventTrigger trigger = new EventTrigger();
                EventTypeFilter eventFilter = new EventTypeFilter();
                eventFilter.setType("Timer-" + ((EventSubProcessNode) parser.getParent()).getId());
                trigger.addEventFilter(eventFilter);
                String mapping = (String) startNode.getMetaData("TriggerMapping");
                if (mapping != null) {
                    trigger.addInMapping(mapping, "event");
                }
                startNode.addTrigger(trigger);
                ((EventSubProcessNode) parser.getParent()).addTimer(timer, new DroolsConsequenceAction("java", ""));
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : StartNode(org.jbpm.workflow.core.node.StartNode) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) Timer(org.jbpm.process.core.timer.Timer) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) Element(org.w3c.dom.Element) EventTrigger(org.jbpm.workflow.core.node.EventTrigger)

Example 5 with DroolsConsequenceAction

use of org.jbpm.workflow.core.impl.DroolsConsequenceAction 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)

Aggregations

DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)73 ActionNode (org.jbpm.workflow.core.node.ActionNode)41 DroolsAction (org.jbpm.workflow.core.DroolsAction)40 ArrayList (java.util.ArrayList)32 EndNode (org.jbpm.workflow.core.node.EndNode)28 StartNode (org.jbpm.workflow.core.node.StartNode)25 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)24 Action (org.jbpm.process.instance.impl.Action)21 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)18 Test (org.junit.Test)18 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)17 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)17 KieSession (org.kie.api.runtime.KieSession)17 ProcessContext (org.kie.api.runtime.process.ProcessContext)17 EventNode (org.jbpm.workflow.core.node.EventNode)16 Timer (org.jbpm.process.core.timer.Timer)11 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 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)8