Java Code Examples for org.flowable.engine.impl.util.CommandContextUtil#getHistoricTaskService()

The following examples show how to use org.flowable.engine.impl.util.CommandContextUtil#getHistoricTaskService() . 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: AbstractHistoryManager.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void updateActivity(ExecutionEntity childExecution, String oldActivityId, FlowElement newFlowElement, TaskEntity task, Date updateTime) {
    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricActivityInstanceEntityManager historicActivityInstanceEntityManager = CommandContextUtil.getHistoricActivityInstanceEntityManager();
        List<HistoricActivityInstanceEntity> historicActivityInstances = historicActivityInstanceEntityManager.findHistoricActivityInstancesByExecutionAndActivityId(childExecution.getId(), oldActivityId);
        for (HistoricActivityInstanceEntity historicActivityInstance : historicActivityInstances) {
            historicActivityInstance.setProcessDefinitionId(childExecution.getProcessDefinitionId());
            historicActivityInstance.setActivityId(childExecution.getActivityId());
            historicActivityInstance.setActivityName(newFlowElement.getName());
        }
    }

    if (isHistoryLevelAtLeast(HistoryLevel.AUDIT)) {
        HistoricTaskService historicTaskService = CommandContextUtil.getHistoricTaskService();
        historicTaskService.recordTaskInfoChange(task, updateTime);
    }

}
 
Example 2
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void recordTaskInfoChange(TaskEntity taskEntity, String activityInstanceId, Date changeTime) {
    boolean assigneeChanged = false;
    if (isHistoryLevelAtLeast(HistoryLevel.AUDIT, taskEntity.getProcessDefinitionId())) {
        HistoricTaskService historicTaskService = CommandContextUtil.getHistoricTaskService();
        HistoricTaskInstanceEntity originalHistoricTaskInstanceEntity = historicTaskService.getHistoricTask(taskEntity.getId());
        String originalAssignee = null;
        if (originalHistoricTaskInstanceEntity != null) {
            originalAssignee = originalHistoricTaskInstanceEntity.getAssignee();
        }

        HistoricTaskInstanceEntity historicTaskInstance = historicTaskService.recordTaskInfoChange(taskEntity, changeTime);
        if (historicTaskInstance != null) {
            if (!Objects.equals(originalAssignee, taskEntity.getAssignee())) {
                assigneeChanged = true;
            }
        }
    }

    if (assigneeChanged && isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, taskEntity.getProcessDefinitionId())) {
        if (taskEntity.getExecutionId() != null) {
            HistoricActivityInstanceEntity historicActivityInstance;
            if (activityInstanceId != null) {
                historicActivityInstance = getHistoricActivityInstanceEntityManager().findById(activityInstanceId);
            } else {
                // backup for the case when runtime activityInstance was not created
                ExecutionEntity executionEntity = getExecutionEntityManager().findById(taskEntity.getExecutionId());
                historicActivityInstance = findHistoricActivityInstance(executionEntity, true);
            }
            if (historicActivityInstance != null) {
                historicActivityInstance.setAssignee(taskEntity.getAssignee());
            }
        }
    }
}
 
Example 3
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void updateProcessDefinitionIdInHistory(ProcessDefinitionEntity processDefinitionEntity, ExecutionEntity processInstance) {
    if (isHistoryEnabled(processDefinitionEntity.getId())) {
        HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceEntityManager().findById(processInstance.getId());
        historicProcessInstance.setProcessDefinitionId(processDefinitionEntity.getId());
        getHistoricProcessInstanceEntityManager().update(historicProcessInstance);

        HistoricTaskService historicTaskService = CommandContextUtil.getHistoricTaskService();
        HistoricTaskInstanceQueryImpl taskQuery = new HistoricTaskInstanceQueryImpl();
        taskQuery.processInstanceId(processInstance.getId());
        List<HistoricTaskInstance> historicTasks = historicTaskService.findHistoricTaskInstancesByQueryCriteria(taskQuery);
        if (historicTasks != null) {
            for (HistoricTaskInstance historicTaskInstance : historicTasks) {
                HistoricTaskInstanceEntity taskEntity = (HistoricTaskInstanceEntity) historicTaskInstance;
                taskEntity.setProcessDefinitionId(processDefinitionEntity.getId());
                historicTaskService.updateHistoricTask(taskEntity, true);
            }
        }

        // because of upgrade runtimeActivity instances can be only subset of historicActivity instances
        HistoricActivityInstanceQueryImpl historicActivityQuery = new HistoricActivityInstanceQueryImpl();
        historicActivityQuery.processInstanceId(processInstance.getId());
        List<HistoricActivityInstance> historicActivities = getHistoricActivityInstanceEntityManager().findHistoricActivityInstancesByQueryCriteria(historicActivityQuery);
        if (historicActivities != null) {
            for (HistoricActivityInstance historicActivityInstance : historicActivities) {
                HistoricActivityInstanceEntity activityEntity = (HistoricActivityInstanceEntity) historicActivityInstance;
                activityEntity.setProcessDefinitionId(processDefinitionEntity.getId());
                getHistoricActivityInstanceEntityManager().update(activityEntity);
            }
        }
    }
}
 
Example 4
Source File: UpdateProcessDefinitionCascadeHistoryJsonTransformer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void transformJson(HistoryJobEntity job, ObjectNode historicalData, CommandContext commandContext) {
    String processDefinitionId = getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_DEFINITION_ID);
    String processInstanceId = getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_INSTANCE_ID);
    
    HistoricProcessInstanceEntityManager historicProcessInstanceEntityManager = CommandContextUtil.getHistoricProcessInstanceEntityManager(commandContext);
    HistoricProcessInstanceEntity historicProcessInstance = (HistoricProcessInstanceEntity) historicProcessInstanceEntityManager.findById(processInstanceId);
    historicProcessInstance.setProcessDefinitionId(processDefinitionId);
    historicProcessInstanceEntityManager.update(historicProcessInstance);

    HistoricTaskService historicTaskService = CommandContextUtil.getHistoricTaskService();
    HistoricTaskInstanceQueryImpl taskQuery = new HistoricTaskInstanceQueryImpl();
    taskQuery.processInstanceId(processInstanceId);
    List<HistoricTaskInstance> historicTasks = historicTaskService.findHistoricTaskInstancesByQueryCriteria(taskQuery);
    if (historicTasks != null) {
        for (HistoricTaskInstance historicTaskInstance : historicTasks) {
            HistoricTaskInstanceEntity taskEntity = (HistoricTaskInstanceEntity) historicTaskInstance;
            taskEntity.setProcessDefinitionId(processDefinitionId);
            historicTaskService.updateHistoricTask(taskEntity, true);
        }
    }
    
    HistoricActivityInstanceEntityManager historicActivityInstanceEntityManager = CommandContextUtil.getHistoricActivityInstanceEntityManager(commandContext);
    HistoricActivityInstanceQueryImpl activityQuery = new HistoricActivityInstanceQueryImpl();
    activityQuery.processInstanceId(processInstanceId);
    List<HistoricActivityInstance> historicActivities = historicActivityInstanceEntityManager.findHistoricActivityInstancesByQueryCriteria(activityQuery);
    if (historicActivities != null) {
        for (HistoricActivityInstance historicActivityInstance : historicActivities) {
            HistoricActivityInstanceEntity activityEntity = (HistoricActivityInstanceEntity) historicActivityInstance;
            activityEntity.setProcessDefinitionId(processDefinitionId);
            historicActivityInstanceEntityManager.update(activityEntity);
        }
    }
}
 
Example 5
Source File: TaskCreatedHistoryJsonTransformer.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void transformJson(HistoryJobEntity job, ObjectNode historicalData, CommandContext commandContext) {
    HistoricTaskService historicTaskService = CommandContextUtil.getHistoricTaskService();

    String taskId = getStringFromJson(historicalData, HistoryJsonConstants.ID);
    String executionId = getStringFromJson(historicalData, HistoryJsonConstants.EXECUTION_ID);
    
    HistoricTaskInstanceEntity historicTaskInstance = historicTaskService.getHistoricTask(taskId);
    
    if (historicTaskInstance == null) {
        historicTaskInstance = historicTaskService.createHistoricTask();
        historicTaskInstance.setId(taskId);
        historicTaskInstance.setProcessDefinitionId(getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_DEFINITION_ID));
        historicTaskInstance.setProcessInstanceId(getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_INSTANCE_ID));
        historicTaskInstance.setExecutionId(executionId);
        historicTaskInstance.setName(getStringFromJson(historicalData, HistoryJsonConstants.NAME));
        historicTaskInstance.setParentTaskId(getStringFromJson(historicalData, HistoryJsonConstants.PARENT_TASK_ID));
        historicTaskInstance.setDescription(getStringFromJson(historicalData, HistoryJsonConstants.DESCRIPTION));
        historicTaskInstance.setOwner(getStringFromJson(historicalData, HistoryJsonConstants.OWNER));
        historicTaskInstance.setAssignee(getStringFromJson(historicalData, HistoryJsonConstants.ASSIGNEE));
        if (historicalData.has(HistoryJsonConstants.CREATE_TIME)) {
            historicTaskInstance.setCreateTime(getDateFromJson(historicalData, HistoryJsonConstants.CREATE_TIME));
        } else {
            // For backwards compatibility. New async data uses the CREATE_TIME. This should be removed eventually
            historicTaskInstance.setCreateTime(getDateFromJson(historicalData, HistoryJsonConstants.START_TIME));
        }
        historicTaskInstance.setTaskDefinitionKey(getStringFromJson(historicalData, HistoryJsonConstants.TASK_DEFINITION_KEY));
        historicTaskInstance.setTaskDefinitionId(getStringFromJson(historicalData, HistoryJsonConstants.TASK_DEFINITION_ID));
        historicTaskInstance.setFormKey(getStringFromJson(historicalData, HistoryJsonConstants.FORM_KEY));
        historicTaskInstance.setPriority(getIntegerFromJson(historicalData, HistoryJsonConstants.PRIORITY));
        historicTaskInstance.setDueDate(getDateFromJson(historicalData, HistoryJsonConstants.DUE_DATE));
        historicTaskInstance.setCategory(getStringFromJson(historicalData, HistoryJsonConstants.CATEGORY));
        historicTaskInstance.setClaimTime(getDateFromJson(historicalData, HistoryJsonConstants.CLAIM_TIME));
        historicTaskInstance.setTenantId(getStringFromJson(historicalData, HistoryJsonConstants.TENANT_ID));
        historicTaskInstance.setLastUpdateTime(getDateFromJson(historicalData, HistoryJsonConstants.TIMESTAMP));

        historicTaskService.insertHistoricTask(historicTaskInstance, true);
    }

    // there can be still job in the queue which can have activityId in and we should be able to handle it
    if (StringUtils.isNotEmpty(executionId)) {
        String activityId = getStringFromJson(historicalData, HistoryJsonConstants.ACTIVITY_ID);
        if (StringUtils.isNotEmpty(activityId)) {
            HistoricActivityInstanceEntity historicActivityInstanceEntity = findHistoricActivityInstance(commandContext, executionId, activityId);
            if (historicActivityInstanceEntity != null) {
                historicActivityInstanceEntity.setTaskId(taskId);
            }
        }
    }
}