Java Code Examples for org.camunda.bpm.engine.repository.ProcessDefinition#getId()

The following examples show how to use org.camunda.bpm.engine.repository.ProcessDefinition#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: ProcessList.java    From camunda-bpm-platform-osgi with Apache License 2.0 6 votes vote down vote up
public void printProcessDefinition(String deploymentId) {
  String[] header = new String[]{"ID", "KEY", "NAME", "DEPLOYMENT", "CATEGORY"};

  List<ProcessDefinition> processes = engine.getRepositoryService().createProcessDefinitionQuery().deploymentId(deploymentId).list();
  String[][] data = new String[processes.size()][header.length];
  int i = 0;
  for (ProcessDefinition process : processes) {
    data[i++] = new String[]{
        process.getId(),
        process.getKey(),
        process.getName(),
        process.getDeploymentId(),
        process.getCategory()
    };
  }
  ASCIITable.getInstance().printTable(header, data);


}
 
Example 2
Source File: DeleteProcessDefinitionsByKeyCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
  ensureNotNull("processDefinitionKey", processDefinitionKey);

  List<ProcessDefinition> processDefinitions = commandContext.getProcessDefinitionManager()
    .findDefinitionsByKeyAndTenantId(processDefinitionKey, tenantId, isTenantIdSet);
  ensureNotEmpty(NotFoundException.class, "No process definition found with key '" + processDefinitionKey + "'",
    "processDefinitions", processDefinitions);

  for (ProcessDefinition processDefinition: processDefinitions) {
    String processDefinitionId = processDefinition.getId();
    deleteProcessDefinitionCmd(commandContext, processDefinitionId, cascade, skipCustomListeners, skipIoMappings);
  }

  return null;
}
 
Example 3
Source File: CompetingSuspensionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Ensures that suspending a process definition and its process instances will also increase the revision of the executions
 * such that concurrent updates fail with an OptimisticLockingException.
 */
@Deployment
public void testCompetingSuspension() {
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("CompetingSuspensionProcess").singleResult();

  ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
  Execution execution = runtimeService
      .createExecutionQuery()
      .processInstanceId(processInstance.getId())
      .activityId("wait1")
      .singleResult();

  SuspendProcessDefinitionThread suspensionThread = new SuspendProcessDefinitionThread(processDefinition.getId());
  suspensionThread.startAndWaitUntilControlIsReturned();

  SignalThread signalExecutionThread = new SignalThread(execution.getId());
  signalExecutionThread.startAndWaitUntilControlIsReturned();

  suspensionThread.proceedAndWaitTillDone();
  assertNull(suspensionThread.exception);

  signalExecutionThread.proceedAndWaitTillDone();
  assertNotNull(signalExecutionThread.exception);
}
 
Example 4
Source File: ProcessInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryByProcessDefinitionKeyIn() {
  // given (deploy another process)
  ProcessDefinition oneTaskProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);

  String oneTaskProcessDefinitionId = oneTaskProcessDefinition.getId();
  runtimeService.startProcessInstanceById(oneTaskProcessDefinitionId);
  runtimeService.startProcessInstanceById(oneTaskProcessDefinitionId);

  // assume
  assertThat(runtimeService.createProcessInstanceQuery().count(), is(7l));

  // when
  ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery()
    .processDefinitionKeyIn(PROCESS_DEFINITION_KEY, PROCESS_DEFINITION_KEY_2);

  // then
  assertThat(query.count(), is(5l));
  assertThat(query.list().size(), is(5));
}
 
Example 5
Source File: ProcessInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryByProcessDefinitionKeyNotIn() {
  // given (deploy another process)
  ProcessDefinition oneTaskProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);

  String oneTaskProcessDefinitionId = oneTaskProcessDefinition.getId();
  runtimeService.startProcessInstanceById(oneTaskProcessDefinitionId);
  runtimeService.startProcessInstanceById(oneTaskProcessDefinitionId);

  // assume
  assertThat(runtimeService.createProcessInstanceQuery().count(), is(7l));

  // when
  ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery()
    .processDefinitionKeyNotIn(PROCESS_DEFINITION_KEY, PROCESS_DEFINITION_KEY_2);

  // then
  assertThat(query.count(), is(2l));
  assertThat(query.list().size(), is(2));
}
 
Example 6
Source File: ProcessDefinitionDto.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static ProcessDefinitionDto fromProcessDefinition(ProcessDefinition definition) {
  ProcessDefinitionDto dto = new ProcessDefinitionDto();
  dto.id = definition.getId();
  dto.key = definition.getKey();
  dto.category = definition.getCategory();
  dto.description = definition.getDescription();
  dto.name = definition.getName();
  dto.version = definition.getVersion();
  dto.resource = definition.getResourceName();
  dto.deploymentId = definition.getDeploymentId();
  dto.diagram = definition.getDiagramResourceName();
  dto.suspended = definition.isSuspended();
  dto.tenantId = definition.getTenantId();
  dto.versionTag = definition.getVersionTag();
  dto.historyTimeToLive = definition.getHistoryTimeToLive();
  dto.isStartableInTasklist = definition.isStartableInTasklist();
  return dto;
}
 
Example 7
Source File: HalProcessDefinition.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static HalProcessDefinition fromProcessDefinition(ProcessDefinition processDefinition, ProcessEngine processEngine) {
  HalProcessDefinition halProcDef = new HalProcessDefinition();

  halProcDef.id = processDefinition.getId();
  halProcDef.key = processDefinition.getKey();
  halProcDef.category = processDefinition.getCategory();
  halProcDef.description = processDefinition.getDescription();
  halProcDef.name = processDefinition.getName();
  halProcDef.version = processDefinition.getVersion();
  halProcDef.versionTag = processDefinition.getVersionTag();
  halProcDef.resource = processDefinition.getResourceName();
  halProcDef.deploymentId = processDefinition.getDeploymentId();
  halProcDef.diagram = processDefinition.getDiagramResourceName();
  halProcDef.suspended = processDefinition.isSuspended();
  halProcDef.contextPath = ApplicationContextPathUtil.getApplicationPathForDeployment(processEngine, processDefinition.getDeploymentId());

  halProcDef.linker.createLink(REL_SELF, processDefinition.getId());
  halProcDef.linker.createLink(REL_DEPLOYMENT, processDefinition.getDeploymentId());
  halProcDef.linker.createLink(REL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(), processDefinition.getResourceName());

  return halProcDef;
}
 
Example 8
Source File: FormServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {
  "org/camunda/bpm/engine/test/api/form/util/VacationRequest_deprecated_forms.bpmn20.xml",
  "org/camunda/bpm/engine/test/api/form/util/approve.form",
  "org/camunda/bpm/engine/test/api/form/util/request.form",
  "org/camunda/bpm/engine/test/api/form/util/adjustRequest.form" })
@Test
public void testTaskFormsWithVacationRequestProcess() {

  // Get start form
  String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
  Object startForm = formService.getRenderedStartForm(procDefId, "juel");
  assertNotNull(startForm);

  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
  String processDefinitionId = processDefinition.getId();
  assertEquals("org/camunda/bpm/engine/test/api/form/util/request.form", formService.getStartFormData(processDefinitionId).getFormKey());

  // Define variables that would be filled in through the form
  Map<String, String> formProperties = new HashMap<>();
  formProperties.put("employeeName", "kermit");
  formProperties.put("numberOfDays", "4");
  formProperties.put("vacationMotivation", "I'm tired");
  formService.submitStartFormData(procDefId, formProperties);

  // Management should now have a task assigned to them
  Task task = taskService.createTaskQuery().taskCandidateGroup("management").singleResult();
  assertEquals("Vacation request by kermit", task.getDescription());
  Object taskForm = formService.getRenderedTaskForm(task.getId(), "juel");
  assertNotNull(taskForm);

  // Rejecting the task should put the process back to first task
  taskService.complete(task.getId(), CollectionUtil.singletonMap("vacationApproved", "false"));
  task = taskService.createTaskQuery().singleResult();
  assertEquals("Adjust vacation request", task.getName());
}
 
Example 9
Source File: DeleteProcessDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteProcessDefinitionAndRefillDeploymentCache() {
  // given a deployment with two process definitions in one xml model file
  deployment = repositoryService.createDeployment()
          .addClasspathResource("org/camunda/bpm/engine/test/repository/twoProcesses.bpmn20.xml")
          .deploy();
  ProcessDefinition processDefinitionOne =
      repositoryService.createProcessDefinitionQuery().processDefinitionKey("one").singleResult();
  ProcessDefinition processDefinitionTwo =
      repositoryService.createProcessDefinitionQuery().processDefinitionKey("two").singleResult();

  String idOne = processDefinitionOne.getId();
  //one is deleted from the deployment
  repositoryService.deleteProcessDefinition(idOne);

  //when clearing the deployment cache
  processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache();

  //then creating process instance from the existing process definition
  ProcessInstanceWithVariables procInst = runtimeService.createProcessInstanceByKey("two").executeWithVariablesInReturn();
  assertNotNull(procInst);
  assertTrue(procInst.getProcessDefinitionId().contains("two"));

  //should refill the cache
  Cache cache = processEngineConfiguration.getDeploymentCache().getProcessDefinitionCache();
  assertNotNull(cache.get(processDefinitionTwo.getId()));
  //The deleted process definition should not be recreated after the cache is refilled
  assertNull(cache.get(processDefinitionOne.getId()));
}
 
Example 10
Source File: MigrationMessageStartEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testMigrateEventSubscription() {
  // given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(MessageReceiveModels.MESSAGE_START_PROCESS);
  String sourceProcessDefinitionId = sourceProcessDefinition.getId();

  MigrationPlan migrationPlan = runtimeService
    .createMigrationPlan(sourceProcessDefinitionId, sourceProcessDefinitionId)
    .mapEqualActivities()
    .build();

  ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinitionId);
  EventSubscription eventSubscription = runtimeService
      .createEventSubscriptionQuery()
      .activityId("startEvent")
      .eventName(MessageReceiveModels.MESSAGE_NAME)
      .singleResult();

  // when
  runtimeService.newMigration(migrationPlan).processInstanceIds(processInstance.getId()).execute();

  // then
  assertEventSubscriptionMigrated(eventSubscription, "startEvent", MessageReceiveModels.MESSAGE_NAME);

  testHelper.completeTask("userTask");
  testHelper.assertProcessEnded(processInstance.getId());
}