]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleRoles.java
New implementation NearestOwnerFinder of CommonDBUtils.getNearestOwner
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / PossibleRoles.java
1 package org.simantics.db.layer0.request;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.common.request.ResourceRead2;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.db.layer0.adapter.Instances;
11 import org.simantics.user.UserResource;
12
13 public class PossibleRoles extends ResourceRead2<Collection<Resource>> {
14
15     public PossibleRoles(Resource model, Resource user) {
16         super(model, user);
17     }
18     
19     @Override
20     public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
21
22         UserResource USER = UserResource.getInstance(graph);
23         ArrayList<Resource> result = new ArrayList<Resource>();
24         Instances query = graph.adapt(USER.RoleAssignment, Instances.class);
25         for(Resource assignment : query.find(graph, resource)) {
26             if(graph.syncRequest(new IsUserAssigned(assignment, resource2))) {
27                 result.addAll(graph.getObjects(assignment, USER.RoleAssignment_HasRole));
28             }
29         }
30         result.add(USER.DefaultRole);
31         return result;
32         
33     }
34     
35 }