use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.
the class CancelNodeInstanceCommand method execute.
public Void execute(Context context) {
logger.debug("About to cancel node instance with id {} on process instance {}", nodeInstanceId, processInstanceId);
KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
RuleFlowProcessInstance wfp = (RuleFlowProcessInstance) kieSession.getProcessInstance(processInstanceId, false);
if (wfp == null) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " not found");
}
NodeInstance nodeInstance = wfp.getNodeInstances(true).stream().filter(ni -> ni.getId() == nodeInstanceId).findFirst().orElse(null);
if (nodeInstance == null) {
throw new NodeInstanceNotFoundException("Node instance with id " + nodeInstanceId + " not found");
}
logger.debug("Found node instance {} to be canceled", nodeInstance);
((NodeInstanceImpl) nodeInstance).cancel();
logger.debug("Node instance {} canceled successfully", nodeInstance);
return null;
}
use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.
the class FlowTest method testInclusiveJoinWithLoopAndHumanTasks.
@Test
public void testInclusiveJoinWithLoopAndHumanTasks() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-InclusiveGatewayWithHumanTasksProcess.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();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("firstXor", true);
params.put("secondXor", true);
params.put("thirdXor", true);
ProcessInstance processInstance = ksession.startProcess("InclusiveWithAdvancedLoop", params);
// simulate completion of first task
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
List<WorkItem> workItems = handler.getWorkItems();
assertNotNull(workItems);
assertEquals(2, workItems.size());
WorkItem remainingWork = null;
for (WorkItem wi : workItems) {
assertProcessInstanceActive(processInstance);
// complete second task that will trigger converging OR gateway
if (wi.getParameter("NodeName").equals("HT Form2")) {
ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
} else {
remainingWork = wi;
}
}
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(remainingWork.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("HT Form1"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("and1"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("HT Form2"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("xor1"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("xor2"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("HT Form3"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Koniec"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("xor 3"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("HT Form4"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("xor4"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Koniec2"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("or1"));
}
use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.
the class CreateNewNodeFactory method getNodeInstance.
public NodeInstance getNodeInstance(Node node, WorkflowProcessInstance processInstance, NodeInstanceContainer nodeInstanceContainer) {
try {
NodeInstanceImpl nodeInstance = (NodeInstanceImpl) this.cls.newInstance();
nodeInstance.setNodeId(node.getId());
nodeInstance.setNodeInstanceContainer(nodeInstanceContainer);
nodeInstance.setProcessInstance(processInstance);
String uniqueId = (String) node.getMetaData().get("UniqueId");
assert uniqueId != null : node.getClass().getSimpleName() + " [" + node.getName() + "] does not have a unique id.";
if (uniqueId == null) {
uniqueId = node.getId() + "";
}
nodeInstance.setMetaData("UniqueId", uniqueId);
int level = ((org.jbpm.workflow.instance.NodeInstanceContainer) nodeInstanceContainer).getLevelForNode(uniqueId);
nodeInstance.setLevel(level);
return nodeInstance;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Unable to instantiate node: '" + this.cls.getName() + "':" + e.getMessage());
}
}
use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.
the class ReuseNodeFactory method getNodeInstance.
public NodeInstance getNodeInstance(Node node, WorkflowProcessInstance processInstance, NodeInstanceContainer nodeInstanceContainer) {
NodeInstance result = ((org.jbpm.workflow.instance.NodeInstanceContainer) nodeInstanceContainer).getFirstNodeInstance(node.getId());
if (result != null) {
return result;
}
try {
NodeInstanceImpl nodeInstance = (NodeInstanceImpl) cls.newInstance();
nodeInstance.setNodeId(node.getId());
nodeInstance.setNodeInstanceContainer(nodeInstanceContainer);
nodeInstance.setProcessInstance(processInstance);
String uniqueId = (String) node.getMetaData().get("UniqueId");
assert uniqueId != null : node.getName() + " does not have a unique id.";
if (uniqueId == null) {
uniqueId = node.getId() + "";
}
nodeInstance.setMetaData("UniqueId", uniqueId);
int level = ((org.jbpm.workflow.instance.NodeInstanceContainer) nodeInstanceContainer).getLevelForNode(uniqueId);
nodeInstance.setLevel(level);
return nodeInstance;
} catch (Exception e) {
throw new RuntimeException("Unable to instantiate node '" + this.cls.getName() + "': " + e.getMessage());
}
}
use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.
the class AbstractProcessInstanceMarshaller method readNodeInstanceContent.
protected NodeInstanceImpl readNodeInstanceContent(int nodeType, ObjectInputStream stream, MarshallerReaderContext context, WorkflowProcessInstance processInstance) throws IOException {
NodeInstanceImpl nodeInstance = null;
switch(nodeType) {
case PersisterEnums.RULE_SET_NODE_INSTANCE:
nodeInstance = new RuleSetNodeInstance();
int nbTimerInstances = stream.readInt();
if (nbTimerInstances > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (int i = 0; i < nbTimerInstances; i++) {
timerInstances.add(stream.readLong());
}
((RuleSetNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case PersisterEnums.HUMAN_TASK_NODE_INSTANCE:
nodeInstance = new HumanTaskNodeInstance();
((HumanTaskNodeInstance) nodeInstance).internalSetWorkItemId(stream.readLong());
nbTimerInstances = stream.readInt();
if (nbTimerInstances > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (int i = 0; i < nbTimerInstances; i++) {
timerInstances.add(stream.readLong());
}
((HumanTaskNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case PersisterEnums.WORK_ITEM_NODE_INSTANCE:
nodeInstance = new WorkItemNodeInstance();
((WorkItemNodeInstance) nodeInstance).internalSetWorkItemId(stream.readLong());
nbTimerInstances = stream.readInt();
if (nbTimerInstances > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (int i = 0; i < nbTimerInstances; i++) {
timerInstances.add(stream.readLong());
}
((WorkItemNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case PersisterEnums.SUB_PROCESS_NODE_INSTANCE:
nodeInstance = new SubProcessNodeInstance();
((SubProcessNodeInstance) nodeInstance).internalSetProcessInstanceId(stream.readLong());
nbTimerInstances = stream.readInt();
if (nbTimerInstances > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (int i = 0; i < nbTimerInstances; i++) {
timerInstances.add(stream.readLong());
}
((SubProcessNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case PersisterEnums.MILESTONE_NODE_INSTANCE:
nodeInstance = new MilestoneNodeInstance();
nbTimerInstances = stream.readInt();
if (nbTimerInstances > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (int i = 0; i < nbTimerInstances; i++) {
timerInstances.add(stream.readLong());
}
((MilestoneNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case PersisterEnums.TIMER_NODE_INSTANCE:
nodeInstance = new TimerNodeInstance();
((TimerNodeInstance) nodeInstance).internalSetTimerId(stream.readLong());
break;
case PersisterEnums.EVENT_NODE_INSTANCE:
nodeInstance = new EventNodeInstance();
break;
case PersisterEnums.JOIN_NODE_INSTANCE:
nodeInstance = new JoinInstance();
int number = stream.readInt();
if (number > 0) {
Map<Long, Integer> triggers = new HashMap<Long, Integer>();
for (int i = 0; i < number; i++) {
long l = stream.readLong();
int count = stream.readInt();
triggers.put(l, count);
}
((JoinInstance) nodeInstance).internalSetTriggers(triggers);
}
break;
case PersisterEnums.COMPOSITE_NODE_INSTANCE:
nodeInstance = new CompositeContextNodeInstance();
nbTimerInstances = stream.readInt();
if (nbTimerInstances > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (int i = 0; i < nbTimerInstances; i++) {
timerInstances.add(stream.readLong());
}
((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case PersisterEnums.FOR_EACH_NODE_INSTANCE:
nodeInstance = new ForEachNodeInstance();
break;
case PersisterEnums.DYNAMIC_NODE_INSTANCE:
nodeInstance = new DynamicNodeInstance();
nbTimerInstances = stream.readInt();
if (nbTimerInstances > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (int i = 0; i < nbTimerInstances; i++) {
timerInstances.add(stream.readLong());
}
((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case PersisterEnums.STATE_NODE_INSTANCE:
nodeInstance = new StateNodeInstance();
nbTimerInstances = stream.readInt();
if (nbTimerInstances > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (int i = 0; i < nbTimerInstances; i++) {
timerInstances.add(stream.readLong());
}
((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
default:
throw new IllegalArgumentException("Unknown node type: " + nodeType);
}
return nodeInstance;
}
Aggregations