Search in sources :

Example 1 with ProcessInstanceDto

use of org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto in project camunda-bpm-platform by camunda.

the class ProcessDefinitionResourceImpl method submitForm.

@Override
public ProcessInstanceDto submitForm(UriInfo context, StartProcessInstanceDto parameters) {
    FormService formService = engine.getFormService();
    ProcessInstance instance = null;
    try {
        Map<String, Object> variables = VariableValueDto.toMap(parameters.getVariables(), engine, objectMapper);
        String businessKey = parameters.getBusinessKey();
        if (businessKey != null) {
            instance = formService.submitStartForm(processDefinitionId, businessKey, variables);
        } else {
            instance = formService.submitStartForm(processDefinitionId, variables);
        }
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
    } catch (RestException e) {
        String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
        throw new InvalidRequestException(e.getStatus(), e, errorMessage);
    }
    ProcessInstanceDto result = ProcessInstanceDto.fromProcessInstance(instance);
    URI uri = context.getBaseUriBuilder().path(rootResourcePath).path(ProcessInstanceRestService.PATH).path(instance.getId()).build();
    result.addReflexiveLink(uri, HttpMethod.GET, "self");
    return result;
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestartProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.RestartProcessInstanceDto) ProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto) StartProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.StartProcessInstanceDto) FormService(org.camunda.bpm.engine.FormService) RestException(org.camunda.bpm.engine.rest.exception.RestException) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) URI(java.net.URI) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 2 with ProcessInstanceDto

use of org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto in project camunda-bpm-platform by camunda.

the class ProcessDefinitionResourceImpl method startProcessInstance.

@Override
public ProcessInstanceDto startProcessInstance(UriInfo context, StartProcessInstanceDto parameters) {
    ProcessInstanceWithVariables instance = null;
    try {
        instance = startProcessInstanceAtActivities(parameters);
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
    } catch (RestException e) {
        String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
        throw new InvalidRequestException(e.getStatus(), e, errorMessage);
    }
    ProcessInstanceDto result;
    if (parameters.isWithVariablesInReturn()) {
        result = ProcessInstanceWithVariablesDto.fromProcessInstance(instance);
    } else {
        result = ProcessInstanceDto.fromProcessInstance(instance);
    }
    URI uri = context.getBaseUriBuilder().path(rootResourcePath).path(ProcessInstanceRestService.PATH).path(instance.getId()).build();
    result.addReflexiveLink(uri, HttpMethod.GET, "self");
    return result;
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestartProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.RestartProcessInstanceDto) ProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto) StartProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.StartProcessInstanceDto) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessInstanceWithVariables(org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables) URI(java.net.URI) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 3 with ProcessInstanceDto

use of org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto 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 4 with ProcessInstanceDto

use of org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto in project camunda-bpm-platform by camunda.

the class ProcessInstanceRestServiceImpl method queryProcessInstances.

@Override
public List<ProcessInstanceDto> queryProcessInstances(ProcessInstanceQueryDto queryDto, Integer firstResult, Integer maxResults) {
    ProcessEngine engine = getProcessEngine();
    queryDto.setObjectMapper(getObjectMapper());
    ProcessInstanceQuery query = queryDto.toQuery(engine);
    List<ProcessInstance> matchingInstances;
    if (firstResult != null || maxResults != null) {
        matchingInstances = executePaginatedQuery(query, firstResult, maxResults);
    } else {
        matchingInstances = query.list();
    }
    List<ProcessInstanceDto> instanceResults = new ArrayList<ProcessInstanceDto>();
    for (ProcessInstance instance : matchingInstances) {
        ProcessInstanceDto resultInstance = ProcessInstanceDto.fromProcessInstance(instance);
        instanceResults.add(resultInstance);
    }
    return instanceResults;
}
Also used : HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) ProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto) ArrayList(java.util.ArrayList) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngine(org.camunda.bpm.engine.ProcessEngine)

Example 5 with ProcessInstanceDto

use of org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto in project camunda-bpm-platform by camunda.

the class ConditionRestServiceImpl method evaluateCondition.

@Override
public List<ProcessInstanceDto> evaluateCondition(EvaluationConditionDto conditionDto) {
    if (conditionDto.getTenantId() != null && conditionDto.isWithoutTenantId()) {
        throw new InvalidRequestException(Status.BAD_REQUEST, "Parameter 'tenantId' cannot be used together with parameter 'withoutTenantId'.");
    }
    ConditionEvaluationBuilder builder = createConditionEvaluationBuilder(conditionDto);
    List<ProcessInstance> processInstances = builder.evaluateStartConditions();
    List<ProcessInstanceDto> result = new ArrayList<ProcessInstanceDto>();
    for (ProcessInstance processInstance : processInstances) {
        result.add(ProcessInstanceDto.fromProcessInstance(processInstance));
    }
    return result;
}
Also used : ProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto) ConditionEvaluationBuilder(org.camunda.bpm.engine.runtime.ConditionEvaluationBuilder) ArrayList(java.util.ArrayList) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance)

Aggregations

ProcessInstanceDto (org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto)5 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)4 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)4 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 RestartProcessInstanceDto (org.camunda.bpm.engine.rest.dto.runtime.RestartProcessInstanceDto)2 StartProcessInstanceDto (org.camunda.bpm.engine.rest.dto.runtime.StartProcessInstanceDto)2 RestException (org.camunda.bpm.engine.rest.exception.RestException)2 FormService (org.camunda.bpm.engine.FormService)1 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)1 RuntimeService (org.camunda.bpm.engine.RuntimeService)1 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)1 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)1 ConditionEvaluationBuilder (org.camunda.bpm.engine.runtime.ConditionEvaluationBuilder)1 ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)1 ProcessInstanceWithVariables (org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables)1