@Test public void filterChecksIfTheVertexContainsTheRightFondsAndFondsNaam() { Graph graph = newGraph().withVertex(v -> v.withTimId("id1") .withProperty(FONDS, "fonds") .withProperty(FONDS_NAAM, "fondsNaam")) .withVertex(v -> v.withProperty(FONDS, "fonds1") .withProperty(FONDS_NAAM, "fondsNaam")) .build(); CharterPortaalFondsFacetDescription instance = new CharterPortaalFondsFacetDescription(FACET_NAME, Mockito.mock(PropertyParser.class)); GraphTraversal<Vertex, Vertex> traversal = graph.traversal().V(); instance.filter(traversal, Lists.newArrayList(new ListFacetValue("facetName", Lists.newArrayList("fondsNaam (fonds)")))); List<Vertex> actual = traversal.toList(); assertThat(actual, contains(likeVertex().withTimId("id1"))); }
@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()); } } }
CharterPortaalFondsFacetDescription extends AbstractFacetDescription { @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()); } } } }
CharterPortaalFondsFacetDescription extends AbstractFacetDescription { @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()); } } } CharterPortaalFondsFacetDescription(String facetName, PropertyParser propertyParser); }
CharterPortaalFondsFacetDescription extends AbstractFacetDescription { @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()); } } } CharterPortaalFondsFacetDescription(String facetName, PropertyParser propertyParser); @Override void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets); @Override List<String> getValues(Vertex vertex); }
CharterPortaalFondsFacetDescription extends AbstractFacetDescription { @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()); } } } CharterPortaalFondsFacetDescription(String facetName, PropertyParser propertyParser); @Override void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets); @Override List<String> getValues(Vertex vertex); static final Logger LOG; static final String FONDS_NAAM; static final String FONDS; }