Exemplo n.º 1
0
        public virtual IList <CaseInstanceDto> queryCaseInstances(CaseInstanceQueryDto queryDto, int?firstResult, int?maxResults)
        {
            ProcessEngine engine = ProcessEngine;

            queryDto.ObjectMapper = ObjectMapper;
            CaseInstanceQuery query = queryDto.toQuery(engine);

            IList <CaseInstance> matchingInstances;

            if (firstResult != null || maxResults != null)
            {
                matchingInstances = executePaginatedQuery(query, firstResult, maxResults);
            }
            else
            {
                matchingInstances = query.list();
            }

            IList <CaseInstanceDto> instanceResults = new List <CaseInstanceDto>();

            foreach (CaseInstance instance in matchingInstances)
            {
                CaseInstanceDto resultInstance = CaseInstanceDto.fromCaseInstance(instance);
                instanceResults.Add(resultInstance);
            }
            return(instanceResults);
        }
Exemplo n.º 2
0
        public virtual CaseInstanceDto createCaseInstance(UriInfo context, CreateCaseInstanceDto parameters)
        {
            CaseService caseService = engine.CaseService;

            CaseInstance instance = null;

            try
            {
                string      businessKey = parameters.BusinessKey;
                VariableMap variables   = VariableValueDto.toMap(parameters.Variables, engine, objectMapper);

                instance = caseService.withCaseDefinition(caseDefinitionId).businessKey(businessKey).setVariables(variables).create();
            }
            catch (RestException e)
            {
                string errorMessage = string.Format("Cannot instantiate case definition {0}: {1}", caseDefinitionId, e.Message);
                throw new InvalidRequestException(e.Status, e, errorMessage);
            }
            catch (NotFoundException e)
            {
                string errorMessage = string.Format("Cannot instantiate case definition {0}: {1}", caseDefinitionId, e.Message);
                throw new InvalidRequestException(Response.Status.NOT_FOUND, e, errorMessage);
            }
            catch (NotValidException e)
            {
                string errorMessage = string.Format("Cannot instantiate case definition {0}: {1}", caseDefinitionId, e.Message);
                throw new InvalidRequestException(Response.Status.BAD_REQUEST, e, errorMessage);
            }
            catch (NotAllowedException e)
            {
                string errorMessage = string.Format("Cannot instantiate case definition {0}: {1}", caseDefinitionId, e.Message);
                throw new InvalidRequestException(Response.Status.FORBIDDEN, e, errorMessage);
            }
            catch (ProcessEngineException e)
            {
                string errorMessage = string.Format("Cannot instantiate case definition {0}: {1}", caseDefinitionId, e.Message);
                throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e, errorMessage);
            }

            CaseInstanceDto result = CaseInstanceDto.fromCaseInstance(instance);

            URI uri = context.BaseUriBuilder.path(rootResourcePath).path(org.camunda.bpm.engine.rest.CaseInstanceRestService_Fields.PATH).path(instance.Id).build();

            result.addReflexiveLink(uri, HttpMethod.GET, "self");

            return(result);
        }