Search in sources :

Example 6 with ProcessInstanceList

use of org.kie.server.api.model.instance.ProcessInstanceList in project droolsjbpm-integration by kiegroup.

the class ProcessResource method getProcessInstancesByDeploymentId.

@ApiOperation(value = "Returns a list of process instances in a specified KIE container.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Container Id not found"), @ApiResponse(code = 200, response = ProcessInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_INSTANCES_RESPONSE_JSON) })) })
@GET
@Path(PROCESS_INSTANCES_BY_CONTAINER_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessInstancesByDeploymentId(@Context HttpHeaders headers, @ApiParam(value = "container id that process instance belongs to", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "optional process instance status (active, completed, aborted) - defaults ot active (1) only", required = false, allowableValues = "1,2,3") @QueryParam("status") List<Integer> status, @ApiParam(value = "optional pagination - at which page to start, defaults to 0 (meaning first)", required = false) @QueryParam("page") @DefaultValue("0") Integer page, @ApiParam(value = "optional pagination - size of the result, defaults to 10", required = false) @QueryParam("pageSize") @DefaultValue("10") Integer pageSize, @ApiParam(value = "optional sort column, no default", required = false) @QueryParam("sort") String sort, @ApiParam(value = "optional sort direction (asc, desc) - defaults to asc", required = false) @QueryParam("sortOrder") @DefaultValue("true") boolean sortOrder) {
    Variant v = getVariant(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
    try {
        ProcessInstanceList processInstanceList = runtimeDataServiceBase.getProcessInstancesByDeploymentId(containerId, status, page, pageSize, sort, sortOrder);
        logger.debug("Returning result of process instance search: {}", processInstanceList);
        return createCorrectVariant(processInstanceList, headers, Response.Status.OK, conversationIdHeader);
    } catch (DeploymentNotFoundException e) {
        return notFound(MessageFormat.format(CONTAINER_NOT_FOUND, containerId), v, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(errorMessage(e), v, conversationIdHeader);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) DeploymentNotActiveException(org.jbpm.services.api.DeploymentNotActiveException) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with ProcessInstanceList

use of org.kie.server.api.model.instance.ProcessInstanceList in project droolsjbpm-integration by kiegroup.

the class RuntimeDataResource method getProcessInstances.

@ApiOperation(value = "Returns all process instances filtered by optional parameters.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, message = "Successful response", response = ProcessInstanceList.class, examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_INSTANCES_RESPONSE_JSON) })) })
@GET
@Path(PROCESS_INSTANCES_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessInstances(@Context HttpHeaders headers, @ApiParam(value = "optional process instance status (active, completed, aborted) - defaults ot active (1) only", required = false, allowableValues = "1,2,3") @QueryParam("status") List<Integer> status, @ApiParam(value = "optional process instance initiator - user who started process instance to filter process instances", required = false) @QueryParam("initiator") String initiator, @ApiParam(value = "optional process name to filter process instances", required = false) @QueryParam("processName") String processName, @ApiParam(value = "optional pagination - at which page to start, defaults to 0 (meaning first)", required = false) @QueryParam("page") @DefaultValue("0") Integer page, @ApiParam(value = "optional pagination - size of the result, defaults to 10", required = false) @QueryParam("pageSize") @DefaultValue("10") Integer pageSize, @ApiParam(value = "optional sort column, no default", required = false) @QueryParam("sort") String sort, @ApiParam(value = "optional sort direction (asc, desc) - defaults to asc", required = false) @QueryParam("sortOrder") @DefaultValue("true") boolean sortOrder) {
    // no container id available so only used to transfer conversation id if given by client
    Header conversationIdHeader = buildConversationIdHeader("", context, headers);
    ProcessInstanceList processInstanceList = runtimeDataServiceBase.getProcessInstances(status, initiator, processName, page, pageSize, sort, sortOrder);
    logger.debug("Returning result of process instance search: {}", processInstanceList);
    return createCorrectVariant(processInstanceList, headers, Response.Status.OK, conversationIdHeader);
}
Also used : ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 8 with ProcessInstanceList

use of org.kie.server.api.model.instance.ProcessInstanceList in project droolsjbpm-integration by kiegroup.

the class RuntimeDataResource method getProcessInstancesByProcessId.

@ApiOperation(value = "Returns all process instances for a specified process.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = ProcessInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_INSTANCES_RESPONSE_JSON) })) })
@GET
@Path(PROCESS_INSTANCES_BY_PROCESS_ID_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessInstancesByProcessId(@Context HttpHeaders headers, @ApiParam(value = "process id to filter process instance", required = true) @PathParam(PROCESS_ID) String processId, @ApiParam(value = "optional process instance status (active, completed, aborted) - defaults ot active (1) only", required = false, allowableValues = "1,2,3") @QueryParam("status") List<Integer> status, @ApiParam(value = "optinal process instance initiator - user who started process instance to filtr process instances", required = false) @QueryParam("initiator") String initiator, @ApiParam(value = "optional pagination - at which page to start, defaults to 0 (meaning first)", required = false) @QueryParam("page") @DefaultValue("0") Integer page, @ApiParam(value = "optional pagination - size of the result, defaults to 10", required = false) @QueryParam("pageSize") @DefaultValue("10") Integer pageSize, @ApiParam(value = "optional sort column, no default", required = false) @QueryParam("sort") String sort, @ApiParam(value = "optional sort direction (asc, desc) - defaults to asc", required = false) @QueryParam("sortOrder") @DefaultValue("true") boolean sortOrder) {
    // no container id available so only used to transfer conversation id if given by client
    Header conversationIdHeader = buildConversationIdHeader("", context, headers);
    ProcessInstanceList processInstanceList = runtimeDataServiceBase.getProcessInstancesByProcessId(processId, status, initiator, page, pageSize, sort, sortOrder);
    logger.debug("Returning result of process instance search: {}", processInstanceList);
    return createCorrectVariant(processInstanceList, headers, Response.Status.OK, conversationIdHeader);
}
Also used : ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 9 with ProcessInstanceList

use of org.kie.server.api.model.instance.ProcessInstanceList in project droolsjbpm-integration by kiegroup.

the class ProcessServiceRestOnlyIntegrationTest method testProcessWhichBelongsToAContainer.

@Test
public void testProcessWhichBelongsToAContainer() {
    Map<String, Object> valuesMap = new HashMap<String, Object>();
    valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
    valuesMap.put(RestURI.PROCESS_ID, PROCESS_ID_USERTASK);
    Response response = null;
    try {
        // start process instance
        WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + START_PROCESS_POST_URI, valuesMap));
        logger.debug("[POST] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).post(createEntity(""));
        assertThat(response.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode());
        Long pid = response.readEntity(JaxbLong.class).unwrap();
        assertThat(pid).isNotNull();
        response.close();
        // find process instances which are deployed in the given container
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCES_BY_CONTAINER_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        Marshaller marshaller = MarshallerFactory.getMarshaller(marshallingFormat, Thread.currentThread().getContextClassLoader());
        ProcessInstanceList processInstanceList = marshaller.unmarshall(response.readEntity(String.class), ProcessInstanceList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        assertThat(processInstanceList.getItems()).hasSize(1);
        response.close();
        // find process instances of non-existing container
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, NON_EXISTING_CONTAINER_ID);
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCES_BY_CONTAINER_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        assertThat(response.readEntity(String.class)).contains(NON_EXISTING_CONTAINER_ID);
        assertThat(response.getStatus()).isEqualTo(Response.Status.NOT_FOUND.getStatusCode());
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) JaxbLong(org.kie.server.api.model.type.JaxbLong) WebTarget(javax.ws.rs.client.WebTarget) JaxbLong(org.kie.server.api.model.type.JaxbLong) Test(org.junit.Test)

Example 10 with ProcessInstanceList

use of org.kie.server.api.model.instance.ProcessInstanceList in project droolsjbpm-integration by kiegroup.

the class CaseServicesClientImpl method getProcessInstances.

@Override
public List<ProcessInstance> getProcessInstances(String containerId, String caseId, List<Integer> status, Integer page, Integer pageSize, String sort, boolean sortOrder) {
    ProcessInstanceList list = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(CASE_ID, caseId);
        String queryString = getPagingQueryString("", page, pageSize);
        queryString = getAdditionalParams(queryString, "status", status);
        queryString = getSortingQueryString(queryString, sort, sortOrder);
        list = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), CASE_URI + "/" + CASE_PROCESS_INSTANCES_GET_URI, valuesMap) + queryString, ProcessInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseQueryService", "getProcessInstancesForCase", new Object[] { containerId, caseId, safeList(status), page, pageSize, sort, sortOrder })));
        ServiceResponse<ProcessInstanceList> response = (ServiceResponse<ProcessInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        list = response.getResult();
    }
    if (list != null) {
        return list.getItems();
    }
    return Collections.emptyList();
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Aggregations

ProcessInstanceList (org.kie.server.api.model.instance.ProcessInstanceList)34 HashMap (java.util.HashMap)15 CommandScript (org.kie.server.api.commands.CommandScript)14 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)14 KieServerCommand (org.kie.server.api.model.KieServerCommand)14 ServiceResponse (org.kie.server.api.model.ServiceResponse)14 GET (javax.ws.rs.GET)9 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiResponses (io.swagger.annotations.ApiResponses)8 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)8 Header (org.kie.server.remote.rest.common.Header)8 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)7 ConvertUtils.convertToProcessInstanceList (org.kie.server.services.jbpm.ConvertUtils.convertToProcessInstanceList)6 ArrayList (java.util.ArrayList)5 Variant (javax.ws.rs.core.Variant)4 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)4 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)3 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)2