1 package org.simantics.db.layer0.request;
3 import org.simantics.db.Resource;
4 import org.simantics.db.VirtualGraph;
5 import org.simantics.db.WriteGraph;
6 import org.simantics.db.common.request.WriteResultRequest;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.db.service.VirtualGraphSupport;
9 import org.simantics.operation.Layer0X;
11 public class ActivateModel extends WriteResultRequest<Boolean> {
13 final Resource project;
16 public ActivateModel(Resource project, Resource model) {
18 if(project == null) throw new IllegalArgumentException("project can not be null");
19 this.project = project;
24 public static Boolean perform(WriteGraph graph, Resource project, Resource model) throws DatabaseException {
25 Layer0X L0X = Layer0X.getInstance(graph);
27 if (!graph.hasStatement(model, L0X.IsActivatedBy, project)) {
28 graph.deny(project, L0X.Activates);
29 graph.claim(project, L0X.Activates, model);
33 if (graph.hasStatement(project, L0X.Activates)) {
34 graph.deny(project, L0X.Activates);
42 public Boolean perform(WriteGraph graph) throws DatabaseException {
43 VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class);
44 VirtualGraph activations = support.getWorkspacePersistent("activations");
45 VirtualGraph vg = graph.getProvider();
46 if (vg == activations) {
47 return perform(graph, project, model);
49 return graph.syncRequest(new WriteResultRequest<Boolean>(activations) {
51 public Boolean perform(WriteGraph graph) throws DatabaseException {
52 return ActivateModel.perform(graph, project, model);