如何将任务分配给组?

How to assign a task to a group?

如何在activiti中将任务分配给用户组。对于单个用户,可以使用以下代码完成。

taskService.setAssignee(taskId, userId);

但是我们如何将单个任务分配给一个组,该组可以由属于该组的任何用户选择。

使用TaskService:

      /**
   * Convenience shorthand for {@link #addGroupIdentityLink(String, String, String)}; with type {@link IdentityLinkType#CANDIDATE}
   * 
   * @param taskId
   *          id of the task, cannot be null.
   * @param groupId
   *          id of the group to use as candidate, cannot be null.
   * @throws ActivitiObjectNotFoundException
   *           when the task or group doesn't exist.
   */
  void addCandidateGroup(String taskId, String groupId);

添加候选组时,可以通过以下方式获取任务:

  taskService.addCandidateGroup(task.getId(), "sales");
  assertNotNull(taskService.createTaskQuery().taskCandidateGroup("sales").singleResult());

有关更多信息,请查看 activiti 源中的 org.activiti.engine.test.api.task.TaskServiceTest#testDeleteTaskIdentityLink