use of org.activiti.engine.runtime.ProcessInstanceQuery in project carbon-business-process by wso2.
the class BaseProcessInstanceService method getQueryResponse.
protected DataResponse getQueryResponse(ProcessInstanceQueryRequest queryRequest, Map<String, String> requestParams, UriInfo uriInfo) {
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
// Populate query based on request
if (queryRequest.getProcessInstanceId() != null) {
query.processInstanceId(queryRequest.getProcessInstanceId());
}
if (queryRequest.getProcessDefinitionKey() != null) {
query.processDefinitionKey(queryRequest.getProcessDefinitionKey());
}
if (queryRequest.getProcessDefinitionId() != null) {
query.processDefinitionId(queryRequest.getProcessDefinitionId());
}
if (queryRequest.getProcessBusinessKey() != null) {
query.processInstanceBusinessKey(queryRequest.getProcessBusinessKey());
}
if (queryRequest.getInvolvedUser() != null) {
query.involvedUser(queryRequest.getInvolvedUser());
}
if (queryRequest.getSuspended() != null) {
if (queryRequest.getSuspended()) {
query.suspended();
} else {
query.active();
}
}
if (queryRequest.getSubProcessInstanceId() != null) {
query.subProcessInstanceId(queryRequest.getSubProcessInstanceId());
}
if (queryRequest.getSuperProcessInstanceId() != null) {
query.superProcessInstanceId(queryRequest.getSuperProcessInstanceId());
}
if (queryRequest.getExcludeSubprocesses() != null) {
query.excludeSubprocesses(queryRequest.getExcludeSubprocesses());
}
if (queryRequest.getIncludeProcessVariables() != null) {
if (queryRequest.getIncludeProcessVariables()) {
query.includeProcessVariables();
}
}
if (queryRequest.getVariables() != null) {
addVariables(query, queryRequest.getVariables());
}
if (queryRequest.getTenantId() != null) {
query.processInstanceTenantId(queryRequest.getTenantId());
}
if (queryRequest.getTenantIdLike() != null) {
query.processInstanceTenantIdLike(queryRequest.getTenantIdLike());
}
if (Boolean.TRUE.equals(queryRequest.getWithoutTenantId())) {
query.processInstanceWithoutTenantId();
}
return new ProcessInstancePaginateList(new RestResponseFactory(), uriInfo).paginateList(requestParams, queryRequest, query, "id", allowedSortProperties);
}
use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.
the class ProcessInstanceQueryTest method testOrQueryIntegerVariable.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testOrQueryIntegerVariable() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("integerVar", 12345);
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("integerVar", 12345);
vars.put("integerVar2", 67890);
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("integerVar", 55555);
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
// Query on single integer variable, should result in 2 matches
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().or().variableValueEquals("integerVar", 12345).processDefinitionId("undefined").endOr();
List<ProcessInstance> processInstances = query.list();
assertNotNull(processInstances);
assertEquals(2, processInstances.size());
query = runtimeService.createProcessInstanceQuery().or().variableValueEquals("integerVar", 12345).processDefinitionId("undefined").endOr().or().processDefinitionKey("oneTaskProcess").processDefinitionId("undefined").endOr();
processInstances = query.list();
assertNotNull(processInstances);
assertEquals(2, processInstances.size());
// Query on two integer variables, should result in single value
query = runtimeService.createProcessInstanceQuery().variableValueEquals("integerVar", 12345).or().variableValueEquals("integerVar2", 67890).processDefinitionId("undefined").endOr();
ProcessInstance resultInstance = query.singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance2.getId(), resultInstance.getId());
// Query with unexisting variable value
resultInstance = runtimeService.createProcessInstanceQuery().or().variableValueEquals("integerVar", 9999).processDefinitionId("undefined").endOr().singleResult();
assertNull(resultInstance);
// Test NOT_EQUALS
resultInstance = runtimeService.createProcessInstanceQuery().or().variableValueNotEquals("integerVar", 12345).processDefinitionId("undefined").endOr().singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
// Test GREATER_THAN
resultInstance = runtimeService.createProcessInstanceQuery().or().variableValueGreaterThan("integerVar", 44444).processDefinitionId("undefined").endOr().singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = runtimeService.createProcessInstanceQuery().or().variableValueGreaterThan("integerVar", 44444).processDefinitionId("undefined").endOr().or().processDefinitionKey("oneTaskProcess").processDefinitionId("undefined").endOr().singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(0, runtimeService.createProcessInstanceQuery().or().variableValueGreaterThan("integerVar", 55555).processDefinitionId("undefined").endOr().count());
assertEquals(3, runtimeService.createProcessInstanceQuery().or().variableValueGreaterThan("integerVar", 1).processDefinitionId("undefined").endOr().count());
// Test GREATER_THAN_OR_EQUAL
resultInstance = runtimeService.createProcessInstanceQuery().or().variableValueGreaterThanOrEqual("integerVar", 44444).processDefinitionId("undefined").endOr().singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = runtimeService.createProcessInstanceQuery().or().variableValueGreaterThanOrEqual("integerVar", 55555).processDefinitionId("undefined").endOr().singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(3, runtimeService.createProcessInstanceQuery().or().variableValueGreaterThanOrEqual("integerVar", 1).processDefinitionId("undefined").endOr().count());
// Test LESS_THAN
processInstances = runtimeService.createProcessInstanceQuery().or().variableValueLessThan("integerVar", 55555).processDefinitionId("undefined").endOr().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().or().variableValueLessThan("integerVar", 12345).processDefinitionId("undefined").endOr().count());
assertEquals(3, runtimeService.createProcessInstanceQuery().or().variableValueLessThan("integerVar", 66666).processDefinitionId("undefined").endOr().count());
// Test LESS_THAN_OR_EQUAL
processInstances = runtimeService.createProcessInstanceQuery().or().variableValueLessThanOrEqual("integerVar", 55555).processDefinitionId("undefined").endOr().list();
assertEquals(3, processInstances.size());
assertEquals(0, runtimeService.createProcessInstanceQuery().or().variableValueLessThanOrEqual("integerVar", 12344).processDefinitionId("undefined").endOr().count());
// Test value-only matching
resultInstance = runtimeService.createProcessInstanceQuery().or().variableValueEquals(55555).processDefinitionId("undefined").endOr().singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
processInstances = runtimeService.createProcessInstanceQuery().or().variableValueEquals(12345).processDefinitionId("undefined").endOr().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().or().variableValueEquals(9999).processDefinitionId("undefined").endOr().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 Activiti by Activiti.
the class ProcessInstanceQueryTest method testQueryShortVariable.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryShortVariable() {
Map<String, Object> vars = new HashMap<String, Object>();
short shortVar = 1234;
vars.put("shortVar", shortVar);
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
short shortVar2 = 6789;
vars = new HashMap<String, Object>();
vars.put("shortVar", shortVar);
vars.put("shortVar2", shortVar2);
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("shortVar", (short) 5555);
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
// Query on single short variable, should result in 2 matches
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("shortVar", shortVar);
List<ProcessInstance> processInstances = query.list();
assertNotNull(processInstances);
assertEquals(2, processInstances.size());
// Query on two short variables, should result in single value
query = runtimeService.createProcessInstanceQuery().variableValueEquals("shortVar", shortVar).variableValueEquals("shortVar2", shortVar2);
ProcessInstance resultInstance = query.singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance2.getId(), resultInstance.getId());
// Query with unexisting variable value
short unexistingValue = (short) 9999;
resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("shortVar", unexistingValue).singleResult();
assertNull(resultInstance);
// Test NOT_EQUALS
resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("shortVar", (short) 1234).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
// Test GREATER_THAN
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("shortVar", (short) 4444).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("shortVar", (short) 5555).count());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("shortVar", (short) 1).count());
// Test GREATER_THAN_OR_EQUAL
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("shortVar", (short) 4444).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("shortVar", (short) 5555).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("shortVar", (short) 1).count());
// Test LESS_THAN
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("shortVar", (short) 5555).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("shortVar", (short) 1234).count());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("shortVar", (short) 6666).count());
// Test LESS_THAN_OR_EQUAL
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("shortVar", (short) 5555).list();
assertEquals(3, processInstances.size());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("shortVar", (short) 1233).count());
// Test value-only matching
resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals((short) 5555).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
processInstances = runtimeService.createProcessInstanceQuery().variableValueEquals((short) 1234).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((short) 999).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 Activiti by Activiti.
the class ProcessInstanceQueryTest method testQueryVariablesUpdatedToNullValue.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryVariablesUpdatedToNullValue() {
// Start process instance with different types of variables
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("longVar", 928374L);
variables.put("shortVar", (short) 123);
variables.put("integerVar", 1234);
variables.put("stringVar", "coca-cola");
variables.put("dateVar", new Date());
variables.put("booleanVar", true);
variables.put("nullVar", null);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("longVar", null).variableValueEquals("shortVar", null).variableValueEquals("integerVar", null).variableValueEquals("stringVar", null).variableValueEquals("booleanVar", null).variableValueEquals("dateVar", null);
ProcessInstanceQuery notQuery = runtimeService.createProcessInstanceQuery().variableValueNotEquals("longVar", null).variableValueNotEquals("shortVar", null).variableValueNotEquals("integerVar", null).variableValueNotEquals("stringVar", null).variableValueNotEquals("booleanVar", null).variableValueNotEquals("dateVar", null);
assertNull(query.singleResult());
assertNotNull(notQuery.singleResult());
// Set all existing variables values to null
runtimeService.setVariable(processInstance.getId(), "longVar", null);
runtimeService.setVariable(processInstance.getId(), "shortVar", null);
runtimeService.setVariable(processInstance.getId(), "integerVar", null);
runtimeService.setVariable(processInstance.getId(), "stringVar", null);
runtimeService.setVariable(processInstance.getId(), "dateVar", null);
runtimeService.setVariable(processInstance.getId(), "nullVar", null);
runtimeService.setVariable(processInstance.getId(), "booleanVar", null);
Execution queryResult = query.singleResult();
assertNotNull(queryResult);
assertEquals(processInstance.getId(), queryResult.getId());
assertNull(notQuery.singleResult());
}
use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.
the class ProcessInstanceQueryTest method testQueryByProcessDefinitionIds.
public void testQueryByProcessDefinitionIds() {
final ProcessDefinition processDefinition1 = repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_DEFINITION_KEY).singleResult();
final ProcessDefinition processDefinition2 = repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_DEFINITION_KEY_2).singleResult();
final Set<String> processDefinitionIdSet = new HashSet<String>(2);
processDefinitionIdSet.add(processDefinition1.getId());
processDefinitionIdSet.add(processDefinition2.getId());
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processDefinitionIds(processDefinitionIdSet);
assertEquals(PROCESS_DEPLOY_COUNT, query.count());
assertEquals(PROCESS_DEPLOY_COUNT, query.list().size());
try {
query.singleResult();
fail();
} catch (ActivitiException e) {
// Exception is expected
}
}
Aggregations