Update of
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action
In directory
james.mmbase.org:/tmp/cvs-serv25107/applications/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action
Modified Files:
ToggleRelationAction.java AbstractRelationAction.java
Action.java AbstractNodeAction.java SortRelationAction.java
DeleteNodeAction.java
Log Message:
work in progress on the java code
See also:
http://cvs.mmbase.org/viewcvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action
Index: ToggleRelationAction.java
===================================================================
RCS file:
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action/ToggleRelationAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ToggleRelationAction.java 18 Aug 2008 19:13:05 -0000 1.1
+++ ToggleRelationAction.java 22 Sep 2008 14:33:46 -0000 1.2
@@ -11,7 +11,11 @@
import org.mmbase.applications.vprowizards.spring.util.DateTime;
import org.mmbase.bridge.Node;
import org.mmbase.bridge.NodeList;
+import org.mmbase.bridge.Relation;
+import org.mmbase.bridge.RelationList;
import org.mmbase.bridge.Transaction;
+import org.mmbase.util.logging.Logger;
+import org.mmbase.util.logging.Logging;
import org.springframework.web.multipart.MultipartFile;
/**
@@ -28,6 +32,8 @@
*
*/
public class ToggleRelationAction extends CreateRelationAction {
+ private static final Logger log =
Logging.getLoggerInstance(ToggleRelationAction.class);
+
private String relate;
private boolean isNodeCreated = false;
private List<Integer> nodesDelted = new ArrayList<Integer>();
@@ -36,6 +42,11 @@
return relate;
}
+ /**
+ * when this is set to 'true' and the relation does not exist yet, the
relation is created.
+ * Otherwise the relation is deleted if it exists.
+ * @param relate
+ */
public void setRelate(String relate) {
this.relate = relate;
}
@@ -43,29 +54,38 @@
@Override
protected Node doCreateNode(Transaction transaction, Map<String, Node>
idMap, HttpServletRequest request) {
// if relate is not empty and there is not a relation between
source and destination yet, create it.
- NodeList nl = sourceNode.getNodeManager()
-
.getRelatedNodes(destinationNode.getNodeManager(), role, "destination");
- if (nl.size() > 0) {
+// NodeList nl =
sourceNode.getRelatedNodes(destinationNode.getNodeManager(), role, null);
+ RelationList rl = sourceNode.getRelations(role,
destinationNode.getNodeManager(), "destination");
+ if (rl.size() > 0) {
// we have a relation
+ log.debug("relation already exist");
if (!StringUtils.isBlank(relate) &&
"true".equals(relate.toLowerCase())) {
// and we must relate: do nothing
+ log.debug("create is true: we do nothing");
} else {
// we must undo the relation
- for (int i = 0; i < nl.size(); i++) {
-
nodesDelted.add(nl.getNode(i).getNumber());
- nl.getNode(i).delete();
+ log.debug("create is false: we delete the
node");
+ for (int i = 0; i < rl.size(); i++) {
+
nodesDelted.add(rl.getRelation(i).getNumber());
+ rl.getRelation(i).delete(true);
}
}
} else {
// we don't have relation yet
+ log.debug("relation doesn't exist yet");
if (!StringUtils.isBlank(relate) &&
"true".equals(relate.toLowerCase())) {
// we must create a relation
- super.doCreateNode(transaction, idMap, request);
+ log.debug("create is true: we must create the
relation");
+ Node newRelation =
super.doCreateNode(transaction, idMap, request);
if (!hasErrors()) {
isNodeCreated = true;
+ return newRelation;
+ }else{
+ log.warn("error creating the relation");
}
} else {
+ log.debug("create is false, do nothing");
// and we don't have to create: do nothing
}
}
Index: AbstractRelationAction.java
===================================================================
RCS file:
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action/AbstractRelationAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- AbstractRelationAction.java 8 Sep 2008 16:52:10 -0000 1.2
+++ AbstractRelationAction.java 22 Sep 2008 14:33:46 -0000 1.3
@@ -30,6 +30,11 @@
protected String role;
protected RelationManager relationManager;
+ /**
+ * This template method implementation handles all the preconditions
for relation actions. When
+ * these are met, a new template method is called, [EMAIL PROTECTED]
this#doCreateNode(Transaction, Map, HttpServletRequest)}
+ * When you create specific relation actions, you extend this class and
implement that method.
+ */
@Override
protected final Node createNode(Transaction transaction, Map<String,
Node> idMap, HttpServletRequest request) {
if (StringUtils.isBlank(role)) {
@@ -60,7 +65,7 @@
}
/**
- * This callback method should be implemented by concrete
implementations of
+ * This template method should be implemented by concrete
implementations of
* this class. It is called by [EMAIL PROTECTED]
AbstractRelationAction#createNode(Transaction, Map, HttpServletRequest)} after
all
* the preliminary checks.
* @param transaction
Index: Action.java
===================================================================
RCS file:
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action/Action.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Action.java 8 Sep 2008 16:52:10 -0000 1.2
+++ Action.java 22 Sep 2008 14:33:46 -0000 1.3
@@ -1,9 +1,6 @@
package org.mmbase.applications.vprowizards.spring.action;
-import java.util.Map;
-
import org.mmbase.applications.vprowizards.spring.ResultContainer;
-import org.mmbase.bridge.Node;
/**
* This should be extended by all actions that can be registered to an Command
instance.
Index: AbstractNodeAction.java
===================================================================
RCS file:
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action/AbstractNodeAction.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- AbstractNodeAction.java 8 Sep 2008 16:52:10 -0000 1.3
+++ AbstractNodeAction.java 22 Sep 2008 14:33:46 -0000 1.4
@@ -8,13 +8,15 @@
import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.collections15.Factory;
+import org.apache.commons.collections15.FactoryUtils;
+import org.apache.commons.collections15.MapUtils;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.mmbase.applications.vprowizards.spring.FieldError;
import org.mmbase.applications.vprowizards.spring.GlobalError;
import org.mmbase.applications.vprowizards.spring.ResultContainer;
import org.mmbase.applications.vprowizards.spring.cache.CacheFlushHint;
import org.mmbase.applications.vprowizards.spring.util.DateTime;
-import org.mmbase.bridge.Cloud;
import org.mmbase.bridge.Node;
import org.mmbase.bridge.NodeList;
import org.mmbase.bridge.NodeManager;
@@ -32,7 +34,9 @@
public abstract class AbstractNodeAction extends Action {
private Map<String, String> fields = new HashMap<String, String>();
- private Map<String, DateTime> dateFields = new HashMap<String,
DateTime>();
+// private Map<String, DateTime> dateFields = new HashMap<String,
DateTime>();
+ private Map<String, DateTime> dateFields =
+ MapUtils.lazyMap(new HashMap<String, DateTime>(),
FactoryUtils.instantiateFactory(DateTime.class));
private String id = null;
private MultipartFile file = null;
private static org.mmbase.util.logging.Logger log =
Logging.getLoggerInstance(AbstractNodeAction.class);
@@ -131,25 +135,6 @@
}
/**
- * Check if all the fields set for this node action actually exist in
the nodemanager.
- */
- private void checkBasicFields() {
- for (String field : fields.keySet()) {
- if (!node.getNodeManager().hasField(field)) {
- log.warn(String.format(
- "You try to set field '%s' on a
node of type '%s', but the nodetype does not have this field",
- field,
node.getNodeManager().getName()));
- addGlobalError("error.field.unknown", new
String[] { field, this.getClass().getName(),
- node.getNodeManager().getName()
});
- }
- }
- }
-
- /*
- * these are the template methods
- */
-
- /**
* This template method is called to obtain the node for this action.
it is the responsibility of the implementation
* of this method to set a global error (using addGlobalError) when
something goes wrong. In that case the action
* stops.
@@ -271,6 +256,21 @@
protected abstract void createCacheFlushHints();
/**
+ * Check if all the fields set for this node action actually exist in
the nodemanager.
+ */
+ private void checkBasicFields() {
+ for (String field : fields.keySet()) {
+ if (!node.getNodeManager().hasField(field)) {
+ log.warn(String.format(
+ "You try to set field '%s' on a
node of type '%s', but the nodetype does not have this field",
+ field,
node.getNodeManager().getName()));
+ addGlobalError("error.field.unknown", new
String[] { field, this.getClass().getName(),
+ node.getNodeManager().getName()
});
+ }
+ }
+ }
+
+ /**
* Set the fields, dateFields and file on the given node. Errors are
created when fields are not part of the present
* nodes manager. TODO: use datatypes to validate the input. TODO: a
builder can have more than one binary field
* with another name than 'handle'
Index: SortRelationAction.java
===================================================================
RCS file:
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action/SortRelationAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- SortRelationAction.java 8 Sep 2008 16:52:10 -0000 1.2
+++ SortRelationAction.java 22 Sep 2008 14:33:46 -0000 1.3
@@ -63,6 +63,7 @@
if(!relationManager.hasField(sortField)){
addGlobalError("error.property.illegal.sortfield", new
String[]{sortField, this.getClass().getName(), role});
}
+ log.debug(String.format("preconditions met for action %s.
errors found: %s", this.getClass().getName(), hasErrors()));
if(!hasErrors()){
PathBuilder pathBuilder = createPathBuilder();
@@ -85,11 +86,11 @@
addGlobalError("error.relation.notfound",
new String[]{role, "" +
sourceNode.getNumber(), "" + destinationNode.getNumber()});
return null;
- }else{
- Node result =
transaction.getRelation(nl.getNode(0).getStringValue(pathBuilder.getStep(1) +
".number"));
- log.debug("node found for RelationSortAction:
"+result);
- return result;
}
+ Node result =
transaction.getNode(nl.getNode(0).getStringValue(pathBuilder.getStep(1) +
".number"));
+ log.debug("node found for SortRelationAction: " +
result);
+ return result;
+
}
return null;
}
@@ -171,13 +172,16 @@
nodeToSwapWith.getIntValue(sortField)));
log.debug(String.format("node number is %s and
swap node number is %s", getNode().getNumber(), nodeToSwapWith.getNumber()));
+ log.debug(String.format("node pos is %s and
swap pos is %s", getNode().getStringValue("pos"),
nodeToSwapWith.getStringValue("pos")));
// now let the two nodes swap position
int p1 = getNode().getIntValue(sortField);
int p2 = nodeToSwapWith.getIntValue(sortField);
+ log.debug("swapping the position values");
getNode().setIntValue(sortField, p2);
nodeToSwapWith.setIntValue(sortField, p1);
+ log.debug(String.format("after: node pos is %s
and swap pos is %s", getNode().getStringValue("pos"),
nodeToSwapWith.getStringValue("pos")));
// a cacheflush hint needs to be created for
this action.
doSetCachflushHint();
@@ -257,7 +261,6 @@
if(oldValue != lowest){
log.debug("setting node
"+relationNode.getNumber()+" to value "+lowest);
relationNode.setIntValue(sortField,
lowest);
- relationNode.commit();
}else{
log.debug("node
"+relationNode.getNumber()+" has the right pos value: "+lowest+". skip it");
Index: DeleteNodeAction.java
===================================================================
RCS file:
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/action/DeleteNodeAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- DeleteNodeAction.java 8 Sep 2008 16:52:10 -0000 1.2
+++ DeleteNodeAction.java 22 Sep 2008 14:33:46 -0000 1.3
@@ -6,6 +6,7 @@
import org.mmbase.applications.vprowizards.spring.GlobalError;
import org.mmbase.applications.vprowizards.spring.ResultContainer;
import org.mmbase.bridge.Node;
+import org.mmbase.bridge.NotFoundException;
import org.mmbase.util.logging.Logger;
import org.mmbase.util.logging.Logging;
@@ -31,6 +32,8 @@
@Override
public void process(ResultContainer resultContainer) {
if(StringUtils.isBlank(nodenr)){
+ //this can't really happen, becouse the only way of
instantiating a delete node action, is by setting
+ //this property. there are no others!
resultContainer.getGlobalErrors().add(
new GlobalError(
"error.property.required",
@@ -40,7 +43,11 @@
);
}else{
log.debug("deleting node with number "+nodenr);
+ try{
resultContainer.getTransaction().getNode(nodenr).delete(true);
+ }catch (NotFoundException e){
+ resultContainer.addGlobalError(new
GlobalError("error.node.notfound", new String[]{""+nodenr},
resultContainer.getLocale()));
+ }
}
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs