Java Code Examples for org.activiti.engine.task.IdentityLink#getGroupId()

The following examples show how to use org.activiti.engine.task.IdentityLink#getGroupId() . 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: 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 2
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 3
Source File: DelegateTaskTestTaskListener.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void notify(DelegateTask delegateTask) {
  Set<IdentityLink> candidates = delegateTask.getCandidates();
  Set<String> candidateUsers = new HashSet<String>();
  Set<String> candidateGroups = new HashSet<String>();
  for (IdentityLink candidate : candidates) {
    if (candidate.getUserId() != null) {
      candidateUsers.add(candidate.getUserId());
    } else if (candidate.getGroupId() != null) {
      candidateGroups.add(candidate.getGroupId());
    }
  }
  delegateTask.setVariable(VARNAME_CANDIDATE_USERS, candidateUsers);
  delegateTask.setVariable(VARNAME_CANDIDATE_GROUPS, candidateGroups);
}
 
Example 4
Source File: TaskIdentityLinkFamilyResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Get all identitylinks for a task for either groups or users", tags = {"Tasks"},
    notes="## Get all identitylinks for a task URL\n\n"
        + " ```\n GET runtime/tasks/{taskId}/identitylinks/users\n" + "GET runtime/tasks/{taskId}/identitylinks/groups  ```"
        + "\n\n\n"
        + "Returns only identity links targetting either users or groups. Response body and status-codes are exactly the same as when getting the full list of identity links for a task."
    )
@ApiResponses(value = {
    @ApiResponse(code = 200, message =  "Indicates the task was found and the requested identity links are returned."),
    @ApiResponse(code = 404, message = "Indicates the requested task was not found.")
})
@RequestMapping(value = "/runtime/tasks/{taskId}/identitylinks/{family}", method = RequestMethod.GET, produces = "application/json")
public List<RestIdentityLink> getIdentityLinksForFamily(@ApiParam(name="taskId") @PathVariable("taskId") String taskId,@ApiParam(name="family") @PathVariable("family") String family, HttpServletRequest request) {

  Task task = getTaskFromRequest(taskId);

  if (family == null || (!RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_GROUPS.equals(family) && !RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS.equals(family))) {
    throw new ActivitiIllegalArgumentException("Identity link family should be 'users' or 'groups'.");
  }

  boolean isUser = family.equals(RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS);
  List<RestIdentityLink> results = new ArrayList<RestIdentityLink>();

  List<IdentityLink> allLinks = taskService.getIdentityLinksForTask(task.getId());
  for (IdentityLink link : allLinks) {
    boolean match = false;
    if (isUser) {
      match = link.getUserId() != null;
    } else {
      match = link.getGroupId() != null;
    }

    if (match) {
      results.add(restResponseFactory.createRestIdentityLink(link));
    }
  }
  return results;
}
 
Example 5
Source File: DelegateTaskTestTaskListener.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void notify(DelegateTask delegateTask) {
  Set<IdentityLink> candidates = delegateTask.getCandidates();
  Set<String> candidateUsers = new HashSet<String>();
  Set<String> candidateGroups = new HashSet<String>();
  for (IdentityLink candidate : candidates) {
    if (candidate.getUserId() != null) {
      candidateUsers.add(candidate.getUserId());
    } else if (candidate.getGroupId() != null) {
      candidateGroups.add(candidate.getGroupId());
    }
  }
  delegateTask.setVariable(VARNAME_CANDIDATE_USERS, candidateUsers);
  delegateTask.setVariable(VARNAME_CANDIDATE_GROUPS, candidateGroups);
}
 
Example 6
Source File: TaskCandidate.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public TaskCandidate(IdentityLink identityLink)
{
    if (StringUtils.isNotEmpty(identityLink.getUserId())) {
        candidateId = identityLink.getUserId();
        candidateType = "user";
    } else {
        candidateId = identityLink.getGroupId();
        candidateType = "group";
    }
}
 
Example 7
Source File: IdentityUtils.java    From openwebflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static List<String> getInvolvedUsers(TaskService taskService, Task task,
		IdentityMembershipManager membershipManager) throws Exception
{
	Map<String, Object> userIds = new HashMap<String, Object>();
	String assignee = task.getAssignee();
	//如果直接指定了任务执行人,则忽略其他候选人
	if (assignee != null)
	{
		userIds.put(assignee, new Object());
	}
	else
	{
		for (IdentityLink link : taskService.getIdentityLinksForTask(task.getId()))
		{
			String userId = link.getUserId();
			if (userId != null)
			{
				userIds.put(userId, new Object());
			}

			String groupId = link.getGroupId();
			if (groupId != null)
			{
				for (String gUserId : membershipManager.findUserIdsByGroup(groupId))
				{
					userIds.put(gUserId, new Object());
				}
			}
		}
	}

	return new ArrayList<String>(userIds.keySet());
}
 
Example 8
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;
}
 
Example 9
Source File: ActivitiPooledActorsPropertyHandler.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Returns a DTO containing the users and groups to add and the links to remove.
 * 
 * @param value Serializable
 * @param links Collection<? extends IdentityLink>
 * @return UserAndGroupUpdates
 */
private UserAndGroupUpdates getUserAndGroupUpdates(Serializable value, Collection<? extends IdentityLink> links)
{
    Collection<NodeRef> actors = getNodes(value);

    List<String> users = new ArrayList<String>();
    List<String> groups = new ArrayList<String>();
    for (NodeRef actor : actors)
    {
        String authorityName = authorityManager.getAuthorityName(actor);
        List<String> pooledAuthorities = authorityManager.isUser(authorityName)? users : groups;
        pooledAuthorities.add(authorityName);
    }
    
    // Removes all users and groups that are already links.
    // Also records links that are not part of the new set of users and
    // groups, in order to delete them.
    List<IdentityLink> linksToRemove = new LinkedList<IdentityLink>();
    for (IdentityLink link : links)
    {
        if (IdentityLinkType.CANDIDATE.equals(link.getType())) 
        {
            String userId = link.getUserId();
            if (userId != null)
            {
                if (users.remove(userId)==false)
                {
                    linksToRemove.add(link);
                }
            }
            else 
            {
                String groupId = link.getGroupId();
                if (groupId != null && groups.remove(groupId) == false)
                {
                    linksToRemove.add(link);
                }
            }
        }
    }
    return new UserAndGroupUpdates(users, groups, linksToRemove);
}
 
Example 10
Source File: AutoCompleteFirstTaskListener.java    From lemon with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(DelegateTask delegateTask) throws Exception {
    String initiatorId = Authentication.getAuthenticatedUserId();

    if (initiatorId == null) {
        return;
    }

    String assignee = delegateTask.getAssignee();

    if (assignee == null) {
        return;
    }

    PvmActivity targetActivity = this.findFirstActivity(delegateTask
            .getProcessDefinitionId());

    if (!targetActivity.getId().equals(
            delegateTask.getExecution().getCurrentActivityId())) {
        return;
    }

    if (!initiatorId.equals(assignee)) {
        return;
    }

    logger.debug("auto complete first task : {}", delegateTask);

    for (IdentityLink identityLink : delegateTask.getCandidates()) {
        String userId = identityLink.getUserId();
        String groupId = identityLink.getGroupId();

        if (userId != null) {
            delegateTask.deleteCandidateUser(userId);
        }

        if (groupId != null) {
            delegateTask.deleteCandidateGroup(groupId);
        }
    }

    // 对提交流程的任务进行特殊处理
    HumanTaskDTO humanTaskDto = humanTaskConnector
            .findHumanTaskByTaskId(delegateTask.getId());
    humanTaskDto.setCatalog(HumanTaskConstants.CATALOG_START);
    humanTaskConnector.saveHumanTask(humanTaskDto);

    // ((TaskEntity) delegateTask).complete();
    // Context.getCommandContext().getHistoryManager().recordTaskId((TaskEntity) delegateTask);
    new CompleteTaskWithCommentCmd(delegateTask.getId(), null, "发起流程")
            .execute(Context.getCommandContext());
}
 
Example 11
Source File: AutoCompleteFirstTaskEventListener.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void onCreate(DelegateTask delegateTask) throws Exception {
    String initiatorId = Authentication.getAuthenticatedUserId();

    if (initiatorId == null) {
        return;
    }

    String assignee = delegateTask.getAssignee();

    if (assignee == null) {
        return;
    }

    if (!initiatorId.equals(assignee)) {
        return;
    }

    PvmActivity targetActivity = this.findFirstActivity(delegateTask
            .getProcessDefinitionId());
    logger.debug("targetActivity : {}", targetActivity);

    if (!targetActivity.getId().equals(
            delegateTask.getExecution().getCurrentActivityId())) {
        return;
    }

    logger.debug("auto complete first task : {}", delegateTask);

    for (IdentityLink identityLink : delegateTask.getCandidates()) {
        String userId = identityLink.getUserId();
        String groupId = identityLink.getGroupId();

        if (userId != null) {
            delegateTask.deleteCandidateUser(userId);
        }

        if (groupId != null) {
            delegateTask.deleteCandidateGroup(groupId);
        }
    }

    // 对提交流程的任务进行特殊处理
    HumanTaskDTO humanTaskDto = humanTaskConnector
            .findHumanTaskByTaskId(delegateTask.getId());
    humanTaskDto.setCatalog(HumanTaskConstants.CATALOG_START);
    humanTaskConnector.saveHumanTask(humanTaskDto);

    // ((TaskEntity) delegateTask).complete();
    // Context.getCommandContext().getHistoryManager().recordTaskId((TaskEntity) delegateTask);
    // Context.getCommandContext().getHistoryManager().recordTaskId((TaskEntity) delegateTask);
    // new CompleteTaskWithCommentCmd(delegateTask.getId(), null, "发起流程")
    // .execute(Context.getCommandContext());

    // 因为recordTaskId()会判断endTime,而complete以后会导致endTime!=null,
    // 所以才会出现record()放在complete后面导致taskId没记录到historyActivity里的情况
    delegateTask.getExecution().setVariableLocal(
            "_ACTIVITI_SKIP_EXPRESSION_ENABLED", true);

    TaskDefinition taskDefinition = ((TaskEntity) delegateTask)
            .getTaskDefinition();
    ExpressionManager expressionManager = Context
            .getProcessEngineConfiguration().getExpressionManager();
    Expression expression = expressionManager
            .createExpression("${_ACTIVITI_SKIP_EXPRESSION_ENABLED}");
    taskDefinition.setSkipExpression(expression);
}