Search in sources :

Example 16 with RequestInfoInstanceList

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

the class ExecutorServiceBase method getRequestsByStatus.

// queries
public RequestInfoInstanceList getRequestsByStatus(List<String> statuses, Integer page, Integer pageSize) {
    List<STATUS> statusList = convertStatusList(statuses);
    List<RequestInfo> requests = executorService.getRequestsByStatus(statusList, buildQueryContext(page, pageSize));
    RequestInfoInstanceList result = convertToRequestInfoList(requests, false, false);
    return result;
}
Also used : STATUS(org.kie.api.executor.STATUS) RequestInfoInstanceList(org.kie.server.api.model.instance.RequestInfoInstanceList) RequestInfo(org.kie.api.executor.RequestInfo)

Example 17 with RequestInfoInstanceList

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

the class ExecutorResource method getRequestsByContainer.

@ApiOperation(value = "Returns jobs for specified KIE container.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = RequestInfoInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_REQUESTS_RESPONSE_JSON) })) })
@GET
@Path(JOB_INSTANCES_BY_CONTAINER_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getRequestsByContainer(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "identifier of the container that asynchornous jobs should be found for", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "optional job status (QUEUED, DONE, CANCELLED, ERROR, RETRYING, RUNNING)", required = false, allowableValues = "QUEUED,DONE,CANCELLED,ERROR,RETRYING,RUNNING") @QueryParam("status") List<String> statuses, @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) {
    Variant v = getVariant(headers);
    // no container id available so only used to transfer conversation id if given by client
    Header conversationIdHeader = buildConversationIdHeader("", context, headers);
    try {
        RequestInfoInstanceList result = executorServiceBase.getRequestsByContainer(containerId, statuses, page, pageSize);
        return createCorrectVariant(result, headers, Response.Status.OK, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(errorMessage(e), v, conversationIdHeader);
    }
}
Also used : RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) RequestInfoInstanceList(org.kie.server.api.model.instance.RequestInfoInstanceList) 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 18 with RequestInfoInstanceList

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

the class ExecutorResource method getRequestsByCommand.

@ApiOperation(value = "Returns jobs configured to run job commands, such as a job type org.jbpm.executor.commands.LogCleanupCommand.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = RequestInfoInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_REQUESTS_RESPONSE_JSON) })) })
@GET
@Path(JOB_INSTANCES_BY_CMD_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getRequestsByCommand(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "name of the command that asynchornous jobs should be found for", required = true, example = "com.sample.CommandImpl") @PathParam("cmd") String command, @ApiParam(value = "optional job status (QUEUED, DONE, CANCELLED, ERROR, RETRYING, RUNNING)", required = false, allowableValues = "QUEUED,DONE,CANCELLED,ERROR,RETRYING,RUNNING") @QueryParam("status") List<String> statuses, @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) {
    Variant v = getVariant(headers);
    // no container id available so only used to transfer conversation id if given by client
    Header conversationIdHeader = buildConversationIdHeader("", context, headers);
    try {
        RequestInfoInstanceList result = null;
        if (statuses == null || statuses.isEmpty()) {
            result = executorServiceBase.getRequestsByCommand(command, page, pageSize);
        } else {
            result = executorServiceBase.getRequestsByCommand(command, statuses, page, pageSize);
        }
        return createCorrectVariant(result, headers, Response.Status.OK, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(errorMessage(e), v, conversationIdHeader);
    }
}
Also used : RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) RequestInfoInstanceList(org.kie.server.api.model.instance.RequestInfoInstanceList) 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 19 with RequestInfoInstanceList

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

the class JobServicesClientImpl method getRequestsByProcessInstance.

@Override
public List<RequestInfoInstance> getRequestsByProcessInstance(Long processInstanceId, List<String> statuses, Integer page, Integer pageSize) {
    RequestInfoInstanceList list = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(PROCESS_INST_ID, processInstanceId);
        String statusQuery = getAdditionalParams("", "status", statuses);
        String queryString = getPagingQueryString(statusQuery, page, pageSize);
        list = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), JOB_URI + "/" + JOB_INSTANCES_BY_PROCESS_INSTANCE_GET_URI, valuesMap) + queryString, RequestInfoInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("JobService", "getRequestsByProcessInstance", new Object[] { processInstanceId, safeList(statuses), page, pageSize })));
        ServiceResponse<RequestInfoInstanceList> response = (ServiceResponse<RequestInfoInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        list = response.getResult();
    }
    if (list != null && list.getRequestInfoInstances() != null) {
        return Arrays.asList(list.getRequestInfoInstances());
    }
    return Collections.emptyList();
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) RequestInfoInstanceList(org.kie.server.api.model.instance.RequestInfoInstanceList) CommandScript(org.kie.server.api.commands.CommandScript)

Example 20 with RequestInfoInstanceList

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

the class JobServicesClientImpl method getRequestsByBusinessKey.

@Override
public List<RequestInfoInstance> getRequestsByBusinessKey(String businessKey, List<String> statuses, Integer page, Integer pageSize) {
    RequestInfoInstanceList list = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(JOB_KEY, businessKey);
        String statusQuery = getAdditionalParams("", "status", statuses);
        String queryString = getPagingQueryString(statusQuery, page, pageSize);
        list = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), JOB_URI + "/" + JOB_INSTANCES_BY_KEY_GET_URI, valuesMap) + queryString, RequestInfoInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("JobService", "getRequestsByBusinessKey", new Object[] { businessKey, safeList(statuses), page, pageSize })));
        ServiceResponse<RequestInfoInstanceList> response = (ServiceResponse<RequestInfoInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        list = response.getResult();
    }
    if (list != null && list.getRequestInfoInstances() != null) {
        return Arrays.asList(list.getRequestInfoInstances());
    }
    return Collections.emptyList();
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) RequestInfoInstanceList(org.kie.server.api.model.instance.RequestInfoInstanceList) CommandScript(org.kie.server.api.commands.CommandScript)

Aggregations

RequestInfoInstanceList (org.kie.server.api.model.instance.RequestInfoInstanceList)21 RequestInfo (org.kie.api.executor.RequestInfo)8 ServiceResponse (org.kie.server.api.model.ServiceResponse)8 HashMap (java.util.HashMap)7 CommandScript (org.kie.server.api.commands.CommandScript)7 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)7 KieServerCommand (org.kie.server.api.model.KieServerCommand)7 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 GET (javax.ws.rs.GET)5 Produces (javax.ws.rs.Produces)5 Variant (javax.ws.rs.core.Variant)5 STATUS (org.kie.api.executor.STATUS)5 Header (org.kie.server.remote.rest.common.Header)5 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)5 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)5 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)5 Path (javax.ws.rs.Path)4 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 KieServerInfo (org.kie.server.api.model.KieServerInfo)1