1 package org.simantics.db.layer0.request;
3 import org.simantics.db.RequestProcessor;
4 import org.simantics.db.Resource;
5 import org.simantics.db.SessionModel;
6 import org.simantics.db.WriteGraph;
7 import org.simantics.db.common.request.WriteRequest;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.service.VirtualGraphSupport;
10 import org.simantics.layer0.Layer0;
11 import org.simantics.operation.Layer0X;
12 import org.simantics.user.UserResource;
14 public class SetActiveSessionRole extends WriteRequest {
16 final private Resource model;
17 final private Resource role;
19 public SetActiveSessionRole(RequestProcessor processor, Resource model, Resource role) {
20 super(processor.getService(VirtualGraphSupport.class).getWorkspacePersistent("activations"));
26 public void perform(WriteGraph graph) throws DatabaseException {
28 Layer0 L0 = Layer0.getInstance(graph);
29 Layer0X L0X = Layer0X.getInstance(graph);
30 UserResource USER = UserResource.getInstance(graph);
31 Resource session = graph.getService(SessionModel.class).getResource();
34 for(Resource selection : graph.getObjects(session, L0X.Session_HasRoleSelection)) {
35 Resource selectionModel = graph.getPossibleObject(selection, USER.RoleSelection_HasModel);
36 if(selectionModel.equals(model)) {
37 graph.deny(selection, USER.RoleSelection_HasRole);
38 graph.claim(selection, USER.RoleSelection_HasRole, role);
44 Resource selection = graph.newResource();
45 graph.claim(selection, L0.InstanceOf, null, USER.RoleSelection);
46 graph.claim(selection, USER.RoleSelection_HasModel, model);
47 graph.claim(selection, USER.RoleSelection_HasRole, role);
48 graph.claim(session, L0X.Session_HasRoleSelection, selection);