Search in sources :

Example 1 with IndexHandler

use of nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler in project timbuctoo by HuygensING.

the class FulltextIndexChangeListenerTest method onCreateHandlesWwDocumentsUsingCustomLogic.

@Test
public void onCreateHandlesWwDocumentsUsingCustomLogic() {
    IndexHandler indexHandler = mock(IndexHandler.class);
    GraphWrapper graphWrapper = newGraph().withVertex("doc", v -> v.withProperty("wwdocument_name", "foo").withOutgoingRelation("isCreatedBy", "authorA", r -> r.withAccepted("wwrelation", true).withIsLatest(true)).withOutgoingRelation("isCreatedBy", "authorB", r -> r.withAccepted("wwrelation", true).withIsLatest(true))).withVertex("authorA", v -> v.withProperty("wwperson_name", "authorA")).withVertex("authorB", v -> v.withProperty("wwperson_name", "authorB")).wrap();
    FulltextIndexChangeListener instance = new FulltextIndexChangeListener(indexHandler, graphWrapper);
    Collection collection = new VresBuilder().withVre("womenwriters", "ww", vre -> vre.withCollection("wwdocuments", coll -> coll.withDisplayName(localProperty("wwdocument_name"))).withCollection("wwpersons", coll -> coll.withDisplayName(localProperty("wwperson_name")))).build().getCollection("wwdocuments").get();
    Vertex vertex = graphWrapper.getGraph().traversal().V().next();
    instance.onCreate(collection, vertex);
    verify(indexHandler).upsertIntoQuickSearchIndex(collection, "authorA; authorB foo", vertex, null);
}
Also used : GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) IndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Optional(java.util.Optional) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Mockito.mock(org.mockito.Mockito.mock) Mockito.verify(org.mockito.Mockito.verify) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) IndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Test(org.junit.Test)

Example 2 with IndexHandler

use of nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler in project timbuctoo by HuygensING.

the class IdIndexChangeListenerTest method onCreateAddsTheVertexToTheIdIndex.

@Test
public void onCreateAddsTheVertexToTheIdIndex() {
    UUID timId = UUID.randomUUID();
    Vertex vertex = vertexWithId(timId);
    IndexHandler indexHandler = mock(IndexHandler.class);
    IdIndexChangeListener instance = new IdIndexChangeListener(indexHandler);
    instance.onCreate(NULL_COLLECTION, vertex);
    verify(indexHandler).upsertIntoIdIndex(timId, vertex);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) IndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with IndexHandler

use of nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler in project timbuctoo by HuygensING.

the class Neo4jLuceneEntityFetcherTest method getEntityRetrievesTheLatestFromTheGraphEvenIfTheIndexIsNotUpToDate.

@Test
public void getEntityRetrievesTheLatestFromTheGraphEvenIfTheIndexIsNotUpToDate() {
    final UUID timId = UUID.randomUUID();
    final String collectionName = "things";
    TinkerPopGraphManager graphManager = newGraph().withVertex("latest", v -> v.withTimId(timId).isLatest(true)).withVertex(v -> v.withTimId(timId).isLatest(false).withOutgoingRelation("VERSION_OF", "latest")).wrap();
    GraphTraversal<Vertex, Vertex> secondLatestVertexT = graphManager.getGraph().traversal().V().has("tim_id", timId.toString()).has("isLatest", false);
    given(indexHandler.findById(timId)).willReturn(Optional.of(secondLatestVertexT.next()));
    Neo4jLuceneEntityFetcher instance = new Neo4jLuceneEntityFetcher(graphManager, indexHandler);
    GraphTraversalSource traversal = graphManager.getGraph().traversal();
    GraphTraversal<Vertex, Vertex> entityT = instance.getEntity(traversal, timId, null, collectionName);
    assertThat(entityT.hasNext(), is(true));
    assertThat(entityT.next(), is(likeVertex().withTimId(timId).withProperty("isLatest", true)));
}
Also used : TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Neo4jLuceneEntityFetcher(nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jLuceneEntityFetcher) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) BDDMockito.given(org.mockito.BDDMockito.given) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) IndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) UUID(java.util.UUID) Neo4jLuceneEntityFetcher(nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jLuceneEntityFetcher) Test(org.junit.Test)

Example 4 with IndexHandler

use of nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler in project timbuctoo by HuygensING.

the class Neo4jLuceneEntityFetcherTest method getEntityRetrievesTheVertexDirectFromTheDatabaseWhenTheIndexDoesNotContainIt.

@Test
public void getEntityRetrievesTheVertexDirectFromTheDatabaseWhenTheIndexDoesNotContainIt() {
    final UUID timId = UUID.randomUUID();
    final String things = "things";
    TinkerPopGraphManager graphManager = newGraph().withVertex("latest", v -> v.withTimId(timId).isLatest(true)).withVertex(v -> v.withTimId(timId).isLatest(false).withOutgoingRelation("VERSION_OF", "latest")).wrap();
    given(indexHandler.findById(timId)).willReturn(Optional.empty());
    Neo4jLuceneEntityFetcher instance = new Neo4jLuceneEntityFetcher(graphManager, indexHandler);
    GraphTraversalSource traversal = graphManager.getGraph().traversal();
    GraphTraversal<Vertex, Vertex> entityT = instance.getEntity(traversal, timId, null, things);
    assertThat(entityT.next().value("tim_id"), equalTo(timId.toString()));
}
Also used : TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Neo4jLuceneEntityFetcher(nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jLuceneEntityFetcher) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) BDDMockito.given(org.mockito.BDDMockito.given) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) IndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) UUID(java.util.UUID) Neo4jLuceneEntityFetcher(nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jLuceneEntityFetcher) Test(org.junit.Test)

Example 5 with IndexHandler

use of nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler in project timbuctoo by HuygensING.

the class FulltextIndexChangeListenerTest method doesNotThrowWhenDisplayNameTraversalYieldsNoResults.

@Test
public void doesNotThrowWhenDisplayNameTraversalYieldsNoResults() {
    final String theMissingPropertyName = "missingProperty_name";
    IndexHandler indexHandler = mock(IndexHandler.class);
    GraphWrapper graphWrapper = newGraph().withVertex("newVertex", v -> v.withProperty("locateMe", "here")).wrap();
    FulltextIndexChangeListener instance = new FulltextIndexChangeListener(indexHandler, graphWrapper);
    Collection collection = new VresBuilder().withVre("thevre", "vre", vre -> vre.withCollection("vrecolls", coll -> coll.withDisplayName(localProperty(theMissingPropertyName)))).build().getCollection("vrecolls").get();
    Vertex newVertex = graphWrapper.getGraph().traversal().V().has("locateMe", "here").next();
    instance.onAddToCollection(collection, Optional.empty(), newVertex);
}
Also used : GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) IndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Optional(java.util.Optional) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Mockito.mock(org.mockito.Mockito.mock) Mockito.verify(org.mockito.Mockito.verify) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) IndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Test(org.junit.Test)

Aggregations

IndexHandler (nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler)7 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)7 Test (org.junit.Test)7 Optional (java.util.Optional)6 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)6 Mockito.mock (org.mockito.Mockito.mock)6 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)4 PropertyTypes.localProperty (nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty)4 VresBuilder (nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder)4 GraphWrapper (nl.knaw.huygens.timbuctoo.server.GraphWrapper)4 Mockito.verify (org.mockito.Mockito.verify)4 UUID (java.util.UUID)3 Neo4jLuceneEntityFetcher (nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jLuceneEntityFetcher)2 TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)2 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)2 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)2 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Matchers.is (org.hamcrest.Matchers.is)2