[PATCH 1 of 2] Renaming (predefined...) and own package for database loaded S-Info series of collisions and infrastructure height

Wald Commits scm-commit at wald.intevation.org
Mon Aug 6 11:51:33 CEST 2018


# HG changeset patch
# User mschaefer
# Date 1533548929 -7200
# Node ID e8d65cecc950cdad8d6a5057c2fe2c4789b85ed4
# Parent  f318359b81a26fd8a245c3c9c11b4a2dd2619806
Renaming (predefined...) and own package for database loaded S-Info series of collisions and infrastructure height

diff -r f318359b81a2 -r e8d65cecc950 artifacts/doc/conf/conf.xml
--- a/artifacts/doc/conf/conf.xml	Fri Aug 03 17:02:38 2018 +0200
+++ b/artifacts/doc/conf/conf.xml	Mon Aug 06 11:48:49 2018 +0200
@@ -201,10 +201,10 @@
                artifact="org.dive4elements.river.artifacts.sinfo.predefinedflowdepth.PredefinedFlowDepthArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
             <artifact-factory name="infrastructuref" description="Factory to create an artifact used in sinfo datacage."
                 ttl="3600000"
-               artifact="org.dive4elements.river.artifacts.sinfo.flood_duration.InfrastructureArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
+               artifact="org.dive4elements.river.artifacts.sinfo.predefinedinfrastructure.PredefinedInfrastructureArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
             <artifact-factory name="collisionf" description="Factory to create an artifact used in sinfo datacage."
                 ttl="3600000"
-               artifact="org.dive4elements.river.artifacts.sinfo.collision.CollisionArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
+               artifact="org.dive4elements.river.artifacts.sinfo.predefinedcollision.PredefinedCollisionArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
                 
         </artifact-factories>
 
diff -r f318359b81a2 -r e8d65cecc950 artifacts/doc/conf/generators/longitudinal-diagram-defaults.xml
--- a/artifacts/doc/conf/generators/longitudinal-diagram-defaults.xml	Fri Aug 03 17:02:38 2018 +0200
+++ b/artifacts/doc/conf/generators/longitudinal-diagram-defaults.xml	Mon Aug 06 11:48:49 2018 +0200
@@ -67,8 +67,8 @@
     <processor class="org.dive4elements.river.artifacts.sinfo.common.PredefinedDepthEvolProcessor" axis="flowdepthDevelopmentAxis"/>
     <processor class="org.dive4elements.river.artifacts.sinfo.common.PredefinedDepthEvolPerYearProcessor" axis="flowdepthDevelopmentPerYearAxis"/>
     <processor class="org.dive4elements.river.artifacts.sinfo.common.PredefinedFlowDepthProcessor" axis="flowdepthAxis"/>
-    <processor class="org.dive4elements.river.artifacts.sinfo.common.InfrastructureHeightProcessor" axis="W"/>
-    <processor class="org.dive4elements.river.artifacts.sinfo.collision.CollisionCountProcessor" axis="countAxis"/>
+    <processor class="org.dive4elements.river.artifacts.sinfo.common.PredefinedInfrastructureProcessor" axis="W"/>
+    <processor class="org.dive4elements.river.artifacts.sinfo.predefinedcollision.PredefinedCollisionProcessor" axis="countAxis"/>
 
     <chartextender class="org.dive4elements.river.artifacts.sinfo.flowdepth.FlowDepthChartExtender" />
     
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionArtifact.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionArtifact.java	Fri Aug 03 17:02:38 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,142 +0,0 @@
-/** 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.collision;
-
-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.states.StaticState;
-import org.w3c.dom.Document;
-
-/**
- * Display of a river bed collision data series loaded from database
- *
- * @author Matthias Schäfer
- *
- */
-public class CollisionArtifact extends AbstractStaticStateArtifact implements FacetTypes {
-
-    private static final long serialVersionUID = 1L;
-
-    /** The log for this class. */
-    private static Logger log = Logger.getLogger(CollisionArtifact.class);
-
-    /** Artifact name. */
-    private static final String NAME = "collision";
-
-    static {
-        // TODO: Move to configuration.
-        FacetActivity.Registry.getInstance().register(NAME, FacetActivity.INACTIVE);
-    }
-
-    public static final String STATIC_STATE_NAME = "state.predefined_collision.static";
-
-    /**
-     * Trivial Constructor.
-     */
-    public CollisionArtifact() {
-        log.debug("new CollisionArtifact");
-    }
-
-    @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("CollisionArtifact.setup");
-
-        if (log.isDebugEnabled()) {
-            log.debug(XMLUtils.toString(data));
-        }
-
-        final String code = getDatacageIDValue(data);
-        final String[] parts = code.split("-");
-        if (parts.length >= 2)
-            addStringData("collision_id", parts[1]);
-        if (parts.length >= 3)
-            addStringData("year", parts[2]);
-        else
-            addStringData("year", "jahr?");
-        String seriesName;
-        if (parts.length >= 4)
-            seriesName = parts[3];
-        else
-            seriesName = "name?";
-
-        // if different facet wanted, e.g. for each year use different facetIndex
-        // if multiple Result treated, get each Result from data
-        createFacets(callMeta, code, seriesName, getDataAsString("year"));
-
-        super.setup(identifier, factory, context, callMeta, data, loadFacets);
-    }
-
-    private void createFacets(final CallMeta callMeta, final String code, final String seriesName, final String yearForName) {
-        if (code == null)
-            return;
-
-        final String[] parts = code.split("-");
-        if (parts.length < 2) {
-            log.error("Invalid datacage ID '" + code + "'");
-            return;
-        }
-        final ArrayList<Facet> facets = new ArrayList<>(1);
-        facets.add(CollisionCountProcessor.createFacet(0, callMeta, yearForName));
-        // facets.add(CollisionGaugeWProcessor.createFacet(callMeta, seriesName)); //REMARK gauge_w is the cm above gauge datum,
-        // therefore only useful with transformation to NHN
-        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
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCountProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCountProcessor.java	Fri Aug 03 17:02:38 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/** 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.collision;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
-import org.dive4elements.artifactdatabase.state.Facet;
-import org.dive4elements.artifacts.CallMeta;
-import org.dive4elements.river.artifacts.common.AbstractProcessor;
-import org.dive4elements.river.artifacts.resources.Resources;
-import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
-import org.dive4elements.river.exports.DiagramGenerator;
-import org.dive4elements.river.themes.ThemeDocument;
-
-/**
- * Processor to generate a data series for bed collision count data loaded from the database
- *
- * @author Matthias Schäfer
- *
- */
-public class CollisionCountProcessor extends AbstractProcessor {
-
-    public static final String FACET_COLLISION_COUNT = "sinfo_facet_collision_count";
-
-    private static final String I18N_AXIS_LABEL = "chart.collision_count.section.yaxis.label";
-
-    private static final String I18N_SERIES_NAME_PATTERN = "collision.count.title";
-
-    private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
-
-    static {
-        HANDLED_FACET_TYPES.add(FACET_COLLISION_COUNT);
-    }
-
-    public CollisionCountProcessor() {
-        super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
-    }
-
-    public static Facet createFacet(final int facetIndex, final CallMeta callMeta, final String year) {
-        return new CollisionFacet(facetIndex, FACET_COLLISION_COUNT, Resources.getMsg(callMeta, I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, year),
-                I18N_AXIS_LABEL);
-    }
-
-    @Override
-    protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
-
-        return buildSeriesForType(generator, bundle, theme, visible, SInfoResultType.collisionCount, null);
-    }
-}
\ No newline at end of file
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionDbAccess.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionDbAccess.java	Fri Aug 03 17:02:38 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/** 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.collision;
-
-import org.dive4elements.river.artifacts.D4EArtifact;
-import org.dive4elements.river.artifacts.access.RangeAccess;
-
-/**
- * Access to the database loaded river bed collision artifact data
- *
- * @author Matthias Schäfer
- */
-final class CollisionDbAccess extends RangeAccess {
-
-    /***** FIELDS *****/
-
-    private Integer id;
-
-    private String name;
-
-
-    /***** CONSTRUCTORS *****/
-
-    public CollisionDbAccess(final D4EArtifact artifact) {
-        super(artifact);
-    }
-
-
-    /***** METHODS *****/
-
-    public Integer getId() {
-        if (this.id == null) {
-            this.id = getInteger("collision_id");
-        }
-        return this.id;
-    }
-
-    public String getName() {
-        if (this.name == null) {
-            this.name = getString("name");
-        }
-        return this.name;
-    }
-}
\ No newline at end of file
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionFacet.java	Fri Aug 03 17:02:38 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-/** 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.collision;
-
-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.DefaultCalculationResult;
-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.sinfo.common.SInfoResultType;
-import org.dive4elements.river.model.sinfo.Collision;
-import org.dive4elements.river.model.sinfo.CollisionAggregateValue;
-
-/**
- * Facet for a river bed collision value series loaded from the database
- *
- * @author Matthias Schäfer
- */
-public class CollisionFacet extends BlackboardDataFacet {
-
-    private static final long serialVersionUID = 1;
-
-    public CollisionFacet(final int facetIndex, final String name, final String description, final String yAxisLabel) {
-        super(facetIndex, 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 CollisionQueryCalculationResult
-     */
-    @Override
-    public Object getData(final Artifact artifact, final CallContext context) {
-
-        final CollisionDbAccess access = new CollisionDbAccess((D4EArtifact) artifact);
-        final Collision series = Collision.getSeries(access.getId());
-        final List<CollisionAggregateValue> values = CollisionAggregateValue.getValuesByKm(series, access.getFrom(true), access.getTo(true));
-        final Collection<ResultRow> rows = new ArrayList<>();
-        for (final CollisionAggregateValue value : values) {
-
-            final ResultRow row = ResultRow.create();
-
-            row.putValue(GeneralResultType.station, value.getStation());
-            // Not needed: row.putValue(SInfoResultType.years, series.getYear());
-            row.putValue(SInfoResultType.collisionCount, value.getCount());
-            row.putValue(SInfoResultType.collisionGaugeW, value.getGaugeW());
-
-            rows.add(row);
-        }
-        return new DefaultCalculationResult(series.getFilename(), rows);
-    }
-
-    /**
-     * Create a deep copy of this Facet.
-     *
-     * @return a deep copy.
-     */
-    @Override
-    public CollisionFacet deepCopy() {
-        final CollisionFacet copy = new CollisionFacet(this.index, this.name, this.description, this.metaData.get("Y"));
-        copy.set(this);
-        return copy;
-    }
-}
\ No newline at end of file
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/InfrastructureHeightProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/InfrastructureHeightProcessor.java	Fri Aug 03 17:02:38 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/** 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.Set;
-
-import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
-import org.dive4elements.artifactdatabase.state.Facet;
-import org.dive4elements.artifacts.CallMeta;
-import org.dive4elements.river.artifacts.common.AbstractProcessor;
-import org.dive4elements.river.artifacts.resources.Resources;
-import org.dive4elements.river.artifacts.sinfo.flood_duration.InfrastructureFacet;
-import org.dive4elements.river.exports.DiagramGenerator;
-import org.dive4elements.river.themes.ThemeDocument;
-
-/**
- * Processor to generate a data series for infrastructure height data loaded from the database
- *
- * @author Matthias Schäfer
- *
- */
-public class InfrastructureHeightProcessor extends AbstractProcessor {
-
-    public static final String FACET_INFRASTRUCTURE_HEIGHT = "sinfo_facet_infrastructure_height";
-
-    private static final String I18N_AXIS_LABEL = "chart.longitudinal.section.yaxis.label";
-
-    private static final String I18N_SERIES_NAME_PATTERN = "infrastructure.height.title";
-
-    private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
-
-    static {
-        HANDLED_FACET_TYPES.add(FACET_INFRASTRUCTURE_HEIGHT);
-    }
-
-    public InfrastructureHeightProcessor() {
-        super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
-    }
-
-    @Override
-    protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
-
-        return buildSeriesForType(generator, bundle, theme, visible, SInfoResultType.infrastructureHeight, null);
-    }
-
-    public static Facet createFacet(final CallMeta callMeta, final String seriesName) {
-        return new InfrastructureFacet(FACET_INFRASTRUCTURE_HEIGHT, Resources.getMsg(callMeta, I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, seriesName),
-                I18N_AXIS_LABEL);
-    }
-}
\ No newline at end of file
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/PredefinedInfrastructureProcessor.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/PredefinedInfrastructureProcessor.java	Mon Aug 06 11:48:49 2018 +0200
@@ -0,0 +1,59 @@
+/** 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.Set;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifacts.CallMeta;
+import org.dive4elements.river.artifacts.common.AbstractProcessor;
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.artifacts.sinfo.predefinedinfrastructure.PredefinedInfrastructureFacet;
+import org.dive4elements.river.exports.DiagramGenerator;
+import org.dive4elements.river.themes.ThemeDocument;
+
+/**
+ * Processor to generate a data series for infrastructure height data loaded from the database
+ *
+ * @author Matthias Schäfer
+ *
+ */
+public class PredefinedInfrastructureProcessor extends AbstractProcessor {
+
+    public static final String FACET_INFRASTRUCTURE_HEIGHT = "sinfo_facet_infrastructure_height";
+
+    private static final String I18N_AXIS_LABEL = "chart.longitudinal.section.yaxis.label";
+
+    private static final String I18N_SERIES_NAME_PATTERN = "infrastructure.height.title";
+
+    private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
+
+    static {
+        HANDLED_FACET_TYPES.add(FACET_INFRASTRUCTURE_HEIGHT);
+    }
+
+    public PredefinedInfrastructureProcessor() {
+        super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
+    }
+
+    @Override
+    protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
+
+        return buildSeriesForType(generator, bundle, theme, visible, SInfoResultType.infrastructureHeight, null);
+    }
+
+    public static Facet createFacet(final CallMeta callMeta, final String seriesName) {
+        return new PredefinedInfrastructureFacet(FACET_INFRASTRUCTURE_HEIGHT, Resources.getMsg(callMeta, I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, seriesName),
+                I18N_AXIS_LABEL);
+    }
+}
\ No newline at end of file
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/InfrastructureAccess.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/InfrastructureAccess.java	Fri Aug 03 17:02:38 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/** 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.flood_duration;
-
-import org.dive4elements.river.artifacts.D4EArtifact;
-import org.dive4elements.river.artifacts.access.RangeAccess;
-
-/**
- * Access to the database loaded infrastructure artifact data
- *
- * @author Matthias Schäfer
- */
-final class InfrastructureAccess extends RangeAccess {
-
-    /***** FIELDS *****/
-
-    private Integer id;
-
-    private String name;
-
-
-    /***** CONSTRUCTORS *****/
-
-    public InfrastructureAccess(final D4EArtifact artifact) {
-        super(artifact);
-    }
-
-
-    /***** METHODS *****/
-
-    public Integer getId() {
-        if (this.id == null) {
-            this.id = getInteger("infrastructure_id");
-        }
-        return this.id;
-    }
-
-    public String getName() {
-        if (this.name == null) {
-            this.name = getString("name");
-        }
-        return this.name;
-    }
-}
\ No newline at end of file
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/InfrastructureArtifact.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/InfrastructureArtifact.java	Fri Aug 03 17:02:38 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-/** 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.flood_duration;
-
-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.InfrastructureHeightProcessor;
-import org.dive4elements.river.artifacts.states.StaticState;
-import org.w3c.dom.Document;
-
-/**
- * Display of a infrastructure height data series loaded from database
- *
- * @author Matthias Schäfer
- *
- */
-public class InfrastructureArtifact extends AbstractStaticStateArtifact implements FacetTypes {
-
-    /** The log for this class. */
-    private static Logger log = Logger.getLogger(InfrastructureArtifact.class);
-
-    /** Artifact name. */
-    private static final String NAME = "infrastructure";
-
-    static {
-        // TODO: Move to configuration.
-        FacetActivity.Registry.getInstance().register(NAME, FacetActivity.INACTIVE);
-    }
-
-    public static final String STATIC_STATE_NAME = "state.predefined_infrastructure.static";
-
-    /**
-     * Trivial Constructor.
-     */
-    public InfrastructureArtifact() {
-        log.debug("new InfrastructureArtifact");
-    }
-
-    @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("InfrastructureArtifact.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("infrastructure_id", parts[1]);
-        final ArrayList<Facet> facets = new ArrayList<>(2);
-        facets.add(InfrastructureHeightProcessor.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
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/InfrastructureFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/InfrastructureFacet.java	Fri Aug 03 17:02:38 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-/** 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.flood_duration;
-
-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.DefaultCalculationResult;
-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.Infrastructure;
-import org.dive4elements.river.model.sinfo.InfrastructureValue;
-
-/**
- * Facet for a infrastructure value series loaded from the database
- *
- * @author Matthias Schäfer
- */
-public class InfrastructureFacet extends BlackboardDataFacet implements FacetTypes {
-
-    private static final long serialVersionUID = 1;
-
-    public InfrastructureFacet(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 InfrastructureQueryCalculationResult
-     */
-    @Override
-    public Object getData(final Artifact artifact, final CallContext context) {
-
-        final InfrastructureAccess access = new InfrastructureAccess((D4EArtifact) artifact);
-        final Infrastructure series = Infrastructure.getSeries(access.getId());
-        final List<InfrastructureValue> values = InfrastructureValue.getValues(series, access.getFrom(true), access.getTo(true));
-        final Collection<ResultRow> rows = new ArrayList<>();
-        for (final InfrastructureValue value : values) {
-            rows.add(ResultRow.create().putValue(GeneralResultType.station, value.getStation()) //
-                    .putValue(SInfoResultType.infrastructureHeight, value.getHeight()));
-        }
-        return new DefaultCalculationResult(series.getFilename(), rows);
-    }
-
-    /**
-     * Create a deep copy of this Facet.
-     *
-     * @return a deep copy.
-     */
-    @Override
-    public InfrastructureFacet deepCopy() {
-        final InfrastructureFacet copy = new InfrastructureFacet(this.name, this.description, this.metaData.get("Y"));
-        copy.set(this);
-        return copy;
-    }
-}
\ No newline at end of file
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedcollision/PredefinedCollisionAccess.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedcollision/PredefinedCollisionAccess.java	Mon Aug 06 11:48:49 2018 +0200
@@ -0,0 +1,52 @@
+/** 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.predefinedcollision;
+
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.RangeAccess;
+
+/**
+ * Access to the database loaded river bed collision artifact data
+ *
+ * @author Matthias Schäfer
+ */
+final class PredefinedCollisionAccess extends RangeAccess {
+
+    /***** FIELDS *****/
+
+    private Integer id;
+
+    private String name;
+
+
+    /***** CONSTRUCTORS *****/
+
+    public PredefinedCollisionAccess(final D4EArtifact artifact) {
+        super(artifact);
+    }
+
+
+    /***** METHODS *****/
+
+    public Integer getId() {
+        if (this.id == null) {
+            this.id = getInteger("collision_id");
+        }
+        return this.id;
+    }
+
+    public String getName() {
+        if (this.name == null) {
+            this.name = getString("name");
+        }
+        return this.name;
+    }
+}
\ No newline at end of file
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedcollision/PredefinedCollisionArtifact.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedcollision/PredefinedCollisionArtifact.java	Mon Aug 06 11:48:49 2018 +0200
@@ -0,0 +1,142 @@
+/** 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.predefinedcollision;
+
+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.states.StaticState;
+import org.w3c.dom.Document;
+
+/**
+ * Display of a river bed collision data series loaded from database
+ *
+ * @author Matthias Schäfer
+ *
+ */
+public class PredefinedCollisionArtifact extends AbstractStaticStateArtifact implements FacetTypes {
+
+    private static final long serialVersionUID = 1L;
+
+    /** The log for this class. */
+    private static Logger log = Logger.getLogger(PredefinedCollisionArtifact.class);
+
+    /** Artifact name. */
+    private static final String NAME = "collision";
+
+    static {
+        // TODO: Move to configuration.
+        FacetActivity.Registry.getInstance().register(NAME, FacetActivity.INACTIVE);
+    }
+
+    public static final String STATIC_STATE_NAME = "state.predefined_collision.static";
+
+    /**
+     * Trivial Constructor.
+     */
+    public PredefinedCollisionArtifact() {
+        log.debug("new PredefinedCollisionArtifact");
+    }
+
+    @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("PredefinedCollisionArtifact.setup");
+
+        if (log.isDebugEnabled()) {
+            log.debug(XMLUtils.toString(data));
+        }
+
+        final String code = getDatacageIDValue(data);
+        final String[] parts = code.split("-");
+        if (parts.length >= 2)
+            addStringData("collision_id", parts[1]);
+        if (parts.length >= 3)
+            addStringData("year", parts[2]);
+        else
+            addStringData("year", "jahr?");
+        String seriesName;
+        if (parts.length >= 4)
+            seriesName = parts[3];
+        else
+            seriesName = "name?";
+
+        // if different facet wanted, e.g. for each year use different facetIndex
+        // if multiple Result treated, get each Result from data
+        createFacets(callMeta, code, seriesName, getDataAsString("year"));
+
+        super.setup(identifier, factory, context, callMeta, data, loadFacets);
+    }
+
+    private void createFacets(final CallMeta callMeta, final String code, final String seriesName, final String yearForName) {
+        if (code == null)
+            return;
+
+        final String[] parts = code.split("-");
+        if (parts.length < 2) {
+            log.error("Invalid datacage ID '" + code + "'");
+            return;
+        }
+        final ArrayList<Facet> facets = new ArrayList<>(1);
+        facets.add(PredefinedCollisionProcessor.createFacet(0, callMeta, yearForName));
+        // facets.add(CollisionGaugeWProcessor.createFacet(callMeta, seriesName)); //REMARK gauge_w is the cm above gauge datum,
+        // therefore only useful with transformation to NHN
+        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
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedcollision/PredefinedCollisionFacet.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedcollision/PredefinedCollisionFacet.java	Mon Aug 06 11:48:49 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.predefinedcollision;
+
+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.DefaultCalculationResult;
+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.sinfo.common.SInfoResultType;
+import org.dive4elements.river.model.sinfo.Collision;
+import org.dive4elements.river.model.sinfo.CollisionAggregateValue;
+
+/**
+ * Facet for a river bed collision value series loaded from the database
+ *
+ * @author Matthias Schäfer
+ */
+public class PredefinedCollisionFacet extends BlackboardDataFacet {
+
+    private static final long serialVersionUID = 1;
+
+    public PredefinedCollisionFacet(final int facetIndex, final String name, final String description, final String yAxisLabel) {
+        super(facetIndex, 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 CollisionQueryCalculationResult
+     */
+    @Override
+    public Object getData(final Artifact artifact, final CallContext context) {
+
+        final PredefinedCollisionAccess access = new PredefinedCollisionAccess((D4EArtifact) artifact);
+        final Collision series = Collision.getSeries(access.getId());
+        final List<CollisionAggregateValue> values = CollisionAggregateValue.getValuesByKm(series, access.getFrom(true), access.getTo(true));
+        final Collection<ResultRow> rows = new ArrayList<>();
+        for (final CollisionAggregateValue value : values) {
+
+            final ResultRow row = ResultRow.create();
+
+            row.putValue(GeneralResultType.station, value.getStation());
+            // Not needed: row.putValue(SInfoResultType.years, series.getYear());
+            row.putValue(SInfoResultType.collisionCount, value.getCount());
+            row.putValue(SInfoResultType.collisionGaugeW, value.getGaugeW());
+
+            rows.add(row);
+        }
+        return new DefaultCalculationResult(series.getFilename(), rows);
+    }
+
+    /**
+     * Create a deep copy of this Facet.
+     *
+     * @return a deep copy.
+     */
+    @Override
+    public PredefinedCollisionFacet deepCopy() {
+        final PredefinedCollisionFacet copy = new PredefinedCollisionFacet(this.index, this.name, this.description, this.metaData.get("Y"));
+        copy.set(this);
+        return copy;
+    }
+}
\ No newline at end of file
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedcollision/PredefinedCollisionProcessor.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedcollision/PredefinedCollisionProcessor.java	Mon Aug 06 11:48:49 2018 +0200
@@ -0,0 +1,59 @@
+/** 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.predefinedcollision;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifacts.CallMeta;
+import org.dive4elements.river.artifacts.common.AbstractProcessor;
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
+import org.dive4elements.river.exports.DiagramGenerator;
+import org.dive4elements.river.themes.ThemeDocument;
+
+/**
+ * Processor to generate a data series for bed collision count data loaded from the database
+ *
+ * @author Matthias Schäfer
+ *
+ */
+public class PredefinedCollisionProcessor extends AbstractProcessor {
+
+    public static final String FACET_COLLISION_COUNT = "sinfo_facet_collision_count";
+
+    private static final String I18N_AXIS_LABEL = "chart.collision_count.section.yaxis.label";
+
+    private static final String I18N_SERIES_NAME_PATTERN = "collision.count.title";
+
+    private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
+
+    static {
+        HANDLED_FACET_TYPES.add(FACET_COLLISION_COUNT);
+    }
+
+    public PredefinedCollisionProcessor() {
+        super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
+    }
+
+    public static Facet createFacet(final int facetIndex, final CallMeta callMeta, final String year) {
+        return new PredefinedCollisionFacet(facetIndex, FACET_COLLISION_COUNT, Resources.getMsg(callMeta, I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, year),
+                I18N_AXIS_LABEL);
+    }
+
+    @Override
+    protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
+
+        return buildSeriesForType(generator, bundle, theme, visible, SInfoResultType.collisionCount, null);
+    }
+}
\ No newline at end of file
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedinfrastructure/PredefinedInfrastructureAccess.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedinfrastructure/PredefinedInfrastructureAccess.java	Mon Aug 06 11:48:49 2018 +0200
@@ -0,0 +1,52 @@
+/** 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.predefinedinfrastructure;
+
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.RangeAccess;
+
+/**
+ * Access to the database loaded infrastructure artifact data
+ *
+ * @author Matthias Schäfer
+ */
+final class PredefinedInfrastructureAccess extends RangeAccess {
+
+    /***** FIELDS *****/
+
+    private Integer id;
+
+    private String name;
+
+
+    /***** CONSTRUCTORS *****/
+
+    public PredefinedInfrastructureAccess(final D4EArtifact artifact) {
+        super(artifact);
+    }
+
+
+    /***** METHODS *****/
+
+    public Integer getId() {
+        if (this.id == null) {
+            this.id = getInteger("infrastructure_id");
+        }
+        return this.id;
+    }
+
+    public String getName() {
+        if (this.name == null) {
+            this.name = getString("name");
+        }
+        return this.name;
+    }
+}
\ No newline at end of file
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedinfrastructure/PredefinedInfrastructureArtifact.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedinfrastructure/PredefinedInfrastructureArtifact.java	Mon Aug 06 11:48:49 2018 +0200
@@ -0,0 +1,126 @@
+/** 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.predefinedinfrastructure;
+
+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.PredefinedInfrastructureProcessor;
+import org.dive4elements.river.artifacts.states.StaticState;
+import org.w3c.dom.Document;
+
+/**
+ * Display of a infrastructure height data series loaded from database
+ *
+ * @author Matthias Schäfer
+ *
+ */
+public class PredefinedInfrastructureArtifact extends AbstractStaticStateArtifact implements FacetTypes {
+
+    /** The log for this class. */
+    private static Logger log = Logger.getLogger(PredefinedInfrastructureArtifact.class);
+
+    /** Artifact name. */
+    private static final String NAME = "infrastructure";
+
+    static {
+        // TODO: Move to configuration.
+        FacetActivity.Registry.getInstance().register(NAME, FacetActivity.INACTIVE);
+    }
+
+    public static final String STATIC_STATE_NAME = "state.predefined_infrastructure.static";
+
+    /**
+     * Trivial Constructor.
+     */
+    public PredefinedInfrastructureArtifact() {
+        log.debug("new InfrastructureArtifact");
+    }
+
+    @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("InfrastructureArtifact.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("infrastructure_id", parts[1]);
+        final ArrayList<Facet> facets = new ArrayList<>(2);
+        facets.add(PredefinedInfrastructureProcessor.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
diff -r f318359b81a2 -r e8d65cecc950 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedinfrastructure/PredefinedInfrastructureFacet.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedinfrastructure/PredefinedInfrastructureFacet.java	Mon Aug 06 11:48:49 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.predefinedinfrastructure;
+
+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.DefaultCalculationResult;
+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.Infrastructure;
+import org.dive4elements.river.model.sinfo.InfrastructureValue;
+
+/**
+ * Facet for a infrastructure value series loaded from the database
+ *
+ * @author Matthias Schäfer
+ */
+public class PredefinedInfrastructureFacet extends BlackboardDataFacet implements FacetTypes {
+
+    private static final long serialVersionUID = 1;
+
+    public PredefinedInfrastructureFacet(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 InfrastructureQueryCalculationResult
+     */
+    @Override
+    public Object getData(final Artifact artifact, final CallContext context) {
+
+        final PredefinedInfrastructureAccess access = new PredefinedInfrastructureAccess((D4EArtifact) artifact);
+        final Infrastructure series = Infrastructure.getSeries(access.getId());
+        final List<InfrastructureValue> values = InfrastructureValue.getValues(series, access.getFrom(true), access.getTo(true));
+        final Collection<ResultRow> rows = new ArrayList<>();
+        for (final InfrastructureValue value : values) {
+            rows.add(ResultRow.create().putValue(GeneralResultType.station, value.getStation()) //
+                    .putValue(SInfoResultType.infrastructureHeight, value.getHeight()));
+        }
+        return new DefaultCalculationResult(series.getFilename(), rows);
+    }
+
+    /**
+     * Create a deep copy of this Facet.
+     *
+     * @return a deep copy.
+     */
+    @Override
+    public PredefinedInfrastructureFacet deepCopy() {
+        final PredefinedInfrastructureFacet copy = new PredefinedInfrastructureFacet(this.name, this.description, this.metaData.get("Y"));
+        copy.set(this);
+        return copy;
+    }
+}
\ No newline at end of file


More information about the Dive4Elements-commits mailing list