Search in sources :

Example 1 with TinkerpopSaver

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;
        }
    }
}
Also used : StateMachine(nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.StateMachine) InvalidFileException(nl.knaw.huygens.timbuctoo.bulkupload.InvalidFileException) TinkerpopSaver(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver) IOException(java.io.IOException) ResultReporter(nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.ResultReporter) Importer(nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.Importer)

Example 2 with TinkerpopSaver

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")));
}
Also used : ImportPropertyDescriptions(nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.ImportPropertyDescriptions) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerpopSaver(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver) Test(org.junit.Test)

Example 3 with TinkerpopSaver

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));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerpopSaver(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver) Test(org.junit.Test)

Example 4 with TinkerpopSaver

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));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerpopSaver(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver) Test(org.junit.Test)

Example 5 with TinkerpopSaver

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));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerpopSaver(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver) Test(org.junit.Test)

Aggregations

TinkerpopSaver (nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver)7 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)6 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)6 Test (org.junit.Test)6 ImportPropertyDescriptions (nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.ImportPropertyDescriptions)2 IOException (java.io.IOException)1 InvalidFileException (nl.knaw.huygens.timbuctoo.bulkupload.InvalidFileException)1 Importer (nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.Importer)1 ResultReporter (nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.ResultReporter)1 StateMachine (nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.StateMachine)1