changeset 61:5f47881f7c97

Implementation of the MIN- / MAX-Value Representation gnv-artifacts/trunk@44 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Wed, 09 Sep 2009 09:29:39 +0000
parents eed1baaeb481
children 9f57053d0384
files gnv-artifacts/Changelog gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/MinMaxTransition.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/DefaultMinMaxDescribeData.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/DescribeData.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/MinMaxDescribeData.java
diffstat 7 files changed, 229 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/Changelog	Tue Sep 08 16:24:34 2009 +0000
+++ b/gnv-artifacts/Changelog	Wed Sep 09 09:29:39 2009 +0000
@@ -1,3 +1,20 @@
+2009-09-09  Tim Englich  <tim.englich@intevation.de>
+
+    * src/main/java/de/intevation/gnv/transition/describedata/DefaultMinMaxDescribeData.java , 
+    * src/main/java/de/intevation/gnv/transition/describedata/MinMaxDescribeData.java,
+    * src/main/java/de/intevation/gnv/transition/describedata/DescribeData.java Added:
+      Interface Structure and Defaultimplementation for Representing DescribeData of an
+      Transition added. In this Way we are able to switch between different Renderingmethods
+      for descibe. 
+    * src/main/java/de/intevation/gnv/transition/MinMaxTransition.java Added:
+     Added MinMaxTransition for representing Min-/Max-Value Results in a Tansition
+    * src/main/java/de/intevation/gnv/transition/TransitionBase.java Edited:
+     Integrated Min- / MAX-Value Support for Describe. Also done some Refactoring Work
+     for easy creating Extensions of this Class. 
+    * src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Edited:
+      Userinterface Informations were integrated in the wrong Method. Now the
+      Informations are put into the ui-Node 
+
 2009-09-08  Tim Englich  <tim.englich@intevation.de>
 
     * src/test/ressources/timeseries/timeseries_step_01_advance.xml Edited, 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Tue Sep 08 16:24:34 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Wed Sep 09 09:29:39 2009 +0000
@@ -251,7 +251,9 @@
     protected void createUserInterface(Element parent, Document document){
         Element uiNode = createElement(document,"ui");
         
-        // TODO mit leben füllen.
+        if (this.current != null){
+            this.current.describe(document, uiNode);
+        }
         
         parent.appendChild(uiNode);
     }
@@ -259,9 +261,7 @@
     protected void createOutputs(Element parent, Document document){
         Element outputsNode = createElement(document,"outputs");
         
-        if (this.current != null){
-            this.current.describe(document, outputsNode);
-        }
+        // TODO_ Mit Leben füllen.
         
         parent.appendChild(outputsNode);
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/MinMaxTransition.java	Wed Sep 09 09:29:39 2009 +0000
@@ -0,0 +1,63 @@
+/**
+ *
+ */
+package de.intevation.gnv.transition;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import de.intevation.gnv.geobackend.base.Result;
+import de.intevation.gnv.transition.describedata.DefaultMinMaxDescribeData;
+import de.intevation.gnv.transition.describedata.DescribeData;
+import de.intevation.gnv.transition.describedata.MinMaxDescribeData;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class MinMaxTransition extends TransitionBase {
+    
+    /**
+     * the logger, used to log exceptions and additonaly information
+     */
+    private static Logger log = Logger.getLogger(MinMaxTransition.class);
+    
+    /**
+     * Constructor
+     */
+    public MinMaxTransition() {
+        super();
+    }
+    /**
+     * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection)
+     */
+    @Override
+    protected void purifyResult(Collection<Result> result) {
+        log.debug("MinMaxTransition.purifyResult");
+        if (this.descibeData == null){
+            this.descibeData = new ArrayList<Object>();
+        }
+        if (result != null && result.size() == 1){
+            Result value = result.iterator().next();
+            DescribeData describeData = new DefaultMinMaxDescribeData(value.getObject("MIN"), value.getObject("MAX"));
+            log.debug(describeData.toString());
+            this.descibeData.add(describeData);
+        }else{
+            log.warn("Result cannot be handled as MinMax Resultset");
+        }
+        
+    }
+
+    /**
+     * @see de.intevation.gnv.transition.Transition#validate()
+     */
+    public boolean validate() {
+        // TODO: Implement ME
+        return true;
+    }
+
+}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Tue Sep 08 16:24:34 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Wed Sep 09 09:29:39 2009 +0000
@@ -5,6 +5,8 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -21,6 +23,8 @@
 import de.intevation.gnv.geobackend.base.query.QueryExecutor;
 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
 import de.intevation.gnv.geobackend.base.query.exception.QueryException;
+import de.intevation.gnv.geobackend.util.DateUtils;
+import de.intevation.gnv.transition.describedata.MinMaxDescribeData;
 import de.intevation.gnv.transition.exception.TransitionException;
 
 /**
@@ -54,7 +58,8 @@
     
     private Map<String,InputData> inputData = null;
     
-    private Collection<Object> descibeData = null;
+    protected Collection<Object> descibeData = null;
+    
     /**
      * Constructor
      */
@@ -200,15 +205,22 @@
             }
             QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor();
             Collection<Result> result = queryExecutor.executeQuery(this.queryID, filterValues);
-            if (this.descibeData == null){
-                this.descibeData = new ArrayList<Object>();
-            }
-            this.descibeData.add(result);
+            this.purifyResult(result);
         } catch (QueryException e) {
             log.error(e,e);
             throw new TransitionException(e);
         }
     }
+
+    /**
+     * @param result
+     */
+    protected void purifyResult(Collection<Result> result) {
+        if (this.descibeData == null){
+            this.descibeData = new ArrayList<Object>();
+        }
+        this.descibeData.add(result);
+    }
     
     /**
      * @see de.intevation.gnv.transition.Transition#describe(org.w3c.dom.Document, org.w3c.dom.Node)
@@ -218,43 +230,79 @@
         if(this.descibeData != null){
             Iterator<Object> it = this.descibeData.iterator();
             while (it.hasNext()){
-                Element selectNode = this.createXFormElement(document,"select");
-                // TODO: HACK:
-                // BESSERE LÖSUNG FINDEN
-                Object[] names = this.inputValueNames.toArray();
-                String name = names[names.length-1].toString();
-                
-                selectNode.setAttribute("ref", name);
-                
-                Element lableNode = this.createXFormElement(document, "label");
-                lableNode.setTextContent(name);
-                Element choiceNode = this.createXFormElement(document, "choices");
-                
-                
                 Object o = it.next();
                 if (o instanceof Collection<?>){
+                    Element selectNode = this.createXFormElement(document,"select");
+                    // TODO: HACK:
+                    // BESSERE LÖSUNG FINDEN
+                    Object[] names = this.inputValueNames.toArray();
+                    String name = names[names.length-1].toString();
+                    
+                    selectNode.setAttribute("ref", name);
+                    
+                    Element lableNode = this.createXFormElement(document, "label");
+                    lableNode.setTextContent(name);
+                    Element choiceNode = this.createXFormElement(document, "choices");
+                    
                     Collection<Result> values = (Collection)o;
                     Iterator<Result> resultIt = values.iterator();
                     while (resultIt.hasNext()){
                         Result result = resultIt.next();
                         Element itemNode = this.createXFormElement(document, "item");
-                        String lableName = result.getResultDescriptor().getColumnName(1);
-                        String valueName = result.getResultDescriptor().getColumnName(0);
+                        
                         
                         Element choiceLableNode = this.createXFormElement(document, "label");
-                        choiceLableNode.setTextContent(result.getString(lableName));
+                        choiceLableNode.setTextContent(result.getString("VALUE"));
                         itemNode.appendChild(choiceLableNode);
                         
                         Element choicValueNode = this.createXFormElement(document, "value");
-                        choicValueNode.setTextContent(result.getString(valueName));
+                        choicValueNode.setTextContent(result.getString("KEY"));
                         itemNode.appendChild(choicValueNode);
                         
                         choiceNode.appendChild(itemNode);
                     }
+                    selectNode.appendChild(lableNode);
+                    selectNode.appendChild(choiceNode);
+                    rootNode.appendChild(selectNode);
+                }else if (o instanceof MinMaxDescribeData){
+                    MinMaxDescribeData descibeData = (MinMaxDescribeData)o;
+                    Object min = descibeData.getMinValue();
+                    Object max = descibeData.getMaxValue();
+                    if (min instanceof GregorianCalendar){
+                        Date d = ((GregorianCalendar)min).getTime();
+                        min = DateUtils.getPatternedDateGerm(d);
+                    }
+                    
+                    if (max instanceof GregorianCalendar){
+                        Date d = ((GregorianCalendar)max).getTime();
+                        max = DateUtils.getPatternedDateGerm(d);
+                    }
+                    
+                    Element inputMinNode = this.createXFormElement(document, "input");
+                    inputMinNode.setAttribute("ref", "minvalue");
+                    Element inputMinLableNode = this.createXFormElement(document, "label");
+                    inputMinLableNode.setTextContent("minvalue");
+                    inputMinNode.appendChild(inputMinLableNode);
+                    
+                    Element inputMinValueNode = this.createXFormElement(document, "value");
+                    inputMinValueNode.setTextContent(min.toString());
+                    inputMinNode.appendChild(inputMinValueNode);
+                    
+                    Element inputMaxNode = this.createXFormElement(document, "input");
+                    inputMaxNode.setAttribute("ref", "maxvalue");
+                    Element inputMaxLableNode = this.createXFormElement(document, "label");
+                    inputMaxLableNode.setTextContent("maxvalue");
+                    inputMaxNode.appendChild(inputMaxLableNode);
+                    
+                    Element inputMaxValueNode = this.createXFormElement(document, "value");
+                    inputMaxValueNode.setTextContent(max.toString());
+                    inputMaxNode.appendChild(inputMaxValueNode);
+                    
+                    rootNode.appendChild(inputMinNode);
+                    rootNode.appendChild(inputMaxNode);
+                    
                 }
-                selectNode.appendChild(lableNode);
-                selectNode.appendChild(choiceNode);
-                rootNode.appendChild(selectNode);
+
             }
         }
        
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/DefaultMinMaxDescribeData.java	Wed Sep 09 09:29:39 2009 +0000
@@ -0,0 +1,46 @@
+/**
+ *
+ */
+package de.intevation.gnv.transition.describedata;
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class DefaultMinMaxDescribeData implements MinMaxDescribeData {
+
+    private Object minValue = null;
+    
+    private Object maxValue = null;
+    /**
+     * Constructor
+     */
+    public DefaultMinMaxDescribeData( Object minValue, Object maxValue) {
+        super();
+        this.minValue = minValue;
+        this.maxValue = maxValue;
+    }
+
+    /**
+     * @see de.intevation.gnv.transition.describedata.MinMaxDescribeData#getMaxValue()
+     */
+    public Object getMaxValue() {
+        return this.maxValue;
+    }
+
+    /**
+     * @see de.intevation.gnv.transition.describedata.MinMaxDescribeData#getMinValue()
+     */
+    public Object getMinValue() {
+        return this.minValue;
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return "MIN: "+this.minValue.toString()+" ; MAX: "+this.maxValue.toString();
+    }
+    
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/DescribeData.java	Wed Sep 09 09:29:39 2009 +0000
@@ -0,0 +1,12 @@
+/**
+ *
+ */
+package de.intevation.gnv.transition.describedata;
+/**
+ * Markerinterface
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public interface DescribeData {
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/MinMaxDescribeData.java	Wed Sep 09 09:29:39 2009 +0000
@@ -0,0 +1,14 @@
+/**
+ *
+ */
+package de.intevation.gnv.transition.describedata;
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public interface MinMaxDescribeData extends DescribeData {
+    
+    public Object getMinValue();
+    public Object getMaxValue();
+
+}

http://dive4elements.wald.intevation.org