Search in sources :

Example 1 with ConceptBuilder

use of ai.grakn.engine.controller.response.ConceptBuilder in project grakn by graknlabs.

the class ConceptController method getConcept.

private String getConcept(Response response, Keyspace keyspace, Function<GraknTx, ai.grakn.concept.Concept> getter) throws JsonProcessingException {
    response.type(APPLICATION_JSON);
    try (GraknTx tx = factory.tx(keyspace, READ);
        Timer.Context context = conceptIdGetTimer.time()) {
        ai.grakn.concept.Concept concept = getter.apply(tx);
        Optional<Concept> conceptWrapper = Optional.ofNullable(concept).map(ConceptBuilder::build);
        if (conceptWrapper.isPresent()) {
            response.status(SC_OK);
            return objectMapper.writeValueAsString(conceptWrapper.get());
        } else {
            response.status(SC_NOT_FOUND);
            return "";
        }
    }
}
Also used : Concept(ai.grakn.engine.controller.response.Concept) GraknTx(ai.grakn.GraknTx) ConceptBuilder(ai.grakn.engine.controller.response.ConceptBuilder) Timer(com.codahale.metrics.Timer)

Aggregations

GraknTx (ai.grakn.GraknTx)1 Concept (ai.grakn.engine.controller.response.Concept)1 ConceptBuilder (ai.grakn.engine.controller.response.ConceptBuilder)1 Timer (com.codahale.metrics.Timer)1