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

The following examples show how to use org.activiti.engine.task.Task#getExecutionId() . 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: VariablesTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testGetVariablesWithCollectionThroughRuntimeService() {
	
	Map<String, Object> vars = runtimeService.getVariables(processInstanceId, Arrays.asList("intVar1", "intVar3", "intVar5", "intVar9"));
	assertEquals(4, vars.size());
	assertEquals(100, vars.get("intVar1"));
	assertEquals(300, vars.get("intVar3"));
	assertEquals(500, vars.get("intVar5"));
	assertEquals(900, vars.get("intVar9"));
	
	assertEquals(4, runtimeService.getVariablesLocal(processInstanceId, Arrays.asList("intVar1", "intVar3", "intVar5", "intVar9")).size());
	
	// Trying the same after moving the process
	Task task = taskService.createTaskQuery().singleResult();
	taskService.complete(task.getId());

	task = taskService.createTaskQuery().taskName("Task 3").singleResult();
	String executionId = task.getExecutionId();
	assertFalse(processInstanceId.equals(executionId));

	
	assertEquals(0, runtimeService.getVariablesLocal(executionId, Arrays.asList("intVar1", "intVar3", "intVar5", "intVar9")).size());
	
}
 
Example 2
Source File: TaskVariableCollectionResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void addGlobalVariables(Task task, Map<String, RestVariable> variableMap) {
  if (task.getExecutionId() != null) {
    Map<String, Object> rawVariables = runtimeService.getVariables(task.getExecutionId());
    List<RestVariable> globalVariables = restResponseFactory.createRestVariables(rawVariables, task.getId(), RestResponseFactory.VARIABLE_TASK, RestVariableScope.GLOBAL);

    // Overlay global variables over local ones. In case they are
    // present the values are not overridden,
    // since local variables get precedence over global ones at all
    // times.
    for (RestVariable var : globalVariables) {
      if (!variableMap.containsKey(var.getName())) {
        variableMap.put(var.getName(), var);
      }
    }
  }
}
 
Example 3
Source File: TaskVariableBaseResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void setVariable(Task task, String name, Object value, RestVariableScope scope, boolean isNew) {
  // Create can only be done on new variables. Existing variables should
  // be updated using PUT
  boolean hasVariable = hasVariableOnScope(task, name, scope);
  if (isNew && hasVariable) {
    throw new ActivitiException("Variable '" + name + "' is already present on task '" + task.getId() + "'.");
  }

  if (!isNew && !hasVariable) {
    throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a variable with name: '" + name + "'.", null);
  }

  if (scope == RestVariableScope.LOCAL) {
    taskService.setVariableLocal(task.getId(), name, value);
  } else {
    if (task.getExecutionId() != null) {
      // Explicitly set on execution, setting non-local variable on
      // task will override local-variable if exists
      runtimeService.setVariable(task.getExecutionId(), name, value);
    } else {
      // Standalone task, no global variables possible
      throw new ActivitiIllegalArgumentException("Cannot set global variable '" + name + "' on task '" + task.getId() + "', task is not part of process.");
    }
  }
}
 
Example 4
Source File: VariablesTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testGetVariablesWithCollectionThroughRuntimeService() {

    Map<String, Object> vars = runtimeService.getVariables(processInstanceId, Arrays.asList("intVar1", "intVar3", "intVar5", "intVar9"));
    assertEquals(4, vars.size());
    assertEquals(100, vars.get("intVar1"));
    assertEquals(300, vars.get("intVar3"));
    assertEquals(500, vars.get("intVar5"));
    assertEquals(900, vars.get("intVar9"));

    assertEquals(4, runtimeService.getVariablesLocal(processInstanceId, Arrays.asList("intVar1", "intVar3", "intVar5", "intVar9")).size());

    // Trying the same after moving the process
    Task task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());

    task = taskService.createTaskQuery().taskName("Task 3").singleResult();
    String executionId = task.getExecutionId();
    assertFalse(processInstanceId.equals(executionId));

    assertEquals(0, runtimeService.getVariablesLocal(executionId, Arrays.asList("intVar1", "intVar3", "intVar5", "intVar9")).size());

  }
 
Example 5
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testQueryByInvolvedUser() {
  try {
    Task adhocTask = taskService.newTask();
    adhocTask.setAssignee("kermit");
    adhocTask.setOwner("fozzie");
    taskService.saveTask(adhocTask);
    taskService.addUserIdentityLink(adhocTask.getId(), "gonzo", "customType");

    assertEquals(3, taskService.getIdentityLinksForTask(adhocTask.getId()).size());

    assertEquals(1, taskService.createTaskQuery().taskId(adhocTask.getId()).taskInvolvedUser("gonzo").count());
    assertEquals(1, taskService.createTaskQuery().taskId(adhocTask.getId()).taskInvolvedUser("kermit").count());
    assertEquals(1, taskService.createTaskQuery().taskId(adhocTask.getId()).taskInvolvedUser("fozzie").count());

  } finally {
    List<Task> allTasks = taskService.createTaskQuery().list();
    for(Task task : allTasks) {
      if(task.getExecutionId() == null) {
        taskService.deleteTask(task.getId());
        if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
          historyService.deleteHistoricTaskInstance(task.getId());
        }
      }
    }
  }
}
 
Example 6
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testQueryByInvolvedGroup() {
  try {
    Task adhocTask = taskService.newTask();
    adhocTask.setAssignee("kermit");
    adhocTask.setOwner("fozzie");
    taskService.saveTask(adhocTask);
    taskService.addGroupIdentityLink(adhocTask.getId(), "group1", IdentityLinkType.PARTICIPANT);

    List<String> groups = new ArrayList<String>();
    groups.add("group1");

    assertEquals(3, taskService.getIdentityLinksForTask(adhocTask.getId()).size());
    assertEquals(1, taskService.createTaskQuery()
        .taskId(adhocTask.getId()).taskInvolvedGroupsIn(groups).count());
  } finally {
    List<Task> allTasks = taskService.createTaskQuery().list();
    for (Task task : allTasks) {
      if (task.getExecutionId() == null) {
        taskService.deleteTask(task.getId());
        if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
          historyService.deleteHistoricTaskInstance(task.getId());
        }
      }
    }
  }
}
 
Example 7
Source File: TaskResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Delete a task", tags = {"Tasks"})
@ApiResponses(value = {
    @ApiResponse(code = 204, message =  "Indicates the task was found and has been deleted. Response-body is intentionally empty."),
    @ApiResponse(code = 403, message = "Indicates the requested task cannot be deleted because it’s part of a workflow."),
    @ApiResponse(code = 404, message = "Indicates the requested task was not found.")
})	  
@RequestMapping(value = "/runtime/tasks/{taskId}", method = RequestMethod.DELETE)
public void deleteTask(@ApiParam(name="taskId", value="The id of the task to delete.") @PathVariable String taskId,@ApiParam(hidden=true) @RequestParam(value = "cascadeHistory", required = false) Boolean cascadeHistory,
    @ApiParam(hidden=true) @RequestParam(value = "deleteReason", required = false) String deleteReason, HttpServletResponse response) {

  Task taskToDelete = getTaskFromRequest(taskId);
  if (taskToDelete.getExecutionId() != null) {
    // Can't delete a task that is part of a process instance
    throw new ActivitiForbiddenException("Cannot delete a task that is part of a process-instance.");
  }

  if (cascadeHistory != null) {
    // Ignore delete-reason since the task-history (where the reason is
    // recorded) will be deleted anyway
    taskService.deleteTask(taskToDelete.getId(), cascadeHistory);
  } else {
    // Delete with delete-reason
    taskService.deleteTask(taskToDelete.getId(), deleteReason);
  }
  response.setStatus(HttpStatus.NO_CONTENT.value());
}
 
Example 8
Source File: AttachmentEntityManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void deleteAttachmentsByTaskId(String taskId) {
    checkHistoryEnabled();
    List<AttachmentEntity> attachments = getDbSqlSession().selectList("selectAttachmentsByTaskId", taskId);
    boolean dispatchEvents = getProcessEngineConfiguration().getEventDispatcher().isEnabled();

    String processInstanceId = null;
    String processDefinitionId = null;
    String executionId = null;

    if (dispatchEvents && attachments != null && !attachments.isEmpty()) {
        // Forced to fetch the task to get hold of the process definition for event-dispatching, if available
        Task task = getTaskManager().findTaskById(taskId);
        if (task != null) {
            processDefinitionId = task.getProcessDefinitionId();
            processInstanceId = task.getProcessInstanceId();
            executionId = task.getExecutionId();
        }
    }

    for (AttachmentEntity attachment : attachments) {
        String contentId = attachment.getContentId();
        if (contentId != null) {
            getByteArrayManager().deleteByteArrayById(contentId);
        }
        getDbSqlSession().delete(attachment);
        if (dispatchEvents) {
            getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                    ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_DELETED, attachment, executionId, processInstanceId, processDefinitionId));
        }
    }
}
 
Example 9
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByInvolvedUserOr() {
  try {
    Task adhocTask = taskService.newTask();
    adhocTask.setAssignee("kermit");
    adhocTask.setOwner("fozzie");
    taskService.saveTask(adhocTask);
    taskService.addUserIdentityLink(adhocTask.getId(), "gonzo", "customType");
    
    assertEquals(3, taskService.getIdentityLinksForTask(adhocTask.getId()).size());
    
    assertEquals(1, taskService.createTaskQuery().taskId(adhocTask.getId())
        .or()
        .taskId("invalid")
        .taskInvolvedUser("gonzo").count());
    assertEquals(1, taskService.createTaskQuery().taskId(adhocTask.getId())
        .or()
        .taskId("invalid")
        .taskInvolvedUser("kermit").count());
    assertEquals(1, taskService.createTaskQuery().taskId(adhocTask.getId())
        .or()
        .taskId("invalid")
        .taskInvolvedUser("fozzie").count());
    
  } finally {
    List<Task> allTasks = taskService.createTaskQuery().list();
    for(Task task : allTasks) {
      if(task.getExecutionId() == null) {
        taskService.deleteTask(task.getId());
        if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
          historyService.deleteHistoricTaskInstance(task.getId());
        }
      }
    }
  }
}
 
Example 10
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByInvolvedUser() {
  try {
    Task adhocTask = taskService.newTask();
    adhocTask.setAssignee("kermit");
    adhocTask.setOwner("fozzie");
    taskService.saveTask(adhocTask);
    taskService.addUserIdentityLink(adhocTask.getId(), "gonzo", "customType");
    
    assertEquals(3, taskService.getIdentityLinksForTask(adhocTask.getId()).size());
    
    assertEquals(1, taskService.createTaskQuery()
        .taskId(adhocTask.getId()).taskInvolvedUser("gonzo").count());
    assertEquals(1, taskService.createTaskQuery().taskId(adhocTask.getId()).taskInvolvedUser("kermit").count());
    assertEquals(1, taskService.createTaskQuery().taskId(adhocTask.getId()).taskInvolvedUser("fozzie").count());
    
  } finally {
    List<Task> allTasks = taskService.createTaskQuery().list();
    for(Task task : allTasks) {
      if(task.getExecutionId() == null) {
        taskService.deleteTask(task.getId());
        if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
          historyService.deleteHistoricTaskInstance(task.getId());
        }
      }
    }
  }
}
 
Example 11
Source File: VariablesTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testGetVariablesLocal() {

		// Regular getVariables after process instance start
		Map<String, Object> vars = runtimeService.getVariablesLocal(processInstanceId);
		assertEquals(50, vars.size());
		int nrOfStrings = 0, nrOfInts = 0, nrOfDates = 0, nrOfBooleans = 0, nrOfSerializable = 0;
		for (String variableName : vars.keySet()) {
			Object variableValue = vars.get(variableName);
			if (variableValue instanceof String) {
				nrOfStrings++;
			} else if (variableValue instanceof Integer) {
				nrOfInts++;
			} else if (variableValue instanceof Boolean) {
				nrOfBooleans++;
			} else if (variableValue instanceof Date) {
				nrOfDates++;
			} else if (variableValue instanceof TestSerializableVariable) {
				nrOfSerializable++;
			}
		}

		assertEquals(10, nrOfStrings);
		assertEquals(10, nrOfBooleans);
		assertEquals(10, nrOfDates);
		assertEquals(10, nrOfInts);
		assertEquals(10, nrOfSerializable);

		// Trying the same after moving the process
		Task task = taskService.createTaskQuery().singleResult();
		taskService.complete(task.getId());

		task = taskService.createTaskQuery().taskName("Task 3").singleResult();
		String executionId = task.getExecutionId();
		assertFalse(processInstanceId.equals(executionId));

		// On the local scope level, the vars shouldn't be visible
		vars = runtimeService.getVariablesLocal(executionId);
		assertEquals(0, vars.size());
	}
 
Example 12
Source File: TaskVariableBaseResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected boolean hasVariableOnScope(Task task, String variableName, RestVariableScope scope) {
  boolean variableFound = false;

  if (scope == RestVariableScope.GLOBAL) {
    if (task.getExecutionId() != null && runtimeService.hasVariable(task.getExecutionId(), variableName)) {
      variableFound = true;
    }

  } else if (scope == RestVariableScope.LOCAL) {
    if (taskService.hasVariableLocal(task.getId(), variableName)) {
      variableFound = true;
    }
  }
  return variableFound;
}
 
Example 13
Source File: AttachmentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteAttachmentsByTaskId(String taskId) {
  checkHistoryEnabled();
  List<AttachmentEntity> attachments = findAttachmentsByTaskId(taskId);
  boolean dispatchEvents = getEventDispatcher().isEnabled();

  String processInstanceId = null;
  String processDefinitionId = null;
  String executionId = null;

  if (dispatchEvents && attachments != null && !attachments.isEmpty()) {
    // Forced to fetch the task to get hold of the process definition
    // for event-dispatching, if available
    Task task = getTaskEntityManager().findById(taskId);
    if (task != null) {
      processDefinitionId = task.getProcessDefinitionId();
      processInstanceId = task.getProcessInstanceId();
      executionId = task.getExecutionId();
    }
  }

  for (Attachment attachment : attachments) {
    String contentId = attachment.getContentId();
    if (contentId != null) {
      getByteArrayEntityManager().deleteByteArrayById(contentId);
    }
    
    attachmentDataManager.delete((AttachmentEntity) attachment);
    
    if (dispatchEvents) {
      getEventDispatcher().dispatchEvent(
          ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, attachment, executionId, processInstanceId, processDefinitionId));
    }
  }
}
 
Example 14
Source File: VariablesTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testGetVariablesLocal() {

    // Regular getVariables after process instance start
    Map<String, Object> vars = runtimeService.getVariablesLocal(processInstanceId);
    assertEquals(70, vars.size());
    int nrOfStrings = 0, nrOfInts = 0, nrOfDates = 0, nrOfLocalDates = 0, nrOfDateTimes = 0, nrOfBooleans = 0, nrOfSerializable = 0;
    for (String variableName : vars.keySet()) {
      Object variableValue = vars.get(variableName);
      if (variableValue instanceof String) {
        nrOfStrings++;
      } else if (variableValue instanceof Integer) {
        nrOfInts++;
      } else if (variableValue instanceof Boolean) {
        nrOfBooleans++;
      } else if (variableValue instanceof Date) {
        nrOfDates++;
      } else if (variableValue instanceof LocalDate) {
        nrOfLocalDates++;
      } else if (variableValue instanceof DateTime) {
        nrOfDateTimes++;
      } else if (variableValue instanceof TestSerializableVariable) {
        nrOfSerializable++;
      }
    }

    assertEquals(10, nrOfStrings);
    assertEquals(10, nrOfBooleans);
    assertEquals(10, nrOfDates);
    assertEquals(10, nrOfLocalDates);
    assertEquals(10, nrOfDateTimes);
    assertEquals(10, nrOfInts);
    assertEquals(10, nrOfSerializable);

    // Trying the same after moving the process
    Task task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());

    task = taskService.createTaskQuery().taskName("Task 3").singleResult();
    String executionId = task.getExecutionId();
    assertFalse(processInstanceId.equals(executionId));

    // On the local scope level, the vars shouldn't be visible
    vars = runtimeService.getVariablesLocal(executionId);
    assertEquals(0, vars.size());
  }
 
Example 15
Source File: TaskInvolvementTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testQueryMultipleAndAndSingleOr() {
    try {
        Task taskUser1Group1 = taskService.newTask();
        taskUser1Group1.setAssignee("kermit");
        taskUser1Group1.setOwner("user1");
        taskUser1Group1.setPriority(10);
        taskService.saveTask(taskUser1Group1);
        taskService.addGroupIdentityLink(taskUser1Group1.getId(), "group1", IdentityLinkType.PARTICIPANT);

        Task taskUser1Group2 = taskService.newTask();
        taskUser1Group2.setAssignee("kermit");
        taskUser1Group2.setOwner("user1");
        taskUser1Group2.setPriority(10);
        taskService.saveTask(taskUser1Group2);
        taskService.addGroupIdentityLink(taskUser1Group2.getId(), "group2", IdentityLinkType.PARTICIPANT);

        Task taskUser1Group1and2 = taskService.newTask();
        taskUser1Group1and2.setAssignee("kermit");
        taskUser1Group1and2.setOwner("user1");
        taskUser1Group1and2.setPriority(10);
        taskService.saveTask(taskUser1Group1and2);
        taskService.addGroupIdentityLink(taskUser1Group2.getId(), "group1", IdentityLinkType.PARTICIPANT);
        taskService.addGroupIdentityLink(taskUser1Group2.getId(), "group2", IdentityLinkType.PARTICIPANT);


        Task taskUser1Group1and3 = taskService.newTask();
        taskUser1Group1and3.setAssignee("kermit");
        taskUser1Group1and3.setOwner("user1");
        taskUser1Group1and3.setPriority(10);
        taskService.saveTask(taskUser1Group1and3);
        taskService.addGroupIdentityLink(taskUser1Group1and3.getId(), "group1", IdentityLinkType.PARTICIPANT);
        taskService.addGroupIdentityLink(taskUser1Group1and3.getId(), "group3", IdentityLinkType.PARTICIPANT);


        Task taskUser1Group1and4 = taskService.newTask();
        taskUser1Group1and4.setAssignee("kermit");
        taskUser1Group1and4.setOwner("user1");
        taskUser1Group1and4.setPriority(10);
        taskService.saveTask(taskUser1Group1and4);
        taskService.addGroupIdentityLink(taskUser1Group1and4.getId(), "group1", IdentityLinkType.PARTICIPANT);
        taskService.addGroupIdentityLink(taskUser1Group1and4.getId(), "group4", IdentityLinkType.PARTICIPANT);



        List<String> andGroup = new ArrayList<String>();
        andGroup.add("group1");

        List<String> orGroup = new ArrayList<String>();
        orGroup.add("group2");
        orGroup.add("group4");

        assertEquals(2, taskService.createTaskQuery()

                .taskInvolvedUser("user1")
                .taskInvolvedGroupsIn(andGroup)

                .or().taskInvolvedGroupsIn(orGroup).endOr()

                .count());



    } finally {
        List<Task> allTasks = taskService.createTaskQuery().list();
        for(Task task : allTasks) {
            if(task.getExecutionId() == null) {
                taskService.deleteTask(task.getId());
                if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
                    historyService.deleteHistoricTaskInstance(task.getId());
                }
            }
        }
    }
}
 
Example 16
Source File: TaskQueryResourceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Test querying tasks. GET runtime/tasks
 */
public void testQueryTasksWithPaging() throws Exception {
  try {
    Calendar adhocTaskCreate = Calendar.getInstance();
    adhocTaskCreate.set(Calendar.MILLISECOND, 0);

    processEngineConfiguration.getClock().setCurrentTime(adhocTaskCreate.getTime());
    List<String> taskIdList = new ArrayList<String>();
    for (int i = 0; i < 10; i++) {
      Task adhocTask = taskService.newTask();
      adhocTask.setAssignee("gonzo");
      adhocTask.setOwner("owner");
      adhocTask.setDelegationState(DelegationState.PENDING);
      adhocTask.setDescription("Description one");
      adhocTask.setName("Name one");
      adhocTask.setDueDate(adhocTaskCreate.getTime());
      adhocTask.setPriority(100);
      taskService.saveTask(adhocTask);
      taskService.addUserIdentityLink(adhocTask.getId(), "misspiggy", IdentityLinkType.PARTICIPANT);
      taskIdList.add(adhocTask.getId());
    }
    Collections.sort(taskIdList);

    // Check filter-less to fetch all tasks
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_QUERY);
    ObjectNode requestNode = objectMapper.createObjectNode();
    String[] taskIds = new String[] { taskIdList.get(0), taskIdList.get(1), taskIdList.get(2) };
    assertResultsPresentInPostDataResponse(url + "?size=3&sort=id&order=asc", requestNode, taskIds);

    taskIds = new String[] { taskIdList.get(4), taskIdList.get(5), taskIdList.get(6), taskIdList.get(7) };
    assertResultsPresentInPostDataResponse(url + "?start=4&size=4&sort=id&order=asc", requestNode, taskIds);

    taskIds = new String[] { taskIdList.get(8), taskIdList.get(9) };
    assertResultsPresentInPostDataResponse(url + "?start=8&size=10&sort=id&order=asc", requestNode, taskIds);

  } finally {
    // Clean adhoc-tasks even if test fails
    List<Task> tasks = taskService.createTaskQuery().list();
    for (Task task : tasks) {
      if (task.getExecutionId() == null) {
        taskService.deleteTask(task.getId(), true);
      }
    }
  }
}
 
Example 17
Source File: TaskInvolvementTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testQueryByInvolvedGroupAndUser() {
    try {
        Task adhocTask = taskService.newTask();
        adhocTask.setAssignee("kermit");
        adhocTask.setOwner("involvedUser");
        adhocTask.setPriority(10);
        taskService.saveTask(adhocTask);
        taskService.addGroupIdentityLink(adhocTask.getId(), "group1", IdentityLinkType.PARTICIPANT);



        List<String> groups = new ArrayList<String>();
        groups.add("group2");

        assertEquals(3, taskService.getIdentityLinksForTask(adhocTask.getId()).size());
        assertEquals(0, taskService.createTaskQuery()

                .taskInvolvedUser("involvedUser")
                .taskInvolvedGroupsIn(groups)

                .count());

        if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
            assertEquals(0, historyService.createHistoricTaskInstanceQuery()

                    .taskInvolvedUser("involvedUser")
                    .taskInvolvedGroupsIn(groups)

                    .count());
        }

    } finally {
        List<Task> allTasks = taskService.createTaskQuery().list();
        for(Task task : allTasks) {
            if(task.getExecutionId() == null) {
                taskService.deleteTask(task.getId());
                if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
                    historyService.deleteHistoricTaskInstance(task.getId());
                }
            }
        }
    }
}
 
Example 18
Source File: TaskInvolvementTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testQueryByInvolvedGroupOrUser2() {
    try {
        Task taskUser1WithGroups = taskService.newTask();
        taskUser1WithGroups.setAssignee("kermit");
        taskUser1WithGroups.setOwner("user1");
        taskUser1WithGroups.setPriority(10);
        taskService.saveTask(taskUser1WithGroups);
        taskService.addGroupIdentityLink(taskUser1WithGroups.getId(), "group1", IdentityLinkType.PARTICIPANT);


        Task taskUser1WithGroupsCandidateUser = taskService.newTask();
        taskUser1WithGroupsCandidateUser.setAssignee("kermit");
        taskUser1WithGroupsCandidateUser.setOwner("involvedUser");
        taskUser1WithGroupsCandidateUser.setPriority(10);
        taskService.saveTask(taskUser1WithGroupsCandidateUser);
        taskService.addGroupIdentityLink(taskUser1WithGroupsCandidateUser.getId(), "group1", IdentityLinkType.PARTICIPANT);
        taskService.addCandidateUser(taskUser1WithGroupsCandidateUser.getId(), "candidateUser1");



        List<String> groups = new ArrayList<String>();
        groups.add("group1");

        assertEquals(2, taskService.createTaskQuery()
                //.taskId(adhocTask.getId())
                .or()
                .taskInvolvedUser("user1")
                .taskInvolvedGroupsIn(groups)
                .endOr()
                .count());

        assertEquals(2, taskService.createTaskQuery()
                //.taskId(adhocTask.getId())
                .or()
                .taskCandidateUser("user1")
                .taskInvolvedGroupsIn(groups)
                .endOr()
                .count());

        assertEquals(2, taskService.createTaskQuery()
                //.taskId(adhocTask.getId())
                .or()
                .taskCandidateGroup("group2")
                .taskInvolvedGroupsIn(groups)
                .endOr()
                .count());

    } finally {
        List<Task> allTasks = taskService.createTaskQuery().list();
        for(Task task : allTasks) {
            if(task.getExecutionId() == null) {
                taskService.deleteTask(task.getId());
                if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
                    historyService.deleteHistoricTaskInstance(task.getId());
                }
            }
        }
    }
}
 
Example 19
Source File: TaskInvolvementTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testQueryByInvolvedGroupOrUser() {
    try {
        Task adhocTask = taskService.newTask();
        adhocTask.setAssignee("kermit");
        adhocTask.setOwner("involvedUser");
        adhocTask.setPriority(10);
        taskService.saveTask(adhocTask);
        taskService.addGroupIdentityLink(adhocTask.getId(), "group1", IdentityLinkType.PARTICIPANT);

        List<String> groups = new ArrayList<String>();
        groups.add("group1");

        assertEquals(3, taskService.getIdentityLinksForTask(adhocTask.getId()).size());
        assertEquals(1, taskService.createTaskQuery()
                //.taskId(adhocTask.getId())
                .or()
                .taskInvolvedUser("involvedUser")
                .taskInvolvedGroupsIn(groups)
                .endOr()
                .count());

        if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
            assertEquals(1, historyService.createHistoricTaskInstanceQuery()
                    .or().taskCategory("j").taskPriority(10).endOr()
                    .or()
                    .taskInvolvedUser("involvedUser")
                    .taskInvolvedGroupsIn(groups)
                    .endOr()
                    .count());
        }
    } finally {
        List<Task> allTasks = taskService.createTaskQuery().list();
        for(Task task : allTasks) {
            if(task.getExecutionId() == null) {
                taskService.deleteTask(task.getId());
                if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
                    historyService.deleteHistoricTaskInstance(task.getId());
                }
            }
        }
    }
}
 
Example 20
Source File: TaskInvolvementTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testQueryByInvolvedGroupOrUserO() {
    try {
        Task adhocTask = taskService.newTask();
        adhocTask.setAssignee("kermit");
        adhocTask.setOwner("involvedUser");
        adhocTask.setPriority(10);
        taskService.saveTask(adhocTask);


        List<String> groups = new ArrayList<String>();
        groups.add("group1");


        assertEquals(1, taskService.createTaskQuery()
                .or()
                .taskInvolvedUser("involvedUser")
                .taskInvolvedGroupsIn(groups)
                .endOr()
                .count());

        if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
            assertEquals(1, historyService.createHistoricTaskInstanceQuery()
                    .or()
                    .taskInvolvedUser("involvedUser")
                    .taskInvolvedGroupsIn(groups)
                    .endOr()
                    .count());
        }

    } finally {
        List<Task> allTasks = taskService.createTaskQuery().list();
        for(Task task : allTasks) {
            if(task.getExecutionId() == null) {
                taskService.deleteTask(task.getId());
                if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
                    historyService.deleteHistoricTaskInstance(task.getId());
                }
            }
        }
    }
}