Search in sources :

Example 31 with ProcessInstanceList

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

the class ProcessResource method getProcessInstances.

@ApiOperation(value = "Returns a list of process instances for which a specified process instance is a parent process instance")
@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_PARENT_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessInstances(@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 = "identifier of the parent process instance that process instances should be collected for", required = true, example = "123") @PathParam(PROCESS_INST_ID) long parentProcessInstanceId, @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) {
    Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
    ProcessInstanceList processInstanceList = processServiceBase.getProcessInstancesByParent(parentProcessInstanceId, status, 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 32 with ProcessInstanceList

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

the class RuntimeDataResource method getProcessInstancesByDeploymentId.

@ApiOperation(value = "Returns 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 = ProcessInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_INSTANCES_RESPONSE_JSON) })) })
@GET
@Path(PROCESS_INSTANCES_BY_CONTAINER_ID_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessInstancesByDeploymentId(@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, @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);
    Variant v = getVariant(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) 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)

Example 33 with ProcessInstanceList

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

the class CaseManagementRuntimeDataServiceBase method getProcessInstancesForCase.

public ProcessInstanceList getProcessInstancesForCase(String containerId, String caseId, List<Integer> status, Integer page, Integer pageSize, String sort, boolean sortOrder) {
    status = safeProcessStatus(status);
    sort = safeProcessInstanceSort(sort);
    Collection<ProcessInstanceDesc> processInstanceDescs = caseRuntimeDataService.getProcessInstancesForCase(caseId, status, ConvertUtils.buildQueryContext(page, pageSize, sort, sortOrder));
    List<ProcessInstance> processInstances = ConvertUtils.transformProcessInstance(processInstanceDescs);
    ProcessInstanceList processInstancesList = new ProcessInstanceList(processInstances);
    return processInstancesList;
}
Also used : ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance)

Example 34 with ProcessInstanceList

use of org.kie.server.api.model.instance.ProcessInstanceList in project businessautomation-cop by redhat-cop.

the class CustomResource method insertFireReturn.

@GET
@Path("/{aliasId}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response insertFireReturn(@Context HttpHeaders headers, @PathParam("aliasId") String alias) {
    Variant v = getVariant(headers);
    String contentType = getContentType(headers);
    MarshallingFormat format = MarshallingFormat.fromType(contentType);
    if (format == null) {
        format = MarshallingFormat.valueOf(contentType);
    }
    MarshallerHelper marshallerHelper = new MarshallerHelper(context);
    try {
        // get all the containers with the given alias
        List<KieContainerInstanceImpl> filteredContainers = context.getContainersForAlias(alias);
        List<ProcessInstance> instances = new ArrayList<ProcessInstance>();
        // for each container obtain a list of active process instances
        filteredContainers.forEach(container -> {
            String containerId = container.getContainerId();
            ProcessInstanceList instanceList = runtimeDataService.getProcessInstancesByDeploymentId(containerId, Arrays.asList(1), 0, 0, "", true);
            logger.debug("Found " + instanceList.getItems().size() + " active process instances  in container with id " + containerId);
            instances.addAll(instanceList.getItems());
        });
        // return the list to the client
        ProcessInstanceList finalList = new ProcessInstanceList(instances);
        String result = marshallerHelper.marshal(format.toString(), finalList);
        logger.debug("Returning OK response with content '{}'", result);
        return createResponse(result, v, Response.Status.OK);
    } catch (Exception e) {
        // in case marshalling failed return the call container response to keep
        // backward compatibility
        String response = "Execution failed with error : " + e.getMessage();
        logger.debug("Returning Failure response with content '{}'", response);
        return createResponse(response, v, Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : RESTUtils.getVariant(org.redhat.gss.extension.RESTUtils.getVariant) Variant(javax.ws.rs.core.Variant) ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) MarshallerHelper(org.kie.server.services.impl.marshal.MarshallerHelper) ArrayList(java.util.ArrayList) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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