Java Code Examples for org.camunda.bpm.engine.repository.ProcessDefinitionQuery#list()

The following examples show how to use org.camunda.bpm.engine.repository.ProcessDefinitionQuery#list() . 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: MultiTenancyProcessDefinitionCmdsTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteProcessDefinitionWithAuthenticatedTenant() {
  //given deployment with two process definitions
  Deployment deployment = testRule.deployForTenant(TENANT_ONE, "org/camunda/bpm/engine/test/repository/twoProcesses.bpmn20.xml");
  ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId());
  List<ProcessDefinition> processDefinitions = processDefinitionQuery.list();
  //and user with tenant authentication
  identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));

  //when delete process definition with authenticated user
  repositoryService.deleteProcessDefinition(processDefinitions.get(0).getId());

  //then process definition should be deleted
  identityService.clearAuthentication();
  assertThat(processDefinitionQuery.count(), is(1L));
  assertThat(processDefinitionQuery.tenantIdIn(TENANT_ONE).count(), is(1L));
}
 
Example 2
Source File: MultiTenancyProcessDefinitionCmdsTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteProcessDefinitionDisabledTenantCheck() {
  //given deployment with two process definitions
  Deployment deployment = testRule.deployForTenant(TENANT_ONE, "org/camunda/bpm/engine/test/repository/twoProcesses.bpmn20.xml");
  //tenant check disabled
  processEngineConfiguration.setTenantCheckEnabled(false);
  ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId());
  List<ProcessDefinition> processDefinitions = processDefinitionQuery.list();
  //user with no authentication
  identityService.setAuthentication("user", null, null);

  //when process definition should be deleted without tenant check
  repositoryService.deleteProcessDefinition(processDefinitions.get(0).getId());

  //then process definition is deleted
  identityService.clearAuthentication();
  assertThat(processDefinitionQuery.count(), is(1L));
  assertThat(processDefinitionQuery.tenantIdIn(TENANT_ONE).count(), is(1L));
}
 
Example 3
Source File: ProcessDefinitionRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public List<ProcessDefinitionDto> getProcessDefinitions(UriInfo uriInfo,
    Integer firstResult, Integer maxResults) {
   ProcessDefinitionQueryDto queryDto = new ProcessDefinitionQueryDto(getObjectMapper(), uriInfo.getQueryParameters());
  List<ProcessDefinitionDto> definitions = new ArrayList<ProcessDefinitionDto>();

  ProcessEngine engine = getProcessEngine();
  ProcessDefinitionQuery query = queryDto.toQuery(engine);

  List<ProcessDefinition> matchingDefinitions = null;

  if (firstResult != null || maxResults != null) {
    matchingDefinitions = executePaginatedQuery(query, firstResult, maxResults);
  } else {
    matchingDefinitions = query.list();
  }

  for (ProcessDefinition definition : matchingDefinitions) {
    ProcessDefinitionDto def = ProcessDefinitionDto.fromProcessDefinition(definition);
    definitions.add(def);
  }
  return definitions;
}
 
Example 4
Source File: ProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testQuerySorting() {

  // asc

  ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionId().asc();
  verifyQueryResults(query, 4);

  query = repositoryService.createProcessDefinitionQuery().orderByDeploymentId().asc();
  verifyQueryResults(query, 4);

  query = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionKey().asc();
  verifyQueryResults(query, 4);

  query = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionVersion().asc();
  verifyQueryResults(query, 4);

  // desc

  query = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionId().desc();
  verifyQueryResults(query, 4);

  query = repositoryService.createProcessDefinitionQuery().orderByDeploymentId().desc();
  verifyQueryResults(query, 4);

  query = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionKey().desc();
  verifyQueryResults(query, 4);

  query = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionVersion().desc();
  verifyQueryResults(query, 4);

  // Typical use case
  query = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionKey().asc().orderByProcessDefinitionVersion().desc();
  List<ProcessDefinition> processDefinitions = query.list();
  assertThat(processDefinitions.size()).isEqualTo(4);

  assertThat(processDefinitions.get(0).getKey()).isEqualTo("one");
  assertThat(processDefinitions.get(0).getVersion()).isEqualTo(2);
  assertThat(processDefinitions.get(1).getKey()).isEqualTo("one");
  assertThat(processDefinitions.get(1).getVersion()).isEqualTo(1);
  assertThat(processDefinitions.get(2).getKey()).isEqualTo("two");
  assertThat(processDefinitions.get(2).getVersion()).isEqualTo(1);
}