use of org.flowable.task.api.history.HistoricTaskInstanceQuery 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;
}
}
Aggregations