use of org.activiti.engine.history.HistoricTaskInstanceQuery in project Activiti by Activiti.
the class HistoryServiceTest method testHistoricTaskInstanceQueryByDeploymentId.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricTaskInstanceQueryByDeploymentId() {
org.activiti.engine.repository.Deployment deployment = repositoryService.createDeploymentQuery().singleResult();
HashSet<String> processInstanceIds = new HashSet<String>();
for (int i = 0; i < 4; i++) {
processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess", i + "").getId());
}
processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess2", "1").getId());
HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().deploymentId(deployment.getId());
assertEquals(5, taskInstanceQuery.count());
List<HistoricTaskInstance> taskInstances = taskInstanceQuery.list();
assertNotNull(taskInstances);
assertEquals(5, taskInstances.size());
taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().deploymentId("invalid");
assertEquals(0, taskInstanceQuery.count());
}
use of org.activiti.engine.history.HistoricTaskInstanceQuery in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowHistoricTaskInstanceService method find.
@Override
public Page<WorkflowHistoricTaskInstanceDto> find(WorkflowFilterDto filter, Pageable pageable, BasePermission... permission) {
String processDefinitionId = filter.getProcessDefinitionId();
String processInstanceId = filter.getProcessInstanceId();
HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery();
query.includeProcessVariables();
if (filter.getId() != null) {
query.taskId(filter.getId().toString());
}
if (processInstanceId != null) {
query.processInstanceId(processInstanceId);
}
if (processDefinitionId != null) {
query.processDefinitionId(processDefinitionId);
}
if (filter.getProcessDefinitionKey() != null) {
query.processDefinitionKey(filter.getProcessDefinitionKey());
}
// historic task instance ... admin can see all historic tasks every time
if (!securityService.isAdmin()) {
// TODO Now we don't have detail for historic task. When we need detail, then we will need create different projection (detail can't be read by applicant)
String loggedUserId = securityService.getCurrentId().toString();
query.taskInvolvedUser(loggedUserId);
}
String fieldForSort = null;
boolean ascSort = false;
boolean descSort = false;
if (pageable != null) {
Sort sort = pageable.getSort();
if (sort != null) {
for (Order order : sort) {
if (!StringUtils.isEmpty(order.getProperty())) {
// TODO: now is implemented only one property sort
fieldForSort = order.getProperty();
if (order.getDirection() == Direction.ASC) {
ascSort = true;
} else if (order.getDirection() == Direction.DESC) {
descSort = true;
}
break;
}
}
}
}
if (WorkflowHistoricTaskInstanceService.SORT_BY_CREATE_TIME.equals(fieldForSort)) {
query.orderByTaskCreateTime();
} else if (WorkflowHistoricTaskInstanceService.SORT_BY_END_TIME.equals(fieldForSort)) {
query.orderByHistoricTaskInstanceEndTime();
} else {
query.orderByProcessDefinitionId();
// there must be default order
query.asc();
}
if (ascSort) {
query.asc();
}
if (descSort) {
query.desc();
}
long count = query.count();
List<HistoricTaskInstance> processInstances = null;
if (pageable == null) {
processInstances = query.list();
} else {
processInstances = query.listPage((pageable.getPageNumber()) * pageable.getPageSize(), pageable.getPageSize());
}
List<WorkflowHistoricTaskInstanceDto> dtos = new ArrayList<>();
if (processInstances != null) {
for (HistoricTaskInstance instance : processInstances) {
dtos.add(toResource(instance));
}
}
return new PageImpl<WorkflowHistoricTaskInstanceDto>(dtos, pageable, count);
}
Aggregations