use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class RuntimeDataServiceEJBIntegrationTest method testGetTaskByWorkItemId.
@Test
public void testGetTaskByWorkItemId() {
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
ProcessInstance instance = processService.getProcessInstance(processInstanceId);
assertNotNull(instance);
Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
NodeInstance node = activeNodes.iterator().next();
assertNotNull(node);
assertTrue(node instanceof WorkItemNodeInstance);
Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId();
assertNotNull(workItemId);
UserTaskInstanceDesc userTask = runtimeDataService.getTaskByWorkItemId(workItemId);
assertNotNull(userTask);
assertEquals(processInstanceId, userTask.getProcessInstanceId());
assertEquals("Write a Document", userTask.getName());
}
use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class RuntimeDataServiceEJBIntegrationTest method testGetTaskAudit.
@Test
public void testGetTaskAudit() {
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
ProcessInstance instance = processService.getProcessInstance(processInstanceId);
assertNotNull(instance);
Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
NodeInstance node = activeNodes.iterator().next();
assertNotNull(node);
assertTrue(node instanceof WorkItemNodeInstance);
Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId();
assertNotNull(workItemId);
List<AuditTask> auditTasks = runtimeDataService.getAllAuditTask("salaboy", new QueryFilter(0, 10));
assertNotNull(auditTasks);
assertEquals(1, auditTasks.size());
assertEquals("Write a Document", auditTasks.get(0).getName());
}
use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class RuntimeDataServiceEJBIntegrationTest method testGetTaskEvents.
@Test
public void testGetTaskEvents() {
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
ProcessInstance instance = processService.getProcessInstance(processInstanceId);
assertNotNull(instance);
Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
NodeInstance node = activeNodes.iterator().next();
assertNotNull(node);
assertTrue(node instanceof WorkItemNodeInstance);
Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId();
assertNotNull(workItemId);
UserTaskInstanceDesc userTask = runtimeDataService.getTaskByWorkItemId(workItemId);
assertNotNull(userTask);
List<TaskEvent> auditTasks = runtimeDataService.getTaskEvents(userTask.getTaskId(), new QueryFilter());
assertNotNull(auditTasks);
assertEquals(1, auditTasks.size());
assertEquals(TaskEvent.TaskEventType.ADDED, auditTasks.get(0).getType());
userTaskService.start(userTask.getTaskId(), "salaboy");
auditTasks = runtimeDataService.getTaskEvents(userTask.getTaskId(), new QueryFilter());
assertNotNull(auditTasks);
assertEquals(2, auditTasks.size());
assertEquals(TaskEvent.TaskEventType.ADDED, auditTasks.get(0).getType());
assertEquals(TaskEvent.TaskEventType.STARTED, auditTasks.get(1).getType());
}
use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class MigrationManager method cancelActiveTimersBeforeMigration.
protected Map<Long, List<TimerInstance>> cancelActiveTimersBeforeMigration(RuntimeManager manager) {
RuntimeEngine engineBefore = manager.getRuntimeEngine(ProcessInstanceIdContext.get(migrationSpec.getProcessInstanceId()));
try {
Map<Long, List<TimerInstance>> timerMigrated = engineBefore.getKieSession().execute(new ExecutableCommand<Map<Long, List<TimerInstance>>>() {
private static final long serialVersionUID = 7144271692067781976L;
@Override
public Map<Long, List<TimerInstance>> execute(Context context) {
Map<Long, List<TimerInstance>> result = new LinkedHashMap<>();
KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
TimerManager timerManager = getTimerManager(kieSession);
WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) kieSession.getProcessInstance(migrationSpec.getProcessInstanceId());
Collection<org.jbpm.workflow.instance.NodeInstance> activeInstances = processInstance.getNodeInstances(true);
for (org.jbpm.workflow.instance.NodeInstance active : activeInstances) {
if (active instanceof TimerNodeInstance) {
TimerInstance timerInstance = timerManager.getTimerMap().get(((TimerNodeInstance) active).getTimerId());
timerManager.cancelTimer(timerInstance.getId());
result.put(active.getId(), Arrays.asList(timerInstance));
} else if (active instanceof StateBasedNodeInstance) {
List<Long> timers = ((StateBasedNodeInstance) active).getTimerInstances();
if (timers != null && !timers.isEmpty()) {
List<TimerInstance> collected = new ArrayList<>();
for (Long timerId : timers) {
TimerInstance timerInstance = timerManager.getTimerMap().get(timerId);
timerManager.cancelTimer(timerInstance.getId());
collected.add(timerInstance);
}
result.put(active.getId(), collected);
}
}
}
return result;
}
});
return timerMigrated;
} finally {
manager.disposeRuntimeEngine(engineBefore);
}
}
use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class MigrationManager method upgradeProcessInstance.
private void upgradeProcessInstance(KieRuntime oldkruntime, KieRuntime kruntime, long processInstanceId, String processId, Map<String, String> nodeMapping, EntityManager em, String deploymentId) {
if (nodeMapping == null) {
nodeMapping = new HashMap<String, String>();
}
WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) oldkruntime.getProcessInstance(processInstanceId);
if (processInstance == null) {
report.addEntry(Type.ERROR, "Could not find process instance " + processInstanceId);
}
if (processId == null) {
report.addEntry(Type.ERROR, "Null process id");
}
WorkflowProcess process = (WorkflowProcess) kruntime.getKieBase().getProcess(processId);
if (process == null) {
report.addEntry(Type.ERROR, "Could not find process " + processId);
}
if (processInstance.getProcessId().equals(processId)) {
report.addEntry(Type.WARN, "Source and target process id is exactly the same (" + processId + ") it's recommended to use unique process ids");
}
synchronized (processInstance) {
org.kie.api.definition.process.Process oldProcess = processInstance.getProcess();
processInstance.disconnect();
processInstance.setProcess(oldProcess);
updateNodeInstances(processInstance, nodeMapping, (NodeContainer) process, em);
processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) extractIfNeeded(kruntime));
processInstance.setDeploymentId(deploymentId);
processInstance.setProcess(process);
processInstance.reconnect();
}
}
Aggregations