Search in sources :

Example 1 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue in project timbuctoo by HuygensING.

the class ListFacetDescriptionTest method filterAddsNoFilterIfTheFacetValuesIsEmpty.

@Test
public void filterAddsNoFilterIfTheFacetValuesIsEmpty() {
    String value1 = "value1";
    List<FacetValue> facetValues = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList()));
    SearchRequestV2_1 searchRequest = new SearchRequestV2_1();
    searchRequest.setFacetValues(facetValues);
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withProperty(PROPERTY, value1).withTimId("1")).withVertex(v -> v.withProperty(PROPERTY, "value2").withTimId("2")).build().traversal().V();
    instance.filter(traversal, facetValues);
    assertThat(traversal.toList(), containsInAnyOrder(VertexMatcher.likeVertex().withTimId("1"), VertexMatcher.likeVertex().withTimId("2")));
}
Also used : VertexMatcher(nl.knaw.huygens.timbuctoo.util.VertexMatcher) Test(org.junit.Test) 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) SearchRequestV2_1(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1) Mockito.verify(org.mockito.Mockito.verify) PropertyParser(nl.knaw.huygens.timbuctoo.search.description.PropertyParser) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Lists(com.google.common.collect.Lists) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) BDDMockito.given(org.mockito.BDDMockito.given) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) 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) SearchRequestV2_1(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue in project timbuctoo by HuygensING.

the class RelatedListFacetDescriptionTest method filterAddsNoFilterWhenTheFacetValueHasNoValues.

@Test
public void filterAddsNoFilterWhenTheFacetValueHasNoValues() {
    RelatedListFacetDescription instance = new RelatedListFacetDescription(FACET_NAME, PROPERTY, parser, RELATION);
    List<FacetValue> facets = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList()));
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex("v1", v -> v.withTimId("id1").withProperty(PROPERTY, VALUE1)).withVertex("v2", v -> v.withTimId("id2").withProperty(PROPERTY, VALUE2)).withVertex("v3", v -> v.withTimId("id3").withOutgoingRelation(RELATION, "v1")).withVertex("v4", v -> v.withTimId("id4").withOutgoingRelation(RELATION, "v2")).build().traversal().V();
    instance.filter(traversal, facets);
    assertThat(traversal.toList(), containsInAnyOrder(likeVertex().withTimId("id1"), likeVertex().withTimId("id2"), likeVertex().withTimId("id3"), likeVertex().withTimId("id4")));
}
Also used : Test(org.junit.Test) 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) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) PropertyParser(nl.knaw.huygens.timbuctoo.search.description.PropertyParser) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Lists(com.google.common.collect.Lists) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) BDDMockito.given(org.mockito.BDDMockito.given) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) 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) Test(org.junit.Test)

Example 3 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue in project timbuctoo by HuygensING.

the class RelatedListFacetDescriptionTest method filterAddsAFilterToTheGraphTraversal.

@Test
public void filterAddsAFilterToTheGraphTraversal() {
    RelatedListFacetDescription instance = new RelatedListFacetDescription(FACET_NAME, PROPERTY, parser, RELATION);
    List<FacetValue> facets = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList(VALUE1)));
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex("v1", v -> v.withTimId("id1").withProperty(PROPERTY, VALUE1)).withVertex("v2", v -> v.withTimId("id2").withProperty(PROPERTY, VALUE2)).withVertex("v3", v -> v.withTimId("id3").withOutgoingRelation(RELATION, "v1")).withVertex("v4", v -> v.withTimId("id4").withOutgoingRelation(RELATION, "v2")).build().traversal().V();
    instance.filter(traversal, facets);
    List<Vertex> vertices = traversal.toList();
    assertThat(vertices, contains(likeVertex().withTimId("id3")));
}
Also used : Test(org.junit.Test) 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) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) PropertyParser(nl.knaw.huygens.timbuctoo.search.description.PropertyParser) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Lists(com.google.common.collect.Lists) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) BDDMockito.given(org.mockito.BDDMockito.given) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) 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) Test(org.junit.Test)

Example 4 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue in project timbuctoo by HuygensING.

the class RelatedMultiValueListFacetDescriptionTest method filterAddsNoFilterWhenTheFacetValueHasNoValues.

@Test
public void filterAddsNoFilterWhenTheFacetValueHasNoValues() {
    RelatedMultiValueListFacetDescription instance = new RelatedMultiValueListFacetDescription(FACET_NAME, PROPERTY, RELATION);
    List<FacetValue> facets = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList()));
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex("v1", v -> v.withTimId("id1").withProperty(PROPERTY, VALUE1)).withVertex("v2", v -> v.withTimId("id2").withProperty(PROPERTY, VALUE2)).withVertex("v3", v -> v.withTimId("id3").withOutgoingRelation(RELATION, "v1")).withVertex("v4", v -> v.withTimId("id4").withOutgoingRelation(RELATION, "v2")).build().traversal().V();
    instance.filter(traversal, facets);
    assertThat(traversal.toList(), containsInAnyOrder(likeVertex().withTimId("id1"), likeVertex().withTimId("id2"), likeVertex().withTimId("id3"), likeVertex().withTimId("id4")));
}
Also used : Test(org.junit.Test) 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) ArrayList(java.util.ArrayList) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Lists(com.google.common.collect.Lists) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) 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) Test(org.junit.Test)

Example 5 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue 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)

Aggregations

List (java.util.List)18 ListFacetValue (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue)18 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)18 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)18 FacetValue (nl.knaw.huygens.timbuctoo.search.FacetValue)17 Lists (com.google.common.collect.Lists)16 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)14 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)14 Test (org.junit.Test)14 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)13 Matchers.contains (org.hamcrest.Matchers.contains)11 Before (org.junit.Before)11 PropertyParser (nl.knaw.huygens.timbuctoo.search.description.PropertyParser)9 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 BDDMockito.given (org.mockito.BDDMockito.given)6 Mockito.mock (org.mockito.Mockito.mock)6 Mockito.verify (org.mockito.Mockito.verify)6 ArrayList (java.util.ArrayList)5 SearchRequestV2_1 (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1)5