From a51d73068762e87d514532103bd13ff4e67347e7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Fri, 12 May 2017 10:12:59 +0300 Subject: [PATCH] (refs #7215) Preserve identity types in NamespaceMigrationStep Change-Id: Ida23a57053d0bca00523b4a87e6c896810373602 --- .../migration/NamespaceMigrationStep.java | 23 +++++++++++++------ .../org.simantics.graph/META-INF/MANIFEST.MF | 1 + .../refactoring/GraphRefactoringUtils.java | 10 ++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/NamespaceMigrationStep.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/NamespaceMigrationStep.java index 1262f3909..a0d4f9da5 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/NamespaceMigrationStep.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/NamespaceMigrationStep.java @@ -11,8 +11,6 @@ *******************************************************************************/ package org.simantics.db.layer0.migration; -import gnu.trove.set.hash.TIntHashSet; - import java.util.ArrayList; import org.eclipse.core.runtime.IProgressMonitor; @@ -29,12 +27,19 @@ import org.simantics.graph.refactoring.GraphRefactoringException; import org.simantics.graph.refactoring.GraphRefactoringUtils; import org.simantics.graph.refactoring.MappingSpecification; import org.simantics.graph.refactoring.MappingSpecification.MappingRule; +import org.simantics.graph.representation.Identity; +import org.simantics.graph.representation.Internal; import org.simantics.graph.representation.TransferableGraph1; import org.simantics.graph.store.IdentityStore; import org.simantics.layer0.Layer0; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import gnu.trove.set.hash.TIntHashSet; public class NamespaceMigrationStep implements MigrationStep { - + private static final Logger LOGGER = LoggerFactory.getLogger(NamespaceMigrationStep.class); + final ArrayList rules; public NamespaceMigrationStep(ReadGraph graph, Resource step) throws DatabaseException { @@ -50,7 +55,7 @@ public class NamespaceMigrationStep implements MigrationStep { if(fromURI != null && toURI != null) rules.add(new MappingRule(fromURI, toURI)); else - System.err.println("Namespace migration uri formation error: base " + base + " from " + from + " to " + to); + LOGGER.error("Namespace migration uri formation error: base " + base + " from " + from + " to " + to); } } } @@ -63,9 +68,13 @@ public class NamespaceMigrationStep implements MigrationStep { try { MappingSpecification mappingSpec = new MappingSpecification(rules); boolean fixed = GraphRefactoringUtils.fixIncorrectRoot(tg.identities); - System.err.println("fixed=" + fixed); + LOGGER.info("fixed=" + fixed); IdentityStore idStore = TransferableGraphConversion.extractIdentities(tg); - idStore.printChildMap(); + // Mark internal identities new + for(Identity id : tg.identities) + if(id.definition instanceof Internal) + idStore.markNew(id.resource); +// idStore.printChildMap(); // System.err.println("ids: " + idStore); // System.err.println("rc: " + tg.resourceCount); // System.err.println("idStore: " + idStore.toArray().length); @@ -79,7 +88,7 @@ public class NamespaceMigrationStep implements MigrationStep { if(fixed) GraphRefactoringUtils.unfixIncorrectRoot(tg.identities); - System.err.println("rc2: " + tg.resourceCount); + LOGGER.info("rc2: " + tg.resourceCount); // System.err.println("idStore2: " + idStore.toArray().length); } catch (GraphRefactoringException e) { diff --git a/bundles/org.simantics.graph/META-INF/MANIFEST.MF b/bundles/org.simantics.graph/META-INF/MANIFEST.MF index 5f4404acc..d64e63f57 100644 --- a/bundles/org.simantics.graph/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.graph/META-INF/MANIFEST.MF @@ -18,3 +18,4 @@ Export-Package: org.simantics.graph, org.simantics.graph.utils Bundle-ClassPath: . Bundle-Vendor: VTT Technical Research Centre of Finland +Import-Package: org.slf4j diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.java b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.java index 9882048b7..ddc31aa5b 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.java @@ -21,13 +21,13 @@ import org.simantics.graph.representation.old.OldTransferableGraph1; import org.simantics.graph.representation.old.OldValue1; import org.simantics.graph.store.GraphStore; import org.simantics.graph.store.IdentityStore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import gnu.trove.list.array.TIntArrayList; -import gnu.trove.map.hash.TIntIntHashMap; import gnu.trove.set.hash.TIntHashSet; public class GraphRefactoringUtils { - + private static final Logger LOGGER = LoggerFactory.getLogger(GraphRefactoringUtils.class); /** * Moves an external resource. Returns true if did something. * @param parentsAffected @@ -48,7 +48,7 @@ public class GraphRefactoringUtils { // Find parent id int toParentId = ids.createPathToId(to.parent); if(ids.hasChild(toParentId, to.name)) { - System.err.println("refactor statements from " + from + " to " + to); + LOGGER.info("refactor statements from " + from + " to " + to); //throw new GraphRefactoringException("External reference to " + to + " already exists."); int toId = ids.pathToId(to); int[] statements = tg.statements; @@ -68,7 +68,7 @@ public class GraphRefactoringUtils { if(!(rule.to instanceof PathChild)) throw new GraphRefactoringException("Invalid target URI " + rule.to); if(!moveExternal(tg, ids, rule.from, (PathChild)rule.to, parentsAffected)) - System.err.println("Didn't find " + rule.from); + LOGGER.warn("Didn't find " + rule.from); } } -- 2.47.1