- Resource lib = graph.newResource();
- graph.newClusterSet(lib);
- graph.setClusterSet4NewResource(lib);
- graph.claim(lib, L0.InstanceOf, null, recipe.second);
- String name = URIStringUtils.unescape( recipe.third.get(recipe.third.size()-1) );
- graph.addLiteral(lib, L0.HasName, L0.NameOf, name, Bindings.STRING);
- graph.claim(base, L0.ConsistsOf, L0.PartOf, lib);
+ Pair<Boolean,Boolean> mode = xs.getServiceMode();
+
+ try {
+
+ graph.markUndoPoint();
+
+ if(published) {
+ xs.setServiceMode(true, true);
+ } else {
+ xs.setServiceMode(true, mode.second);
+ }
+
+ graph.setClusterSet4NewResource(graph.getRootLibrary());
+ graph.flushCluster();
+
+ for(RootInfo info : getRootInfo()) {
+ // At this stage these are existing L0.ExternalEntity instances that are now being imported.
+ graph.deny(info.resource, L0.InstanceOf, null, L0.ExternalEntity, null);
+ }
+
+ for(Map.Entry<Root, Triple<Resource, Resource, List<String>>> entry : toCreate.entrySet()) {
+
+ Triple<Resource, Resource, List<String>> recipe = entry.getValue();
+
+ Resource base = recipe.first;
+ for(int i=0;i<recipe.third.size()-1;i++) {
+ Resource lib = graph.newResource();
+ graph.claim(lib, L0.InstanceOf, null, L0.Library);
+ graph.addLiteral(lib, L0.HasName, L0.NameOf, URIStringUtils.unescape( recipe.third.get(i) ), Bindings.STRING);
+ graph.claim(base, L0.ConsistsOf, L0.PartOf, lib);
+ base = lib;
+ }
+
+ Resource lib = graph.newResource();
+ graph.newClusterSet(lib);
+ graph.setClusterSet4NewResource(lib);
+ graph.claim(lib, L0.InstanceOf, null, recipe.second);
+ String name = URIStringUtils.unescape( recipe.third.get(recipe.third.size()-1) );
+ graph.addLiteral(lib, L0.HasName, L0.NameOf, name, Bindings.STRING);
+ graph.claim(base, L0.ConsistsOf, L0.PartOf, lib);
+
+ addRootInfo(entry.getKey(), name, lib);
+
+ created.put(entry.getKey(), lib);
+
+ }
+
+ graph.flushCluster();
+
+ } finally {