]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/ActiveRuns.java
New implementation NearestOwnerFinder of CommonDBUtils.getNearestOwner
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / ActiveRuns.java
1 package org.simantics.db.layer0.request;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.ResourceRead;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.variable.Variable;
12 import org.simantics.db.layer0.variable.Variables;
13 import org.simantics.simulation.ontology.SimulationResource;
14
15 public class ActiveRuns extends ResourceRead<Collection<Variable>> {
16
17     public ActiveRuns(ReadGraph graph, Variable model) throws DatabaseException {
18         super(model.getRepresents(graph));
19     }
20
21     public ActiveRuns(Resource model) {
22         super(model);
23     }
24
25     @Override
26     public Collection<Variable> perform(ReadGraph graph) throws DatabaseException {
27
28         Variable variable = Variables.getPossibleVariable(graph, resource);
29         if (variable == null)
30             return Collections.emptyList();
31
32         Collection<Variable> result = new ArrayList<Variable>();
33         SimulationResource SIMU = SimulationResource.getInstance(graph);
34
35         for(Variable experiment : variable.getChildren(graph)) {
36                 Resource experimentType = experiment.getPossibleType(graph, SIMU.Experiment);
37                 if(experimentType == null) continue;
38                 for(Variable run : experiment.getChildren(graph)) {
39                         Resource runType = run.getPossibleType(graph);
40                         if(runType == null) continue;
41                         if(graph.isInheritedFrom(runType, SIMU.Run)) {
42                                 Resource represents = run.getRepresents(graph);
43                                 if(graph.hasStatement(represents, SIMU.IsActive)) result.add(run);
44                         }
45                 }
46         }
47         return result;
48
49     }
50
51 }