Java Code Examples for org.activiti.engine.task.Task#getTaskDefinitionKey()

The following examples show how to use org.activiti.engine.task.Task#getTaskDefinitionKey() . 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: FunctionEventListener.java    From lemon with Apache License 2.0 6 votes vote down vote up
public void onTaskCompleted(ActivitiEntityEvent event) {
    logger.debug("task completed {}", event);

    String processInstanceId = event.getProcessInstanceId();
    ExecutionEntity executionEntity = Context.getCommandContext()
            .getExecutionEntityManager()
            .findExecutionById(processInstanceId);
    String businessKey = executionEntity.getBusinessKey();
    String processDefinitionId = event.getProcessDefinitionId();
    Task task = (Task) event.getEntity();
    String activityId = task.getTaskDefinitionKey();
    String activityName = this.findActivityName(activityId,
            processDefinitionId);
    int eventCode = 5;
    String eventName = "complete";
    String userId = Authentication.getAuthenticatedUserId();
    this.invokeExpression(eventCode, eventName, businessKey, userId,
            activityId, activityName);
}
 
Example 2
Source File: BpmTaskServiceImpl.java    From hsweb-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void setCandidate(String doingUserId, Task task) {
    if (task == null) {
        return;
    }
    if (task.getTaskDefinitionKey() != null) {
        //从配置中获取候选人
        List<CandidateInfo> candidateInfoList = processConfigurationService
                .getActivityConfiguration(doingUserId, task.getProcessDefinitionId(), task.getTaskDefinitionKey())
                .getCandidateInfo(task);
        if (CollectionUtils.isEmpty(candidateInfoList)) {
            logger.warn("任务:{}未能设置候选人,此任务可能无法办理!", task);
        } else {
            for (CandidateInfo candidateInfo : candidateInfoList) {
                Authentication user = candidateInfo.user();
                if (user != null) {
                    taskService.addCandidateUser(task.getId(), user.getUser().getId());
                }
            }
        }
    } else {
        logger.warn("未能成功设置环节候选人,task:{}", task);
    }
}
 
Example 3
Source File: MyTaskController.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 跳转到任务办理界面
 */
@Before(IdRequired.class)
public void goCompleteForm() {
    String taskId = getPara("id");
    Task task = ActivitiKit.getTaskService().createTaskQuery()
            .taskId(taskId).singleResult();

    set("taskName", task.getName());
    if (StringUtils.notEmpty(task.getDescription())) {
        set("taskDescription", task.getDescription());
    }
    set("taskId", task.getId());
    String processInstanceId = task.getProcessInstanceId();
    set("processInstanceId", processInstanceId);

    ProcessInstance processInstance = ActivitiKit.getRuntimeService().createProcessInstanceQuery()
            .processInstanceId(processInstanceId)
            .includeProcessVariables()
            .singleResult();

    String businessForm = (String) processInstance.getProcessVariables().get("businessForm");
    String initiator = (String) processInstance.getProcessVariables().get("initiator");
    String renderedTaskForm = (String) ActivitiKit.getFormService().getRenderedTaskForm(taskId);

    setAttr("initiator", initiator);  // 发起人
    setAttr("processInstanceName", processInstance.getName()); // 流程实例名
    setAttr("businessKey", processInstance.getBusinessKey()); // 业务表 id
    setAttr("businessForm", businessForm);  // 业务表名
    setAttr("renderedTaskForm", renderedTaskForm); // 任务表单

    // 如果是调整表单, 显示调整操作
    String taskDefinitionKey = task.getTaskDefinitionKey();
    setAttr("taskDefinitionKey", taskDefinitionKey);
    if ("adjustForm".equals(taskDefinitionKey)) {
        String adjustFormUrl = StrKit.toCamelCase(businessForm) + "/newModel?id=" + getAttr("businessKey");
        setAttr("adjustFormUrl", adjustFormUrl);
    }

    render("oa/myTask_complete.ftl");
}
 
Example 4
Source File: LeaveController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 任务列表
 *
 * @param leave
 */
@RequestMapping(value = "task/view/{taskId}")
public ModelAndView showTaskView(@PathVariable("taskId") String taskId) {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    Leave leave = leaveManager.get(new Long(processInstance.getBusinessKey()));
    ModelAndView mav = new ModelAndView("/chapter7/leave/task-" + task.getTaskDefinitionKey());
    mav.addObject("leave", leave);
    mav.addObject("task", task);
    return mav;
}
 
Example 5
Source File: LeaveController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 任务列表
 *
 * @param leave
 */
@RequestMapping(value = "task/view/{taskId}")
public ModelAndView showTaskView(@PathVariable("taskId") String taskId) {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    Leave leave = leaveManager.get(new Long(processInstance.getBusinessKey()));
    ModelAndView mav = new ModelAndView("/chapter7/leave/task-" + task.getTaskDefinitionKey());
    mav.addObject("leave", leave);
    mav.addObject("task", task);
    return mav;
}
 
Example 6
Source File: LeaveController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 任务列表
 *
 * @param leave
 */
@RequestMapping(value = "task/view/{taskId}")
public ModelAndView showTaskView(@PathVariable("taskId") String taskId) {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    Leave leave = leaveManager.get(new Long(processInstance.getBusinessKey()));
    ModelAndView mav = new ModelAndView("/chapter7/leave/task-" + task.getTaskDefinitionKey());
    mav.addObject("leave", leave);
    mav.addObject("task", task);
    return mav;
}
 
Example 7
Source File: LeaveController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 任务列表
 *
 * @param leave
 */
@RequestMapping(value = "task/view/{taskId}")
public ModelAndView showTaskView(@PathVariable("taskId") String taskId) {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    Leave leave = leaveManager.get(new Long(processInstance.getBusinessKey()));
    ModelAndView mav = new ModelAndView("/chapter7/leave/task-" + task.getTaskDefinitionKey());
    mav.addObject("leave", leave);
    mav.addObject("task", task);
    return mav;
}
 
Example 8
Source File: LeaveController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 任务列表
 *
 * @param leave
 */
@RequestMapping(value = "task/view/{taskId}")
public ModelAndView showTaskView(@PathVariable("taskId") String taskId) {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    Leave leave = leaveManager.get(new Long(processInstance.getBusinessKey()));
    ModelAndView mav = new ModelAndView("/chapter7/leave/task-" + task.getTaskDefinitionKey());
    mav.addObject("leave", leave);
    mav.addObject("task", task);
    return mav;
}
 
Example 9
Source File: LeaveController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 任务列表
 *
 * @param leave
 */
@RequestMapping(value = "task/view/{taskId}")
public ModelAndView showTaskView(@PathVariable("taskId") String taskId) {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    Leave leave = leaveManager.get(new Long(processInstance.getBusinessKey()));
    ModelAndView mav = new ModelAndView("/chapter7/leave/task-" + task.getTaskDefinitionKey());
    mav.addObject("leave", leave);
    mav.addObject("task", task);
    return mav;
}
 
Example 10
Source File: LeaveController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 任务列表
 *
 * @param leave
 */
@RequestMapping(value = "task/view/{taskId}")
public ModelAndView showTaskView(@PathVariable("taskId") String taskId) {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    Leave leave = leaveManager.get(new Long(processInstance.getBusinessKey()));
    ModelAndView mav = new ModelAndView("/chapter7/leave/task-" + task.getTaskDefinitionKey());
    mav.addObject("leave", leave);
    mav.addObject("task", task);
    return mav;
}
 
Example 11
Source File: LeaveController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 任务列表
 *
 * @param leave
 */
@RequestMapping(value = "task/view/{taskId}")
public ModelAndView showTaskView(@PathVariable("taskId") String taskId) {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    Leave leave = leaveManager.get(new Long(processInstance.getBusinessKey()));
    ModelAndView mav = new ModelAndView("/chapter7/leave/task-" + task.getTaskDefinitionKey());
    mav.addObject("leave", leave);
    mav.addObject("task", task);
    return mav;
}
 
Example 12
Source File: LeaveController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 任务列表
 *
 * @param leave
 */
@RequestMapping(value = "task/view/{taskId}")
public ModelAndView showTaskView(@PathVariable("taskId") String taskId) {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    Leave leave = leaveManager.get(new Long(processInstance.getBusinessKey()));
    ModelAndView mav = new ModelAndView("/chapter7/leave/task-" + task.getTaskDefinitionKey());
    mav.addObject("leave", leave);
    mav.addObject("task", task);
    return mav;
}
 
Example 13
Source File: LeaveController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 任务列表
 *
 * @param leave
 */
@RequestMapping(value = "task/view/{taskId}")
public ModelAndView showTaskView(@PathVariable("taskId") String taskId) {
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    Leave leave = leaveManager.get(new Long(processInstance.getBusinessKey()));
    ModelAndView mav = new ModelAndView("/chapter7/leave/task-" + task.getTaskDefinitionKey());
    mav.addObject("leave", leave);
    mav.addObject("task", task);
    return mav;
}
 
Example 14
Source File: ActivitiInternalProcessConnector.java    From lemon with Apache License 2.0 4 votes vote down vote up
/**
 * 获得任务表单,不包含表单内容.
 */
public FormDTO findTaskForm(String taskId) {
    if (taskId == null) {
        logger.error("taskId cannot be null");

        return null;
    }

    Task task = processEngine.getTaskService().createTaskQuery()
            .taskId(taskId).singleResult();

    if (task == null) {
        logger.error("cannot find task for {}", taskId);

        return null;
    }

    String processDefinitionId = task.getProcessDefinitionId();
    String activityId = task.getTaskDefinitionKey();
    FormDTO formDto = new FormDTO();
    formDto.setTaskId(taskId);

    List<BpmConfOperation> bpmConfOperations = bpmConfOperationManager
            .find("from BpmConfOperation where bpmConfNode.bpmConfBase.processDefinitionId=? and bpmConfNode.code=?",
                    processDefinitionId, activityId);

    for (BpmConfOperation bpmConfOperation : bpmConfOperations) {
        formDto.getButtons().add(bpmConfOperation.getValue());
    }

    formDto.setProcessDefinitionId(processDefinitionId);
    formDto.setActivityId(activityId);

    List<BpmConfForm> bpmConfForms = bpmConfFormManager
            .find("from BpmConfForm where bpmConfNode.bpmConfBase.processDefinitionId=? and bpmConfNode.code=?",
                    processDefinitionId, activityId);

    if (!bpmConfForms.isEmpty()) {
        BpmConfForm bpmConfForm = bpmConfForms.get(0);

        if (!Integer.valueOf(2).equals(bpmConfForm.getStatus())) {
            // 外部表单
            if (Integer.valueOf(1).equals(bpmConfForm.getType())) {
                formDto.setRedirect(true);
                formDto.setUrl(bpmConfForm.getValue());
            } else {
                formDto.setCode(bpmConfForm.getValue());
            }
        }
    }

    return formDto;
}
 
Example 15
Source File: HistoricTaskInstanceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment
public void testHistoricTaskInstance() throws Exception {
  Map<String, Object> varMap = new HashMap<String, Object>();
  varMap.put("formKeyVar", "expressionFormKey");
  String processInstanceId = runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest", varMap).getId();

  SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");

  // Set priority to non-default value
  Task runtimeTask = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
  runtimeTask.setPriority(1234);

  // Set due-date
  Date dueDate = sdf.parse("01/02/2003 04:05:06");
  runtimeTask.setDueDate(dueDate);
  taskService.saveTask(runtimeTask);

  String taskId = runtimeTask.getId();
  String taskDefinitionKey = runtimeTask.getTaskDefinitionKey();

  assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());
  HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
  assertEquals(taskId, historicTaskInstance.getId());
  assertEquals(1234, historicTaskInstance.getPriority());
  assertEquals("Clean up", historicTaskInstance.getName());
  assertEquals("Schedule an engineering meeting for next week with the new hire.", historicTaskInstance.getDescription());
  assertEquals(dueDate, historicTaskInstance.getDueDate());
  assertEquals("kermit", historicTaskInstance.getAssignee());
  assertEquals(taskDefinitionKey, historicTaskInstance.getTaskDefinitionKey());
  assertEquals("expressionFormKey", historicTaskInstance.getFormKey());
  assertNull(historicTaskInstance.getEndTime());
  assertNull(historicTaskInstance.getDurationInMillis());
  assertNull(historicTaskInstance.getWorkTimeInMillis());

  runtimeService.setVariable(processInstanceId, "deadline", "yesterday");

  taskService.claim(taskId, "kermit");

  assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());
  historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
  assertNotNull(historicTaskInstance.getClaimTime());
  assertNull(historicTaskInstance.getWorkTimeInMillis());
  assertEquals("expressionFormKey", historicTaskInstance.getFormKey());

  taskService.complete(taskId);

  assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());

  historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
  assertEquals(taskId, historicTaskInstance.getId());
  assertEquals(1234, historicTaskInstance.getPriority());
  assertEquals("Clean up", historicTaskInstance.getName());
  assertEquals("Schedule an engineering meeting for next week with the new hire.", historicTaskInstance.getDescription());
  assertEquals(dueDate, historicTaskInstance.getDueDate());
  assertEquals("kermit", historicTaskInstance.getAssignee());
  assertNull(historicTaskInstance.getDeleteReason());
  assertEquals(taskDefinitionKey, historicTaskInstance.getTaskDefinitionKey());
  assertEquals("expressionFormKey", historicTaskInstance.getFormKey());
  assertNotNull(historicTaskInstance.getEndTime());
  assertNotNull(historicTaskInstance.getDurationInMillis());
  assertNotNull(historicTaskInstance.getClaimTime());
  assertNotNull(historicTaskInstance.getWorkTimeInMillis());

  historyService.deleteHistoricTaskInstance(taskId);

  assertEquals(0, historyService.createHistoricTaskInstanceQuery().count());
}
 
Example 16
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 读取用户任务的表单字段
 */
@RequestMapping(value = "task/getform/{taskId}")
public ModelAndView readTaskForm(@PathVariable("taskId") String taskId) throws Exception {
    String viewName = "chapter6/task-form";
    ModelAndView mav = new ModelAndView(viewName);
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    Task task = null;

    // 外置表单
    if (taskFormData != null && taskFormData.getFormKey() != null) {
        Object renderedTaskForm = formService.getRenderedTaskForm(taskId);
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("taskFormData", renderedTaskForm);
        mav.addObject("hasFormKey", true);
    } else if (taskFormData != null) { // 动态表单
        mav.addObject("taskFormData", taskFormData);
        task = taskFormData.getTask();
    } else { // 手动创建的任务(包括子任务)
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("manualTask", true);
    }
    mav.addObject("task", task);

    // 读取任务参与人列表
    List<IdentityLink> identityLinksForTask = taskService.getIdentityLinksForTask(taskId);
    mav.addObject("identityLinksForTask", identityLinksForTask);

    // 读取所有人员
    List<User> users = identityService.createUserQuery().list();
    mav.addObject("users", users);

    // 读取所有组
    List<Group> groups = identityService.createGroupQuery().list();
    mav.addObject("groups", groups);

    // 读取子任务
    List<HistoricTaskInstance> subTasks = historyService.createHistoricTaskInstanceQuery().taskParentTaskId(taskId).list();
    mav.addObject("subTasks", subTasks);

    // 读取上级任务
    if (task != null && task.getParentTaskId() != null) {
        HistoricTaskInstance parentTask = historyService.createHistoricTaskInstanceQuery().taskId(task.getParentTaskId()).singleResult();
        mav.addObject("parentTask", parentTask);
    }

    // 读取附件
    List<Attachment> attachments = null;
    if (task.getTaskDefinitionKey() != null) {
        attachments = taskService.getTaskAttachments(taskId);
    } else {
        attachments = taskService.getProcessInstanceAttachments(task.getProcessInstanceId());
    }
    mav.addObject("attachments", attachments);

    return mav;
}
 
Example 17
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 读取用户任务的表单字段
 */
@RequestMapping(value = "task/getform/{taskId}")
public ModelAndView readTaskForm(@PathVariable("taskId") String taskId) throws Exception {
    String viewName = "chapter6/task-form";
    ModelAndView mav = new ModelAndView(viewName);
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    Task task = null;

    // 外置表单
    if (taskFormData != null && taskFormData.getFormKey() != null) {
        Object renderedTaskForm = formService.getRenderedTaskForm(taskId);
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("taskFormData", renderedTaskForm);
        mav.addObject("hasFormKey", true);
    } else if (taskFormData != null) { // 动态表单
        mav.addObject("taskFormData", taskFormData);
        task = taskFormData.getTask();
    } else { // 手动创建的任务(包括子任务)
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("manualTask", true);
    }
    mav.addObject("task", task);

    // 读取任务参与人列表
    List<IdentityLink> identityLinksForTask = taskService.getIdentityLinksForTask(taskId);
    mav.addObject("identityLinksForTask", identityLinksForTask);

    // 读取所有人员
    List<User> users = identityService.createUserQuery().list();
    mav.addObject("users", users);

    // 读取所有组
    List<Group> groups = identityService.createGroupQuery().list();
    mav.addObject("groups", groups);

    // 读取子任务
    List<HistoricTaskInstance> subTasks = historyService.createHistoricTaskInstanceQuery().taskParentTaskId(taskId).list();
    mav.addObject("subTasks", subTasks);

    // 读取上级任务
    if (task != null && task.getParentTaskId() != null) {
        HistoricTaskInstance parentTask = historyService.createHistoricTaskInstanceQuery().taskId(task.getParentTaskId()).singleResult();
        mav.addObject("parentTask", parentTask);
    }

    // 读取附件
    List<Attachment> attachments = null;
    if (task.getTaskDefinitionKey() != null) {
        attachments = taskService.getTaskAttachments(taskId);
    } else {
        attachments = taskService.getProcessInstanceAttachments(task.getProcessInstanceId());
    }
    mav.addObject("attachments", attachments);

    return mav;
}
 
Example 18
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 读取用户任务的表单字段
 */
@RequestMapping(value = "task/getform/{taskId}")
public ModelAndView readTaskForm(@PathVariable("taskId") String taskId) throws Exception {
    String viewName = "chapter6/task-form";
    ModelAndView mav = new ModelAndView(viewName);
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    Task task = null;

    // 外置表单
    if (taskFormData != null && taskFormData.getFormKey() != null) {
        Object renderedTaskForm = formService.getRenderedTaskForm(taskId);
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("taskFormData", renderedTaskForm);
        mav.addObject("hasFormKey", true);
    } else if (taskFormData != null) { // 动态表单
        mav.addObject("taskFormData", taskFormData);
        task = taskFormData.getTask();
    } else { // 手动创建的任务(包括子任务)
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("manualTask", true);
    }
    mav.addObject("task", task);

    // 读取任务参与人列表
    List<IdentityLink> identityLinksForTask = taskService.getIdentityLinksForTask(taskId);
    mav.addObject("identityLinksForTask", identityLinksForTask);

    // 读取所有人员
    List<User> users = identityService.createUserQuery().list();
    mav.addObject("users", users);

    // 读取所有组
    List<Group> groups = identityService.createGroupQuery().list();
    mav.addObject("groups", groups);

    // 读取子任务
    List<HistoricTaskInstance> subTasks = historyService.createHistoricTaskInstanceQuery().taskParentTaskId(taskId).list();
    mav.addObject("subTasks", subTasks);

    // 读取上级任务
    if (task != null && task.getParentTaskId() != null) {
        HistoricTaskInstance parentTask = historyService.createHistoricTaskInstanceQuery().taskId(task.getParentTaskId()).singleResult();
        mav.addObject("parentTask", parentTask);
    }

    // 读取附件
    List<Attachment> attachments = null;
    if (task.getTaskDefinitionKey() != null) {
        attachments = taskService.getTaskAttachments(taskId);
    } else {
        attachments = taskService.getProcessInstanceAttachments(task.getProcessInstanceId());
    }
    mav.addObject("attachments", attachments);

    return mav;
}
 
Example 19
Source File: BpmTaskServiceImpl.java    From hsweb-framework with Apache License 2.0 4 votes vote down vote up
@SneakyThrows
public void doJumpTask(Task task, String activityId, Consumer<Task> newTaskConsumer) {

    ProcessDefinitionEntity entity = (ProcessDefinitionEntity)
            ((RepositoryServiceImpl) repositoryService)
                    .getDeployedProcessDefinition(task.getProcessDefinitionId());

    String sourceId = task.getTaskDefinitionKey();

    ActivityImpl targetActivity = entity.findActivity(activityId);
    ActivityImpl sourceActivity = entity.findActivity(sourceId);

    if (logger.isDebugEnabled()) {
        logger.debug("流程[{}({})]跳转[{}]->[{}]",
                entity.getName(),
                entity.getId(),
                sourceActivity.getId(),
                targetActivity.getId());
    }

    //回退的节点
    List<PvmActivity> backActivities = new ArrayList<>();
    //如果目标节点的Outgoing中有源节点,说明是回退需要删除对应的连线
    findActivity(targetActivity,
            activity -> activity
                    .getOutgoingTransitions()
                    .stream()
                    .map(PvmTransition::getDestination)
                    .collect(Collectors.toList()),
            activity -> sourceActivity.getId().equals(activity.getId()),
            backActivities::add);

    //回退
    if (!backActivities.isEmpty()) {
        for (PvmActivity pvmTransition : backActivities) {
            if (logger.isDebugEnabled()) {
                logger.debug("流程[{}({})]回退[{}]->[{}],删除链接线:{}",
                        entity.getName(),
                        entity.getId(),
                        sourceActivity.getId(),
                        targetActivity.getId(),
                        pvmTransition.getId());
            }
            //删除连线
            List<HistoricActivityInstance> instance = historyService
                    .createHistoricActivityInstanceQuery()
                    .processInstanceId(task.getProcessInstanceId())
                    .activityId(pvmTransition.getId())
                    .list();
            for (HistoricActivityInstance historicActivityInstance : instance) {
                sqlExecutor.delete("delete from act_hi_actinst where id_= #{id}", historicActivityInstance);
            }
        }
    }
    //执行回退命令
    TaskServiceImpl taskServiceImpl = (TaskServiceImpl) taskService;
    taskServiceImpl.getCommandExecutor().execute(new JumpTaskCmd(task.getExecutionId(), activityId));
    //设置候选人并回调
    selectNowTask(task.getProcessInstanceId())
            .forEach(t -> {
                //设置候选人
                setCandidate(task.getAssignee(), t);
                newTaskConsumer.accept(t);
            });

}
 
Example 20
Source File: HistoricTaskInstanceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment
public void testHistoricTaskInstance() throws Exception {
  Map<String, Object> varMap = new HashMap<String, Object>();
  varMap.put("formKeyVar", "expressionFormKey");
  String processInstanceId = runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest", varMap).getId();
  
  SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
  
  // Set priority to non-default value
  Task runtimeTask = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
  runtimeTask.setPriority(1234);
  
  // Set due-date
  Date dueDate = sdf.parse("01/02/2003 04:05:06");
  runtimeTask.setDueDate(dueDate);
  taskService.saveTask(runtimeTask);
  
  String taskId = runtimeTask.getId();
  String taskDefinitionKey = runtimeTask.getTaskDefinitionKey();
  
  assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());
  HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
  assertEquals(taskId, historicTaskInstance.getId());
  assertEquals(1234, historicTaskInstance.getPriority());
  assertEquals("Clean up", historicTaskInstance.getName());
  assertEquals("Schedule an engineering meeting for next week with the new hire.", historicTaskInstance.getDescription());
  assertEquals(dueDate, historicTaskInstance.getDueDate());
  assertEquals("kermit", historicTaskInstance.getAssignee());
  assertEquals(taskDefinitionKey, historicTaskInstance.getTaskDefinitionKey());
  assertEquals("expressionFormKey", historicTaskInstance.getFormKey());
  assertNull(historicTaskInstance.getEndTime());
  assertNull(historicTaskInstance.getDurationInMillis());
  assertNull(historicTaskInstance.getWorkTimeInMillis());
  
  runtimeService.setVariable(processInstanceId, "deadline", "yesterday");
  
  taskService.claim(taskId, "kermit");
  
  assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());
  historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
  assertNotNull(historicTaskInstance.getClaimTime());
  assertNull(historicTaskInstance.getWorkTimeInMillis());
  assertEquals("expressionFormKey", historicTaskInstance.getFormKey());
  
  taskService.complete(taskId);
  
  assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());

  historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
  assertEquals(taskId, historicTaskInstance.getId());
  assertEquals(1234, historicTaskInstance.getPriority());
  assertEquals("Clean up", historicTaskInstance.getName());
  assertEquals("Schedule an engineering meeting for next week with the new hire.", historicTaskInstance.getDescription());
  assertEquals(dueDate, historicTaskInstance.getDueDate());
  assertEquals("kermit", historicTaskInstance.getAssignee());
  assertEquals(taskDefinitionKey, historicTaskInstance.getTaskDefinitionKey());
  assertEquals("expressionFormKey", historicTaskInstance.getFormKey());
  assertNotNull(historicTaskInstance.getEndTime());
  assertNotNull(historicTaskInstance.getDurationInMillis());
  assertNotNull(historicTaskInstance.getClaimTime());
  assertNotNull(historicTaskInstance.getWorkTimeInMillis());
  
  historyService.deleteHistoricTaskInstance(taskId);

  assertEquals(0, historyService.createHistoricTaskInstanceQuery().count());
}