org.activiti.engine.task.IdentityLink Java Examples

The following examples show how to use org.activiti.engine.task.IdentityLink. 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: TaskIdentityLinksTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources="org/activiti5/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testCustomTypeUserLink() {
  runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
  
  String taskId = taskService
    .createTaskQuery()
    .singleResult()
    .getId();
  
  taskService.addUserIdentityLink(taskId, "kermit", "interestee");
  
  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  IdentityLink identityLink = identityLinks.get(0);
  
  assertNull(identityLink.getGroupId());
  assertEquals("kermit", identityLink.getUserId());
  assertEquals("interestee", identityLink.getType());
  assertEquals(taskId, identityLink.getTaskId());
  
  assertEquals(1, identityLinks.size());

  taskService.deleteUserIdentityLink(taskId, "kermit", "interestee");
  
  assertEquals(0, taskService.getIdentityLinksForTask(taskId).size());
}
 
Example #2
Source File: TaskIdentityLinksTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources="org/activiti5/engine/test/api/task/TaskIdentityLinksTest.testDeleteCandidateUser.bpmn20.xml")
public void testDeleteCandidateUser() {
  runtimeService.startProcessInstanceByKey("TaskIdentityLinks");

  String taskId = taskService
    .createTaskQuery()
    .singleResult()
    .getId();

  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);

  assertEquals(1, identityLinks.size());
  IdentityLink identityLink = identityLinks.get(0);

  assertEquals("user", identityLink.getUserId());
}
 
Example #3
Source File: HumanTaskEventListener.java    From lemon with Apache License 2.0 6 votes vote down vote up
public HumanTaskDTO createHumanTask(DelegateTask delegateTask)
        throws Exception {
    HumanTaskDTO humanTaskDto = new HumanTaskBuilder()
            .setDelegateTask(delegateTask)
            .setVote(this.isVote(delegateTask)).build();

    humanTaskDto = humanTaskConnector.saveHumanTask(humanTaskDto);
    logger.debug("candidates : {}", delegateTask.getCandidates());

    for (IdentityLink identityLink : delegateTask.getCandidates()) {
        String type = identityLink.getType();
        ParticipantDTO participantDto = new ParticipantDTO();
        participantDto.setType(type);
        participantDto.setHumanTaskId(humanTaskDto.getId());

        if ("user".equals(type)) {
            participantDto.setCode(identityLink.getUserId());
        } else {
            participantDto.setCode(identityLink.getGroupId());
        }

        humanTaskConnector.saveParticipant(participantDto);
    }

    return humanTaskDto;
}
 
Example #4
Source File: ActivitiPropertyConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public List<NodeRef> getPooledActorsReference(Collection<IdentityLink> links) 
{
     List<NodeRef> pooledActorRefs = new ArrayList<NodeRef>();
     if(links != null)
     {
         for(IdentityLink link : links)
         {
             if(IdentityLinkType.CANDIDATE.equals(link.getType()))
             {
                 String id = link.getGroupId();
                 if(id == null)
                 {
                     id = link.getUserId();
                 }
                 NodeRef pooledNodeRef = authorityManager.mapNameToAuthority(id);
                 if (pooledNodeRef != null)
                 {
                     pooledActorRefs.add(pooledNodeRef);
                 }
             }
         }
     }
     return pooledActorRefs;
}
 
Example #5
Source File: TaskIdentityLinksTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/activiti5/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testEmptyCandidateUserLink() {
  runtimeService.startProcessInstanceByKey("IdentityLinksProcess");

  String taskId = taskService
      .createTaskQuery()
      .singleResult()
      .getId();

  taskService.addCandidateGroup(taskId, "muppets");
  taskService.deleteCandidateUser(taskId, "kermit");

  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  assertNotNull(identityLinks);
  assertEquals( 1, identityLinks.size());

  IdentityLink identityLink = identityLinks.get(0);
  assertEquals("muppets", identityLink.getGroupId());
  assertEquals(null, identityLink.getUserId());
  assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
  assertEquals(taskId, identityLink.getTaskId());

  taskService.deleteCandidateGroup(taskId, "muppets");

  assertEquals(0, taskService.getIdentityLinksForTask(taskId).size());
}
 
Example #6
Source File: DeploymentController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 读取流程定义的相关候选启动人、组,根据link信息转换并封装为User、Group对象
 * @param processDefinitionList
 * @return
 */
private Map<String, Map<String, List<? extends Object>>> setCandidateUserAndGroups(List<ProcessDefinition> processDefinitionList) {
    Map<String, Map<String, List<? extends Object>>> linksMap = new HashMap<String, Map<String, List<? extends Object>>>();
    for (ProcessDefinition processDefinition : processDefinitionList) {
        List<IdentityLink> identityLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());

        Map<String, List<? extends Object>> single = new Hashtable<String, List<? extends Object>>();
        List<User> linkUsers = new ArrayList<User>();
        List<Group> linkGroups = new ArrayList<Group>();

        for (IdentityLink link : identityLinks) {
            if (StringUtils.isNotBlank(link.getUserId())) {
                linkUsers.add(identityService.createUserQuery().userId(link.getUserId()).singleResult());
            } else if (StringUtils.isNotBlank(link.getGroupId())) {
                linkGroups.add(identityService.createGroupQuery().groupId(link.getGroupId()).singleResult());
            }
        }

        single.put("user", linkUsers);
        single.put("group", linkGroups);

        linksMap.put(processDefinition.getId(), single);

    }
    return linksMap;
}
 
Example #7
Source File: TaskIdentityLinksTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testCustomIdentityLink() {
  runtimeService.startProcessInstanceByKey("customIdentityLink");

  List<Task> tasks = taskService.createTaskQuery().taskInvolvedUser("kermit").list();
  assertEquals(1, tasks.size());

  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(tasks.get(0).getId());
  assertEquals(2, identityLinks.size());
  
  for (IdentityLink idLink : identityLinks) {
    assertEquals("businessAdministrator", idLink.getType());
    String userId = idLink.getUserId();
    if (userId == null) {
      assertEquals("management", idLink.getGroupId());
    } else {
      assertEquals("kermit", userId);
    }
  }
}
 
Example #8
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testGetIdentityLinksWithCandidateUser() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  String taskId = task.getId();

  identityService.saveUser(identityService.newUser("kermit"));

  taskService.addCandidateUser(taskId, "kermit");
  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  assertEquals(1, identityLinks.size());
  assertEquals("kermit", identityLinks.get(0).getUserId());
  assertNull(identityLinks.get(0).getGroupId());
  assertEquals(IdentityLinkType.CANDIDATE, identityLinks.get(0).getType());

  // cleanup
  taskService.deleteTask(taskId, true);
  identityService.deleteUser("kermit");
}
 
Example #9
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testGetIdentityLinksWithCandidateGroup() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  String taskId = task.getId();

  identityService.saveGroup(identityService.newGroup("muppets"));

  taskService.addCandidateGroup(taskId, "muppets");
  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  assertEquals(1, identityLinks.size());
  assertEquals("muppets", identityLinks.get(0).getGroupId());
  assertNull(identityLinks.get(0).getUserId());
  assertEquals(IdentityLinkType.CANDIDATE, identityLinks.get(0).getType());

  // cleanup
  taskService.deleteTask(taskId, true);
  identityService.deleteGroup("muppets");
}
 
Example #10
Source File: TaskDelagationAssignmentHandler.java    From openwebflow with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void retrieveCandidateUserIdsAndGroupIds(TaskEntity task, Map<String, Object> userIdMap,
		Map<String, Object> groupIdMap)
{
	for (IdentityLink link : task.getCandidates())
	{
		String userId = link.getUserId();
		if (userId != null)
		{
			userIdMap.put(userId, 0);
		}

		String groupId = link.getGroupId();
		if (groupId != null)
		{
			groupIdMap.put(groupId, 0);
		}
	}
}
 
Example #11
Source File: TaskIdentityLinksTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources="org/activiti5/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testCustomLinkGroupLink() {
  runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
  
  String taskId = taskService
    .createTaskQuery()
    .singleResult()
    .getId();
  
  taskService.addGroupIdentityLink(taskId, "muppets", "playing");
  
  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  IdentityLink identityLink = identityLinks.get(0);
  
  assertEquals("muppets", identityLink.getGroupId());
  assertNull("kermit", identityLink.getUserId());
  assertEquals("playing", identityLink.getType());
  assertEquals(taskId, identityLink.getTaskId());
  
  assertEquals(1, identityLinks.size());

  taskService.deleteGroupIdentityLink(taskId, "muppets", "playing");
  
  assertEquals(0, taskService.getIdentityLinksForTask(taskId).size());
}
 
Example #12
Source File: TaskIdentityLinksTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/activiti/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testEmptyCandidateUserLink() {
  runtimeService.startProcessInstanceByKey("IdentityLinksProcess");

  String taskId = taskService.createTaskQuery().singleResult().getId();

  taskService.addCandidateGroup(taskId, "muppets");
  taskService.deleteCandidateUser(taskId, "kermit");

  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  assertNotNull(identityLinks);
  assertEquals(1, identityLinks.size());

  IdentityLink identityLink = identityLinks.get(0);
  assertEquals("muppets", identityLink.getGroupId());
  assertEquals(null, identityLink.getUserId());
  assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
  assertEquals(taskId, identityLink.getTaskId());

  taskService.deleteCandidateGroup(taskId, "muppets");

  assertEquals(0, taskService.getIdentityLinksForTask(taskId).size());
}
 
Example #13
Source File: ProcessManagerController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 读取已设置的候选启动人、组
 * @param processDefinitionId
 * @return
 */
@RequestMapping(value = "startable/read/{processDefinitionId}", method = RequestMethod.GET)
@ResponseBody
public Map<String, List<String>> readStartableData(@PathVariable("processDefinitionId") String processDefinitionId) {
    Map<String, List<String>> datas = new HashMap<String, List<String>>();
    ArrayList<String> users = new ArrayList<String>();
    ArrayList<String> groups = new ArrayList<String>();

    List<IdentityLink> links = repositoryService.getIdentityLinksForProcessDefinition(processDefinitionId);
    for (IdentityLink link : links) {
        if (StringUtils.isNotBlank(link.getUserId())) {
            users.add(link.getUserId());
        }
        if (StringUtils.isNotBlank(link.getGroupId())) {
            groups.add(link.getGroupId());
        }
    }
    datas.put("users", users);
    datas.put("groups", groups);
    return datas;
}
 
Example #14
Source File: ProcessManagerController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 读取已设置的候选启动人、组
 * @param processDefinitionId
 * @return
 */
@RequestMapping(value = "startable/read/{processDefinitionId}", method = RequestMethod.GET)
@ResponseBody
public Map<String, List<String>> readStartableData(@PathVariable("processDefinitionId") String processDefinitionId) {
    Map<String, List<String>> datas = new HashMap<String, List<String>>();
    ArrayList<String> users = new ArrayList<String>();
    ArrayList<String> groups = new ArrayList<String>();

    List<IdentityLink> links = repositoryService.getIdentityLinksForProcessDefinition(processDefinitionId);
    for (IdentityLink link : links) {
        if (StringUtils.isNotBlank(link.getUserId())) {
            users.add(link.getUserId());
        }
        if (StringUtils.isNotBlank(link.getGroupId())) {
            groups.add(link.getGroupId());
        }
    }
    datas.put("users", users);
    datas.put("groups", groups);
    return datas;
}
 
Example #15
Source File: ProcessDefinitionIdentityLinkResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Delete a candidate starter from a process definition", tags = {"Process Definitions"})
@ApiResponses(value = {
    @ApiResponse(code = 204, message = "Indicates the process definition was found and the identity link was removed. The response body is intentionally empty."),
    @ApiResponse(code = 404, message = "Indicates the requested process definition was not found or the process definition doesn’t have an identity-link that matches the url.")
})
@RequestMapping(value = "/repository/process-definitions/{processDefinitionId}/identitylinks/{family}/{identityId}", method = RequestMethod.DELETE)
public void deleteIdentityLink(@ApiParam(name = "processDefinitionId", value="The id of the process definition.")  @PathVariable("processDefinitionId") String processDefinitionId,@ApiParam(name = "family", value="Either users or groups, depending on the type of identity link.") @PathVariable("family") String family,@ApiParam(name = "identityId", value="Either the user or group of the identity to remove as candidate starter.") @PathVariable("identityId") String identityId,
    HttpServletResponse response) {

  ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);

  validateIdentityLinkArguments(family, identityId);

  // Check if identitylink to delete exists
  IdentityLink link = getIdentityLink(family, identityId, processDefinition.getId());
  if (link.getUserId() != null) {
    repositoryService.deleteCandidateStarterUser(processDefinition.getId(), link.getUserId());
  } else {
    repositoryService.deleteCandidateStarterGroup(processDefinition.getId(), link.getGroupId());
  }

  response.setStatus(HttpStatus.NO_CONTENT.value());
}
 
Example #16
Source File: ProcessDefinitionIdentityLinkResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected IdentityLink getIdentityLink(String family, String identityId, String processDefinitionId) {
  boolean isUser = family.equals(RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS);

  // Perhaps it would be better to offer getting a single identitylink
  // from
  // the API
  List<IdentityLink> allLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinitionId);
  for (IdentityLink link : allLinks) {
    boolean rightIdentity = false;
    if (isUser) {
      rightIdentity = identityId.equals(link.getUserId());
    } else {
      rightIdentity = identityId.equals(link.getGroupId());
    }

    if (rightIdentity && link.getType().equals(IdentityLinkType.CANDIDATE)) {
      return link;
    }
  }
  throw new ActivitiObjectNotFoundException("Could not find the requested identity link.", IdentityLink.class);
}
 
Example #17
Source File: ProcessInstanceIdentityLinkResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get a specific involved people from process instance", tags = { "Process Instances" }, nickname = "getProcessInstanceIdentityLinks")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the process instance was found and the specified link is retrieved."),
    @ApiResponse(code = 404, message = "Indicates the requested process instance was not found or the link to delete doesn’t exist. The response status contains additional information about the error.")
})
@RequestMapping(value = "/runtime/process-instances/{processInstanceId}/identitylinks/users/{identityId}/{type}", method = RequestMethod.GET, produces = "application/json")
public RestIdentityLink getIdentityLink(@ApiParam(name = "processInstanceId",  value="The id of the process instance to get.") @PathVariable("processInstanceId") String processInstanceId,@ApiParam(name = "identityId") @PathVariable("identityId") String identityId,@ApiParam(name = "type") @PathVariable("type") String type,
    HttpServletRequest request) {

  ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);

  validateIdentityLinkArguments(identityId, type);

  IdentityLink link = getIdentityLink(identityId, type, processInstance.getId());
  return restResponseFactory.createRestIdentityLink(link);
}
 
Example #18
Source File: TaskIdentityLinkResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get a single identity link on a task", tags = {"Tasks"}, nickname = "getTaskInstanceIdentityLinks")
@ApiResponses(value = {
    @ApiResponse(code = 200, message =  "Indicates the task and identity link was found and returned."),
    @ApiResponse(code = 404, message = "Indicates the requested task was not found or the task doesn’t have the requested identityLink. The status contains additional information about this error.")
})
@RequestMapping(value = "/runtime/tasks/{taskId}/identitylinks/{family}/{identityId}/{type}", method = RequestMethod.GET, produces = "application/json")
public RestIdentityLink getIdentityLink(@ApiParam(name="taskId", value="The id of the task .") @PathVariable("taskId") String taskId,@ApiParam(name="family", value="Either groups or users, depending on what kind of identity is targeted.") @PathVariable("family") String family,@ApiParam(name="identityId", value="The id of the identity.") @PathVariable("identityId") String identityId,
    @ApiParam(name="type", value="The type of identity link.") @PathVariable("type") String type, HttpServletRequest request) {

  Task task = getTaskFromRequest(taskId);
  validateIdentityLinkArguments(family, identityId, type);

  IdentityLink link = getIdentityLink(family, identityId, type, task.getId());

  return restResponseFactory.createRestIdentityLink(link);
}
 
Example #19
Source File: TaskIdentityLinkResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected IdentityLink getIdentityLink(String family, String identityId, String type, String taskId) {
  boolean isUser = family.equals(RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS);

  // Perhaps it would be better to offer getting a single identitylink
  // from the API
  List<IdentityLink> allLinks = taskService.getIdentityLinksForTask(taskId);
  for (IdentityLink link : allLinks) {
    boolean rightIdentity = false;
    if (isUser) {
      rightIdentity = identityId.equals(link.getUserId());
    } else {
      rightIdentity = identityId.equals(link.getGroupId());
    }

    if (rightIdentity && link.getType().equals(type)) {
      return link;
    }
  }
  throw new ActivitiObjectNotFoundException("Could not find the requested identity link.", IdentityLink.class);
}
 
Example #20
Source File: DeploymentController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 读取流程定义的相关候选启动人、组,根据link信息转换并封装为User、Group对象
 * @param processDefinitionList
 * @return
 */
private Map<String, Map<String, List<? extends Object>>> setCandidateUserAndGroups(List<ProcessDefinition> processDefinitionList) {
    Map<String, Map<String, List<? extends Object>>> linksMap = new HashMap<String, Map<String, List<? extends Object>>>();
    for (ProcessDefinition processDefinition : processDefinitionList) {
        List<IdentityLink> identityLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());

        Map<String, List<? extends Object>> single = new Hashtable<String, List<? extends Object>>();
        List<User> linkUsers = new ArrayList<User>();
        List<Group> linkGroups = new ArrayList<Group>();

        for (IdentityLink link : identityLinks) {
            if (StringUtils.isNotBlank(link.getUserId())) {
                linkUsers.add(identityService.createUserQuery().userId(link.getUserId()).singleResult());
            } else if (StringUtils.isNotBlank(link.getGroupId())) {
                linkGroups.add(identityService.createGroupQuery().groupId(link.getGroupId()).singleResult());
            }
        }

        single.put("user", linkUsers);
        single.put("group", linkGroups);

        linksMap.put(processDefinition.getId(), single);

    }
    return linksMap;
}
 
Example #21
Source File: ProcessInstanceIdentityLinksTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources="org/activiti5/engine/test/api/runtime/IdentityLinksProcess.bpmn20.xml")
public void testCustomTypeUserLink() {
  Authentication.setAuthenticatedUserId(null);
  runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
  
  String processInstanceId = runtimeService
    .createProcessInstanceQuery()
    .singleResult()
    .getId();
  
  runtimeService.addUserIdentityLink(processInstanceId, "kermit", "interestee");
  
  List<IdentityLink> identityLinks = runtimeService.getIdentityLinksForProcessInstance(processInstanceId);
  IdentityLink identityLink = identityLinks.get(0);
  
  assertNull(identityLink.getGroupId());
  assertEquals("kermit", identityLink.getUserId());
  assertEquals("interestee", identityLink.getType());
  assertEquals(processInstanceId, identityLink.getProcessInstanceId());
  
  assertEquals(1, identityLinks.size());

  runtimeService.deleteUserIdentityLink(processInstanceId, "kermit", "interestee");
  
  assertEquals(0, runtimeService.getIdentityLinksForProcessInstance(processInstanceId).size());
}
 
Example #22
Source File: ProcessInstanceIdentityLinksTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources="org/activiti5/engine/test/api/runtime/IdentityLinksProcess.bpmn20.xml")
public void testCustomLinkGroupLink() {
  Authentication.setAuthenticatedUserId(null);
  runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
  
  String processInstanceId = runtimeService
    .createProcessInstanceQuery()
    .singleResult()
    .getId();
  
  runtimeService.addGroupIdentityLink(processInstanceId, "muppets", "playing");
  
  List<IdentityLink> identityLinks = runtimeService.getIdentityLinksForProcessInstance(processInstanceId);
  IdentityLink identityLink = identityLinks.get(0);
  
  assertEquals("muppets", identityLink.getGroupId());
  assertNull("kermit", identityLink.getUserId());
  assertEquals("playing", identityLink.getType());
  assertEquals(processInstanceId, identityLink.getProcessInstanceId());
  
  assertEquals(1, identityLinks.size());

  runtimeService.deleteGroupIdentityLink(processInstanceId, "muppets", "playing");
  
  assertEquals(0, runtimeService.getIdentityLinksForProcessInstance(processInstanceId).size());
}
 
Example #23
Source File: ProcessManagerController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 读取已设置的候选启动人、组
 * @param processDefinitionId
 * @return
 */
@RequestMapping(value = "startable/read/{processDefinitionId}", method = RequestMethod.GET)
@ResponseBody
public Map<String, List<String>> readStartableData(@PathVariable("processDefinitionId") String processDefinitionId) {
    Map<String, List<String>> datas = new HashMap<String, List<String>>();
    ArrayList<String> users = new ArrayList<String>();
    ArrayList<String> groups = new ArrayList<String>();

    List<IdentityLink> links = repositoryService.getIdentityLinksForProcessDefinition(processDefinitionId);
    for (IdentityLink link : links) {
        if (StringUtils.isNotBlank(link.getUserId())) {
            users.add(link.getUserId());
        }
        if (StringUtils.isNotBlank(link.getGroupId())) {
            groups.add(link.getGroupId());
        }
    }
    datas.put("users", users);
    datas.put("groups", groups);
    return datas;
}
 
Example #24
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 反签收任务
 */
@RequestMapping(value = "task/unclaim/{id}")
public String unclaim(@PathVariable("id") String taskId, HttpSession session, RedirectAttributes redirectAttributes) {
    // 反签收条件过滤
    List<IdentityLink> links = taskService.getIdentityLinksForTask(taskId);
    for (IdentityLink identityLink : links) {
        // 如果一个任务有相关的候选人、组就可以反签收
        if (StringUtils.equals(IdentityLinkType.CANDIDATE, identityLink.getType())) {
            taskService.claim(taskId, null);
            redirectAttributes.addFlashAttribute("message", "任务已反签收");
            return TASK_LIST;
        }
    }
    redirectAttributes.addFlashAttribute("error", "该任务不允许反签收!");
    return TASK_LIST;
}
 
Example #25
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testGetIdentityLinksWithCandidateGroup() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  String taskId = task.getId();
  
  identityService.saveGroup(identityService.newGroup("muppets"));
  
  taskService.addCandidateGroup(taskId, "muppets");
  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  assertEquals(1, identityLinks.size());
  assertEquals("muppets", identityLinks.get(0).getGroupId());
  assertNull(identityLinks.get(0).getUserId());
  assertEquals(IdentityLinkType.CANDIDATE, identityLinks.get(0).getType());
  
  //cleanup
  taskService.deleteTask(taskId, true);
  identityService.deleteGroup("muppets");
}
 
Example #26
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testGetIdentityLinksWithAssignee() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  String taskId = task.getId();
  
  identityService.saveUser(identityService.newUser("kermit"));
  
  taskService.claim(taskId, "kermit");
  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  assertEquals(1, identityLinks.size());
  assertEquals("kermit", identityLinks.get(0).getUserId());
  assertNull(identityLinks.get(0).getGroupId());
  assertEquals(IdentityLinkType.ASSIGNEE, identityLinks.get(0).getType());
  
  //cleanup
  taskService.deleteTask(taskId, true);
  identityService.deleteUser("kermit");
}
 
Example #27
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testGetIdentityLinksWithNonExistingOwner() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  String taskId = task.getId();
  
  taskService.claim(taskId, "nonExistingOwner");
  taskService.delegateTask(taskId, "nonExistingAssignee");
  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  assertEquals(2, identityLinks.size());

  IdentityLink assignee = identityLinks.get(0);
  assertEquals("nonExistingAssignee", assignee.getUserId());
  assertNull(assignee.getGroupId());
  assertEquals(IdentityLinkType.ASSIGNEE, assignee.getType());
  
  IdentityLink owner = identityLinks.get(1);
  assertEquals("nonExistingOwner", owner.getUserId());
  assertNull(owner.getGroupId());
  assertEquals(IdentityLinkType.OWNER, owner.getType());

  //cleanup
  taskService.deleteTask(taskId, true);
}
 
Example #28
Source File: TaskIdentityLinksTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources="org/activiti5/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testCandidateUserLink() {
  runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
  
  String taskId = taskService
    .createTaskQuery()
    .singleResult()
    .getId();
  
  taskService.addCandidateUser(taskId, "kermit");
  
  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  IdentityLink identityLink = identityLinks.get(0);
  
  assertNull(identityLink.getGroupId());
  assertEquals("kermit", identityLink.getUserId());
  assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
  assertEquals(taskId, identityLink.getTaskId());
  
  assertEquals(1, identityLinks.size());

  taskService.deleteCandidateUser(taskId, "kermit");
  
  assertEquals(0, taskService.getIdentityLinksForTask(taskId).size());
}
 
Example #29
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testGetIdentityLinksWithNonExistingOwner() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  String taskId = task.getId();

  taskService.claim(taskId, "nonExistingOwner");
  taskService.delegateTask(taskId, "nonExistingAssignee");
  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  assertEquals(2, identityLinks.size());

  IdentityLink assignee = identityLinks.get(0);
  assertEquals("nonExistingAssignee", assignee.getUserId());
  assertNull(assignee.getGroupId());
  assertEquals(IdentityLinkType.ASSIGNEE, assignee.getType());

  IdentityLink owner = identityLinks.get(1);
  assertEquals("nonExistingOwner", owner.getUserId());
  assertNull(owner.getGroupId());
  assertEquals(IdentityLinkType.OWNER, owner.getType());

  // cleanup
  taskService.deleteTask(taskId, true);
}
 
Example #30
Source File: ProcessExtensionServiceImpl.java    From activiti-demo with Apache License 2.0 5 votes vote down vote up
/**
 *  查询某个用户ID是否在某个Activity里面拥有权限
 * @param taskId    任务ID
 * @param userId    用户ID
 * @return
 */
public boolean isPermissionInActivity(String taskId,String userId){

    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);

    for(IdentityLink identityLink : identityLinks){

        //查询
        if("candidate".equals(identityLink.getType())){
            if(null==identityLink.getGroupId()){
                if(identityLink.getUserId().equals(userId)){
                       return true;
                }
            }
            //如果该任务执行权限为组,则匹配指派人toSign的组是否一致
            else{
                List<Group> groupList =  identityService.createGroupQuery().groupMember(userId).list();
                for(Group g : groupList){
                    if(g.getId().equals(identityLink.getGroupId())){
                        return true;
                    }
                }
            }

        }
    }

      return false;
}