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;
}
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);
}
}
}
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);
}
}
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);
}
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"));
}
Aggregations