Search in sources :

Example 21 with ProcessInstanceList

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

the class RuntimeDataServiceBase method getProcessInstanceByVariables.

public ProcessInstanceList getProcessInstanceByVariables(String variableName, String variableValue, List<Integer> status, Integer page, Integer pageSize, String sort, boolean sortOrder) {
    if (sort == null || sort.isEmpty()) {
        sort = "ProcessInstanceId";
    }
    Collection<ProcessInstanceDesc> instances = null;
    if (variableValue != null && !variableValue.isEmpty()) {
        logger.debug("About to search for process instance that has variable '{}' with value '{}' with page {} and page size {}", variableName, variableValue, page, pageSize);
        instances = runtimeDataService.getProcessInstancesByVariableAndValue(variableName, variableValue, status, buildQueryContext(page, pageSize, sort, sortOrder));
        logger.debug("Found {} process instance with variable {} and variable value {}", instances.size(), variableName, variableValue);
    } else {
        logger.debug("About to search for process instance that has variable '{}' with page {} and page size {}", variableName, page, pageSize);
        instances = runtimeDataService.getProcessInstancesByVariable(variableName, status, buildQueryContext(page, pageSize, sort, sortOrder));
        logger.debug("Found {} process instance with variable {} ", instances.size(), variableName);
    }
    ProcessInstanceList processInstanceList = convertToProcessInstanceList(instances);
    logger.debug("Returning result of process instance search: {}", processInstanceList);
    return processInstanceList;
}
Also used : ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) ConvertUtils.convertToProcessInstanceList(org.kie.server.services.jbpm.ConvertUtils.convertToProcessInstanceList) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc)

Example 22 with ProcessInstanceList

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

the class CaseResource method getCaseInstanceProcessInstance.

@ApiOperation(value = "Returns process instances in a specified case instance.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Case instance not found"), @ApiResponse(code = 200, response = ProcessInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = PROCESS_INSTANCES_JSON) })) })
@GET
@Path(CASE_PROCESS_INSTANCES_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getCaseInstanceProcessInstance(@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 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) {
    return invokeCaseOperation(headers, containerId, caseId, (Variant v, String type, Header... customHeaders) -> {
        List<Integer> actualStatus = status;
        if (status == null || status.isEmpty()) {
            actualStatus = new ArrayList<Integer>();
            actualStatus.add(ProcessInstance.STATE_ACTIVE);
        }
        logger.debug("About to look for process instances in case {} with status {}", caseId, actualStatus);
        ProcessInstanceList responseObject = this.caseManagementRuntimeDataServiceBase.getProcessInstancesForCase(containerId, caseId, actualStatus, page, pageSize, sort, sortOrder);
        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) ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) Header(org.kie.server.remote.rest.common.Header) 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 23 with ProcessInstanceList

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

the class ProcessServicesClientImpl method findProcessInstances.

@Override
public List<ProcessInstance> findProcessInstances(String containerId, Integer page, Integer pageSize, String sort, boolean sortOrder) {
    ProcessInstanceList result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        String queryString = getPagingQueryString("?sort=" + sort + "&sortOrder=" + sortOrder, page, pageSize);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_URI + "/" + PROCESS_INSTANCES_BY_CONTAINER_GET_URI, valuesMap) + queryString, ProcessInstanceList.class);
    } else {
        CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstances", new Object[] { new ArrayList(), "", "", page, pageSize, sort, sortOrder })));
        ServiceResponse<ProcessInstanceList> response = (ServiceResponse<ProcessInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    if (result != null && result.getProcessInstances() != null) {
        return Arrays.asList(result.getProcessInstances());
    }
    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) ArrayList(java.util.ArrayList) CommandScript(org.kie.server.api.commands.CommandScript)

Example 24 with ProcessInstanceList

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

the class QueryServicesClientImpl method findProcessInstancesByProcessId.

@Override
public List<ProcessInstance> findProcessInstancesByProcessId(String processId, List<Integer> status, Integer page, Integer pageSize, String sort, boolean sortOrder) {
    ProcessInstanceList result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(PROCESS_ID, processId);
        String statusQueryString = getAdditionalParams("?sort=" + sort + "&sortOrder=" + sortOrder, "status", status);
        String queryString = getPagingQueryString(statusQueryString, page, pageSize);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_INSTANCES_BY_PROCESS_ID_GET_URI, valuesMap) + queryString, ProcessInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstancesByProcessId", new Object[] { processId, safeList(status), "", page, pageSize, sort, sortOrder })));
        ServiceResponse<ProcessInstanceList> response = (ServiceResponse<ProcessInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    if (result != null && result.getProcessInstances() != null) {
        return Arrays.asList(result.getProcessInstances());
    }
    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)

Example 25 with ProcessInstanceList

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

the class QueryServicesClientImpl method findProcessInstancesByVariableAndValue.

@Override
public List<ProcessInstance> findProcessInstancesByVariableAndValue(String variableName, String variableValue, List<Integer> status, Integer page, Integer pageSize, String sort, boolean sortOrder) {
    ProcessInstanceList result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(VAR_NAME, variableName);
        String statusQueryString = getAdditionalParams("?varValue=" + variableValue + "&sort=" + sort + "&sortOrder=" + sortOrder, "status", status);
        String queryString = getPagingQueryString(statusQueryString, page, pageSize);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_INSTANCE_BY_VAR_NAME_GET_URI, valuesMap) + queryString, ProcessInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstanceByVariables", new Object[] { variableName, variableValue, safeList(status), page, pageSize, sort, sortOrder })));
        ServiceResponse<ProcessInstanceList> response = (ServiceResponse<ProcessInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    if (result != null && result.getProcessInstances() != null) {
        return Arrays.asList(result.getProcessInstances());
    }
    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