use of ai.grakn.engine.controller.response.ListResource in project grakn by graknlabs.
the class ConceptController method getConcepts.
private String getConcepts(Request request, Response response, String key, Function<GraknTx, Stream<? extends ai.grakn.concept.Concept>> getter) 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()) {
List<Concept> concepts = getter.apply(tx).map(ConceptBuilder::<Concept>build).collect(Collectors.toList());
ListResource list = ListResource.create(Requests.selfLink(request), key, concepts);
response.status(SC_OK);
return objectMapper.writeValueAsString(list);
}
}
Aggregations