It seems that this check-in broke the possibility to use $<variable>
in the create action ('e.g. $origin). I don't understand why. Any idea
what could be the problem?



2008/2/14, Nico Klasens <[EMAIL PROTECTED]>:
> Update of 
> /var/cvs/applications/editwizard/src/org/mmbase/applications/editwizard
>  In directory 
> james.mmbase.org:/tmp/cvs-serv2669/applications/editwizard/src/org/mmbase/applications/editwizard
>
>  Modified Files:
>       Tag: MMBase-1_8
>         WizardDatabaseConnector.java Wizard.java
>  Log Message:
>  MMB-1594 Data loaded by included lists (add list item) are not saved when 
> changed
>
>
>  See also: 
> http://cvs.mmbase.org/viewcvs/applications/editwizard/src/org/mmbase/applications/editwizard
>  See also: http://www.mmbase.org/jira/browse/MMB-1594
>
>
>  Index: WizardDatabaseConnector.java
>  ===================================================================
>  RCS file: 
> /var/cvs/applications/editwizard/src/org/mmbase/applications/editwizard/WizardDatabaseConnector.java,v
>  retrieving revision 1.46
>  retrieving revision 1.46.2.1
>  diff -u -b -r1.46 -r1.46.2.1
>  --- WizardDatabaseConnector.java        13 Feb 2006 16:16:50 -0000      1.46
>  +++ WizardDatabaseConnector.java        14 Feb 2008 17:16:11 -0000      
> 1.46.2.1
>  @@ -31,7 +31,7 @@
>   * @author Michiel Meeuwissen
>   * @author Pierre van Rooden
>   * @since MMBase-1.6
>  - * @version $Id: WizardDatabaseConnector.java,v 1.46 2006/02/13 16:16:50 
> pierre Exp $
>  + * @version $Id: WizardDatabaseConnector.java,v 1.46.2.1 2008/02/14 
> 17:16:11 nklasens Exp $
>   *
>   */
>   public class WizardDatabaseConnector {
>  @@ -406,8 +406,8 @@
>       * @return The resulting object(tree) node.
>       * @throws WizardException if the object cannot be created
>       */
>  -    public Node createObject(Document data, Node targetParentNode, Node 
> objectDef, Map params) throws WizardException {
>  -        return createObject(data, targetParentNode, objectDef, params, 1);
>  +    public Node createObject(Document data, Node targetParentNode, Node 
> objectDef, Map params, Document loadedData) throws WizardException {
>  +        return createObject(data, targetParentNode, objectDef, params, 1, 
> loadedData);
>      }
>
>      /**
>  @@ -442,7 +442,7 @@
>       * @return The resulting object(tree) node.
>       * @throws WizardException if the object cannot be created
>       */
>  -    public Node createObject(Document data, Node targetParentNode, Node 
> objectDef, Map params, int createorder) throws WizardException {
>  +    public Node createObject(Document data, Node targetParentNode, Node 
> objectDef, Map params, int createorder, Document loadedData) throws 
> WizardException {
>
>          String context = (String)params.get("context");
>
>  @@ -456,7 +456,7 @@
>              NodeList objectdefs = Utils.selectNodeList(objectDef, 
> "object|relation");
>              Node firstobject = null;
>              for (int i=0; i < objectdefs.getLength(); i++) {
>  -                firstobject = createObject(data, targetParentNode, 
> objectdefs.item(i), params);
>  +                firstobject = createObject(data, targetParentNode, 
> objectdefs.item(i), params, loadedData);
>              }
>              log.debug("This is an action");  // no relations to add here..
>              return firstobject;
>  @@ -515,8 +515,10 @@
>                  } catch (Exception e) {
>                      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.appendChild(loadedData.importNode(inside_object.cloneNode(true), 
> true));
>  +
>                  // grab the type
>                  dtype = Utils.getAttribute(inside_object, "type", "");
>              } else {
>  @@ -549,7 +551,7 @@
>                      
> ((Element)inside_object).setAttribute("type",Utils.getAttribute(relation, 
> "destinationtype", ""));
>                      
> ((Element)inside_object).setAttribute("disposable","true");
>                  } else {
>  -                    inside_object = createObject(data,relationNode, 
> inside_objectdef, params);
>  +                    inside_object = createObject(data,relationNode, 
> inside_objectdef, params, loadedData);
>                      dnumber = Utils.getAttribute(inside_object, "number");
>                      
> ((Element)relationNode).setAttribute("destination",dnumber);
>                  }
>  @@ -639,11 +641,12 @@
>       *
>       * @param     originalData            The original data object tree.
>       * @param     newData                 The new and manipulated data. 
> According to differences between the original and the new data, the 
> transaction is constructed.
>  +     * @param     loadedData              The data loaded by actions on the 
> wizard
>       * @param     binaries                 A hashmap with the uploaded 
> binaries.
>       * @return   The element containing the results of the put transaction.
>       */
>  -    public Element put(Document originalData, Document newData, Map 
> binaries) throws WizardException {
>  -        Node putcmd =getPutData(originalData, newData);
>  +    public Element put(Document originalData, Document loadedData, Document 
> newData, Map binaries) throws WizardException {
>  +        Node putcmd =getPutData(originalData, loadedData, newData);
>          return sendCommand(putcmd.getOwnerDocument().getDocumentElement(), 
> binaries);
>      }
>
>  @@ -738,9 +741,10 @@
>       * The differences between the original and the new data define the 
> transaction.
>       *
>       * @param     originalData    The original data.
>  +     * @param     loadedData      The data loaded by actions
>       * @param     newData         The new data.
>       */
>  -    public Node getPutData(Document originalData, Document newData) throws 
> WizardException {
>  +    public Node getPutData(Document originalData, Document loadedData, 
> Document newData) throws WizardException {
>          Document workDoc = Utils.emptyDocument();
>          
> workDoc.appendChild(workDoc.importNode(newData.getDocumentElement().cloneNode(true),
>  true));
>
>  @@ -761,8 +765,12 @@
>          }
>
>          // serialize original data. Place objects first, relations second
>  +        // serialize loaded data. Place objects first, relations second
>          makeFlat(originalData, reqorig, ".//object", "field");
>  +        makeFlat(loadedData, reqorig, ".//object", "field");
>  +
>          makeFlat(originalData, reqorig, ".//relation", "field");
>  +        makeFlat(loadedData, reqorig, ".//relation", "field");
>
>          // serialize new data. Place objects first, relations second
>          makeFlat(workRoot, reqnew, ".//object", "field");
>  @@ -784,10 +792,8 @@
>              String nodename = node.getNodeName();
>
>              String did = Utils.getAttribute(node, "did", "");
>  -            Node orignode = Utils.selectSingleNode(reqorig, ".//[EMAIL 
> PROTECTED]'"+did+"' and not(@already-exists)]");
>  +            Node orignode = Utils.selectSingleNode(reqorig, ".//[EMAIL 
> PROTECTED]'"+did+"']");
>
>  -//            String nodenumber = Utils.getAttribute(node, "number", "");
>  -//            Node orignode = Utils.selectSingleNode(reqorig, ".//[EMAIL 
> PROTECTED]'"+nodenumber+"' and not(@already-exists)]");
>              if (orignode!=null) {
>                  // we found the original relation. Check to see if 
> destination has changed.
>                  if (nodename.equals("relation")) {
>  @@ -840,13 +846,7 @@
>                      }
>                  }
>              } 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");
>
>                          // check if fields values have been set
>  @@ -862,36 +862,10 @@
>                                  
> fields.item(j).getParentNode().removeChild(fields.item(j));
>                              }
>                          }
>  -
>  -                } else {
>  -                    // remove it from the list.
>  -                    node.getParentNode().removeChild(node);
>  -                }
>              }
>          }
>
>  -        // remove all repository nodes
>  -        NodeList repnodes = Utils.selectNodeList(reqorig, ".//[EMAIL 
> PROTECTED]'true']|.//[EMAIL PROTECTED]'true']");
>  -        for (int i=0; i<repnodes.getLength(); i++) {
>  -            Node repnode = repnodes.item(i);
>  -            repnode.getParentNode().removeChild(repnode);
>  -        }
>  -
>  -        // find all deleted relations and objects
>  -        NodeList orignodes = Utils.selectNodeList(reqorig, 
> ".//relation|.//object");
>  -        for (int i=0; i<orignodes.getLength(); i++) {
>  -            Node orignode = orignodes.item(i);
>  -            String nodenumber = Utils.getAttribute(orignode, "number", "");
>  -            Node node = Utils.selectSingleNode(reqnew, ".//[EMAIL 
> PROTECTED]'"+nodenumber+"']");
>  -            if (node==null) {
>  -                // item is apparently deleted.
>  -                // place relation node anyway but say that it should be 
> deleted (and make it so more explicit)
>  -                Node newnode = req.createElement(orignode.getNodeName());
>  -                Utils.copyAllAttributes(orignode, newnode);
>  -                Utils.setAttribute(newnode, "status", "delete");
>  -                reqnew.appendChild(newnode);
>  -            }
>  -        }
>  +        markDeletedNodes(req, reqnew, reqorig);
>
>          // now, do our final calculations:
>          //
>  @@ -941,6 +915,31 @@
>          return req.getDocumentElement();
>      }
>
>  +    private void markDeletedNodes(Document req, Node reqnew, Node reqorig) {
>  +        // remove all repository nodes
>  +        NodeList repnodes = Utils.selectNodeList(reqorig, ".//[EMAIL 
> PROTECTED]'true']|.//[EMAIL PROTECTED]'true']");
>  +        for (int i=0; i<repnodes.getLength(); i++) {
>  +            Node repnode = repnodes.item(i);
>  +            repnode.getParentNode().removeChild(repnode);
>  +        }
>  +
>  +        // find all deleted relations and objects
>  +        NodeList orignodes = Utils.selectNodeList(reqorig, 
> ".//relation|.//object");
>  +        for (int i=0; i<orignodes.getLength(); i++) {
>  +            Node orignode = orignodes.item(i);
>  +            String nodenumber = Utils.getAttribute(orignode, "number", "");
>  +            Node node = Utils.selectSingleNode(reqnew, ".//[EMAIL 
> PROTECTED]'"+nodenumber+"']");
>  +            if (node==null) {
>  +                // item is apparently deleted.
>  +                // place relation node anyway but say that it should be 
> deleted (and make it so more explicit)
>  +                Node newnode = req.createElement(orignode.getNodeName());
>  +                Utils.copyAllAttributes(orignode, newnode);
>  +                Utils.setAttribute(newnode, "status", "delete");
>  +                reqnew.appendChild(newnode);
>  +            }
>  +        }
>  +    }
>  +
>      /**
>       * This method makes the object data tree flat, so that Dove can 
> construct a transaction from it.
>       *
>
>
>  Index: Wizard.java
>  ===================================================================
>  RCS file: 
> /var/cvs/applications/editwizard/src/org/mmbase/applications/editwizard/Wizard.java,v
>  retrieving revision 1.149.2.2
>  retrieving revision 1.149.2.3
>  diff -u -b -r1.149.2.2 -r1.149.2.3
>  --- Wizard.java 6 Feb 2008 14:07:12 -0000       1.149.2.2
>  +++ Wizard.java 14 Feb 2008 17:16:11 -0000      1.149.2.3
>  @@ -45,7 +45,7 @@
>   * @author Pierre van Rooden
>   * @author Hillebrand Gelderblom
>   * @since MMBase-1.6
>  - * @version $Id: Wizard.java,v 1.149.2.2 2008/02/06 14:07:12 michiel Exp $
>  + * @version $Id: Wizard.java,v 1.149.2.3 2008/02/14 17:16:11 nklasens Exp $
>   *
>   */
>   public class Wizard implements org.mmbase.util.SizeMeasurable {
>  @@ -107,14 +107,17 @@
>      private String timezone;
>
>      /**
>  -     * public xmldom's: the schema, the data and the originaldata is stored.
>  -     *
>  -     * @scope private
>  +     * xmldom's: the schema, the data and the originaldata is stored.
>       */
>      private Document schema;
>      private Document data;
>      private Document originalData;
>
>  +    /**
>  +     *  document where loaded data will be stored in when added by wizard 
> actions
>  +     */
>  +    private Document loadedData;
>  +
>      // not yet committed uploads are stored in these hashmaps
>      private Map binaries = new HashMap();
>      private Map binaryNames = new HashMap();
>  @@ -294,7 +297,7 @@
>       * Returns true if the specified operation is valid for the node with 
> the specified objectnumber.
>       * The  operation is valid if the node has the given property set to 
> true.
>       * To maintain backwards compatible, if the property is not given, the 
> default value is true.
>  -     * @param objectNumber teh number of teh ndoe to check
>  +     * @param objectNumber the number of the node to check
>       * @param operation a valid operation, i.e. maywrite or maydelete
>       * @throws WizardException if the object cannot be retrieved
>       */
>  @@ -413,12 +416,13 @@
>          // If dataid equals null, we don't need to do anything. Wizard will 
> not be used to show or save data;
>          // just to load schema information.
>          if (dataId != null) {
>  -            // setup original data
>  -            originalData = Utils.emptyDocument();
>  -
>              if (dataId.equals("new")) {
>                  log.debug("Creating new xml");
>
>  +                // setup original data
>  +                originalData = Utils.emptyDocument();
>  +                loadedData = Utils.emptyDocument();
>  +
>                  // Get the definition and create a copy of the 
> object-definition.
>                  Node objectdef = Utils.selectSingleNode(schema, 
> "./wizard-schema/[EMAIL PROTECTED]'create']");
>
>  @@ -435,7 +439,7 @@
>                  Node parent = data.getDocumentElement();
>
>                  // Ask the database to create that object, ultimately to get 
> the new id.
>  -                Node newobject = databaseConnector.createObject(data, 
> parent, objectdef, variables);
>  +                Node newobject = databaseConnector.createObject(data, 
> parent, objectdef, variables, loadedData);
>
>                  if (newobject == null) {
>                      throw new WizardException("Could not create new object. 
> Did you forget to add an 'object' subtag?");
>  @@ -457,6 +461,7 @@
>          if (currentFormId == null) {
>              currentFormId = determineNextForm("first");
>          }
>  +
>      }
>
>      /**
>  @@ -473,6 +478,7 @@
>          }
>          // setup original data
>          originalData = Utils.emptyDocument();
>  +        loadedData = Utils.emptyDocument();
>
>
>          // store original data, so that the put routines will know what to 
> save/change/add/delete
>  @@ -2113,6 +2119,9 @@
>              String value = cmd.getValue();
>              NodeList nodesToUpdate = Utils.selectNodeList(data, ".//[EMAIL 
> PROTECTED]'" + value + "']");
>              NodeList originalNodesToUpdate = 
> Utils.selectNodeList(originalData, ".//[EMAIL PROTECTED]'" + value + "']");
>  +            if (originalNodesToUpdate == null) {
>  +                originalNodesToUpdate = Utils.selectNodeList(loadedData, 
> ".//[EMAIL PROTECTED]'" + value + "']");
>  +            }
>
>              if ((nodesToUpdate != null) || (originalNodesToUpdate != null)) {
>                  Node updatedNode = null;
>  @@ -2289,7 +2298,7 @@
>                  log.debug("new orig: " + Utils.stringFormatted(data));
>              }
>
>  -            Element results = databaseConnector.put(originalData, data, 
> binaries);
>  +            Element results = databaseConnector.put(originalData, 
> loadedData, data, binaries);
>
>              // find the (new) objectNumber and store it.
>              String oldNumber = Utils.selectSingleNodeText(data, 
> ".//object/@number", null);
>  @@ -2399,7 +2408,7 @@
>
>
>          // Ask the database to create that object, and return it.
>  -        Node newRelation =  databaseConnector.createObject(data, parent, 
> relationDefinition, variables, createOrder);
>  +        Node newRelation =  databaseConnector.createObject(data, parent, 
> relationDefinition, variables, createOrder, loadedData);
>
>          // reload the data, there may be sub-list-data to be reloaded.
>          if (destinationId != null) {
>  @@ -2411,24 +2420,12 @@
>
>                  if (loadAction != null) {
>                      Collection newSubRelations = 
> databaseConnector.loadRelations(newRelatedNode, destinationId, loadAction);
>  -                    // newly loaded objects must be marked as 
> 'already-existing'.
>  +                    // newly loaded objects must be marked.
>
>                      Iterator i = newSubRelations.iterator();
>                      while (i.hasNext()) {
>                          Node newSubRelation = (Node) i.next();
>  -                        Utils.setAttribute(newSubRelation, 
> "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");
>  -                        }
>  -
>  -                        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");
>  -                        }
>  +                        
> loadedData.appendChild(loadedData.importNode(newSubRelation.cloneNode(true), 
> true));
>                      }
>                  } else {
>                      log.debug("Nothing found to load");
>  _______________________________________________
>  Cvs mailing list
>  [EMAIL PROTECTED]
>  http://lists.mmbase.org/mailman/listinfo/cvs
>


-- 
mihxil'  http://meeuw.org
nl_NL eo_XX en_US
_______________________________________________
Developers mailing list
Developers@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/developers

Reply via email to