@Test public void filterAddsAFilterToTheGraphTraversal() { RelatedMultiValueListFacetDescription instance = new RelatedMultiValueListFacetDescription(FACET_NAME, PROPERTY, RELATION); List<FacetValue> facets = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList(FACET_VALUE))); 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"))); }
@Override public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) { Optional<FacetValue> value = facets.stream() .filter(facetValue -> Objects.equals(facetValue.getName(), facetName)) .findFirst(); if (value.isPresent()) { FacetValue facetValue = value.get(); if (facetValue instanceof ListFacetValue) { List<String> values = ((ListFacetValue) facetValue).getValues(); if (!values.isEmpty()) { graphTraversal.where(__.bothE(relations).otherV().has(propertyName, P.test((o1, o2) -> { return o1 instanceof String && o2 instanceof List && ((List<?>) o2).stream().anyMatch(val -> ((String) o1).contains("\"" + val + "\"")); }, values))); } } } }
RelatedMultiValueListFacetDescription extends AbstractFacetDescription { @Override public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) { Optional<FacetValue> value = facets.stream() .filter(facetValue -> Objects.equals(facetValue.getName(), facetName)) .findFirst(); if (value.isPresent()) { FacetValue facetValue = value.get(); if (facetValue instanceof ListFacetValue) { List<String> values = ((ListFacetValue) facetValue).getValues(); if (!values.isEmpty()) { graphTraversal.where(__.bothE(relations).otherV().has(propertyName, P.test((o1, o2) -> { return o1 instanceof String && o2 instanceof List && ((List<?>) o2).stream().anyMatch(val -> ((String) o1).contains("\"" + val + "\"")); }, values))); } } } } }
RelatedMultiValueListFacetDescription extends AbstractFacetDescription { @Override public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) { Optional<FacetValue> value = facets.stream() .filter(facetValue -> Objects.equals(facetValue.getName(), facetName)) .findFirst(); if (value.isPresent()) { FacetValue facetValue = value.get(); if (facetValue instanceof ListFacetValue) { List<String> values = ((ListFacetValue) facetValue).getValues(); if (!values.isEmpty()) { graphTraversal.where(__.bothE(relations).otherV().has(propertyName, P.test((o1, o2) -> { return o1 instanceof String && o2 instanceof List && ((List<?>) o2).stream().anyMatch(val -> ((String) o1).contains("\"" + val + "\"")); }, values))); } } } } RelatedMultiValueListFacetDescription(String facetName, String propertyName, String... relations); }
RelatedMultiValueListFacetDescription extends AbstractFacetDescription { @Override public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) { Optional<FacetValue> value = facets.stream() .filter(facetValue -> Objects.equals(facetValue.getName(), facetName)) .findFirst(); if (value.isPresent()) { FacetValue facetValue = value.get(); if (facetValue instanceof ListFacetValue) { List<String> values = ((ListFacetValue) facetValue).getValues(); if (!values.isEmpty()) { graphTraversal.where(__.bothE(relations).otherV().has(propertyName, P.test((o1, o2) -> { return o1 instanceof String && o2 instanceof List && ((List<?>) o2).stream().anyMatch(val -> ((String) o1).contains("\"" + val + "\"")); }, values))); } } } } RelatedMultiValueListFacetDescription(String facetName, String propertyName, String... relations); @Override void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets); }
RelatedMultiValueListFacetDescription extends AbstractFacetDescription { @Override public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) { Optional<FacetValue> value = facets.stream() .filter(facetValue -> Objects.equals(facetValue.getName(), facetName)) .findFirst(); if (value.isPresent()) { FacetValue facetValue = value.get(); if (facetValue instanceof ListFacetValue) { List<String> values = ((ListFacetValue) facetValue).getValues(); if (!values.isEmpty()) { graphTraversal.where(__.bothE(relations).otherV().has(propertyName, P.test((o1, o2) -> { return o1 instanceof String && o2 instanceof List && ((List<?>) o2).stream().anyMatch(val -> ((String) o1).contains("\"" + val + "\"")); }, values))); } } } } RelatedMultiValueListFacetDescription(String facetName, String propertyName, String... relations); @Override void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets);  }