]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/migration/DocumentCleanupMigrationStep.java
Find SCL references in SCLModuleEditor with Ctrl+Shift+G
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / migration / DocumentCleanupMigrationStep.java
1 package org.simantics.modeling.migration;
2
3 import org.eclipse.core.runtime.IProgressMonitor;
4 import org.simantics.db.Resource;
5 import org.simantics.db.Session;
6 import org.simantics.db.WriteGraph;
7 import org.simantics.db.common.request.WriteRequest;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.layer0.migration.MigrationState;
10 import org.simantics.db.layer0.migration.MigrationStep;
11 import org.simantics.db.layer0.migration.MigrationUtils;
12 import org.simantics.db.layer0.util.RemoverUtil;
13 import org.simantics.document.DocumentResource;
14 import org.simantics.layer0.Layer0;
15 import org.simantics.modeling.ModelingUtils;
16
17 public class DocumentCleanupMigrationStep implements MigrationStep {
18
19     @Override
20     public void applyTo(IProgressMonitor monitor, Session session, MigrationState state) throws DatabaseException {
21         
22         final Resource indexRoot = MigrationUtils.getResource(monitor, session, state);
23         if(indexRoot == null) return;
24
25         session.sync(new WriteRequest() {
26                 
27             @Override
28             public void perform(WriteGraph graph) throws DatabaseException {
29                 
30                 Layer0 L0 = Layer0.getInstance(graph);
31                 DocumentResource DOC = DocumentResource.getInstance(graph);
32                 
33                 for(Resource model : graph.getObjects(indexRoot, L0.ConsistsOf)) {
34                                 for(Resource instance : ModelingUtils.searchByType(graph, model, DOC.ScenegraphDocument)) {
35                                         if(!graph.hasStatement(instance, DOC.HasDocumentation_Inverse)) {
36                                                 System.err.println("Removing stray document " + graph.getURI(instance));
37                                                 RemoverUtil.remove(graph, instance);
38                                         }
39                                 }
40                 }
41
42             }
43
44         });
45
46     }
47
48 }