Search in sources :

Example 1 with CountDefinition

use of org.kie.server.api.model.definition.CountDefinition in project droolsjbpm-integration by kiegroup.

the class QueryServicesClientImpl method countProcessInstancesByContainerId.

public Long countProcessInstancesByContainerId(String containerId, List<Integer> status) {
    CountDefinition result;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<>();
        valuesMap.put(CONTAINER_ID, containerId);
        String queryString = getAdditionalParams("", "status", status);
        result = makeHttpGetRequestAndCreateCustomResponseWithHandleNotFound(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_INSTANCES_BY_CONTAINER_ID_COUNT_URI, valuesMap) + queryString, CountDefinition.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList(new DescriptorCommand("QueryService", "countProcessInstancesByDeploymentId", new Object[] { containerId, safeList(status) })));
        ServiceResponse<CountDefinition> response = (ServiceResponse<CountDefinition>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    if (result != null) {
        return result.getCount();
    }
    return null;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) HashMap(java.util.HashMap) CountDefinition(org.kie.server.api.model.definition.CountDefinition) CommandScript(org.kie.server.api.commands.CommandScript)

Example 2 with CountDefinition

use of org.kie.server.api.model.definition.CountDefinition in project droolsjbpm-integration by kiegroup.

the class RuntimeDataResource method countProcessInstancesByDeploymentId.

@ApiOperation(value = "Returns the count of all process instances for a specified KIE container.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Container Id not found"), @ApiResponse(code = 200, response = CountDefinition.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = COUNT_PROCESS_INSTANCES_RESPONSE_JSON) })) })
@GET
@Path(PROCESS_INSTANCES_BY_CONTAINER_ID_COUNT_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response countProcessInstancesByDeploymentId(@Context HttpHeaders headers, @ApiParam(value = "container id to filter process instance", required = true) @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) {
    // no container id available so only used to transfer conversation id if given by client
    Header conversationIdHeader = buildConversationIdHeader("", context, headers);
    Variant v = getVariant(headers);
    try {
        CountDefinition count = runtimeDataServiceBase.countProcessInstancesByDeploymentId(containerId, status);
        logger.debug("Returning result of process instance count: {}", count);
        return createCorrectVariant(count, 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) 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) CountDefinition(org.kie.server.api.model.definition.CountDefinition) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) 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)

Aggregations

CountDefinition (org.kie.server.api.model.definition.CountDefinition)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Variant (javax.ws.rs.core.Variant)1 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)1 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)1 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)1 CommandScript (org.kie.server.api.commands.CommandScript)1 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)1 ServiceResponse (org.kie.server.api.model.ServiceResponse)1 Header (org.kie.server.remote.rest.common.Header)1 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)1 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)1 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)1