use of org.apache.stanbol.entityhub.ldpath.query.LDPathSelect in project stanbol by apache.
the class FieldQueryToJsonUtils method toJSON.
/**
* Converts a {@link FieldQuery} to it's JSON representation
*
* @param query the Query
* @return the {@link JSONObject}
* @throws JSONException
*/
public static JSONObject toJSON(FieldQuery query, NamespacePrefixService nsPrefixService) throws JSONException {
JSONObject jQuery = new JSONObject();
jQuery.put("selected", new JSONArray(query.getSelectedFields()));
JSONArray constraints = new JSONArray();
jQuery.put("constraints", constraints);
for (Entry<String, Constraint> fieldConstraint : query) {
JSONObject jFieldConstraint = convertConstraintToJSON(fieldConstraint.getValue(), nsPrefixService);
//add the field
jFieldConstraint.put("field", fieldConstraint.getKey());
//write the boost if present
Double boost = fieldConstraint.getValue().getBoost();
if (boost != null) {
jFieldConstraint.put("boost", boost);
}
//add fieldConstraint
constraints.put(jFieldConstraint);
}
if (query.getLimit() != null) {
jQuery.put("limit", query.getLimit());
}
//if(query.getOffset() != 0){
jQuery.put("offset", query.getOffset());
//}
if (query instanceof LDPathSelect && ((LDPathSelect) query).getLDPathSelect() != null && !((LDPathSelect) query).getLDPathSelect().isEmpty()) {
jQuery.put("ldpath", ((LDPathSelect) query).getLDPathSelect());
}
return jQuery;
}
use of org.apache.stanbol.entityhub.ldpath.query.LDPathSelect in project stanbol by apache.
the class ReferencedSiteRootResource method executeQuery.
/**
* Executes the query parsed by {@link #queryEntities(String, File, HttpHeaders)} or created based
* {@link #findEntity(String, String, String, int, int, HttpHeaders)}
*
* @param query
* The query to execute
* @param headers the request headers
* @return the response (results of error)
*/
private Response executeQuery(Site site, FieldQuery query, HttpHeaders headers) throws WebApplicationException {
MediaType mediaType = getAcceptableMediaType(headers, ENTITY_SUPPORTED_MEDIA_TYPES, APPLICATION_JSON_TYPE);
if (query instanceof LDPathSelect && ((LDPathSelect) query).getLDPathSelect() != null) {
//use the LDPath variant to process this query
return executeLDPathQuery(site, query, ((LDPathSelect) query).getLDPathSelect(), mediaType, headers);
} else {
//use the default query execution
QueryResultList<Representation> result;
try {
result = site.find(query);
} catch (SiteException e) {
String message = String.format("Unable to Query Site '%s' (message: %s)", site.getId(), e.getMessage());
log.error(message, e);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).header(HttpHeaders.ACCEPT, mediaType).build();
}
ResponseBuilder rb = Response.ok(result);
rb.header(HttpHeaders.CONTENT_TYPE, mediaType + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
}
Aggregations