use of org.apache.qpid.server.management.plugin.servlet.query.ConfiguredObjectQuery in project qpid-broker-j by apache.
the class QueryServlet method performQuery.
private void performQuery(final HttpServletRequest request, final HttpServletResponse response, final ConfiguredObject<?> managedObject) throws IOException, ServletException {
String categoryName;
X parent = getParent(request, managedObject);
if (parent != null && ((categoryName = getRequestedCategory(request, managedObject)) != null)) {
Model model = parent.getModel();
Class<? extends ConfiguredObject> category = getSupportedCategory(categoryName, model);
if (category != null) {
List<ConfiguredObject<?>> objects = getAllObjects(parent, category, request);
try {
ConfiguredObjectQuery query = new ConfiguredObjectQuery(objects, request.getParameter("select"), request.getParameter("where"), request.getParameter("orderBy"), request.getParameter("limit"), request.getParameter("offset"));
String attachmentFilename = request.getParameter(CONTENT_DISPOSITION_ATTACHMENT_FILENAME_PARAM);
if (attachmentFilename != null) {
setContentDispositionHeaderIfNecessary(response, attachmentFilename);
}
if ("csv".equalsIgnoreCase(request.getParameter("format"))) {
sendCsvResponse(query, response);
} else {
Map<String, Object> resultsObject = new LinkedHashMap<>();
resultsObject.put("headers", query.getHeaders());
resultsObject.put("results", query.getResults());
resultsObject.put("total", query.getTotalNumberOfRows());
sendJsonResponse(resultsObject, request, response);
}
} catch (SelectorParsingException e) {
sendJsonErrorResponse(request, response, HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
} catch (EvaluationException e) {
sendJsonErrorResponse(request, response, SC_UNPROCESSABLE_ENTITY, e.getMessage());
}
} else {
sendJsonErrorResponse(request, response, HttpServletResponse.SC_NOT_FOUND, "Unknown object type " + categoryName);
}
} else {
sendJsonErrorResponse(request, response, HttpServletResponse.SC_NOT_FOUND, "Invalid path");
}
}
Aggregations