[PATCH] Distinguish between csv and pdf column headers

Wald Commits scm-commit at wald.intevation.org
Wed Mar 14 18:34:39 CET 2018


# HG changeset patch
# User gernotbelger
# Date 1521048874 -3600
# Node ID 09e4a4909814faeb2ff56a709ed8e684e0a8ace9
# Parent  a4f1ac81f26db2eb4f7fb18209e58abe591c4052
Distinguish between csv and pdf column headers

diff -r a4f1ac81f26d -r 09e4a4909814 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/SInfoI18NStrings.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/SInfoI18NStrings.java	Wed Mar 14 14:10:32 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/SInfoI18NStrings.java	Wed Mar 14 18:34:34 2018 +0100
@@ -40,6 +40,8 @@
 
     String CSV_MEAN_BED_HEIGHT_HEADER = "sinfo.export.flow_depth.csv.header.mean_bed_height";
 
+    String CSV_MEAN_BED_HEIGHT_HEADER_SHORT = "sinfo.export.flow_depth.csv.header.mean_bed_height.short";
+
     String CSV_WATERLEVEL_HEADER = "sinfo.export.flow_depth.csv.header.waterlevel";
 
     String CSV_DISCHARGE_HEADER = "sinfo.export.flow_depth.csv.header.discharge";
@@ -62,6 +64,8 @@
 
     String CSV_TKH_HEADER = "sinfo.export.tkh.csv.header.tkh";
 
+    String CSV_TKH_HEADER_SHORT = "sinfo.export.flow_depth.csv.header.tkh";
+
     String CSV_TKHKIND_HEADER = "sinfo.export.tkh.csv.header.tkhkind";
 
     String CSV_META_HEADER_WATERLEVEL = "sinfo.export.flow_depth.csv.meta.header.waterlevel";
@@ -78,8 +82,6 @@
 
     String CSV_META_HEIGHT_UNIT_RIVER = "sinfo.export.flow_depth.csv.meta.height_unit.river";
 
-    String CSV_MEAN_BED_HEIGHT_HEADER_SHORT = "sinfo.export.flow_depth.csv.header.mean_bed_height.short";
-
     String PREFIX_TKH_KIND = "sinfo.export.tkh.soilkind.";
 
     String UNIT_NONE = "-";
diff -r a4f1ac81f26d -r 09e4a4909814 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultType.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultType.java	Wed Mar 14 14:10:32 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultType.java	Wed Mar 14 18:34:34 2018 +0100
@@ -84,7 +84,9 @@
         }
     },
 
-    meanBedHeight(null, SInfoI18NStrings.CSV_MEAN_BED_HEIGHT_HEADER) {
+    // FIXME: use pgetPdfHeader instead of getCsvHeader
+
+    meanBedHeight(null, SInfoI18NStrings.CSV_MEAN_BED_HEIGHT_HEADER, SInfoI18NStrings.CSV_MEAN_BED_HEIGHT_HEADER_SHORT) {
         @Override
         public String exportValue(final CallContext context, final Object value) {
             final double doubleValue = asDouble(value);
@@ -224,7 +226,7 @@
             throw new UnsupportedOperationException();
         }
     },
-    tkh(SInfoI18NStrings.UNIT_CM, SInfoI18NStrings.CSV_TKH_HEADER) {
+    tkh(SInfoI18NStrings.UNIT_CM, SInfoI18NStrings.CSV_TKH_HEADER, SInfoI18NStrings.CSV_TKH_HEADER_SHORT) {
         @Override
         public String exportValue(final CallContext context, final Object value) {
             final double doubleValue = asDouble(value);
@@ -280,9 +282,16 @@
 
     private final String csvHeader;
 
-    private SInfoResultType(final String untit, final String csvHeader) {
-        this.unit = untit;
+    private final String pdfHeader;
+
+    private SInfoResultType(final String unit, final String csvAndPdfHeader) {
+        this(unit, csvAndPdfHeader, csvAndPdfHeader);
+    }
+
+    private SInfoResultType(final String unit, final String csvHeader, final String pdfHeader) {
+        this.unit = unit;
         this.csvHeader = csvHeader;
+        this.pdfHeader = pdfHeader;
     }
 
     public abstract String exportValue(final CallContext context, final Object value);
@@ -333,6 +342,10 @@
         return this.csvHeader;
     }
 
+    public String getPdfHeader(final CallMeta meta) {
+        return Resources.getMsg(meta, this.pdfHeader, this.pdfHeader);
+    }
+
     public final String getUnit() {
         return this.unit;
     }
diff -r a4f1ac81f26d -r 09e4a4909814 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthExporter.java	Wed Mar 14 14:10:32 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthExporter.java	Wed Mar 14 18:34:34 2018 +0100
@@ -137,18 +137,17 @@
         super.addJRMetaDataDefaults(source, results);
 
         /* column headings */
-
-        source.addMetaData("station_header", msg(SInfoResultType.station.getCsvHeader()));
-        source.addMetaData("flowdepth_header", msg(SInfoResultType.flowdepth.getCsvHeader()));
-        source.addMetaData("flowdepth_tkh_header", msg(SInfoResultType.flowdepthtkh.getCsvHeader()));
-        source.addMetaData("tkh_header", msg(SInfoResultType.tkh.getCsvHeader()));
-        source.addMetaData("waterlevel_header", msg(SInfoResultType.waterlevel.getCsvHeader()));
-        source.addMetaData("discharge_header", msg(SInfoResultType.discharge.getCsvHeader()));
-        source.addMetaData("waterlevel_name_header", msg(SInfoResultType.waterlevelLabel.getCsvHeader()));
-        source.addMetaData("gauge_header", msg(SInfoResultType.gaugeLabel.getCsvHeader()));
-        source.addMetaData("bedheight_header", msg(SInfoResultType.meanBedHeight.getCsvHeader()));
-        source.addMetaData("sounding_name_header", msg(SInfoResultType.soundingLabel.getCsvHeader()));
-        source.addMetaData("location_header", msg(SInfoResultType.location.getCsvHeader()));
+        source.addMetaData("station_header", SInfoResultType.station.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("flowdepth_header", SInfoResultType.flowdepth.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("flowdepth_tkh_header", SInfoResultType.flowdepthtkh.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("tkh_header", SInfoResultType.tkh.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("waterlevel_header", SInfoResultType.waterlevel.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("discharge_header", SInfoResultType.discharge.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("waterlevel_name_header", SInfoResultType.waterlevelLabel.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("gauge_header", SInfoResultType.gaugeLabel.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("bedheight_header", SInfoResultType.meanBedHeight.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("sounding_name_header", SInfoResultType.soundingLabel.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("location_header", SInfoResultType.location.getPdfHeader(this.context.getMeta()));
     }
 
     @Override
diff -r a4f1ac81f26d -r 09e4a4909814 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxExporter.java	Wed Mar 14 14:10:32 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxExporter.java	Wed Mar 14 18:34:34 2018 +0100
@@ -136,16 +136,16 @@
         super.addJRMetaDataDefaults(source, results);
 
         /* column headings */
-        source.addMetaData("station_header", msg(SInfoResultType.station.getCsvHeader()));
-        source.addMetaData("flowdepthmin_header", msg(SInfoResultType.flowdepthmin.getCsvHeader()));
-        source.addMetaData("flowdepthmax_header", msg(SInfoResultType.flowdepthmax.getCsvHeader()));
-        source.addMetaData("waterlevel_header", msg(SInfoResultType.waterlevel.getCsvHeader()));
-        source.addMetaData("discharge_header", msg(SInfoResultType.discharge.getCsvHeader()));
-        source.addMetaData("waterlevel_name_header", msg(SInfoResultType.waterlevelLabel.getCsvHeader()));
-        source.addMetaData("gauge_header", msg(SInfoResultType.gaugeLabel.getCsvHeader()));
-        source.addMetaData("bedheight_header", msg(SInfoResultType.meanBedHeight.getCsvHeader()));
-        source.addMetaData("sounding_name_header", msg(SInfoResultType.soundingLabel.getCsvHeader()));
-        source.addMetaData("location_header", msg(SInfoResultType.location.getCsvHeader()));
+        source.addMetaData("station_header", SInfoResultType.station.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("flowdepthmin_header", SInfoResultType.flowdepthmin.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("flowdepthmax_header", SInfoResultType.flowdepthmax.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("waterlevel_header", SInfoResultType.waterlevel.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("discharge_header", SInfoResultType.discharge.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("waterlevel_name_header", SInfoResultType.waterlevelLabel.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("gauge_header", SInfoResultType.gaugeLabel.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("bedheight_header", SInfoResultType.meanBedHeight.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("sounding_name_header", SInfoResultType.soundingLabel.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("location_header", SInfoResultType.location.getPdfHeader(this.context.getMeta()));
     }
 
     @Override
diff -r a4f1ac81f26d -r 09e4a4909814 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhExporter.java	Wed Mar 14 14:10:32 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhExporter.java	Wed Mar 14 18:34:34 2018 +0100
@@ -38,9 +38,6 @@
 
     private static final String CSV_META_CALCULATION_FORMULA = "sinfo.export.tkh.calculation.formula";
 
-    // FIXME: use pgetPdfHeader instead of getCsvHeader
-    private static final String CSV_MEAN_BED_HEIGHT_HEADER_SHORT = "sinfo.export.flow_depth.csv.header.mean_bed_height.short";
-
     private static final String JASPER_FILE = "/jasper/sinfo.flowdepth.jasper";
 
     @Override
@@ -144,20 +141,21 @@
         super.addJRMetaDataDefaults(source, results);
 
         /* column headings */
-        source.addMetaData("station_header", msg( SInfoResultType.station.getCsvHeader()));
-        source.addMetaData("tkh_header", msg(SInfoResultType.tkh.getCsvHeader()));
-        source.addMetaData("bedheight_header", msg(SInfoResultType.meanBedHeight.getCsvHeader()));
-        source.addMetaData("waterlevel_header", msg(SInfoResultType.waterlevel.getCsvHeader()));
-        source.addMetaData("discharge_header", msg(SInfoResultType.discharge.getCsvHeader()));
+        source.addMetaData("station_header", SInfoResultType.station.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("tkh_header", SInfoResultType.tkh.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("bedheight_header", SInfoResultType.meanBedHeight.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("waterlevel_header", SInfoResultType.waterlevel.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("discharge_header", SInfoResultType.discharge.getPdfHeader(this.context.getMeta()));
 
         // REMARK: actually the column makes no sense if description header is null. But (software symmetry...) WINFO also
         // writes an empty column into the pdf in that case (most probably to avoid the need for two jasper templates).
         final String descriptionHeader = results.getDescriptionHeader();
-        final String waterlevelNameHeader = descriptionHeader == null ? msg(SInfoResultType.waterlevelLabel.getCsvHeader()) : descriptionHeader;
+        final String waterlevelNameHeader = descriptionHeader == null ? SInfoResultType.waterlevelLabel.getPdfHeader(this.context.getMeta())
+                : descriptionHeader;
         source.addMetaData("waterlevel_name_header", waterlevelNameHeader);
 
-        source.addMetaData("gauge_header", msg(SInfoResultType.gaugeLabel.getCsvHeader()));
-        source.addMetaData("location_header", msg(SInfoResultType.location.getCsvHeader()));
+        source.addMetaData("gauge_header", SInfoResultType.gaugeLabel.getPdfHeader(this.context.getMeta()));
+        source.addMetaData("location_header", SInfoResultType.location.getPdfHeader(this.context.getMeta()));
     }
 
     @Override


More information about the Dive4Elements-commits mailing list