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;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public class DocumentCleanupMigrationStep implements MigrationStep {
21 private static final Logger LOGGER = LoggerFactory.getLogger(DocumentCleanupMigrationStep.class);
24 public void applyTo(IProgressMonitor monitor, Session session, MigrationState state) throws DatabaseException {
26 final Resource indexRoot = MigrationUtils.getResource(monitor, session, state);
27 if(indexRoot == null) return;
29 session.sync(new WriteRequest() {
32 public void perform(WriteGraph graph) throws DatabaseException {
34 Layer0 L0 = Layer0.getInstance(graph);
35 DocumentResource DOC = DocumentResource.getInstance(graph);
37 for(Resource model : graph.getObjects(indexRoot, L0.ConsistsOf)) {
38 for(Resource instance : ModelingUtils.searchByType(graph, model, DOC.ScenegraphDocument)) {
39 if(!graph.hasStatement(instance, DOC.HasDocumentation_Inverse)) {
40 LOGGER.info("Removing stray document " + graph.getURI(instance));
41 RemoverUtil.remove(graph, instance);