}
@Override
public TraversalDescription getTraversalDescription(final SecurityContext securityContext) {
TraversalDescription description = StructrApp.getInstance(securityContext).getGraphDatabaseService().traversalDescription()
.breadthFirst()
.uniqueness(Uniqueness.NODE_RECENT)
.evaluator(Evaluators.excludeStartPosition())
.evaluator(new Evaluator() {
@Override
public Evaluation evaluate(Path path) {
// prune path at depth maxDepth
if(path.length() > maxDepth) {
return Evaluation.EXCLUDE_AND_PRUNE;
}
Node endNode = path.endNode();
if(!predicates.isEmpty()) {
boolean include = true;
for(Predicate<Node> predicate : predicates) {
try {
include &= predicate.evaluate(securityContext, endNode);
} catch(PruneException p) {
// catch PruneException to stop
// evaluating this specific path
// immediately.
return Evaluation.EXCLUDE_AND_PRUNE;
}
}
if(include) {
return Evaluation.INCLUDE_AND_CONTINUE;
}
} else {
logger.log(Level.WARNING, "No predicates to evaluate, this collector will not return any nodes!");
}
// node has wrong type: exclude and continue traversal
return Evaluation.EXCLUDE_AND_CONTINUE;
}
})
;
int numRels = relTypes.size();
for(int i=0; i<numRels; i++) {
RelationshipType relType = relTypes.get(i);
Direction direction = directions.get(i);
description = description.relationships(relType, direction);
}
return description;
}