diff gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java @ 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 b7bb66440cc8
children c0504976e606
line wrap: on
line diff
--- 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,

http://dive4elements.wald.intevation.org