changeset 473:a6a33ef35809

Added support to step back to previous states. Add state names to xform nodes in describe document and append old targets to list of reachable targets. gnv-artifacts/trunk@539 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 13 Jan 2010 23:10:56 +0000
parents d6a100d5f74a
children ab29e4ff2fda
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/SingleInputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultKeyValueDescribeData.java gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultMinMaxDescribeData.java gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultSingleValueDescribeData.java gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/KeyValueDescibeData.java gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/MinMaxDescribeData.java gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/SingleValueDescribeData.java
diffstat 12 files changed, 184 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Wed Jan 13 18:58:26 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Wed Jan 13 23:10:56 2010 +0000
@@ -1,3 +1,38 @@
+2010-01-13  Ingo Weinzierl <ingo_weinzierl@web.de>
+
+	* src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java: 'advance'
+	  method will now consider old states. We reset input data of target state
+	  and clean cache from 'future data' before stepping back to previous
+	  states.
+
+	  TODO: Refactor caching mechanism which should take care of different 
+	  states' hash values to be able to use the cache more efficiently.
+
+	* src/main/java/de/intevation/gnv/state/State.java: Added method to return
+	  map which stores input data of the current state.
+
+	* src/main/java/de/intevation/gnv/state/describedata/MinMaxDescribeData.java,
+	  src/main/java/de/intevation/gnv/state/describedata/SingleValueDescribeData.java,
+	  src/main/java/de/intevation/gnv/state/describedata/KeyValueDescibeData.java
+	  src/main/java/de/intevation/gnv/state/describedata/DefaultSingleValueDescribeData.java,
+	  src/main/java/de/intevation/gnv/state/describedata/DefaultMinMaxDescribeData.java,
+	  src/main/java/de/intevation/gnv/state/describedata/DefaultKeyValueDescribeData.java:
+	  Add current state's name when initializing new objects of these classes.
+	  The name of a state is added as attribute to a node when creating the 
+	  describe-document. The xsl transformer will read this attribute and create
+	  a link which allows the user to step back to previous states.
+	
+	* src/main/java/de/intevation/gnv/state/SingleInputState.java,
+	  src/main/java/de/intevation/gnv/state/MinMaxState.java,
+	  src/main/java/de/intevation/gnv/state/StateBase.java:
+	  - Add state name when creating objects to store input data.
+	  - Use XMLUtils.ElementCreator to write namespace aware xml elements.
+	  - Add state names as attributes to xform elements.
+	  - Append old states to list of reachable targets in describe-document.
+	  - Remove data from cache which belong to future states after stepping
+	    back to a previous state.
+	  - Remove input data of current state after stepping back.
+
 2010-01-12	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* doc/conf/conf.xml,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Wed Jan 13 18:58:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Wed Jan 13 23:10:56 2010 +0000
@@ -9,10 +9,13 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import javax.xml.xpath.XPathConstants;
 
+import net.sf.ehcache.Cache;
+
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -27,6 +30,7 @@
 import de.intevation.artifacts.ArtifactNamespaceContext;
 import de.intevation.artifacts.CallContext;
 import de.intevation.artifacts.CallMeta;
+import de.intevation.gnv.artifacts.cache.CacheFactory;
 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
 import de.intevation.gnv.artifacts.fis.FISSelectArtifact;
 import de.intevation.gnv.artifacts.fis.product.Product;
@@ -37,6 +41,7 @@
 import de.intevation.gnv.state.OutputMode;
 import de.intevation.gnv.state.OutputState;
 import de.intevation.gnv.state.State;
+import de.intevation.gnv.state.StateBase;
 import de.intevation.gnv.state.StateFactory;
 import de.intevation.gnv.state.exception.StateException;
 import de.intevation.gnv.transition.Transition;
@@ -166,7 +171,13 @@
 
             // step backward
             else if((next = getPreviousState(current, targetState)) != null) {
+
+                // reset input data
                 resetFutureStates(current, targetState);
+
+                // remove data from future states from cache
+                resetDescribeData(current, identifier, targetState);
+                
                 current = next;
 
                 result = createReport(
@@ -247,6 +258,27 @@
         }
     }
 
+    public void resetDescribeData(State state, String uuid, String target) {
+        CacheFactory factory = CacheFactory.getInstance();
+        
+        if (factory.isInitialized()) {
+            Cache  cache = factory.getCache();
+            String key   = uuid + StateBase.DESCRIBEDATAKEY;
+
+            net.sf.ehcache.Element value = cache.get(key);
+            if (value == null)
+                return;
+
+            List data = (List) value.getObjectValue();
+            while(!target.equals(state.getID())) {
+                data.remove(data.size()-1);
+                state = state.getParent();
+            }
+
+            cache.put(new net.sf.ehcache.Element(key, data));
+        }
+    }
+
 
     protected void resetFutureStates(State current, String name) {
         if (current == null) {
@@ -264,7 +296,6 @@
 
 
     private boolean isStateCurrentlyReachable(String stateid){
-        log.debug("GNVArtifactBase.isStateCurrentlyReachable "+stateid);
         Iterator<Transition> it = this.transitions.iterator();
         String from = this.current.getID();
         while (it.hasNext()){
@@ -275,7 +306,6 @@
                 }
             }
         }
-        log.debug("State is not reachable.");
         return false;
     }
     
@@ -553,6 +583,8 @@
     ) {
         Element stateNode = creator.create("reachable-states");
         if (this.current != null) {
+
+            // add future states
             Iterator<Transition> transitions = this.transitions.iterator();
             while (transitions.hasNext()) {
                 Transition tmpTransition = transitions.next();
@@ -560,7 +592,6 @@
                     tmpTransition.isValid(this.current)){
                     Element currentNode = creator.create("state");
                     creator.addAttr(currentNode, "name", tmpTransition.getTo());
-                    log.debug("Reachable State: " + tmpTransition.getTo());
                     creator.addAttr(
                         currentNode,
                         "description",
@@ -568,10 +599,34 @@
                     stateNode.appendChild(currentNode);
                 }
             }
+
+
+            // add old states
+            appendOldReachableStates(creator, stateNode, current);
         }
         parent.appendChild(stateNode);
     }
 
+
+    protected void appendOldReachableStates(
+        XMLUtils.ElementCreator creator,
+        Element                 parent,
+        State                   state
+    ) {
+        if (state == null)
+            return;
+
+        while (state != null) {
+            Element currentNode = creator.create("state");
+            creator.addAttr(currentNode, "name", state.getID());
+            creator.addAttr(currentNode, "description", state.getDescription());
+            parent.appendChild(currentNode);
+
+            state = state.getParent();
+        }
+    }
+
+
     protected void createCurrentState(
         XMLUtils.ElementCreator creator,
         Element                 parent,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java	Wed Jan 13 18:58:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java	Wed Jan 13 23:10:56 2010 +0000
@@ -49,9 +49,11 @@
         if (result != null && result.size() == 1) {
             
             Result value = result.iterator().next();
-            DescribeData values = new DefaultMinMaxDescribeData(this.dataName, 
-                                                               value.getObject("MIN"), 
-                                                               value.getObject("MAX"));
+            DescribeData values = new DefaultMinMaxDescribeData(
+                dataName, 
+                value.getObject("MIN"), 
+                value.getObject("MAX"),
+                getID());
             log.debug(values.toString());
             describeData.add(values);
         } else {
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/SingleInputState.java	Wed Jan 13 18:58:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/SingleInputState.java	Wed Jan 13 23:10:56 2010 +0000
@@ -53,7 +53,8 @@
             value = "";
         }
 
-        describeData.add(new DefaultSingleValueDescribeData(this.dataName,value));
+        describeData.add(new DefaultSingleValueDescribeData(
+            this.dataName, value, getID()));
         this.setDescibeData(uuid, describeData);
     }
 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java	Wed Jan 13 18:58:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java	Wed Jan 13 23:10:56 2010 +0000
@@ -5,6 +5,7 @@
 
 import java.io.Serializable;
 import java.util.Collection;
+import java.util.Map;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
@@ -33,6 +34,8 @@
 
     public Collection<InputValue> getRequiredInputValues();
 
+    public Map<String, InputData> inputData();
+
     public void putInputData(Collection<InputData> inputData, 
                              String uuid)throws StateException;
 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Wed Jan 13 18:58:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Wed Jan 13 23:10:56 2010 +0000
@@ -63,7 +63,7 @@
     
     private final static String NODATASELECTIONKEY = "n/n";
     
-    private final static String DESCRIBEDATAKEY = "_DESCRIBEDATA";
+    public final static String DESCRIBEDATAKEY = "_DESCRIBEDATA";
 
     private String id = null;
 
@@ -119,20 +119,12 @@
 
     public void reset(String uuid) {
         
-        // clear input values of the current state
-        Iterator iter = inputValueNames.iterator();
-        while (iter.hasNext()) {
-            String name = (String) iter.next();
-            inputValues.remove(name);
-        }
-
-        // remove data of last state from cache
-        List describeData = getDescibeData(uuid);
-        if (describeData != null && describeData.size() != 0) {
-            describeData.remove(describeData.size()-1);
+        if (parent != null) {
+            inputData = parent.inputData();
         }
     }
 
+
     /**
      * @see de.intevation.gnv.state.State#setup(org.w3c.dom.Node)
      */
@@ -500,13 +492,18 @@
         keyValueDescibeData.setMultiSelect(this.dataMultiSelect);
         
         if (this.dataNoSelect){
-            keyValueDescibeData.add(new DefaultKeyValueDescribeData(NODATASELECTIONKEY, 
-                                                                    "No Selection"));
+            keyValueDescibeData.add(new DefaultKeyValueDescribeData(
+                NODATASELECTIONKEY,
+                "No Selection",
+                getID()
+            ));
         }
+
         boolean initialized = false;
-        int keyPos= 0;
-        int valuePos = 1;
-        String previousKey = null;
+        int     keyPos      = 0;
+        int     valuePos    = 1;
+        String  previousKey = null;
+
         while (rit.hasNext()) {
             Result resultValue = rit.next();
             if (!initialized){
@@ -521,7 +518,7 @@
             // TODO: FIXME: We have to do that because the arcsde does not support a distinct Query on Layers.
             if (previousKey == null || !tmpKey.equals(previousKey)){
                 previousKey = tmpKey;
-                keyValueDescibeData.add(new DefaultKeyValueDescribeData(tmpKey, resultValue.getString(valuePos)));
+                keyValueDescibeData.add(new DefaultKeyValueDescribeData(tmpKey, resultValue.getString(valuePos), getID()));
             }
         }
         return keyValueDescibeData;
@@ -560,11 +557,11 @@
                 Object o = it.next();
                 if ((!it.hasNext() && dataName != null)) {
                     appendToDynamicNode(
-                        xCreator, document, dynamic, callMeta, o);
+                        creator, xCreator, document, dynamic, callMeta, o);
                 }
                 else {
                     appendToStaticNode(
-                        xCreator, document, staticNode, callMeta, o);
+                        creator, xCreator, document, staticNode, callMeta, o);
                 }
             }
         }
@@ -572,6 +569,7 @@
 
 
     protected void appendToStaticNode(
+        XMLUtils.ElementCreator artCreator,
         XMLUtils.ElementCreator creator,
         Document                document,
         Node                    staticNode,
@@ -604,6 +602,10 @@
                 KeyValueDescibeData result = resultIt.next();
 
                 if (result.isSelected()) {
+                    artCreator.addAttr(
+                        selectNode, "state", result.getState(), true
+                    );
+
                     Element itemNode = creator.create("item");
 
                     creator.addAttr(itemNode, "selected", "true");
@@ -625,6 +627,7 @@
         }
         else if (o instanceof MinMaxDescribeData) {
             appendMinMaxDescribeData(
+                artCreator,
                 creator,
                 document,
                 staticNode,
@@ -633,6 +636,7 @@
         }
         else if (o instanceof SingleValueDescribeData) {
             appendSingleValueDescribeData(
+                artCreator,
                 creator,
                 document,
                 staticNode,
@@ -643,6 +647,7 @@
 
 
     protected void appendToDynamicNode(
+        XMLUtils.ElementCreator artCreator,
         XMLUtils.ElementCreator creator,
         Document                document,
         Node                    dynamicNode,
@@ -695,6 +700,7 @@
         }
         else if (o instanceof MinMaxDescribeData) {
             appendMinMaxDescribeData(
+                artCreator,
                 creator,
                 document,
                 dynamicNode,
@@ -703,6 +709,7 @@
         }
         else if (o instanceof SingleValueDescribeData) {
             appendSingleValueDescribeData(
+                artCreator,
                 creator,
                 document,
                 dynamicNode,
@@ -713,6 +720,7 @@
 
 
     protected void appendMinMaxDescribeData(
+        XMLUtils.ElementCreator artCreator,
         XMLUtils.ElementCreator creator,
         Document                document,
         Node                    node,
@@ -733,6 +741,8 @@
         }
 
         Element groupNode = creator.create("group");
+        artCreator.addAttr(groupNode, "state", minMaxDescibeData.getState(), true);
+
         creator.addAttr(groupNode, "ref", minMaxDescibeData.getName());
         Element groupNodeLableNode = creator.create("label");
         groupNodeLableNode.setTextContent(RessourceFactory
@@ -775,8 +785,8 @@
     }
 
 
-
     protected void appendSingleValueDescribeData(
+        XMLUtils.ElementCreator artCreator,
         XMLUtils.ElementCreator creator,
         Document                document,
         Node                    node,
@@ -786,6 +796,7 @@
         SingleValueDescribeData svdb = (SingleValueDescribeData) o;
 
         Element groupNode = creator.create("group");
+        artCreator.addAttr(groupNode, "state", svdb.getState(), true);
         creator.addAttr(groupNode, "ref",  svdb.getName());
 
         Element groupNodeLableNode = creator.create("label");
@@ -839,6 +850,10 @@
         }
     }
 
+    public Map<String, InputData> inputData() {
+        return inputData;
+    }
+
     /**
      * @see de.intevation.gnv.state.State#getInputData()
      */
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultKeyValueDescribeData.java	Wed Jan 13 18:58:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultKeyValueDescribeData.java	Wed Jan 13 23:10:56 2010 +0000
@@ -18,12 +18,19 @@
 
     private String value = null;
 
+    private String state;
+
     private boolean selected = false;
 
     public DefaultKeyValueDescribeData(String key, String value) {
+        this(key, value, null);
+    }
+
+    public DefaultKeyValueDescribeData(String key, String value, String state) {
         super();
         this.key = key;
         this.value = value;
+        this.state = state;
     }
 
     /**
@@ -54,4 +61,9 @@
         this.selected = selected;
     }
 
+
+    public String getState() {
+        return this.state;
+    }
+
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultMinMaxDescribeData.java	Wed Jan 13 18:58:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultMinMaxDescribeData.java	Wed Jan 13 23:10:56 2010 +0000
@@ -20,6 +20,8 @@
     
     private String name = null; 
 
+    private String state = null;
+
     private final static String minName = "minvalue";
 
     private final static String maxName = "maxvalue";
@@ -27,11 +29,17 @@
     /**
      * Constructor
      */
-    public DefaultMinMaxDescribeData(String name, Object minValue, Object maxValue) {
+    public DefaultMinMaxDescribeData(
+        String name,
+        Object minValue,
+        Object maxValue,
+        String state
+    ) {
         super();
         this.name = name;
         this.minValue = minValue;
         this.maxValue = maxValue;
+        this.state    = state;
     }
 
     /**
@@ -89,4 +97,8 @@
        return this.name;
     }
 
+    public String getState() {
+        return this.state;
+    }
+
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultSingleValueDescribeData.java	Wed Jan 13 18:58:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultSingleValueDescribeData.java	Wed Jan 13 23:10:56 2010 +0000
@@ -18,16 +18,27 @@
 
     private String value = null;
 
+    private String state = null;
+
+    public DefaultSingleValueDescribeData(String name, String value) {
+        this(name, value, null);
+    }
+
     /**
      * Constructor
      * 
      * @param name
      * @param value
      */
-    public DefaultSingleValueDescribeData(String name, String value) {
+    public DefaultSingleValueDescribeData(
+        String name,
+        String value,
+        String state
+    ) {
         super();
         this.name = name;
         this.value = value;
+        this.state = state;
     }
 
     /**
@@ -48,4 +59,7 @@
         this.value = value;
     }
 
+    public String getState() {
+        return this.state;
+    }
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/KeyValueDescibeData.java	Wed Jan 13 18:58:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/KeyValueDescibeData.java	Wed Jan 13 23:10:56 2010 +0000
@@ -15,6 +15,8 @@
 
     public String getValue();
 
+    public String getState();
+
     public boolean isSelected();
 
     public void setSelected(boolean selected);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/MinMaxDescribeData.java	Wed Jan 13 18:58:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/MinMaxDescribeData.java	Wed Jan 13 23:10:56 2010 +0000
@@ -23,4 +23,5 @@
 
     public String getMaxName();
 
+    public String getState();
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/SingleValueDescribeData.java	Wed Jan 13 18:58:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/SingleValueDescribeData.java	Wed Jan 13 23:10:56 2010 +0000
@@ -14,4 +14,6 @@
     public String getValue();
     
     public void setValue(String value);
+
+    public String getState();
 }

http://dive4elements.wald.intevation.org