]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Graph comparator did not handle non-traversed statements.
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 29 Jun 2016 10:49:03 +0000 (10:49 +0000)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 2 Feb 2017 12:01:34 +0000 (14:01 +0200)
refs #6560

git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@32929 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java

index 0366df96a2a33749eb7074aae083e22d7b5fede2..e20c83e10b2ef021c1b8218e1ae7aab0e6ff6363 100644 (file)
@@ -30,10 +30,6 @@ import org.simantics.db.Statement;
 import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.exception.DoesNotContainValueException;\r
-import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
-import org.simantics.db.exception.ServiceException;\r
-import org.simantics.db.exception.ValidationException;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.utils.datastructures.BijectionMap;\r
 import org.simantics.utils.datastructures.MapList;\r
@@ -212,7 +208,7 @@ public class GraphComparator {
                \r
                comparator.setComparator(this);\r
                \r
-               comparableResources.map(r1, r2);\r
+               addComparable(r1, r2, false);\r
                \r
                final Stack<Resource> objectsLeft = new Stack<Resource>();\r
                final Stack<Resource> objectsRight = new Stack<Resource>();\r
@@ -276,9 +272,10 @@ public class GraphComparator {
                        processedResources.add(r1);\r
                        \r
                \r
-                       if(!comparableResources.contains(r1, r2) && (comparableResources.containsLeft(r1)||comparableResources.containsRight(r2))) {\r
+                       if((comparableResources.containsLeft(r1)||comparableResources.containsRight(r2)) && !comparableResources.contains(r1, r2)) {\r
                                throw new DatabaseException("Comparator error: Trying to map " + r1 + " to " + r2 + " while mappings " + r1 + " to " + comparableResources.getRight(r1) + " and " + comparableResources.getLeft(r2) + " to " + r2 + " exist.");\r
                        }\r
+                       addComparable(r1, r2, false);\r
                        \r
                        //System.out.println("test " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2));\r
                        compareProps(r1, r2);\r
@@ -293,6 +290,7 @@ public class GraphComparator {
                                ss1 = filterNonTested(ss1);\r
                                ss2 = filterNonTested(ss2);\r
                                \r
+                               \r
                                compareStatements(ss1, ss2, null, null,null,null);\r
                                ss1.clear();\r
                                ss2.clear();\r
@@ -303,6 +301,8 @@ public class GraphComparator {
                                ss2.addAll(g.getStatements(r2, rel));\r
                                ss1 = filterAsserted(r1, ss1);\r
                                ss2 = filterAsserted(r2, ss2);\r
+                               ss1 = filterNonTraversed(ss1);\r
+                               ss2 = filterNonTraversed(ss2);\r
                                compareStatements(ss1, ss2, objectsLeft, objectsRight,unreliableLeft,unreliableRight);\r
                                ss1.clear();\r
                                ss2.clear();\r
@@ -602,7 +602,6 @@ public class GraphComparator {
                        return false;\r
                BijectionMap<Path,Path> map = getMatchingPaths(leftPaths, rightPaths);\r
                return map.size() == leftPaths.size();\r
-                       \r
        }\r
        \r
        private BijectionMap<Path,Path> getMatchingPaths(Set<Path> leftPaths, Set<Path> rightPaths) {\r
@@ -622,7 +621,7 @@ public class GraphComparator {
                return map;\r
        }\r
        \r
-       private void expand(Set<Path> paths) throws ManyObjectsForFunctionalRelationException, ServiceException {\r
+       private void expand(Set<Path> paths) throws DatabaseException {\r
                Set<Path> stepPathsLeft = new HashSet<Path>();\r
                if (paths.size() == 0)\r
                        return;\r
@@ -639,7 +638,7 @@ public class GraphComparator {
                }\r
        }\r
        \r
-       private Collection<Path> findComparableRight(Path leftPath, Resource beginRight) throws ManyObjectsForFunctionalRelationException, ServiceException {\r
+       private Collection<Path> findComparableRight(Path leftPath, Resource beginRight) throws DatabaseException {\r
                Set<Path> rightPaths = new HashSet<Path>();\r
                rightPaths.addAll(Path.create(g.getStatements(beginRight, getRight(leftPath.getStatements().get(0).getPredicate()))));\r
                for (int i = 1; i < leftPath.getLength(); i++) {\r
@@ -670,6 +669,10 @@ public class GraphComparator {
                return comparableStatements;\r
        }\r
        \r
+       public BijectionMap<Resource, Resource> getComparableResources() {\r
+               return comparableResources;\r
+       }\r
+       \r
        public GraphChanges getChanges() {\r
                return new GraphChanges(r1,r2,changes1,changes2,modifications,comparableResources);\r
        }\r
@@ -677,21 +680,22 @@ public class GraphComparator {
        private void addComparable(Statement left, Statement right, boolean process) throws DatabaseException {\r
                addComparable(left.getObject(), right.getObject(), process);\r
                comparableStatements.map(left, right);\r
-               comparableResources.map(left.getObject(), right.getObject());\r
+               //comparableResources.map(left.getObject(), right.getObject());\r
        }\r
        \r
        private void addComparable(Resource left, Resource right, boolean process) throws DatabaseException {\r
-               if(!comparableResources.contains(r1, r2)) {\r
-                       if (comparableResources.containsLeft(r1)||comparableResources.containsRight(r2)) {\r
-                               throw new DatabaseException("Comparator error: Trying to map " + r1 + " to " + r2 + " while mappings " + r1 + " to " + comparableResources.getRight(r1) + " and " + comparableResources.getLeft(r2) + " to " + r2 + " exist.");\r
+               if(!comparableResources.contains(left, right)) {\r
+                       if (comparableResources.containsLeft(left)||comparableResources.containsRight(right)) {\r
+                               throw new DatabaseException("Comparator error: Trying to map " + left + " to " + right + " while mappings " + left + " to " + comparableResources.getRight(left) + " and " + comparableResources.getLeft(right) + " to " + right + " exist.");\r
                        } else {\r
+                               if (DEBUG) System.out.println(left + " = " + right);\r
                                comparableResources.map(left, right);           \r
                        }\r
                }\r
                \r
        }\r
        \r
-       public List<Statement> filterAsserted(Resource r, Collection<Statement> in) throws ServiceException {\r
+       public List<Statement> filterAsserted(Resource r, Collection<Statement> in) throws DatabaseException {\r
                List<Statement> out = new ArrayList<Statement>();\r
                for (Statement s : in) {\r
                        if (!s.isAsserted(r))\r
@@ -700,20 +704,26 @@ public class GraphComparator {
                }\r
                return out;\r
        }\r
+       \r
+       \r
 \r
-       private String printStatement(ReadGraph graph, Statement s) throws ValidationException, ServiceException {\r
+       private String printStatement(ReadGraph graph, Statement s) throws DatabaseException {\r
                return NameUtils.getSafeName(graph, s.getSubject()) + " " + NameUtils.getSafeName(graph, s.getPredicate()) + " " + NameUtils.getSafeName(graph, s.getObject());\r
        }\r
        \r
-       private List<Statement> filterTraversed(List<Statement> in) throws ServiceException {\r
+       private List<Statement> filterTraversed(List<Statement> in) throws DatabaseException {\r
                return filter(traversed, in);\r
        }\r
        \r
-       private List<Statement> filterNonTested(List<Statement> in) throws ServiceException {\r
+       private List<Statement> filterNonTested(List<Statement> in) throws DatabaseException {\r
                return filter(nonTested, in);\r
        }\r
        \r
-       private List<Statement> filter(Collection<Resource> toFilter, List<Statement> in) throws ServiceException {\r
+       private List<Statement> filterNonTraversed(List<Statement> in) throws DatabaseException {\r
+               return filter(nonTraversed, in);\r
+       }\r
+       \r
+       private List<Statement> filter(Collection<Resource> toFilter, List<Statement> in) throws DatabaseException {\r
                if (toFilter.size() == 0)\r
                        return in;\r
                List<Statement> out = new ArrayList<Statement>();\r