Reputation: 720
Let's imagine the following graph :
Let's assume that each Vertex is a type "Account", except for the client which is a type... "Client" or whatever.
Assuming that the Edge "supervise" allows the Boss to access all the informations of his Managers. And "frames" allows the Manager to access all the informations of his interns. And finally, belongs_to allows the intern to see client informations.
Starting from an account, I want to know if this account can access to a specific client. Allowing some Directions for some Edges and forbidding others... For instance, it would be possible to go through the Edge supervise the way : OUT ---> IN but not IN ---> OUT.
But for belongs_to, IN---> OUT would be possible.
Doing it from Java, I was thinking of a recursive function but it might be difficult to avoid redundancy and infinite recursive in some cases, and it seems like there's a lot of conditions to manage.
From SQL command we could do something like :
SELECT EXPAND(SET(OUT('supervise').OUT('frames').IN('belongs_to'))) FROM #Boss_id
I think it would return a list of client and we could check the presence of the wanted client. But this would only work for the boss, and for a Manager I would only do :
SELECT EXPAND(SET(OUT('frames').IN('belongs_to'))) FROM #Manager_id
I don't really see how to generalize this command.
So my question is :
Is there an "easy" way to run through a graph, something in the Java API or any recommanded way ?
Upvotes: 1
Views: 195
Reputation: 1579
create class Account extends V
create class Client extends V
create class Supervise extends E
create class Frames extends E
create class BelongsTo extends E
create vertex Account set name = 'boss' #12:0
create vertex Account set name = 'manager1' #12:1
create vertex Account set name = 'manager2' #12:2
create vertex Account set name = 'intern1' #12:3
create vertex Account set name = 'intern2' #12:4
create vertex Client set name = 'client1'
create edge Supervise from #12:0 to [#12:1, #12:2]
create edge Frames from #12:2 to [#12:3, #12:4]
create edge BelongsTo from #13:0 to #12:4
I believe this is the situation described above. You can:
select from (
traverse out('Supervise'), out('Frames'), in('BelongsTo') from <rid>
) where @class = 'Client'
Note that the client1 will be returned only if you replace the rid with #12:0, #12:2 or #12:4.
Upvotes: 1