diff gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java @ 610:6484464d2059

Changed the mechanism for searching for specific parameter collections. gnv-artifacts/trunk@676 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 11 Feb 2010 11:58:39 +0000
parents cef17cc90fd0
children 93978859fa9e
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java	Thu Feb 11 08:54:58 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java	Thu Feb 11 11:58:39 2010 +0000
@@ -19,12 +19,18 @@
 
 import de.intevation.gnv.geobackend.base.query.exception.QueryException;
 
+import de.intevation.gnv.state.describedata.MinMaxDescribeData;
+
 import de.intevation.gnv.state.exception.StateException;
 
+import de.intevation.gnv.utils.InputValidator;
+
 import java.io.OutputStream;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Locale;
 
 import org.apache.log4j.Logger;
@@ -170,7 +176,7 @@
         log.debug("OutputStateBase.getChartResult");
         Object result = null;
         if (CacheFactory.getInstance().isInitialized()) {
-            String key = uuid + super.getID();
+            String key = "chart_" + getHash();
             log.debug("Hash for Queryelements: " + key);
             net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key);
             if (value != null) {
@@ -190,7 +196,7 @@
         log.debug("Fetch chart [" + uuid + "] from cache");
         CacheFactory cacheFactory = CacheFactory.getInstance();
         if (cacheFactory.isInitialized()) {
-            String key = "chart_" + uuid + super.getID();
+            String key = "chart_" + getHash();
             net.sf.ehcache.Element object = cacheFactory.getCache().get(key);
 
             if (object != null) {
@@ -238,7 +244,7 @@
     protected void removeChartResult(String uuid) {
         log.debug("OutputStateBase.getChartResult");
         if (CacheFactory.getInstance().isInitialized()) {
-            String key = uuid + super.getID();
+            String key = "chart_" + getHash();
             log.debug("Hash for Queryelements: " + key);
             net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key);
             if (value != null) {
@@ -252,7 +258,7 @@
 
         CacheFactory cacheFactory = CacheFactory.getInstance();
         if (cacheFactory.isInitialized()) {
-            String key = "chart_" + uuid + super.getID();
+            String key = "chart_" + getHash();
             net.sf.ehcache.Element object = cacheFactory.getCache().get(key);
             if (object != null)
                 cacheFactory.getCache().remove(key);
@@ -263,11 +269,19 @@
         log.debug("Prufify chart [" + uuid + "]");
         CacheFactory cacheFactory = CacheFactory.getInstance();
         if (cacheFactory.isInitialized()) {
-            String key = "chart_" + uuid + getID();
+            String key = "chart_" + getHash();
             cacheFactory.getCache().put(new net.sf.ehcache.Element(key, chart));
         }
     }
 
+
+    @Override
+    public void feed(Collection<InputData> inputData, String uuid)
+    throws StateException
+    {
+        putInputData(inputData, uuid);
+    }
+
     /**
      * @see de.intevation.gnv.state.StateBase#putInputData(java.util.Collection, java.lang.String)
      */
@@ -278,7 +292,94 @@
         log.debug("OutputStateBase.putInputData");
         this.removeChartResult(uuid);
         this.removeChart(uuid);
-        super.putInputData(inputData, uuid);
+
+        if (inputData != null) {
+            Iterator<InputData> it = inputData.iterator();
+            InputValidator iv = new InputValidator();
+            while (it.hasNext()) {
+                InputData tmpItem     = it.next();
+                Object    tmpObj      = tmpItem.getObject();
+                InputValue inputValue = this.inputValues.get(tmpItem.getName());
+                if (inputValue != null) {
+                    if (this.inputData == null) {
+                        this.inputData = new HashMap<String, InputData>(
+                                inputData.size());
+                    }
+
+                    boolean valid = iv.isInputValid(tmpItem.getValue(),
+                            inputValue.getType());
+                    if (valid) {
+                        if (tmpItem.getName().equals(MINVALUEFIELDNAME)){
+                            String minValue = tmpItem.getValue();
+                            String maxValue = getInputValue4ID(inputData, MAXVALUEFIELDNAME);
+                            valid = iv.isInputValid(maxValue,inputValue.getType());
+                            if (!valid){
+                                String errMsg = "Wrong input for " + tmpItem.getValue()
+                                                + " is not an " + inputValue.getType()
+                                                + " Value.";
+                                log.warn(errMsg);
+                                throw new StateException(errMsg);
+                            }
+
+                            valid = iv.isInputValid(minValue,
+                                    maxValue,
+                                    inputValue.getType());
+                            if (!valid){
+                                String errMsg = "MaxValue-Input is less than MinValue-Input ";
+                                log.warn(errMsg);
+                                throw new StateException(errMsg);
+                            }
+                        }else if (tmpItem.getName().equals(MAXVALUEFIELDNAME)){
+                            String minValue = getInputValue4ID(inputData, MINVALUEFIELDNAME);
+                            String maxValue = tmpItem.getValue();
+                            valid = iv.isInputValid(minValue,inputValue.getType());
+                            if (!valid){
+                                String errMsg = "Wrong input for " + tmpItem.getValue()
+                                                + " is not an " + inputValue.getType()
+                                                + " Value.";
+                                log.warn(errMsg);
+                                throw new StateException(errMsg);
+                            }
+
+                            valid = iv.isInputValid(minValue,
+                                                    maxValue,
+                                                    inputValue.getType());
+                            if (!valid){
+                                String errMsg = "MaxValue-Input is less than MinValue-Input ";
+                                log.warn(errMsg);
+                                throw new StateException(errMsg);
+                            }
+                        }
+                        this.inputData.put(tmpItem.getName(), tmpItem);
+                    } else {
+                        String errMsg = "Wrong input for " + tmpItem.getValue()
+                                        + " is not an " + inputValue.getType()
+                                        + " Value.";
+                        log.warn(errMsg);
+                        throw new StateException(errMsg);
+                    }
+
+                } 
+                else if (tmpObj != null && tmpObj instanceof MinMaxDescribeData) {
+                    MinMaxDescribeData data = (MinMaxDescribeData) tmpObj;
+                    if (this.inputData == null) {
+                        this.inputData = new HashMap<String, InputData>(inputData.size());
+                    }
+                    this.inputData.put(tmpItem.getName(), tmpItem);
+                    this.inputData.put("minvalue", new DefaultInputData("minvalue", (String) data.getMinValue()));
+                    this.inputData.put("maxvalue", new DefaultInputData("maxvalue", (String) data.getMaxValue()));
+                }
+                else {
+                
+                    String errMsg = "No Inputvalue given for Inputdata "
+                                    + tmpItem.getName();
+                    log.warn(errMsg + "Value will be ignored");
+
+                }
+            }
+        } else {
+            log.warn("No Inputdata given");
+        }
     }
 
     public void out(String outputMode, Collection<InputData> inputData,

http://dive4elements.wald.intevation.org