use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.
the class ProcessInstanceQueryTest method testQueryDoubleVariable.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryDoubleVariable() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("doubleVar", 12345.6789);
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("doubleVar", 12345.6789);
vars.put("doubleVar2", 9876.54321);
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("doubleVar", 55555.5555);
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
// Query on single double variable, should result in 2 matches
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("doubleVar", 12345.6789);
List<ProcessInstance> processInstances = query.list();
assertNotNull(processInstances);
assertEquals(2, processInstances.size());
// Query on two double variables, should result in single value
query = runtimeService.createProcessInstanceQuery().variableValueEquals("doubleVar", 12345.6789).variableValueEquals("doubleVar2", 9876.54321);
ProcessInstance resultInstance = query.singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance2.getId(), resultInstance.getId());
// Query with unexisting variable value
resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("doubleVar", 9999.99).singleResult();
assertNull(resultInstance);
// Test NOT_EQUALS
resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("doubleVar", 12345.6789).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
// Test GREATER_THAN
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("doubleVar", 44444.4444).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("doubleVar", 55555.5555).count());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("doubleVar", 1.234).count());
// Test GREATER_THAN_OR_EQUAL
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("doubleVar", 44444.4444).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("doubleVar", 55555.5555).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("doubleVar", 1.234).count());
// Test LESS_THAN
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("doubleVar", 55555.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("doubleVar", 12345.6789).count());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("doubleVar", 66666.6666).count());
// Test LESS_THAN_OR_EQUAL
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("doubleVar", 55555.5555).list();
assertEquals(3, processInstances.size());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("doubleVar", 12344.6789).count());
// Test value-only matching
resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(55555.5555).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
processInstances = runtimeService.createProcessInstanceQuery().variableValueEquals(12345.6789).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(999.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 testQueryNoSpecificsList.
public void testQueryNoSpecificsList() {
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
assertEquals(PROCESS_DEPLOY_COUNT, query.count());
assertEquals(PROCESS_DEPLOY_COUNT, query.list().size());
}
use of org.activiti.engine.runtime.ProcessInstanceQuery in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowProcessInstanceService method searchInternal.
@Override
public ResourcesWrapper<WorkflowProcessInstanceDto> searchInternal(WorkflowFilterDto filter, boolean checkRight) {
String processDefinitionId = filter.getProcessDefinitionId();
Map<String, Object> equalsVariables = filter.getEqualsVariables();
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
query.active();
query.includeProcessVariables();
if (processDefinitionId != null) {
query.processDefinitionId(processDefinitionId);
}
if (filter.getProcessDefinitionKey() != null) {
query.processDefinitionKey(filter.getProcessDefinitionKey());
}
if (filter.getProcessInstanceId() != null) {
query.processInstanceId(filter.getProcessInstanceId());
}
if (filter.getCategory() != null) {
// Find definitions with this category (use double sided like)
// We have to find definitions first, because process instance can't
// be find by category.
ProcessDefinitionQuery queryDefinition = repositoryService.createProcessDefinitionQuery();
queryDefinition.active();
queryDefinition.latestVersion();
queryDefinition.processDefinitionCategoryLike(filter.getCategory() + "%");
List<ProcessDefinition> processDefinitions = queryDefinition.list();
Set<String> processDefinitionKeys = new HashSet<>();
processDefinitions.forEach(p -> processDefinitionKeys.add(p.getKey()));
if (processDefinitionKeys.isEmpty()) {
// We don`t have any definitions ... nothing must be returned
processDefinitionKeys.add("-1");
}
query.processDefinitionKeys(processDefinitionKeys);
}
if (equalsVariables != null) {
for (Entry<String, Object> entry : equalsVariables.entrySet()) {
query.variableValueEquals(entry.getKey(), entry.getValue());
}
}
// (subprocess) started. This modification allow not use OR clause.
if (checkRight && !securityService.isAdmin()) {
query.involvedUser(securityService.getCurrentId().toString());
}
query.orderByProcessDefinitionId();
query.desc();
long count = query.count();
List<ProcessInstance> processInstances = query.listPage((filter.getPageNumber()) * filter.getPageSize(), filter.getPageSize());
List<WorkflowProcessInstanceDto> dtos = new ArrayList<>();
if (processInstances != null) {
for (ProcessInstance instance : processInstances) {
dtos.add(toResource(instance));
}
}
double totalPageDouble = ((double) count / filter.getPageSize());
double totlaPageFlorred = Math.floor(totalPageDouble);
long totalPage = 0;
if (totalPageDouble > totlaPageFlorred) {
totalPage = (long) (totlaPageFlorred + 1);
}
return new ResourcesWrapper<>(dtos, count, totalPage, filter.getPageNumber(), filter.getPageSize());
}
use of org.activiti.engine.runtime.ProcessInstanceQuery in project carbon-business-process by wso2.
the class BPMNInstanceService method getPaginatedInstances.
/**
* Get paginated instances
*
* @param start
* @param size
* @return list of BPMNInstances
* @throws BPSFault
*/
public BPMNInstance[] getPaginatedInstances(int start, int size) throws BPSFault {
List<BPMNInstance> bpmnInstanceList = new ArrayList<>();
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
RuntimeService runtimeService = engine.getRuntimeService();
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId.toString());
HistoricProcessInstanceQuery historicQuery = BPMNServerHolder.getInstance().getEngine().getHistoryService().createHistoricProcessInstanceQuery().processInstanceTenantId(tenantId.toString());
processInstanceCount = (int) query.count();
List<ProcessInstance> instances = query.includeProcessVariables().listPage(start, size);
for (ProcessInstance instance : instances) {
BPMNInstance bpmnInstance = new BPMNInstance();
bpmnInstance.setInstanceId(instance.getId());
bpmnInstance.setProcessId(instance.getProcessDefinitionId());
bpmnInstance.setSuspended(instance.isSuspended());
bpmnInstance.setStartTime(historicQuery.processInstanceId(instance.getId()).singleResult().getStartTime());
bpmnInstance.setVariables(formatVariables(instance.getProcessVariables()));
bpmnInstanceList.add(bpmnInstance);
}
return bpmnInstanceList.toArray(new BPMNInstance[bpmnInstanceList.size()]);
}
use of org.activiti.engine.runtime.ProcessInstanceQuery in project carbon-business-process by wso2.
the class BPMNInstanceService method getInstanceCount.
/**
* Get total instance count
*
* @return count int
* @throws BPSFault
*/
public int getInstanceCount() throws BPSFault {
if (processInstanceCount == -1) {
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
RuntimeService runtimeService = engine.getRuntimeService();
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId.toString());
processInstanceCount = (int) query.includeProcessVariables().count();
}
return processInstanceCount;
}
Aggregations