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

The following examples show how to use org.camunda.bpm.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: TaskList.java    From camunda-bpm-platform-osgi with Apache License 2.0 6 votes vote down vote up
@Override
protected Object doExecute() throws Exception {
  TaskQuery taskQuery = engine.getTaskService().createTaskQuery();
  if (processId != null) {
    taskQuery.processDefinitionId(processId);
  }
  List<Task> tasks = taskQuery.orderByTaskCreateTime().asc().list();
  int i = 0;
  String[][] data = new String[tasks.size()][HEADER.length];
  for (Task task : tasks) {
    data[i++] = new String[]{
        task.getId(),
        task.getProcessInstanceId(),
        task.getProcessDefinitionId(),
        task.getAssignee(),
        task.getName()};
  }
  return null;
}
 
Example 2
Source File: NestedInterruptingEventSubprocessParallelScenarioTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@ScenarioUnderTest("init.1")
public void testInitSynchronization() {
  // given
  Task eventSubProcessTask1 = rule.taskQuery().taskDefinitionKey("innerEventSubProcessTask1").singleResult();
  Task eventSubProcessTask2 = rule.taskQuery().taskDefinitionKey("innerEventSubProcessTask2").singleResult();

  // when
  CompleteTaskThread completeTaskThread1 = new CompleteTaskThread(eventSubProcessTask1.getId(),
      (ProcessEngineConfigurationImpl) rule.getProcessEngine().getProcessEngineConfiguration());

  CompleteTaskThread completeTaskThread2 = new CompleteTaskThread(eventSubProcessTask2.getId(),
      (ProcessEngineConfigurationImpl) rule.getProcessEngine().getProcessEngineConfiguration());

  completeTaskThread1.startAndWaitUntilControlIsReturned();
  completeTaskThread2.startAndWaitUntilControlIsReturned();

  completeTaskThread1.proceedAndWaitTillDone();
  completeTaskThread2.proceedAndWaitTillDone();

  // then
  Assert.assertNull(completeTaskThread1.getException());
  Assert.assertNotNull(completeTaskThread2.getException());
}
 
Example 3
Source File: StandaloneTaskTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testOptimisticLockingThrownOnMultipleUpdates() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  String taskId = task.getId();

  // first modification
  Task task1 = taskService.createTaskQuery().taskId(taskId).singleResult();
  Task task2 = taskService.createTaskQuery().taskId(taskId).singleResult();

  task1.setDescription("first modification");
  taskService.saveTask(task1);

  // second modification on the initial instance
  task2.setDescription("second modification");
  try {
    taskService.saveTask(task2);
    fail("should get an exception here as the task was modified by someone else.");
  } catch (OptimisticLockingException expected) {
    //  exception was thrown as expected
  }

  taskService.deleteTask(taskId, true);
}
 
Example 4
Source File: JavaSerializationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testStandaloneTaskTransientVariable() {
  Task task = taskService.newTask();
  task.setName("gonzoTask");
  taskService.saveTask(task);

  String taskId = task.getId();

  try {
    taskService
      .setVariable(taskId, "instrument", Variables.serializedObjectValue("trumpet")
        .serializationDataFormat(Variables.SerializationDataFormats.JAVA)
        .setTransient(true)
        .create());
    fail("Exception is expected.");
  } catch (ProcessEngineException ex) {
    assertEquals("ENGINE-17007 Cannot set variable with name instrument. Java serialization format is prohibited", ex.getMessage());
  } finally {
    taskService.deleteTask(taskId, true);
  }

}
 
Example 5
Source File: CustomTaskAssignmentTest.java    From camunda-bpm-platform 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 6
Source File: CompetingTransactionsOptimisticLockingTestWithoutBatchProcessing.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/concurrency/CompetingTransactionsOptimisticLockingTest.testCompetingTransactionsOptimisticLocking.bpmn20.xml")
public void testCompetingTransactionsOptimisticLocking() throws Exception {
  // given
  runtimeService.startProcessInstanceByKey("competingTransactionsProcess");
  List<Task> tasks = taskService.createTaskQuery().list();

  assertEquals(2, tasks.size());

  Task firstTask = "task1-1".equals(tasks.get(0).getTaskDefinitionKey()) ? tasks.get(0) : tasks.get(1);
  Task secondTask = "task2-1".equals(tasks.get(0).getTaskDefinitionKey()) ? tasks.get(0) : tasks.get(1);

  TransactionThread thread1 = new TransactionThread(firstTask.getId());
  thread1.startAndWaitUntilControlIsReturned();
  TransactionThread thread2 = new TransactionThread(secondTask.getId());
  thread2.startAndWaitUntilControlIsReturned();

  thread2.proceedAndWaitTillDone();
  assertNull(thread2.exception);

  thread1.proceedAndWaitTillDone();
  assertNotNull(thread1.exception);
  assertEquals(OptimisticLockingException.class, thread1.exception.getClass());
}
 
Example 7
Source File: BulkHistoryDeleteTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCleanupHistoryCaseInstanceTaskAttachmentByteArray() {
  // given
  // create case instance
  CaseInstance caseInstance = caseService.createCaseInstanceByKey("oneTaskCase");

  Task task = taskService.createTaskQuery().singleResult();
  String taskId = task.getId();
  taskService.createAttachment("foo", taskId, null, "something", null, new ByteArrayInputStream("someContent".getBytes()));

  // assume
  List<Attachment> attachments = taskService.getTaskAttachments(taskId);
  assertEquals(1, attachments.size());
  String contentId = findAttachmentContentId(attachments);
  terminateAndCloseCaseInstance(caseInstance.getId(), null);

  // when
  historyService.deleteHistoricCaseInstancesBulk(Arrays.asList(caseInstance.getId()));

  // then
  attachments = taskService.getTaskAttachments(taskId);
  assertEquals(0, attachments.size());
  verifyByteArraysWereRemoved(contentId);
}
 
Example 8
Source File: TaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
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 9
Source File: TaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolveTaskWithParametersNullParameters() {
  Task task = taskService.newTask();
  task.setDelegationState(DelegationState.PENDING);
  taskService.saveTask(task);

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

  if (processEngineConfiguration.getHistoryLevel().getId()>= ProcessEngineConfigurationImpl.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 10
Source File: TaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetIdentityLinksWithNonExistingAssignee() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  String taskId = task.getId();

  taskService.claim(taskId, "nonExistingAssignee");
  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  assertEquals(1, identityLinks.size());
  assertEquals("nonExistingAssignee", identityLinks.get(0).getUserId());
  assertNull(identityLinks.get(0).getGroupId());
  assertEquals(IdentityLinkType.ASSIGNEE, identityLinks.get(0).getType());

  //cleanup
  taskService.deleteTask(taskId, true);
}
 
Example 11
Source File: DelegationAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testScriptIoMappingExecutesQueryAfterUserCompletesTask() {
  // given
  startProcessInstancesByKey(DEFAULT_PROCESS_KEY, 5);
  Task task = selectAnyTask();

  String taskId = task.getId();
  String processInstanceId = task.getProcessInstanceId();

  createGrantAuthorization(TASK, taskId, userId, UPDATE);

  // when
  taskService.complete(taskId);

  // then
  disableAuthorization();

  VariableInstanceQuery query = runtimeService
      .createVariableInstanceQuery()
      .processInstanceIdIn(processInstanceId);

  VariableInstance variableUser = query
      .variableName("userId")
      .singleResult();
  assertNotNull(variableUser);
  assertEquals(userId, variableUser.getValue());

  VariableInstance variableCount = query
      .variableName("count")
      .singleResult();
  assertNotNull(variableCount);
  assertEquals(5l, variableCount.getValue());

  enableAuthorization();
}
 
Example 12
Source File: TaskDto.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static TaskDto fromEntity(Task task) {
  TaskDto dto = new TaskDto();
  dto.id = task.getId();
  dto.name = task.getName();
  dto.assignee = task.getAssignee();
  dto.created = task.getCreateTime();
  dto.due = task.getDueDate();
  dto.followUp = task.getFollowUpDate();

  if (task.getDelegationState() != null) {
    dto.delegationState = task.getDelegationState().toString();
  }

  dto.description = task.getDescription();
  dto.executionId = task.getExecutionId();
  dto.owner = task.getOwner();
  dto.parentTaskId = task.getParentTaskId();
  dto.priority = task.getPriority();
  dto.processDefinitionId = task.getProcessDefinitionId();
  dto.processInstanceId = task.getProcessInstanceId();
  dto.taskDefinitionKey = task.getTaskDefinitionKey();
  dto.caseDefinitionId = task.getCaseDefinitionId();
  dto.caseExecutionId = task.getCaseExecutionId();
  dto.caseInstanceId = task.getCaseInstanceId();
  dto.suspended = task.isSuspended();
  dto.tenantId = task.getTenantId();

  try {
    dto.formKey = task.getFormKey();
  }
  catch (BadUserRequestException e) {
    // ignore (initializeFormKeys was not called)
  }
  return dto;
}
 
Example 13
Source File: DelegationAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testScriptTaskListenerExecutesQueryAfterUserCompletesTask() {
  // given
  startProcessInstancesByKey(DEFAULT_PROCESS_KEY, 5);
  Task task = selectAnyTask();

  String taskId = task.getId();
  String processInstanceId = task.getProcessInstanceId();

  createGrantAuthorization(TASK, taskId, userId, UPDATE);

  // when
  taskService.complete(taskId);

  // then
  disableAuthorization();

  VariableInstanceQuery query = runtimeService
      .createVariableInstanceQuery()
      .processInstanceIdIn(processInstanceId);

  VariableInstance variableUser = query
      .variableName("userId")
      .singleResult();
  assertNotNull(variableUser);
  assertEquals(userId, variableUser.getValue());

  VariableInstance variableCount = query
      .variableName("count")
      .singleResult();
  assertNotNull(variableCount);
  assertEquals(5l, variableCount.getValue());

  enableAuthorization();
}
 
Example 14
Source File: DelegationAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testScriptExecutionListenerExecutesQueryAfterUserCompletesTask() {
  // given
  startProcessInstancesByKey(DEFAULT_PROCESS_KEY, 5);
  Task task = selectAnyTask();

  String taskId = task.getId();
  String processInstanceId = task.getProcessInstanceId();

  createGrantAuthorization(TASK, taskId, userId, UPDATE);

  // when
  taskService.complete(taskId);

  // then
  disableAuthorization();

  VariableInstanceQuery query = runtimeService
      .createVariableInstanceQuery()
      .processInstanceIdIn(processInstanceId);

  VariableInstance variableUser = query
      .variableName("userId")
      .singleResult();
  assertNotNull(variableUser);
  assertEquals(userId, variableUser.getValue());

  VariableInstance variableCount = query
      .variableName("count")
      .singleResult();
  assertNotNull(variableCount);
  assertEquals(5l, variableCount.getValue());

  enableAuthorization();
}
 
Example 15
Source File: DelegationAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testScriptTaskExecutesQueryAfterUserCompletesTask() {
  // given
  startProcessInstancesByKey(DEFAULT_PROCESS_KEY, 5);
  Task task = selectAnyTask();

  String taskId = task.getId();
  String processInstanceId = task.getProcessInstanceId();

  createGrantAuthorization(TASK, taskId, userId, UPDATE);

  // when
  taskService.complete(taskId);

  // then
  disableAuthorization();

  VariableInstanceQuery query = runtimeService
      .createVariableInstanceQuery()
      .processInstanceIdIn(processInstanceId);

  VariableInstance variableUser = query
      .variableName("userId")
      .singleResult();
  assertNotNull(variableUser);
  assertEquals(userId, variableUser.getValue());

  VariableInstance variableCount = query
      .variableName("count")
      .singleResult();
  assertNotNull(variableCount);
  assertEquals(5l, variableCount.getValue());

  enableAuthorization();
}
 
Example 16
Source File: EndEventTest.java    From camunda-bpm-platform 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 17
Source File: HistoryByteArrayTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testAttachmentContentBinaries() {
    // create and save task
    Task task = taskService.newTask();
    taskService.saveTask(task);
    taskId = task.getId();

    // when
    AttachmentEntity attachment = (AttachmentEntity) taskService.createAttachment("web page", taskId, "someprocessinstanceid", "weatherforcast", "temperatures and more", new ByteArrayInputStream("someContent".getBytes()));

    ByteArrayEntity byteArrayEntity = configuration.getCommandExecutorTxRequired().execute(new GetByteArrayCommand(attachment.getContentId()));

    checkBinary(byteArrayEntity);
}
 
Example 18
Source File: HistoricTaskInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testHistoricTaskInstanceQueryByProcessVariableValue() throws Exception {
  int historyLevel = processEngineConfiguration.getHistoryLevel().getId();
  if (historyLevel >= ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("hallo", "steffen");

    String processInstanceId = runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest", variables).getId();

    Task runtimeTask = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
    String taskId = runtimeTask.getId();

    HistoricTaskInstance historicTaskInstance = historyService
        .createHistoricTaskInstanceQuery()
        .processVariableValueEquals("hallo", "steffen")
        .singleResult();

    assertNotNull(historicTaskInstance);
    assertEquals(taskId, historicTaskInstance.getId());

    taskService.complete(taskId);
    assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskId(taskId).count());

    historyService.deleteHistoricTaskInstance(taskId);
    assertEquals(0, historyService.createHistoricTaskInstanceQuery().count());
  }
}
 
Example 19
Source File: MultiTenancyTaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected String createTaskForTenant(String tenantId) {
  Task task = taskService.newTask();
  if (tenantId != null) {
    task.setTenantId(tenantId);
  }
  taskService.saveTask(task);

  String taskId = task.getId();
  taskIds.add(taskId);

  return taskId;
}
 
Example 20
Source File: CompetingMessageCorrelationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public Void execute(CommandContext commandContext) {

      for (Task task : tasks) {
        CompleteTaskCmd completeTaskCmd = new CompleteTaskCmd(task.getId(), null);
        completeTaskCmd.execute(commandContext);
      }

      monitor.sync();

      return null;
    }