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

The following examples show how to use org.activiti.engine.impl.persistence.entity.TaskEntity#setAssigneeWithoutCascade() . 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: ChangeSubTaskCmd.java    From lemon with Apache License 2.0 5 votes vote down vote up
public Object execute(CommandContext commandContext) {
    TaskEntity parentTask = commandContext.getTaskEntityManager()
            .findTaskById(taskId);

    this.createSubTask(parentTask, parentTask.getAssignee());
    this.createSubTask(parentTask, userId);
    parentTask.setAssigneeWithoutCascade(null);

    return null;
}
 
Example 3
Source File: CompleteNotice.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void processComplete(DelegateTask delegateTask,
        BpmConfNotice bpmConfNotice) {
    UserConnector userConnector = ApplicationContextHelper
            .getBean(UserConnector.class);
    NotificationConnector notificationConnector = ApplicationContextHelper
            .getBean(NotificationConnector.class);

    //
    Map<String, Object> data = new HashMap<String, Object>();
    TaskEntity taskEntity = new TaskEntity();
    taskEntity.setId(delegateTask.getId());
    taskEntity.setName(delegateTask.getName());
    taskEntity.setAssigneeWithoutCascade(userConnector.findById(
            delegateTask.getAssignee()).getDisplayName());
    taskEntity.setVariableLocal("initiator",
            getInitiator(userConnector, delegateTask));

    //
    data.put("task", taskEntity);
    data.put("initiator", this.getInitiator(userConnector, delegateTask));

    String receiver = bpmConfNotice.getReceiver();

    /*
     * BpmMailTemplate bpmMailTemplate = bpmConfNotice.getBpmMailTemplate(); ExpressionManager expressionManager =
     * Context .getProcessEngineConfiguration().getExpressionManager();
     */
    UserDTO userDto = null;

    if ("任务接收人".equals(receiver)) {
        userDto = userConnector.findById(delegateTask.getAssignee());
    } else if ("流程发起人".equals(receiver)) {
        userDto = userConnector.findById((String) delegateTask
                .getVariables().get("initiator"));
    } else {
        HistoricProcessInstanceEntity historicProcessInstanceEntity = Context
                .getCommandContext()
                .getHistoricProcessInstanceEntityManager()
                .findHistoricProcessInstance(
                        delegateTask.getProcessInstanceId());
        userDto = userConnector.findById(historicProcessInstanceEntity
                .getStartUserId());
    }

    /*
     * String subject = expressionManager .createExpression(bpmMailTemplate.getSubject())
     * .getValue(taskEntity).toString();
     * 
     * String content = expressionManager .createExpression(bpmMailTemplate.getContent())
     * .getValue(taskEntity).toString(); this.sendMail(userDto, subject, content); this.sendSiteMessage(userDto,
     * subject, content);
     */
    NotificationDTO notificationDto = new NotificationDTO();
    notificationDto.setReceiver(userDto.getId());
    notificationDto.setReceiverType("userid");
    notificationDto.setTypes(Arrays.asList(bpmConfNotice
            .getNotificationType().split(",")));
    notificationDto.setData(data);
    notificationDto.setTemplate(bpmConfNotice.getTemplateCode());
    notificationConnector.send(notificationDto, delegateTask.getTenantId());
}
 
Example 4
Source File: ArrivalNotice.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void processArrival(DelegateTask delegateTask,
        BpmConfNotice bpmConfNotice) {
    UserConnector userConnector = ApplicationContextHelper
            .getBean(UserConnector.class);
    NotificationConnector notificationConnector = ApplicationContextHelper
            .getBean(NotificationConnector.class);

    //
    Map<String, Object> data = new HashMap<String, Object>();

    TaskEntity taskEntity = new TaskEntity();
    taskEntity.setId(delegateTask.getId());
    taskEntity.setName(delegateTask.getName());
    taskEntity.setAssigneeWithoutCascade(userConnector.findById(
            delegateTask.getAssignee()).getDisplayName());
    taskEntity.setVariableLocal("initiator",
            getInitiator(userConnector, delegateTask));
    logger.debug("initiator : {}", delegateTask.getVariable("initator"));
    logger.debug("variables : {}", delegateTask.getVariables());
    //
    data.put("task", taskEntity);
    data.put("initiator", this.getInitiator(userConnector, delegateTask));

    String receiver = bpmConfNotice.getReceiver();

    /*
     * BpmMailTemplate bpmMailTemplate = bpmConfNotice.getBpmMailTemplate(); ExpressionManager expressionManager =
     * Context .getProcessEngineConfiguration().getExpressionManager();
     */
    UserDTO userDto = null;

    /*
     * String subject = expressionManager .createExpression(bpmMailTemplate.getSubject())
     * .getValue(taskEntity).toString();
     * 
     * String content = expressionManager .createExpression(bpmMailTemplate.getContent())
     * .getValue(taskEntity).toString();
     */
    if ("任务接收人".equals(receiver)) {
        userDto = userConnector.findById(delegateTask.getAssignee());
    } else if ("流程发起人".equals(receiver)) {
        userDto = userConnector.findById((String) delegateTask
                .getVariables().get("initiator"));
    } else {
        HistoricProcessInstanceEntity historicProcessInstanceEntity = Context
                .getCommandContext()
                .getHistoricProcessInstanceEntityManager()
                .findHistoricProcessInstance(
                        delegateTask.getProcessInstanceId());
        userDto = userConnector.findById(historicProcessInstanceEntity
                .getStartUserId());
    }

    // this.sendMail(userDto, subject, content);
    // this.sendSiteMessage(userDto, subject, content);
    NotificationDTO notificationDto = new NotificationDTO();
    notificationDto.setReceiver(userDto.getId());
    notificationDto.setReceiverType("userid");
    notificationDto.setTypes(Arrays.asList(bpmConfNotice
            .getNotificationType().split(",")));
    notificationDto.setData(data);
    notificationDto.setTemplate(bpmConfNotice.getTemplateCode());
    notificationConnector.send(notificationDto, delegateTask.getTenantId());
}
 
Example 5
Source File: TimeoutNotice.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void processTimeout(DelegateTask delegateTask,
        BpmConfNotice bpmConfNotice) {
    try {
        Date dueDate = delegateTask.getDueDate();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(dueDate);

        DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
        Duration duration = datatypeFactory.newDuration("-"
                + bpmConfNotice.getDueDate());
        duration.addTo(calendar);

        Date noticeDate = calendar.getTime();
        Date now = new Date();

        if ((now.getTime() < noticeDate.getTime())
                && ((noticeDate.getTime() - now.getTime()) < (60 * 1000))) {
            UserConnector userConnector = ApplicationContextHelper
                    .getBean(UserConnector.class);
            NotificationConnector notificationConnector = ApplicationContextHelper
                    .getBean(NotificationConnector.class);

            //
            Map<String, Object> data = new HashMap<String, Object>();
            TaskEntity taskEntity = new TaskEntity();
            taskEntity.setId(delegateTask.getId());
            taskEntity.setName(delegateTask.getName());
            taskEntity.setAssigneeWithoutCascade(userConnector.findById(
                    delegateTask.getAssignee()).getDisplayName());
            taskEntity.setVariableLocal("initiator",
                    getInitiator(userConnector, delegateTask));
            //
            data.put("task", taskEntity);
            data.put("initiator",
                    this.getInitiator(userConnector, delegateTask));

            String receiver = bpmConfNotice.getReceiver();

            /*
             * BpmMailTemplate bpmMailTemplate = bpmConfNotice .getBpmMailTemplate(); ExpressionManager
             * expressionManager = Context .getProcessEngineConfiguration().getExpressionManager();
             */
            UserDTO userDto = null;

            if ("任务接收人".equals(receiver)) {
                userDto = userConnector
                        .findById(delegateTask.getAssignee());
            } else if ("流程发起人".equals(receiver)) {
                userDto = userConnector.findById((String) delegateTask
                        .getVariables().get("initiator"));
            } else {
                HistoricProcessInstanceEntity historicProcessInstanceEntity = Context
                        .getCommandContext()
                        .getHistoricProcessInstanceEntityManager()
                        .findHistoricProcessInstance(
                                delegateTask.getProcessInstanceId());
                userDto = userConnector
                        .findById(historicProcessInstanceEntity
                                .getStartUserId());
            }

            /*
             * String subject = expressionManager .createExpression(bpmMailTemplate.getSubject())
             * .getValue(taskEntity).toString();
             * 
             * String content = expressionManager .createExpression(bpmMailTemplate.getContent())
             * .getValue(taskEntity).toString();
             * 
             * this.sendMail(userDto, subject, content); this.sendSiteMessage(userDto, subject, content);
             */
            NotificationDTO notificationDto = new NotificationDTO();
            notificationDto.setReceiver(userDto.getId());
            notificationDto.setReceiverType("userid");
            notificationDto.setTypes(Arrays.asList(bpmConfNotice
                    .getNotificationType().split(",")));
            notificationDto.setData(data);
            notificationDto.setTemplate(bpmConfNotice.getTemplateCode());

            notificationConnector.send(notificationDto,
                    delegateTask.getTenantId());
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }
}
 
Example 6
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 7
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 8
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 9
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);
    }
}