Search in sources :

Example 6 with HistoricTaskInstanceQuery

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;
    }
}
Also used : HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) HistoricProcessInstanceQuery(org.flowable.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) ProcessInstanceNotFoundException(org.ow2.petals.se.flowable.clientserver.api.admin.exception.ProcessInstanceNotFoundException) HistoricTaskInstanceQuery(org.flowable.task.api.history.HistoricTaskInstanceQuery) LinkedList(java.util.LinkedList)

Aggregations

HistoricTaskInstanceQuery (org.flowable.task.api.history.HistoricTaskInstanceQuery)6 HistoricTaskInstance (org.flowable.task.api.history.HistoricTaskInstance)4 HistoricProcessInstance (org.flowable.engine.history.HistoricProcessInstance)3 TaskPaginateList (com.plumdo.flow.rest.task.TaskPaginateList)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 CollUtil (cn.hutool.core.collection.CollUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 ServiceExceptionUtil.exception (cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception)1 PageResult (cn.iocoder.yudao.framework.common.pojo.PageResult)1 CollectionUtils.convertMap (cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap)1 CollectionUtils.convertSet (cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet)1 NumberUtils (cn.iocoder.yudao.framework.common.util.number.NumberUtils)1 PageUtils (cn.iocoder.yudao.framework.common.util.object.PageUtils)1 cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task (cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task)1 BpmTaskConvert (cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert)1 BpmTaskExtDO (cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO)1 BpmTaskExtMapper (cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmTaskExtMapper)1 ErrorCodeConstants (cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants)1 BpmProcessInstanceResultEnum (cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum)1 BpmMessageService (cn.iocoder.yudao.module.bpm.service.message.BpmMessageService)1