private <T> JSONObject toJSON(QueryResultList<?> resultList, NamespacePrefixService nsPrefixService) throws JSONException{ JSONObject jResultList = new JSONObject(); if(resultList.getQuery() != null){ jResultList.put("query", FieldQueryToJsonUtils.toJSON(resultList.getQuery(),nsPrefixService)); } jResultList.put("results", convertResultsToJSON(resultList,resultList.getType())); return jResultList; }
@Override public final QueryResultList<Entity> findEntities(FieldQuery query) throws YardException{ QueryResultList<String> references = entityhubYard.findReferences(query); List<Entity> entities = new ArrayList<Entity>(references.size()); for(String reference : references){ Entity entity = lookupLocalEntity(reference); if(entity != null){ entities.add(entity); } else { log.warn("Unable to create Entity for Reference {} in the Yard " + "usd by the entity hub [id={}] -> ignore reference", reference,config.getEntityhubYardId()); } } return new QueryResultListImpl<Entity>(references.getQuery(), entities, Entity.class); }
@Override public final QueryResultList<Entity> findEntities(FieldQuery query) throws YardException{ QueryResultList<String> references = entityhubYard.findReferences(query); List<Entity> entities = new ArrayList<Entity>(references.size()); for(String reference : references){ Entity entity = lookupLocalEntity(reference); if(entity != null){ entities.add(entity); } else { log.warn("Unable to create Entity for Reference {} in the Yard " + "usd by the entity hub [id={}] -> ignore reference", reference,config.getEntityhubYardId()); } } return new QueryResultListImpl<Entity>(references.getQuery(), entities, Entity.class); }
@Override public void write(QueryResultList<?> result, OutputStream out, MediaType mediaType) throws WebApplicationException, IOException { Model queryRdf = toRDF(result); //we need also to the JSON formatted FieldQuery as a literal to the //RDF data. FieldQuery query = result.getQuery(); if(query != null){ try { JSONObject fieldQueryJson = FieldQueryToJsonUtils.toJSON(query, nsPrefixService); if(fieldQueryJson != null){ //add the triple with the fieldQuery queryRdf.add(QUERY_RESULT_LIST, FIELD_QUERY, sesameFactory.createLiteral(fieldQueryJson.toString())); } } catch (JSONException e) { log.warn(String.format("Unable to serialize Fieldquery '%s' to JSON! " + "Query response will not contain the serialized query.", query),e); } } //now serialise the data writeRdf(queryRdf,out,mediaType); }
@Override public void write(QueryResultList<?> result, OutputStream out, MediaType mediaType) throws WebApplicationException, IOException { Graph queryRdf = toRDF(result); //we need also to the JSON formatted FieldQuery as a literal to the //RDF data. FieldQuery query = result.getQuery(); if(query != null){ try { JSONObject fieldQueryJson = FieldQueryToJsonUtils.toJSON(query, nsPrefixService); if(fieldQueryJson != null){ //add the triple with the fieldQuery queryRdf.add(new TripleImpl(QUERY_RESULT_LIST, FIELD_QUERY, literalFactory.createTypedLiteral(fieldQueryJson.toString()))); } } catch (JSONException e) { log.warn(String.format("Unable to serialize Fieldquery '%s' to JSON! " + "Query response will not contain the serialized query.", query),e); } } //now serialise the data writeRdf(queryRdf,out,mediaType); }
+ "' on Entityhub Site '" + site.getId() + "!", e); log.debug(" - {} results returned by query {}", results.size(), results.getQuery());
log.debug(" - {} results returned by query {}", results.size(), results.getQuery()); if (results.isEmpty()) { // no results nothing to do return Collections.emptyList();
@Override public QueryResultList<Entity> findEntities(FieldQuery query) throws ManagedSiteException { QueryResultList<Representation> results; try { results = getYard().findRepresentation(query); } catch (YardException e) { throw new ManagedSiteException(e.getMessage(), e); } return new QueryResultListImpl<Entity>(results.getQuery(), new AdaptingIterator<Representation,Entity>( results.iterator(), new AdaptingIterator.Adapter<Representation,Entity>() { private final String siteId = config.getId(); @Override public Entity adapt(Representation value, Class<Entity> type) { Entity entity = new EntityImpl(siteId,value,null); SiteUtils.initEntityMetadata(entity, siteMetadata, null); return entity; } }, Entity.class),Entity.class); }