use of nl.knaw.huygens.timbuctoo.core.dto.DataStream in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getCollectionReturnsTheKnowsDisplayNameForEachItem.
@Test
public void getCollectionReturnsTheKnowsDisplayNameForEachItem() {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withLabel("testthing").withVre("test").withType("thing").isLatest(true).withTimId(id1.toString()).withProperty("testthing_displayName", // configured in JsonCrudServiceBuilder
"displayName1")).withVertex(v -> v.withLabel("testthing").withVre("test").withType("thing").isLatest(true).withTimId(id2.toString()).withProperty("testthing_displayName", // configured in JsonCrudServiceBuilder
"displayName2")).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
DataStream<ReadEntity> entities = instance.getCollection(collection, 0, 2, true, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
List<String> displayNames = entities.map(ReadEntity::getDisplayName);
assertThat(displayNames, containsInAnyOrder("displayName1", "displayName2"));
}
use of nl.knaw.huygens.timbuctoo.core.dto.DataStream in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getCollectionReturnsAllTheLatestEntitiesOfACollection.
@Test
public void getCollectionReturnsAllTheLatestEntitiesOfACollection() {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
UUID id3 = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withLabel("testthing").withType("thing").withVre("test").isLatest(true).withTimId(id1.toString())).withVertex(v -> v.withLabel("testthing").withType("thing").withVre("test").isLatest(true).withTimId(id2.toString())).withVertex(v -> v.withLabel("testthing").withType("thing").withVre("test").isLatest(false).withTimId(id2.toString())).withVertex(v -> v.withLabel("testthing").withType("thing").withVre("test").isLatest(true).withTimId(id3.toString())).withVertex(v -> v.withLabel("teststuff").withType("stuff").withVre("test").isLatest(true).withTimId(UUID.randomUUID().toString())).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
DataStream<ReadEntity> entities = instance.getCollection(collection, 0, 3, false, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
List<UUID> ids = entities.map(ReadEntity::getId);
assertThat(ids, hasSize(3));
assertThat(ids, containsInAnyOrder(id1, id2, id3));
}
use of nl.knaw.huygens.timbuctoo.core.dto.DataStream in project timbuctoo by HuygensING.
the class JsonCrudService method getCollection.
public List<ObjectNode> getCollection(String collectionName, int rows, int start, boolean withRelations) throws InvalidCollectionException {
final Collection collection = mappings.getCollection(collectionName).orElseThrow(() -> new InvalidCollectionException(collectionName));
DataStream<ReadEntity> entities = timDbAccess.getCollection(collection, start, rows, withRelations, (traversalSource, vre) -> {
}, (entity1, entityVertex, target, relationRef) -> {
});
List<ObjectNode> result = entities.map(entity -> entityToJsonMapper.mapEntity(collection, entity, withRelations, (readEntity, resultJson) -> {
}, (relationRef, resultJson) -> {
}));
return result;
}
use of nl.knaw.huygens.timbuctoo.core.dto.DataStream in project timbuctoo by HuygensING.
the class TinkerPopOperations method getCollection.
@Override
public DataStream<ReadEntity> getCollection(Collection collection, int start, int rows, boolean withRelations, CustomEntityProperties customEntityProperties, CustomRelationProperties customRelationProperties) {
GraphTraversal<Vertex, Vertex> entities = getCurrentEntitiesFor(collection.getEntityTypeName()).range(start, start + rows);
TinkerPopToEntityMapper tinkerPopToEntityMapper = new TinkerPopToEntityMapper(collection, traversal, mappings, customEntityProperties, customRelationProperties);
return new TinkerPopGetCollection(entities.toStream().map(vertex -> tinkerPopToEntityMapper.mapEntity(vertex, withRelations)));
}
use of nl.knaw.huygens.timbuctoo.core.dto.DataStream in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getCollectionReturnsRelationsIfRequested.
@Test
public void getCollectionReturnsRelationsIfRequested() {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID thingId = UUID.randomUUID();
UUID stuffId = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex("v1", v -> v.withLabel("testthing").withVre("test").withType("thing").isLatest(true).withTimId(thingId.toString()).withOutgoingRelation("isCreatorOf", "stuff")).withVertex("stuff", v -> v.withVre("test").withType("stuff").withTimId(stuffId.toString())).withVertex(v -> v.withProperty("relationtype_regularName", "isCreatedBy").withProperty("relationtype_inverseName", "isCreatorOf")).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
DataStream<ReadEntity> entities = instance.getCollection(collection, 0, 1, true, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
ReadEntity readEntity = entities.map(entity -> entity).get(0);
assertThat(readEntity.getRelations(), contains(allOf(hasProperty("entityId", equalTo(stuffId.toString())), hasProperty("collectionName", equalTo("teststuffs")), hasProperty("entityType", equalTo("teststuff")), hasProperty("relationType", equalTo("isCreatorOf")))));
}
Aggregations