Update of 
/var/cvs/applications/editwizard/src/org/mmbase/applications/editwizard
In directory james.mmbase.org:/tmp/cvs-serv29639

Modified Files:
        Wizard.java WizardDatabaseConnector.java 
Log Message:
Editwizards horribly broken if you try to link an object to an object of the 
same type (using ), it ends up making a copy of the origin node. See also 
devlist. Fixed in 1.8 branch already on march 3


See also: 
http://cvs.mmbase.org/viewcvs/applications/editwizard/src/org/mmbase/applications/editwizard


Index: Wizard.java
===================================================================
RCS file: 
/var/cvs/applications/editwizard/src/org/mmbase/applications/editwizard/Wizard.java,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -b -r1.162 -r1.163
--- Wizard.java 19 Mar 2008 13:13:56 -0000      1.162
+++ Wizard.java 11 Jul 2008 14:24:59 -0000      1.163
@@ -46,7 +46,7 @@
  * @author Pierre van Rooden
  * @author Hillebrand Gelderblom
  * @since MMBase-1.6
- * @version $Id: Wizard.java,v 1.162 2008/03/19 13:13:56 michiel Exp $
+ * @version $Id: Wizard.java,v 1.163 2008/07/11 14:24:59 michiel Exp $
  *
  */
 public class Wizard implements org.mmbase.util.SizeMeasurable, 
java.io.Serializable {
@@ -2466,9 +2466,26 @@
 
                     Iterator<Node> i = newSubRelations.iterator();
                     while (i.hasNext()) {
-                        Node newSubRelation = i.next();
+                        Node newSubRelation = (Node) i.next();
+                        Utils.setAttribute(newSubRelation, "already-exists", 
"true");
+                        NodeList newSubSubRelations = 
Utils.selectNodeList(newSubRelation, ".//relation");
+                        for (int k = 0; k < newSubSubRelations.getLength(); 
k++) {
+                            Node newSubSubRelation = 
newSubSubRelations.item(k);
+                            Utils.setAttribute(newSubSubRelation, 
"already-exists", "true");
+                        }
+                        NodeList newSubObjects = 
Utils.selectNodeList(newSubRelation, ".//object");
+                        for (int j = 0; j < newSubObjects.getLength(); j++) {
+                            Node newSubObject = newSubObjects.item(j);
+                            Utils.setAttribute(newSubObject, "already-exists", 
"true");
+                            
//loadedData.getDocumentElement().appendChild(loadedData.importNode(newSubObject.cloneNode(true),
 true));
+                        }
+
                         
loadedData.getDocumentElement().appendChild(loadedData.importNode(newSubRelation.cloneNode(true),
 true));
+
+
+
                     }
+
                 } else {
                     log.debug("Nothing found to load");
                 }


Index: WizardDatabaseConnector.java
===================================================================
RCS file: 
/var/cvs/applications/editwizard/src/org/mmbase/applications/editwizard/WizardDatabaseConnector.java,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- WizardDatabaseConnector.java        19 Feb 2008 20:52:31 -0000      1.52
+++ WizardDatabaseConnector.java        11 Jul 2008 14:24:59 -0000      1.53
@@ -31,7 +31,7 @@
  * @author Michiel Meeuwissen
  * @author Pierre van Rooden
  * @since MMBase-1.6
- * @version $Id: WizardDatabaseConnector.java,v 1.52 2008/02/19 20:52:31 
nklasens Exp $
+ * @version $Id: WizardDatabaseConnector.java,v 1.53 2008/07/11 14:24:59 
michiel Exp $
  *
  */
 public class WizardDatabaseConnector implements java.io.Serializable {
@@ -492,7 +492,7 @@
             if (context!=null && !context.equals("")) {
                 Utils.setAttribute(objectNode, "context", context);
             }
-            
fillObjectFields(data,targetParentNode,objectDef,objectNode,params,createorder);
+            fillObjectFields(data, targetParentNode, objectDef, objectNode, 
params, createorder);
             relations = Utils.selectNodeList(objectDef, "relation");
         } else {
            throw new WizardException("Can only create with 'action' 'object' 
or 'relation' nodes");
@@ -511,7 +511,14 @@
             // determine destination
             // dnumber can be null
             String dnumber = Utils.getAttribute(relation, "destination", null);
-            dnumber = Utils.transformAttribute(data.getDocumentElement(), 
dnumber, false, params);
+            if (dnumber != null) {
+                String dnumberTransformed = 
Utils.transformAttribute(data.getDocumentElement(), dnumber, false, params);
+                log.debug("dnumber " + dnumber + " -> " + dnumberTransformed);
+                if (! dnumber.equals(dnumberTransformed)) {
+                    dnumber = dnumberTransformed;
+                    Utils.setAttribute(relation, "destination", dnumber);
+                }
+            }
             String dtype = "";
 
             String createDir = Utils.getAttribute(relation, 
Dove.ELM_CREATEDIR, "either");
@@ -527,6 +534,7 @@
                     throw new WizardException("Could not load object (" + 
dnumber + "). Message: " + Logging.stackTrace(e));
                 }
                 // but annotate that this one is loaded from mmbase. Not a new 
one
+                Utils.setAttribute(inside_object, "already-exists", "true");
                 
loadedData.getDocumentElement().appendChild(loadedData.importNode(inside_object.cloneNode(true),
 true));
                 
                 // grab the type
@@ -809,7 +817,7 @@
             String nodename = node.getNodeName();
 
             String did = Utils.getAttribute(node, "did", "");
-            Node orignode = Utils.selectSingleNode(reqorig, ".//[EMAIL 
PROTECTED]'"+did+"']");
+            Node orignode = Utils.selectSingleNode(reqorig, ".//[EMAIL 
PROTECTED]'"+did+"' and not(@already-exists)]");
 
             if (orignode!=null) {
                 // we found the original relation. Check to see if destination 
has changed.
@@ -863,6 +871,13 @@
                     }
                 }
             } else {
+                // this is a new relation or object. Remember that
+                // but, check first if the may-be-new object has a  
"already-exists" attribute. If so,
+                // we don't have a new object, no no, this is a later-loaded 
object which is not added to the
+                // original datanode (should be better in later versions, eg. 
by using a repository).
+                String already_exists = Utils.getAttribute(node, 
"already-exists", "false");
+                if (!already_exists.equals("true")) {
+                    // go ahead. this seems to be a really new one...
                 // this is a new relation or object.
                     Utils.setAttribute(node, "status", "new");
 
@@ -881,6 +896,7 @@
                         }
                }
         }
+        }
 
         markDeletedNodes(req, reqnew, reqorig);
 
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to