X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Frequest%2FActivateModel.java;h=c7187b88301189fa504c1af0200ac5e707552e58;hb=0d600d71de7dfab22bdcd0588cd792800bfe3a8c;hp=690267dc5f7f7ad7d69ecda8b5b716503f64c544;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/ActivateModel.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/ActivateModel.java index 690267dc5..c7187b883 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/ActivateModel.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/ActivateModel.java @@ -1,58 +1,58 @@ -package org.simantics.db.layer0.request; - -import org.simantics.db.Resource; -import org.simantics.db.VirtualGraph; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteResultRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.service.VirtualGraphSupport; -import org.simantics.operation.Layer0X; - -public class ActivateModel extends WriteResultRequest { - - final Resource project; - final Resource model; - - public ActivateModel(Resource project, Resource model) { - - if(project == null) throw new IllegalArgumentException("project can not be null"); - this.project = project; - this.model = model; - - } - - public static Boolean perform(WriteGraph graph, Resource project, Resource model) throws DatabaseException { - Layer0X L0X = Layer0X.getInstance(graph); - if (model != null) { - if (!graph.hasStatement(model, L0X.IsActivatedBy, project)) { - graph.deny(project, L0X.Activates); - graph.claim(project, L0X.Activates, model); - return true; - } - } else { - if (graph.hasStatement(project, L0X.Activates)) { - graph.deny(project, L0X.Activates); - return true; - } - } - return false; - } - - @Override - public Boolean perform(WriteGraph graph) throws DatabaseException { - VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class); - VirtualGraph activations = support.getWorkspacePersistent("activations"); - VirtualGraph vg = graph.getProvider(); - if (vg == activations) { - return perform(graph, project, model); - } else { - return graph.syncRequest(new WriteResultRequest() { - @Override - public Boolean perform(WriteGraph graph) throws DatabaseException { - return ActivateModel.perform(graph, project, model); - } - }); - } - } - -} +package org.simantics.db.layer0.request; + +import org.simantics.db.Resource; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.operation.Layer0X; + +public class ActivateModel extends WriteResultRequest { + + final Resource project; + final Resource model; + + public ActivateModel(Resource project, Resource model) { + + if(project == null) throw new IllegalArgumentException("project can not be null"); + this.project = project; + this.model = model; + + } + + public static Boolean perform(WriteGraph graph, Resource project, Resource model) throws DatabaseException { + Layer0X L0X = Layer0X.getInstance(graph); + if (model != null) { + if (!graph.hasStatement(model, L0X.IsActivatedBy, project)) { + graph.deny(project, L0X.Activates); + graph.claim(project, L0X.Activates, model); + return true; + } + } else { + if (graph.hasStatement(project, L0X.Activates)) { + graph.deny(project, L0X.Activates); + return true; + } + } + return false; + } + + @Override + public Boolean perform(WriteGraph graph) throws DatabaseException { + VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class); + VirtualGraph activations = support.getWorkspacePersistent("activations"); + VirtualGraph vg = graph.getProvider(); + if (vg == activations) { + return perform(graph, project, model); + } else { + return graph.syncRequest(new WriteResultRequest(activations) { + @Override + public Boolean perform(WriteGraph graph) throws DatabaseException { + return ActivateModel.perform(graph, project, model); + } + }); + } + } + +}