[PATCH 2 of 2] issue1416: Move a stub new SedimentLoadExporter in place

Wald Commits scm-commit at wald.intevation.org
Fri Jul 26 10:35:59 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1374828347 -7200
# Node ID 368db84f12416bf85d6f1d3a514e5f1dca208b99
# Parent  84349d440987fd02c1af4d8ccaa0efee55fe8d07
issue1416: Move a stub new SedimentLoadExporter in place.

SedimentLoadExporter: New stub for exporter.
minfo.xml: Register csv facet, declare new out.
conf.xml: Register exporter for new out.
SedimentLoadCalculate: Create a data facet to become active in new out.

diff -r 84349d440987 -r 368db84f1241 artifacts/doc/conf/artifacts/minfo.xml
--- a/artifacts/doc/conf/artifacts/minfo.xml	Fri Jul 26 09:21:47 2013 +0200
+++ b/artifacts/doc/conf/artifacts/minfo.xml	Fri Jul 26 10:45:47 2013 +0200
@@ -524,6 +524,14 @@
                         <facet name="longitudinal_section.annotations" description="facet.longitudinal_section.annotations"/>
                     </facets>
                 </outputmode>
+                <outputmode name="sedimentload_ls_export" description="output.sedimentload_ls_export" mime-type="text/plain" type="export">
+                    <facets>
+                        <facet name="csv" description="facet.sedimentload_ls_export.csv" />
+                        <!--
+                        <facet name="pdf" description=".pdf" />
+                        -->
+                    </facets>
+                </outputmode>
                 <outputmode name="sedimentload_ls_report" description="output.sedimentload_ls_report" mime-type="text/xml" type="report">
                     <facets>
                         <facet name="report" description="facet.sedimentload_ls_export.report" />
diff -r 84349d440987 -r 368db84f1241 artifacts/doc/conf/conf.xml
--- a/artifacts/doc/conf/conf.xml	Fri Jul 26 09:21:47 2013 +0200
+++ b/artifacts/doc/conf/conf.xml	Fri Jul 26 10:45:47 2013 +0200
@@ -363,6 +363,7 @@
         <output-generator name="fix_vollmer_wq_curve">org.dive4elements.river.exports.fixings.FixWQCurveGenerator</output-generator>
         <output-generator name="fix_vollmer_wq_curve_chartinfo">org.dive4elements.river.exports.fixings.FixWQCurveInfoGenerator</output-generator>
         <output-generator name="sedimentload_ls">org.dive4elements.river.exports.minfo.SedimentLoadLSGenerator</output-generator>
+        <output-generator name="sedimentload_ls_export">org.dive4elements.river.exports.minfo.SedimentLoadExporter</output-generator>
         <output-generator name="sedimentload_ls_chartinfo">org.dive4elements.river.exports.minfo.SedimentLoadLSInfoGenerator</output-generator>
         <!-- Error report generators. -->
         <output-generator name="discharge_longitudinal_section_report">org.dive4elements.river.exports.ReportGenerator</output-generator>
diff -r 84349d440987 -r 368db84f1241 artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadCalculate.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadCalculate.java	Fri Jul 26 09:21:47 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadCalculate.java	Fri Jul 26 10:45:47 2013 +0200
@@ -21,6 +21,7 @@
 import org.dive4elements.river.artifacts.D4EArtifact;
 import org.dive4elements.river.artifacts.access.SedimentLoadAccess;
 import org.dive4elements.river.artifacts.model.CalculationResult;
+import org.dive4elements.river.artifacts.model.DataFacet;
 import org.dive4elements.river.artifacts.model.FacetTypes;
 import org.dive4elements.river.artifacts.model.ReportFacet;
 import org.dive4elements.river.artifacts.model.minfo.SedimentLoad;
@@ -167,6 +168,10 @@
                 getID(),
                 hash));
         }
+
+        newFacets.add(
+            new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id));
+
         facets.addAll(newFacets);
 
         return res;
diff -r 84349d440987 -r 368db84f1241 artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java	Fri Jul 26 10:45:47 2013 +0200
@@ -0,0 +1,108 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.exports.minfo;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.IOException;
+
+import java.text.NumberFormat;
+
+import org.w3c.dom.Document;
+
+import org.apache.log4j.Logger;
+
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallContext;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+
+import org.dive4elements.river.artifacts.D4EArtifact;
+
+import org.dive4elements.river.artifacts.model.CalculationResult;
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoadResult;
+
+import org.dive4elements.river.exports.AbstractExporter;
+
+import org.dive4elements.river.model.River;
+import org.dive4elements.river.utils.RiverUtils;
+import org.dive4elements.river.utils.Formatter;
+import org.dive4elements.river.artifacts.access.RangeAccess;
+
+import au.com.bytecode.opencsv.CSVWriter;
+
+public class SedimentLoadExporter
+extends      AbstractExporter
+{
+    /** Private logger. */
+    private static Logger logger = Logger.getLogger(SedimentLoadExporter.class);
+
+
+    private SedimentLoadResult[] results;
+
+    public SedimentLoadExporter() {
+    }
+
+    /** Trivial init. */
+    @Override
+    public void init(Document request, OutputStream out, CallContext context) {
+        super.init(request, out, context);
+        logger.debug("init");
+        results = new SedimentLoadResult[0];
+    }
+
+
+    /** Process all stored data and write csv. */
+    @Override
+    protected void writeCSVData(CSVWriter writer) throws IOException {
+        writeCSVHeader(writer);
+
+        NumberFormat kmf = Formatter.getCalculationKm(context.getMeta());
+        /* writer.writeNext(new String[] { */
+    }
+
+    /** Writes i18ned header for csv file/stream. */
+    protected void writeCSVHeader(CSVWriter writer) {
+        logger.debug("writeCSVHeader()");
+
+        List<String> header = new LinkedList<String>();
+        if (results != null)  {
+            /*header.add(msg(CSV_HEADER_KM, "km"));
+            header.add(msg(CSV_HEADER_VAL, "m"));*/
+        }
+        writer.writeNext(header.toArray(new String[header.size()]));
+    }
+
+    /** Store data internally, accepting only SedimentLoadResults[] in
+     * calculationresults data. */
+    @Override
+    protected void addData(Object data) {
+        if (!(data instanceof CalculationResult)) {
+            logger.warn("Invalid data type.");
+            return;
+        }
+        Object[] d = (Object[])((CalculationResult)data).getData();
+
+        if (!(d instanceof SedimentLoadResult[])) {
+            logger.warn("Invalid result object.");
+            return;
+        }
+        logger.debug("addData: Data added.");
+        results = (SedimentLoadResult[])d;
+    }
+
+    @Override
+    protected void writePDF(OutputStream out) {
+        logger.warn("Not implemented.");
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the Dive4elements-commits mailing list