Search in sources :

Example 16 with WorkImpl

use of org.jbpm.process.core.impl.WorkImpl in project jbpm by kiegroup.

the class EventSubProcessTest method testNestedEventSubProcess.

@Test
public void testNestedEventSubProcess() throws Exception {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setAutoComplete(true);
    String processId = "org.jbpm.process.event.subprocess";
    process.setId(processId);
    process.setName("Event SubProcess Process");
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("event");
    ObjectDataType personDataType = new ObjectDataType();
    personDataType.setClassName("org.drools.Person");
    variable.setType(personDataType);
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
    NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
    NodeCreator<CompositeNode> compNodeCreator = new NodeCreator<CompositeNode>(process, CompositeNode.class);
    // outer process
    StartNode startNode = startNodeCreator.createNode("start0");
    CompositeNode compositeNode = compNodeCreator.createNode("comp0");
    connect(startNode, compositeNode);
    EndNode endNode = endNodeCreator.createNode("end0");
    connect(compositeNode, endNode);
    // 1rst level nested subprocess
    startNodeCreator.setNodeContainer(compositeNode);
    endNodeCreator.setNodeContainer(compositeNode);
    compNodeCreator.setNodeContainer(compositeNode);
    startNode = startNodeCreator.createNode("start1");
    compositeNode = compNodeCreator.createNode("comp1");
    connect(startNode, compositeNode);
    endNode = endNodeCreator.createNode("end1");
    connect(compositeNode, endNode);
    // 2nd level subprocess
    startNodeCreator.setNodeContainer(compositeNode);
    endNodeCreator.setNodeContainer(compositeNode);
    NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(compositeNode, WorkItemNode.class);
    startNode = startNodeCreator.createNode("start2");
    WorkItemNode workItemNode = workItemNodeCreator.createNode("workItem2");
    Work work = new WorkImpl();
    String workItemName = "play";
    work.setName(workItemName);
    workItemNode.setWork(work);
    connect(startNode, workItemNode);
    endNode = endNodeCreator.createNode("end2");
    connect(workItemNode, endNode);
    // (3rd level) event sub process in 2nd level subprocess
    NodeCreator<EventSubProcessNode> espNodeCreator = new NodeCreator<EventSubProcessNode>(compositeNode, EventSubProcessNode.class);
    EventSubProcessNode espNode = espNodeCreator.createNode("eventSub2");
    EventTypeFilter eventFilter = new EventTypeFilter();
    String EVENT_NAME = "subEvent";
    eventFilter.setType(EVENT_NAME);
    espNode.addEvent(eventFilter);
    startNodeCreator.setNodeContainer(espNode);
    endNodeCreator.setNodeContainer(espNode);
    NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(espNode, ActionNode.class);
    startNode = startNodeCreator.createNode("start3*");
    ActionNode actionNode = actionNodeCreator.createNode("print3*");
    actionNode.setName("Print");
    final List<String> eventList = new ArrayList<String>();
    DroolsAction action = new DroolsConsequenceAction("java", null);
    action.setMetaData("Action", new Action() {

        public void execute(ProcessContext context) throws Exception {
            eventList.add("Executed action");
        }
    });
    actionNode.setAction(action);
    connect(startNode, actionNode);
    endNode = endNodeCreator.createNode("end3*");
    connect(actionNode, endNode);
    // run process
    KieSession ksession = createKieSession(process);
    TestProcessEventListener procEventListener = new TestProcessEventListener();
    ksession.addEventListener(procEventListener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler(workItemName, workItemHandler);
    ProcessInstance processInstance = ksession.startProcess(processId);
    processInstance.signalEvent(EVENT_NAME, null);
    assertEquals("Event " + EVENT_NAME + " did not fire!", 1, eventList.size());
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    verifyEventHistory(nestedEventOrder, procEventListener.getEventHistory());
}
Also used : TestWorkItemHandler(org.jbpm.process.test.TestWorkItemHandler) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) 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) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ArrayList(java.util.ArrayList) ActionNode(org.jbpm.workflow.core.node.ActionNode) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) ProcessContext(org.kie.api.runtime.process.ProcessContext) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl) KieSession(org.kie.api.runtime.KieSession) DroolsAction(org.jbpm.workflow.core.DroolsAction) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EndNode(org.jbpm.workflow.core.node.EndNode) NodeCreator(org.jbpm.process.test.NodeCreator) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) TestProcessEventListener(org.jbpm.process.test.TestProcessEventListener) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 17 with WorkImpl

use of org.jbpm.process.core.impl.WorkImpl in project jbpm by kiegroup.

the class WorkItemNodeFactory method workName.

public WorkItemNodeFactory workName(String name) {
    Work work = getWorkItemNode().getWork();
    if (work == null) {
        work = new WorkImpl();
        getWorkItemNode().setWork(work);
    }
    work.setName(name);
    return this;
}
Also used : Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl)

Example 18 with WorkImpl

use of org.jbpm.process.core.impl.WorkImpl in project jbpm by kiegroup.

the class HumanTaskNodeFactory method comment.

public HumanTaskNodeFactory comment(String comment) {
    Work work = getHumanTaskNode().getWork();
    if (work == null) {
        work = new WorkImpl();
        getHumanTaskNode().setWork(work);
    }
    work.setParameter("Comment", comment);
    return this;
}
Also used : Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl)

Example 19 with WorkImpl

use of org.jbpm.process.core.impl.WorkImpl in project jbpm by kiegroup.

the class HumanTaskNodeFactory method actorId.

public HumanTaskNodeFactory actorId(String actorId) {
    Work work = getHumanTaskNode().getWork();
    if (work == null) {
        work = new WorkImpl();
        getHumanTaskNode().setWork(work);
    }
    work.setParameter("ActorId", actorId);
    return this;
}
Also used : Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl)

Example 20 with WorkImpl

use of org.jbpm.process.core.impl.WorkImpl in project jbpm by kiegroup.

the class HumanTaskNodeFactory method workParameter.

public HumanTaskNodeFactory workParameter(String name, Object value) {
    Work work = getHumanTaskNode().getWork();
    if (work == null) {
        work = new WorkImpl();
        getHumanTaskNode().setWork(work);
    }
    work.setParameter(name, value);
    return this;
}
Also used : Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl)

Aggregations

Work (org.jbpm.process.core.Work)23 WorkImpl (org.jbpm.process.core.impl.WorkImpl)23 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)10 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)10 EndNode (org.jbpm.workflow.core.node.EndNode)8 StartNode (org.jbpm.workflow.core.node.StartNode)8 ArrayList (java.util.ArrayList)7 Variable (org.jbpm.process.core.context.variable.Variable)6 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)6 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)5 ActionNode (org.jbpm.workflow.core.node.ActionNode)5 ParameterDefinition (org.jbpm.process.core.ParameterDefinition)4 ParameterDefinitionImpl (org.jbpm.process.core.impl.ParameterDefinitionImpl)4 HashSet (java.util.HashSet)3 IntegerDataType (org.jbpm.process.core.datatype.impl.type.IntegerDataType)3 StringDataType (org.jbpm.process.core.datatype.impl.type.StringDataType)3 DroolsAction (org.jbpm.workflow.core.DroolsAction)3 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)3 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)2 ProcessBuilderImpl (org.jbpm.compiler.ProcessBuilderImpl)2