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

The following examples show how to use org.camunda.bpm.engine.repository.ProcessDefinitionQuery#singleResult() . 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: MultiTenancyProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryByLatestWithoutTenantId() {
  // deploy a second version without tenant id
  deployment(emptyProcess);

  ProcessDefinitionQuery query = repositoryService
      .createProcessDefinitionQuery()
      .processDefinitionKey(PROCESS_DEFINITION_KEY)
      .latestVersion()
      .withoutTenantId();

  assertThat(query.count(), is(1L));

  ProcessDefinition processDefinition = query.singleResult();
  assertThat(processDefinition.getTenantId(), is(nullValue()));
  assertThat(processDefinition.getVersion(), is(2));
}
 
Example 2
Source File: ProcessDefinitionAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryWithRevokedReadPermission() {
  // given
  // given user gets all permissions on any process definition
  createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, ALL);

  Authorization authorization = createRevokeAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY);
  authorization.setUserId(userId);
  authorization.removePermission(READ);
  saveAuthorization(authorization);

  // when
  ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();

  // then
  verifyQueryResults(query, 1);

  ProcessDefinition definition = query.singleResult();
  assertNotNull(definition);
  assertEquals(TWO_TASKS_PROCESS_KEY, definition.getKey());
}
 
Example 3
Source File: ProcessDefinitionAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryWithGroupAuthorizationRevokedReadPermission() {
  // given
  // given user gets all permissions on any process definition
  Authorization authorization = createGrantAuthorization(PROCESS_DEFINITION, ANY);
  authorization.setGroupId(groupId);
  authorization.addPermission(ALL);
  saveAuthorization(authorization);

  authorization = createRevokeAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY);
  authorization.setGroupId(groupId);
  authorization.removePermission(READ);
  saveAuthorization(authorization);

  // when
  ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();

  // then
  verifyQueryResults(query, 1);

  ProcessDefinition definition = query.singleResult();
  assertNotNull(definition);
  assertEquals(TWO_TASKS_PROCESS_KEY, definition.getKey());
}
 
Example 4
Source File: TestAdditionalResourceSuffixes.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeployProcessArchive() {
  assertNotNull(processEngine);
  RepositoryService repositoryService = processEngine.getRepositoryService();

  ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery()
    .processDefinitionKey("invoice-it");

  assertEquals(1, processDefinitionQuery.count());
  ProcessDefinition processDefinition = processDefinitionQuery.singleResult();

  String deploymentId = repositoryService.createDeploymentQuery()
    .deploymentId(processDefinition.getDeploymentId())
    .singleResult()
    .getId();
  List<Resource> deploymentResources = repositoryService.getDeploymentResources(deploymentId);
  assertEquals(3, deploymentResources.size());
}
 
Example 5
Source File: WorkflowEngineService.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
public ProcessDefinition retrieveProcessDefinition(String processDefinitionId) {
	if (StringUtils.isBlank(processDefinitionId)) {
		throw new IllegalArgumentException("Process definition ID is blank.");
	}
	ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery()
			.processDefinitionId(processDefinitionId);
	ProcessDefinition procDef = query.singleResult();
	if (procDef == null) {
		log.warn("such process definition did not exist,processDefinitionId={}", processDefinitionId);
	}
	return procDef;
}
 
Example 6
Source File: WorkflowEngineService.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessInstance(String processDefinitionId, String processInstanceKey) {
	if (StringUtils.isBlank(processDefinitionId)) {
		throw new IllegalArgumentException("Process definition ID is blank.");
	}

	if (log.isDebugEnabled()) {
		log.debug("try to start process instance with id {} and key {}", processDefinitionId, processInstanceKey);
	}

	ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery()
			.processDefinitionId(processDefinitionId);
	ProcessDefinition procDef = query.singleResult();
	if (procDef == null) {
		log.warn("such process definition did not exist,processDefinitionId={}", processDefinitionId);
		throw new WecubeCoreException(
				String.format("Such proccess definition [%s] does not exist.", processDefinitionId));
	}

	ProcessInstance instance = runtimeService.startProcessInstanceById(processDefinitionId, processInstanceKey);

	if (instance == null) {
		log.warn("Failed to create process instance with id {} and key {}", processDefinitionId,
				processInstanceKey);
		throw new WecubeCoreException(String.format("Failed to create process instance with id %s and key %s.",
				processDefinitionId, processInstanceKey));
	}

	return instance;
}
 
Example 7
Source File: MultiTenancyProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByLatestWithTenantId() {
  // deploy a second version for tenant one
  deploymentForTenant(TENANT_ONE, emptyProcess);

  ProcessDefinitionQuery query = repositoryService
      .createProcessDefinitionQuery()
      .processDefinitionKey(PROCESS_DEFINITION_KEY)
      .latestVersion()
      .tenantIdIn(TENANT_ONE);

  assertThat(query.count(), is(1L));

  ProcessDefinition processDefinition = query.singleResult();
  assertThat(processDefinition.getTenantId(), is(TENANT_ONE));
  assertThat(processDefinition.getVersion(), is(2));

  query = repositoryService
      .createProcessDefinitionQuery()
      .processDefinitionKey(PROCESS_DEFINITION_KEY)
      .latestVersion()
      .tenantIdIn(TENANT_TWO);

  assertThat(query.count(), is(1L));

  processDefinition = query.singleResult();
  assertThat(processDefinition.getTenantId(), is(TENANT_TWO));
  assertThat(processDefinition.getVersion(), is(1));
}
 
Example 8
Source File: ProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByLatestAndName() {
  String firstDeployment = repositoryService
      .createDeployment()
      .addClasspathResource("org/camunda/bpm/engine/test/api/repository/first-process.bpmn20.xml")
      .deploy()
      .getId();

  String secondDeployment = repositoryService
      .createDeployment()
      .addClasspathResource("org/camunda/bpm/engine/test/api/repository/first-process.bpmn20.xml")
      .deploy()
      .getId();

  ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();

  query
    .processDefinitionName("First Test Process")
    .latestVersion();

  verifyQueryResults(query, 1);

  ProcessDefinition result = query.singleResult();

  assertThat(result.getName()).isEqualTo("First Test Process");
  assertThat(result.getVersion()).isEqualTo(2);

  repositoryService.deleteDeployment(firstDeployment, true);
  repositoryService.deleteDeployment(secondDeployment, true);

}
 
Example 9
Source File: ProcessDefinitionAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryWithReadPermissionOnOneTaskProcess() {
  // given
  // given user gets read permission on "oneTaskProcess" process definition
  createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, READ);

  // when
  ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();

  // then
  verifyQueryResults(query, 1);

  ProcessDefinition definition = query.singleResult();
  assertNotNull(definition);
  assertEquals(ONE_TASK_PROCESS_KEY, definition.getKey());
}
 
Example 10
Source File: ProcessDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testQueryByLatestAndNameLike() {
  String firstDeployment = repositoryService
      .createDeployment()
      .addClasspathResource("org/camunda/bpm/engine/test/api/repository/first-process.bpmn20.xml")
      .deploy()
      .getId();

  String secondDeployment = repositoryService
      .createDeployment()
      .addClasspathResource("org/camunda/bpm/engine/test/api/repository/second-process.bpmn20.xml")
      .deploy()
      .getId();

  ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();

  query
    .processDefinitionNameLike("%Test Process")
    .latestVersion();

  verifyQueryResults(query, 1);

  ProcessDefinition result = query.singleResult();

  assertThat(result.getName()).isEqualTo("Second Test Process");
  assertThat(result.getVersion()).isEqualTo(2);

  query
    .processDefinitionNameLike("%Test%")
    .latestVersion();

  verifyQueryResults(query, 1);

  result = query.singleResult();

  assertThat(result.getName()).isEqualTo("Second Test Process");
  assertThat(result.getVersion()).isEqualTo(2);

  query
    .processDefinitionNameLike("Second%")
    .latestVersion();

  result = query.singleResult();

  assertThat(result.getName()).isEqualTo("Second Test Process");
  assertThat(result.getVersion()).isEqualTo(2);

  repositoryService.deleteDeployment(firstDeployment, true);
  repositoryService.deleteDeployment(secondDeployment, true);
}