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

The following examples show how to use org.activiti.engine.task.Task#setCategory() . 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: TasksResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/rest/tasks", method = RequestMethod.POST)
public TaskRepresentation createNewTask(@RequestBody CreateTaskRepresentation taskRepresentation, HttpServletRequest request) {
  if (StringUtils.isEmpty(taskRepresentation.getName())) {
    throw new BadRequestException("Task name is required");
  }

  Task task = taskService.newTask();
  task.setName(taskRepresentation.getName());
  task.setDescription(taskRepresentation.getDescription());
  if (StringUtils.isNotEmpty(taskRepresentation.getCategory())) {
    task.setCategory(taskRepresentation.getCategory());
  }
  task.setAssignee(SecurityUtils.getCurrentUserId());
  taskService.saveTask(task);
  return new TaskRepresentation(taskService.createTaskQuery().taskId(task.getId()).singleResult());
}
 
Example 2
Source File: TaskRepresentation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void fillTask(Task task) {
  task.setName(name);
  task.setDescription(description);
  if (assignee != null && assignee.getId() != null) {
    task.setAssignee(String.valueOf(assignee.getId()));
  }
  task.setDueDate(dueDate);
  if (priority != null) {
    task.setPriority(priority);
  }
  task.setCategory(category);
}
 
Example 3
Source File: UserTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testTaskCategory() {
  runtimeService.startProcessInstanceByKey("testTaskCategory");
  Task task = taskService.createTaskQuery().singleResult();

  // Test if the property set in the model is shown in the task
  String testCategory = "My Category";
  assertEquals(testCategory, task.getCategory());

  // Test if can be queried by query API
  assertEquals("Task with category", taskService.createTaskQuery().taskCategory(testCategory).singleResult().getName());
  assertTrue(taskService.createTaskQuery().taskCategory("Does not exist").count() == 0);

  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    // Check historic task
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).singleResult();
    assertEquals(testCategory, historicTaskInstance.getCategory());
    assertEquals("Task with category", historyService.createHistoricTaskInstanceQuery().taskCategory(testCategory).singleResult().getName());
    assertTrue(historyService.createHistoricTaskInstanceQuery().taskCategory("Does not exist").count() == 0);

    // Update category
    String newCategory = "New Test Category";
    task.setCategory(newCategory);
    taskService.saveTask(task);

    task = taskService.createTaskQuery().singleResult();
    assertEquals(newCategory, task.getCategory());
    assertEquals("Task with category", taskService.createTaskQuery().taskCategory(newCategory).singleResult().getName());
    assertTrue(taskService.createTaskQuery().taskCategory(testCategory).count() == 0);

    // Complete task and verify history
    taskService.complete(task.getId());
    historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).singleResult();
    assertEquals(newCategory, historicTaskInstance.getCategory());
    assertEquals("Task with category", historyService.createHistoricTaskInstanceQuery().taskCategory(newCategory).singleResult().getName());
    assertTrue(historyService.createHistoricTaskInstanceQuery().taskCategory(testCategory).count() == 0);
  }
}
 
Example 4
Source File: TaskBaseResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Populate the task based on the values that are present in the given {@link TaskRequest}.
 */
protected void populateTaskFromRequest(Task task, TaskRequest taskRequest) {
  if (taskRequest.isNameSet()) {
    task.setName(taskRequest.getName());
  }
  if (taskRequest.isAssigneeSet()) {
    task.setAssignee(taskRequest.getAssignee());
  }
  if (taskRequest.isDescriptionSet()) {
    task.setDescription(taskRequest.getDescription());
  }
  if (taskRequest.isDuedateSet()) {
    task.setDueDate(taskRequest.getDueDate());
  }
  if (taskRequest.isOwnerSet()) {
    task.setOwner(taskRequest.getOwner());
  }
  if (taskRequest.isParentTaskIdSet()) {
    task.setParentTaskId(taskRequest.getParentTaskId());
  }
  if (taskRequest.isPrioritySet()) {
    task.setPriority(taskRequest.getPriority());
  }
  if (taskRequest.isCategorySet()) {
    task.setCategory(taskRequest.getCategory());
  }
  if (taskRequest.isTenantIdSet()) {
    task.setTenantId(taskRequest.getTenantId());
  }
  if (taskRequest.isFormKeySet()) {
    task.setFormKey(taskRequest.getFormKey());
  }

  if (taskRequest.isDelegationStateSet()) {
    DelegationState delegationState = getDelegationState(taskRequest.getDelegationState());
    task.setDelegationState(delegationState);
  }
}
 
Example 5
Source File: UserTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testTaskCategory() {
	runtimeService.startProcessInstanceByKey("testTaskCategory");
	Task task = taskService.createTaskQuery().singleResult();
	
	// Test if the property set in the model is shown in the task
	String testCategory = "My Category";
	assertEquals(testCategory, task.getCategory());
	
	// Test if can be queried by query API
	assertEquals("Task with category", taskService.createTaskQuery().taskCategory(testCategory).singleResult().getName());
	assertTrue(taskService.createTaskQuery().taskCategory("Does not exist").count() == 0);
	
	if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
		// Check historic task
		HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).singleResult();
		assertEquals(testCategory, historicTaskInstance.getCategory());
		assertEquals("Task with category", historyService.createHistoricTaskInstanceQuery().taskCategory(testCategory).singleResult().getName());
		assertTrue(historyService.createHistoricTaskInstanceQuery().taskCategory("Does not exist").count() == 0);
		
		// Update category
		String newCategory = "New Test Category";
		task.setCategory(newCategory);
		taskService.saveTask(task);
		
		task = taskService.createTaskQuery().singleResult();
		assertEquals(newCategory, task.getCategory());
		assertEquals("Task with category", taskService.createTaskQuery().taskCategory(newCategory).singleResult().getName());
		assertTrue(taskService.createTaskQuery().taskCategory(testCategory).count() == 0);
		
		// Complete task and verify history
		taskService.complete(task.getId());
		historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).singleResult();
		assertEquals(newCategory, historicTaskInstance.getCategory());
		assertEquals("Task with category", historyService.createHistoricTaskInstanceQuery().taskCategory(newCategory).singleResult().getName());
		assertTrue(historyService.createHistoricTaskInstanceQuery().taskCategory(testCategory).count() == 0);
	}
}
 
Example 6
Source File: ActivitiTestBase.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
protected Task addTask(String name, int priority) {
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.newTask();
    task.setName(name);
    task.setPriority(priority);
    task.setAssignee("john");
    task.setCategory("testCategory");
    task.setDueDate(new Date());
    task.setOwner("jane");
    task.setDescription("testDescription");
    task.setTenantId("testTenant");
    taskService.saveTask(task);
    return task;

}