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;
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations