]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/ActiveSessionRole.java
Merge "Allow loading databoard serialized files with type adapting" into release...
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / ActiveSessionRole.java
1 package org.simantics.db.layer0.request;
2
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.db.SessionModel;
6 import org.simantics.db.common.request.ResourceRead;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.operation.Layer0X;
9 import org.simantics.user.UserResource;
10
11 public class ActiveSessionRole extends ResourceRead<Resource> {
12
13     public ActiveSessionRole(Resource model) {
14         super(model);
15     }
16     
17     @Override
18     public Resource perform(ReadGraph graph) throws DatabaseException {
19         Layer0X L0X = Layer0X.getInstance(graph);
20         UserResource USER = UserResource.getInstance(graph);
21         Resource session = graph.getService(SessionModel.class).getResource();
22         for(Resource selection : graph.getObjects(session, L0X.Session_HasRoleSelection)) {
23             Resource model = graph.getPossibleObject(selection, USER.RoleSelection_HasModel);
24             if(model.equals(resource)) {
25                 return graph.getPossibleObject(selection, USER.RoleSelection_HasRole);
26             }
27         }
28         return USER.DefaultRole;
29     }
30     
31 }