diff flys-artifacts/src/main/java/de/intevation/flys/mapserver/ArtifactMapfileGenerator.java @ 5175:cfc5540a4eec mapgenfix

Re-add layer generation for floodmap layers (somewhat buggy though).
author Christian Lins <christian.lins@intevation.de>
date Wed, 06 Mar 2013 14:14:15 +0100
parents cbfdd7376009
children
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/mapserver/ArtifactMapfileGenerator.java	Mon Feb 25 11:55:34 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/mapserver/ArtifactMapfileGenerator.java	Wed Mar 06 14:14:15 2013 +0100
@@ -6,7 +6,6 @@
 import de.intevation.flys.artifacts.model.LayerInfo;
 import de.intevation.flys.artifacts.model.map.WMSDBLayerFacet;
 import de.intevation.flys.artifacts.model.map.WMSLayerFacet;
-import de.intevation.flys.artifacts.model.map.WSPLGENLayerFacet;
 import de.intevation.flys.artifacts.resources.Resources;
 import de.intevation.flys.utils.FLYSUtils;
 import de.intevation.flys.utils.GeometryUtils;
@@ -46,8 +45,7 @@
      * Generates flys.map file that contains layers of all
      * projects and types (floodmap, user defined, barriers).
      */
-    @Override
-    public void generate() throws IOException
+    public void generate(String style, CallContext context, FLYSArtifact flys) throws IOException
     {
         // Get all directories below "shapefiles/"
         File[] prjDirs = getProjectDirs();
@@ -59,44 +57,47 @@
 
         // Generate layer snippet for each shapefile
         for (File layerShape : layerShapes) {
-            String fileName = layerShape.getName();
+            String fileName  = layerShape.getName();
+            File   layerFile = null;
+
             if (fileName.startsWith(MS_PREFIX_BARRIERS)) {
 
             }
             else if (fileName.startsWith(MS_PREFIX_USER)) {
-                File userLayer = createUserShapeLayer(layerShape);
-                if (userLayer != null) {
-                    layerSnippets.add(userLayer.getCanonicalPath());
-                }
+                layerFile = createUserShapeLayer(layerShape);
             }
-            else if (fileName.startsWith(MS_PREFIX_WSPLGEN)) {
+            else if (fileName.startsWith(MS_PREFIX_WSPLGEN) &&
+                     style != null && context != null && flys != null) {
+                layerFile = createFloodmapLayer(layerShape, style, context, flys);
+            }
 
+            if (layerFile != null) {
+                layerSnippets.add(layerFile.getCanonicalPath());
             }
         }
 
         writeMapfile(layerSnippets);
     }
 
+    @Override
+    public void generate() throws IOException {
+        generate(null, null, null);
+    }
+
     /**
      * Creates a layer file used for Mapserver's mapfile which represents the
      * floodmap.
-     *
-     * @param flys The FLYSArtifact that owns <i>wms</i>.
-     * @param wms The WMSLayerFacet that contains information for the layer.
      */
-    protected void createUeskLayer(
-        FLYSArtifact  flys,
-        WSPLGENLayerFacet wms,
-        String        style,
-        CallContext context
-    ) throws FileNotFoundException, IOException
+    protected File createFloodmapLayer(File file, String style, CallContext context, FLYSArtifact flys)
+            throws FileNotFoundException, IOException
     {
+        String uuid = uuidFromPath(file.getAbsolutePath());
         logger.debug("createUeskLayer");
 
         LayerInfo layerinfo = new LayerInfo();
-        layerinfo.setName(MS_PREFIX_WSPLGEN + flys.identifier());
+        layerinfo.setName(MS_PREFIX_WSPLGEN + "-" + uuid);
         layerinfo.setType("POLYGON");
-        layerinfo.setDirectory(flys.identifier());
+        layerinfo.setDirectory(uuid);
         layerinfo.setData(WSPLGEN_RESULT_SHAPE);
         layerinfo.setTitle(Resources.getMsg(Resources.getLocale(context.getMeta()),
                                             "floodmap.uesk",
@@ -106,21 +107,24 @@
         String river = access.getRiver();
         layerinfo.setSrid(FLYSUtils.getRiverDGMSrid(river));
 
-        String name = MS_LAYER_PREFIX + wms.getName();
+        String name = "floodmap.layer"; //MS_LAYER_PREFIX + wms.getName();
 
         Template template = getTemplateByName(WSPLGEN_LAYER_TEMPLATE);
         if (template == null) {
             logger.warn("Template '" + WSPLGEN_LAYER_TEMPLATE + "' found.");
-            return;
+            return null;
         }
 
         try {
-            File dir = new File(getShapefileBaseDir(), flys.identifier());
-            writeLayer(layerinfo, new File(dir, name), template);
+            File dir = new File(getShapefileBaseDir(), uuid);
+            File layerFile = new File(dir, name);
+            writeLayer(layerinfo, layerFile, template);
+            return layerFile;
         }
         catch (FileNotFoundException fnfe) {
             logger.error(fnfe, fnfe);
             logger.warn("Unable to write layer: " + name);
+            return null;
         }
     }
 

http://dive4elements.wald.intevation.org