]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java
Graph comparison and change management fixes.
[simantics/interop.git] / org.simantics.interop / src / org / simantics / interop / test / GraphChanges.java
index 3fe74177a2b93bcc71f09e90656b8ffc09858d74..304c156f3ec166a85440569087aa0e5c74221fdb 100644 (file)
@@ -39,9 +39,6 @@ public class GraphChanges {
                        this.leftStm = leftStm;
                        this.rightStm = rightStm;
                        
-                       if (leftSub.getResourceId() < 0)
-                               System.out.println();
-                       
                        hashCode = leftSub.hashCode() + rightSub.hashCode();
                        if (leftStm != null)
                                hashCode += leftStm.hashCode();
@@ -50,11 +47,11 @@ public class GraphChanges {
                }
 
                public boolean isLeftAsserted() {
-                       return !leftSub.equals(leftStm.getSubject());
+                       return leftStm != null && !leftSub.equals(leftStm.getSubject());
                }
                
                public boolean isRightAsserted() {
-                       return !rightSub.equals(rightStm.getSubject());
+                       return rightStm != null && !rightSub.equals(rightStm.getSubject());
                }
 
                public Resource getLeftSub() {
@@ -274,6 +271,8 @@ public class GraphChanges {
                                                p2 = p1;
                                        Resource o1 = del.getObject();
                                        Resource o2 = bijection.getComparable().getRight(o1);
+                                       if (o2 == null)
+                                               o2 = graph.getPossibleObject(s2, p2);
                                        
                                        if (s2 == null || p2 == null || o2 == null) {
                                                throw new DatabaseException("Did not find matching statement from bijection for (" + s1 +","+p1+","+o1+"), got (" + s2 +","+p2+","+o2+")");
@@ -304,49 +303,54 @@ public class GraphChanges {
                                        Statement del = mod.leftStm;
                                        Resource sub1 = mod.getLeftSub();
                                        Resource sub2 = bijection.getComparable().getRight(sub1);
-                                       if (sub2 == null) {
-                                               throw new DatabaseException("Did not find matching resource from bijection for " + sub1);
-                                       }
-                                       Resource s1 = del.getSubject();
-                                       Resource s2 = bijection.getComparable().getRight(s1);
-                                       Resource p1 = del.getPredicate();
+                                       Resource p1 = del != null ? del.getPredicate() : mod.getPredicate();
                                        Resource p2 = bijection.getComparable().getRight(p1);
                                        if (p2 == null)
                                                p2 = p1;
-                                       Resource o1 = del.getObject();
+                                       Resource o1 = del != null ? del.getObject() : null;
                                        Resource o2 = bijection.getComparable().getRight(o1);
+                                       
+                                       if (mod.isLeftAsserted()) {
+                                               if (sub2 == null)
+                                                       sub2 = sub1;
+                                               
+                                       }
+                                       if (o2 == null && p2 != null)
+                                               o2 = graph.getPossibleObject(sub2, p2);
                                        if (mod.isLeftAsserted()) {
-                                               if (s2 == null)
-                                                       s2 = s1;
                                                if (o2 == null)
                                                        o2 = o1;
-                                       } 
-                                       
-                                       if (s2 == null || p2 == null) {
-                                               throw new DatabaseException("Did not find matching statement from bijection for (" + s1 +","+p1+","+o1+"), got (" + s2 +","+p2+","+o2+")");
                                        }
-                                       Collection<Statement> stms = graph.getStatements(s2, p2);
-                                       Statement stm2 = null;
-                                       if (o2 == null) {
-                                               // Matching literal resources are not included in bijection map.
-                                               if (stms.size() == 1) {
-                                                        stm2 = stms.iterator().next();
-                                               } else {
-                                                        throw new DatabaseException("Did not find matching statement from bijection for (" + s1 +","+p1+","+o1+"), got (" + s2 +","+p2+","+o2+")");
-                                               }
+                                       if (sub2 == null || p2 == null) {
+                                               throw new DatabaseException("Did not find matching statement from bijection for (" + sub1 +","+p1+","+o1+"), got (" + sub2 +","+p2+","+o2+")");
+                                       }
+                                       if (del == null) {
+                                               Modification mod2 = new Modification(sub2, mod.rightSub, null, mod.rightStm);
+                                               modifications.add(mod2);
                                        } else {
-                                               for (Statement s : stms) {
-                                                       if (s.getObject().equals(o2)) {
-                                                               stm2 = s;
-                                                               break;
+                                               Collection<Statement> stms = graph.getStatements(sub2, p2);
+                                               Statement stm2 = null;
+                                               if (o2 == null) {
+                                                       // Matching literal resources are not included in bijection map.
+                                                       if (stms.size() == 1) {
+                                                               stm2 = stms.iterator().next();
+                                                       } else {
+                                                               throw new DatabaseException("Did not find matching statement from bijection for (" + sub1 +","+p1+","+o1+"), got (" + sub2 +","+p2+","+o2+")");
+                                                       }
+                                               } else {
+                                                       for (Statement s : stms) {
+                                                               if (s.getObject().equals(o2)) {
+                                                                       stm2 = s;
+                                                                       break;
+                                                               }
                                                        }
                                                }
+                                               if (stm2 == null) {
+                                                       throw new DatabaseException("Did not find matching statement from bijection for (" + sub1 +","+p1+","+o1+"), got (" + sub2 +","+p2+","+o2+"), but it is not in DB!");
+                                               }
+                                               Modification mod2 = new Modification(sub2, mod.rightSub, stm2, mod.rightStm);
+                                               modifications.add(mod2);
                                        }
-                                       if (stm2 == null) {
-                                               throw new DatabaseException("Did not find matching statement from bijection for (" + s1 +","+p1+","+o1+"), got (" + s2 +","+p2+","+o2+"), but it is not in DB!");
-                                       }
-                                       Modification mod2 = new Modification(sub2, mod.rightSub, stm2, mod.rightStm);
-                                       modifications.add(mod2);
                                }
                                
                        }