Hi,
I have the following graph with entities and roles in a tree. The roles attach to various entities in the tree and would provide access to all entities from the attached entity, down through the tree until it gets to another entity with a role attached.
eg
role 1 - Domain1
-- Sub1
role 2 -- Sub2
--Sub3
I want to query to start at domain1 returning role1 and recurse the tree returning all the sub domains that don't have a role attached to assoiate to the previous role.
So as an output I'm trying to effectively create an list of roles with their associated scope of domains they cover.
role1 {
scope: [domain1, sub1]
}
role2 {
scope: [sub2, sub3]
}
I've been trying out different quieries and have been able to return a set of results that does map the roles to the domains. The problem is I can't get the query to stop returning domains once it hits a lower role. This is my query so far.
select * where {
?user a :User;
?user :hasRole ?role.
?role :canAccess ?roleDomain;
?roleDomain a :Domain;
:name ?roleDomainName.
OPTIONAL {
?roleDomain (:hasDomain)+ ?subdomain.
FILTER EXISTS {
?subdomain ^:canAccess ?subRole.
}
?subdomain :name ?subName;
}
}
This does return a row for role for each domain so 4 rows as follows
role 1 -> domain1 -> sub1
role 1 -> domain1 -> sub2
role 1 -> domain1 -> sub3
role 2 -> sub2 -> sub3
But I don't want the follwoing 2 lines returned.
role 1 -> domain1 -> sub2
role 1 -> domain1 -> sub3
Weirdly I was trying to say filter not exists, as in filter out subdomains that have a role, but that doesn't seem to work at all, so feels like FILTER EXISTS above is backwards, but it's the only way I can at least get the rows to return.
Any help would be greatly appreciated.