use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.
the class PropertyTest method getTraversalReturnsATraversalThatLetsTheParserDetermineTheOrder.
@Test
public void getTraversalReturnsATraversalThatLetsTheParserDetermineTheOrder() {
GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY, "123")).withVertex(v -> v.withTimId("id2").withProperty(PROPERTY, "1234")).withVertex(v -> v.withTimId("id3").withProperty(PROPERTY, "254")).build().traversal().V();
Property instance = Property.localProperty().withName(PROPERTY).withParser(new IntegerParser()).build();
GraphTraversal<?, ?> orderTraversal = instance.getTraversal();
List<Vertex> vertices = traversal.order().by(orderTraversal, Order.incr).toList();
assertThat(vertices, contains(likeVertex().withTimId("id1"), likeVertex().withTimId("id3"), likeVertex().withTimId("id2")));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.
the class ChangeRangeFacetDescription method filter.
@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);
// Use range because the java.time.Period has no way to determine if a date falls in that Period.
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)));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal 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());
}
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.
the class MultiValueListFacetDescription method filter.
@Override
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facetValues) {
Optional<FacetValue> first = facetValues.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
if (!first.isPresent()) {
return;
}
FacetValue facetValue = first.get();
if (!(facetValue instanceof ListFacetValue)) {
return;
}
List<String> values = ((ListFacetValue) facetValue).getValues();
if (values.isEmpty()) {
return;
}
graphTraversal.where(__.<String>has(propertyName, P.test((o1, o2) -> o1 instanceof String && o2 instanceof List && ((List<?>) o2).stream().anyMatch(value -> ((String) o1).contains("\"" + value + "\"")), values)));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.
the class RelatedDatableRangeFacetDescription method filter.
@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;
}
// pad the strings to make them parsable
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);
}
}
Aggregations