From: Marko Luukkainen Date: Tue, 17 Dec 2019 12:23:30 +0000 (+0200) Subject: TransferableGraph import to VG with different name X-Git-Tag: v1.43.0~136^2~5^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=55feb8ea3a74bf5ce73619d62d4c73e576ae89fc TransferableGraph import to VG with different name * Root are processed first during tg import, which allows Import Advisor to replace the current name. gitlab #432 Change-Id: Ia297b4df4c0ad1895a985f592064a178a6c4fb10 (cherry picked from commit c85fa803ee6833f46532097250ba0c3ac5ace86c) --- diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java index 6d3f7e48e..e61937fc9 100644 --- a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java +++ b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java @@ -188,6 +188,21 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap this.handles = new int[resourceCount]; TIntObjectMap identityMap = TransferableGraphUtils.mapIdentities(identities); + // We must process roots first, because internal identifiers depend on them. + for(Identity identity : identities) { + IdentityDefinition definition = identity.definition; + if (definition instanceof Root) { + Root root = (Root) definition; + if (root.name.equals("")) + handles[identity.resource] = builder.handle(RootLibrary); + else { + Resource existing = advisor.analyzeRoot(graph, root); + if (existing != null) + handles[identity.resource] = builder.handle(existing); + } + } + } + for(Identity identity : identities) { IdentityDefinition definition = identity.definition; if(definition instanceof External) { @@ -227,16 +242,6 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap existingInternalMap.put(identity.resource, existing); } } - else if(definition instanceof Root) { - Root root = (Root)definition; - if(root.name.equals("")) - handles[identity.resource] = builder.handle(RootLibrary); - else { - Resource existing = advisor.analyzeRoot(graph, root); - if(existing != null) - handles[identity.resource] = builder.handle(existing); - } - } else if(definition instanceof Optional) { External def = (External)definition; Resource parent = builder.resource(handles[def.parent]); @@ -269,6 +274,8 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap } int[] getClustering() { + if (vg != null) + return null; Variant v = extensions.get(Extensions.CLUSTERING); if(v == null) return null; try { @@ -280,6 +287,8 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap } int[] getClusterSets() { + if (vg != null) + return null; Variant v = extensions.get(Extensions.CLUSTER_SETS); if(v == null) return null; try { @@ -605,7 +614,11 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap tg.forValues2(null, new ValueProcedure()); for(Resource r : existingInternalMap.valueCollection()) { - graph.deny(r, InstanceOf, null, ExternalEntity, null); + try { + graph.deny(r, InstanceOf, null, ExternalEntity, null); + } catch (DatabaseException e) { + graph.deny(r, InstanceOf, null, ExternalEntity, vg); + } } } diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphImportProcess.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphImportProcess.java index 4ec713866..3b3c78bac 100644 --- a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphImportProcess.java +++ b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphImportProcess.java @@ -174,7 +174,7 @@ public class TransferableGraphImportProcess implements TransferableGraphImporter missingExternals.add(external); } - void prepare(ReadGraph graph) throws DatabaseException { + public void prepare(ReadGraph graph) throws DatabaseException { findBuiltins(graph); Resource[] resources = new Resource[tg.resourceCount]; @@ -338,7 +338,7 @@ public class TransferableGraphImportProcess implements TransferableGraphImporter } - void write(WriteOnlyGraph graph) throws DatabaseException { + public void write(WriteOnlyGraph graph) throws DatabaseException { Resource[] resources = this.resources;