1 package org.simantics.modeling.migration;
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;
17 public class DocumentCleanupMigrationStep implements MigrationStep {
20 public void applyTo(IProgressMonitor monitor, Session session, MigrationState state) throws DatabaseException {
22 final Resource indexRoot = MigrationUtils.getResource(monitor, session, state);
23 if(indexRoot == null) return;
25 session.sync(new WriteRequest() {
28 public void perform(WriteGraph graph) throws DatabaseException {
30 Layer0 L0 = Layer0.getInstance(graph);
31 DocumentResource DOC = DocumentResource.getInstance(graph);
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);