From: Jussi Koskela Date: Wed, 14 Jun 2017 13:01:51 +0000 (+0300) Subject: Use proper URI encoding/decoding in fail-safe import X-Git-Tag: v1.31.0~322 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=c8d17ec86ad48f769923d1e674e2755471e20189;p=simantics%2Fplatform.git Use proper URI encoding/decoding in fail-safe import Earlier implementation didn't handle correctly cases where missing resources had slashes in their names. Also fixed error reporting logic to not remove error messages from sibling resources with matching prefix. refs #7300 Change-Id: Ia3ff0b09e592ff63fbb2872fa9329c3a471ed382 --- 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 4894467e3..9a8196354 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 @@ -163,8 +163,8 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap void addMissing(int handleIndex, String external) { allMissingExternals.put(external, handleIndex); Set removals = new HashSet<>(); - for(String ext : missingExternals) if(ext.startsWith(external)) return; - for(String ext : missingExternals) if(external.startsWith(ext)) removals.add(ext); + for(String ext : missingExternals) if(ext.startsWith(external + "/")) return; + for(String ext : missingExternals) if(external.startsWith(ext + "/")) removals.add(ext); missingExternals.removeAll(removals); missingExternals.add(external); } @@ -210,18 +210,18 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap TransientCacheAsyncListener.instance()); Resource child = childMap.get(def.name); if(child == null) { - addMissing(identity.resource, graph.getURI(parent) + "/" + def.name); + addMissing(identity.resource, graph.getURI(parent) + "/" + URIStringUtils.escape(def.name)); } else { handles[identity.resource] = builder.handle(child); } } else { - addMissing(identity.resource, TransferableGraphUtils.getURI(resourceCount, identityMap, def.parent) + "/" + def.name); + addMissing(identity.resource, TransferableGraphUtils.getURI(resourceCount, identityMap, def.parent) + "/" + URIStringUtils.escape(def.name)); } } } } else if(definition instanceof Internal) { - String uri = TransferableGraphUtils.getTrueURI(resourceCount, identityMap, identity.resource); + String uri = TransferableGraphUtils.getURI(resourceCount, identityMap, identity.resource); Resource existing = graph.getPossibleResource(uri); if(existing != null) { existingInternalMap.put(identity.resource, existing); @@ -355,7 +355,7 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap Resource nameResource = graph.newResource(); graph.claim(nameResource, InstanceOf, null, String); - graph.claimValue(nameResource, parts[1], WriteBindings.STRING); + graph.claimValue(nameResource, URIStringUtils.unescape(parts[1]), WriteBindings.STRING); graph.claim(childResource, HasName, NameOf, nameResource); graph.claim(parent, ConsistsOf, PartOf, childResource); 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 a7b92c8d0..5b40113ae 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 @@ -256,36 +256,14 @@ public class TransferableGraphUtils { if(definition instanceof External) { External def = (External)definition; if(def.parent == -1) return "http:/"; - else return getURI(resourceCount, identities, def.parent) + "/" + def.name; + else return getURI(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 getURI(resourceCount, identities, def.parent) + "/" + def.name; - } else { - return ""; - } - } - 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); + return getURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name); } else { return ""; } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImportWizard.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImportWizard.java index 235c304e6..9f9dc489e 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImportWizard.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImportWizard.java @@ -34,11 +34,10 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.preferences.ScopedPreferenceStore; import org.simantics.Simantics; import org.simantics.databoard.binding.Binding; -import org.simantics.databoard.binding.mutable.Variant; import org.simantics.databoard.container.DataContainer; import org.simantics.databoard.container.DataContainers; import org.simantics.databoard.container.FormatHandler; -import org.simantics.databoard.util.binary.BinaryFile; +import org.simantics.databoard.util.URIStringUtils; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.layer0.migration.MigratedImportResult; @@ -46,7 +45,6 @@ import org.simantics.db.layer0.migration.MigrationState; import org.simantics.db.layer0.migration.MigrationStateKeys; import org.simantics.db.layer0.migration.MigrationUtils; import org.simantics.db.layer0.migration.ModelImportAdvisor; -import org.simantics.db.layer0.util.DraftStatusBean; import org.simantics.db.management.ISessionContext; import org.simantics.graph.db.ImportResult; import org.simantics.graph.db.MissingDependencyException; @@ -153,7 +151,7 @@ public class ModelImportWizard extends Wizard implements IImportWizard { if (result[0].hasMissingExternals()) { InfoDialog.open(getShell(), "Missing Externals Created", "The system was unable to find some of the external entities referenced by the imported material. Place-holders have been created for the missing entities.\nThe missing entities are:\n" - + EString.implode(result[0].tgResult.missingExternals), + + URIStringUtils.unescape(EString.implode(result[0].tgResult.missingExternals)), SWT.SHEET); } } catch (InvocationTargetException e) { diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyImportWizard.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyImportWizard.java index df6564634..8345c229e 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyImportWizard.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyImportWizard.java @@ -36,6 +36,7 @@ import org.simantics.databoard.binding.mutable.Variant; import org.simantics.databoard.container.DataContainer; import org.simantics.databoard.container.DataContainers; import org.simantics.databoard.container.FormatHandler; +import org.simantics.databoard.util.URIStringUtils; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.layer0.migration.MigratedImportResult; @@ -146,7 +147,7 @@ public class SharedOntologyImportWizard extends Wizard implements IImportWizard if (result[0].hasMissingExternals()) { InfoDialog.open(getShell(), "Missing Externals Created", "The system was unable to find some of the external entities referenced by the imported material. Place-holders have been created for the missing entities.\nThe missing entities are:\n" - + EString.implode(result[0].tgResult.missingExternals), + + URIStringUtils.unescape(EString.implode(result[0].tgResult.missingExternals)), SWT.SHEET); } } catch (InvocationTargetException e) {