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

The following examples show how to use org.activiti.engine.task.Task#getId() . 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: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void testResolveTaskWithParametersEmptyParameters() {
  Task task = taskService.newTask();
  task.setDelegationState(DelegationState.PENDING);
  taskService.saveTask(task);

  String taskId = task.getId();
  taskService.resolveTask(taskId, Collections.EMPTY_MAP);

  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    historyService.deleteHistoricTaskInstance(taskId);
  }

  // Fetch the task again
  task = taskService.createTaskQuery().taskId(taskId).singleResult();
  assertEquals(DelegationState.RESOLVED, task.getDelegationState());

  taskService.deleteTask(taskId, true);
}
 
Example 2
Source File: CustomTaskAssignmentTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testReleaseTask() throws Exception {
  runtimeService.startProcessInstanceByKey("releaseTaskProcess");
  
  Task task = taskService.createTaskQuery().taskAssignee("fozzie").singleResult();
  assertNotNull(task);
  String taskId = task.getId();
  
  // Set assignee to null
  taskService.setAssignee(taskId, null);
  
  task = taskService.createTaskQuery().taskAssignee("fozzie").singleResult();
  assertNull(task);
  
  task = taskService.createTaskQuery().taskId(taskId).singleResult();
  assertNotNull(task);
  assertNull(task.getAssignee());
}
 
Example 3
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 4
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testTaskComments() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    Task task = taskService.newTask();
    task.setOwner("johndoe");
    taskService.saveTask(task);
    String taskId = task.getId();

    identityService.setAuthenticatedUserId("johndoe");
    // Fetch the task again and update
    taskService.addComment(taskId, null, "look at this \n       isn't this great? slkdjf sldkfjs ldkfjs ldkfjs ldkfj sldkfj sldkfj sldkjg laksfg sdfgsd;flgkj ksajdhf skjdfh ksjdhf skjdhf kalskjgh lskh dfialurhg kajsh dfuieqpgkja rzvkfnjviuqerhogiuvysbegkjz lkhf ais liasduh flaisduh ajiasudh vaisudhv nsfd");
    Comment comment = taskService.getTaskComments(taskId).get(0);
    assertEquals("johndoe", comment.getUserId());
    assertEquals(taskId, comment.getTaskId());
    assertNull(comment.getProcessInstanceId());
    assertEquals("look at this isn't this great? slkdjf sldkfjs ldkfjs ldkfjs ldkfj sldkfj sldkfj sldkjg laksfg sdfgsd;flgkj ksajdhf skjdfh ksjdhf skjdhf kalskjgh lskh dfialurhg ...", ((Event)comment).getMessage());
    assertEquals("look at this \n       isn't this great? slkdjf sldkfjs ldkfjs ldkfjs ldkfj sldkfj sldkfj sldkjg laksfg sdfgsd;flgkj ksajdhf skjdfh ksjdhf skjdhf kalskjgh lskh dfialurhg kajsh dfuieqpgkja rzvkfnjviuqerhogiuvysbegkjz lkhf ais liasduh flaisduh ajiasudh vaisudhv nsfd", comment.getFullMessage());
    assertNotNull(comment.getTime());

    // Finally, delete task
    taskService.deleteTask(taskId, true);
  }
}
 
Example 5
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void testCompleteTaskWithParametersEmptyParameters() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  
  String taskId = task.getId();
  taskService.complete(taskId, Collections.EMPTY_MAP);

  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    historyService.deleteHistoricTaskInstance(taskId);
  }
  
  // Fetch the task again
  task = taskService.createTaskQuery().taskId(taskId).singleResult();
  assertNull(task);
}
 
Example 6
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testTaskDelegationThroughServiceCall() {
  Task task = taskService.newTask();
  task.setOwner("johndoe");
  taskService.saveTask(task);
  String taskId = task.getId();

  // Fetch the task again and update
  task = taskService.createTaskQuery().taskId(taskId).singleResult();

  taskService.delegateTask(task.getId(), "joesmoe");

  task = taskService.createTaskQuery().taskId(taskId).singleResult();
  assertEquals("johndoe", task.getOwner());
  assertEquals("joesmoe", task.getAssignee());
  assertEquals(DelegationState.PENDING, task.getDelegationState());

  taskService.resolveTask(taskId);

  task = taskService.createTaskQuery().taskId(taskId).singleResult();
  assertEquals("johndoe", task.getOwner());
  assertEquals("johndoe", task.getAssignee());
  assertEquals(DelegationState.RESOLVED, task.getDelegationState());

  // Finally, delete task
  taskService.deleteTask(taskId, true);
}
 
Example 7
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * @see <a href="https://activiti.atlassian.net/browse/ACT-1059">https://activiti.atlassian.net/browse/ACT-1059</a>
 */
public void testSetDelegationState() {
  Task task = taskService.newTask();
  task.setOwner("wuzh");
  taskService.saveTask(task);
  taskService.delegateTask(task.getId(), "other");
  String taskId = task.getId();

  task = taskService.createTaskQuery().taskId(taskId).singleResult();
  assertEquals("wuzh", task.getOwner());
  assertEquals("other", task.getAssignee());
  assertEquals(DelegationState.PENDING, task.getDelegationState());

  task.setDelegationState(DelegationState.RESOLVED);
  taskService.saveTask(task);

  task = taskService.createTaskQuery().taskId(taskId).singleResult();
  assertEquals("wuzh", task.getOwner());
  assertEquals("other", task.getAssignee());
  assertEquals(DelegationState.RESOLVED, task.getDelegationState());

  taskService.deleteTask(taskId, true);
}
 
Example 8
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testTaskComments() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    Task task = taskService.newTask();
    task.setOwner("johndoe");
    taskService.saveTask(task);
    String taskId = task.getId();

    identityService.setAuthenticatedUserId("johndoe");
    // Fetch the task again and update
    taskService
        .addComment(
            taskId,
            null,
            "look at this \n       isn't this great? slkdjf sldkfjs ldkfjs ldkfjs ldkfj sldkfj sldkfj sldkjg laksfg sdfgsd;flgkj ksajdhf skjdfh ksjdhf skjdhf kalskjgh lskh dfialurhg kajsh dfuieqpgkja rzvkfnjviuqerhogiuvysbegkjz lkhf ais liasduh flaisduh ajiasudh vaisudhv nsfd");
    Comment comment = taskService.getTaskComments(taskId).get(0);
    assertEquals("johndoe", comment.getUserId());
    assertEquals(taskId, comment.getTaskId());
    assertNull(comment.getProcessInstanceId());
    assertEquals("look at this isn't this great? slkdjf sldkfjs ldkfjs ldkfjs ldkfj sldkfj sldkfj sldkjg laksfg sdfgsd;flgkj ksajdhf skjdfh ksjdhf skjdhf kalskjgh lskh dfialurhg ...",
        ((Event) comment).getMessage());
    assertEquals(
        "look at this \n       isn't this great? slkdjf sldkfjs ldkfjs ldkfjs ldkfj sldkfj sldkfj sldkjg laksfg sdfgsd;flgkj ksajdhf skjdfh ksjdhf skjdhf kalskjgh lskh dfialurhg kajsh dfuieqpgkja rzvkfnjviuqerhogiuvysbegkjz lkhf ais liasduh flaisduh ajiasudh vaisudhv nsfd",
        comment.getFullMessage());
    assertNotNull(comment.getTime());

    // Finally, delete task
    taskService.deleteTask(taskId, true);
  }
}
 
Example 9
Source File: TaskVariablesTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testStandaloneTaskVariables() {
  Task task = taskService.newTask();
  task.setName("gonzoTask");
  taskService.saveTask(task);

  String taskId = task.getId();
  taskService.setVariable(taskId, "instrument", "trumpet");
  assertEquals("trumpet", taskService.getVariable(taskId, "instrument"));
  
  taskService.deleteTask(taskId, true);
}
 
Example 10
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testGetIdentityLinksWithOwner() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  String taskId = task.getId();
  
  identityService.saveUser(identityService.newUser("kermit"));
  identityService.saveUser(identityService.newUser("fozzie"));
  
  taskService.claim(taskId, "kermit");
  taskService.delegateTask(taskId, "fozzie");

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

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

  //cleanup
  taskService.deleteTask(taskId, true);
  identityService.deleteUser("kermit");
  identityService.deleteUser("fozzie");
}
 
Example 11
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testDeleteTaskIdentityLink() {
  Task task = null;
  try {
    task = taskService.newTask();
    task.setName("test");
    taskService.saveTask(task);

    taskService.addCandidateGroup(task.getId(), "sales");
    taskService.addCandidateUser(task.getId(), "kermit");

    assertNotNull(taskService.createTaskQuery().taskCandidateGroup("sales").singleResult());
    assertNotNull(taskService.createTaskQuery().taskCandidateUser("kermit").singleResult());

    // Delete identity link for group
    taskService.deleteGroupIdentityLink(task.getId(), "sales", "candidate");

    // Link should be removed
    assertNull(taskService.createTaskQuery().taskCandidateGroup("sales").singleResult());

    // User link should remain unaffected
    assertNotNull(taskService.createTaskQuery().taskCandidateUser("kermit").singleResult());

  } finally {
    // Adhoc task not part of deployment, cleanup
    if (task != null && task.getId() != null) {
      taskService.deleteTask(task.getId());
      if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        historyService.deleteHistoricTaskInstance(task.getId());
      }
    }
  }
}
 
Example 12
Source File: EndEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testConcurrentEndOfSameProcess() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskWithDelay");
  Task task = taskService.createTaskQuery().singleResult();
  assertNotNull(task);

  // We will now start two threads that both complete the task.
  // In the process, the task is followed by a delay of three seconds
  // This will cause both threads to call the taskService.complete method with enough time,
  // before ending the process. Both threads will now try to end the process
  // and only one should succeed (due to optimistic locking).
  TaskCompleter taskCompleter1 = new TaskCompleter(task.getId());
  TaskCompleter taskCompleter2 = new TaskCompleter(task.getId());

  assertFalse(taskCompleter1.isSucceeded());
  assertFalse(taskCompleter2.isSucceeded());

  taskCompleter1.start();
  taskCompleter2.start();
  taskCompleter1.join();
  taskCompleter2.join();

  int successCount = 0;
  if (taskCompleter1.isSucceeded()) {
    successCount++;
  }
  if (taskCompleter2.isSucceeded()) {
    successCount++;
  }

  assertEquals("(Only) one thread should have been able to successfully end the process", 1, successCount);
  assertProcessEnded(processInstance.getId());
}
 
Example 13
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testTaskAttachments() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    Task task = taskService.newTask();
    task.setOwner("johndoe");
    taskService.saveTask(task);
    String taskId = task.getId();
    identityService.setAuthenticatedUserId("johndoe");
    // Fetch the task again and update
    taskService.createAttachment("web page", taskId, null, "weatherforcast", "temperatures and more", "http://weather.com");
    Attachment attachment = taskService.getTaskAttachments(taskId).get(0);
    assertEquals("weatherforcast", attachment.getName());
    assertEquals("temperatures and more", attachment.getDescription());
    assertEquals("web page", attachment.getType());
    assertEquals(taskId, attachment.getTaskId());
    assertNull(attachment.getProcessInstanceId());
    assertEquals("http://weather.com", attachment.getUrl());
    assertNull(taskService.getAttachmentContent(attachment.getId()));

    // Finally, clean up
    taskService.deleteTask(taskId);

    assertEquals(0, taskService.getTaskComments(taskId).size());
    assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskId(taskId).list().size());

    taskService.deleteTask(taskId, true);
  }
}
 
Example 14
Source File: CustomMybatisXMLMapperTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected String createTask(String name, String owner, String assignee, int priority){
  Task task = taskService.newTask();
  task.setName(name);
  task.setOwner(owner);
  task.setAssignee(assignee);
  task.setPriority(priority);
  taskService.saveTask(task);
  return task.getId();
}
 
Example 15
Source File: TaskVariablesTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testStandaloneTaskVariables() {
  Task task = taskService.newTask();
  task.setName("gonzoTask");
  taskService.saveTask(task);

  String taskId = task.getId();
  taskService.setVariable(taskId, "instrument", "trumpet");
  assertEquals("trumpet", taskService.getVariable(taskId, "instrument"));

  taskService.deleteTask(taskId, true);
}
 
Example 16
Source File: ActivitiTypeConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Converts the given task into a {@link WorkflowTask}, allows ignoring domain mismatch (ALF-12264)
 * @param task Task
 * @param ignoreDomainMismatch whether or not to ignore domain mismatch exception
 * @return the converter task. Returns null when the domain mismatched and ignoreDomainMismatch was true.
 */
public WorkflowTask convert(Task task, boolean ignoreDomainMismatch)
{
    if(task == null)
        return null;
    String id = task.getId();
    String defaultTitle = task.getName();
    String defaultDescription = task.getDescription();
    
    WorkflowTaskState state = WorkflowTaskState.IN_PROGRESS;
    WorkflowPath path = getWorkflowPath(task.getExecutionId(), ignoreDomainMismatch);
    
    if(path != null) 
    {
    	// Since the task is active, it's safe to use the active node on
        // the execution path
        WorkflowNode node = path.getNode();
        
        TaskFormData taskFormData =formService.getTaskFormData(task.getId());
        String taskDefId = null;
        if(taskFormData != null) 
        {
            taskDefId = taskFormData.getFormKey();
        }
        WorkflowTaskDefinition taskDef = factory.createTaskDefinition(taskDefId, node, taskDefId, false);
        
        // All task-properties should be fetched, not only local
        Map<QName, Serializable> properties = propertyConverter.getTaskProperties(task);
        
        return factory.createTask(id,
                    taskDef, taskDef.getId(), defaultTitle, defaultDescription, state, path, properties);
    }
    else
    {
    	// Ignoring this task, domain mismatched and safely ignoring that
    	return null;
    }
}
 
Example 17
Source File: CustomMybatisXMLMapperTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected String createTask(String name, String owner, String assignee, int priority) {
  Task task = taskService.newTask();
  task.setName(name);
  task.setOwner(owner);
  task.setAssignee(assignee);
  task.setPriority(priority);
  taskService.saveTask(task);
  return task.getId();
}
 
Example 18
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testCustomTaskComments() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    Task task = taskService.newTask();
    task.setOwner("johndoe");
    taskService.saveTask(task);
    String taskId = task.getId();

    identityService.setAuthenticatedUserId("johndoe");
    String customType1 = "Type1";
    String customType2 = "Type2";

    Comment comment = taskService.addComment(taskId, null, "This is a regular comment");
    Comment customComment1 = taskService.addComment(taskId, null, customType1, "This is a custom comment of type Type1");
    Comment customComment2 = taskService.addComment(taskId, null, customType1, "This is another Type1 comment");
    Comment customComment3 = taskService.addComment(taskId, null, customType2, "This is another custom comment. Type2 this time!");

    assertEquals(CommentEntity.TYPE_COMMENT, comment.getType());
    assertEquals(customType1, customComment1.getType());
    assertEquals(customType2, customComment3.getType());

    assertNotNull(taskService.getComment(comment.getId()));
    assertNotNull(taskService.getComment(customComment1.getId()));

    List<Comment> regularComments = taskService.getTaskComments(taskId);
    assertEquals(1, regularComments.size());
    assertEquals("This is a regular comment", regularComments.get(0).getFullMessage());

    List<Event> allComments = taskService.getTaskEvents(taskId);
    assertEquals(4, allComments.size());

    List<Comment> type2Comments = taskService.getCommentsByType(customType2);
    assertEquals(1, type2Comments.size());
    assertEquals("This is another custom comment. Type2 this time!", type2Comments.get(0).getFullMessage());

    List<Comment> taskTypeComments = taskService.getTaskComments(taskId, customType1);
    assertEquals(2, taskTypeComments.size());

    // Clean up
    taskService.deleteTask(taskId, true);
  }
}
 
Example 19
Source File: FormServiceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/form/FormsProcess.bpmn20.xml", "org/activiti/engine/test/api/form/start.form", "org/activiti/engine/test/api/form/task.form" })
public void testTaskFormPropertyDefaultsAndFormRendering() {
  String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
  StartFormData startForm = formService.getStartFormData(procDefId);
  assertNotNull(startForm);
  assertEquals(deploymentIdFromDeploymentAnnotation, startForm.getDeploymentId());
  assertEquals("org/activiti/engine/test/api/form/start.form", startForm.getFormKey());
  assertEquals(new ArrayList<FormProperty>(), startForm.getFormProperties());
  assertEquals(procDefId, startForm.getProcessDefinition().getId());

  Object renderedStartForm = formService.getRenderedStartForm(procDefId);
  assertEquals("start form content", renderedStartForm);

  Map<String, String> properties = new HashMap<String, String>();
  properties.put("room", "5b");
  properties.put("speaker", "Mike");
  String processInstanceId = formService.submitStartFormData(procDefId, properties).getId();

  Map<String, Object> expectedVariables = new HashMap<String, Object>();
  expectedVariables.put("room", "5b");
  expectedVariables.put("speaker", "Mike");

  Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
  assertEquals(expectedVariables, variables);

  Task task = taskService.createTaskQuery().singleResult();
  String taskId = task.getId();
  TaskFormData taskForm = formService.getTaskFormData(taskId);
  assertEquals(deploymentIdFromDeploymentAnnotation, taskForm.getDeploymentId());
  assertEquals("org/activiti/engine/test/api/form/task.form", taskForm.getFormKey());
  assertEquals(new ArrayList<FormProperty>(), taskForm.getFormProperties());
  assertEquals(taskId, taskForm.getTask().getId());

  assertEquals("Mike is speaking in room 5b", formService.getRenderedTaskForm(taskId));

  properties = new HashMap<String, String>();
  properties.put("room", "3f");
  formService.submitTaskFormData(taskId, properties);

  expectedVariables = new HashMap<String, Object>();
  expectedVariables.put("room", "3f");
  expectedVariables.put("speaker", "Mike");

  variables = runtimeService.getVariables(processInstanceId);
  assertEquals(expectedVariables, variables);
}
 
Example 20
Source File: StandaloneTaskTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testCreateToComplete() {

    // Create and save task
    Task task = taskService.newTask();
    task.setName("testTask");
    taskService.saveTask(task);
    String taskId = task.getId();

    // Add user as candidate user
    taskService.addCandidateUser(taskId, "kermit");
    taskService.addCandidateUser(taskId, "gonzo");

    // Retrieve task list for kermit
    List<Task> tasks = taskService.createTaskQuery().taskCandidateUser("kermit").list();
    assertEquals(1, tasks.size());
    assertEquals("testTask", tasks.get(0).getName());

    // Retrieve task list for gonzo
    tasks = taskService.createTaskQuery().taskCandidateUser("gonzo").list();
    assertEquals(1, tasks.size());
    assertEquals("testTask", tasks.get(0).getName());

    task.setName("Update name");
    taskService.saveTask(task);
    tasks = taskService.createTaskQuery().taskCandidateUser("kermit").list();
    assertEquals(1, tasks.size());
    assertEquals("Update name", tasks.get(0).getName());

    // Claim task
    taskService.claim(taskId, "kermit");

    // Tasks shouldn't appear in the candidate tasklists anymore
    assertTrue(taskService.createTaskQuery().taskCandidateUser("kermit").list().isEmpty());
    assertTrue(taskService.createTaskQuery().taskCandidateUser("gonzo").list().isEmpty());

    // Complete task
    taskService.deleteTask(taskId, true);

    // Task should be removed from runtime data
    // TODO: check for historic data when implemented!
    assertNull(taskService.createTaskQuery().taskId(taskId).singleResult());
  }