]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/ActiveRuns.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / ActiveRuns.java
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/ActiveRuns.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/ActiveRuns.java
new file mode 100644 (file)
index 0000000..b58f9aa
--- /dev/null
@@ -0,0 +1,51 @@
+package org.simantics.db.layer0.request;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ResourceRead;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+\r
+public class ActiveRuns extends ResourceRead<Collection<Variable>> {\r
+\r
+    public ActiveRuns(ReadGraph graph, Variable model) throws DatabaseException {\r
+        super(model.getRepresents(graph));\r
+    }\r
+\r
+    public ActiveRuns(Resource model) {\r
+        super(model);\r
+    }\r
+\r
+    @Override\r
+    public Collection<Variable> perform(ReadGraph graph) throws DatabaseException {\r
+\r
+        Variable variable = Variables.getPossibleVariable(graph, resource);\r
+        if (variable == null)\r
+            return Collections.emptyList();\r
+\r
+        Collection<Variable> result = new ArrayList<Variable>();\r
+        SimulationResource SIMU = SimulationResource.getInstance(graph);\r
+\r
+       for(Variable experiment : variable.getChildren(graph)) {\r
+               Resource experimentType = experiment.getPossibleType(graph, SIMU.Experiment);\r
+               if(experimentType == null) continue;\r
+               for(Variable run : experiment.getChildren(graph)) {\r
+                       Resource runType = run.getPossibleType(graph);\r
+                       if(runType == null) continue;\r
+                       if(graph.isInheritedFrom(runType, SIMU.Run)) {\r
+                               Resource represents = run.getRepresents(graph);\r
+                               if(graph.hasStatement(represents, SIMU.IsActive)) result.add(run);\r
+                       }\r
+               }\r
+       }\r
+       return result;\r
+\r
+    }\r
+\r
+}\r