]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.export.ui/src/org/simantics/export/ui/util/ExportUIQueries.java
Fixed MigrationUtils.importTo root activation to use virtual graph
[simantics/platform.git] / bundles / org.simantics.export.ui / src / org / simantics / export / ui / util / ExportUIQueries.java
1 package org.simantics.export.ui.util;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.List;
6
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.ObjectsWithType;
10 import org.simantics.db.common.request.ResourceRead;
11 import org.simantics.db.common.request.UniqueRead;
12 import org.simantics.db.exception.AssumptionException;
13 import org.simantics.db.exception.DatabaseException;
14 import org.simantics.db.exception.ServiceException;
15 import org.simantics.db.exception.ValidationException;
16 import org.simantics.db.layer0.request.ActiveModels;
17 import org.simantics.db.request.Read;
18 import org.simantics.layer0.Layer0;
19 import org.simantics.simulation.ontology.SimulationResource;
20
21 public class ExportUIQueries {
22
23         
24         /**
25          * Get a query that returns active models
26          * @param project
27          * @return a query that returns active models
28          */
29         public static ResourceRead<Collection<Resource>> activeModels(Resource project) {
30                 return new ActiveModels(project);
31         }
32         
33
34         public static Read<List<String>> models(final String project) {
35                 return new UniqueRead<List<String>>() {
36                         @Override
37                         public List<String> perform(ReadGraph graph) throws DatabaseException {
38                         Layer0 L0 = Layer0.getInstance(graph);
39                         SimulationResource SIMU = SimulationResource.getInstance(graph);
40                         ArrayList<String> result = new ArrayList<String>();
41                         Resource projectRes = graph.getResource(project);
42                         for (Resource model : graph.syncRequest(new ObjectsWithType(projectRes, L0.ConsistsOf, SIMU.Model))) {
43                         try { 
44                                 String uri = graph.getURI(model);
45                                 if ( uri!=null ) result.add( uri );
46                         } catch (AssumptionException e) {
47                                 e.printStackTrace();
48                         } catch (ValidationException e) {
49                                 e.printStackTrace();
50                         } catch (ServiceException e) {
51                                 e.printStackTrace();
52                         }                               
53                         }
54                         return result;
55                                 
56                         }
57                 };
58         }       
59 }