]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
TransferableGraph import to VG with different name 40/3740/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 17 Dec 2019 12:23:30 +0000 (14:23 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 13 Jan 2020 13:45:23 +0000 (13:45 +0000)
* 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)

bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java
bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphImportProcess.java

index 6d3f7e48e7d421a0e5fe7e444e453f585ce2dfd5..e61937fc9e90aaf92d2dc57767d35c4545d6b91e 100644 (file)
@@ -188,6 +188,21 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap
                this.handles = new int[resourceCount];
                TIntObjectMap<Identity> 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);
+                       }
                }
                
        }
index 4ec7138660fc2dd8c585fefe07bceb96bc4b5c00..3b3c78bac7039c6c7e31147de6bf06a39c084d94 100644 (file)
@@ -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;