changeset 1805:5e9696c32f04

Added datacage config and loaders for KM WMS layer in floodmaps. flys-artifacts/trunk@3131 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 01 Nov 2011 14:54:59 +0000
parents 00f14b837e65
children 50110699e38e
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/winfo.xml flys-artifacts/doc/conf/conf.xml flys-artifacts/doc/conf/meta-data.xml flys-artifacts/doc/conf/themes.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSKmArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java flys-artifacts/src/main/resources/messages.properties flys-artifacts/src/main/resources/messages_de.properties flys-artifacts/src/main/resources/messages_de_DE.properties flys-artifacts/src/main/resources/messages_en.properties
diffstat 13 files changed, 374 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Nov 01 14:24:30 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Nov 01 14:54:59 2011 +0000
@@ -1,3 +1,34 @@
+2011-11-01  Ingo Weinzierl <ingo@intevation.de>
+
+	* doc/conf/meta-data.xml: Added a datacage node that represents a
+	  kilometer WMS layer.
+
+	* doc/conf/conf.xml: Added a new Artifact WMSKmArtifact.
+
+	* doc/conf/themes.xml: Added a style for 'floodmap.kms' facets.
+
+	* doc/conf/artifacts/winfo.xml: Defined 'floodmap.kms' as valid floodmap
+	  facet.
+
+	* src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java: Added
+	  a 'floodmap.kms' facet.
+
+	* src/main/java/de/intevation/flys/utils/FLYSUtils.java: Added a method to
+	  determine the srid of a river based on its name.
+
+	* src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java: New. This
+	  Artifact should act as base Artifact for WMS layers that represent data
+	  from database datastore.
+
+	* src/main/java/de/intevation/flys/artifacts/WMSKmArtifact.java: New. This
+	  Artifact is used to generate facets for kilometer WMS layers.
+
+	* src/main/resources/messages.properties,
+	  src/main/resources/messages_de_DE.properties,
+	  src/main/resources/messages_en.properties,
+	  src/main/resources/messages_de.properties: Added default descriptions
+	  for 'floodmap.kms' facets.
+
 2011-11-01	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	Fix incompilability.
--- a/flys-artifacts/doc/conf/artifacts/winfo.xml	Tue Nov 01 14:24:30 2011 +0000
+++ b/flys-artifacts/doc/conf/artifacts/winfo.xml	Tue Nov 01 14:54:59 2011 +0000
@@ -355,6 +355,7 @@
                         <facet name="floodmap.barriers"/>
                         <facet name="floodmap.riveraxis"/>
                         <facet name="floodmap.wmsbackground"/>
+                        <facet name="floodmap.kms"/>
                     </facets>
                 </outputmode>
                 <outputmode name="wsplgen_report" description="output.wsplgen_report" mime-type="text/xml" type="report">
--- a/flys-artifacts/doc/conf/conf.xml	Tue Nov 01 14:24:30 2011 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Tue Nov 01 14:54:59 2011 +0000
@@ -17,6 +17,9 @@
             <artifact-factory name="riveraxis" description="Factory to create an artifact to be used in WINFO"
                 ttl="3600000"
                 artifact="de.intevation.flys.artifacts.RiverAxisArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
+            <artifact-factory name="wmskmfactory" description="Factory to create an artifact that generates WMS facets for KMs."
+                ttl="3600000"
+                artifact="de.intevation.flys.artifacts.WMSKmArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
             <artifact-factory name="wmsbackground" description="Factory to create an artifact to be used in WINFO"
                 ttl="3600000"
                 artifact="de.intevation.flys.artifacts.WMSBackgroundArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
--- a/flys-artifacts/doc/conf/meta-data.xml	Tue Nov 01 14:24:30 2011 +0000
+++ b/flys-artifacts/doc/conf/meta-data.xml	Tue Nov 01 14:54:59 2011 +0000
@@ -510,12 +510,29 @@
                   </dc:context>
                 </dems>
               </dc:macro>
+              <dc:macro name="flood-map-km">
+                <dc:context>
+                  <dc:statement>
+                    SELECT count(*) as km_exists
+                    FROM river_axes_km WHERE river_id = ${river_id}
+                  </dc:statement>
+                   <dc:elements>
+                    <dc:if test="$km_exists>0">
+                      <km>
+                        <dc:attribute name="factory" value="wmskmfactory"/>
+                        <dc:attribute name="ids" value="${river_id}"/>
+                      </km>
+                    </dc:if>
+                  </dc:elements>
+                </dc:context>
+              </dc:macro>
               <dc:macro name="flood-map-complete">
                   <kilometrage>
                       <riveraxis>
                           <dc:attribute name="factory" value="riveraxis"/>
                           <dc:attribute name="ids" value="${river_id}"/>
                       </riveraxis>
+                    <dc:call-macro name="flood-map-km"/>
                   </kilometrage>
                   <rastermap>
                       <background>
--- a/flys-artifacts/doc/conf/themes.xml	Tue Nov 01 14:24:30 2011 +0000
+++ b/flys-artifacts/doc/conf/themes.xml	Tue Nov 01 14:54:59 2011 +0000
@@ -549,6 +549,13 @@
         </fields>
     </theme>
 
+    <theme name="Kms">
+        <fields>
+            <field name="linecolor" type="Color" display="Linienfarbe" default="#800080"/>
+            <field name="linesize"  type="int"   display="Liniendicke" default="5" hints="h"/>
+        </fields>
+    </theme>
+
 
     <!-- Mappings are following now. A mapping maps between a name of a facet
          and a theme. -->
@@ -605,5 +612,6 @@
         <mapping from="longitudinal_section.annotations" to="Annotations"/>
         <mapping from="w_differences" to="Differences"/>
         <mapping from="floodmap.riveraxis" to="RiverAxis"/>
+        <mapping from="floodmap.kms" to="Kms"/>
     </mappings>
 </themes>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java	Tue Nov 01 14:54:59 2011 +0000
@@ -0,0 +1,149 @@
+package de.intevation.flys.artifacts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.w3c.dom.Document;
+
+import org.apache.log4j.Logger;
+
+import com.vividsolutions.jts.geom.Envelope;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.artifacts.CallMeta;
+
+import de.intevation.artifactdatabase.data.DefaultStateData;
+import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.artifactdatabase.state.State;
+
+import de.intevation.artifacts.common.ArtifactNamespaceContext;
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.flys.artifacts.states.DefaultState;
+import de.intevation.flys.artifacts.model.WMSDBLayerFacet;
+
+
+public abstract class WMSDBArtifact extends StaticFLYSArtifact {
+
+    private static final Logger logger = Logger.getLogger(WMSDBArtifact.class);
+
+    public static final String XPATH_IDS = "/art:action/art:ids/@value";
+
+
+    @Override
+    public void setup(
+        String          identifier,
+        ArtifactFactory factory,
+        Object          context,
+        CallMeta        callMeta,
+        Document        data)
+    {
+        logger.debug("WMSDBArtifact.setup");
+
+        super.setup(identifier, factory, context, callMeta, data);
+
+        String ids = XMLUtils.xpathString(
+            data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE);
+
+        if (ids != null && ids.length() > 0) {
+            addData("ids", new DefaultStateData("ids", null, null, ids));
+        }
+        else {
+            throw new IllegalArgumentException("No attribute 'ids' found!");
+        }
+
+        List<Facet> fs = new ArrayList<Facet>();
+
+        WMSDBState state = (WMSDBState) getCurrentState(context);
+        state.computeInit(this, hash(), context, callMeta, fs);
+
+        if (!fs.isEmpty()) {
+            facets.put(getCurrentStateId(), fs);
+        }
+    }
+
+
+    @Override
+    protected void initialize(
+        Artifact artifact,
+        Object   context,
+        CallMeta callMeta)
+    {
+        // do nothing
+    }
+
+
+    /**
+     * Get a list containing the one and only State.
+     * @param  context ignored.
+     * @return list with one and only state.
+     */
+    @Override
+    protected List<State> getStates(Object context) {
+        ArrayList<State> states = new ArrayList<State>();
+        states.add(getCurrentState(context));
+
+        return states;
+    }
+
+
+
+    public static abstract class WMSDBState extends DefaultState {
+        private static final Logger logger = Logger.getLogger(WMSDBState.class);
+
+        protected WMSDBArtifact artifact;
+
+        public WMSDBState(WMSDBArtifact artifact) {
+            this.artifact = artifact;
+        }
+
+        @Override
+        public Object computeInit(
+            FLYSArtifact artifact,
+            String       hash,
+            Object       context,
+            CallMeta     meta,
+            List<Facet>  facets
+        ) {
+            logger.debug("WMSDBState.computeInit");
+
+            String type = getFacetType();
+
+            WMSDBLayerFacet facet = new WMSDBLayerFacet(
+                0,
+                type,
+                getTitle(meta),
+                ComputeType.INIT,
+                getID(), hash,
+                getUrl());
+
+            String name = artifact.identifier() + "-" + type;
+
+            facet.addLayer(name);
+            facet.setExtent(getExtent());
+            facet.setSrid(getSrid());
+            facet.setData(getDataString());
+            facet.setFilter(getFilter());
+
+            facets.add(facet);
+
+            return null;
+        }
+
+        protected abstract String getFacetType();
+
+        protected abstract String getTitle(CallMeta meta);
+
+        protected abstract String getUrl();
+
+        protected abstract String getSrid();
+
+        protected abstract Envelope getExtent();
+
+        protected abstract String getFilter();
+
+        protected abstract String getDataString();
+    } // end of WMSDBState
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSKmArtifact.java	Tue Nov 01 14:54:59 2011 +0000
@@ -0,0 +1,154 @@
+package de.intevation.flys.artifacts;
+
+import java.util.List;
+
+import org.w3c.dom.Document;
+
+import org.apache.log4j.Logger;
+
+import com.vividsolutions.jts.geom.Envelope;
+import com.vividsolutions.jts.geom.Geometry;
+
+import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.artifacts.CallMeta;
+
+import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.artifactdatabase.state.DefaultOutput;
+import de.intevation.artifactdatabase.state.State;
+
+import de.intevation.flys.model.River;
+import de.intevation.flys.model.RiverAxis;
+
+import de.intevation.flys.artifacts.WMSDBArtifact.WMSDBState;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.RiverFactory;
+import de.intevation.flys.artifacts.resources.Resources;
+import de.intevation.flys.utils.FLYSUtils;
+
+
+public class WMSKmArtifact extends WMSDBArtifact {
+
+    public static final String NAME = "wmskm";
+
+
+    private static final Logger logger = Logger.getLogger(WMSKmArtifact.class);
+
+
+    @Override
+    public void setup(
+        String          identifier,
+        ArtifactFactory factory,
+        Object          context,
+        CallMeta        callMeta,
+        Document        data)
+    {
+        logger.debug("WMSKmArtifact.setup");
+
+        super.setup(identifier, factory, context, callMeta, data);
+    }
+
+
+    @Override
+    public String getName() {
+        return NAME;
+    }
+
+
+    @Override
+    public State getCurrentState(Object cc) {
+        State s = new WMSKmState(this);
+
+        List<Facet> fs = facets.get(getCurrentStateId());
+
+        DefaultOutput o = new DefaultOutput(
+            "floodmap",
+            "floodmap",
+            "image/png",
+            fs,
+            "map");
+
+        s.getOutputs().add(o);
+
+        return s;
+    }
+
+
+
+    public static class WMSKmState extends WMSDBState implements FacetTypes {
+
+        private static final Logger logger = Logger.getLogger(WMSKmState.class);
+
+        protected Geometry geom;
+        protected int      riverId;
+
+        public WMSKmState(WMSDBArtifact artifact) {
+            super(artifact);
+            riverId = 0;
+        }
+
+        public int getRiverId() {
+            if (riverId == 0) {
+                String ids = artifact.getDataAsString("ids");
+
+                try {
+                    riverId = Integer.valueOf(ids);
+                }
+                catch (NumberFormatException nfe) {
+                    logger.error("Cannot parse river id from '" + ids + "'");
+                }
+            }
+
+            return riverId;
+        }
+
+        public Geometry getGeom() {
+            if (geom == null) {
+                // TODO replace riveraxis with kilometrage geometry
+                River river = RiverFactory.getRiver(getRiverId());
+                RiverAxis a = RiverAxis.getRiverAxis(river.getName());
+
+                geom = a.getGeom();
+            }
+
+            return geom;
+        }
+
+        @Override
+        protected String getFacetType() {
+            return FLOODMAP_KMS;
+        }
+
+        @Override
+        protected String getTitle(CallMeta meta) {
+            return Resources.getMsg(meta, FLOODMAP_KMS, FLOODMAP_KMS);
+        }
+
+        @Override
+        protected String getUrl() {
+            return FLYSUtils.getUserWMSUrl(artifact.identifier());
+        }
+
+        @Override
+        protected String getSrid() {
+            River river = RiverFactory.getRiver(getRiverId());
+            return FLYSUtils.getRiverSrid(river.getName());
+        }
+
+        @Override
+        protected Envelope getExtent() {
+            return getGeom().getEnvelopeInternal();
+        }
+
+        @Override
+        protected String getFilter() {
+            return "river_id=" + String.valueOf(getRiverId());
+        }
+
+        @Override
+        protected String getDataString() {
+            return "geom FROM river_axes_km USING UNIQUE id USING SRID 31466";
+        }
+
+    } // end of WMSKmState
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Tue Nov 01 14:24:30 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Tue Nov 01 14:54:59 2011 +0000
@@ -6,6 +6,7 @@
     String FLOODMAP_BARRIERS      = "floodmap.barriers";
     String FLOODMAP_RIVERAXIS     = "floodmap.riveraxis";
     String FLOODMAP_WMSBACKGROUND = "floodmap.wmsbackground";
+    String FLOODMAP_KMS           = "floodmap.kms";
 
     String DISCHARGE_LONGITUDINAL_W = "discharge_longitudinal_section.w";
     String DISCHARGE_LONGITUDINAL_Q = "discharge_longitudinal_section.q";
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Tue Nov 01 14:24:30 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Tue Nov 01 14:54:59 2011 +0000
@@ -231,8 +231,13 @@
             return null;
         }
 
+        return getRiverSrid(river);
+    }
+
+
+    public static String getRiverSrid(String rivername) {
         Map<String, String> variables = new HashMap<String, String>(1);
-        variables.put("name", river);
+        variables.put("name", rivername);
 
         Document cfg = Config.getConfig();
 
--- a/flys-artifacts/src/main/resources/messages.properties	Tue Nov 01 14:24:30 2011 +0000
+++ b/flys-artifacts/src/main/resources/messages.properties	Tue Nov 01 14:54:59 2011 +0000
@@ -86,6 +86,7 @@
 floodmap.riveraxis = River Axis
 floodmap.uesk = Floodmap
 floodmap.barriers = Digitized Objects
+floodmap.kms = Kilometrage
 
 wsplgen.job.queued = WSPLGEN job in queue.
 wsplgen.job.error = An unexpected error while starting WSPLGEN occured.
--- a/flys-artifacts/src/main/resources/messages_de.properties	Tue Nov 01 14:24:30 2011 +0000
+++ b/flys-artifacts/src/main/resources/messages_de.properties	Tue Nov 01 14:54:59 2011 +0000
@@ -86,6 +86,7 @@
 floodmap.riveraxis = Flussachse
 floodmap.uesk = \u00dcberschwemmungsfl\u00e4che
 floodmap.barriers = Digitalisierte Objekte
+floodmap.kms = Kilometrierung
 
 wsplgen.job.queued = WSPLGEN Berechnung befindet sich in Warteschlange.
 wsplgen.job.error = Ein unerwarteter Fehler beim Starten von WSPLGEN ist aufgetreten.
--- a/flys-artifacts/src/main/resources/messages_de_DE.properties	Tue Nov 01 14:24:30 2011 +0000
+++ b/flys-artifacts/src/main/resources/messages_de_DE.properties	Tue Nov 01 14:54:59 2011 +0000
@@ -86,6 +86,7 @@
 floodmap.riveraxis = Flussachse
 floodmap.uesk = \u00dcberschwemmungsfl\u00e4che
 floodmap.barriers = Digitalisierte Objekte
+floodmap.kms = Kilometrierung
 
 wsplgen.job.queued = WSPLGEN Berechnung befindet sich in Warteschlange.
 wsplgen.job.error = Ein unerwarteter Fehler beim Starten von WSPLGEN ist aufgetreten.
--- a/flys-artifacts/src/main/resources/messages_en.properties	Tue Nov 01 14:24:30 2011 +0000
+++ b/flys-artifacts/src/main/resources/messages_en.properties	Tue Nov 01 14:54:59 2011 +0000
@@ -84,6 +84,7 @@
 floodmap.riveraxis = River Axis
 floodmap.uesk = Floodmap
 floodmap.barriers = Digitized Objects
+floodmap.kms = Kilometrage
 
 wsplgen.job.queued = WSPLGEN job in queue.
 wsplgen.job.error = An unexpected error while starting WSPLGEN occured.

http://dive4elements.wald.intevation.org