changeset 9112:189cc8ededbd

Added datacage select and chart display for river channel sizes loaded from database
author mschaefer
date Mon, 04 Jun 2018 08:36:09 +0200
parents ee77e544e890
children bfc0da2aa3aa
files artifacts/doc/conf/conf.xml artifacts/doc/conf/generators/longitudinal-diagram-defaults.xml artifacts/doc/conf/meta-data.xml artifacts/doc/conf/themes.xml artifacts/doc/conf/themes/default.xml artifacts/doc/conf/themes/second.xml artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/PredefinedChannelDepthProcessor.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/PredefinedChannelWidthProcessor.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoI18NStrings.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultType.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedchannel/PredefinedChannelAccess.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedchannel/PredefinedChannelArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedchannel/PredefinedChannelFacet.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedchannel/PredefinedChannelQueryCalculationResult.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefineddepthevol/PredefinedDepthEvolAccess.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedflowdepth/PredefinedFlowDepthColumnAccess.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedtkh/PredefinedTkhColumnAccess.java artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java artifacts/src/main/resources/messages.properties artifacts/src/main/resources/messages_de.properties backend/src/main/java/org/dive4elements/river/model/sinfo/Channel.java backend/src/main/java/org/dive4elements/river/model/sinfo/ChannelValue.java gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties
diffstat 25 files changed, 627 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/doc/conf/conf.xml	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/doc/conf/conf.xml	Mon Jun 04 08:36:09 2018 +0200
@@ -187,6 +187,9 @@
                 ttl="3600000"
                 artifact="org.dive4elements.river.artifacts.bundu.BUNDUArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
                 
+            <artifact-factory name="channelf" description="Factory to create an artifact used in sinfo datacage."
+                ttl="3600000"
+               artifact="org.dive4elements.river.artifacts.sinfo.predefinedchannel.PredefinedChannelArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
             <artifact-factory name="tkhxf" description="Factory to create an artifact used in sinfo datacage."
                 ttl="3600000"
                 artifact="org.dive4elements.river.artifacts.sinfo.predefinedtkh.PredefinedTkhArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
--- a/artifacts/doc/conf/generators/longitudinal-diagram-defaults.xml	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/doc/conf/generators/longitudinal-diagram-defaults.xml	Mon Jun 04 08:36:09 2018 +0200
@@ -56,6 +56,8 @@
     <processor class="org.dive4elements.river.artifacts.sinfo.common.FlowDepthDevelopmentProcessor" axis="flowdepthDevelopmentAxis"/>
     <processor class="org.dive4elements.river.artifacts.sinfo.common.FlowDepthDevelopmentPerYearProcessor" axis="flowdepthDevelopmentPerYearAxis"/>
     
+    <processor class="org.dive4elements.river.artifacts.sinfo.common.PredefinedChannelWidthProcessor" axis="Width"/>
+    <processor class="org.dive4elements.river.artifacts.sinfo.common.PredefinedChannelDepthProcessor" axis="flowdepthAxis"/>
     <processor class="org.dive4elements.river.artifacts.sinfo.common.PredefinedTkhProcessor" axis="tkhAxis"/>
     <processor class="org.dive4elements.river.artifacts.sinfo.common.PredefinedDepthEvolProcessor" axis="flowdepthDevelopmentAxis"/>
     <processor class="org.dive4elements.river.artifacts.sinfo.common.PredefinedDepthEvolPerYearProcessor" axis="flowdepthDevelopmentPerYearAxis"/>
--- a/artifacts/doc/conf/meta-data.xml	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/doc/conf/meta-data.xml	Mon Jun 04 08:36:09 2018 +0200
@@ -1614,6 +1614,10 @@
           <dc:call-macro name="sinfo_predefined_flowdepth-m"/>
         </sinfo_predefined_flowdepths>
 
+        <sinfo_predefined_channel>
+          <dc:call-macro name="sinfo_predefined_channel"/>
+        </sinfo_predefined_channel>
+
         <sinfo_predefined_tkh>
           <dc:call-macro name="sinfo_predefined_tkh-berechnung"/>
           <dc:call-macro name="sinfo_predefined_tkh-messung"/>
@@ -3411,6 +3415,28 @@
       </dc:filter>
     </dc:macro>
 
+    <!-- channel size imported from CSV-files for S-INFO -->
+    <dc:macro name="sinfo_predefined_channel">
+      <dc:context>
+        <dc:statement>
+          SELECT s.id AS id, MIN(s.filename) AS seriesname, MIN(v.station) AS km_min, MAX(v.station) AS km_max,
+          MIN(s.filename) || '&lt;br /&gt;'
+          || '[km ' || MIN(v.station) || ' - ' || MAX(v.station) || ']&lt;br /&gt;'
+          || MIN(s.year_from) || ' - ' || MIN(s.year_to) || '&lt;br /&gt;' AS info
+          FROM channel s INNER JOIN channel_values v ON s.id=v.channel_id
+          WHERE (s.river_id=${river_id})
+          AND (v.station BETWEEN ${fromkm}-0.0001 AND ${tokm}+0.0001)
+          GROUP BY s.id
+          ORDER BY MIN(s.year_to) DESC;
+        </dc:statement>
+        <dc:if test="dc:has-result()">
+          <dc:for-each>
+            <channelseries name="{$seriesname}" ids="channelx-{$id}-{$seriesname}" factory="channelf" target_out="{$out}" info="{$info}"/>
+          </dc:for-each>
+        </dc:if>
+      </dc:context>
+    </dc:macro>
+
     <!-- tkh imported from CSV-files for S-INFO -->
     <dc:macro name="sinfo_predefined_tkh-berechnung">
       <predefined_tkh_berechnung>
--- a/artifacts/doc/conf/themes.xml	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/doc/conf/themes.xml	Mon Jun 04 08:36:09 2018 +0200
@@ -441,6 +441,8 @@
         <mapping from="sinfo_facet_waterlevel_difference.filtered" to="SInfoWaterlevelDifference" />
         <mapping from="sinfo_facet_bedheight_difference.filtered" to="SInfoBedHeightDifference" />
         
+        <mapping from="sinfo_facet_predefined_channel_width" to="SInfoPredefinedChannelWidth" />
+        <mapping from="sinfo_facet_predefined_channel_depth" to="SInfoPredefinedChannelDepth" />
         <mapping from="sinfo_facet_predefined_tkh" to="SInfoPredefinedTkh" />
         <mapping from="sinfo_facet_predefined_depthevol" to="SInfoPredefinedDepthEvol" />
         <mapping from="sinfo_facet_predefined_depthevol_per_year" to="SInfoPredefinedDepthEvolPerYear" />
--- a/artifacts/doc/conf/themes/default.xml	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/doc/conf/themes/default.xml	Mon Jun 04 08:36:09 2018 +0200
@@ -2993,6 +2993,22 @@
             <field name="linecolor" type="Color" display="Linienfarbe" default="255, 0, 0" />
         </fields>
     </theme>
+    <theme name="SInfoPredefinedChannelWidth">
+        <inherits>
+            <inherit from="LongitudinalSectionW" />
+        </inherits>
+        <fields>
+            <field name="linecolor" type="Color" display="Linienfarbe" default="128, 64, 0" />
+        </fields>
+    </theme>
+    <theme name="SInfoPredefinedChannelDepth">
+        <inherits>
+            <inherit from="LongitudinalSectionW" />
+        </inherits>
+        <fields>
+            <field name="linecolor" type="Color" display="Linienfarbe" default="128, 64, 64" />
+        </fields>
+    </theme>
     <theme name="SInfoPredefinedTkh">
         <inherits>
             <inherit from="SInfoTkh" />
--- a/artifacts/doc/conf/themes/second.xml	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/doc/conf/themes/second.xml	Mon Jun 04 08:36:09 2018 +0200
@@ -2981,6 +2981,22 @@
             <field name="linecolor" type="Color" display="Linienfarbe" default="255, 0, 0" />
         </fields>
     </theme>            
+    <theme name="SInfoPredefinedChannelWidth">
+        <inherits>
+            <inherit from="LongitudinalSectionW" />
+        </inherits>
+        <fields>
+            <field name="linecolor" type="Color" display="Linienfarbe" default="128, 64, 0" />
+        </fields>
+    </theme>
+    <theme name="SInfoPredefinedChannelDepth">
+        <inherits>
+            <inherit from="LongitudinalSectionW" />
+        </inherits>
+        <fields>
+            <field name="linecolor" type="Color" display="Linienfarbe" default="128, 64, 64" />
+        </fields>
+    </theme>
     <theme name="SInfoPredefinedTkh">
         <inherits>
             <inherit from="SInfoTkh" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/PredefinedChannelDepthProcessor.java	Mon Jun 04 08:36:09 2018 +0200
@@ -0,0 +1,87 @@
+/** 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.sinfo.common;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.artifacts.CallMeta;
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.artifacts.sinfo.predefinedchannel.PredefinedChannelFacet;
+import org.dive4elements.river.artifacts.sinfo.predefinedchannel.PredefinedChannelQueryCalculationResult;
+import org.dive4elements.river.exports.DiagramGenerator;
+import org.dive4elements.river.exports.StyledSeriesBuilder;
+import org.dive4elements.river.jfree.StyledXYSeries;
+import org.dive4elements.river.themes.ThemeDocument;
+
+/**
+ * Processor to generate a data series for river channel depth data loaded from the database
+ *
+ * @author Matthias Schäfer
+ *
+ */
+public class PredefinedChannelDepthProcessor extends AbstractSInfoProcessor {
+
+    // private final static Logger log = Logger.getLogger(PredefinedChannelDepthProcessor.class);
+
+    public static final String FACET_PREDEFINED_CHANNEL_DEPTH = "sinfo_facet_predefined_channel_depth";
+
+    private static final String I18N_AXIS_LABEL = "sinfo.chart.flow_depth.section.yaxis.label";
+
+    private static final String I18N_SERIES_NAME_PATTERN = "predefinedchannel.depth.title";
+
+    private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
+
+    static {
+        HANDLED_FACET_TYPES.add(FACET_PREDEFINED_CHANNEL_DEPTH);
+    }
+
+    public PredefinedChannelDepthProcessor() {
+        super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
+    }
+
+    @Override
+    protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
+
+        final CallContext context = generator.getCallContext();
+        final Map<String, String> metaData = bundle.getFacet().getMetaData();
+
+        final Artifact artifact = bundle.getArtifact();
+
+        final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme);
+        series.putMetaData(metaData, artifact, context);
+
+        final String facetName = bundle.getFacetName();
+        final PredefinedChannelQueryCalculationResult data = (PredefinedChannelQueryCalculationResult) bundle.getData(context);
+        if (data == null) {
+            // Check has been here before so we keep it for security reasons
+            // this should never happen though.
+            throw new IllegalStateException("Data is null for facet: " + facetName);
+        }
+
+        final double[][] points = data.getStationPoints(SInfoResultType.channelDepth);
+
+        StyledSeriesBuilder.addPoints(series, points, true);
+        generator.addAxisSeries(series, getAxisName(), visible);
+
+        return metaData.get("Y");
+    }
+
+    public static Facet createFacet(final CallMeta callMeta, final String seriesName) {
+        return new PredefinedChannelFacet(FACET_PREDEFINED_CHANNEL_DEPTH,
+                Resources.getMsg(callMeta, I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, seriesName), I18N_AXIS_LABEL);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/PredefinedChannelWidthProcessor.java	Mon Jun 04 08:36:09 2018 +0200
@@ -0,0 +1,87 @@
+/** 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.sinfo.common;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.artifacts.CallMeta;
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.artifacts.sinfo.predefinedchannel.PredefinedChannelFacet;
+import org.dive4elements.river.artifacts.sinfo.predefinedchannel.PredefinedChannelQueryCalculationResult;
+import org.dive4elements.river.exports.DiagramGenerator;
+import org.dive4elements.river.exports.StyledSeriesBuilder;
+import org.dive4elements.river.jfree.StyledXYSeries;
+import org.dive4elements.river.themes.ThemeDocument;
+
+/**
+ * Processor to generate a data series for river channel width data loaded from the database
+ *
+ * @author Matthias Schäfer
+ *
+ */
+public class PredefinedChannelWidthProcessor extends AbstractSInfoProcessor {
+
+    // private final static Logger log = Logger.getLogger(PredefinedChannelWidthProcessor.class);
+
+    public static final String FACET_PREDEFINED_CHANNEL_WIDTH = "sinfo_facet_predefined_channel_width";
+
+    private static final String I18N_AXIS_LABEL = "sinfo.chart.channel_width.section.yaxis.label";
+
+    private static final String I18N_SERIES_NAME_PATTERN = "predefinedchannel.width.title";
+
+    private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
+
+    static {
+        HANDLED_FACET_TYPES.add(FACET_PREDEFINED_CHANNEL_WIDTH);
+    }
+
+    public PredefinedChannelWidthProcessor() {
+        super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
+    }
+
+    @Override
+    protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
+
+        final CallContext context = generator.getCallContext();
+        final Map<String, String> metaData = bundle.getFacet().getMetaData();
+
+        final Artifact artifact = bundle.getArtifact();
+
+        final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme);
+        series.putMetaData(metaData, artifact, context);
+
+        final String facetName = bundle.getFacetName();
+        final PredefinedChannelQueryCalculationResult data = (PredefinedChannelQueryCalculationResult) bundle.getData(context);
+        if (data == null) {
+            // Check has been here before so we keep it for security reasons
+            // this should never happen though.
+            throw new IllegalStateException("Data is null for facet: " + facetName);
+        }
+
+        final double[][] points = data.getStationPoints(SInfoResultType.channelWidth);
+
+        StyledSeriesBuilder.addPoints(series, points, true);
+        generator.addAxisSeries(series, getAxisName(), visible);
+
+        return metaData.get("Y");
+    }
+
+    public static Facet createFacet(final CallMeta callMeta, final String seriesName) {
+        return new PredefinedChannelFacet(FACET_PREDEFINED_CHANNEL_WIDTH,
+                Resources.getMsg(callMeta, I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, seriesName), I18N_AXIS_LABEL);
+    }
+}
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoI18NStrings.java	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoI18NStrings.java	Mon Jun 04 08:36:09 2018 +0200
@@ -20,7 +20,7 @@
     String CSV_META_HEADER_WATERLEVEL_GAUGE = "sinfo.export.flow_depth.csv.meta.header.waterlevel.gauge";
 
     String CSV_META_HEADER_WATERLEVEL_YEAR = "sinfo.export.flow_depth.csv.meta.header.waterlevel.year";
-    
+
     String CSV_META_HEADER_EVALUATOR = "sinfo.export.flow_depth.csv.meta.header.sounding.evaluator";
 
     String CSV_MEAN_BED_HEIGHT_HEADER = "sinfo.export.flow_depth.csv.header.mean_bed_height";
@@ -53,6 +53,10 @@
 
     String CSV_TKHKIND_HEADER = "sinfo.export.tkh.csv.header.tkhkind";
 
+    String CSV_CHANNEL_WIDTH_HEADER = "sinfo.export.csv.header.channel.width";
+
+    String CSV_CHANNEL_DEPTH_HEADER = "sinfo.export.csv.header.channel.depth";
+
     String CSV_FLOWDEPTH_DEVELOPMENT_HEADER = "sinfo.export.csv.header.flowdepth.development";
 
     String PDF_FLOWDEPTH_DEVELOPMENT_HEADER = "sinfo.export.pdf.header.flowdepth.development";
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultType.java	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultType.java	Mon Jun 04 08:36:09 2018 +0200
@@ -330,6 +330,36 @@
         }
     };
 
+    public static final SInfoResultType channelWidth = new SInfoResultType(I18NStrings.UNIT_M, SInfoI18NStrings.CSV_CHANNEL_WIDTH_HEADER) {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public String exportValue(final CallContext context, final Object value) {
+            final double doubleValue = asDouble(value);
+            return exportDoubleValue(context, doubleValue);
+        }
+
+        @Override
+        protected NumberFormat createFormatter(final CallContext context) {
+            return Formatter.getChannelWidth(context);
+        }
+    };
+
+    public static final SInfoResultType channelDepth = new SInfoResultType(I18NStrings.UNIT_M, SInfoI18NStrings.CSV_CHANNEL_DEPTH_HEADER) {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public String exportValue(final CallContext context, final Object value) {
+            final double doubleValue = asDouble(value);
+            return exportDoubleValue(context, doubleValue);
+        }
+
+        @Override
+        protected NumberFormat createFormatter(final CallContext context) {
+            return Formatter.getChannelDepth(context);
+        }
+    };
+
     public static final SInfoResultType flowdepthDevelopment = new SInfoResultType(I18NStrings.UNIT_M, SInfoI18NStrings.CSV_FLOWDEPTH_DEVELOPMENT_HEADER,
             SInfoI18NStrings.PDF_FLOWDEPTH_DEVELOPMENT_HEADER) {
         private static final long serialVersionUID = 1L;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedchannel/PredefinedChannelAccess.java	Mon Jun 04 08:36:09 2018 +0200
@@ -0,0 +1,50 @@
+/** 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.sinfo.predefinedchannel;
+
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.RangeAccess;
+
+/**
+ * Access to the database loaded channel artifact data
+ *
+ * @author Matthias Schäfer
+ */
+final class PredefinedChannelAccess extends RangeAccess {
+
+    /***** FIELDS *****/
+
+    private Integer id;
+
+    private String name;
+
+    /***** CONSTRUCTORS *****/
+
+    public PredefinedChannelAccess(final D4EArtifact artifact) {
+        super(artifact);
+    }
+
+    /***** METHODS *****/
+
+    public Integer getId() {
+        if (this.id == null) {
+            this.id = getInteger("channel_id");
+        }
+        return this.id;
+    }
+
+    public String getName() {
+        if (this.name == null) {
+            this.name = getString("name");
+        }
+        return this.name;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedchannel/PredefinedChannelArtifact.java	Mon Jun 04 08:36:09 2018 +0200
@@ -0,0 +1,128 @@
+/** 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.sinfo.predefinedchannel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.dive4elements.artifactdatabase.state.DefaultOutput;
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifactdatabase.state.FacetActivity;
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.ArtifactFactory;
+import org.dive4elements.artifacts.CallMeta;
+import org.dive4elements.artifacts.common.utils.XMLUtils;
+import org.dive4elements.river.artifacts.AbstractStaticStateArtifact;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.artifacts.sinfo.common.PredefinedChannelDepthProcessor;
+import org.dive4elements.river.artifacts.sinfo.common.PredefinedChannelWidthProcessor;
+import org.dive4elements.river.artifacts.states.StaticState;
+import org.w3c.dom.Document;
+
+/**
+ * Display of a river channel data series loaded from database
+ *
+ * @author Matthias Schäfer
+ *
+ */
+public class PredefinedChannelArtifact extends AbstractStaticStateArtifact implements FacetTypes {
+
+    /** The log for this class. */
+    private static Logger log = Logger.getLogger(PredefinedChannelArtifact.class);
+
+    /** Artifact name. */
+    private static final String NAME = "channel";
+
+    static {
+        // TODO: Move to configuration.
+        FacetActivity.Registry.getInstance().register(NAME, FacetActivity.INACTIVE);
+    }
+
+    public static final String STATIC_STATE_NAME = "state.predefined_channel.static";
+
+    /**
+     * Trivial Constructor.
+     */
+    public PredefinedChannelArtifact() {
+        log.debug("new PredefinedChannelArtifact");
+    }
+
+    @Override
+    public String getName() {
+        return NAME;
+    }
+
+    /**
+     * Gets called from factory, to set things up.
+     */
+    @Override
+    public void setup(final String identifier, final ArtifactFactory factory, final Object context, final CallMeta callMeta, final Document data,
+            final List<Class> loadFacets) {
+
+        log.debug("PredefinedChannelArtifact.setup");
+
+        if (log.isDebugEnabled()) {
+            log.debug(XMLUtils.toString(data));
+        }
+
+        final String code = getDatacageIDValue(data);
+        final String seriesName = (code.split("-").length >= 3) ? code.split("-", 3)[2] : "name?";
+
+        createFacets(callMeta, code, seriesName);
+
+        super.setup(identifier, factory, context, callMeta, data, loadFacets);
+    }
+
+    private void createFacets(final CallMeta callMeta, final String code, final String seriesName) {
+        if (code == null)
+            return;
+        final String[] parts = code.split("-");
+        if (parts.length < 2) {
+            log.error("Invalid datacage ID '" + code + "'");
+            return;
+        }
+        addStringData("channel_id", parts[1]);
+        final ArrayList<Facet> facets = new ArrayList<>(2);
+        facets.add(PredefinedChannelDepthProcessor.createFacet(callMeta, seriesName));
+        facets.add(PredefinedChannelWidthProcessor.createFacet(callMeta, seriesName));
+        addFacets(STATIC_STATE_NAME, facets);
+    }
+
+    @Override
+    protected void initStaticState() {
+
+        log.debug("initStaticState " + getName() + " " + identifier());
+
+        final StaticState state = new StaticState(STATIC_STATE_NAME);
+        final DefaultOutput output = new DefaultOutput("general", "general", "image/png", "chart");
+
+        final List<Facet> facets = getFacets(STATIC_STATE_NAME);
+        output.addFacets(facets);
+        state.addOutput(output);
+
+        setStaticState(state);
+    }
+
+    @Override
+    protected void initialize(final Artifact artifact, final Object context, final CallMeta meta) {
+        // do not clone facets, etc. from master artifact
+
+        log.debug("initialize");
+        importData((D4EArtifact) artifact, "river");
+        importData((D4EArtifact) artifact, "ld_from");
+        importData((D4EArtifact) artifact, "ld_to");
+
+        log.debug("ld_from " + getDataAsString("ld_from"));
+        log.debug("ld_to " + getDataAsString("ld_to"));
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedchannel/PredefinedChannelFacet.java	Mon Jun 04 08:36:09 2018 +0200
@@ -0,0 +1,81 @@
+/** 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.sinfo.predefinedchannel;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.common.GeneralResultType;
+import org.dive4elements.river.artifacts.common.ResultRow;
+import org.dive4elements.river.artifacts.model.BlackboardDataFacet;
+import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
+import org.dive4elements.river.model.sinfo.Channel;
+import org.dive4elements.river.model.sinfo.ChannelValue;
+
+/**
+ * Facet for a river channel value series loaded from the database
+ *
+ * @author Matthias Schäfer
+ */
+public class PredefinedChannelFacet extends BlackboardDataFacet implements FacetTypes {
+
+    private static final long serialVersionUID = 56753318291306671L;
+
+    public PredefinedChannelFacet(final String name, final String description, final String yAxisLabel) {
+        super(0, name, description);
+
+        this.metaData.put("X", "chart.longitudinal.section.xaxis.label");
+        this.metaData.put("Y", yAxisLabel);
+    }
+
+    /**
+     * Returns the data this facet requires.
+     *
+     * @param artifact
+     *            the owner artifact.
+     * @param context
+     *            the CallContext (ignored).
+     *
+     * @return
+     *         the data as PredefinedChannelWidthQueryCalculationResult
+     */
+    @Override
+    public Object getData(final Artifact artifact, final CallContext context) {
+
+        final PredefinedChannelAccess access = new PredefinedChannelAccess((D4EArtifact) artifact);
+        final Channel series = Channel.getSeries(access.getId());
+        final List<ChannelValue> values = ChannelValue.getValues(series, access.getFrom(true), access.getTo(true));
+        final Collection<ResultRow> rows = new ArrayList<>();
+        for (final ChannelValue value : values) {
+            rows.add(ResultRow.create().putValue(GeneralResultType.station, value.getStation()) //
+                    .putValue(SInfoResultType.channelWidth, value.getWidth()) //
+                    .putValue(SInfoResultType.channelDepth, value.getDepth()));
+        }
+        return new PredefinedChannelQueryCalculationResult(series.getFilename(), rows);
+    }
+
+    /**
+     * Create a deep copy of this Facet.
+     *
+     * @return a deep copy.
+     */
+    @Override
+    public PredefinedChannelFacet deepCopy() {
+        final PredefinedChannelFacet copy = new PredefinedChannelFacet(this.name, this.description, this.metaData.get("Y"));
+        copy.set(this);
+        return copy;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedchannel/PredefinedChannelQueryCalculationResult.java	Mon Jun 04 08:36:09 2018 +0200
@@ -0,0 +1,29 @@
+/* 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.sinfo.predefinedchannel;
+
+import java.util.Collection;
+
+import org.dive4elements.river.artifacts.common.ResultRow;
+import org.dive4elements.river.artifacts.sinfo.common.AbstractSInfoCalculationResult;
+
+/**
+ * Contains the results of a database query of a river channel width series
+ *
+ * @author Matthias Schäfer
+ */
+public final class PredefinedChannelQueryCalculationResult extends AbstractSInfoCalculationResult {
+
+    private static final long serialVersionUID = 1L;
+
+    public PredefinedChannelQueryCalculationResult(final String label, final Collection<ResultRow> rows) {
+        super(label, null, rows);
+    }
+}
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefineddepthevol/PredefinedDepthEvolAccess.java	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefineddepthevol/PredefinedDepthEvolAccess.java	Mon Jun 04 08:36:09 2018 +0200
@@ -32,7 +32,7 @@
         super(artifact);
     }
 
-    /***** METHDOS *****/
+    /***** METHODS *****/
 
     public Integer getId() {
         if (this.id == null) {
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedflowdepth/PredefinedFlowDepthColumnAccess.java	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedflowdepth/PredefinedFlowDepthColumnAccess.java	Mon Jun 04 08:36:09 2018 +0200
@@ -34,7 +34,7 @@
         super(artifact);
     }
 
-    /***** METHDOS *****/
+    /***** METHODS *****/
 
     public Integer getSeriesId() {
         if (this.seriesId == null) {
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedtkh/PredefinedTkhColumnAccess.java	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedtkh/PredefinedTkhColumnAccess.java	Mon Jun 04 08:36:09 2018 +0200
@@ -34,7 +34,7 @@
         super(artifact);
     }
 
-    /***** METHDOS *****/
+    /***** METHODS *****/
 
     public Integer getTkhId() {
         if (this.tkhId == null) {
--- a/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java	Mon Jun 04 08:36:09 2018 +0200
@@ -391,6 +391,14 @@
         return getFormatter(meta, 2, 2);
     }
 
+    public static NumberFormat getChannelWidth(final CallContext context) {
+        return getFormatter(context.getMeta(), 2, 2);
+    }
+
+    public static NumberFormat getChannelDepth(final CallContext context) {
+        return getFormatter(context.getMeta(), 2, 2);
+    }
+
     public static NumberFormat getFlowDepthDevelopmentPerYear(final CallContext context) {
         return getFormatter(context.getMeta(), 2, 2);
     }
--- a/artifacts/src/main/resources/messages.properties	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/src/main/resources/messages.properties	Mon Jun 04 08:36:09 2018 +0200
@@ -1012,6 +1012,8 @@
 sinfo.export.csv.meta.header.sounding.historical = ##METADATEN PEILUNG historisch
 sinfo.export.csv.meta.header.waterlevel.current = ##METADATEN WASSERSPIEGELLAGE aktuell
 sinfo.export.csv.meta.header.waterlevel.historical = ##METADATEN WASSERSPIEGELLAGE historisch																			
+sinfo.export.csv.header.channel.width = Sollbreite Fahrrinne
+sinfo.export.csv.header.channel.depth = Solltiefe Fahrrinne
 sinfo.export.csv.header.flowdepth.development = Flie\u00dftiefenentwicklung
 sinfo.export.pdf.header.flowdepth.development = Flie\u00dftiefen-entwicklung
 sinfo.export.csv.header.flowdepth.development.per.year = Flie\u00dftiefenent-wicklung pro Jahr
@@ -1077,6 +1079,12 @@
 
 predefineddepthevol.total.title = Gesamt: {0}
 predefineddepthevol.peryear.title = J\u00e4hrlich: {0}
+ 
+predefinedchannel.width.title = Sollbreite Fahrrinne
+predefinedchannel.depth.title = Solltiefe Fahrrinne
+
+sinfo.chart.channel_width.section.yaxis.label = Sollbreite Fahrrinne [m]
+sinfo.chart.channel_depth.section.yaxis.label = Solltiefe Fahrrinne [m]
 
 bundu_bezugswst = Bezugswasserst\u00e4nde
 bundu_analysis = Fixinganalysis
--- a/artifacts/src/main/resources/messages_de.properties	Mon Jun 04 08:32:25 2018 +0200
+++ b/artifacts/src/main/resources/messages_de.properties	Mon Jun 04 08:36:09 2018 +0200
@@ -1012,6 +1012,8 @@
 sinfo.export.csv.meta.header.sounding.historical = ##METADATEN PEILUNG historisch
 sinfo.export.csv.meta.header.waterlevel.current = ##METADATEN WASSERSPIEGELLAGE aktuell
 sinfo.export.csv.meta.header.waterlevel.historical = ##METADATEN WASSERSPIEGELLAGE historisch
+sinfo.export.csv.header.channel.width = Sollbreite Fahrrinne
+sinfo.export.csv.header.channel.depth = Solltiefe Fahrrinne
 sinfo.export.pdf.header.flowdepth.development = Flie\u00dftiefen-entwicklung
 sinfo.export.csv.header.flowdepth.development = Flie\u00dftiefenentwicklung																			
 sinfo.export.csv.header.flowdepth.development.per.year = Flie\u00dftiefenent-wicklung pro Jahr
@@ -1077,7 +1079,13 @@
 
 predefineddepthevol.total.title = Gesamt: {0}
 predefineddepthevol.peryear.title = J\u00e4hrlich: {0}
- 
+
+sinfo.chart.channel_width.section.yaxis.label = Sollbreite Fahrrinne [m]
+sinfo.chart.channel_depth.section.yaxis.label = Solltiefe Fahrrinne [m]
+
+predefinedchannel.width.title = Sollbreite Fahrrinne
+predefinedchannel.depth.title = Solltiefe Fahrrinne
+
 bundu_bezugswst = Bezugswasserst\u00e4nde
 bundu_analysis = Fixierungsanalyse
 bundu_vollmer = ausgelagerte Wasserspiegellage
--- a/backend/src/main/java/org/dive4elements/river/model/sinfo/Channel.java	Mon Jun 04 08:32:25 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/Channel.java	Mon Jun 04 08:36:09 2018 +0200
@@ -25,7 +25,10 @@
 import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
 
+import org.dive4elements.river.backend.SessionHolder;
 import org.dive4elements.river.model.River;
+import org.hibernate.Query;
+import org.hibernate.Session;
 
 /**
  * Hibernate binding for the DB table channel
@@ -157,4 +160,14 @@
     public void addValue(final ChannelValue value) {
         this.values.add(value);
     }
+
+    /**
+     * Get data series by id
+     */
+    public static Channel getSeries(final int id) {
+        final Session session = SessionHolder.HOLDER.get();
+        final Query query = session.createQuery("FROM Channel WHERE (id=:id)");
+        query.setParameter("id", id);
+        return (Channel) query.list().get(0);
+    }
 }
\ No newline at end of file
--- a/backend/src/main/java/org/dive4elements/river/model/sinfo/ChannelValue.java	Mon Jun 04 08:32:25 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/ChannelValue.java	Mon Jun 04 08:36:09 2018 +0200
@@ -11,6 +11,7 @@
 package org.dive4elements.river.model.sinfo;
 
 import java.io.Serializable;
+import java.util.List;
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -22,6 +23,10 @@
 import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
 
+import org.dive4elements.river.backend.SessionHolder;
+import org.hibernate.Query;
+import org.hibernate.Session;
+
 
 /**
  * Hibernate binding for the DB table channel_values
@@ -118,4 +123,17 @@
     public void setDepth(final Double depth) {
         this.depth = depth;
     }
+
+    /**
+     * Selects the channel size values of a data series in a km range from the database
+     */
+    public static List<ChannelValue> getValues(final Channel parent, final double kmLo, final double kmHi) {
+        final Session session = SessionHolder.HOLDER.get();
+        final Query query = session.createQuery("FROM ChannelValue WHERE (channel=:parent)"
+                + " AND (station >= :kmLo - 0.0001) AND (station <= :kmHi + 0.0001)");
+        query.setParameter("parent", parent);
+        query.setParameter("kmLo", new Double(kmLo));
+        query.setParameter("kmHi", new Double(kmHi));
+        return query.list();
+    }
 }
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java	Mon Jun 04 08:32:25 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java	Mon Jun 04 08:36:09 2018 +0200
@@ -1483,6 +1483,8 @@
 
     String sinfo_additional_ls_withoutQ();
 
+    String sinfo_predefined_channel();
+
     String sinfo_predefined_tkh();
 
     String predefined_tkh_berechnung();
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties	Mon Jun 04 08:32:25 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties	Mon Jun 04 08:36:09 2018 +0200
@@ -790,6 +790,8 @@
 sinfo_additional_ls_withQ = mit Abfluss
 sinfo_additional_ls_withoutQ = ohne Abfluss
 
+sinfo_predefined_channel = Zu gew\u00e4hrleistende Fahrrinnenverh\u00e4ltnisse
+
 sinfo_predefined_tkh = Transportk\u00f6rperh\u00f6hen
 predefined_tkh_berechnung = Berechnungsergebnisse
 predefined_tkh_messung = Naturmessungen
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties	Mon Jun 04 08:32:25 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties	Mon Jun 04 08:36:09 2018 +0200
@@ -790,6 +790,8 @@
 sinfo_additional_ls_withQ = mit Abfluss
 sinfo_additional_ls_withoutQ = ohne Abfluss
 
+sinfo_predefined_channel = Zu gew\u00e4hrleistende Fahrrinnenverh\u00e4ltnisse
+
 sinfo_predefined_tkh = Transportk\u00f6rperh\u00f6hen
 predefined_tkh_berechnung = Berechnungsergebnisse
 predefined_tkh_messung = Naturmessungen

http://dive4elements.wald.intevation.org