package org.simantics.db.layer0.request; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.ResourceRead; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; import org.simantics.simulation.ontology.SimulationResource; public class ActiveRuns extends ResourceRead> { public ActiveRuns(ReadGraph graph, Variable model) throws DatabaseException { super(model.getRepresents(graph)); } public ActiveRuns(Resource model) { super(model); } @Override public Collection perform(ReadGraph graph) throws DatabaseException { Variable variable = Variables.getPossibleVariable(graph, resource); if (variable == null) return Collections.emptyList(); Collection result = new ArrayList(); SimulationResource SIMU = SimulationResource.getInstance(graph); for(Variable experiment : variable.getChildren(graph)) { Resource experimentType = experiment.getPossibleType(graph, SIMU.Experiment); if(experimentType == null) continue; for(Variable run : experiment.getChildren(graph)) { Resource runType = run.getPossibleType(graph); if(runType == null) continue; if(graph.isInheritedFrom(runType, SIMU.Run)) { Resource represents = run.getRepresents(graph); if(graph.hasStatement(represents, SIMU.IsActive)) result.add(run); } } } return result; } }