Search in sources :

Example 11 with CaseInstanceList

use of org.kie.server.api.model.cases.CaseInstanceList in project droolsjbpm-integration by kiegroup.

the class CaseServicesClientImpl method getCaseInstances.

@Override
public List<CaseInstance> getCaseInstances(List<String> status, Integer page, Integer pageSize, String sort, boolean sortOrder, boolean withData) {
    CaseInstanceList list = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        String queryString = getPagingQueryString("", page, pageSize);
        queryString = getAdditionalParams(queryString, "status", status);
        queryString = getSortingQueryString(queryString, sort, sortOrder);
        queryString = getAdditionalParams(queryString, "withData", Collections.singletonList(withData));
        list = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), CASE_QUERY_URI + "/" + CASE_ALL_INSTANCES_GET_URI, valuesMap) + queryString, CaseInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseQueryService", "getCaseInstancesAnyRole", new Object[] { safeList(status), page, pageSize, sort, sortOrder, withData })));
        ServiceResponse<CaseInstanceList> response = (ServiceResponse<CaseInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        list = response.getResult();
    }
    if (list != null) {
        return list.getItems();
    }
    return Collections.emptyList();
}
Also used : CaseInstanceList(org.kie.server.api.model.cases.CaseInstanceList) 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)

Example 12 with CaseInstanceList

use of org.kie.server.api.model.cases.CaseInstanceList in project droolsjbpm-integration by kiegroup.

the class CaseAdminServicesClientImpl method getCaseInstances.

@Override
public List<CaseInstance> getCaseInstances(List<String> status, Integer page, Integer pageSize, String sort, boolean sortOrder) {
    CaseInstanceList list = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        String queryString = getPagingQueryString("", page, pageSize);
        queryString = getAdditionalParams(queryString, "status", status);
        queryString = getSortingQueryString(queryString, sort, sortOrder);
        list = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), ADMIN_CASE_URI + "/" + ADMIN_CASE_ALL_INSTANCES_GET_URI, valuesMap) + queryString, CaseInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseQueryService", "getCaseInstances", new Object[] { safeList(status), page, pageSize, sort, sortOrder })));
        ServiceResponse<CaseInstanceList> response = (ServiceResponse<CaseInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        list = response.getResult();
    }
    if (list != null) {
        return list.getItems();
    }
    return Collections.emptyList();
}
Also used : CaseInstanceList(org.kie.server.api.model.cases.CaseInstanceList) 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)

Example 13 with CaseInstanceList

use of org.kie.server.api.model.cases.CaseInstanceList in project droolsjbpm-integration by kiegroup.

the class PrometheusKieServerExtension method init.

@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
    this.context = registry;
    customMetrics = new PrometheusCustomMetricsSupport(this);
    registerDefaultDescriptor();
    // Prometheus Monitoring
    KieServerExtension jBPMExtension = context.getServerExtension(JbpmKieServerExtension.EXTENSION_NAME);
    if (jBPMExtension != null) {
        final KModuleDeploymentService deploymentService = jBPMExtension.getAppComponents(KModuleDeploymentService.class);
        if (deploymentService != null) {
            List<DeploymentEventListener> metrics = customMetrics.getDeploymentEventListener();
            if (!metrics.isEmpty()) {
                List<DeploymentEventListener> listeners = new ArrayList<>(metrics);
                listeners.forEach(l -> deploymentService.addListener(l));
            }
            deploymentService.addListener(new PrometheusDeploymentEventListener());
        }
        final ExecutorServiceImpl executorService = jBPMExtension.getAppComponents(ExecutorServiceImpl.class);
        if (executorService != null) {
            List<AsynchronousJobListener> metrics = customMetrics.getAsynchronousJobListener();
            if (!metrics.isEmpty()) {
                List<AsynchronousJobListener> listeners = new ArrayList<>(metrics);
                listeners.forEach(l -> executorService.addAsyncJobListener(l));
            }
            executorService.addAsyncJobListener(new PrometheusJobListener());
        }
        final QueryServiceImpl queryService = jBPMExtension.getAppComponents(QueryServiceImpl.class);
        if (queryService != null) {
            final DataSetDefRegistry dataSetDefRegistry = queryService.getDataSetDefRegistry();
            final PrometheusDataSetListener listener = new PrometheusDataSetListener(dataSetDefRegistry);
            listener.init();
            dataSetDefRegistry.addListener(listener);
        }
        final RuntimeDataService dataService = jBPMExtension.getAppComponents(RuntimeDataService.class);
        if (dataService != null) {
            final Collection<ProcessInstanceDesc> processInstances = dataService.getProcessInstances(asList(ProcessInstance.STATE_ACTIVE), null, new QueryContext(0, Integer.MAX_VALUE));
            processInstances.forEach(pi -> recordRunningProcessInstance(pi.getDeploymentId(), pi.getProcessId()));
        }
    }
    KieServerExtension caseExtension = context.getServerExtension(CaseKieServerExtension.EXTENSION_NAME);
    if (caseExtension != null) {
        final CaseManagementRuntimeDataServiceBase caseRuntime = caseExtension.getAppComponents(CaseManagementRuntimeDataServiceBase.class);
        if (caseRuntime != null) {
            final CaseInstanceList caseInstances = caseRuntime.getCaseInstances(asList(CaseStatus.OPEN.getName()), 0, Integer.MAX_VALUE, null, false);
            for (CaseInstance instance : caseInstances.getCaseInstances()) {
                recordRunningCaseInstance(instance.getCaseDefinitionId());
            }
        }
    }
    initialized = true;
    if (!customMetrics.hasCustomMetrics()) {
        LOGGER.info("{} started", toString());
    } else {
        LOGGER.info("{} started with custom Prometheus metrics provider(s): {}", toString(), customMetrics.customMetricsProviders());
    }
}
Also used : RuntimeDataService(org.jbpm.services.api.RuntimeDataService) AsynchronousJobListener(org.jbpm.executor.AsynchronousJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) JbpmKieServerExtension(org.kie.server.services.jbpm.JbpmKieServerExtension) KieServerExtension(org.kie.server.services.api.KieServerExtension) CaseKieServerExtension(org.kie.server.services.casemgmt.CaseKieServerExtension) CaseManagementRuntimeDataServiceBase(org.kie.server.services.casemgmt.CaseManagementRuntimeDataServiceBase) ArrayList(java.util.ArrayList) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) DataSetDefRegistry(org.dashbuilder.dataset.def.DataSetDefRegistry) CaseInstanceList(org.kie.server.api.model.cases.CaseInstanceList) CaseInstance(org.kie.server.api.model.cases.CaseInstance) PrometheusCaseEventListener.recordRunningCaseInstance(org.kie.server.services.prometheus.PrometheusCaseEventListener.recordRunningCaseInstance) KModuleDeploymentService(org.jbpm.kie.services.impl.KModuleDeploymentService) DeploymentEventListener(org.jbpm.services.api.DeploymentEventListener) QueryServiceImpl(org.jbpm.kie.services.impl.query.QueryServiceImpl)

Example 14 with CaseInstanceList

use of org.kie.server.api.model.cases.CaseInstanceList in project droolsjbpm-integration by kiegroup.

the class CaseQueryResource method getCaseInstancesByRole.

@ApiOperation(value = "Returns cases instances that involve the querying user in a specified role.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = CaseInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = CASE_INSTANCES_JSON) })) })
@GET
@Path(CASE_INSTANCES_BY_ROLE_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getCaseInstancesByRole(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "case role that instances should be found for", required = true, example = "owner") @PathParam(CASE_ROLE_NAME) String roleName, @ApiParam(value = "optional case instance status (open, closed, canceled) - defaults ot open (1) only", required = false, allowableValues = "open,closed,cancelled") @QueryParam("status") List<String> 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, @ApiParam(value = "optional flag to load data when loading case instance", required = false) @QueryParam("withData") @DefaultValue("false") boolean withData) {
    return invokeCaseOperation(headers, "", null, (Variant v, String type, Header... customHeaders) -> {
        logger.debug("About to look for case instances with status {}", status);
        CaseInstanceList responseObject = this.caseManagementRuntimeDataServiceBase.getCaseInstancesByRole(roleName, status, page, pageSize, sort, sortOrder, withData);
        logger.debug("Returning OK response with content '{}'", responseObject);
        return createCorrectVariant(responseObject, headers, Response.Status.OK, customHeaders);
    });
}
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) CaseInstanceList(org.kie.server.api.model.cases.CaseInstanceList) 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 15 with CaseInstanceList

use of org.kie.server.api.model.cases.CaseInstanceList in project droolsjbpm-integration by kiegroup.

the class CaseAdminResource method getCaseInstances.

@ApiOperation(value = "Returns case instances without authentication checks.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = CaseInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = CASE_INSTANCES_JSON) })) })
@GET
@Path(ADMIN_CASE_ALL_INSTANCES_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getCaseInstances(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "optional case instance status (open, closed, canceled) - defaults ot open (1) only", required = false, allowableValues = "open,closed,cancelled") @QueryParam("status") List<String> 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, @ApiParam(value = "optional flag to load data when loading case instance", required = false) @QueryParam("withData") @DefaultValue("false") boolean withData) {
    return invokeCaseOperation(headers, "", null, (Variant v, String type, Header... customHeaders) -> {
        CaseInstanceList responseObject = null;
        logger.debug("About to look for case instances with status {}", status);
        responseObject = this.caseManagementRuntimeDataServiceBase.getCaseInstances(status, page, pageSize, sort, sortOrder, withData);
        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) CaseInstanceList(org.kie.server.api.model.cases.CaseInstanceList) 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)

Aggregations

CaseInstanceList (org.kie.server.api.model.cases.CaseInstanceList)20 CaseInstance (org.kie.server.api.model.cases.CaseInstance)9 CaseStatus (org.jbpm.casemgmt.api.model.CaseStatus)7 HashMap (java.util.HashMap)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 Variant (javax.ws.rs.core.Variant)6 CommandScript (org.kie.server.api.commands.CommandScript)6 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)6 KieServerCommand (org.kie.server.api.model.KieServerCommand)6 ServiceResponse (org.kie.server.api.model.ServiceResponse)6 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 Header (org.kie.server.remote.rest.common.Header)5 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)5 ArrayList (java.util.ArrayList)2 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)2 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)2 Consumes (javax.ws.rs.Consumes)1