changeset 177:08b8b79b30ff

Integrated special CSV-Export for HorizontalProfiles gnv-artifacts/trunk@221 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Thu, 15 Oct 2009 12:43:46 +0000
parents bff7bbb7c6f0
children 9bcf315f57e4
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java
diffstat 4 files changed, 119 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Wed Oct 14 10:49:35 2009 +0000
+++ b/gnv-artifacts/ChangeLog	Thu Oct 15 12:43:46 2009 +0000
@@ -1,3 +1,11 @@
+2009-10-15  Tim Englich  <tim.englich@intevation.de>
+
+	* src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java (testHorizontalProfileMeshPointArtifact): 
+	  Activate Tests for CSV and Statistics on HorizontalProfiles
+	* src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java (createCSV): 
+	* src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java (createCSV):
+	  Integrated special CSV-Export for HorizontalProfiles 
+
 2009-10-14  Tim Englich  <tim.englich@intevation.de>
 
 	* src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java (createXYSeries):
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java	Wed Oct 14 10:49:35 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java	Thu Oct 15 12:43:46 2009 +0000
@@ -5,15 +5,28 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
 import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.log4j.Logger;
+
+import au.com.bytecode.opencsv.CSVWriter;
+
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.WKTReader;
 
 import de.intevation.gnv.chart.ChartLabels;
 import de.intevation.gnv.chart.ChartStyle;
 import de.intevation.gnv.chart.HorizontalProfileChartFactory;
 import de.intevation.gnv.chart.exception.TechnicalChartException;
+import de.intevation.gnv.geobackend.base.Result;
 import de.intevation.gnv.statistics.HorizontalProfileStatistics;
 import de.intevation.gnv.statistics.Statistics;
 import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
+import de.intevation.gnv.transition.exception.TransitionException;
 import de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition;
 
 /**
@@ -27,6 +40,8 @@
      */
     private static final long serialVersionUID = 4401516087492028840L;
 
+    private static Logger log = Logger
+    .getLogger(HorizontalProfileOutputTransition.class);
     /**
      * Constructor
      */
@@ -61,4 +76,47 @@
         return new HorizontalProfileStatistics();
     }
 
+    @Override
+    protected void createCSV(OutputStream outputStream,
+                             Collection<Result> chartResult)
+                                                            throws UnsupportedEncodingException,
+                                                            IOException,
+                                                            TransitionException {
+       
+        if (chartResult != null) {
+            try {
+                CSVWriter writer = new CSVWriter(new OutputStreamWriter(
+                        outputStream, "ISO-8859-1"), ','); 
+                // USE THIS ENCODING BECAUSE OF
+                // PROBLEMS WITH EXCEL AND UTF-8
+                Iterator<Result> it = chartResult.iterator();
+                WKTReader wktReader = new WKTReader();
+                while (it.hasNext()) {
+                    Result result = it.next();
+                    int i = 0;
+                    String[] entries = new String[6];
+                    Point p = (Point)wktReader.read(result.getString("SHAPE"));
+                    entries[i++] = ""+p.getX();
+                    entries[i++] = ""+p.getY();
+                    entries[i++] = result.getString("YORDINATE");
+                    entries[i++] = result.getString("GROUP1");
+                    entries[i++] = result.getString("GROUP2");
+                    entries[i++] = result.getString("GROUP3");
+                    writer.writeNext(entries);
+                }
+                writer.close();
+            } catch (ParseException e) {
+                log.error(e,e);
+                throw new TransitionException(
+                "Exception occured while parsing an Point from WKT.");
+            }
+        } else {
+            log.error("No Data given for generation an CSV-File.");
+            throw new TransitionException(
+                    "No Data given for generation an CSV-File.");
+        }
+    }
+    
+    
+
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Wed Oct 14 10:49:35 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Thu Oct 15 12:43:46 2009 +0000
@@ -8,6 +8,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
 import java.util.Collection;
 import java.util.Iterator;
 
@@ -127,32 +128,7 @@
                         chartStyle, chartLables, uuid);
             } else if (outputMode.equalsIgnoreCase("csv")) {
                 log.debug("CSV-File will be generated.");
-                if (chartResult != null) {
-                    CSVWriter writer = new CSVWriter(new OutputStreamWriter(
-                            outputStream, "ISO-8859-1"), ','); // USE THIS
-                    // ENCODING
-                    // BECAUSE OF
-                    // PROBLEMS WITH
-                    // EXCEL AND
-                    // UTF-8
-                    Iterator<Result> it = chartResult.iterator();
-                    while (it.hasNext()) {
-                        Result result = it.next();
-                        int i = 0;
-                        String[] entries = new String[5];
-                        entries[i++] = result.getString("XORDINATE");
-                        entries[i++] = result.getString("YORDINATE");
-                        entries[i++] = result.getString("GROUP1");
-                        entries[i++] = result.getString("GROUP2");
-                        entries[i++] = result.getString("GROUP3");
-                        writer.writeNext(entries);
-                    }
-                    writer.close();
-                } else {
-                    log.error("No Data given for generation an CSV-File.");
-                    throw new TransitionException(
-                            "No Data given for generation an CSV-File.");
-                }
+                this.createCSV(outputStream, chartResult);
             } else if (outputMode.equalsIgnoreCase("statistics")) {
                 log.debug("Statistics will be generated.");
                 Statistics s = getStatisticsGenerator();
@@ -174,6 +150,43 @@
     }
 
     /**
+     * @param outputStream
+     * @param chartResult
+     * @throws UnsupportedEncodingException
+     * @throws IOException
+     * @throws TransitionException
+     */
+    protected void createCSV(OutputStream outputStream,
+                            Collection<Result> chartResult)
+                                                          throws UnsupportedEncodingException,
+                                                          IOException,
+                                                          TransitionException {
+        if (chartResult != null) {
+            CSVWriter writer = new CSVWriter(new OutputStreamWriter(
+                    outputStream, "ISO-8859-1"), ','); 
+            // USE THIS ENCODING BECAUSE OF
+            // PROBLEMS WITH EXCEL AND UTF-8
+            Iterator<Result> it = chartResult.iterator();
+            while (it.hasNext()) {
+                Result result = it.next();
+                int i = 0;
+                String[] entries = new String[5];
+                entries[i++] = result.getString("XORDINATE");
+                entries[i++] = result.getString("YORDINATE");
+                entries[i++] = result.getString("GROUP1");
+                entries[i++] = result.getString("GROUP2");
+                entries[i++] = result.getString("GROUP3");
+                writer.writeNext(entries);
+            }
+            writer.close();
+        } else {
+            log.error("No Data given for generation an CSV-File.");
+            throw new TransitionException(
+                    "No Data given for generation an CSV-File.");
+        }
+    }
+
+    /**
      * @return
      */
     protected Statistics getStatisticsGenerator() {
--- a/gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java	Wed Oct 14 10:49:35 2009 +0000
+++ b/gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java	Thu Oct 15 12:43:46 2009 +0000
@@ -683,18 +683,18 @@
                                 + System.currentTimeMillis() + ".csv");
                 artifact
                         .feed(
-                                this
-                                        .readDocument("src/test/ressources/horizontalProfile_instantaneouspoint/horizontalprofile_step_06_feed.xml"),
+                                this.readDocument("src/test/ressources/horizontalProfile_instantaneouspoint/horizontalprofile_step_06_feed.xml"),
                                 cc);
-                // artifact.out(this.readDocument("src/test/ressources/horizontalProfile_instantaneouspoint/horizontalprofile_step_06_out_statistics.xml"),fos2,
-                // cc);
-                artifact
-                        .out(
-                                this
-                                        .readDocument("src/test/ressources/horizontalProfile_instantaneouspoint/horizontalprofile_step_06_out_chart.xml"),
-                                fos, cc);
-                // artifact.out(this.readDocument("src/test/ressources/horizontalProfile_instantaneouspoint/horizontalprofile_step_06_out_csv.xml"),fos3,
-                // cc);
+                artifact.out(this.readDocument("src/test/ressources/horizontalProfile_instantaneouspoint/horizontalprofile_step_06_out_statistics.xml"),
+                                fos2,
+                                cc);
+                artifact.out(
+                                this.readDocument("src/test/ressources/horizontalProfile_instantaneouspoint/horizontalprofile_step_06_out_chart.xml"),
+                                fos, 
+                                cc);
+                artifact.out(this.readDocument("src/test/ressources/horizontalProfile_instantaneouspoint/horizontalprofile_step_06_out_csv.xml"),
+                             fos3,
+                             cc);
             } catch (Exception e) {
                 log.error(e, e);
                 fail();
@@ -814,8 +814,9 @@
                                 this
                                         .readDocument("src/test/ressources/horizontalProfile_mesh/horizontalprofile_step_08_out_chart.xml"),
                                 fos, cc);
-                // artifact.out(this.readDocument("src/test/ressources/horizontalProfile_mesh/horizontalprofile_step_08_out_csv.xml"),fos3,
-                // cc);
+                artifact.out(this.readDocument("src/test/ressources/horizontalProfile_mesh/horizontalprofile_step_08_out_csv.xml"),
+                             fos3,
+                             cc);
             } catch (Exception e) {
                 log.error(e, e);
                 fail();

http://dive4elements.wald.intevation.org