]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java
Graph Comparison / Change management fixes.
[simantics/interop.git] / org.simantics.interop / src / org / simantics / interop / test / GraphChanges.java
index e52ad97924aff74d121ad27d6453fca44393f73d..f9065070fe095f8e3c247c12bf03011f8db811cd 100644 (file)
@@ -47,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() {
@@ -301,49 +301,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);
                                }
                                
                        }