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

The following examples show how to use org.flowable.engine.impl.util.CommandContextUtil#getHistoricProcessInstanceEntityManager() . 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: AbstractProcessInstanceDeleteHistoryTransformer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void deleteProcessInstance(String processInstanceId, CommandContext commandContext) {
    HistoricProcessInstanceEntityManager historicProcessInstanceEntityManager = CommandContextUtil.getHistoricProcessInstanceEntityManager(commandContext);
    HistoricProcessInstanceEntity historicProcessInstance = historicProcessInstanceEntityManager.findById(processInstanceId);
    
    CommandContextUtil.getHistoricDetailEntityManager(commandContext).deleteHistoricDetailsByProcessInstanceId(processInstanceId);
    CommandContextUtil.getHistoricVariableService().deleteHistoricVariableInstancesByProcessInstanceId(processInstanceId);
    CommandContextUtil.getHistoricActivityInstanceEntityManager(commandContext).deleteHistoricActivityInstancesByProcessInstanceId(processInstanceId);
    TaskHelper.deleteHistoricTaskInstancesByProcessInstanceId(processInstanceId);
    CommandContextUtil.getHistoricIdentityLinkService().deleteHistoricIdentityLinksByProcessInstanceId(processInstanceId);
    HistoricEntityLinkService historicEntityLinkService = CommandContextUtil.getHistoricEntityLinkService();
    if (historicEntityLinkService != null) {
        historicEntityLinkService.deleteHistoricEntityLinksByScopeIdAndScopeType(processInstanceId, ScopeTypes.BPMN);
    }
    CommandContextUtil.getCommentEntityManager(commandContext).deleteCommentsByProcessInstanceId(processInstanceId);

    historicProcessInstanceEntityManager.delete(historicProcessInstance, false);

    // Also delete any sub-processes that may be active (ACT-821)

    List<HistoricProcessInstance> selectList = historicProcessInstanceEntityManager.findHistoricProcessInstancesBySuperProcessInstanceId(processInstanceId);
    for (HistoricProcessInstance child : selectList) {
        deleteProcessInstance(child.getId(), commandContext);
    }
}
 
Example 2
Source File: ProcessInstanceStartHistoryJsonTransformer.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) {
    HistoricProcessInstanceEntityManager historicProcessInstanceEntityManager = CommandContextUtil.getHistoricProcessInstanceEntityManager(commandContext);

    String id = getStringFromJson(historicalData, "id");
    HistoricProcessInstanceEntity historicProcessInstance = historicProcessInstanceEntityManager.findById(id);
    if (historicProcessInstance == null) {
        historicProcessInstance = historicProcessInstanceEntityManager.create();
        historicProcessInstance.setId(getStringFromJson(historicalData, HistoryJsonConstants.ID));
        historicProcessInstance.setProcessInstanceId(getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_INSTANCE_ID));
        historicProcessInstance.setName(getStringFromJson(historicalData, HistoryJsonConstants.NAME));
        historicProcessInstance.setBusinessKey(getStringFromJson(historicalData, HistoryJsonConstants.BUSINESS_KEY));
        historicProcessInstance.setProcessDefinitionId(getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_DEFINITION_ID));
        historicProcessInstance.setProcessDefinitionKey(getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_DEFINITION_KEY));
        historicProcessInstance.setProcessDefinitionName(getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_DEFINITION_NAME));
        String versionString = getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_DEFINITION_VERSION);
        historicProcessInstance.setProcessDefinitionVersion(versionString != null ? Integer.valueOf(versionString) : 0);
        historicProcessInstance.setDeploymentId(getStringFromJson(historicalData, HistoryJsonConstants.DEPLOYMENT_ID));
        historicProcessInstance.setStartTime(getDateFromJson(historicalData, HistoryJsonConstants.START_TIME));
        historicProcessInstance.setStartUserId(getStringFromJson(historicalData, HistoryJsonConstants.START_USER_ID));
        historicProcessInstance.setStartActivityId(getStringFromJson(historicalData, HistoryJsonConstants.START_ACTIVITY_ID));
        historicProcessInstance.setSuperProcessInstanceId(getStringFromJson(historicalData, HistoryJsonConstants.SUPER_PROCESS_INSTANCE_ID));
        historicProcessInstance.setCallbackId(getStringFromJson(historicalData, HistoryJsonConstants.CALLBACK_ID));
        historicProcessInstance.setCallbackType(getStringFromJson(historicalData, HistoryJsonConstants.CALLBACK_TYPE));
        historicProcessInstance.setReferenceId(getStringFromJson(historicalData, HistoryJsonConstants.REFERENCE_ID));
        historicProcessInstance.setReferenceType(getStringFromJson(historicalData, HistoryJsonConstants.REFERENCE_TYPE));
        historicProcessInstance.setTenantId(getStringFromJson(historicalData, HistoryJsonConstants.TENANT_ID));

        historicProcessInstanceEntityManager.insert(historicProcessInstance, false);

        dispatchEvent(commandContext, FlowableEventBuilder.createEntityEvent(FlowableEngineEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
        
    } else {
        historicProcessInstance.setStartActivityId(getStringFromJson(historicalData, HistoryJsonConstants.START_ACTIVITY_ID));
        historicProcessInstanceEntityManager.update(historicProcessInstance, false);
    }
}
 
Example 3
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 4
Source File: AbstractNeedsProcessInstanceHistoryJsonTransformer.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isApplicable(ObjectNode historicalData, CommandContext commandContext) {
    String processInstanceId = getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_INSTANCE_ID);
    HistoricProcessInstanceEntityManager historicProcessInstanceEntityManager = CommandContextUtil.getHistoricProcessInstanceEntityManager(commandContext);
    return historicProcessInstanceEntityManager.findById(processInstanceId) != null;
}
 
Example 5
Source File: ProcessInstanceDeleteHistoryJsonTransformer.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isApplicable(ObjectNode historicalData, CommandContext commandContext) {
    String id = getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_INSTANCE_ID);
    HistoricProcessInstanceEntityManager historicProcessInstanceEntityManager = CommandContextUtil.getHistoricProcessInstanceEntityManager(commandContext);
    return historicProcessInstanceEntityManager.findById(id) != null;
}
 
Example 6
Source File: SubProcessInstanceStartHistoryJsonTransformer.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) {
    HistoricProcessInstanceEntityManager historicProcessInstanceEntityManager = CommandContextUtil.getHistoricProcessInstanceEntityManager(commandContext);

    String id = getStringFromJson(historicalData, HistoryJsonConstants.ID);
    String processInstanceId = getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_INSTANCE_ID);
    HistoricProcessInstanceEntity historicProcessInstance = historicProcessInstanceEntityManager.findById(id);
    if (historicProcessInstance == null) {
        HistoricProcessInstanceEntity subProcessInstance = historicProcessInstanceEntityManager.create();

        subProcessInstance.setId(id);
        subProcessInstance.setProcessInstanceId(processInstanceId);
        subProcessInstance.setBusinessKey(getStringFromJson(historicalData, HistoryJsonConstants.BUSINESS_KEY));
        subProcessInstance.setProcessDefinitionId(getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_DEFINITION_ID));
        subProcessInstance.setProcessDefinitionKey(getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_DEFINITION_KEY));
        subProcessInstance.setProcessDefinitionName(getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_DEFINITION_NAME));
        String versionString = getStringFromJson(historicalData, HistoryJsonConstants.PROCESS_DEFINITION_VERSION);
        subProcessInstance.setProcessDefinitionVersion(versionString != null ? Integer.valueOf(versionString) : 0);
        subProcessInstance.setDeploymentId(getStringFromJson(historicalData, HistoryJsonConstants.DEPLOYMENT_ID));
        subProcessInstance.setStartTime(getDateFromJson(historicalData, HistoryJsonConstants.START_TIME));
        subProcessInstance.setStartUserId(getStringFromJson(historicalData, HistoryJsonConstants.START_USER_ID));
        subProcessInstance.setStartActivityId(getStringFromJson(historicalData, HistoryJsonConstants.START_ACTIVITY_ID));
        subProcessInstance.setSuperProcessInstanceId(getStringFromJson(historicalData, HistoryJsonConstants.SUPER_PROCESS_INSTANCE_ID));
        subProcessInstance.setCallbackId(getStringFromJson(historicalData, HistoryJsonConstants.CALLBACK_ID));
        subProcessInstance.setCallbackType(getStringFromJson(historicalData, HistoryJsonConstants.CALLBACK_TYPE));
        subProcessInstance.setReferenceId(getStringFromJson(historicalData, HistoryJsonConstants.REFERENCE_ID));
        subProcessInstance.setReferenceType(getStringFromJson(historicalData, HistoryJsonConstants.REFERENCE_TYPE));
        subProcessInstance.setTenantId(getStringFromJson(historicalData, HistoryJsonConstants.TENANT_ID));
    
        historicProcessInstanceEntityManager.insert(subProcessInstance, false);

        // Fire event
        dispatchEvent(commandContext, FlowableEventBuilder.createEntityEvent(
                FlowableEngineEventType.HISTORIC_PROCESS_INSTANCE_CREATED, subProcessInstance));
    }
    
    String executionId = getStringFromJson(historicalData, HistoryJsonConstants.EXECUTION_ID);
    String activityId = getStringFromJson(historicalData, HistoryJsonConstants.ACTIVITY_ID);

    HistoricActivityInstanceEntity activityInstance = findHistoricActivityInstance(commandContext, executionId, activityId);
    if (activityInstance != null) {
        activityInstance.setCalledProcessInstanceId(processInstanceId);
    }
}