use of nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopToEntityMapper 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.database.tinkerpop.conversion.TinkerPopToEntityMapper in project timbuctoo by HuygensING.
the class TinkerPopToEntityMapperTest method mapEntitySetsABogusTimIdWhenTheVertexHasNoTimId.
@Test
public void mapEntitySetsABogusTimIdWhenTheVertexHasNoTimId() {
UUID bogusId = UUID.fromString("0000000-0000-0000-0000-000000000000");
GraphTraversalSource traversalSource = newGraph().withVertex(v -> v.withType("thing").withVre("test").withProperty("isLatest", true).withProperty("deleted", true).withProperty("rev", 1)).build().traversal();
GraphTraversal<Vertex, Vertex> traversal = traversalSource.V();
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
TinkerPopToEntityMapper instance = new TinkerPopToEntityMapper(collection, traversalSource, vres, (entity, entityVertex) -> {
}, (traversalSource1, vre, target, relationRef) -> {
});
ReadEntity readEntity = instance.mapEntity(traversal, false);
assertThat(readEntity.getId(), is(bogusId));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopToEntityMapper in project timbuctoo by HuygensING.
the class TinkerPopOperations method getEntity.
@Override
public ReadEntity getEntity(UUID id, Integer rev, Collection collection, CustomEntityProperties customEntityProperties, CustomRelationProperties customRelationProperties) throws NotFoundException {
GraphTraversal<Vertex, Vertex> fetchedEntity = entityFetcher.getEntity(traversal, id, rev, collection.getCollectionName());
if (!fetchedEntity.hasNext()) {
throw new NotFoundException();
}
Vertex entityVertex = entityFetcher.getEntity(traversal, id, rev, collection.getCollectionName()).next();
GraphTraversal<Vertex, Vertex> entityT = traversal.V(entityVertex.id());
if (!entityT.asAdmin().clone().hasNext()) {
throw new NotFoundException();
}
String entityTypesStr = getProp(entityT.asAdmin().clone().next(), "types", String.class).orElse("[]");
if (!entityTypesStr.contains("\"" + collection.getEntityTypeName() + "\"")) {
throw new NotFoundException();
}
return new TinkerPopToEntityMapper(collection, traversal, mappings, customEntityProperties, customRelationProperties).mapEntity(entityT, true);
}
Aggregations