Marcello, I have a question regarding your domain. Is the relationship really bidirectional?
I.e. are there permissions that go _from_ the application, _to_ the user? You really only need both if you have relationships that might be incoming and outgoing and you want to collect all of them. I.e. having User - follows -> User Then I can get all the social contacts of the user by using both, and its followers by using Direction.INCOMING and the people he follows by Direction.OUTGOING. I'm afraid the mixing of annotations you did in Permission does not work that way as for each field it has to be deterministic which annotation applies. I think you just have to use Direction.OUTGOING on user and Direction.INCOMING on Application if your Relationship goes that way (or the other way round if it goes from Application to User). Yes, you can have enums as properties (for both Node and Relationship-Entities), they are converted using the provided conversion service which hooks into Spring's Conversion facilities. Right now we don't support Set's or other collection types for non-enty values but that will come in the next SDG release. You could try to create an array of your enums. That should probably work. And then create the set on the fly when you access the field return new EnumSet<Action>.of(actions). Hope that helps, just ask if you have further questions. And thanks for the praise :) Cheers Michael Am 07.06.2011 um 09:28 schrieb Marcello de Sales: > Hi All, > > I have posted this question at the SpringSource NoSQL forum... > http://forum.springsource.org/showthread.php?110318-Modeling-Direction.BOTH-Relationships-with-RelatedToVia-element-classes-on-Neo4J... > I decided to learn by modifying the my-restaurants-social example by adding > an RBAC implementation for applications... > > ---- > > I must say that the project is looking amazing!!! Congratulations Spring > team and Neo4J team to bring this together... I must say I was already in > love with NoSQL using MongoDB, but Graph Databases with Neo4J is just a > piece of art!!! After watching the presentation about Spring Data Graph, I > must say I was hooked after I saw the term "Polyglot Persistence" and I > decided to give this a try!!! > > Suppose I have an RBAC model such that users are granted action permissions > to applications... The questions I'd like to answer about it is as follows: > > 1. Which permissions a user have been granted to a set of applications? > 2. Which users have certain action permissions to an application? > > User <---> Permission <---> Application > > By reading the documentation, I thought I could use a @Direction.BOTH > implementation of a @RelationshipEntity using a @RelatedToVia aggregation on > my User @NodeEntity... Here's the code snippet for User... > > Code: > > > @NodeEntity > public class User { > > @Indexed > private String id; > > @Indexed > private String username; > > @RelatedToVia(type = "grantedPermissions", Direction.BOTH, > elementClass = Permission.class) > Iterable<Permission> permissions; > > public Iterable<Permission> getPermissions() { > return this.permissions; > } > ... > ... > } > > The implementation of the Application @NodeEntity... At this point, I > decided to paste the same code, but with a different property name and same > "type" value for the annotation @RelatedToVia using @Direction.BOTH... > > Code: > > > @NodeEntity > public class Application { > > @Indexed > private String id; > > @Indexed > private String name; > > ... > ... > @RelatedToVia(type = "grantedPermissions", Direction.BOTH, > elementClass = Permission.class) > Iterable<Permission> permittedUsers; > > public Iterable<Permission> getPermittedUsers() { > return this.permittedUsers; > } > } > > Now here are the questions for the implementation Permission as > @RelationshipEntity... > > 1. Can I express the @StartNode and the @EndNode in the same property on a > @RelationshipEntity? > > 2. Given the "public enum Action { CREATE, VIEW, EDIT, DELETE }", can I have > a set of ENUMs as a @RelationshipEntity property? > > Here's the implementation of the @RelationshipEntity... > > Code: > > > @RelationshipEntity > public class Permission { > > @StartNode > @EndNode > private User user; > > @EndNode > @StartNode > private Application application; > > private Set<Action> actions; > > public Permission() { > > } > > public void addAction(Action action) { > this.actions.add(action); > } > > } > > Would this work? I'm still setting up my environment and I'm adding this to > the my-restaurants-social application based on the Neo4J presentation... > > Thanks > Marcello > _______________________________________________ > Neo4j mailing list > [email protected] > https://lists.neo4j.org/mailman/listinfo/user _______________________________________________ Neo4j mailing list [email protected] https://lists.neo4j.org/mailman/listinfo/user

