use of ai.grakn.concept.Type 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);
}
}
use of ai.grakn.concept.Type in project grakn by graknlabs.
the class RemoteConceptsTest method whenCallingPlayedByTypes_GetTheExpectedResult.
@Test
public void whenCallingPlayedByTypes_GetTheExpectedResult() {
Type a = RemoteConcepts.createEntityType(tx, A);
Type b = RemoteConcepts.createRelationshipType(tx, B);
Type c = RemoteConcepts.createAttributeType(tx, C);
mockConceptMethod(ConceptMethods.GET_TYPES_THAT_PLAY_ROLE, Stream.of(a, b, c));
assertThat(role.playedByTypes().collect(toSet()), containsInAnyOrder(a, b, c));
}
use of ai.grakn.concept.Type in project grakn by graknlabs.
the class RemoteConceptsTest method whenCallingType_GetTheExpectedResult.
@Test
public void whenCallingType_GetTheExpectedResult() {
Type type = RemoteConcepts.createEntityType(tx, A);
mockConceptMethod(GET_DIRECT_TYPE, type);
assertEquals(type, thing.type());
}
use of ai.grakn.concept.Type in project grakn by graknlabs.
the class RemoteConceptsTest method whenCallingSubs_GetTheExpectedResult.
@Test
public void whenCallingSubs_GetTheExpectedResult() {
Type me = relationshipType;
Type mySub = RemoteConcepts.createRelationshipType(tx, A);
Type mySubsSub = RemoteConcepts.createRelationshipType(tx, B);
mockConceptMethod(ConceptMethods.GET_SUB_CONCEPTS, Stream.of(me, mySub, mySubsSub));
assertThat(relationshipType.subs().collect(toSet()), containsInAnyOrder(me, mySub, mySubsSub));
}
use of ai.grakn.concept.Type in project grakn by graknlabs.
the class RemoteConceptsTest method whenCallingSups_GetTheExpectedResult.
@Test
public void whenCallingSups_GetTheExpectedResult() {
Type me = entityType;
Type mySuper = RemoteConcepts.createEntityType(tx, A);
Type mySupersSuper = RemoteConcepts.createEntityType(tx, B);
Type metaType = RemoteConcepts.createMetaType(tx, C);
mockConceptMethod(ConceptMethods.GET_SUPER_CONCEPTS, Stream.of(me, mySuper, mySupersSuper, metaType));
Set<Type> sups = entityType.sups().collect(toSet());
assertThat(sups, containsInAnyOrder(me, mySuper, mySupersSuper));
assertThat(sups, not(hasItem(metaType)));
}
Aggregations