Search in sources :

Example 1 with Things

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

the class ConceptController method getTypeInstances.

private String getTypeInstances(Request request, Response response) throws JsonProcessingException {
    response.type(APPLICATION_JSON);
    Keyspace keyspace = Keyspace.of(mandatoryPathParameter(request, KEYSPACE_PARAM));
    Label label = Label.of(mandatoryPathParameter(request, LABEL_PARAMETER));
    int offset = getOffset(request);
    int limit = getLimit(request);
    try (GraknTx tx = factory.tx(keyspace, READ);
        Timer.Context context = instancesGetTimer.time()) {
        Type type = tx.getType(label);
        if (type == null) {
            response.status(SC_NOT_FOUND);
            return "";
        }
        // Get the wrapper
        Things things = ConceptBuilder.buildThings(type, offset, limit);
        response.status(SC_OK);
        return objectMapper.writeValueAsString(things);
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Type(ai.grakn.concept.Type) Timer(com.codahale.metrics.Timer) Keyspace(ai.grakn.Keyspace) Things(ai.grakn.engine.controller.response.Things) Label(ai.grakn.concept.Label)

Aggregations

GraknTx (ai.grakn.GraknTx)1 Keyspace (ai.grakn.Keyspace)1 Label (ai.grakn.concept.Label)1 Type (ai.grakn.concept.Type)1 Things (ai.grakn.engine.controller.response.Things)1 Timer (com.codahale.metrics.Timer)1