use of nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver in project timbuctoo by HuygensING.
the class BulkUploadService method saveToDb.
public void saveToDb(String vreName, Loader loader, List<Tuple<String, File>> tempFiles, String vreLabel, Consumer<String> statusUpdate) throws IOException, InvalidFileException {
String fileNamesDisplay;
if (tempFiles.size() == 1) {
fileNamesDisplay = tempFiles.get(0).getLeft();
} else {
fileNamesDisplay = "multiple files: " + tempFiles.stream().map(Tuple::getLeft).collect(joining(", "));
}
try (TinkerpopSaver saver = new TinkerpopSaver(vres, graphwrapper, vreName, vreLabel, maxVertices, fileNamesDisplay)) {
try {
loader.loadData(tempFiles, new Importer(new StateMachine(saver), new ResultReporter(statusUpdate)));
saver.setUploadFinished(vreName, Vre.PublishState.MAPPING_CREATION);
} catch (IOException | InvalidFileException e) {
saver.setUploadFinished(vreName, Vre.PublishState.UPLOAD_FAILED);
throw e;
}
}
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver in project timbuctoo by HuygensING.
the class TinkerpopSaverTest method addPropertyDescriptionsStoresTheOrderOfThePropertyDescriptions.
@Test
public void addPropertyDescriptionsStoresTheOrderOfThePropertyDescriptions() {
final TinkerpopSaver instance = new TinkerpopSaver(vres, graphWrapper, VRE_NAME, VRE_NAME, MAX_VERTICES_PER_TRANSACTION, VRE_NAME);
ImportPropertyDescriptions importPropertyDescriptions = new ImportPropertyDescriptions();
importPropertyDescriptions.getOrCreate(6).setPropertyName("first");
importPropertyDescriptions.getOrCreate(5).setPropertyName("second");
importPropertyDescriptions.getOrCreate(7).setPropertyName("third");
instance.addPropertyDescriptions(rawCollection, importPropertyDescriptions);
Iterator<Vertex> hasFirstProperty = rawCollection.vertices(Direction.OUT, "hasFirstProperty");
assertThat(hasFirstProperty.hasNext(), is(true));
Vertex first = hasFirstProperty.next();
assertThat(first, likeVertex().withProperty("id", 6).withProperty("name", "first"));
Iterator<Vertex> hasNextProperty = first.vertices(Direction.OUT, "hasNextProperty");
assertThat(hasNextProperty.hasNext(), is(true));
Vertex second = hasNextProperty.next();
assertThat(second, is(likeVertex().withProperty("id", 5).withProperty("name", "second")));
Iterator<Vertex> hasNextProperty2 = second.vertices(Direction.OUT, "hasNextProperty");
assertThat(hasNextProperty2.hasNext(), is(true));
assertThat(hasNextProperty2.next(), is(likeVertex().withProperty("id", 7).withProperty("name", "third")));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver in project timbuctoo by HuygensING.
the class TinkerpopSaverTest method addEntityAddsARelationThatIndicatesTheFirstRelation.
@Test
public void addEntityAddsARelationThatIndicatesTheFirstRelation() {
TinkerpopSaver instance = new TinkerpopSaver(vres, graphWrapper, VRE_NAME, VRE_NAME, MAX_VERTICES_PER_TRANSACTION, VRE_NAME);
Vertex first = instance.addEntity(rawCollection, Maps.newHashMap());
instance.addEntity(rawCollection, Maps.newHashMap());
List<Vertex> hasFirstItems = Lists.newArrayList(rawCollection.vertices(Direction.OUT, NEXT_RAW_ITEM_EDGE_NAME));
assertThat(hasFirstItems, hasSize(1));
assertThat(hasFirstItems, contains(first));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver in project timbuctoo by HuygensING.
the class TinkerpopSaverTest method addEntityAddsEachEntityToTheCollection.
@Test
public void addEntityAddsEachEntityToTheCollection() {
TinkerpopSaver instance = new TinkerpopSaver(vres, graphWrapper, VRE_NAME, VRE_NAME, MAX_VERTICES_PER_TRANSACTION, VRE_NAME);
Vertex first = instance.addEntity(rawCollection, Maps.newHashMap());
Vertex second = instance.addEntity(rawCollection, Maps.newHashMap());
List<Vertex> items = Lists.newArrayList(rawCollection.vertices(Direction.OUT, "hasItem"));
assertThat(items, containsInAnyOrder(first, second));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver in project timbuctoo by HuygensING.
the class TinkerpopSaverTest method addEntityCreatesAChainOfEntities.
@Test
public void addEntityCreatesAChainOfEntities() {
final TinkerpopSaver instance = new TinkerpopSaver(vres, graphWrapper, VRE_NAME, VRE_NAME, MAX_VERTICES_PER_TRANSACTION, VRE_NAME);
Vertex first = instance.addEntity(rawCollection, Maps.newHashMap());
Vertex second = instance.addEntity(rawCollection, Maps.newHashMap());
Vertex third = instance.addEntity(rawCollection, Maps.newHashMap());
List<Vertex> orderedList = graphWrapper.getGraph().traversal().V(rawCollection.id()).emit().repeat(__.out(NEXT_RAW_ITEM_EDGE_NAME)).toList();
assertThat(orderedList, contains(rawCollection, first, second, third));
}
Aggregations