Firstly, thanks for your great work on the Spring Data Graph API so far.  I
took a look at the draft you had out here:

https://gist.github.com/835408

And it looks like an awesome start.  I'm relatively new to Neo4J (saw the
SpringOne keynote and the roo talk), but one thing I think would be very
useful is if there was some sort of higher-level PathMapper that worked at
the GraphBacked level, instead of working at the Neo4j node level.

In my immediate case, I have three NodeBacked types in my graph: TypeA,
TypeB, and TypeC.  Types B and C can be related to Type A through the same
relationship type, but I want to define two traversals that include only
each type respectively.  I'm using the FieldTraversalDescriptionBuilder but
its falling down when I try to do something like the following:

class TypeA {
    @GraphTraversal(traversalBuilder = RelatedTraversalBuilder.class,
elementClass = TypeB.class)
    private Iterable<TypeB> typeBs;

    @GraphTraversal(traversalBuilder = RelatedTraversalBuilder.class,
elementClass = TypeC.class)
    private Iterable<TypeC> typeCs;

    private static class RelatedTraversalBuilder implements
FieldTraversalDescriptionBuilder {
       public TraversalDescription build(NodeBacked start, Field field) {
                return new 
TraversalDescriptionImpl().relationships(RelTypes.RELATED_TO);
       }
    }
}

In this particular case, the traversal will return a mix of TypeB and TypeC
and throw a class cast exception.

I'd love to have some abstraction of a Path such that path.startNode() and
path.endNode() would return the actual NodeBacked classes themselves, so I
could write my PathMappers to use something like:

class MyPathMapper implements PathMapper {
 public Void mapPath(GraphPath path) {
   if(path.endNode() instanceof TypeB) {
      return Evaluator.INCLUDE_AND_PRUNE
   } else {
      return Evaluator.EXCLUDE_AND_PRUNE
   }
  }
}

It seems like the template should be able to provide this with something
along the lines of:

interface PathMapper<T> {
   ...
    @Override
       public Void mapPath(GraphPath graphPath) {
           eachPath(graphPath);
           return null;
       }
}

interface GraphPath {
   NodeBacked startNode();
   NodeBacked endNode();
   ...
}

The key here is, of course, that GraphPath provides NodeBacked classes
instead of primitive neo4j nodes.  Beyond the simple instanceof example I
gave, I think it would also be useful for evaluating paths using on
NodeEntity properties rather than having to call
node.getProperty('somePropertyNameThatIWillProbablyMisspell').

Not sure if my request makes sense, or is reasonable to implement, but I
think it would certainly make my life a lot easier.
-- 
View this message in context: 
http://neo4j-user-list.438527.n3.nabble.com/Neo4j-Spring-Neo4jTemplate-tp2525460p2563548.html
Sent from the Neo4J User List mailing list archive at Nabble.com.
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to