1 package org.simantics.modeling.export;
3 import java.util.Collection;
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.common.utils.traverser.TraverseQueryBuilder;
7 import org.simantics.db.common.utils.traverser.TraverseResult;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.request.Read;
10 import org.simantics.export.core.ExportContext;
11 import org.simantics.export.core.error.ExportException;
12 import org.simantics.export.core.intf.DiscoverAction;
13 import org.simantics.export.core.util.ExportQueries;
14 import org.simantics.layer0.Layer0;
15 import org.simantics.simulation.ontology.SimulationResource;
18 * Discovers all models in context ( session, project )
20 * @author toni.kalajainen@semantum.fi
22 public class DiscoverModels implements DiscoverAction {
24 public Read<Collection<String>> discoverRequest(
25 final Collection<String> startLocations) throws ExportException {
26 return new Read<Collection<String>>() {
27 public Collection<String> perform(ReadGraph graph) throws DatabaseException {
29 Layer0 L0 = Layer0.getInstance(graph);
30 SimulationResource SIM = SimulationResource.getInstance(graph);
31 TraverseQueryBuilder builder = new TraverseQueryBuilder();
32 builder.setStartResources( graph.syncRequest( ExportQueries.toResources(startLocations) ) );
33 builder.followRelation( L0.ConsistsOf );
34 builder.followAndReturnInstanceOf( SIM.Model );
35 TraverseResult traverseResult = graph.syncRequest( builder.build() );
36 return graph.syncRequest( ExportQueries.toUris( traverseResult.result ) );
43 public Collection<String> discoverContent(ExportContext ctx, Collection<String> startLocations) throws ExportException {
45 return ctx.session.syncRequest( discoverRequest(startLocations) );
46 } catch (DatabaseException e) {
47 if ( e.getCause() instanceof ExportException ) throw (ExportException) e.getCause();
48 throw new ExportException( e );