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

Modified Files:
      Tag: MMBase-1_8
        Dove.java 
Log Message:
added a missing method to change relations



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


Index: Dove.java
===================================================================
RCS file: 
/var/cvs/applications/dove/src/org/mmbase/applications/dove/Dove.java,v
retrieving revision 1.78.2.6
retrieving revision 1.78.2.7
diff -u -b -r1.78.2.6 -r1.78.2.7
--- Dove.java   3 Mar 2008 14:31:59 -0000       1.78.2.6
+++ Dove.java   19 Mar 2008 12:04:01 -0000      1.78.2.7
@@ -54,7 +54,7 @@
  *
  * @author Pierre van Rooden
  * @since MMBase-1.5
- * @version $Id: Dove.java,v 1.78.2.6 2008/03/03 14:31:59 michiel Exp $
+ * @version $Id: Dove.java,v 1.78.2.7 2008/03/19 12:04:01 andre Exp $
  */
 
 public class Dove extends AbstractDove {
@@ -1064,7 +1064,7 @@
     }
 
     /**
-     * Creates a new node.
+     * Creates a new relation.
      * @param alias the node alias in the put tree
      * @param values a Map with new node values
      * @param aliases a Map with mappings from XML aliases to node reference 
values
@@ -1111,7 +1111,7 @@
 
 
     /**
-     * Creates a new node.
+     * Deletes a node.
      * @param alias the node alias in the put tree
      * @param originalValues a Map with the original values of the node
      * @param out the element that describes 'new' cloud.
@@ -1142,7 +1142,7 @@
      }
 
     /**
-     * Creates a new node.
+     * Deletes a relation.
      * @param alias the node alias in the put tree
      * @param originalValues a Map with the original values of the relation
      * @param out the element that describes 'new' cloud.
@@ -1166,12 +1166,55 @@
             err.setAttribute(ELM_TYPE, IS_SERVER);
             return false;
         }
+     }
 
+    /**
+     * Changes a relation
+     * @param alias the node alias in the put tree
+     * @param values a Map with new node values
+     * @param originalValues a Map with original node values, used for 
validation
+     * @param aliases a Map with mappings from XML aliases to node reference 
values
+     * @param out the element that describes 'new' cloud.
+     *           The result of the put (an error or the resulting cloud) 
should be added
+     *           as childs to this element.
+     * @param cloud the cloud to work on
+     * @return true if succesful, false if an error ocurred
+     */
+    protected boolean putChangeRelation(String alias, Map values, Map 
originalValues, Map aliases, Element out, Cloud cloud) {
+        String role = (String)values.get("_role");
+        
+        RelationManager relman = cloud.getRelationManager(role);
+        String sourcenumber=getNodeReferenceFromValue("_source",values, 
aliases);
+        String 
destinationnumber=getNodeReferenceFromValue("_destination",values, aliases);
 
+        if (log.isDebugEnabled()) log.debug("Changing a relation between node 
" + sourcenumber + " and " + destinationnumber);
+
+        org.mmbase.bridge.Node mmbaseNode = cloud.getNode(alias);
+        // check if they are the same type
+        if (mmbaseNode.getNodeManager().getName().equals(relman.getName()) ) {
+            // create new node for response
+            Element relationElement = doc.createElement(RELATION);
+            relationElement.setAttribute(ELM_SOURCE, "" + sourcenumber);
+            relationElement.setAttribute(ELM_DESTINATION, "" + 
destinationnumber);
+            relationElement.setAttribute(ELM_ROLE, role);
+            if (!fillFields(alias, mmbaseNode, relationElement, values, 
originalValues)) {
+                out.appendChild(relationElement);
+                return false;
+            }
+            mmbaseNode.commit();
+            // add node to response
+            out.appendChild(relationElement);
+            return true;
+        } else {
+            // give error its the wrong type
+            Element err = addContentElement(ERROR, "Node not same type as in 
the cloud, node number : " + alias + ", cloud type=" + 
mmbaseNode.getNodeManager().getName()+", expected=" + relman.getName() + ")", 
out);
+            err.setAttribute(ELM_TYPE, IS_SERVER);
+            return false;
+        }
      }
 
     /**
-     * Creates a new node.
+     * Changes a node.
      * @param alias the node alias in the put tree
      * @param values a Map with new node values
      * @param originalValues a Map with original node values, used for 
validation
@@ -1292,10 +1335,19 @@
                 if (originalValues != null) {
                     if(!putDeleteRelation(alias, originalValues, newElement, 
cloud)) return false;;
                 } // no error ???
-            // add code for change relation ?
+            } else if (status == null || status.equals("") || 
status.equals("change")) {
+                // check if we have an original allready existing relation
+                Map originalValues = (Map) originalRelations.get(alias);
+                if (originalValues != null) {
+                    if(!putChangeRelation(alias, values, originalValues, 
aliases, newElement, cloud)) return false;
+                } else {
+                    Element err = addContentElement(ERROR, "Relation not found 
between original values, node number: " + alias, out);
+                    err.setAttribute(ELM_TYPE, IS_SERVER);
+                    return false;
+                }
             } else {
                 // give error not a org. node
-                Element err = addContentElement(ERROR, "Invalid status " + 
status + " for node : " + alias, out);
+                Element err = addContentElement(ERROR, "Invalid status " + 
status + " for (relation) node : " + alias, out);
                 err.setAttribute(ELM_TYPE, IS_SERVER);
                 return false;
             }
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to