]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/SharedOntologyRemover.java
Check if root allows paste only for non-null target root to prevent NPE
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / adapter / SharedOntologyRemover.java
1 package org.simantics.db.layer0.adapter;
2
3 import org.simantics.db.Resource;
4 import org.simantics.db.WriteGraph;
5 import org.simantics.db.exception.DatabaseException;
6 import org.simantics.db.layer0.adapter.impl.EntityRemover;
7 import org.simantics.db.layer0.exception.CannotRemoveException;
8 import org.simantics.db.layer0.internal.SimanticsInternal;
9 import org.simantics.db.layer0.request.ProjectModels;
10 import org.simantics.db.layer0.util.Layer0Utils;
11 import org.simantics.layer0.Layer0;
12
13 /**
14  * @author Tuukka Lehtonen
15  */
16 public class SharedOntologyRemover extends EntityRemover {
17
18     public SharedOntologyRemover(Resource resource) {
19         super(resource);
20     }
21
22     @Override
23     public void remove(WriteGraph graph) throws DatabaseException {
24         
25         Layer0 L0 = Layer0.getInstance(graph);
26         
27         for(Resource ontology : Layer0Utils.listOntologies(graph)) {
28                 if(graph.hasStatement(ontology, L0.IsLinkedTo, resource))
29                 throw new CannotRemoveException("The shared library is being referenced by " + graph.getURI(ontology));
30         }
31         
32         for(Resource model : graph.syncRequest(new ProjectModels(SimanticsInternal.getProject()))) {
33                 if(graph.hasStatement(model, L0.IsLinkedTo, resource))
34                 throw new CannotRemoveException("The shared library is being referenced by " + graph.getURI(model));
35         }
36         
37         super.remove(graph);
38         
39     }
40
41 }