Java Code Examples for org.activiti.engine.delegate.DelegateTask#getCandidates()

The following examples show how to use org.activiti.engine.delegate.DelegateTask#getCandidates() . 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: 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 2
Source File: HumanTaskTaskListener.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 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: 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 5
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 6
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);
}