@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"))); }
@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); 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))); }
ChangeRangeFacetDescription extends AbstractFacetDescription { @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); 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))); } }
ChangeRangeFacetDescription extends AbstractFacetDescription { @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); 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))); } ChangeRangeFacetDescription(String facetName, String propertyName); }
ChangeRangeFacetDescription extends AbstractFacetDescription { @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); 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))); } ChangeRangeFacetDescription(String facetName, String propertyName); @Override @SuppressWarnings("unchecked") void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets); }
ChangeRangeFacetDescription extends AbstractFacetDescription { @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); 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))); } ChangeRangeFacetDescription(String facetName, String propertyName); @Override @SuppressWarnings("unchecked") void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets); static final DateTimeFormatter FORMATTER; static final Logger LOG; }