changeset 238:a157c6042cb4

ODV-export for timeseries completed. gnv-artifacts/trunk@306 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 09 Nov 2009 13:48:50 +0000
parents 56dcedc4a96c
children 75da91eca29f
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/exports/SimpleOdvDataCollector.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java
diffstat 3 files changed, 96 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Mon Nov 09 13:11:33 2009 +0000
+++ b/gnv-artifacts/ChangeLog	Mon Nov 09 13:48:50 2009 +0000
@@ -1,3 +1,11 @@
+2009-11-09  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	* src/main/java/de/intevation/gnv/exports/SimpleOdvDataCollector.java:
+	  Implemented a DataCollector for Odv exports.
+
+	* src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java:
+	  OEV-export uses a SimpleOdvDataCollector to collect export data.
+
 2009-11-09  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	* src/main/java/de/intevation/gnv/exports/ShapeDataCollector.java,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/SimpleOdvDataCollector.java	Mon Nov 09 13:48:50 2009 +0000
@@ -0,0 +1,77 @@
+package de.intevation.gnv.exports;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Date;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+import org.apache.log4j.Logger;
+
+import com.vividsolutions.jts.io.WKTReader;
+import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.geom.Point;
+
+import de.intevation.gnv.geobackend.base.Result;
+import de.intevation.gnv.transition.exception.TransitionException;
+
+/**
+ * @author Ingo Weinzierl (ingo.weinzierl@intevation.de)
+ */
+public class SimpleOdvDataCollector
+extends ShapeDataCollector
+{
+    private static Logger log = Logger.getLogger(SimpleOdvDataCollector.class);
+
+    public static final String SRC_FORMAT  = "yyyy.MM.dd HH:mm:ss";
+    public static final String DEST_FORMAT = "yyyy-MM-dd HH:mm";
+
+    public static DateFormat srcFormat  = new SimpleDateFormat(SRC_FORMAT);
+    public static DateFormat destFormat = new SimpleDateFormat(DEST_FORMAT);
+
+    public SimpleOdvDataCollector(String[] names) {
+        super(names);
+    }
+
+    public String[] getData(Result result)
+    throws TransitionException
+    {
+        if (rd == null)
+            init(result);
+
+        try {
+            String [] entries = new String[names.length+1];
+            int j             = 0;
+            for (int i = 0; i < names.length; i++) {
+                
+                if (names[i].equals("SHAPE")) {
+                    Point p  = (Point)wktReader.read(result.getString("SHAPE"));
+
+                    entries[j++] = ""+p.getX();
+                    entries[j++] = ""+p.getY();
+                }
+                // Change the datetime format from yyyy.MM.dd HH:mm:ss to 
+                // yyyy-MM-dd HH:mm
+                else if (names[i].equals("TIMEVALUE")) {
+                    Date source  = srcFormat.parse(result.getString(names[i]));
+                    entries[j++] = destFormat.format(source);
+                }
+                else {
+                    entries[j++] = result.getString(names[i]);
+                }
+            }
+
+            return entries;
+        }
+        catch (ParseException pe) {
+            log.error(pe, pe);
+            throw new TransitionException(
+                "Error occured while parsing source data.");
+        }
+        catch (java.text.ParseException pe) {
+            log.error(pe, pe);
+            throw new TransitionException(
+                "Error occured while parsing source data.");
+        }
+    }
+}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Mon Nov 09 13:11:33 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Mon Nov 09 13:48:50 2009 +0000
@@ -54,6 +54,7 @@
 import de.intevation.gnv.transition.exception.TransitionException;
 import de.intevation.gnv.exports.DefaultExport;
 import de.intevation.gnv.exports.DefaultDataCollector;
+import de.intevation.gnv.exports.SimpleOdvDataCollector;
 import de.intevation.gnv.exports.DefaultProfile;
 import de.intevation.gnv.exports.Export.Profile;
 import de.intevation.gnv.utils.ArtifactXMLUtilities;
@@ -98,13 +99,14 @@
           "CRUISE",
           "STATION",
           "TYPE",
+          "SHAPE",
           "BOTDEPTH",
-          "DEPTH",
+          //"DEPTH",
           "TIMEVALUE",
-          "DATAVALUE",
-          "PARAMETER",
-          "MEASUREMENTID",
-          "TIMESERIESID"
+          //"DATAVALUE",
+          //"PARAMETER",
+          //"MEASUREMENTID",
+          //"TIMESERIESID"
       };
 
     /**
@@ -233,9 +235,11 @@
     protected void createODV(OutputStream outputStream, Collection result)
     throws IOException, TransitionException {
 
-        DefaultExport export = new DefaultExport(new DefaultDataCollector(
-            TIMESERIES_CSV_PROFILE_NAMES));
+        DefaultExport export = new DefaultExport(new SimpleOdvDataCollector(
+            TIMESERIES_ODV_PROFILE_NAMES));
 
+        if (result == null)
+            log.error("#################### RESULT == NULL #################");
         export.create(TIMESERIES_ODV_PROFILE, outputStream, result);
     }
 

http://dive4elements.wald.intevation.org