Java Code Examples for org.flowable.engine.impl.persistence.entity.ExecutionEntity#getTenantId()

The following examples show how to use org.flowable.engine.impl.persistence.entity.ExecutionEntity#getTenantId() . 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: StartProcessInstanceAsyncCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void executeAsynchronous(ExecutionEntity execution, Process process) {
    JobService jobService = CommandContextUtil.getJobService();

    JobEntity job = jobService.createJob();
    job.setExecutionId(execution.getId());
    job.setProcessInstanceId(execution.getProcessInstanceId());
    job.setProcessDefinitionId(execution.getProcessDefinitionId());
    job.setElementId(process.getId());
    job.setElementName(process.getName());
    job.setJobHandlerType(AsyncContinuationJobHandler.TYPE);

    // Inherit tenant id (if applicable)
    if (execution.getTenantId() != null) {
        job.setTenantId(execution.getTenantId());
    }

    execution.getJobs().add(job);

    jobService.createAsyncJob(job, false);
    jobService.scheduleAsyncJob(job);
}
 
Example 2
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void recordTaskCreated(TaskEntity task, ExecutionEntity execution) {
    String processDefinitionId = null;
    if (execution != null) {
        processDefinitionId = execution.getProcessDefinitionId();
    } else if (task != null) {
        processDefinitionId = task.getProcessDefinitionId();
    }
    if (isHistoryLevelAtLeast(HistoryLevel.AUDIT, processDefinitionId)) {
        if (execution != null) {
            task.setExecutionId(execution.getId());
            task.setProcessInstanceId(execution.getProcessInstanceId());
            task.setProcessDefinitionId(execution.getProcessDefinitionId());
            
            if (execution.getTenantId() != null) {
                task.setTenantId(execution.getTenantId());
            }
        }
        HistoricTaskInstanceEntity historicTaskInstance = CommandContextUtil.getHistoricTaskService().recordTaskCreated(task);
        historicTaskInstance.setLastUpdateTime(processEngineConfiguration.getClock().getCurrentTime());

        if (execution != null) {
            historicTaskInstance.setExecutionId(execution.getId());
        }
    }
}
 
Example 3
Source File: TaskHelper.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static void insertTask(TaskEntity taskEntity, ExecutionEntity execution, boolean fireCreateEvent, boolean addEntityLinks) {
    // Inherit tenant id (if applicable)
    if (execution != null && execution.getTenantId() != null) {
        taskEntity.setTenantId(execution.getTenantId());
    }

    if (execution != null) {
        execution.getTasks().add(taskEntity);
        taskEntity.setExecutionId(execution.getId());
        taskEntity.setProcessInstanceId(execution.getProcessInstanceId());
        taskEntity.setProcessDefinitionId(execution.getProcessDefinitionId());
    }

    insertTask(taskEntity, fireCreateEvent);

    if (execution != null) {

        if (CountingEntityUtil.isExecutionRelatedEntityCountEnabled(execution)) {
            CountingExecutionEntity countingExecutionEntity = (CountingExecutionEntity) execution;
            countingExecutionEntity.setTaskCount(countingExecutionEntity.getTaskCount() + 1);
        }

        if (addEntityLinks) {
            EntityLinkUtil.createEntityLinks(execution.getProcessInstanceId(), execution.getId(),
                    taskEntity.getTaskDefinitionKey(), taskEntity.getId(), ScopeTypes.TASK);
        }

    }

    FlowableEventDispatcher eventDispatcher = CommandContextUtil.getEventDispatcher();
    if (fireCreateEvent && eventDispatcher != null && eventDispatcher.isEnabled()) {
        if (taskEntity.getAssignee() != null) {
            eventDispatcher.dispatchEvent(
                    FlowableEventBuilder.createEntityEvent(FlowableEngineEventType.TASK_ASSIGNED, taskEntity));
        }
    }

    CommandContextUtil.getActivityInstanceEntityManager().recordTaskCreated(taskEntity, execution);
}
 
Example 4
Source File: AsyncHistoryManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void recordActivityEnd(ExecutionEntity executionEntity, String deleteReason, Date endTime) {
    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, executionEntity.getProcessDefinitionId())) {
        String activityId = getActivityIdForExecution(executionEntity);
        if (StringUtils.isNotEmpty(activityId)) {
            ObjectNode data = processEngineConfiguration.getObjectMapper().createObjectNode();

            putIfNotNull(data, HistoryJsonConstants.PROCESS_DEFINITION_ID, executionEntity.getProcessDefinitionId());
            putIfNotNull(data, HistoryJsonConstants.PROCESS_INSTANCE_ID, executionEntity.getProcessInstanceId());
            putIfNotNull(data, HistoryJsonConstants.EXECUTION_ID, executionEntity.getId());
            putIfNotNull(data, HistoryJsonConstants.ACTIVITY_ID, activityId);

            if (executionEntity.getCurrentFlowElement() != null) {
                putIfNotNull(data, HistoryJsonConstants.ACTIVITY_NAME, executionEntity.getCurrentFlowElement().getName());
                putIfNotNull(data, HistoryJsonConstants.ACTIVITY_TYPE, parseActivityType(executionEntity.getCurrentFlowElement()));
            }

            if (executionEntity.getTenantId() != null) {
                putIfNotNull(data, HistoryJsonConstants.TENANT_ID, executionEntity.getTenantId());
            }

            putIfNotNull(data, HistoryJsonConstants.DELETE_REASON, deleteReason);
            putIfNotNull(data, HistoryJsonConstants.END_TIME, endTime);

            ObjectNode correspondingActivityStartData = getActivityStart(executionEntity.getId(), activityId, true);
            if (correspondingActivityStartData == null) {
                getAsyncHistorySession().addHistoricData(getJobServiceConfiguration(), HistoryJsonConstants.TYPE_ACTIVITY_END, data);
            } else {
                data.put(HistoryJsonConstants.START_TIME, getStringFromJson(correspondingActivityStartData, HistoryJsonConstants.START_TIME));
                getAsyncHistorySession().addHistoricData(getJobServiceConfiguration(), HistoryJsonConstants.TYPE_ACTIVITY_FULL, data);
            }
        }
    }
}
 
Example 5
Source File: DefaultInternalJobManager.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean handleJobInsertInternal(Job job) {
    // add link to execution
    if (job.getExecutionId() != null) {
        ExecutionEntity execution = getExecutionEntityManager().findById(job.getExecutionId());
        if (execution != null) {
            
            // Inherit tenant if (if applicable)
            if (execution.getTenantId() != null) {
                ((AbstractRuntimeJobEntity) job).setTenantId(execution.getTenantId());
            }
            
            CountingExecutionEntity countingExecutionEntity = (CountingExecutionEntity) execution;
            
            if (job instanceof TimerJobEntity) {
                TimerJobEntity timerJobEntity = (TimerJobEntity) job;
                execution.getTimerJobs().add(timerJobEntity);

                if (CountingEntityUtil.isExecutionRelatedEntityCountEnabled(execution)) {
                    countingExecutionEntity.setTimerJobCount(countingExecutionEntity.getTimerJobCount() + 1);
                }
                
            } else if (job instanceof JobEntity) {
                JobEntity jobEntity = (JobEntity) job;
                execution.getJobs().add(jobEntity);

                if (CountingEntityUtil.isExecutionRelatedEntityCountEnabled(execution)) {
                    countingExecutionEntity.setJobCount(countingExecutionEntity.getJobCount() + 1);
                }
            
            } else {
                if (CountingEntityUtil.isExecutionRelatedEntityCountEnabled(execution)) {
                    if (job instanceof SuspendedJobEntity) {
                        countingExecutionEntity.setSuspendedJobCount(countingExecutionEntity.getSuspendedJobCount() + 1);
                    } else if (job instanceof DeadLetterJobEntity) {
                        countingExecutionEntity.setDeadLetterJobCount(countingExecutionEntity.getDeadLetterJobCount() + 1);
                    } else if (job instanceof ExternalWorkerJobEntity) {
                        countingExecutionEntity.setExternalWorkerJobCount(countingExecutionEntity.getExternalWorkerJobCount() + 1);
                    }
                }
            }

        } else {
            // In case the job has an executionId, but the Execution was not found,
            // it means that for example for a boundary timer event on a user task,
            // the task has been completed and the Execution and job have been removed.
            return false;
        }
    }
    
    return true;
}