Search in sources :

Example 11 with org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has

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

the class TinkerPopOperationsTest method deleteVreRemovesAllTheVresCollectionsFromDatabase.

@Test
public void deleteVreRemovesAllTheVresCollectionsFromDatabase() {
    TinkerPopGraphManager graphManager = newGraph().withVertex("vreName", v -> v.withLabel("VRE").withProperty(Vre.VRE_NAME_PROPERTY_NAME, "vreName").withOutgoingRelation(HAS_COLLECTION_RELATION_NAME, "collection1").withOutgoingRelation(HAS_COLLECTION_RELATION_NAME, "collection2")).withVertex("collection1", v -> v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "collection1").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "entityType1").withProperty(IS_RELATION_COLLECTION_PROPERTY_NAME, true).withOutgoingRelation(HAS_DISPLAY_NAME_RELATION_NAME, "displayName").withOutgoingRelation(HAS_PROPERTY_RELATION_NAME, "property").withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityNode")).withVertex("displayName", v -> v.withProperty("displayName", true).withProperty("propertyType", "string")).withVertex("property", v -> v.withProperty("property", true).withProperty("propertyType", "string")).withVertex("entityNode", v -> v.withOutgoingRelation(HAS_ENTITY_RELATION_NAME, "entity")).withVertex("entity", v -> v.withProperty("entity", true)).withVertex("collection2", v -> v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "collection2").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "entityType2").withProperty(IS_RELATION_COLLECTION_PROPERTY_NAME, false)).withVertex("otherVreCollection", v -> v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "otherVreCollection").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "entityType3").withProperty(IS_RELATION_COLLECTION_PROPERTY_NAME, false)).wrap();
    TinkerPopOperations instance = forGraphWrapper(graphManager);
    instance.deleteVre("vreName");
    Graph graph = graphManager.getGraph();
    assertThat(graph.traversal().V().has(Vre.VRE_NAME_PROPERTY_NAME, "vreName").hasNext(), equalTo(false));
    assertThat(graph.traversal().V().has(COLLECTION_NAME_PROPERTY_NAME, "collection1").hasNext(), equalTo(false));
    assertThat(graph.traversal().V().has(COLLECTION_NAME_PROPERTY_NAME, "collection2").hasNext(), equalTo(false));
    assertThat(graph.traversal().V().has(COLLECTION_NAME_PROPERTY_NAME, "otherVreCollection").hasNext(), equalTo(true));
    assertThat(graph.traversal().V().has("entity").hasNext(), equalTo(false));
    assertThat(graph.traversal().V().has("displayName").hasNext(), equalTo(false));
}
Also used : ImmutableCreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableCreateProperty) AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) NodeFactory(org.apache.jena.graph.NodeFactory) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Matchers.not(org.hamcrest.Matchers.not) CreateEntityStubs.withProperties(nl.knaw.huygens.timbuctoo.core.dto.CreateEntityStubs.withProperties) Try(javaslang.control.Try) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) RdfProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfProperty) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) 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) Matchers.allOf(org.hamcrest.Matchers.allOf) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) ValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse) ChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) Element(org.apache.tinkerpop.gremlin.structure.Element) Matchers.contains(org.hamcrest.Matchers.contains) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Matchers.is(org.hamcrest.Matchers.is) TinkerPopOperationsStubs.forGraphWrapperAndMappings(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapperAndMappings) CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) RAW_PROPERTY_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_PROPERTY_EDGE_NAME) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) CreateRelation(nl.knaw.huygens.timbuctoo.core.dto.CreateRelation) Lists(com.google.common.collect.Lists) TinkerPopOperationsStubs.forGraphMappingsAndChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndChangeListener) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) TinkerPopOperationsStubs.forGraphWrapper(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapper) Matchers.hasSize(org.hamcrest.Matchers.hasSize) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RelationType(nl.knaw.huygens.timbuctoo.core.dto.RelationType) DataStream(nl.knaw.huygens.timbuctoo.core.dto.DataStream) Test(org.junit.Test) IOException(java.io.IOException) T(org.apache.tinkerpop.gremlin.structure.T) Direction(org.apache.tinkerpop.gremlin.structure.Direction) Database(nl.knaw.huygens.timbuctoo.rdf.Database) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) GraphReadUtils.getProp(nl.knaw.huygens.timbuctoo.model.GraphReadUtils.getProp) Change(nl.knaw.huygens.timbuctoo.model.Change) P.within(org.apache.tinkerpop.gremlin.process.traversal.P.within) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) StreamIterator.stream(nl.knaw.huygens.timbuctoo.util.StreamIterator.stream) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) Graph(org.apache.tinkerpop.gremlin.structure.Graph) RDF_SYNONYM_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_SYNONYM_PROP) StringProperty(nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) RelationNotPossibleException(nl.knaw.huygens.timbuctoo.core.RelationNotPossibleException) URI(java.net.URI) IS_RELATION_COLLECTION_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.IS_RELATION_COLLECTION_PROPERTY_NAME) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) EntityFinisherHelper(nl.knaw.huygens.timbuctoo.core.EntityFinisherHelper) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Instant(java.time.Instant) RAW_COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_NAME_PROPERTY_NAME) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) TinkerPopOperationsStubs.forGraphMappingsAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndIndex) VERSION_OF(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.VERSION_OF) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VreStubs.minimalCorrectVre(nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre) CollectionNameHelper.defaultEntityTypeName(nl.knaw.huygens.timbuctoo.core.CollectionNameHelper.defaultEntityTypeName) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) 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) Matchers.empty(org.hamcrest.Matchers.empty) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) RAW_ITEM_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_ITEM_EDGE_NAME) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) Mockito.when(org.mockito.Mockito.when) PropertyNameHelper.createPropName(nl.knaw.huygens.timbuctoo.database.tinkerpop.PropertyNameHelper.createPropName) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) Mockito.verify(org.mockito.Mockito.verify) Collectors.toList(java.util.stream.Collectors.toList) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) HAS_COLLECTION_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.HAS_COLLECTION_RELATION_NAME) TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex) 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) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Graph(org.apache.tinkerpop.gremlin.structure.Graph) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Test(org.junit.Test)

Example 12 with org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has

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

the class TinkerPopOperationsTest method deleteEntitySetsDeletedToTrueWhenLastTypeIsRemoved.

@Test
public void deleteEntitySetsDeletedToTrueWhenLastTypeIsRemoved() throws Exception {
    Vres vres = createConfiguration();
    Collection collection = vres.getCollection("testthings").get();
    UUID id = UUID.randomUUID();
    String idString = id.toString();
    TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(idString).withProperty("isLatest", true).withVre("test").withType("thing").withProperty("rev", 1).withIncomingRelation("VERSION_OF", "orig")).withVertex("orig", v -> v.withTimId(idString).withVre("test").withType("thing").withProperty("isLatest", false).withProperty("rev", 1)).wrap();
    TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
    instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
    assertThat(graphManager.getGraph().traversal().V().has("tim_id", idString).has("deleted", true).hasNext(), is(true));
}
Also used : ImmutableCreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableCreateProperty) AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) NodeFactory(org.apache.jena.graph.NodeFactory) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Matchers.not(org.hamcrest.Matchers.not) CreateEntityStubs.withProperties(nl.knaw.huygens.timbuctoo.core.dto.CreateEntityStubs.withProperties) Try(javaslang.control.Try) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) RdfProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfProperty) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) 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) Matchers.allOf(org.hamcrest.Matchers.allOf) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) ValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse) ChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) Element(org.apache.tinkerpop.gremlin.structure.Element) Matchers.contains(org.hamcrest.Matchers.contains) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Matchers.is(org.hamcrest.Matchers.is) TinkerPopOperationsStubs.forGraphWrapperAndMappings(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapperAndMappings) CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) RAW_PROPERTY_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_PROPERTY_EDGE_NAME) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) CreateRelation(nl.knaw.huygens.timbuctoo.core.dto.CreateRelation) Lists(com.google.common.collect.Lists) TinkerPopOperationsStubs.forGraphMappingsAndChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndChangeListener) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) TinkerPopOperationsStubs.forGraphWrapper(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapper) Matchers.hasSize(org.hamcrest.Matchers.hasSize) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RelationType(nl.knaw.huygens.timbuctoo.core.dto.RelationType) DataStream(nl.knaw.huygens.timbuctoo.core.dto.DataStream) Test(org.junit.Test) IOException(java.io.IOException) T(org.apache.tinkerpop.gremlin.structure.T) Direction(org.apache.tinkerpop.gremlin.structure.Direction) Database(nl.knaw.huygens.timbuctoo.rdf.Database) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) GraphReadUtils.getProp(nl.knaw.huygens.timbuctoo.model.GraphReadUtils.getProp) Change(nl.knaw.huygens.timbuctoo.model.Change) P.within(org.apache.tinkerpop.gremlin.process.traversal.P.within) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) StreamIterator.stream(nl.knaw.huygens.timbuctoo.util.StreamIterator.stream) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) Graph(org.apache.tinkerpop.gremlin.structure.Graph) RDF_SYNONYM_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_SYNONYM_PROP) StringProperty(nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) RelationNotPossibleException(nl.knaw.huygens.timbuctoo.core.RelationNotPossibleException) URI(java.net.URI) IS_RELATION_COLLECTION_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.IS_RELATION_COLLECTION_PROPERTY_NAME) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) EntityFinisherHelper(nl.knaw.huygens.timbuctoo.core.EntityFinisherHelper) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Instant(java.time.Instant) RAW_COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_NAME_PROPERTY_NAME) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) TinkerPopOperationsStubs.forGraphMappingsAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndIndex) VERSION_OF(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.VERSION_OF) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VreStubs.minimalCorrectVre(nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre) CollectionNameHelper.defaultEntityTypeName(nl.knaw.huygens.timbuctoo.core.CollectionNameHelper.defaultEntityTypeName) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) 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) Matchers.empty(org.hamcrest.Matchers.empty) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) RAW_ITEM_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_ITEM_EDGE_NAME) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) Mockito.when(org.mockito.Mockito.when) PropertyNameHelper.createPropName(nl.knaw.huygens.timbuctoo.database.tinkerpop.PropertyNameHelper.createPropName) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) Mockito.verify(org.mockito.Mockito.verify) Collectors.toList(java.util.stream.Collectors.toList) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) HAS_COLLECTION_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.HAS_COLLECTION_RELATION_NAME) TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex) 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) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID) Test(org.junit.Test)

Example 13 with org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has

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

the class ChangeRangeFacetDescription method filter.

@Override
@SuppressWarnings("unchecked")
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) {
    Optional<FacetValue> first = facets.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
    if (!first.isPresent()) {
        return;
    }
    FacetValue facetValue = first.get();
    if (!(facetValue instanceof DateRangeFacetValue)) {
        return;
    }
    long lowerLimit = ((DateRangeFacetValue) facetValue).getLowerLimit();
    LocalDate lowerLimitDate = LocalDate.parse("" + lowerLimit, FORMATTER);
    long upperLimit = ((DateRangeFacetValue) facetValue).getUpperLimit();
    LocalDate upperLimitDate = LocalDate.parse(("" + upperLimit), FORMATTER);
    // Use range because the java.time.Period has no way to determine if a date falls in that Period.
    Range<LocalDate> period = Range.closed(lowerLimitDate, upperLimitDate);
    graphTraversal.where(__.has(propertyName, P.test((o1, o2) -> {
        try {
            LocalDate localDate = getChangeLocalDate(o1);
            return ((Range<LocalDate>) o2).contains(localDate);
        } catch (IOException e) {
            LOG.error("Date {} cannot be parsed.", o1);
        }
        return false;
    }, period)));
}
Also used : ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Logger(org.slf4j.Logger) LocalPropertyValueGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.LocalPropertyValueGetter) Range(com.google.common.collect.Range) LoggerFactory(org.slf4j.LoggerFactory) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) IOException(java.io.IOException) 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) ChangeRangeFacetGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.ChangeRangeFacetGetter) Objects(java.util.Objects) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) Change(nl.knaw.huygens.timbuctoo.model.Change) P(org.apache.tinkerpop.gremlin.process.traversal.P) 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) IOException(java.io.IOException) Range(com.google.common.collect.Range) LocalDate(java.time.LocalDate)

Example 14 with org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has

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

the class CharterPortaalFondsFacetDescription method filter.

@Override
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) {
    Optional<FacetValue> first = facets.stream().filter(facetValue -> Objects.equals(facetValue.getName(), getName())).findFirst();
    if (first.isPresent()) {
        FacetValue facetValue = first.get();
        if (facetValue instanceof ListFacetValue) {
            ListFacetValue listFacetValue = (ListFacetValue) facetValue;
            List<String> values = listFacetValue.getValues();
            if (values.isEmpty()) {
                return;
            }
            List<String> formattedVals = values.stream().map(val -> val.substring(val.indexOf("(") + 1, val.length() - 1)).collect(toList());
            graphTraversal.where(__.has(FONDS, P.within(formattedVals)));
        } else {
            LOG.error("Facet with name '{}' is not a ListFacet", getName());
        }
    }
}
Also used : Logger(org.slf4j.Logger) ListFacetGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.ListFacetGetter) LoggerFactory(org.slf4j.LoggerFactory) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) Objects(java.util.Objects) PropertyParser(nl.knaw.huygens.timbuctoo.search.description.PropertyParser) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Lists(com.google.common.collect.Lists) Optional(java.util.Optional) P(org.apache.tinkerpop.gremlin.process.traversal.P) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue)

Example 15 with org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has

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

the class MultiValueListFacetDescription method filter.

@Override
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facetValues) {
    Optional<FacetValue> first = facetValues.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
    if (!first.isPresent()) {
        return;
    }
    FacetValue facetValue = first.get();
    if (!(facetValue instanceof ListFacetValue)) {
        return;
    }
    List<String> values = ((ListFacetValue) facetValue).getValues();
    if (values.isEmpty()) {
        return;
    }
    graphTraversal.where(__.<String>has(propertyName, P.test((o1, o2) -> o1 instanceof String && o2 instanceof List && ((List<?>) o2).stream().anyMatch(value -> ((String) o1).contains("\"" + value + "\"")), values)));
}
Also used : Objects(java.util.Objects) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) ListFacetGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.ListFacetGetter) MultiValuePropertyGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.MultiValuePropertyGetter) Optional(java.util.Optional) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) P(org.apache.tinkerpop.gremlin.process.traversal.P) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) List(java.util.List)

Aggregations

List (java.util.List)48 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)43 Optional (java.util.Optional)42 Edge (org.apache.tinkerpop.gremlin.structure.Edge)39 T (org.apache.tinkerpop.gremlin.structure.T)36 Lists (com.google.common.collect.Lists)35 Instant (java.time.Instant)34 ArrayList (java.util.ArrayList)34 IOException (java.io.IOException)33 Collectors.toList (java.util.stream.Collectors.toList)32 Direction (org.apache.tinkerpop.gremlin.structure.Direction)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)31 LabelP (org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP)31 URI (java.net.URI)30 UUID (java.util.UUID)30 ReadEntity (nl.knaw.huygens.timbuctoo.core.dto.ReadEntity)30 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)30 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)29 Try (javaslang.control.Try)29 OptionalPresentMatcher.present (nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present)29