X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop%2Fsrc%2Forg%2Fsimantics%2Finterop%2Ftest%2FGraphComparator.java;fp=org.simantics.interop%2Fsrc%2Forg%2Fsimantics%2Finterop%2Ftest%2FGraphComparator.java;h=e20c83e10b2ef021c1b8218e1ae7aab0e6ff6363;hb=954617febb489c628824343f08f41e1a0a047796;hp=0366df96a2a33749eb7074aae083e22d7b5fede2;hpb=871c099c9e3bd940029ab2cd9ac4565324b065ce;p=simantics%2Finterop.git diff --git a/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java b/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java index 0366df9..e20c83e 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java @@ -30,10 +30,6 @@ import org.simantics.db.Statement; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.DoesNotContainValueException; -import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; -import org.simantics.db.exception.ServiceException; -import org.simantics.db.exception.ValidationException; import org.simantics.layer0.Layer0; import org.simantics.utils.datastructures.BijectionMap; import org.simantics.utils.datastructures.MapList; @@ -212,7 +208,7 @@ public class GraphComparator { comparator.setComparator(this); - comparableResources.map(r1, r2); + addComparable(r1, r2, false); final Stack objectsLeft = new Stack(); final Stack objectsRight = new Stack(); @@ -276,9 +272,10 @@ public class GraphComparator { processedResources.add(r1); - if(!comparableResources.contains(r1, r2) && (comparableResources.containsLeft(r1)||comparableResources.containsRight(r2))) { + if((comparableResources.containsLeft(r1)||comparableResources.containsRight(r2)) && !comparableResources.contains(r1, r2)) { 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."); } + addComparable(r1, r2, false); //System.out.println("test " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2)); compareProps(r1, r2); @@ -293,6 +290,7 @@ public class GraphComparator { ss1 = filterNonTested(ss1); ss2 = filterNonTested(ss2); + compareStatements(ss1, ss2, null, null,null,null); ss1.clear(); ss2.clear(); @@ -303,6 +301,8 @@ public class GraphComparator { ss2.addAll(g.getStatements(r2, rel)); ss1 = filterAsserted(r1, ss1); ss2 = filterAsserted(r2, ss2); + ss1 = filterNonTraversed(ss1); + ss2 = filterNonTraversed(ss2); compareStatements(ss1, ss2, objectsLeft, objectsRight,unreliableLeft,unreliableRight); ss1.clear(); ss2.clear(); @@ -602,7 +602,6 @@ public class GraphComparator { return false; BijectionMap map = getMatchingPaths(leftPaths, rightPaths); return map.size() == leftPaths.size(); - } private BijectionMap getMatchingPaths(Set leftPaths, Set rightPaths) { @@ -622,7 +621,7 @@ public class GraphComparator { return map; } - private void expand(Set paths) throws ManyObjectsForFunctionalRelationException, ServiceException { + private void expand(Set paths) throws DatabaseException { Set stepPathsLeft = new HashSet(); if (paths.size() == 0) return; @@ -639,7 +638,7 @@ public class GraphComparator { } } - private Collection findComparableRight(Path leftPath, Resource beginRight) throws ManyObjectsForFunctionalRelationException, ServiceException { + private Collection findComparableRight(Path leftPath, Resource beginRight) throws DatabaseException { Set rightPaths = new HashSet(); rightPaths.addAll(Path.create(g.getStatements(beginRight, getRight(leftPath.getStatements().get(0).getPredicate())))); for (int i = 1; i < leftPath.getLength(); i++) { @@ -670,6 +669,10 @@ public class GraphComparator { return comparableStatements; } + public BijectionMap getComparableResources() { + return comparableResources; + } + public GraphChanges getChanges() { return new GraphChanges(r1,r2,changes1,changes2,modifications,comparableResources); } @@ -677,21 +680,22 @@ public class GraphComparator { private void addComparable(Statement left, Statement right, boolean process) throws DatabaseException { addComparable(left.getObject(), right.getObject(), process); comparableStatements.map(left, right); - comparableResources.map(left.getObject(), right.getObject()); + //comparableResources.map(left.getObject(), right.getObject()); } private void addComparable(Resource left, Resource right, boolean process) throws DatabaseException { - if(!comparableResources.contains(r1, r2)) { - if (comparableResources.containsLeft(r1)||comparableResources.containsRight(r2)) { - 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."); + if(!comparableResources.contains(left, right)) { + if (comparableResources.containsLeft(left)||comparableResources.containsRight(right)) { + 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."); } else { + if (DEBUG) System.out.println(left + " = " + right); comparableResources.map(left, right); } } } - public List filterAsserted(Resource r, Collection in) throws ServiceException { + public List filterAsserted(Resource r, Collection in) throws DatabaseException { List out = new ArrayList(); for (Statement s : in) { if (!s.isAsserted(r)) @@ -700,20 +704,26 @@ public class GraphComparator { } return out; } + + - private String printStatement(ReadGraph graph, Statement s) throws ValidationException, ServiceException { + private String printStatement(ReadGraph graph, Statement s) throws DatabaseException { return NameUtils.getSafeName(graph, s.getSubject()) + " " + NameUtils.getSafeName(graph, s.getPredicate()) + " " + NameUtils.getSafeName(graph, s.getObject()); } - private List filterTraversed(List in) throws ServiceException { + private List filterTraversed(List in) throws DatabaseException { return filter(traversed, in); } - private List filterNonTested(List in) throws ServiceException { + private List filterNonTested(List in) throws DatabaseException { return filter(nonTested, in); } - private List filter(Collection toFilter, List in) throws ServiceException { + private List filterNonTraversed(List in) throws DatabaseException { + return filter(nonTraversed, in); + } + + private List filter(Collection toFilter, List in) throws DatabaseException { if (toFilter.size() == 0) return in; List out = new ArrayList();