From: Miro Richard Eklund Date: Wed, 3 May 2017 14:39:29 +0000 (+0300) Subject: Fixed URI problems related to EnternalEntities during import X-Git-Tag: v1.29.0~77^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F79%2F479%2F1;p=simantics%2Fplatform.git Fixed URI problems related to EnternalEntities during import 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 --- 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 524885f5d..06abd615f 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 @@ -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); diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java b/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java index 4646116dc..4b113fa49 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java @@ -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 ":"; } + + public static String getTrueURI(int resourceCount, TIntObjectMap 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 ":"; + } }