changeset 9753:7227621f8496 3.2.x

Get rid of duplicate MapServer URL configurations
author Tom Gottfried <tom@intevation.de>
date Tue, 11 Oct 2022 14:02:20 +0200
parents a41f9c355204
children cd07130ded8d
files artifacts/doc/conf/floodmap.xml artifacts/doc/conf/rivermap.xml artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java artifacts/src/main/java/org/dive4elements/river/artifacts/services/MapInfoService.java docker/README
diffstat 5 files changed, 22 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/doc/conf/floodmap.xml	Tue Oct 11 12:40:36 2022 +0200
+++ b/artifacts/doc/conf/floodmap.xml	Tue Oct 11 14:02:20 2022 +0200
@@ -9,7 +9,6 @@
 
     <river name="Beispielfluss">
         <srid value="31467"/>
-        <river-wms url="http://localhost:8081/cgi-bin/river-wms" layers="Beispielfluss"/>
         <background-wms url="http://osm.intevation.de/bfg/service?" layers="OSM-WMS-Dienst"/>
     </river>
 </floodmap>
--- a/artifacts/doc/conf/rivermap.xml	Tue Oct 11 12:40:36 2022 +0200
+++ b/artifacts/doc/conf/rivermap.xml	Tue Oct 11 14:02:20 2022 +0200
@@ -10,7 +10,6 @@
 
     <river name="Beispielfluss">
         <srid value="31467"/>
-        <river-wms url="http://localhost:8081/cgi-bin/river-wms" layers="Beispielfluss"/>
         <background-wms url="http://osm.intevation.de/bfg/service?" layers="OSM-WMS-Dienst"/>
     </river>
 </rivermap>
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java	Tue Oct 11 12:40:36 2022 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java	Tue Oct 11 14:02:20 2022 +0200
@@ -51,6 +51,7 @@
 import org.dive4elements.river.themes.ThemeFactory;
 import org.dive4elements.river.themes.ThemeGroup;
 import org.dive4elements.river.themes.ThemeMapping;
+import org.dive4elements.river.utils.RiverUtils;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -595,7 +596,7 @@
             Element e = (Element) rivers.item(i);
 
             String river = e.getAttribute("name");
-            String url   = XMLUtils.xpathString(e, "river-wms/@url", null);
+            String url   = RiverUtils.getUserWMSUrl();
 
             if (river != null && url != null) {
                 riverWMS.put(river, url);
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/MapInfoService.java	Tue Oct 11 12:40:36 2022 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/MapInfoService.java	Tue Oct 11 14:02:20 2022 +0200
@@ -18,6 +18,7 @@
 import org.dive4elements.artifacts.common.utils.XMLUtils;
 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
 import org.dive4elements.river.utils.GeometryUtils;
+import org.dive4elements.river.utils.RiverUtils;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -38,6 +39,9 @@
  */
 public class MapInfoService extends XMLService {
 
+    private static final String MAPTYPE_FLOOD = "floodmap";
+    private static final String MAPTYPE_RIVER = "rivermap";
+
     /** XPath that points to the river.*/
     public static final String XPATH_RIVER = "/mapinfo/river/text()";
 
@@ -51,12 +55,6 @@
         "/artifact-database/*[local-name()=$maptype]/"
         + "river[@name=$river]/background-wms";
 
-    private static final String XPATH_RIVER_WMS =
-        "/artifact-database/*[local-name()=$maptype]/"
-        + "river[@name=$river]/river-wms";
-
-
-    /** The log used in this service.*/
     private static Logger log = LogManager.getLogger(MapInfoService.class);
 
 
@@ -106,8 +104,8 @@
 
         String mapType = extractMaptype(data);
         if (mapType == null
-        || !(mapType.equals("floodmap") || mapType.equals("rivermap"))) {
-            mapType = "floodmap";
+        || !(mapType.equals(MAPTYPE_FLOOD) || mapType.equals(MAPTYPE_RIVER))) {
+            mapType = MAPTYPE_FLOOD;
         }
 
         Element root = cr.create("river");
@@ -142,13 +140,20 @@
             log.debug("processXML: " + XMLUtils.toString(root));
         }
 
+        Element bgWMS = (Element) getNodeXPath(XPATH_RIVER_BACKGROUND, vars);
         root.appendChild(
             createWMSElement("background-wms",
-                XPATH_RIVER_BACKGROUND, vars, cr));
+                bgWMS.getAttribute("url"),
+                bgWMS.getAttribute("layers"),
+                cr));
 
         root.appendChild(
             createWMSElement("river-wms",
-                XPATH_RIVER_WMS, vars, cr));
+                mapType == MAPTYPE_FLOOD
+                    ? RiverUtils.getUserWMSUrl()
+                    : RiverUtils.getRiverWMSUrl(),
+                river,
+                cr));
 
         return result;
     }
@@ -156,24 +161,14 @@
 
     protected Element createWMSElement(
         String elementName,
-        String xpath,
-        Map<String, String> vars,
+        String url,
+        String layers,
         ElementCreator cr)
     {
-        log.debug("createWMSElement()");
-
         Element el = cr.create(elementName);
-        Element wms = (Element)getNodeXPath(xpath, vars);
 
-        if (wms != null) {
-            cr.addAttr(el, "url", wms.getAttribute("url"));
-            cr.addAttr(el, "layers", wms.getAttribute("layers"));
-
-            log.debug("createWMSElement: " + XMLUtils.toString(el));
-        }
-        else {
-            log.debug("createWMSElement: wms == null");
-        }
+        cr.addAttr(el, "url", url);
+        cr.addAttr(el, "layers", layers);
 
         return el;
     }
--- a/docker/README	Tue Oct 11 12:40:36 2022 +0200
+++ b/docker/README	Tue Oct 11 14:02:20 2022 +0200
@@ -1,6 +1,6 @@
 Configure:
 _ Change 'localhost' to the hostname of your docker host in
-  artifacts/doc/conf/floodmap.xml and artifacts/doc/conf/rivermap.xml
+  artifacts/doc/conf/conf.xml
 _ Change 'example.com' to the hostname of your docker host plus ':8082' in
   artifacts/doc/conf/conf.xml
 _ Add to gwt-client/config/mapfish/config.yaml to enable map printing:

http://dive4elements.wald.intevation.org