@Test public void filterIncludesTheVerticesWhereOnlyTheEndFallsInTheRange() { GraphTraversal<Vertex, Vertex> traversal = newGraph() .withVertex("target1", v -> v.withTimId("id4").withProperty(PROPERTY_NAME, asSerializedDatable("2015/2020"))) .withVertex("target2", v -> v.withTimId("id5").withProperty(PROPERTY_NAME, asSerializedDatable("0015-01"))) .withVertex("target3", v -> v.withTimId("id6").withProperty(PROPERTY_NAME, asSerializedDatable("0190-01"))) .withVertex("source1", v -> v.withTimId("id1").withOutgoingRelation(RELATION, "target1")) .withVertex("source2", v -> v.withTimId("id2").withOutgoingRelation(RELATION, "target2")) .withVertex("source3", v -> v.withTimId("id3").withOutgoingRelation(RELATION, "target3")) .build().traversal().V(); List<FacetValue> facetValues = Lists.newArrayList(new DateRangeFacetValue(FACET_NAME, 20140101L, 20160224L)); instance.filter(traversal, facetValues); 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; } String lowerLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getLowerLimit(), 8, '0').substring(0, 4); String upperLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getUpperLimit(), 8, '0').substring(0, 4); try { Range<Date> range = Range.closed(FILTER_FORMAT.parse(lowerLimitString), FILTER_FORMAT.parse(upperLimitString)); graphTraversal.where(__.bothE(relations).otherV().has(propertyName, P.test((o1, o2) -> { Datable datable = getDatable("" + o1); if (!datable.isValid()) { return false; } Range<Date> range1 = (Range<Date>) o2; return range1.contains(datable.getFromDate()) || range1.contains(datable.getToDate()); }, range))); } catch (ParseException e) { LOG.error("Cannot parse date", e); } }
RelatedDatableRangeFacetDescription 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; } String lowerLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getLowerLimit(), 8, '0').substring(0, 4); String upperLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getUpperLimit(), 8, '0').substring(0, 4); try { Range<Date> range = Range.closed(FILTER_FORMAT.parse(lowerLimitString), FILTER_FORMAT.parse(upperLimitString)); graphTraversal.where(__.bothE(relations).otherV().has(propertyName, P.test((o1, o2) -> { Datable datable = getDatable("" + o1); if (!datable.isValid()) { return false; } Range<Date> range1 = (Range<Date>) o2; return range1.contains(datable.getFromDate()) || range1.contains(datable.getToDate()); }, range))); } catch (ParseException e) { LOG.error("Cannot parse date", e); } } }
RelatedDatableRangeFacetDescription 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; } String lowerLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getLowerLimit(), 8, '0').substring(0, 4); String upperLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getUpperLimit(), 8, '0').substring(0, 4); try { Range<Date> range = Range.closed(FILTER_FORMAT.parse(lowerLimitString), FILTER_FORMAT.parse(upperLimitString)); graphTraversal.where(__.bothE(relations).otherV().has(propertyName, P.test((o1, o2) -> { Datable datable = getDatable("" + o1); if (!datable.isValid()) { return false; } Range<Date> range1 = (Range<Date>) o2; return range1.contains(datable.getFromDate()) || range1.contains(datable.getToDate()); }, range))); } catch (ParseException e) { LOG.error("Cannot parse date", e); } } RelatedDatableRangeFacetDescription(String facetName, String propertyName, String... relations); }
RelatedDatableRangeFacetDescription 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; } String lowerLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getLowerLimit(), 8, '0').substring(0, 4); String upperLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getUpperLimit(), 8, '0').substring(0, 4); try { Range<Date> range = Range.closed(FILTER_FORMAT.parse(lowerLimitString), FILTER_FORMAT.parse(upperLimitString)); graphTraversal.where(__.bothE(relations).otherV().has(propertyName, P.test((o1, o2) -> { Datable datable = getDatable("" + o1); if (!datable.isValid()) { return false; } Range<Date> range1 = (Range<Date>) o2; return range1.contains(datable.getFromDate()) || range1.contains(datable.getToDate()); }, range))); } catch (ParseException e) { LOG.error("Cannot parse date", e); } } RelatedDatableRangeFacetDescription(String facetName, String propertyName, String... relations); @Override @SuppressWarnings("unchecked") void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets); }
RelatedDatableRangeFacetDescription 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; } String lowerLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getLowerLimit(), 8, '0').substring(0, 4); String upperLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getUpperLimit(), 8, '0').substring(0, 4); try { Range<Date> range = Range.closed(FILTER_FORMAT.parse(lowerLimitString), FILTER_FORMAT.parse(upperLimitString)); graphTraversal.where(__.bothE(relations).otherV().has(propertyName, P.test((o1, o2) -> { Datable datable = getDatable("" + o1); if (!datable.isValid()) { return false; } Range<Date> range1 = (Range<Date>) o2; return range1.contains(datable.getFromDate()) || range1.contains(datable.getToDate()); }, range))); } catch (ParseException e) { LOG.error("Cannot parse date", e); } } RelatedDatableRangeFacetDescription(String facetName, String propertyName, String... relations); @Override @SuppressWarnings("unchecked") void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets); static final SimpleDateFormat FILTER_FORMAT; static final Logger LOG; }