changeset 90:6bdef6e590d6

Added CSV-Support and do some performanceimprovments gnv-artifacts/trunk@132 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Thu, 24 Sep 2009 15:27:33 +0000
parents cde042a0a395
children bd284d8306db
files gnv-artifacts/Changelog gnv-artifacts/pom.xml gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java
diffstat 4 files changed, 51 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/Changelog	Thu Sep 24 11:03:31 2009 +0000
+++ b/gnv-artifacts/Changelog	Thu Sep 24 15:27:33 2009 +0000
@@ -1,3 +1,12 @@
+2009-09-24  Tim Englich  <tim.englich@intevation.de>
+
+    * pom.xml Edited:
+      Added Library for CSV-Support 
+    * src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java (out) Edited:
+      Add support for CSV-Export 
+    * src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java (out) Edited:
+      Add Fag on Context for storing the Artifact status after out. 
+      
 2009-09-24  Tim Englich  <tim.englich@intevation.de>
 
     * src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java (createSuccessReport) Edited:
--- a/gnv-artifacts/pom.xml	Thu Sep 24 11:03:31 2009 +0000
+++ b/gnv-artifacts/pom.xml	Thu Sep 24 15:27:33 2009 +0000
@@ -52,5 +52,11 @@
       <artifactId>jfreechart</artifactId>
       <version>1.0.7</version>
     </dependency>
+    <dependency>
+        <groupId>net.sf.opencsv</groupId>
+        <artifactId>opencsv</artifactId>
+        <version>2.0</version>
+    </dependency>
+    
   </dependencies>
 </project>
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Thu Sep 24 11:03:31 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Thu Sep 24 15:27:33 2009 +0000
@@ -361,6 +361,7 @@
             
             if (current != null && current instanceof OutputTransition){
               ((OutputTransition)current).out(this.readOutputType(format), outputStream);
+               context.afterCall(CallContext.STORE); // TODO: FIXME Schmutzige Lösung: Besser einen weiteren Transitionsschritt zwischenschalten.
             }
         } catch (TransitionException e) {
             log.error(e,e);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Thu Sep 24 11:03:31 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Thu Sep 24 15:27:33 2009 +0000
@@ -7,11 +7,14 @@
 import java.awt.Dimension;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.util.Collection;
 import java.util.Iterator;
 
 import org.apache.log4j.Logger;
 
+import au.com.bytecode.opencsv.CSVWriter;
+
 import de.intevation.gnv.chart.ChartFactory;
 import de.intevation.gnv.chart.ChartLabels;
 import de.intevation.gnv.chart.ChartStyle;
@@ -58,15 +61,39 @@
     * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String, java.io.OutputStream)
     */
     public void out(String outputMode, OutputStream outputStream) throws TransitionException {
-        log.debug("TimeSeriesOutputTransition");
+        log.debug("TimeSeriesOutputTransition.out");
         try {
-            this.advance(); 
-            Collection<KeyValueDescibeData> parameters = this.getParameters();
-            Collection<KeyValueDescibeData> measurements = this.getMeasurements();
-            ChartStyle chartStyle = this.creatStyle(600,400);
-            ChartLabels chartLables = new ChartLabels(this.getSelectedFeatureName(),this.domainLable);
-            this.createChart(outputStream, parameters, measurements,
-                    chartStyle, chartLables);
+            this.advance();
+            if (outputMode.equalsIgnoreCase("chart")){
+                log.debug("Chart will be generated.");
+                Collection<KeyValueDescibeData> parameters = this.getParameters();
+                Collection<KeyValueDescibeData> measurements = this.getMeasurements();
+                ChartStyle chartStyle = this.creatStyle(600,400);
+                ChartLabels chartLables = new ChartLabels(this.getSelectedFeatureName(),this.domainLable);
+                this.createChart(outputStream, parameters, measurements,
+                        chartStyle, chartLables);
+            }else if (outputMode.equalsIgnoreCase("csv")){
+                log.debug("CSV-File will be generated.");
+                if(this.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 = this.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.");
+                }
+            }
         } catch (IOException e) {
             log.error(e,e);
             throw new TransitionException(e);

http://dive4elements.wald.intevation.org