use of ai.grakn.engine.Jacksonisable in project grakn by graknlabs.
the class ConceptController method getConceptCollection.
private <X extends ai.grakn.concept.Concept> String getConceptCollection(Request request, Response response, String key, Function<GraknTx, X> getter, Function<X, Stream<Jacksonisable>> collector) throws JsonProcessingException {
response.type(APPLICATION_JSON);
Keyspace keyspace = Keyspace.of(mandatoryPathParameter(request, KEYSPACE_PARAM));
try (GraknTx tx = factory.tx(keyspace, READ);
Timer.Context context = labelGetTimer.time()) {
X concept = getter.apply(tx);
// If the concept was not found return;
if (concept == null) {
response.status(SC_NOT_FOUND);
return "[]";
}
List<Jacksonisable> list = collector.apply(concept).collect(Collectors.toList());
Link link = Link.create(request.pathInfo());
ListResource<Jacksonisable> listResource = ListResource.create(link, key, list);
return objectMapper.writeValueAsString(listResource);
}
}
Aggregations