changeset 710:cded0924193d

Added generator and facet for error reports. flys-artifacts/trunk@2166 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 20 Jun 2011 13:47:59 +0000
parents 3b7e9ddf6bb1
children 69c8541edcc7
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReportFacet.java flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java flys-artifacts/src/main/java/de/intevation/flys/exports/ReportGenerator.java
diffstat 8 files changed, 141 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Jun 20 12:32:32 2011 +0000
+++ b/flys-artifacts/ChangeLog	Mon Jun 20 13:47:59 2011 +0000
@@ -1,3 +1,26 @@
+2011-06-20  Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/ReportGenerator.java:
+	  New. Generator for calculation reports.
+
+	* doc/conf/conf.xml: Added ReportGenerator.
+
+	* src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java:
+	  Added type 'report'.
+
+	* src/main/java/de/intevation/flys/artifacts/model/ReportFacet.java:
+	  Specialized facet for serving reports. TODO: Added them to the
+	  calculation states.
+
+	* src/main/java/de/intevation/flys/artifacts/model/Calculation.java:
+	  Looped through CallMeta for i18n purposes. TODO: do i18n
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  Removed superfluous import.
+
+	* src/main/java/de/intevation/flys/exports/AbstractExporter.java:
+	  Added some override annotations.
+
 2011-06-20  Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/CalculationResult.java:
--- a/flys-artifacts/doc/conf/conf.xml	Mon Jun 20 12:32:32 2011 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Mon Jun 20 13:47:59 2011 +0000
@@ -63,6 +63,7 @@
         <output-generator name="durationcurve_export">de.intevation.flys.exports.DurationCurveExporter</output-generator>
         <output-generator name="computed_dischargecurve_export">de.intevation.flys.exports.ComputedDischargeCurveExporter</output-generator>
         <output-generator name="discharge_longitudinal_section_export">de.intevation.flys.exports.DischargeLongitudinalSectionExporter</output-generator>
+        <output-generator name="calculation_report">de.intevation.flys.exports.ReportGenerator</output-generator>
     </output-generators>
 
     <rest-server>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Mon Jun 20 12:32:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Mon Jun 20 13:47:59 2011 +0000
@@ -33,7 +33,6 @@
 
 import de.intevation.flys.artifacts.model.DischargeTables;
 import de.intevation.flys.artifacts.model.MainValuesFactory;
-import de.intevation.flys.artifacts.model.WQDay;
 import de.intevation.flys.artifacts.model.WQKms;
 import de.intevation.flys.artifacts.model.WstValueTable;
 import de.intevation.flys.artifacts.model.WstValueTableFactory;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java	Mon Jun 20 12:32:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java	Mon Jun 20 13:47:59 2011 +0000
@@ -8,6 +8,8 @@
 
 import java.io.Serializable;
 
+import de.intevation.artifacts.CallMeta;
+
 public class Calculation
 implements   Serializable
 {
@@ -29,7 +31,8 @@
             this.msg = msg;
         }
 
-        public Element toXML(Document document) {
+        public Element toXML(Document document, CallMeta meta) {
+            // TODO: i18n
             Element problem = document.createElement("problem");
             if (km != null) {
                 problem.setAttribute("km", String.valueOf(km));
@@ -75,13 +78,13 @@
         return problems;
     }
 
-    public void toXML(Document document) {
+    public void toXML(Document document, CallMeta meta) {
 
         Element root = document.createElement("problems");
 
         if (hasProblems()) {
             for (Problem problem: problems) {
-                root.appendChild(problem.toXML(document));
+                root.appendChild(problem.toXML(document, meta));
             }
         }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Mon Jun 20 12:32:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Mon Jun 20 13:47:59 2011 +0000
@@ -16,5 +16,7 @@
 
     String CSV = "csv";
     String WST = "wst";
+
+    String REPORT = "report";
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReportFacet.java	Mon Jun 20 13:47:59 2011 +0000
@@ -0,0 +1,43 @@
+package de.intevation.flys.artifacts.model;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.state.DefaultFacet;
+
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+import de.intevation.flys.artifacts.WINFOArtifact;
+
+
+import org.apache.log4j.Logger;
+
+public class ReportFacet
+extends      DefaultFacet
+implements   FacetTypes
+{
+    private static Logger logger = Logger.getLogger(ReportFacet.class);
+
+    protected ComputeType type;
+
+    public ReportFacet() {
+        this(ComputeType.ADVANCE);
+    }
+
+    public ReportFacet(ComputeType type) {
+        super(0, REPORT, "report");
+        this.type = type;
+    }
+
+    public Object getData(Artifact artifact, CallContext context) {
+        logger.debug("get report data");
+
+        WINFOArtifact winfo = (WINFOArtifact)artifact;
+
+        CalculationResult cr = (CalculationResult)winfo.compute(
+            context, type, false);
+
+        return cr;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java	Mon Jun 20 12:32:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java	Mon Jun 20 13:47:59 2011 +0000
@@ -82,7 +82,7 @@
      */
     protected abstract void addData(Object data);
 
-
+    @Override
     public void init(Document request, OutputStream out, CallContext context) {
         logger.debug("AbstractExporter.init");
 
@@ -92,6 +92,7 @@
     }
 
 
+    @Override
     public void setMasterArtifact(Artifact master) {
         this.master = master;
     }
@@ -109,6 +110,7 @@
      * skipped.
      * @param attr The attr document.
      */
+    @Override
     public void doOut(Artifact artifact, Facet facet, Document attr) {
         String name = facet.getName();
 
@@ -132,6 +134,7 @@
     /**
      * Generates an export based on a specified facet.
      */
+    @Override
     public void generate()
     throws IOException
     {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ReportGenerator.java	Mon Jun 20 13:47:59 2011 +0000
@@ -0,0 +1,62 @@
+package de.intevation.flys.exports;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+import de.intevation.flys.artifacts.model.Calculation;
+
+import org.w3c.dom.Document;
+
+public class ReportGenerator
+implements   OutGenerator 
+{
+    private static Logger logger = Logger.getLogger(ReportGenerator.class);
+
+    protected Document     result;
+    protected OutputStream out;
+    protected CallContext  context;
+
+    public ReportGenerator() {
+    }
+
+    @Override
+    public void init(Document request, OutputStream out, CallContext context) {
+        logger.debug("init");
+        this.out     = out;
+        this.context = context;
+        result = XMLUtils.newDocument();
+    }
+
+    @Override
+    public void setMasterArtifact(Artifact master) {
+        // not needed
+    }
+
+    @Override
+    public void doOut(Artifact artifact, Facet facet, Document attr) {
+        logger.debug("doOut");
+        facet = ((FLYSArtifact)artifact).getNativeFacet(facet);
+        if (facet != null) {
+            Calculation report = (Calculation)facet.getData(artifact, context);
+            report.toXML(result, context.getMeta());
+        }
+    }
+
+    @Override
+    public void generate() throws IOException {
+        logger.debug("generate");
+        XMLUtils.toStream(result, out);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org