changeset 1149:64b465699a24

Added an Output target for WSPLGEN reports that will be available when an WSPLGEN calculation is finished. flys-artifacts/trunk@2680 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 08 Sep 2011 14:42:36 +0000
parents 302461d5d071
children 5f53b443d67c
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/winfo.xml flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENReportFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java flys-artifacts/src/main/java/de/intevation/flys/wsplgen/ProblemObserver.java
diffstat 8 files changed, 225 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Sep 08 11:29:04 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu Sep 08 14:42:36 2011 +0000
@@ -1,3 +1,32 @@
+2011-09-08  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/WSPLGENCalculation.java:
+	  New. This sublcass of Calculation saves warnings and errors that occur
+	  while WSPLGEN is running.
+	  Note, that the interface of this class doesn't exactly apply the interface
+	  of Calculation. Maybe, we should generalize this interface!
+
+	* src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java: Stores
+	  an instance of WSPLGENCalculation now. We use this instance to save
+	  warnings and errors.
+
+	* src/main/java/de/intevation/flys/wsplgen/ProblemObserver.java: Use the
+	  WSPLGENCalculation to save errors and warnings.
+
+	* src/main/java/de/intevation/flys/artifacts/model/WSPLGENReportFacet.java:
+	  New. This facet is used for WSPLGEN reports. It stores an instance of
+	  WSPLGENCalculation which saves ERRORS and WARNINGS that occur while
+	  WSPLGEN execution.
+
+	* src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java:
+	  Create a WSPLGENReportFacet for WSPLGEN reports.
+
+	* doc/conf/conf.xml: Added an OutputGenerator 'report' for WSPLGEN
+	  reports.
+
+	* doc/conf/artifacts/winfo.xml: Added an output 'report' for WSPLGEN
+	  reports.
+
 2011-09-08  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java,
--- a/flys-artifacts/doc/conf/artifacts/winfo.xml	Thu Sep 08 11:29:04 2011 +0000
+++ b/flys-artifacts/doc/conf/artifacts/winfo.xml	Thu Sep 08 14:42:36 2011 +0000
@@ -290,6 +290,11 @@
                         <facet name="floodmap.wsplgen"/>
                     </facets>
                 </outputmode>
+                <outputmode name="wsplgen_report" description="output.wsplgen_report" mime-type="text/xml" type="report">
+                    <facets>
+                        <facet name="report" description="facet.wsplgen_export.report"/>
+                    </facets>
+                </outputmode>
             </outputmodes>
         </state>
 
--- a/flys-artifacts/doc/conf/conf.xml	Thu Sep 08 11:29:04 2011 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Thu Sep 08 14:42:36 2011 +0000
@@ -106,6 +106,7 @@
         <output-generator name="waterlevel_report">de.intevation.flys.exports.ReportGenerator</output-generator>
         <output-generator name="computed_dischargecurve_report">de.intevation.flys.exports.ReportGenerator</output-generator>
         <output-generator name="durationcurve_report">de.intevation.flys.exports.ReportGenerator</output-generator>
+        <output-generator name="wsplgen_report">de.intevation.flys.exports.ReportGenerator</output-generator>
         <!-- AT exporter. -->
         <output-generator name="computed_dischargecurve_at_export">de.intevation.flys.exports.ATExporter</output-generator>
     </output-generators>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENCalculation.java	Thu Sep 08 14:42:36 2011 +0000
@@ -0,0 +1,81 @@
+package de.intevation.flys.artifacts.model;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.CallMeta;
+
+
+public class WSPLGENCalculation extends Calculation {
+
+    private static final Logger log = Logger.getLogger(WSPLGENCalculation.class);
+
+    protected Map<Integer, String> errors;
+    protected Map<Integer, String> warnings;
+
+
+    public WSPLGENCalculation() {
+        errors   = new HashMap<Integer, String>();
+        warnings = new HashMap<Integer, String>();
+    }
+
+
+    public void addError(Integer key, String msg) {
+        log.debug("New error: (" + key + ") " + msg);
+        errors.put(key, msg);
+    }
+
+
+    public void addWarning(Integer key, String msg) {
+        log.debug("New warning: (" + key + ") " + msg);
+        warnings.put(key, msg);
+    }
+
+
+    public int numErrors() {
+        return errors.size();
+    }
+
+
+    public int numWarnings() {
+        return warnings.size();
+    }
+
+
+    public void toXML(Document document, CallMeta meta) {
+        Element root = document.createElement("problems");
+
+        if (numErrors() > 0) {
+            Set<Map.Entry<Integer, String>> entrySet = errors.entrySet();
+
+            for (Map.Entry<Integer, String> entry: entrySet) {
+                Element problem = document.createElement("problem");
+                problem.setAttribute("error", String.valueOf(entry.getKey()));
+                problem.setTextContent(entry.getValue());
+
+                root.appendChild(problem);
+            }
+        }
+
+        if (numWarnings() > 0) {
+            Set<Map.Entry<Integer, String>> entrySet = warnings.entrySet();
+
+            for (Map.Entry<Integer, String> entry: entrySet) {
+                Element problem = document.createElement("problem");
+                problem.setAttribute("error", String.valueOf(entry.getKey()));
+                problem.setTextContent(entry.getValue());
+
+                root.appendChild(problem);
+            }
+        }
+
+        document.appendChild(root);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java	Thu Sep 08 11:29:04 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java	Thu Sep 08 14:42:36 2011 +0000
@@ -23,6 +23,8 @@
 
     protected CallContext callContext;
 
+    protected WSPLGENCalculation calculation;
+
     protected File workingDir;
 
     protected String dgm;
@@ -47,10 +49,16 @@
 
 
 
-    public WSPLGENJob(FLYSArtifact flys, File workingDir, CallContext context) {
+    public WSPLGENJob(
+        FLYSArtifact       flys,
+        File               workingDir,
+        CallContext        context,
+        WSPLGENCalculation calculation)
+    {
         this.artifact    = flys;
         this.workingDir  = workingDir;
         this.callContext = context;
+        this.calculation = calculation;
 
         out   = -1;
         start = Double.NaN;
@@ -68,6 +76,16 @@
     }
 
 
+    public FLYSArtifact getArtifact() {
+        return artifact;
+    }
+
+
+    public WSPLGENCalculation getCalculation() {
+        return calculation;
+    }
+
+
     public CallContext getCallContext() {
         return callContext;
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENReportFacet.java	Thu Sep 08 14:42:36 2011 +0000
@@ -0,0 +1,56 @@
+package de.intevation.flys.artifacts.model;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+
+/**
+ * This facet is used to provide WSPLGEN reports <b>only</b>.
+ */
+public class WSPLGENReportFacet extends ReportFacet {
+
+    private static Logger logger = Logger.getLogger(WSPLGENReportFacet.class);
+
+
+    protected CalculationResult result;
+
+
+    public WSPLGENReportFacet() {
+    }
+
+
+    public WSPLGENReportFacet(
+        ComputeType       type,
+        String            hash,
+        String            stateId,
+        CalculationResult result
+    ) {
+        super(type, hash, stateId);
+        this.result = result;
+    }
+
+
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        return result.getReport();
+    }
+
+
+    @Override
+    public Facet deepCopy() {
+        WSPLGENReportFacet copy = new WSPLGENReportFacet();
+        copy.set(this);
+        copy.type    = type;
+        copy.hash    = hash;
+        copy.stateId = stateId;
+        copy.result  = result;
+        return copy;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Thu Sep 08 11:29:04 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Thu Sep 08 14:42:36 2011 +0000
@@ -7,8 +7,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.xml.xpath.XPathConstants;
-
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.LineString;
@@ -27,7 +25,6 @@
 import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.CallContext;
 
-import de.intevation.artifacts.common.utils.Config;
 import de.intevation.artifacts.common.utils.FileTools;
 
 import de.intevation.artifactdatabase.state.Facet;
@@ -42,7 +39,9 @@
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.WQKms;
 import de.intevation.flys.artifacts.model.WMSLayerFacet;
+import de.intevation.flys.artifacts.model.WSPLGENCalculation;
 import de.intevation.flys.artifacts.model.WSPLGENJob;
+import de.intevation.flys.artifacts.model.WSPLGENReportFacet;
 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
 import de.intevation.flys.exports.WstWriter;
 import de.intevation.flys.utils.FLYSUtils;
@@ -97,7 +96,13 @@
             return null;
         }
 
-        WSPLGENJob job = prepareWSPLGENJob(artifact, artifactDir, context);
+        WSPLGENCalculation calculation = new WSPLGENCalculation();
+
+        WSPLGENJob job = prepareWSPLGENJob(
+            artifact,
+            artifactDir,
+            context,
+            calculation);
 
         if (job == null) {
             if (KEEP_ARTIFACT_DIR.equals("false")) {
@@ -146,8 +151,13 @@
         barriers.setSrid(srid);
         barriers.setExtent(GeometryUtils.getRiverBounds(river));
 
+        CalculationResult  res   = new CalculationResult(null, calculation);
+        WSPLGENReportFacet report= new WSPLGENReportFacet(
+            ComputeType.ADVANCE, hash, getID(), res);
+
         facets.add(wsplgen);
         facets.add(barriers);
+        facets.add(report);
 
         context.afterCall(CallContext.BACKGROUND);
 
@@ -204,14 +214,20 @@
 
 
     protected WSPLGENJob prepareWSPLGENJob(
-        FLYSArtifact artifact,
-        File         artifactDir,
-        CallContext  context
+        FLYSArtifact       artifact,
+        File               artifactDir,
+        CallContext        context,
+        WSPLGENCalculation calculation
     ) {
         logger.debug("FloodMapState.prepareWSPLGENJob");
 
-        WSPLGENJob job = new WSPLGENJob(artifact, artifactDir, context);
-        File  paraFile = new File(artifactDir, WSPLGEN_PARAMETER_FILE);
+        WSPLGENJob job = new WSPLGENJob(
+            artifact,
+            artifactDir,
+            context,
+            calculation);
+
+        File paraFile = new File(artifactDir, WSPLGEN_PARAMETER_FILE);
 
         setOut(artifact, job);
         setRange(artifact, job);
--- a/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/ProblemObserver.java	Thu Sep 08 11:29:04 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/ProblemObserver.java	Thu Sep 08 14:42:36 2011 +0000
@@ -1,12 +1,11 @@
 package de.intevation.flys.wsplgen;
 
-import java.util.HashMap;
-import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.log4j.Logger;
 
+import de.intevation.flys.artifacts.model.WSPLGENCalculation;
 import de.intevation.flys.artifacts.model.WSPLGENJob;
 
 
@@ -35,16 +34,14 @@
     protected int error;
     protected int warning;
 
-    protected Map<Integer, String> errorMsg;
-    protected Map<Integer, String> warningMsg;
+    protected WSPLGENCalculation calculation;
 
 
     public ProblemObserver(WSPLGENJob job) {
         super(job);
-        error      = -1;
-        warning    = -1;
-        errorMsg   = new HashMap<Integer, String>();
-        warningMsg = new HashMap<Integer, String>();
+        error       = -1;
+        warning     = -1;
+        calculation = job.getCalculation();
     }
 
 
@@ -75,7 +72,7 @@
         }
 
         if (error > 0) {
-            errorMsg.put(new Integer(error), log);
+            calculation.addError(new Integer(error), log);
         }
 
         Matcher startWarning = WSPLGEN_WARNING_START.matcher(log);
@@ -90,18 +87,18 @@
         }
 
         if (warning > 0) {
-            warningMsg.put(new Integer(warning), log);
+            calculation.addWarning(new Integer(warning), log);
         }
     }
 
 
     public int numErrors() {
-        return errorMsg.size();
+        return calculation.numErrors();
     }
 
 
     public int numWarnings() {
-        return warningMsg.size();
+        return calculation.numWarnings();
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=5 fenc=utf-8 :

http://dive4elements.wald.intevation.org