[PATCH 2 of 2] vergessen

Wald Commits scm-commit at wald.intevation.org
Thu Jun 14 16:58:33 CEST 2018


# HG changeset patch
# User gernotbelger
# Date 1528988234 -7200
# Node ID bb929b444ea5f17c73f44e33539dc469ade51fa4
# Parent  23945061daece2efc7c0d1f53ebd0a54f77cccd4
vergessen

diff -r 23945061daec -r bb929b444ea5 artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractCalculationResults.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractCalculationResults.java	Thu Jun 14 16:57:14 2018 +0200
@@ -0,0 +1,54 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
+ *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * 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.artifacts.common;
+
+import java.io.Serializable;
+
+import org.apache.commons.lang.math.DoubleRange;
+import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
+
+/**
+ * @author Gernot Belger
+ */
+public abstract class AbstractCalculationResults implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private final String calcModeLabel;
+
+    private final String user;
+
+    private final RiverInfo river;
+
+    private final DoubleRange calcRange;
+
+    public AbstractCalculationResults(final String calcModeLabel, final String user, final RiverInfo river, final DoubleRange calcRange) {
+        this.calcModeLabel = calcModeLabel;
+        this.user = user;
+        this.river = river;
+        this.calcRange = calcRange;
+    }
+
+    public final String getCalcModeLabel() {
+        return this.calcModeLabel;
+    }
+
+    public final String getUser() {
+        return this.user;
+    }
+
+    public final RiverInfo getRiver() {
+        return this.river;
+    }
+
+    public final DoubleRange getCalcRange() {
+        return this.calcRange;
+    }
+}
\ No newline at end of file
diff -r 23945061daec -r bb929b444ea5 artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractCommonExporter.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractCommonExporter.java	Thu Jun 14 16:57:14 2018 +0200
@@ -0,0 +1,96 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
+ *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * 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.artifacts.common;
+
+import java.io.OutputStream;
+
+import org.apache.log4j.Logger;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.model.CalculationResult;
+import org.dive4elements.river.exports.AbstractExporter;
+import org.w3c.dom.Document;
+
+import au.com.bytecode.opencsv.CSVWriter;
+
+/**
+ * @author Gernot Belger
+ */
+public abstract class AbstractCommonExporter<RESULTS extends AbstractCalculationResults> extends AbstractExporter {
+
+    /** The log used in this exporter. */
+    private final Logger log = Logger.getLogger(getClass());
+
+    /** The log used in this exporter. */
+    protected final Logger getLog() {
+        return this.log;
+    }
+
+    private RESULTS results = null;
+
+    private ExportContextPDF helper;
+
+    @Override
+    public void init(final String outName, final Document request, final OutputStream out, final CallContext context) {
+        super.init(outName, request, out, context);
+
+        this.helper = new ExportContextPDF(context); // bleibt so asynchron zu ExportContextCSV - ist so beabsichtigt
+    }
+
+    protected final ExportContextPDF getHelper() {
+        return this.helper;
+    }
+
+    @Override
+    protected final void addData(final Object d) {
+        /* reset */
+        this.results = null;
+
+        if (d instanceof CalculationResult) {
+
+            final Object dat = ((CalculationResult) d).getData();
+            if (dat != null) {
+                @SuppressWarnings("unchecked")
+                final RESULTS result = (RESULTS) dat;
+                this.results = result;
+            }
+        }
+    }
+
+    protected final RESULTS getResults() {
+        return this.results;
+    }
+
+    protected final AbstractCalculationResults getResults2() {
+        return this.results;
+    }
+
+    @Override
+    protected final void writeCSVData(final CSVWriter writer) {
+        doWriteCSVData(writer, this.results);
+    }
+
+    protected abstract void doWriteCSVData(CSVWriter writer, RESULTS results);
+
+    /**
+     * Formats header with unit and label: msg [unit] (label)
+     */
+    // TODO: REMOVE, because it has moved to ExportContextCSV
+    protected final String msgUnitLabel(final String key, final String unit, final String label) {
+        final String msg = msg(key);
+        return String.format("%s [%s] (%s)", msg, unit, label);
+    }
+
+    @Override
+    protected final void writePDF(final OutputStream out) {
+        doWritePdf(out, this.results);
+    }
+
+    protected abstract void doWritePdf(OutputStream out, RESULTS results);
+}
\ No newline at end of file


More information about the Dive4Elements-commits mailing list