# HG changeset patch # User Ingo Weinzierl # Date 1315492956 0 # Node ID 64b465699a24a8899925ea89b804c582d8760817 # Parent 302461d5d071d7ad19e1a21543a899a88db98b1c 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 diff -r 302461d5d071 -r 64b465699a24 flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java, diff -r 302461d5d071 -r 64b465699a24 flys-artifacts/doc/conf/artifacts/winfo.xml --- 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 @@ + + + + + diff -r 302461d5d071 -r 64b465699a24 flys-artifacts/doc/conf/conf.xml --- 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 @@ de.intevation.flys.exports.ReportGenerator de.intevation.flys.exports.ReportGenerator de.intevation.flys.exports.ReportGenerator + de.intevation.flys.exports.ReportGenerator de.intevation.flys.exports.ATExporter diff -r 302461d5d071 -r 64b465699a24 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENCalculation.java --- /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 errors; + protected Map warnings; + + + public WSPLGENCalculation() { + errors = new HashMap(); + warnings = new HashMap(); + } + + + 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> entrySet = errors.entrySet(); + + for (Map.Entry 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> entrySet = warnings.entrySet(); + + for (Map.Entry 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 : diff -r 302461d5d071 -r 64b465699a24 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java --- 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; } diff -r 302461d5d071 -r 64b465699a24 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENReportFacet.java --- /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 only. + */ +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 : diff -r 302461d5d071 -r 64b465699a24 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java --- 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); diff -r 302461d5d071 -r 64b465699a24 flys-artifacts/src/main/java/de/intevation/flys/wsplgen/ProblemObserver.java --- 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 errorMsg; - protected Map warningMsg; + protected WSPLGENCalculation calculation; public ProblemObserver(WSPLGENJob job) { super(job); - error = -1; - warning = -1; - errorMsg = new HashMap(); - warningMsg = new HashMap(); + 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 :