use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.
the class ProcessInstanceQueryTest method testQueryBySuperProcessInstanceId.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/superProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/subProcess.bpmn20.xml" })
public void testQueryBySuperProcessInstanceId() {
ProcessInstance superProcessInstance = runtimeService.startProcessInstanceByKey("subProcessQueryTest");
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().superProcessInstanceId(superProcessInstance.getId());
ProcessInstance subProcessInstance = query.singleResult();
assertNotNull(subProcessInstance);
assertEquals(1, query.list().size());
assertEquals(1, query.count());
}
use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.
the class ProcessInstanceQueryTest method testQueryLongVariable.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryLongVariable() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("longVar", 12345L);
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("longVar", 12345L);
vars.put("longVar2", 67890L);
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("longVar", 55555L);
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
// Query on single long variable, should result in 2 matches
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("longVar", 12345L);
List<ProcessInstance> processInstances = query.list();
assertNotNull(processInstances);
assertEquals(2, processInstances.size());
// Query on two long variables, should result in single match
query = runtimeService.createProcessInstanceQuery().variableValueEquals("longVar", 12345L).variableValueEquals("longVar2", 67890L);
ProcessInstance resultInstance = query.singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance2.getId(), resultInstance.getId());
// Query with unexisting variable value
resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("longVar", 999L).singleResult();
assertNull(resultInstance);
// Test NOT_EQUALS
resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("longVar", 12345L).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
// Test GREATER_THAN
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("longVar", 44444L).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("longVar", 55555L).count());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("longVar", 1L).count());
// Test GREATER_THAN_OR_EQUAL
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("longVar", 44444L).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("longVar", 55555L).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("longVar", 1L).count());
// Test LESS_THAN
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("longVar", 55555L).list();
assertEquals(2, processInstances.size());
List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
List<String> ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("longVar", 12345L).count());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("longVar", 66666L).count());
// Test LESS_THAN_OR_EQUAL
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("longVar", 55555L).list();
assertEquals(3, processInstances.size());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("longVar", 12344L).count());
// Test value-only matching
resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(55555L).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
processInstances = runtimeService.createProcessInstanceQuery().variableValueEquals(12345L).list();
assertEquals(2, processInstances.size());
expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(999L).singleResult();
assertNull(resultInstance);
runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
use of org.activiti.engine.runtime.ProcessInstanceQuery in project daijie-example by daijiejay.
the class BaseService method getProcesses.
@Override
public ModelResult<PageResult<Map<String, Object>>> getProcesses() {
List<Map<String, Object>> rows = new ArrayList<>();
PageResult<Map<String, Object>> datas = new PageResult<>();
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
List<ProcessInstance> processInstances = query.list();
processInstances.forEach(processInstance -> {
List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).unfinished().list();
if (!historicActivityInstances.isEmpty()) {
historicActivityInstances.forEach(historicActivityInstance -> {
Map<String, Object> row = new HashMap<>();
row.put("processInstanceId", processInstance.getId());
Task task = taskService.createTaskQuery().taskId(historicActivityInstance.getTaskId()).singleResult();
row.put("activityName", historicActivityInstance.getActivityName());
row.put("taskId", historicActivityInstance.getTaskId());
row.put("createTime", task.getCreateTime());
row.put("assignee", task.getAssignee());
rows.add(row);
});
} else {
Map<String, Object> row = new HashMap<>();
row.put("processInstanceId", processInstance.getId());
row.put("activityName", "流程结束");
rows.add(row);
}
});
datas.setTotal(query.count());
datas.setRows(rows);
return Result.build(datas);
}
use of org.activiti.engine.runtime.ProcessInstanceQuery in project herd by FINRAOS.
the class JobServiceTest method waitUntilActiveProcessesThreshold.
/**
* Blocks the current calling thread until number of active processes for the process definition id reaches the specified threshold. This method will
* timeout with an assertion error if the waiting takes longer than 15,000 ms. This is a reasonable amount of time for the JUnits that use this method.
*
* @param processDefinitionId the process definition id
* @param activeProcessesThreshold the threshold for the number of active processes
*/
private void waitUntilActiveProcessesThreshold(String processDefinitionId, int activeProcessesThreshold) throws Exception {
// Set the start time.
long startTime = System.currentTimeMillis();
// Create a process instance query for the active sub-processes.
ProcessInstanceQuery processInstanceQuery = activitiRuntimeService.createProcessInstanceQuery().processDefinitionId(processDefinitionId).active();
// Get the current count of the active processes.
long activeProcessesCount = processInstanceQuery.count();
// Run while there are less active processes than the specified threshold.
while (activeProcessesCount < activeProcessesThreshold) {
// Get the elapsed time.
long currentTime = System.currentTimeMillis();
long elapsedTime = currentTime - startTime;
// If time spent waiting is longer than 15,000 ms
if (elapsedTime > 15000) {
// Dump the current runtime variables into the error log to make it easier to debug
StringBuilder builder = new StringBuilder("Dumping workflow variables due to error:\n");
builder.append("Process definition id: ").append(processDefinitionId).append('\n');
builder.append("Active processes threshold: ").append(activeProcessesThreshold).append('\n');
builder.append("Number of active processes: ").append(activeProcessesCount).append('\n');
List<Execution> executions = activitiRuntimeService.createExecutionQuery().list();
builder.append("Total number of executions: ").append(executions.size()).append('\n');
for (Execution execution : executions) {
builder.append("Execution - ").append(execution).append(":\n");
builder.append(" execution.getId():").append(execution.getId()).append('\n');
builder.append(" execution.getActivityId():").append(execution.getActivityId()).append('\n');
builder.append(" execution.getParentId():").append(execution.getParentId()).append('\n');
builder.append(" execution.getProcessInstanceId():").append(execution.getProcessInstanceId()).append('\n');
builder.append(" execution.isEnded():").append(execution.isEnded()).append('\n');
builder.append(" execution.isSuspended():").append(execution.isSuspended()).append('\n');
Map<String, Object> executionVariables = activitiRuntimeService.getVariables(execution.getId());
for (Map.Entry<String, Object> variable : executionVariables.entrySet()) {
builder.append(" ").append(variable).append('\n');
}
}
LOGGER.error(builder.toString());
// Fail assertion
fail("The test did not finished in the specified timeout (15s). See error logs for variable dump.");
}
// Sleep for 100 ms.
Thread.sleep(100);
// Update the current count of the active processes.
activeProcessesCount = processInstanceQuery.count();
}
}
use of org.activiti.engine.runtime.ProcessInstanceQuery in project herd by FINRAOS.
the class ActivitiServiceTest method testGetProcessInstanceById.
@Test
public void testGetProcessInstanceById() {
String processInstanceId = "processInstanceId";
ProcessInstanceQuery processInstanceQuery = mock(ProcessInstanceQuery.class);
when(activitiRuntimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
when(processInstanceQuery.processInstanceId(processInstanceId)).thenReturn(processInstanceQuery);
when(processInstanceQuery.includeProcessVariables()).thenReturn(processInstanceQuery);
ProcessInstance expectedProcessInstance = mock(ProcessInstance.class);
when(processInstanceQuery.singleResult()).thenReturn(expectedProcessInstance);
ProcessInstance actualProcessInstance = activitiService.getProcessInstanceById(processInstanceId);
assertSame(expectedProcessInstance, actualProcessInstance);
InOrder inOrder = inOrder(processInstanceQuery);
inOrder.verify(processInstanceQuery).processInstanceId(processInstanceId);
inOrder.verify(processInstanceQuery).includeProcessVariables();
inOrder.verify(processInstanceQuery).singleResult();
inOrder.verifyNoMoreInteractions();
}
Aggregations