use of org.flowable.engine.history.HistoricProcessInstanceQuery in project petals-se-flowable by petalslink.
the class Assert method assertProcessInstanceFinished.
/**
* Assertion to check that a process instance is finished.
*
* @param processInstanceId
* The process instance identifier
* @param historyService
* The Flowable's history service used to request the Flowable engine about historic process instances.
*/
public static void assertProcessInstanceFinished(final String processInstanceId, final HistoryService historyService) {
final HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
final HistoricProcessInstance processInstance = query.processInstanceId(processInstanceId).finished().singleResult();
assertNotNull(processInstance);
}
use of org.flowable.engine.history.HistoricProcessInstanceQuery in project petals-se-flowable by petalslink.
the class ProcessInstanceCompletedEventListener method createLogData.
@Override
protected AbstractFlowLogData createLogData(final FlowableEvent event) {
if (event instanceof FlowableEntityEventImpl) {
final FlowableEntityEventImpl eventImpl = (FlowableEntityEventImpl) event;
final String processInstanceId = eventImpl.getProcessInstanceId();
this.log.fine("The process instance '" + processInstanceId + "' is completed.");
final HistoricProcessInstanceQuery processQuery = this.historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).includeProcessVariables();
final HistoricProcessInstance processResult = processQuery.singleResult();
final Map<String, Object> processVariables = processResult.getProcessVariables();
final String flowInstanceId = (String) processVariables.get(VAR_PETALS_FLOW_INSTANCE_ID);
final String flowStepId = (String) processVariables.get(VAR_PETALS_FLOW_STEP_ID);
if (this.isFlowTracingEnabled(processVariables)) {
return new ProcessInstanceFlowStepEndLogData(flowInstanceId, flowStepId);
} else {
return null;
}
} else {
this.log.warning("Unexpected event implementation: " + event.getClass().getName());
return null;
}
}
use of org.flowable.engine.history.HistoricProcessInstanceQuery in project RuoYi-Flowable-Plus by KonBAI-Q.
the class WfTaskServiceImpl method myProcess.
/**
* 我发起的流程
*
* @return
*/
@Override
public TableDataInfo<WfTaskVo> myProcess(PageQuery pageQuery) {
Page<WfTaskVo> page = new Page<>();
Long userId = LoginHelper.getUserId();
HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().startedBy(userId.toString()).orderByProcessInstanceStartTime().desc();
int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);
List<HistoricProcessInstance> historicProcessInstances = historicProcessInstanceQuery.listPage(offset, pageQuery.getPageSize());
page.setTotal(historicProcessInstanceQuery.count());
List<WfTaskVo> taskVoList = new ArrayList<>();
for (HistoricProcessInstance hisIns : historicProcessInstances) {
WfTaskVo taskVo = new WfTaskVo();
taskVo.setCreateTime(hisIns.getStartTime());
taskVo.setFinishTime(hisIns.getEndTime());
taskVo.setProcInsId(hisIns.getId());
// 计算耗时
if (Objects.nonNull(hisIns.getEndTime())) {
long time = hisIns.getEndTime().getTime() - hisIns.getStartTime().getTime();
taskVo.setDuration(getDate(time));
} else {
long time = System.currentTimeMillis() - hisIns.getStartTime().getTime();
taskVo.setDuration(getDate(time));
}
// 流程部署实例信息
Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(hisIns.getDeploymentId()).singleResult();
taskVo.setDeployId(hisIns.getDeploymentId());
taskVo.setProcDefId(hisIns.getProcessDefinitionId());
taskVo.setProcDefName(hisIns.getProcessDefinitionName());
taskVo.setProcDefVersion(hisIns.getProcessDefinitionVersion());
taskVo.setCategory(deployment.getCategory());
// 当前所处流程 todo: 本地启动放开以下注释
// List<Task> taskList = taskService.createTaskQuery().processInstanceId(hisIns.getId()).list();
// if (CollectionUtils.isNotEmpty(taskList)) {
// flowTask.setTaskId(taskList.get(0).getId());
// } else {
// List<HistoricTaskInstance> historicTaskInstance = historyService.createHistoricTaskInstanceQuery().processInstanceId(hisIns.getId()).orderByHistoricTaskInstanceEndTime().desc().list();
// flowTask.setTaskId(historicTaskInstance.get(0).getId());
// }
taskVoList.add(taskVo);
}
page.setRecords(taskVoList);
return TableDataInfo.build(page);
}
use of org.flowable.engine.history.HistoricProcessInstanceQuery in project petals-se-flowable by petalslink.
the class AdminOperations method purgeProcessInstance.
/**
* Admin utility operation associated to {@link AdminRuntimeService#purgeProcessInstance(String, boolean)}
*/
public static List<String> purgeProcessInstance(final String procInstId, final boolean returnsCorrelatedFlows, final ProcessEngine flowableEngine) throws PetalsException {
assert procInstId != null;
assert !procInstId.trim().isEmpty();
final List<String> result = new LinkedList<>();
final HistoricProcessInstanceQuery procInstQuery = flowableEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(procInstId).includeProcessVariables();
final HistoricProcessInstance procInst = procInstQuery.singleResult();
if (procInst == null) {
throw new ProcessInstanceNotFoundException(procInstId);
} else {
final String procInstFlowId = (String) procInst.getProcessVariables().get(FlowableSEConstants.Flowable.VAR_PETALS_FLOW_INSTANCE_ID);
if (procInstFlowId != null) {
result.add(procInstFlowId);
}
if (returnsCorrelatedFlows) {
final String procInstCorrelatedFlowId = (String) procInst.getProcessVariables().get(FlowableSEConstants.Flowable.VAR_PETALS_CORRELATED_FLOW_INSTANCE_ID);
if (procInstCorrelatedFlowId != null) {
result.add(procInstCorrelatedFlowId);
}
final HistoricTaskInstanceQuery procInstTasksQuery = flowableEngine.getHistoryService().createHistoricTaskInstanceQuery().processInstanceId(procInstId).includeTaskLocalVariables();
// TODO: We should be able to filter on task local variable, but it seems to not work
// .taskVariableExists(FlowableSEConstants.Flowable.VAR_PETALS_CORRELATED_FLOW_INSTANCE_ID);
final List<HistoricTaskInstance> procInstTasks = procInstTasksQuery.list();
for (final HistoricTaskInstance procInstTask : procInstTasks) {
final String procInstTaskCorrelatedFlowId = (String) procInstTask.getTaskLocalVariables().get(FlowableSEConstants.Flowable.VAR_PETALS_CORRELATED_FLOW_INSTANCE_ID);
if (procInstTaskCorrelatedFlowId != null) {
result.add(procInstTaskCorrelatedFlowId);
}
}
}
flowableEngine.getHistoryService().deleteHistoricProcessInstance(procInstId);
return result;
}
}
use of org.flowable.engine.history.HistoricProcessInstanceQuery in project petals-se-flowable by petalslink.
the class AdminOperations method undeployProcessDefinition.
/**
* Admin utility operation associated to {@link AdminRuntimeService#undeployProcessDefinition(String, int)}
*/
public static void undeployProcessDefinition(final String procDefKey, final int procDefVer, final ProcessEngine flowableEngine) throws PetalsException {
// We look for the process definition
final ProcessDefinition procDef = flowableEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(procDefKey).processDefinitionVersion(procDefVer).singleResult();
if (procDef == null) {
throw new ProcessDefinitionNotFoundException(procDefKey, procDefVer);
}
// Check if pending (active or suspended) process instances exist
final ProcessInstanceQuery procInstsQuery = flowableEngine.getRuntimeService().createProcessInstanceQuery().processDefinitionKey(procDefKey).processDefinitionVersion(procDefVer);
if (procInstsQuery.count() > 0) {
// Pending process instance exist for the given process definition. We can't undeploy it.
throw new ProcessInstanceExistForDefinitionException(procDefKey, procDefVer);
}
// Check if ended process instances exist
final HistoricProcessInstanceQuery endedProcInstsQuery = flowableEngine.getHistoryService().createHistoricProcessInstanceQuery().processDefinitionKey(procDefKey).processDefinitionVersion(procDefVer).finished();
if (endedProcInstsQuery.count() > 0) {
// Ended process instance exist for the given process definition. We can't undeploy it.
throw new ProcessInstanceExistForDefinitionException(procDefKey, procDefVer);
}
// We undeploy the process definition
try {
flowableEngine.getRepositoryService().deleteDeployment(procDef.getDeploymentId());
} catch (final RuntimeException e) {
throw new PetalsException(String.format("An error occurs trying to undeploy the process definition '%s' in its version %d", procDefKey, procDefVer), e);
}
}
Aggregations