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

The following examples show how to use org.camunda.bpm.engine.task.Task#getProcessInstanceId() . 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: TaskQueryExpressionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@After
public void tearDown() {
  Mocks.reset();

  for (Group group : identityService.createGroupQuery().list()) {
    identityService.deleteGroup(group.getId());
  }
  for (User user : identityService.createUserQuery().list()) {
    identityService.deleteUser(user.getId());
  }
  for (Task task : taskService.createTaskQuery().list()) {
    if (task.getProcessInstanceId() == null) {
      taskService.deleteTask(task.getId(), true);
    }
  }

  identityService.clearAuthentication();
}
 
Example 3
Source File: FilterTaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void tearDown() {
  processEngineConfiguration.setEnableExpressionsInAdhocQueries(false);

  Mocks.reset();

  for (Filter filter : filterService.createTaskFilterQuery().list()) {
    filterService.deleteFilter(filter.getId());
  }
  for (Group group : identityService.createGroupQuery().list()) {
    identityService.deleteGroup(group.getId());
  }
  for (User user : identityService.createUserQuery().list()) {
    identityService.deleteUser(user.getId());
  }
  for (Task task : taskService.createTaskQuery().list()) {
    if (task.getProcessInstanceId() == null) {
      taskService.deleteTask(task.getId(), true);
    }
  }
}
 
Example 4
Source File: HistoricDetailQueryTest.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/oneTaskProcess.bpmn20.xml"})
public void testQueryByExecutionIdAndProcessInstanceId() {
  // given
  startProcessInstance(PROCESS_KEY);

  Task task = taskService.createTaskQuery().singleResult();

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

  taskService.resolveTask(taskId, getVariables());

  // when
  HistoricDetail detail = historyService.createHistoricDetailQuery()
      .processInstanceId(processInstanceId)
      .executionId(executionId).singleResult();

  //then
  assertThat(detail.getProcessInstanceId(), is(processInstanceId));
  assertThat(detail.getExecutionId(), is(executionId));
}
 
Example 5
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 6
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 7
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 8
Source File: DelegationAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testScriptConditionExecutesQueryAfterUserCompletesTask() {
  // 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 9
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 10
Source File: CallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testInterruptingEventSubProcessEventSubscriptions.bpmn20.xml",
  "org/camunda/bpm/engine/test/bpmn/callactivity/interruptingEventSubProcessEventSubscriptions.bpmn20.xml"})
public void testInterruptingMessageEventSubProcessEventSubscriptionsInsideCallActivity() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callInterruptingEventSubProcess");

  // one task in the call activity subprocess should be active after starting the process instance
  TaskQuery taskQuery = taskService.createTaskQuery();
  Task taskInsideCallActivity = taskQuery.singleResult();
  assertEquals("taskBeforeInterruptingEventSubprocess", taskInsideCallActivity.getTaskDefinitionKey());

  // we should have no event subscriptions for the parent process
  assertEquals(0, runtimeService.createEventSubscriptionQuery().processInstanceId(processInstance.getId()).count());
  // we should have two event subscriptions for the called process instance, one for message and one for signal
  String calledProcessInstanceId = taskInsideCallActivity.getProcessInstanceId();
  EventSubscriptionQuery eventSubscriptionQuery = runtimeService.createEventSubscriptionQuery().processInstanceId(calledProcessInstanceId);
  List<EventSubscription> subscriptions = eventSubscriptionQuery.list();
  assertEquals(2, subscriptions.size());

  // start the message interrupting event sub process
  runtimeService.correlateMessage("newMessage");
  Task taskAfterMessageStartEvent = taskQuery.processInstanceId(calledProcessInstanceId).singleResult();
  assertEquals("taskAfterMessageStartEvent", taskAfterMessageStartEvent.getTaskDefinitionKey());

  // no subscriptions left
  assertEquals(0, eventSubscriptionQuery.count());

  // Complete the task inside the called process instance
  taskService.complete(taskAfterMessageStartEvent.getId());

  assertProcessEnded(calledProcessInstanceId);
  assertProcessEnded(processInstance.getId());
}
 
Example 11
Source File: CallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testInterruptingEventSubProcessEventSubscriptions.bpmn20.xml",
  "org/camunda/bpm/engine/test/bpmn/callactivity/interruptingEventSubProcessEventSubscriptions.bpmn20.xml"})
public void testInterruptingSignalEventSubProcessEventSubscriptionsInsideCallActivity() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callInterruptingEventSubProcess");

  // one task in the call activity subprocess should be active after starting the process instance
  TaskQuery taskQuery = taskService.createTaskQuery();
  Task taskInsideCallActivity = taskQuery.singleResult();
  assertEquals("taskBeforeInterruptingEventSubprocess", taskInsideCallActivity.getTaskDefinitionKey());

  // we should have no event subscriptions for the parent process
  assertEquals(0, runtimeService.createEventSubscriptionQuery().processInstanceId(processInstance.getId()).count());
  // we should have two event subscriptions for the called process instance, one for message and one for signal
  String calledProcessInstanceId = taskInsideCallActivity.getProcessInstanceId();
  EventSubscriptionQuery eventSubscriptionQuery = runtimeService.createEventSubscriptionQuery().processInstanceId(calledProcessInstanceId);
  List<EventSubscription> subscriptions = eventSubscriptionQuery.list();
  assertEquals(2, subscriptions.size());

  // start the signal interrupting event sub process
  runtimeService.signalEventReceived("newSignal");
  Task taskAfterSignalStartEvent = taskQuery.processInstanceId(calledProcessInstanceId).singleResult();
  assertEquals("taskAfterSignalStartEvent", taskAfterSignalStartEvent.getTaskDefinitionKey());

  // no subscriptions left
  assertEquals(0, eventSubscriptionQuery.count());

  // Complete the task inside the called process instance
  taskService.complete(taskAfterSignalStartEvent.getId());

  assertProcessEnded(calledProcessInstanceId);
  assertProcessEnded(processInstance.getId());
}
 
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: CallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for handing over a null process variables to a sub process
 */
@Deployment(resources = {
  "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testSubProcessDataInputOutput.bpmn20.xml",
  "org/camunda/bpm/engine/test/bpmn/callactivity/dataSubProcess.bpmn20.xml"})
public void testSubProcessWithNullDataInput() {
  String processInstanceId = runtimeService.startProcessInstanceByKey("subProcessDataInputOutput").getId();

  // the variable named "subVariable" is not set on process instance
  VariableInstance variable = runtimeService
          .createVariableInstanceQuery()
          .processInstanceIdIn(processInstanceId)
          .variableName("subVariable")
          .singleResult();
  assertNull(variable);

  variable = runtimeService
          .createVariableInstanceQuery()
          .processInstanceIdIn(processInstanceId)
          .variableName("superVariable")
          .singleResult();
  assertNull(variable);

  // the sub process instance is in the task
  Task task = taskService.createTaskQuery().singleResult();
  assertNotNull(task);
  assertEquals("Task in subprocess", task.getName());

  // the value of "subVariable" is null
  assertNull(taskService.getVariable(task.getId(), "subVariable"));

  String subProcessInstanceId = task.getProcessInstanceId();
  assertFalse(processInstanceId.equals(subProcessInstanceId));

  // the variable "subVariable" is set on the sub process instance
  variable = runtimeService
          .createVariableInstanceQuery()
          .processInstanceIdIn(subProcessInstanceId)
          .variableName("subVariable")
          .singleResult();

  assertNotNull(variable);
  assertNull(variable.getValue());
  assertEquals("subVariable", variable.getName());
}
 
Example 14
Source File: CallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for handing over a null process variables to a sub process
 */
@Deployment(resources = {
  "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testSubProcessDataInputOutputAsExpression.bpmn20.xml",
  "org/camunda/bpm/engine/test/bpmn/callactivity/dataSubProcess.bpmn20.xml"})
public void testSubProcessWithNullDataInputAsExpression() {
  Map<String, Object> params = new HashMap<String, Object>();
  params.put("superVariable", null);
  String processInstanceId = runtimeService.startProcessInstanceByKey("subProcessDataInputOutput", params).getId();

  // the variable named "subVariable" is not set on process instance
  VariableInstance variable = runtimeService
          .createVariableInstanceQuery()
          .processInstanceIdIn(processInstanceId)
          .variableName("subVariable")
          .singleResult();
  assertNull(variable);

  variable = runtimeService
          .createVariableInstanceQuery()
          .processInstanceIdIn(processInstanceId)
          .variableName("superVariable")
          .singleResult();
  assertNotNull(variable);
  assertNull(variable.getValue());

  // the sub process instance is in the task
  Task task = taskService.createTaskQuery().singleResult();
  assertNotNull(task);
  assertEquals("Task in subprocess", task.getName());

  // the value of "subVariable" is null
  assertNull(taskService.getVariable(task.getId(), "subVariable"));

  String subProcessInstanceId = task.getProcessInstanceId();
  assertFalse(processInstanceId.equals(subProcessInstanceId));

  // the variable "subVariable" is set on the sub process instance
  variable = runtimeService
          .createVariableInstanceQuery()
          .processInstanceIdIn(subProcessInstanceId)
          .variableName("subVariable")
          .singleResult();

  assertNotNull(variable);
  assertNull(variable.getValue());
  assertEquals("subVariable", variable.getName());
}
 
Example 15
Source File: HalTask.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public static HalTask fromTask(Task task) {
  HalTask dto = new HalTask();

  // task state
  dto.id = task.getId();
  dto.name = task.getName();
  dto.assignee = task.getAssignee();
  dto.created = task.getCreateTime();
  dto.due = task.getDueDate();
  dto.followUp = task.getFollowUpDate();
  dto.delegationState = task.getDelegationState();
  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)
  }

  // links
  dto.linker.createLink(REL_SELF, task.getId());
  dto.linker.createLink(REL_ASSIGNEE, task.getAssignee());
  dto.linker.createLink(REL_OWNER, task.getOwner());
  dto.linker.createLink(REL_EXECUTION,task.getExecutionId());
  dto.linker.createLink(REL_PARENT_TASK, task.getParentTaskId());
  dto.linker.createLink(REL_PROCESS_DEFINITION, task.getProcessDefinitionId());
  dto.linker.createLink(REL_PROCESS_INSTANCE, task.getProcessInstanceId());
  dto.linker.createLink(REL_CASE_INSTANCE, task.getCaseInstanceId());
  dto.linker.createLink(REL_CASE_EXECUTION, task.getCaseExecutionId());
  dto.linker.createLink(REL_CASE_DEFINITION, task.getCaseDefinitionId());
  dto.linker.createLink(REL_IDENTITY_LINKS, task.getId());

  return dto;
}