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

The following examples show how to use org.activiti.engine.impl.persistence.entity.TaskEntity#create() . 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: 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 2
Source File: TestFlowableEntityEventTaskListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private Task copy(Task aTask) {
    TaskEntity ent = TaskEntity.create(aTask.getCreateTime());
    ent.setId(aTask.getId());
    ent.setName(aTask.getName());
    ent.setDescription(aTask.getDescription());
    ent.setOwner(aTask.getOwner());
    ent.setDueDateWithoutCascade(aTask.getDueDate());
    ent.setAssignee(aTask.getAssignee());
    ent.setPriority(aTask.getPriority());
    return ent;
}
 
Example 3
Source File: NewTaskCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Task execute(CommandContext commandContext) {
    Date currentTime = commandContext.getProcessEngineConfiguration().getClock().getCurrentTime();
    TaskEntity task = TaskEntity.create(currentTime);
    task.setId(taskId);
    return 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);
    }
}