Java Code Examples for org.activiti.engine.history.HistoricProcessInstanceQuery#unfinished()
The following examples show how to use
org.activiti.engine.history.HistoricProcessInstanceQuery#unfinished() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivitiServiceImpl.java From herd with Apache License 2.0 | 5 votes |
/** * Creates a HistoricProcessInstanceQuery in the given process definitions, optionally filtering by the given job status, start and end times. * * @param processDefinitionKeys Collection of process definition keys * @param jobStatus The job status. Optional. * @param startTime The start time. Optional. * @param endTime The end time. Optional. * * @return A HistoricProcessInstanceQuery */ private HistoricProcessInstanceQuery createHistoricProcessInstanceQuery(Collection<String> processDefinitionKeys, JobStatusEnum jobStatus, DateTime startTime, DateTime endTime) { HistoricProcessInstanceQuery query = activitiHistoryService.createHistoricProcessInstanceQuery().processDefinitionKeyIn(new ArrayList<>(processDefinitionKeys)); if (JobStatusEnum.RUNNING.equals(jobStatus) || JobStatusEnum.SUSPENDED.equals(jobStatus)) { // If the filter is for "running" or "suspended", use the "unfinished" query filter. query.unfinished(); } else if (JobStatusEnum.COMPLETED.equals(jobStatus)) { // If the filter is for "completed" processes, use the "finished" query filter. query.finished(); } if (startTime != null) { query.startedAfter(startTime.toDate()); } if (endTime != null) { query.finishedBefore(endTime.toDate()); } return query; }
Example 2
Source File: AbstractProcessInstanceQueryResource.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
public ResultListDataRepresentation getProcessInstances(ObjectNode requestNode) { HistoricProcessInstanceQuery instanceQuery = historyService.createHistoricProcessInstanceQuery(); User currentUser = SecurityUtils.getCurrentUserObject(); instanceQuery.involvedUser(String.valueOf(currentUser.getId())); // Process definition JsonNode processDefinitionIdNode = requestNode.get("processDefinitionId"); if (processDefinitionIdNode != null && processDefinitionIdNode.isNull() == false) { instanceQuery.processDefinitionId(processDefinitionIdNode.asText()); } JsonNode deploymentKeyNode = requestNode.get("deploymentKey"); if (deploymentKeyNode != null && deploymentKeyNode.isNull() == false) { // Results need to be filtered in an app-context. We need to fetch the deployment id for this app and use that in the query List<Deployment> deployments = repositoryService.createDeploymentQuery().deploymentKey(deploymentKeyNode.asText()).list(); List<String> deploymentIds = new ArrayList<String>(); for (Deployment deployment : deployments) { deploymentIds.add(deployment.getId()); } instanceQuery.deploymentIdIn(deploymentIds); } // State filtering JsonNode stateNode = requestNode.get("state"); if (stateNode != null && !stateNode.isNull()) { String state = stateNode.asText(); if ("running".equals(state)) { instanceQuery.unfinished(); } else if ("completed".equals(state)) { instanceQuery.finished(); } else if (!"all".equals(state)) { throw new BadRequestException("Illegal state filter value passed, only 'running', 'completed' or 'all' are supported"); } } else { // Default filtering, only running instanceQuery.unfinished(); } // Sort and ordering JsonNode sortNode = requestNode.get("sort"); if (sortNode != null && !sortNode.isNull()) { if ("created-desc".equals(sortNode.asText())) { instanceQuery.orderByProcessInstanceStartTime().desc(); } else if ("created-asc".equals(sortNode.asText())) { instanceQuery.orderByProcessInstanceStartTime().asc(); } else if ("ended-desc".equals(sortNode.asText())) { instanceQuery.orderByProcessInstanceEndTime().desc(); } else if ("ended-asc".equals(sortNode.asText())) { instanceQuery.orderByProcessInstanceEndTime().asc(); } } else { // Revert to default instanceQuery.orderByProcessInstanceStartTime().desc(); } int page = 0; JsonNode pageNode = requestNode.get("page"); if (pageNode != null && !pageNode.isNull()) { page = pageNode.asInt(0); } int size = DEFAULT_PAGE_SIZE; JsonNode sizeNode = requestNode.get("size"); if (sizeNode != null && !sizeNode.isNull()) { size = sizeNode.asInt(DEFAULT_PAGE_SIZE); } List<HistoricProcessInstance> instances = instanceQuery.listPage(page * size, size); ResultListDataRepresentation result = new ResultListDataRepresentation(convertInstanceList(instances)); // In case we're not on the first page and the size exceeds the page size, we need to do an additional count for the total if (page != 0 || instances.size() == size) { Long totalCount = instanceQuery.count(); result.setTotal(Long.valueOf(totalCount.intValue())); result.setStart(page * size); } return result; }
Example 3
Source File: HistoricProcessInstanceBaseResource.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
protected DataResponse getQueryResponse(HistoricProcessInstanceQueryRequest queryRequest, Map<String, String> allRequestParams) { HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery(); // Populate query based on request if (queryRequest.getProcessInstanceId() != null) { query.processInstanceId(queryRequest.getProcessInstanceId()); } if (queryRequest.getProcessInstanceIds() != null && !queryRequest.getProcessInstanceIds().isEmpty()) { query.processInstanceIds(new HashSet<String>(queryRequest.getProcessInstanceIds())); } 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.getSuperProcessInstanceId() != null) { query.superProcessInstanceId(queryRequest.getSuperProcessInstanceId()); } if (queryRequest.getExcludeSubprocesses() != null) { query.excludeSubprocesses(queryRequest.getExcludeSubprocesses()); } if (queryRequest.getFinishedAfter() != null) { query.finishedAfter(queryRequest.getFinishedAfter()); } if (queryRequest.getFinishedBefore() != null) { query.finishedBefore(queryRequest.getFinishedBefore()); } if (queryRequest.getStartedAfter() != null) { query.startedAfter(queryRequest.getStartedAfter()); } if (queryRequest.getStartedBefore() != null) { query.startedBefore(queryRequest.getStartedBefore()); } if (queryRequest.getStartedBy() != null) { query.startedBy(queryRequest.getStartedBy()); } if (queryRequest.getFinished() != null) { if (queryRequest.getFinished()) { query.finished(); } else { query.unfinished(); } } 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 HistoricProcessInstancePaginateList(restResponseFactory).paginateList(allRequestParams, queryRequest, query, "processInstanceId", allowedSortProperties); }