Search in sources :

Example 11 with NodeInstanceList

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

the class RuntimeDataServiceBase method getProcessInstanceHistory.

public NodeInstanceList getProcessInstanceHistory(long processInstanceId, Boolean active, Boolean completed, Integer page, Integer pageSize) {
    logger.debug("About to search for node instances with page {} and page size {}", page, pageSize);
    Collection<NodeInstanceDesc> result = null;
    if ((Boolean.TRUE.equals(active) && Boolean.TRUE.equals(completed)) || (active == null && completed == null)) {
        logger.debug("Searching for active and completed node instances for process instance with id {}", processInstanceId);
        result = runtimeDataService.getProcessInstanceFullHistory(processInstanceId, buildQueryContext(page, pageSize));
    } else if (Boolean.TRUE.equals(active)) {
        logger.debug("Searching for active node instances for process instance with id {}", processInstanceId);
        result = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, buildQueryContext(page, pageSize));
    } else if (Boolean.TRUE.equals(completed)) {
        logger.debug("Searching for completed node instances for process instance with id {}", processInstanceId);
        result = runtimeDataService.getProcessInstanceHistoryCompleted(processInstanceId, buildQueryContext(page, pageSize));
    }
    NodeInstanceList nodeInstanceList = convertToNodeInstanceList(result);
    logger.debug("Returning result of node instances search: {}", nodeInstanceList);
    return nodeInstanceList;
}
Also used : NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList) ConvertUtils.convertToNodeInstanceList(org.kie.server.services.jbpm.ConvertUtils.convertToNodeInstanceList)

Example 12 with NodeInstanceList

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

the class CaseResource method getCaseInstanceActiveNodes.

@ApiOperation(value = "Returns node instances for a specified case instance.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Case instance not found"), @ApiResponse(code = 200, response = NodeInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = NODE_INSTANCES_JSON) })) })
@GET
@Path(CASE_NODE_INSTANCES_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getCaseInstanceActiveNodes(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id that case instance belongs to", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of the case instance", required = true, example = "CASE-00000000001") @PathParam(CASE_ID) String caseId, @ApiParam(value = "optional flag that allows to control which node instances to load - active or completed, defaults to false loading only active ones", required = false) @QueryParam("completed") @DefaultValue("false") Boolean completed, @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) {
    return invokeCaseOperation(headers, containerId, caseId, (Variant v, String type, Header... customHeaders) -> {
        logger.debug("About to look for active nodes in case {}", caseId);
        NodeInstanceList responseObject = null;
        if (completed) {
            responseObject = this.caseManagementRuntimeDataServiceBase.getCompletedNodes(containerId, caseId, page, pageSize);
        } else {
            responseObject = this.caseManagementRuntimeDataServiceBase.getActiveNodes(containerId, caseId, page, pageSize);
        }
        logger.debug("Returning OK response with content '{}'", responseObject);
        return createCorrectVariant(responseObject, headers, Response.Status.OK, customHeaders);
    });
}
Also used : 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) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList) 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 13 with NodeInstanceList

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

the class QueryServicesClientImpl method findActiveNodeInstances.

@Override
public List<NodeInstance> findActiveNodeInstances(Long processInstanceId, Integer page, Integer pageSize) {
    NodeInstanceList result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(PROCESS_INST_ID, processInstanceId);
        String queryString = getPagingQueryString("?activeOnly=true", page, pageSize);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + NODE_INSTANCES_BY_INSTANCE_ID_GET_URI, valuesMap) + queryString, NodeInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstanceHistory", new Object[] { processInstanceId, true, false, page, pageSize })));
        ServiceResponse<NodeInstanceList> response = (ServiceResponse<NodeInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    if (result != null && result.getNodeInstances() != null) {
        return Arrays.asList(result.getNodeInstances());
    }
    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) CommandScript(org.kie.server.api.commands.CommandScript) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList)

Example 14 with NodeInstanceList

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

the class QueryServicesClientImpl method findCompletedNodeInstances.

@Override
public List<NodeInstance> findCompletedNodeInstances(Long processInstanceId, Integer page, Integer pageSize) {
    NodeInstanceList result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(PROCESS_INST_ID, processInstanceId);
        String queryString = getPagingQueryString("?completedOnly=true", page, pageSize);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + NODE_INSTANCES_BY_INSTANCE_ID_GET_URI, valuesMap) + queryString, NodeInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstanceHistory", new Object[] { processInstanceId, false, true, page, pageSize })));
        ServiceResponse<NodeInstanceList> response = (ServiceResponse<NodeInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    if (result != null && result.getNodeInstances() != null) {
        return Arrays.asList(result.getNodeInstances());
    }
    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) CommandScript(org.kie.server.api.commands.CommandScript) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList)

Example 15 with NodeInstanceList

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

the class ProcessResource method getProcessInstanceHistory.

@ApiOperation(value = "Returns node instances for the specified process instance.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Process Instance or Container Id not found"), @ApiResponse(code = 200, response = NodeInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_INSTANCE_NODES_RESPONSE_JSON) })) })
@GET
@Path(PROCESS_INSTANCES_NODE_INSTANCES_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessInstanceHistory(@Context HttpHeaders headers, @PathParam(CONTAINER_ID) @ApiParam(value = "container id that process instance belongs to", required = true, example = "evaluation_1.0.0-SNAPSHOT") String containerId, @ApiParam(value = "identifier of the process instance that history should be collected for", required = true, example = "123") @PathParam(PROCESS_INST_ID) long processInstanceId, @ApiParam(value = "instructs if active nodes only should be collected, defaults to false", required = false) @QueryParam("activeOnly") Boolean active, @ApiParam(value = "instructs if completed nodes only should be collected, defaults to false", required = false) @QueryParam("completedOnly") Boolean completed, @ApiParam(value = "entry type from the history", required = false, example = "123") @QueryParam(PROCESS_INST_HISTORY_TYPE) String processInstHistoryType, @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);
    Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
    try {
        NodeInstanceList nodeInstanceList = null;
        if (processInstHistoryType == null) {
            nodeInstanceList = runtimeDataServiceBase.getProcessInstanceHistory(processInstanceId, active, completed, page, pageSize);
        } else {
            nodeInstanceList = runtimeDataServiceBase.getProcessInstanceFullHistoryByType(processInstanceId, processInstHistoryType, page, pageSize);
        }
        logger.debug("Returning result of node instances search: {}", nodeInstanceList);
        return createCorrectVariant(nodeInstanceList, headers, Response.Status.OK, conversationIdHeader);
    } catch (ProcessInstanceNotFoundException e) {
        return notFound(MessageFormat.format(PROCESS_INSTANCE_NOT_FOUND, processInstanceId), v, 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) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList) 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)

Aggregations

NodeInstanceList (org.kie.server.api.model.instance.NodeInstanceList)20 HashMap (java.util.HashMap)11 ServiceResponse (org.kie.server.api.model.ServiceResponse)11 CommandScript (org.kie.server.api.commands.CommandScript)10 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)10 KieServerCommand (org.kie.server.api.model.KieServerCommand)10 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)4 Header (org.kie.server.remote.rest.common.Header)4 Variant (javax.ws.rs.core.Variant)3 NodeInstance (org.kie.server.api.model.instance.NodeInstance)3 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)3 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)3 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)2 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)2 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)2