Search in sources :

Example 31 with RuntimeService

use of org.camunda.bpm.engine.RuntimeService in project camunda-bpm-platform by camunda.

the class ProcessInstanceRestServiceImpl method deleteAsyncHistoricQueryBased.

@Override
public BatchDto deleteAsyncHistoricQueryBased(DeleteProcessInstancesDto deleteProcessInstancesDto) {
    List<String> processInstanceIds = new ArrayList<String>();
    HistoricProcessInstanceQueryDto queryDto = deleteProcessInstancesDto.getHistoricProcessInstanceQuery();
    if (queryDto != null) {
        HistoricProcessInstanceQuery query = queryDto.toQuery(getProcessEngine());
        List<HistoricProcessInstance> historicProcessInstances = query.list();
        for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
            processInstanceIds.add(historicProcessInstance.getId());
        }
    }
    if (deleteProcessInstancesDto.getProcessInstanceIds() != null) {
        processInstanceIds.addAll(deleteProcessInstancesDto.getProcessInstanceIds());
    }
    try {
        RuntimeService runtimeService = getProcessEngine().getRuntimeService();
        Batch batch = runtimeService.deleteProcessInstancesAsync(processInstanceIds, null, deleteProcessInstancesDto.getDeleteReason(), deleteProcessInstancesDto.isSkipCustomListeners(), deleteProcessInstancesDto.isSkipSubprocesses());
        return BatchDto.fromBatch(batch);
    } catch (BadUserRequestException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
    }
}
Also used : HistoricProcessInstanceQueryDto(org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto) HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) RuntimeService(org.camunda.bpm.engine.RuntimeService) Batch(org.camunda.bpm.engine.batch.Batch) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException)

Example 32 with RuntimeService

use of org.camunda.bpm.engine.RuntimeService in project camunda-bpm-platform by camunda.

the class ConditionRestServiceImpl method createConditionEvaluationBuilder.

protected ConditionEvaluationBuilder createConditionEvaluationBuilder(EvaluationConditionDto conditionDto) {
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ObjectMapper objectMapper = getObjectMapper();
    VariableMap variables = VariableValueDto.toMap(conditionDto.getVariables(), processEngine, objectMapper);
    ConditionEvaluationBuilder builder = runtimeService.createConditionEvaluation();
    if (variables != null && !variables.isEmpty()) {
        builder.setVariables(variables);
    }
    if (conditionDto.getBusinessKey() != null) {
        builder.processInstanceBusinessKey(conditionDto.getBusinessKey());
    }
    if (conditionDto.getProcessDefinitionId() != null) {
        builder.processDefinitionId(conditionDto.getProcessDefinitionId());
    }
    if (conditionDto.getTenantId() != null) {
        builder.tenantId(conditionDto.getTenantId());
    } else if (conditionDto.isWithoutTenantId()) {
        builder.withoutTenantId();
    }
    return builder;
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) VariableMap(org.camunda.bpm.engine.variable.VariableMap) ConditionEvaluationBuilder(org.camunda.bpm.engine.runtime.ConditionEvaluationBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 33 with RuntimeService

use of org.camunda.bpm.engine.RuntimeService in project camunda-bpm-platform by camunda.

the class MigrationIncidentTest method testCustomIncidentMigrationWithoutConfiguration.

@Test
public void testCustomIncidentMigrationWithoutConfiguration() {
    // given
    RuntimeService runtimeService = engineRule.getRuntimeService();
    BpmnModelInstance instance1 = Bpmn.createExecutableProcess("process1").startEvent().userTask("u1").endEvent().done();
    BpmnModelInstance instance2 = Bpmn.createExecutableProcess("process2").startEvent().userTask("u2").endEvent().done();
    testHelper.deploy(instance1, instance2);
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("process1");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("process2");
    MigrationPlan migrationPlan = runtimeService.createMigrationPlan(processInstance1.getProcessDefinitionId(), processInstance2.getProcessDefinitionId()).mapActivities("u1", "u2").build();
    runtimeService.createIncident("custom", processInstance1.getId(), null);
    // when
    runtimeService.newMigration(migrationPlan).processInstanceIds(processInstance1.getId()).execute();
    // then
    Incident incident = runtimeService.createIncidentQuery().singleResult();
    assertEquals(processInstance2.getProcessDefinitionId(), incident.getProcessDefinitionId());
    assertEquals("custom", incident.getIncidentType());
    assertEquals(processInstance1.getId(), incident.getExecutionId());
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) Incident(org.camunda.bpm.engine.runtime.Incident) Test(org.junit.Test)

Example 34 with RuntimeService

use of org.camunda.bpm.engine.RuntimeService in project camunda-bpm-platform by camunda.

the class BatchMigrationHelper method migrateProcessInstancesAsync.

public Batch migrateProcessInstancesAsync(int numberOfProcessInstances, ProcessDefinition sourceProcessDefinition, ProcessDefinition targetProcessDefinition) {
    RuntimeService runtimeService = engineRule.getRuntimeService();
    List<String> processInstanceIds = new ArrayList<String>(numberOfProcessInstances);
    for (int i = 0; i < numberOfProcessInstances; i++) {
        processInstanceIds.add(runtimeService.startProcessInstanceById(sourceProcessDefinition.getId()).getId());
    }
    MigrationPlan migrationPlan = engineRule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapEqualActivities().build();
    return runtimeService.newMigration(migrationPlan).processInstanceIds(processInstanceIds).executeAsync();
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ArrayList(java.util.ArrayList)

Example 35 with RuntimeService

use of org.camunda.bpm.engine.RuntimeService in project camunda-bpm-platform by camunda.

the class BatchMigrationTest method testBatchCreationWithProcessInstanceQuery.

@Test
public void testBatchCreationWithProcessInstanceQuery() {
    RuntimeService runtimeService = engineRule.getRuntimeService();
    int processInstanceCount = 15;
    ProcessDefinition sourceProcessDefinition = migrationRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessDefinition targetProcessDefinition = migrationRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    for (int i = 0; i < processInstanceCount; i++) {
        runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    }
    MigrationPlan migrationPlan = engineRule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapEqualActivities().build();
    ProcessInstanceQuery sourceProcessInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionId(sourceProcessDefinition.getId());
    assertEquals(processInstanceCount, sourceProcessInstanceQuery.count());
    // when
    Batch batch = runtimeService.newMigration(migrationPlan).processInstanceQuery(sourceProcessInstanceQuery).executeAsync();
    // then a batch is created
    assertBatchCreated(batch, processInstanceCount);
}
Also used : ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) RuntimeService(org.camunda.bpm.engine.RuntimeService) Batch(org.camunda.bpm.engine.batch.Batch) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Test(org.junit.Test)

Aggregations

RuntimeService (org.camunda.bpm.engine.RuntimeService)51 Test (org.junit.Test)12 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)10 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)9 IdentityService (org.camunda.bpm.engine.IdentityService)6 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)6 TaskService (org.camunda.bpm.engine.TaskService)5 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)5 Batch (org.camunda.bpm.engine.batch.Batch)4 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)4 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)4 Task (org.camunda.bpm.engine.task.Task)4 ArrayList (java.util.ArrayList)3 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)3 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)3 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)3 ProcessEngineServices (org.camunda.bpm.engine.ProcessEngineServices)3 RepositoryService (org.camunda.bpm.engine.RepositoryService)3 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)3 ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)3