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());
}
}
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;
}
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());
}
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();
}
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);
}
Aggregations