Java Code Examples for org.activiti.engine.impl.persistence.entity.TaskEntity#setProcessDefinitionId()

The following examples show how to use org.activiti.engine.impl.persistence.entity.TaskEntity#setProcessDefinitionId() . 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: SetProcessDefinitionVersionCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void validateAndSwitchVersionOfExecution(CommandContext commandContext, ExecutionEntity execution, ProcessDefinition newProcessDefinition) {
  // check that the new process definition version contains the current activity
  org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(newProcessDefinition.getId());
  if (execution.getActivityId() != null && process.getFlowElement(execution.getActivityId(), true) == null) { 
    throw new ActivitiException("The new process definition " + "(key = '" + newProcessDefinition.getKey() + "') " + "does not contain the current activity " + "(id = '"
        + execution.getActivityId() + "') " + "of the process instance " + "(id = '" + processInstanceId + "').");
  }

  // switch the process instance to the new process definition version
  execution.setProcessDefinitionId(newProcessDefinition.getId());
  execution.setProcessDefinitionName(newProcessDefinition.getName());
  execution.setProcessDefinitionKey(newProcessDefinition.getKey());

  // and change possible existing tasks (as the process definition id is stored there too)
  List<TaskEntity> tasks = commandContext.getTaskEntityManager().findTasksByExecutionId(execution.getId());
  for (TaskEntity taskEntity : tasks) {
    taskEntity.setProcessDefinitionId(newProcessDefinition.getId());
    commandContext.getHistoryManager().recordTaskProcessDefinitionChange(taskEntity.getId(), newProcessDefinition.getId());
  }
}
 
Example 2
Source File: SetProcessDefinitionVersionCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void validateAndSwitchVersionOfExecution(CommandContext commandContext, ExecutionEntity execution, ProcessDefinitionEntity newProcessDefinition) {
    // check that the new process definition version contains the current activity
    if (execution.getActivity() != null && !newProcessDefinition.contains(execution.getActivity())) {
        throw new ActivitiException(
                "The new process definition " +
                        "(key = '" + newProcessDefinition.getKey() + "') " +
                        "does not contain the current activity " +
                        "(id = '" + execution.getActivity().getId() + "') " +
                        "of the process instance " +
                        "(id = '" + processInstanceId + "').");
    }

    // switch the process instance to the new process definition version
    execution.setProcessDefinition(newProcessDefinition);

    // and change possible existing tasks (as the process definition id is stored there too)
    List<TaskEntity> tasks = commandContext.getTaskEntityManager().findTasksByExecutionId(execution.getId());
    for (TaskEntity taskEntity : tasks) {
        taskEntity.setProcessDefinitionId(newProcessDefinition.getId());
        commandContext.getHistoryManager().recordTaskProcessDefinitionChange(taskEntity.getId(), newProcessDefinition.getId());
    }
}
 
Example 3
Source File: ChangeSubTaskCmd.java    From lemon with Apache License 2.0 6 votes vote down vote up
public void createSubTask(TaskEntity parentTask, String assignee) {
    TaskEntity task = TaskEntity.create(new Date());
    task.setProcessDefinitionId(parentTask.getProcessDefinitionId());
    // task.setId(historicTaskInstanceEntity.getId());
    task.setAssigneeWithoutCascade(assignee);
    task.setParentTaskIdWithoutCascade(parentTask.getId());
    task.setNameWithoutCascade(parentTask.getName());
    task.setTaskDefinitionKey(parentTask.getTaskDefinitionKey());
    task.setExecutionId(parentTask.getExecutionId());
    task.setPriority(parentTask.getPriority());
    task.setProcessInstanceId(parentTask.getProcessInstanceId());
    task.setDescriptionWithoutCascade(parentTask.getDescription());
    task.setCategory("subtask");

    Context.getCommandContext().getTaskEntityManager().insert(task);
}
 
Example 4
Source File: RollbackTaskCmd.java    From lemon with Apache License 2.0 4 votes vote down vote up
/**
 * 根据任务历史,创建待办任务.
 */
public void processHistoryTask(CommandContext commandContext,
        TaskEntity taskEntity,
        HistoricTaskInstanceEntity historicTaskInstanceEntity,
        HistoricActivityInstanceEntity historicActivityInstanceEntity) {
    if (this.userId == null) {
        if (this.useLastAssignee) {
            this.userId = historicTaskInstanceEntity.getAssignee();
        } else {
            String processDefinitionId = taskEntity
                    .getProcessDefinitionId();
            ProcessDefinitionEntity processDefinitionEntity = new GetDeploymentProcessDefinitionCmd(
                    processDefinitionId).execute(commandContext);
            TaskDefinition taskDefinition = processDefinitionEntity
                    .getTaskDefinitions().get(
                            historicTaskInstanceEntity
                                    .getTaskDefinitionKey());

            if (taskDefinition == null) {
                String message = "cannot find taskDefinition : "
                        + historicTaskInstanceEntity.getTaskDefinitionKey();
                logger.info(message);
                throw new IllegalStateException(message);
            }

            if (taskDefinition.getAssigneeExpression() != null) {
                logger.info("assignee expression is null : {}",
                        taskDefinition.getKey());
                this.userId = (String) taskDefinition
                        .getAssigneeExpression().getValue(taskEntity);
            }
        }
    }

    /*
     * historicTaskInstanceEntity.setEndTime(null); historicTaskInstanceEntity.setDurationInMillis(null);
     * historicActivityInstanceEntity.setEndTime(null); historicActivityInstanceEntity.setDurationInMillis(null);
     */

    // 创建新任务
    TaskEntity task = TaskEntity.create(new Date());
    task.setProcessDefinitionId(historicTaskInstanceEntity
            .getProcessDefinitionId());
    // task.setId(historicTaskInstanceEntity.getId());
    task.setAssigneeWithoutCascade(userId);
    task.setParentTaskIdWithoutCascade(historicTaskInstanceEntity
            .getParentTaskId());
    task.setNameWithoutCascade(historicTaskInstanceEntity.getName());
    task.setTaskDefinitionKey(historicTaskInstanceEntity
            .getTaskDefinitionKey());
    task.setExecutionId(historicTaskInstanceEntity.getExecutionId());
    task.setPriority(historicTaskInstanceEntity.getPriority());
    task.setProcessInstanceId(historicTaskInstanceEntity
            .getProcessInstanceId());
    task.setExecutionId(historicTaskInstanceEntity.getExecutionId());
    task.setDescriptionWithoutCascade(historicTaskInstanceEntity
            .getDescription());
    task.setTenantId(historicTaskInstanceEntity.getTenantId());

    Context.getCommandContext().getTaskEntityManager().insert(task);

    // 把流程指向任务对应的节点
    ExecutionEntity executionEntity = Context.getCommandContext()
            .getExecutionEntityManager()
            .findExecutionById(historicTaskInstanceEntity.getExecutionId());
    executionEntity
            .setActivity(getActivity(historicActivityInstanceEntity));

    // 创建HistoricActivityInstance
    Context.getCommandContext().getHistoryManager()
            .recordActivityStart(executionEntity);

    // 创建HistoricTaskInstance
    Context.getCommandContext().getHistoryManager()
            .recordTaskCreated(task, executionEntity);
    Context.getCommandContext().getHistoryManager().recordTaskId(task);
    // 更新ACT_HI_ACTIVITY里的assignee字段
    Context.getCommandContext().getHistoryManager()
            .recordTaskAssignment(task);

    try {
        // humanTask
        this.createHumanTask(task, historicTaskInstanceEntity);
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }
}
 
Example 5
Source File: CheckWithdrawTaskCmd.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void processHistoryTask(
        HistoricTaskInstanceEntity historicTaskInstanceEntity,
        HistoricActivityInstanceEntity historicActivityInstanceEntity) {
    historicTaskInstanceEntity.setEndTime(null);
    historicTaskInstanceEntity.setDurationInMillis(null);
    historicActivityInstanceEntity.setEndTime(null);
    historicActivityInstanceEntity.setDurationInMillis(null);

    TaskEntity task = TaskEntity.create(new Date());
    task.setProcessDefinitionId(historicTaskInstanceEntity
            .getProcessDefinitionId());
    task.setId(historicTaskInstanceEntity.getId());
    task.setAssigneeWithoutCascade(historicTaskInstanceEntity.getAssignee());
    task.setParentTaskIdWithoutCascade(historicTaskInstanceEntity
            .getParentTaskId());
    task.setNameWithoutCascade(historicTaskInstanceEntity.getName());
    task.setTaskDefinitionKey(historicTaskInstanceEntity
            .getTaskDefinitionKey());
    task.setExecutionId(historicTaskInstanceEntity.getExecutionId());
    task.setPriority(historicTaskInstanceEntity.getPriority());
    task.setProcessInstanceId(historicTaskInstanceEntity
            .getProcessInstanceId());
    task.setDescriptionWithoutCascade(historicTaskInstanceEntity
            .getDescription());
    task.setTenantId(historicTaskInstanceEntity.getTenantId());

    Context.getCommandContext().getTaskEntityManager().insert(task);

    try {
        HumanTaskConnector humanTaskConnector = ApplicationContextHelper
                .getBean(HumanTaskConnector.class);
        // humantask
        humanTaskConnector
                .removeHumanTaskByTaskId(historicTaskInstanceEntity.getId());
        this.createHumanTask(task, historicTaskInstanceEntity);
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }

    ExecutionEntity executionEntity = Context.getCommandContext()
            .getExecutionEntityManager()
            .findExecutionById(historicTaskInstanceEntity.getExecutionId());
    executionEntity
            .setActivity(getActivity(historicActivityInstanceEntity));
}
 
Example 6
Source File: WithdrawTaskCmd.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void processHistoryTask(
        HistoricTaskInstanceEntity historicTaskInstanceEntity,
        HistoricActivityInstanceEntity historicActivityInstanceEntity) {
    historicTaskInstanceEntity.setEndTime(null);
    historicTaskInstanceEntity.setDurationInMillis(null);
    historicActivityInstanceEntity.setEndTime(null);
    historicActivityInstanceEntity.setDurationInMillis(null);

    TaskEntity task = TaskEntity.create(new Date());
    task.setProcessDefinitionId(historicTaskInstanceEntity
            .getProcessDefinitionId());
    task.setId(historicTaskInstanceEntity.getId());
    task.setAssigneeWithoutCascade(historicTaskInstanceEntity.getAssignee());
    task.setParentTaskIdWithoutCascade(historicTaskInstanceEntity
            .getParentTaskId());
    task.setNameWithoutCascade(historicTaskInstanceEntity.getName());
    task.setTaskDefinitionKey(historicTaskInstanceEntity
            .getTaskDefinitionKey());
    task.setExecutionId(historicTaskInstanceEntity.getExecutionId());
    task.setPriority(historicTaskInstanceEntity.getPriority());
    task.setProcessInstanceId(historicTaskInstanceEntity
            .getProcessInstanceId());
    task.setDescriptionWithoutCascade(historicTaskInstanceEntity
            .getDescription());
    task.setTenantId(historicTaskInstanceEntity.getTenantId());

    Context.getCommandContext().getTaskEntityManager().insert(task);

    try {
        HumanTaskConnector humanTaskConnector = ApplicationContextHelper
                .getBean(HumanTaskConnector.class);
        // humantask
        humanTaskConnector
                .removeHumanTaskByTaskId(historicTaskInstanceEntity.getId());
        this.createHumanTask(task, historicTaskInstanceEntity);
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }

    ExecutionEntity executionEntity = Context.getCommandContext()
            .getExecutionEntityManager()
            .findExecutionById(historicTaskInstanceEntity.getExecutionId());
    executionEntity
            .setActivity(getActivity(historicActivityInstanceEntity));
}
 
Example 7
Source File: RollbackCmd.java    From lemon with Apache License 2.0 4 votes vote down vote up
/**
 * 根据任务历史,创建待办任务.
 */
public void processHistoryTask(
        HistoricTaskInstanceEntity historicTaskInstanceEntity,
        HistoricActivityInstanceEntity historicActivityInstanceEntity) {
    /*
     * historicTaskInstanceEntity.setEndTime(null); historicTaskInstanceEntity.setDurationInMillis(null);
     * historicActivityInstanceEntity.setEndTime(null); historicActivityInstanceEntity.setDurationInMillis(null);
     */

    // 创建新任务
    TaskEntity task = TaskEntity.create(new Date());
    task.setProcessDefinitionId(historicTaskInstanceEntity
            .getProcessDefinitionId());
    // task.setId(historicTaskInstanceEntity.getId());
    // task.setAssigneeWithoutCascade(historicTaskInstanceEntity.getAssignee());
    task.setAssigneeWithoutCascade(this.userId);
    task.setParentTaskIdWithoutCascade(historicTaskInstanceEntity
            .getParentTaskId());
    task.setNameWithoutCascade(historicTaskInstanceEntity.getName());
    task.setTaskDefinitionKey(historicTaskInstanceEntity
            .getTaskDefinitionKey());
    task.setExecutionId(historicTaskInstanceEntity.getExecutionId());
    task.setPriority(historicTaskInstanceEntity.getPriority());
    task.setProcessInstanceId(historicTaskInstanceEntity
            .getProcessInstanceId());
    task.setExecutionId(historicTaskInstanceEntity.getExecutionId());
    task.setDescriptionWithoutCascade(historicTaskInstanceEntity
            .getDescription());
    task.setTenantId(historicTaskInstanceEntity.getTenantId());

    Context.getCommandContext().getTaskEntityManager().insert(task);

    // 把流程指向任务对应的节点
    ExecutionEntity executionEntity = Context.getCommandContext()
            .getExecutionEntityManager()
            .findExecutionById(historicTaskInstanceEntity.getExecutionId());
    executionEntity
            .setActivity(getActivity(historicActivityInstanceEntity));

    // 创建HistoricActivityInstance
    Context.getCommandContext().getHistoryManager()
            .recordActivityStart(executionEntity);

    // 创建HistoricTaskInstance
    Context.getCommandContext().getHistoryManager()
            .recordTaskCreated(task, executionEntity);
    Context.getCommandContext().getHistoryManager().recordTaskId(task);
    // 更新ACT_HI_ACTIVITY里的assignee字段
    Context.getCommandContext().getHistoryManager()
            .recordTaskAssignment(task);

    try {
        // humanTask
        this.createHumanTask(task, historicTaskInstanceEntity);
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }
}