Search in sources :

Example 26 with RuntimeService

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

the class ProcessDefinitionResourceImpl method createRestartProcessInstanceBuilder.

private RestartProcessInstanceBuilder createRestartProcessInstanceBuilder(RestartProcessInstanceDto restartProcessInstanceDto) {
    RuntimeService runtimeService = engine.getRuntimeService();
    RestartProcessInstanceBuilder builder = runtimeService.restartProcessInstances(processDefinitionId);
    if (restartProcessInstanceDto.getProcessInstanceIds() != null) {
        builder.processInstanceIds(restartProcessInstanceDto.getProcessInstanceIds());
    }
    if (restartProcessInstanceDto.getHistoricProcessInstanceQuery() != null) {
        builder.historicProcessInstanceQuery(restartProcessInstanceDto.getHistoricProcessInstanceQuery().toQuery(engine));
    }
    if (restartProcessInstanceDto.isInitialVariables()) {
        builder.initialSetOfVariables();
    }
    if (restartProcessInstanceDto.isWithoutBusinessKey()) {
        builder.withoutBusinessKey();
    }
    if (restartProcessInstanceDto.isSkipCustomListeners()) {
        builder.skipCustomListeners();
    }
    if (restartProcessInstanceDto.isSkipIoMappings()) {
        builder.skipIoMappings();
    }
    restartProcessInstanceDto.applyTo(builder, engine, objectMapper);
    return builder;
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) RestartProcessInstanceBuilder(org.camunda.bpm.engine.runtime.RestartProcessInstanceBuilder)

Example 27 with RuntimeService

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

the class ProcessInstanceResourceImpl method getProcessInstance.

@Override
public ProcessInstanceDto getProcessInstance() {
    RuntimeService runtimeService = engine.getRuntimeService();
    ProcessInstance instance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    if (instance == null) {
        throw new InvalidRequestException(Status.NOT_FOUND, "Process instance with id " + processInstanceId + " does not exist");
    }
    ProcessInstanceDto result = ProcessInstanceDto.fromProcessInstance(instance);
    return result;
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) ProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 28 with RuntimeService

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

the class ProcessInstanceResourceImpl method getActivityInstanceTree.

@Override
public ActivityInstanceDto getActivityInstanceTree() {
    RuntimeService runtimeService = engine.getRuntimeService();
    ActivityInstance activityInstance = null;
    try {
        activityInstance = runtimeService.getActivityInstance(processInstanceId);
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        throw new InvalidRequestException(Status.INTERNAL_SERVER_ERROR, e, e.getMessage());
    }
    if (activityInstance == null) {
        throw new InvalidRequestException(Status.NOT_FOUND, "Process instance with id " + processInstanceId + " does not exist");
    }
    ActivityInstanceDto result = ActivityInstanceDto.fromActivityInstance(activityInstance);
    return result;
}
Also used : ActivityInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.ActivityInstanceDto) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) RuntimeService(org.camunda.bpm.engine.RuntimeService) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 29 with RuntimeService

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

the class MessageEventSubscriptionResource method triggerEvent.

@Override
public void triggerEvent(ExecutionTriggerDto triggerDto) {
    RuntimeService runtimeService = engine.getRuntimeService();
    try {
        VariableMap variables = VariableValueDto.toMap(triggerDto.getVariables(), engine, objectMapper);
        runtimeService.messageEventReceived(messageName, executionId, variables);
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, String.format("Cannot trigger message %s for execution %s: %s", messageName, executionId, e.getMessage()));
    } catch (RestException e) {
        String errorMessage = String.format("Cannot trigger message %s for execution %s: %s", messageName, executionId, e.getMessage());
        throw new InvalidRequestException(e.getStatus(), e, errorMessage);
    }
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) VariableMap(org.camunda.bpm.engine.variable.VariableMap) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 30 with RuntimeService

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

the class ExecutionResourceImpl method signalExecution.

@Override
public void signalExecution(ExecutionTriggerDto triggerDto) {
    RuntimeService runtimeService = engine.getRuntimeService();
    try {
        VariableMap variables = VariableValueDto.toMap(triggerDto.getVariables(), engine, objectMapper);
        runtimeService.signal(executionId, variables);
    } catch (RestException e) {
        String errorMessage = String.format("Cannot signal execution %s: %s", executionId, e.getMessage());
        throw new InvalidRequestException(e.getStatus(), e, errorMessage);
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, "Cannot signal execution " + executionId + ": " + e.getMessage());
    }
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) VariableMap(org.camunda.bpm.engine.variable.VariableMap) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

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