Search in sources :

Example 1 with QueryDefinition

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

the class QueryServicesClientImpl method replaceQuery.

@Override
public QueryDefinition replaceQuery(QueryDefinition queryDefinition) {
    QueryDefinition result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(QUERY_NAME, queryDefinition.getName());
        result = makeHttpPutRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_DEF_URI + "/" + REPLACE_QUERY_DEF_PUT_URI, valuesMap), queryDefinition, QueryDefinition.class, new HashMap<String, String>());
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryDataService", "replaceQuery", serialize(queryDefinition), marshaller.getFormat().getType(), new Object[] { queryDefinition.getName() })));
        ServiceResponse<QueryDefinition> response = (ServiceResponse<QueryDefinition>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    return result;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) 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 2 with QueryDefinition

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

the class QueryDataResource method replaceQueryDefinition.

@ApiOperation(value = "Replaces existing custom query definition or registers it as new if the query does not already exist.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 201, response = QueryDefinition.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = QUERY_DEF_RESPONSE_JSON) })) })
@PUT
@Path(REPLACE_QUERY_DEF_PUT_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response replaceQueryDefinition(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "identifier of the query definition to be replaced", required = true, example = "customQuery") @PathParam("queryName") String queryName, @ApiParam(value = "query definition represented as QueryDefinition", required = true, examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = QUERY_DEF_JSON), @ExampleProperty(mediaType = XML, value = QUERY_DEF_XML) })) String payload) {
    Variant v = getVariant(headers);
    String type = getContentType(headers);
    // no container id available so only used to transfer conversation id if
    // given by client
    Header conversationIdHeader = buildConversationIdHeader("", context, headers);
    try {
        QueryDefinition def = queryDataServiceBase.replaceQuery(queryName, payload, type);
        logger.debug("Returning CREATED response after registering query with name {}", queryName);
        return createCorrectVariant(def, headers, Response.Status.CREATED, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(errorMessage(e), v, conversationIdHeader);
    }
}
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) QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) HttpStatusCodeException(org.kie.server.common.rest.HttpStatusCodeException) QueryAlreadyRegisteredException(org.jbpm.services.api.query.QueryAlreadyRegisteredException) DataSetLookupException(org.dashbuilder.dataset.exception.DataSetLookupException) QueryNotFoundException(org.jbpm.services.api.query.QueryNotFoundException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Example 3 with QueryDefinition

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

the class QueryDataResource method getQuery.

@ApiOperation(value = "Returns information about a specified custom query.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Query definition with given name not found"), @ApiResponse(code = 200, response = QueryDefinition.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = QUERY_DEF_RESPONSE_JSON) })) })
@GET
@Path(QUERY_DEF_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getQuery(@Context HttpHeaders headers, @ApiParam(value = "identifier of the query definition to be retrieved", required = true, example = "customQuery") @PathParam("queryName") String queryName) {
    Variant v = getVariant(headers);
    // no container id available so only used to transfer conversation id if
    // given by client
    Header conversationIdHeader = buildConversationIdHeader("", context, headers);
    try {
        QueryDefinition queryDefinition = queryDataServiceBase.getQuery(queryName);
        return createCorrectVariant(queryDefinition, headers, Response.Status.OK, conversationIdHeader);
    } catch (QueryNotFoundException e) {
        return notFound(MessageFormat.format(QUERY_NOT_FOUND, queryName), v, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(errorMessage(e), v, conversationIdHeader);
    }
}
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) QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) QueryNotFoundException(org.jbpm.services.api.query.QueryNotFoundException) HttpStatusCodeException(org.kie.server.common.rest.HttpStatusCodeException) QueryAlreadyRegisteredException(org.jbpm.services.api.query.QueryAlreadyRegisteredException) DataSetLookupException(org.dashbuilder.dataset.exception.DataSetLookupException) QueryNotFoundException(org.jbpm.services.api.query.QueryNotFoundException) 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 4 with QueryDefinition

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

the class QueryClientIntegrationTest method registerQuery.

private QueryDefinition registerQuery(final QueryDefinition queryDefinition) {
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("queryDefinition", queryDefinition);
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("query");
    executionServerCommand.setOperation("registerQuery");
    executionServerCommand.setParameters(parameters);
    Object object = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(object).isNotNull();
    Assertions.assertThat(object).isInstanceOf(QueryDefinition.class);
    QueryDefinition response = (QueryDefinition) object;
    return response;
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) HashMap(java.util.HashMap) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand)

Example 5 with QueryDefinition

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

the class QueryClientIntegrationTest method getSimpleQueryDefinition.

private static final QueryDefinition getSimpleQueryDefinition() {
    final QueryDefinition simpleQueryDefinition = new QueryDefinition();
    simpleQueryDefinition.setName(SIMPLE_QUERY_NAME);
    simpleQueryDefinition.setExpression(SIMPLE_QUERY_EXPRESSION);
    simpleQueryDefinition.setTarget(SIMPLE_QUERY_TARGET);
    simpleQueryDefinition.setSource(SIMPLE_QUERY_DATASOURCE);
    return simpleQueryDefinition;
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition)

Aggregations

QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)52 Test (org.junit.Test)33 HashMap (java.util.HashMap)31 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)19 QueryFilterSpecBuilder (org.kie.server.api.util.QueryFilterSpecBuilder)6 TaskInstance (org.kie.server.api.model.instance.TaskInstance)5 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)4 QueryFilterSpec (org.kie.server.api.model.definition.QueryFilterSpec)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Variant (javax.ws.rs.core.Variant)3 DataSetLookupException (org.dashbuilder.dataset.exception.DataSetLookupException)3 QueryAlreadyRegisteredException (org.jbpm.services.api.query.QueryAlreadyRegisteredException)3 QueryNotFoundException (org.jbpm.services.api.query.QueryNotFoundException)3 CommandScript (org.kie.server.api.commands.CommandScript)3 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)3