Search in sources :

Example 61 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.

the class Neo4JIndexHandlerTest method findByQuickSearchRetrievesTheVerticesFromTheIndexAndCreatesTraversalForThem.

@Test
public void findByQuickSearchRetrievesTheVerticesFromTheIndexAndCreatesTraversalForThem() {
    String id1 = UUID.randomUUID().toString();
    String id2 = UUID.randomUUID().toString();
    String id3 = UUID.randomUUID().toString();
    TinkerPopGraphManager tinkerPopGraphManager = newGraph().withVertex(v -> v.withTimId(id1).withProperty("displayName", "query")).withVertex(v -> v.withTimId(id2).withProperty("displayName", "query2")).withVertex(v -> v.withTimId(id3).withProperty("displayName", "notmatching")).wrap();
    Neo4jIndexHandler instance = new Neo4jIndexHandler(tinkerPopGraphManager);
    addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id1).next());
    addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id2).next());
    addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id3).next());
    QuickSearch quickSearch = QuickSearch.fromQueryString("query*");
    GraphTraversal<Vertex, Vertex> vertices = instance.findByQuickSearch(collection, quickSearch);
    assertThat(vertices.map(v -> v.get().value("tim_id")).toList(), containsInAnyOrder(id1, id2));
}
Also used : Matchers.empty(org.hamcrest.Matchers.empty) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Matchers.not(org.hamcrest.Matchers.not) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Assert.assertThat(org.junit.Assert.assertThat) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Optional(java.util.Optional) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) Matchers.is(org.hamcrest.Matchers.is) Transaction(org.neo4j.graphdb.Transaction) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) Test(org.junit.Test)

Example 62 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal 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 63 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal 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 64 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.

the class TinkerPopOperations method replaceEntity.

@Override
public int replaceEntity(Collection collection, UpdateEntity updateEntity) throws NotFoundException, AlreadyUpdatedException, IOException {
    requireCommit = true;
    GraphTraversal<Vertex, Vertex> entityTraversal = entityFetcher.getEntity(this.traversal, updateEntity.getId(), null, collection.getCollectionName());
    if (!entityTraversal.hasNext()) {
        throw new NotFoundException();
    }
    Vertex entityVertex = entityTraversal.next();
    int curRev = getProp(entityVertex, "rev", Integer.class).orElse(1);
    if (curRev != updateEntity.getRev()) {
        throw new AlreadyUpdatedException();
    }
    int newRev = updateEntity.getRev() + 1;
    entityVertex.property("rev", newRev);
    // update properties
    TinkerPopPropertyConverter tinkerPopPropertyConverter = new TinkerPopPropertyConverter(collection);
    for (TimProperty<?> property : updateEntity.getProperties()) {
        try {
            Tuple<String, Object> nameValue = property.convert(tinkerPopPropertyConverter);
            collection.getWriteableProperties().get(nameValue.getLeft()).setValue(entityVertex, nameValue.getRight());
        } catch (IOException e) {
            throw new IOException(property.getName() + " could not be saved. " + e.getMessage(), e);
        }
    }
    // Set removed values to null.
    Set<String> propertyNames = updateEntity.getProperties().stream().map(prop -> prop.getName()).collect(Collectors.toSet());
    for (String name : Sets.difference(collection.getWriteableProperties().keySet(), propertyNames)) {
        collection.getWriteableProperties().get(name).setJson(entityVertex, null);
    }
    String entityTypesStr = getProp(entityVertex, "types", String.class).orElse("[]");
    boolean wasAddedToCollection = false;
    if (!entityTypesStr.contains("\"" + collection.getEntityTypeName() + "\"")) {
        try {
            ArrayNode entityTypes = arrayToEncodedArray.tinkerpopToJson(entityTypesStr);
            entityTypes.add(collection.getEntityTypeName());
            entityVertex.property("types", entityTypes.toString());
            wasAddedToCollection = true;
        } catch (IOException e) {
            // FIXME potential bug?
            LOG.error(Logmarkers.databaseInvariant, "property 'types' was not parseable: " + entityTypesStr);
        }
    }
    setModified(entityVertex, updateEntity.getModified());
    entityVertex.property("pid").remove();
    Vertex duplicate = duplicateVertex(traversal, entityVertex, indexHandler);
    listener.onPropertyUpdate(collection, Optional.of(entityVertex), duplicate);
    if (wasAddedToCollection) {
        listener.onAddToCollection(collection, Optional.of(entityVertex), duplicate);
    }
    return newRev;
}
Also used : AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) RdfImportedDefaultDisplayname(nl.knaw.huygens.timbuctoo.model.properties.RdfImportedDefaultDisplayname) VRE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.VRE_NAME_PROPERTY_NAME) EdgeManipulator.duplicateEdge(nl.knaw.huygens.timbuctoo.database.tinkerpop.EdgeManipulator.duplicateEdge) MediaType(javax.ws.rs.core.MediaType) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) ReadableProperty(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty) RdfProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfProperty) COLLECTION_IS_UNKNOWN_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_IS_UNKNOWN_PROPERTY_NAME) Map(java.util.Map) Converters.arrayToEncodedArray(nl.knaw.huygens.timbuctoo.model.properties.converters.Converters.arrayToEncodedArray) JsonNode(com.fasterxml.jackson.databind.JsonNode) DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) HAS_ENTITY_NODE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) RdfIndexChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.RdfIndexChangeListener) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) Logmarkers.configurationFailure(nl.knaw.huygens.timbuctoo.logging.Logmarkers.configurationFailure) Set(java.util.Set) ChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ImmutableValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableValueTypeInUse) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) DATABASE_LABEL(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.DATABASE_LABEL) Element(org.apache.tinkerpop.gremlin.structure.Element) Stream(java.util.stream.Stream) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Index(org.neo4j.graphdb.index.Index) ERROR_PREFIX(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.ERROR_PREFIX) LocalProperty(nl.knaw.huygens.timbuctoo.model.properties.LocalProperty) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) RAW_PROPERTY_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_PROPERTY_EDGE_NAME) CreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty) Supplier(java.util.function.Supplier) Node(org.neo4j.graphdb.Node) CreateRelation(nl.knaw.huygens.timbuctoo.core.dto.CreateRelation) Lists(com.google.common.collect.Lists) ImmutableVresDto(nl.knaw.huygens.timbuctoo.core.dto.dataset.ImmutableVresDto) PersonNames(nl.knaw.huygens.timbuctoo.model.PersonNames) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) StreamSupport(java.util.stream.StreamSupport) PropertyDescriptorFactory(nl.knaw.huygens.timbuctoo.search.description.property.PropertyDescriptorFactory) RelationType(nl.knaw.huygens.timbuctoo.core.dto.RelationType) Logmarkers.databaseInvariant(nl.knaw.huygens.timbuctoo.logging.Logmarkers.databaseInvariant) RelationTypeService(nl.knaw.huygens.timbuctoo.relationtypes.RelationTypeService) AddLabelChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.AddLabelChangeListener) VreBuilder(nl.knaw.huygens.timbuctoo.model.vre.VreBuilder) DataStream(nl.knaw.huygens.timbuctoo.core.dto.DataStream) ImmutablePredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutablePredicateInUse) IOException(java.io.IOException) T(org.apache.tinkerpop.gremlin.structure.T) HAS_NEXT_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty.HAS_NEXT_PROPERTY_RELATION_NAME) DatabaseMigrator(nl.knaw.huygens.timbuctoo.server.databasemigration.DatabaseMigrator) Direction(org.apache.tinkerpop.gremlin.structure.Direction) VertexDuplicator.duplicateVertex(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.duplicateVertex) CompositeChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.CompositeChangeListener) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) TinkerPopPropertyConverter(nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter) GraphReadUtils.getProp(nl.knaw.huygens.timbuctoo.model.GraphReadUtils.getProp) Change(nl.knaw.huygens.timbuctoo.model.Change) WwDocumentDisplayNameDescriptor(nl.knaw.huygens.timbuctoo.search.description.property.WwDocumentDisplayNameDescriptor) RDFINDEX_NAME(nl.knaw.huygens.timbuctoo.rdf.Database.RDFINDEX_NAME) ImmutableEntityRelation(nl.knaw.huygens.timbuctoo.core.dto.ImmutableEntityRelation) StreamIterator.stream(nl.knaw.huygens.timbuctoo.util.StreamIterator.stream) HAS_ARCHETYPE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ARCHETYPE_RELATION_NAME) Graph(org.apache.tinkerpop.gremlin.structure.Graph) LoggerFactory(org.slf4j.LoggerFactory) RDF_SYNONYM_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_SYNONYM_PROP) PropertyParserFactory(nl.knaw.huygens.timbuctoo.search.description.propertyparser.PropertyParserFactory) EntityRelation(nl.knaw.huygens.timbuctoo.core.dto.EntityRelation) TinkerPopToEntityMapper(nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopToEntityMapper) RelationNotPossibleException(nl.knaw.huygens.timbuctoo.core.RelationNotPossibleException) URI(java.net.URI) P(org.apache.tinkerpop.gremlin.process.traversal.P) Property(org.apache.tinkerpop.gremlin.structure.Property) IS_RELATION_COLLECTION_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.IS_RELATION_COLLECTION_PROPERTY_NAME) CollectionHasEntityRelationChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.CollectionHasEntityRelationChangeListener) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has) ImmutableMap(com.google.common.collect.ImmutableMap) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) EntityFinisherHelper(nl.knaw.huygens.timbuctoo.core.EntityFinisherHelper) LocationNames(nl.knaw.huygens.timbuctoo.model.LocationNames) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) DirectionalRelationType(nl.knaw.huygens.timbuctoo.core.dto.DirectionalRelationType) Optional(java.util.Optional) FulltextIndexChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.FulltextIndexChangeListener) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) HAS_PREDICATE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PREDICATE_RELATION_NAME) Tuple(nl.knaw.huygens.timbuctoo.util.Tuple) HashMap(java.util.HashMap) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Function(java.util.function.Function) VERSION_OF(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.VERSION_OF) VreMetadata(nl.knaw.huygens.timbuctoo.model.vre.VreMetadata) Logmarkers(nl.knaw.huygens.timbuctoo.logging.Logmarkers) CollectionNameHelper.defaultEntityTypeName(nl.knaw.huygens.timbuctoo.core.CollectionNameHelper.defaultEntityTypeName) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) SAVED_MAPPING_STATE(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.SAVED_MAPPING_STATE) HAS_INITIAL_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_INITIAL_PROPERTY_RELATION_NAME) JsonBuilder.jsnA(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnA) COLLECTION_ENTITIES_LABEL(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_ENTITIES_LABEL) NoSuchElementException(java.util.NoSuchElementException) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) Edge(org.apache.tinkerpop.gremlin.structure.Edge) RdfReadProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfReadProperty) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) Logger(org.slf4j.Logger) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) Iterator(java.util.Iterator) RAW_ITEM_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_ITEM_EDGE_NAME) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) PropertyDescriptor(nl.knaw.huygens.timbuctoo.search.description.PropertyDescriptor) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) TempName(nl.knaw.huygens.timbuctoo.model.TempName) Maps(com.google.common.collect.Maps) IdIndexChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.IdIndexChangeListener) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) PropertyNameHelper.createPropName(nl.knaw.huygens.timbuctoo.database.tinkerpop.PropertyNameHelper.createPropName) TIMBUCTOO_NAMESPACE(nl.knaw.huygens.timbuctoo.server.databasemigration.RelationTypeRdfUriMigration.TIMBUCTOO_NAMESPACE) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) SystemPropertyModifier(nl.knaw.huygens.timbuctoo.rdf.SystemPropertyModifier) Collectors.toList(java.util.stream.Collectors.toList) HAS_COLLECTION_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.HAS_COLLECTION_RELATION_NAME) Clock(java.time.Clock) HAS_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PROPERTY_RELATION_NAME) RAW_COLLECTION_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_EDGE_NAME) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexDuplicator.duplicateVertex(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.duplicateVertex) AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) TinkerPopPropertyConverter(nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) IOException(java.io.IOException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 65 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.

the class ChangeRangeFacetDescriptionTest method filterAddsAFilterThatChecksIfTheDateIsBetweenTheUpperAndLowerLimit.

@Test
public void filterAddsAFilterThatChecksIfTheDateIsBetweenTheUpperAndLowerLimit() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY_NAME, serializedChangeWithDate("20150101"))).withVertex(v -> v.withTimId("id2").withProperty(PROPERTY_NAME, serializedChangeWithDate("10000302"))).withVertex(v -> v.withTimId("id3").withProperty(PROPERTY_NAME, serializedChangeWithDate("21000302"))).build().traversal().V();
    List<FacetValue> facets = Lists.newArrayList(new DateRangeFacetValue(FACET_NAME, 20000101, 20160101));
    instance.filter(traversal, facets);
    assertThat(traversal.toList(), contains(likeVertex().withTimId("id1")));
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Instant(java.time.Instant) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ZoneId(java.time.ZoneId) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Lists(com.google.common.collect.Lists) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Change(nl.knaw.huygens.timbuctoo.model.Change) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) Test(org.junit.Test)

Aggregations

GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)93 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)67 Test (org.junit.Test)57 List (java.util.List)51 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)50 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)44 Before (org.junit.Before)42 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)40 Matchers.contains (org.hamcrest.Matchers.contains)39 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)35 Lists (com.google.common.collect.Lists)34 FacetValue (nl.knaw.huygens.timbuctoo.search.FacetValue)31 Optional (java.util.Optional)24 P (org.apache.tinkerpop.gremlin.process.traversal.P)21 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)20 ListFacetValue (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue)19 Matchers.is (org.hamcrest.Matchers.is)17 Mockito.mock (org.mockito.Mockito.mock)17 Matchers.empty (org.hamcrest.Matchers.empty)15 Edge (org.apache.tinkerpop.gremlin.structure.Edge)14