]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed URI problems related to EnternalEntities during import 79/479/1
authorMiro Richard Eklund <miro.eklund@semantum.fi>
Wed, 3 May 2017 14:39:29 +0000 (17:39 +0300)
committerMiro Richard Eklund <miro.eklund@semantum.fi>
Wed, 3 May 2017 14:39:29 +0000 (17:39 +0300)
Introduced a new function, getTrueUri, that gives the escaped URI.
Used when finding external entities.
Previously, getUri was used, which made finding external entities
impossible, for all User Component's with a space in their name.

refs #7182

Change-Id: I7c81eac8843f98f19054ad5df0b4ee73d2a1753e

bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java
bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java

index 524885f5d57a71ba291579c0942f1e0cdff3945f..06abd615fd5df6ffb65d393d498b4a84a458100d 100644 (file)
@@ -221,7 +221,7 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap
                                }
                        }
                        else if(definition instanceof Internal) {
-                               String uri = TransferableGraphUtils.getURI(resourceCount, identityMap, identity.resource);
+                               String uri = TransferableGraphUtils.getTrueURI(resourceCount, identityMap, identity.resource);
                                Resource existing = graph.getPossibleResource(uri);
                                if(existing != null) {
                                        existingInternalMap.put(identity.resource, existing);
@@ -334,7 +334,9 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap
 
                                Resource parent = resolvedParents.get(parts[0]);
                                // TODO: proper exception message
-                               if(parent == null) throw new IllegalStateException("!!");
+                               if(parent == null) {
+                                       throw new IllegalStateException("!!");
+                               }
 
                                Resource childResource = graph.newResource();
                                graph.claim(childResource, InstanceOf, null, ExternalEntity);
index 4646116dc37d784255466ad55f1914e94c545596..4b113fa499b6bc1208d64b62e2be5be66713cc10 100644 (file)
@@ -8,6 +8,7 @@ import java.util.TreeMap;
 
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.adapter.AdaptException;
+import org.simantics.databoard.util.URIStringUtils;
 
 import gnu.trove.list.array.TIntArrayList;
 import gnu.trove.map.TIntObjectMap;
@@ -266,5 +267,27 @@ public class TransferableGraphUtils {
                }
                return "<internal reference " + id + ">:";
        }
+       
+       public static String getTrueURI(int resourceCount, TIntObjectMap<Identity> identities, int id) {
+               Identity identity = identities.get(id);
+               if(identity != null) {
+                       IdentityDefinition definition = identity.definition;
+                       if(definition instanceof External) {
+                               External def = (External)definition;
+                               if(def.parent == -1) return "http:/";
+                               else return getTrueURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name);
+                       } else if(definition instanceof Root) {
+                               Root def = (Root)definition;
+                               if(def.name.isEmpty()) return "http:/";
+                               return def.name;
+                       } else if (definition instanceof Internal) {
+                               Internal def = (Internal)definition;
+                               return getTrueURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name);
+                       } else {
+                               return "";
+                       }
+               }
+               return "<internal reference " + id + ">:";
+       }
 
 }