Search in sources :

Example 11 with NodeInstanceImpl

use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.

the class CompositeNodeInstance method getNodeInstance.

public NodeInstance getNodeInstance(final Node node) {
    // TODO do this cleaner for start / end of composite?
    if (node instanceof CompositeNode.CompositeNodeStart) {
        CompositeNodeStartInstance nodeInstance = new CompositeNodeStartInstance();
        nodeInstance.setNodeId(node.getId());
        nodeInstance.setNodeInstanceContainer(this);
        nodeInstance.setProcessInstance(getProcessInstance());
        return nodeInstance;
    } else if (node instanceof CompositeNode.CompositeNodeEnd) {
        CompositeNodeEndInstance nodeInstance = new CompositeNodeEndInstance();
        nodeInstance.setNodeId(node.getId());
        nodeInstance.setNodeInstanceContainer(this);
        nodeInstance.setProcessInstance(getProcessInstance());
        return nodeInstance;
    }
    Node actualNode = node;
    // async continuation handling
    if (node instanceof AsyncEventNode) {
        actualNode = ((AsyncEventNode) node).getActualNode();
    } else if (useAsync(node)) {
        actualNode = new AsyncEventNode(node);
    }
    NodeInstanceFactory conf = NodeInstanceFactoryRegistry.getInstance(getProcessInstance().getKnowledgeRuntime().getEnvironment()).getProcessNodeInstanceFactory(actualNode);
    if (conf == null) {
        throw new IllegalArgumentException("Illegal node type: " + node.getClass());
    }
    NodeInstanceImpl nodeInstance = (NodeInstanceImpl) conf.getNodeInstance(actualNode, getProcessInstance(), this);
    if (nodeInstance == null) {
        throw new IllegalArgumentException("Illegal node type: " + node.getClass());
    }
    return nodeInstance;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) NodeInstanceFactory(org.jbpm.workflow.instance.impl.NodeInstanceFactory) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) AsyncEventNode(org.jbpm.workflow.core.node.AsyncEventNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.kie.api.definition.process.Node) AsyncEventNode(org.jbpm.workflow.core.node.AsyncEventNode)

Example 12 with NodeInstanceImpl

use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.

the class WorkflowProcessInstanceUpgrader method updateNodeInstances.

private static void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, Long> nodeMapping) {
    for (NodeInstance nodeInstance : nodeInstanceContainer.getNodeInstances()) {
        String oldNodeId = ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getUniqueId();
        Long newNodeId = nodeMapping.get(oldNodeId);
        if (newNodeId == null) {
            newNodeId = nodeInstance.getNodeId();
        }
        // clean up iteration levels for removed (old) nodes
        Map<String, Integer> iterLevels = ((WorkflowProcessInstanceImpl) nodeInstance.getProcessInstance()).getIterationLevels();
        String uniqueId = (String) ((NodeImpl) nodeInstance.getNode()).getMetaData("UniqueId");
        iterLevels.remove(uniqueId);
        // and now set to new node id
        ((NodeInstanceImpl) nodeInstance).setNodeId(newNodeId);
        if (nodeInstance instanceof NodeInstanceContainer) {
            updateNodeInstances((NodeInstanceContainer) nodeInstance, nodeMapping);
        }
    }
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) NodeInstance(org.kie.api.runtime.process.NodeInstance)

Example 13 with NodeInstanceImpl

use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.

the class AsyncAuditLogProducer method afterNodeTriggered.

@Override
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
    // trigger this to record some of the data (like work item id) after activity was triggered
    NodeInstanceLog log = (NodeInstanceLog) ((NodeInstanceImpl) event.getNodeInstance()).getMetaData().get("NodeInstanceLog");
    NodeInstanceLog logUpdated = (NodeInstanceLog) builder.buildEvent(event, log);
    if (logUpdated != null) {
        sendMessage(log, AFTER_NODE_ENTER_EVENT_TYPE);
    }
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog)

Example 14 with NodeInstanceImpl

use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.

the class FlowTest method testMultiInstanceLoopNumberTest.

@Test
public void testMultiInstanceLoopNumberTest() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-MultiInstanceLoop-Numbering.bpmn2");
    ksession = createKnowledgeSession(kbase);
    Map<String, Object> params = new HashMap<String, Object>();
    final Map<String, String> nodeIdNodeNameMap = new HashMap<String, String>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            NodeInstance nodeInstance = event.getNodeInstance();
            String uniqId = ((NodeInstanceImpl) nodeInstance).getUniqueId();
            String nodeName = ((NodeInstanceImpl) nodeInstance).getNode().getName();
            String prevNodeName = nodeIdNodeNameMap.put(uniqId, nodeName);
            if (prevNodeName != null) {
                assertEquals(uniqId + " is used for more than one node instance: ", prevNodeName, nodeName);
            }
        }
    });
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ProcessInstance processInstance = ksession.startProcess("Test.MultipleInstancesBug", params);
    List<WorkItem> workItems = handler.getWorkItems();
    logger.debug("COMPLETING TASKS.");
    ksession.getWorkItemManager().completeWorkItem(workItems.remove(0).getId(), null);
    ksession.getWorkItemManager().completeWorkItem(workItems.remove(0).getId(), null);
    assertProcessInstanceCompleted(processInstance);
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) WorkItem(org.kie.api.runtime.process.WorkItem) KieBase(org.kie.api.KieBase) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) ForEachJoinNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance.ForEachJoinNodeInstance) ForEachNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance) Test(org.junit.Test)

Example 15 with NodeInstanceImpl

use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.

the class FlowTest method testInclusiveSplitWithLoopInsideSubprocess.

@Test
public void testInclusiveSplitWithLoopInsideSubprocess() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-InclusiveGatewayWithLoopInsideSubprocess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    final Map<String, Integer> nodeInstanceExecutionCounter = new HashMap<String, Integer>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            logger.info("{} {}", event.getNodeInstance().getNodeName(), ((NodeInstanceImpl) event.getNodeInstance()).getLevel());
            Integer value = nodeInstanceExecutionCounter.get(event.getNodeInstance().getNodeName());
            if (value == null) {
                value = new Integer(0);
            }
            value++;
            nodeInstanceExecutionCounter.put(event.getNodeInstance().getNodeName(), value);
        }
    });
    TestWorkItemHandler handler = new TestWorkItemHandler();
    TestWorkItemHandler handler2 = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("testWI", handler);
    ksession.getWorkItemManager().registerWorkItemHandler("testWI2", handler2);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", -1);
    ProcessInstance processInstance = ksession.startProcess("Process_1", params);
    assertProcessInstanceActive(processInstance);
    List<WorkItem> workItems = handler.getWorkItems();
    assertNotNull(workItems);
    assertEquals(2, workItems.size());
    for (WorkItem wi : workItems) {
        assertProcessInstanceActive(processInstance);
        ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
    }
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().getId(), null);
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().getId(), null);
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
    assertProcessInstanceCompleted(processInstance);
    assertEquals(13, nodeInstanceExecutionCounter.size());
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("Start"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("Sub Process 1"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("sb-start"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("sb-end"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("OR diverging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow3"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow2"));
    assertEquals(3, (int) nodeInstanceExecutionCounter.get("OR converging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow6"));
    assertEquals(2, (int) nodeInstanceExecutionCounter.get("Script"));
    assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR diverging"));
    assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR converging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("End"));
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) WorkItem(org.kie.api.runtime.process.WorkItem) KieBase(org.kie.api.KieBase) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Aggregations

NodeInstanceImpl (org.jbpm.workflow.instance.impl.NodeInstanceImpl)20 NodeInstance (org.kie.api.runtime.process.NodeInstance)9 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)7 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)7 HashMap (java.util.HashMap)6 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)4 NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)4 SubProcessNodeInstance (org.jbpm.workflow.instance.node.SubProcessNodeInstance)4 WorkItemNodeInstance (org.jbpm.workflow.instance.node.WorkItemNodeInstance)4 Test (org.junit.Test)4 KieBase (org.kie.api.KieBase)4 Node (org.kie.api.definition.process.Node)4 NodeImpl (org.jbpm.workflow.core.impl.NodeImpl)3 CompositeContextNodeInstance (org.jbpm.workflow.instance.node.CompositeContextNodeInstance)3 ForEachNodeInstance (org.jbpm.workflow.instance.node.ForEachNodeInstance)3 HumanTaskNodeInstance (org.jbpm.workflow.instance.node.HumanTaskNodeInstance)3 TimerNodeInstance (org.jbpm.workflow.instance.node.TimerNodeInstance)3 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)3 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)3 KieSession (org.kie.api.runtime.KieSession)3