]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Use proper URI encoding/decoding in fail-safe import 24/624/1
authorJussi Koskela <jussi.koskela@semantum.fi>
Wed, 14 Jun 2017 13:01:51 +0000 (16:01 +0300)
committerJussi Koskela <jussi.koskela@semantum.fi>
Wed, 14 Jun 2017 13:01:51 +0000 (16:01 +0300)
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

bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java
bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImportWizard.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyImportWizard.java

index 4894467e3d1260aa25d4239349942542000ede22..9a819635463a8703651465c312bc688b3622326f 100644 (file)
@@ -163,8 +163,8 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap
        void addMissing(int handleIndex, String external) {
                allMissingExternals.put(external, handleIndex);
                Set<String> 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);
index a7b92c8d015727880d256a9c17494bed54b70ce9..5b40113aecb1fb581e57ec80d1f1786c63df3caa 100644 (file)
@@ -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 "<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);
+                               return getURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name);
                        } else {
                                return "";
                        }
index 235c304e6009f56942a8f288f17d703776f7fcad..9f9dc489e42af88a111b2705fa723bfcc70e6578 100644 (file)
@@ -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) {
index df65646346386755b7cecc2388350ac74824a652..8345c229eb8d5d6d4dca452a270e0d152fef43e9 100644 (file)
@@ -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) {