Search in sources :

Example 1 with CaseInstanceDto

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

the class CaseInstanceRestServiceImpl method queryCaseInstances.

public List<CaseInstanceDto> queryCaseInstances(CaseInstanceQueryDto queryDto, Integer firstResult, Integer maxResults) {
    ProcessEngine engine = getProcessEngine();
    queryDto.setObjectMapper(getObjectMapper());
    CaseInstanceQuery query = queryDto.toQuery(engine);
    List<CaseInstance> matchingInstances;
    if (firstResult != null || maxResults != null) {
        matchingInstances = executePaginatedQuery(query, firstResult, maxResults);
    } else {
        matchingInstances = query.list();
    }
    List<CaseInstanceDto> instanceResults = new ArrayList<CaseInstanceDto>();
    for (CaseInstance instance : matchingInstances) {
        CaseInstanceDto resultInstance = CaseInstanceDto.fromCaseInstance(instance);
        instanceResults.add(resultInstance);
    }
    return instanceResults;
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) ArrayList(java.util.ArrayList) CaseInstanceQuery(org.camunda.bpm.engine.runtime.CaseInstanceQuery) CaseInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.CaseInstanceDto) ProcessEngine(org.camunda.bpm.engine.ProcessEngine)

Example 2 with CaseInstanceDto

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

the class CaseInstanceResourceImpl method getCaseInstance.

public CaseInstanceDto getCaseInstance() {
    CaseService caseService = engine.getCaseService();
    CaseInstance instance = caseService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();
    if (instance == null) {
        throw new InvalidRequestException(Status.NOT_FOUND, "Case instance with id " + caseInstanceId + " does not exist.");
    }
    CaseInstanceDto result = CaseInstanceDto.fromCaseInstance(instance);
    return result;
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) CaseService(org.camunda.bpm.engine.CaseService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) CaseInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.CaseInstanceDto)

Example 3 with CaseInstanceDto

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

the class CaseDefinitionResourceImpl method createCaseInstance.

public CaseInstanceDto createCaseInstance(UriInfo context, CreateCaseInstanceDto parameters) {
    CaseService caseService = engine.getCaseService();
    CaseInstance instance = null;
    try {
        String businessKey = parameters.getBusinessKey();
        VariableMap variables = VariableValueDto.toMap(parameters.getVariables(), engine, objectMapper);
        instance = caseService.withCaseDefinition(caseDefinitionId).businessKey(businessKey).setVariables(variables).create();
    } catch (RestException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new InvalidRequestException(e.getStatus(), e, errorMessage);
    } catch (NotFoundException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new InvalidRequestException(Status.NOT_FOUND, e, errorMessage);
    } catch (NotValidException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new InvalidRequestException(Status.BAD_REQUEST, e, errorMessage);
    } catch (NotAllowedException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new InvalidRequestException(Status.FORBIDDEN, e, errorMessage);
    } catch (ProcessEngineException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
    }
    CaseInstanceDto result = CaseInstanceDto.fromCaseInstance(instance);
    URI uri = context.getBaseUriBuilder().path(rootResourcePath).path(CaseInstanceRestService.PATH).path(instance.getId()).build();
    result.addReflexiveLink(uri, HttpMethod.GET, "self");
    return result;
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) NotValidException(org.camunda.bpm.engine.exception.NotValidException) NotAllowedException(org.camunda.bpm.engine.exception.NotAllowedException) VariableMap(org.camunda.bpm.engine.variable.VariableMap) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) CaseService(org.camunda.bpm.engine.CaseService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) CreateCaseInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.CreateCaseInstanceDto) CaseInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.CaseInstanceDto) URI(java.net.URI) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Aggregations

CaseInstanceDto (org.camunda.bpm.engine.rest.dto.runtime.CaseInstanceDto)3 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)3 CaseService (org.camunda.bpm.engine.CaseService)2 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 NotAllowedException (org.camunda.bpm.engine.exception.NotAllowedException)1 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)1 NotValidException (org.camunda.bpm.engine.exception.NotValidException)1 CreateCaseInstanceDto (org.camunda.bpm.engine.rest.dto.runtime.CreateCaseInstanceDto)1 RestException (org.camunda.bpm.engine.rest.exception.RestException)1 CaseInstanceQuery (org.camunda.bpm.engine.runtime.CaseInstanceQuery)1 VariableMap (org.camunda.bpm.engine.variable.VariableMap)1