changeset 612:e86d37008fd1

Added new Transition and State for using the PreSettingsValue for the decision if a Transition could be used and the usage of PreSettings as InputValues. gnv-artifacts/trunk@678 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 12 Feb 2010 09:11:49 +0000
parents 4b818f13e20a
children f20b65c1ebf3
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/state/PreSettingsTransferState.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/transition/PresettingsValueCompareTransition.java
diffstat 5 files changed, 179 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Thu Feb 11 14:10:15 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Fri Feb 12 09:11:49 2010 +0000
@@ -1,3 +1,27 @@
+2010-02-12  Tim Englich  <tim.englich@intevation.de>
+
+	* src/main/java/de/intevation/gnv/state/PreSettingsTransferState.java: 
+	  This new State ist Implemented for the Case that Values of the PreSettings 
+	  has to be used instead of InputValues. This States will look into the 
+	  Presettings and put Values identified by the configurable Names into the 
+	  InputData-Collection.
+	  For the Configuration you can insert the following XML-Element into the 
+	  Configuration of a State.
+	  <presettings-transfer presetting="geometry" inputvalue="mesh_coordinate"/>
+	
+	* src/main/java/de/intevation/gnv/state/StateBase.java (getPreSettings),
+	  src/main/java/de/intevation/gnv/state/State.java (getPreSettings): 
+	  Added a getter-method for the PreSettings that are set at the State.
+	  Using this way e.g the PresettingsValueCompareTransition can reach the 
+	  Settings an can evaluate them.
+	  
+	* src/main/java/de/intevation/gnv/transition/PresettingsValueCompareTransition.java (operator): 
+	  This transition will have a look at the Values which where ste during the 
+	  instantiation of an Artifact. If a defined Value is given an the Value is 
+	  Equal to the configured Value using the configured Operator the Transition 
+	  to the configured State could be used. Otherwise the Transition could not
+	  be used.
+
 2010-02-11  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	* src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/PreSettingsTransferState.java	Fri Feb 12 09:11:49 2010 +0000
@@ -0,0 +1,75 @@
+/**
+ *
+ */
+package de.intevation.gnv.state;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import de.intevation.artifactdatabase.Config;
+import de.intevation.artifacts.CallContext;
+import de.intevation.gnv.state.exception.StateException;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class PreSettingsTransferState extends DefaultState {
+
+    /**
+     * The UID of this Class
+     */
+    private static final long serialVersionUID = 573381812690806922L;
+
+    private String transferPreSettingsName = null;
+    
+    private String transferInputDataname = null;
+    /**
+     * Constructor
+     */
+    public PreSettingsTransferState() {
+        super();
+    }
+
+    /**
+     * @see de.intevation.gnv.state.StateBase#initialize(java.lang.String, de.intevation.artifacts.CallContext)
+     */
+    @Override
+    public void initialize(String uuid, CallContext context)
+                                                            throws StateException {
+        Map<String, InputData> preSettings = this.getPreSettings();
+        if (preSettings != null){
+            InputData ip = preSettings.get(transferPreSettingsName);
+            if (ip != null){
+                Collection<InputData> localInputdata = new ArrayList<InputData>(1);
+                localInputdata.add(new DefaultInputData(transferInputDataname,
+                                                        ip.getValue()));
+                this.putInputData(localInputdata, uuid);
+            }
+        }
+        
+        super.initialize(uuid, context);
+    }
+
+    /**
+     * @see de.intevation.gnv.state.StateBase#setup(org.w3c.dom.Node)
+     */
+    @Override
+    public void setup(Node configuration) {
+        
+        Element preSettingsNode = (Element)Config.getNodeXPath(configuration,
+                                                         "presettings-transfer");
+        if (preSettingsNode != null){
+            this.transferPreSettingsName = preSettingsNode.getAttribute("presetting");
+            this.transferPreSettingsName = preSettingsNode.getAttribute("inputvalue");
+        }
+        super.setup(configuration);
+    }
+    
+    
+
+}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java	Thu Feb 11 14:10:15 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java	Fri Feb 12 09:11:49 2010 +0000
@@ -60,4 +60,6 @@
     public void endOfLife(Object globalContext);
 
     public void setPreSettings(Map<String,InputData> preSettings);
+
+    public Map<String,InputData> getPreSettings();
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Thu Feb 11 14:10:15 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Fri Feb 12 09:11:49 2010 +0000
@@ -365,6 +365,12 @@
     public void setPreSettings(Map<String, InputData> preSettings) {
         this.preSettings = preSettings;
     }
+    
+    
+
+    public Map<String, InputData> getPreSettings() {
+        return this.preSettings;
+    }
 
     protected String getInputValue4ID(Collection<InputData> inputData, String inputName){
         Iterator<InputData> it = inputData.iterator();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/PresettingsValueCompareTransition.java	Fri Feb 12 09:11:49 2010 +0000
@@ -0,0 +1,72 @@
+/**
+ *
+ */
+package de.intevation.gnv.transition;
+
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Node;
+
+import de.intevation.artifactdatabase.Config;
+import de.intevation.gnv.state.InputData;
+import de.intevation.gnv.state.State;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class PresettingsValueCompareTransition extends TransitionBase {
+
+    /**
+     * the logger, used to log exceptions and additonaly information
+     */
+    private static Logger log = Logger.getLogger(PresettingsValueCompareTransition.class);
+    
+    private String dataName = null;
+    private String dataValue = null;
+    private String operator = null;
+    
+    /**
+     * The UID of this Class.
+     */
+    private static final long serialVersionUID = -7846722158776823205L;
+
+    /**
+     * Constructor
+     */
+    public PresettingsValueCompareTransition() {
+        super();
+    }
+
+    /**
+     * @see de.intevation.gnv.transition.Transition#isValid(de.intevation.gnv.state.State)
+     */
+    public boolean isValid(State state) {
+        Map<String, InputData> preSettings = state.getPreSettings();
+        if (preSettings != null){
+            boolean dataAvailable = preSettings.containsKey(dataName);
+            if (dataAvailable){
+                if (operator.equals("equal")){
+                    return preSettings.get(dataName).getValue().startsWith(dataValue);
+                }else if (operator.equals("notequal")){
+                    return !preSettings.get(dataName).getValue().startsWith(dataValue);
+                }
+            }
+        }
+        if (operator.equals("notequal")){
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public void setup(Node configuration) {
+        super.setup(configuration);
+        this.dataName = Config.getStringXPath(configuration,"condition/@inputvalue");
+        this.dataValue = Config.getStringXPath(configuration,"condition/@value");
+        this.operator = Config.getStringXPath(configuration,"condition/@operator");
+    }
+    
+
+}

http://dive4elements.wald.intevation.org