Search in sources :

Example 1 with ProcessDefinitionList

use of org.kie.server.api.model.definition.ProcessDefinitionList in project droolsjbpm-integration by kiegroup.

the class CaseQueryResource method getProcessDefinitionsByContainer.

@ApiOperation(value = "Returns processes associated with case definitions in a specified KIE container.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = ProcessDefinitionList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_DEFS_RESPONSE_JSON) })) })
@GET
@Path(CASE_PROCESSES_BY_CONTAINER_INSTANCES_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessDefinitionsByContainer(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id that process definitions should be filtered by", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @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, "", null, (Variant v, String type, Header... customHeaders) -> {
        logger.debug("About to look for process definitions with container id {}", containerId);
        ProcessDefinitionList responseObject = this.caseManagementRuntimeDataServiceBase.getProcessDefinitions(null, containerId, page, pageSize, sort, sortOrder);
        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) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) ProcessDefinitionList(org.kie.server.api.model.definition.ProcessDefinitionList) 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 2 with ProcessDefinitionList

use of org.kie.server.api.model.definition.ProcessDefinitionList in project droolsjbpm-integration by kiegroup.

the class CaseQueryResource method getProcessDefinitions.

/*
     * process definition methods
     */
@ApiOperation(value = "Returns a specified process associated with case definitions from all KIE containers.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = ProcessDefinitionList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_DEFS_RESPONSE_JSON) })) })
@GET
@Path(CASE_ALL_PROCESSES_INSTANCES_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessDefinitions(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "process definition id or name that process definitions will be filtered by", required = true) @QueryParam("filter") String filter, @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, "", null, (Variant v, String type, Header... customHeaders) -> {
        logger.debug("About to look for process definitions with filter {}", filter);
        ProcessDefinitionList responseObject = this.caseManagementRuntimeDataServiceBase.getProcessDefinitions(filter, null, page, pageSize, sort, sortOrder);
        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) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) ProcessDefinitionList(org.kie.server.api.model.definition.ProcessDefinitionList) 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 3 with ProcessDefinitionList

use of org.kie.server.api.model.definition.ProcessDefinitionList in project droolsjbpm-integration by kiegroup.

the class QueryServicesClientImpl method findProcessesByContainerId.

@Override
public List<ProcessDefinition> findProcessesByContainerId(String containerId, Integer page, Integer pageSize, String sort, boolean sortOrder) {
    ProcessDefinitionList 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 = makeHttpGetRequestAndCreateCustomResponseWithHandleNotFound(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_DEFINITIONS_BY_CONTAINER_ID_GET_URI, valuesMap) + queryString, ProcessDefinitionList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessesByDeploymentId", new Object[] { containerId, page, pageSize, sort, sortOrder })));
        ServiceResponse<ProcessDefinitionList> response = (ServiceResponse<ProcessDefinitionList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    if (result != null && result.getProcesses() != null) {
        return Arrays.asList(result.getProcesses());
    }
    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) ProcessDefinitionList(org.kie.server.api.model.definition.ProcessDefinitionList) CommandScript(org.kie.server.api.commands.CommandScript)

Example 4 with ProcessDefinitionList

use of org.kie.server.api.model.definition.ProcessDefinitionList in project droolsjbpm-integration by kiegroup.

the class RuntimeDataResource method getProcessesByDeploymentId.

@ApiOperation(value = "Returns all process definitions in a specified KIE container.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = ProcessDefinitionList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_DEFS_RESPONSE_JSON) })) })
@GET
@Path(PROCESS_DEFINITIONS_BY_CONTAINER_ID_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessesByDeploymentId(@Context HttpHeaders headers, @ApiParam(value = "container id to filter process definitions", required = true) @PathParam(CONTAINER_ID) String containerId, @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);
    ProcessDefinitionList processDefinitionList = runtimeDataServiceBase.getProcessesByDeploymentId(containerId, page, pageSize, sort, sortOrder);
    logger.debug("Returning result of process definition search: {}", processDefinitionList);
    return createCorrectVariant(processDefinitionList, headers, Response.Status.OK, conversationIdHeader);
}
Also used : Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) ProcessDefinitionList(org.kie.server.api.model.definition.ProcessDefinitionList) 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 5 with ProcessDefinitionList

use of org.kie.server.api.model.definition.ProcessDefinitionList in project droolsjbpm-integration by kiegroup.

the class ProcessServiceRestOnlyIntegrationTest method testProcessDefinitionWhichBelongsToAContainer.

@Test
public void testProcessDefinitionWhichBelongsToAContainer() {
    Map<String, Object> valuesMap = new HashMap<String, Object>();
    valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
    Response response = null;
    try {
        // find process definitions which belong to the given container
        WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        Marshaller marshaller = MarshallerFactory.getMarshaller(marshallingFormat, Thread.currentThread().getContextClassLoader());
        ProcessDefinitionList processDefinitionList = marshaller.unmarshall(response.readEntity(String.class), ProcessDefinitionList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        // we didn't specify pageSize, so it will be 10 by default
        assertThat(processDefinitionList.getItems()).hasSize(10);
        response.close();
        // find process definitions of non-existing container
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, NON_EXISTING_CONTAINER_ID);
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        assertThat(response.getStatus()).isEqualTo(Response.Status.NOT_FOUND.getStatusCode());
        assertThat(response.readEntity(String.class)).contains(NON_EXISTING_CONTAINER_ID);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) ProcessDefinitionList(org.kie.server.api.model.definition.ProcessDefinitionList) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Aggregations

ProcessDefinitionList (org.kie.server.api.model.definition.ProcessDefinitionList)19 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 HashMap (java.util.HashMap)6 GET (javax.ws.rs.GET)6 Produces (javax.ws.rs.Produces)6 ServiceResponse (org.kie.server.api.model.ServiceResponse)6 Header (org.kie.server.remote.rest.common.Header)6 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)6 Path (javax.ws.rs.Path)5 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)5 CommandScript (org.kie.server.api.commands.CommandScript)5 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)5 KieServerCommand (org.kie.server.api.model.KieServerCommand)5 Variant (javax.ws.rs.core.Variant)3 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)3 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)3 ArrayList (java.util.ArrayList)2 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1