changeset 5087:cbfdd7376009 mapgenfix

ArtifactMapfileGenerator can now generate user shape mapfiles again.
author Christian Lins <christian.lins@intevation.de>
date Mon, 25 Feb 2013 11:51:17 +0100
parents cc50e1b9fc60
children 2b24073e80d9
files flys-artifacts/src/main/java/de/intevation/flys/mapserver/ArtifactMapfileGenerator.java flys-artifacts/src/main/java/de/intevation/flys/mapserver/MapfileGenerator.java
diffstat 2 files changed, 19 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/mapserver/ArtifactMapfileGenerator.java	Wed Feb 20 21:00:33 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/mapserver/ArtifactMapfileGenerator.java	Mon Feb 25 11:51:17 2013 +0100
@@ -64,7 +64,10 @@
 
             }
             else if (fileName.startsWith(MS_PREFIX_USER)) {
-                createUserShapeLayer(layerShape);
+                File userLayer = createUserShapeLayer(layerShape);
+                if (userLayer != null) {
+                    layerSnippets.add(userLayer.getCanonicalPath());
+                }
             }
             else if (fileName.startsWith(MS_PREFIX_WSPLGEN)) {
 
@@ -253,7 +256,7 @@
          * Creates a layer file used for Mapserver's mapfile which represents the
          * shape files uploaded by the user.
          */
-        protected void createUserShapeLayer(File file)
+        protected File createUserShapeLayer(File file)
         throws FileNotFoundException, IOException
         {
             String uuid = uuidFromPath(file.getAbsolutePath());
@@ -264,7 +267,7 @@
 
             if (!test.exists() || !test.canRead()) {
                 logger.debug("No user layer existing.");
-                return;
+                return null;
             }
 
             File userShape = new File(dir, WSPLGEN_USER_SHAPE);
@@ -284,7 +287,8 @@
                 info.setType("POLYGON");
             }
             else {
-                return;
+                logger.debug("createUserShapeLayer(): unexpected geometry type");
+                return null;
             }
             info.setDirectory(uuid);
             info.setData(WSPLGEN_USER_SHAPE);
@@ -298,17 +302,19 @@
             Template tpl = getTemplateByName(SHP_LAYER_TEMPLATE);
             if (tpl == null) {
                 logger.warn("Template '" + SHP_LAYER_TEMPLATE + "' found.");
-                return;
+                return null;
             }
 
+            File layerFile = new File(dir, nameUser);
+
             try {
-                writeLayer(info, new File(dir, nameUser), tpl);
+                writeLayer(info, layerFile, tpl);
             }
             catch (FileNotFoundException fnfe) {
                 logger.error(fnfe, fnfe);
                 logger.warn("Unable to write layer: " + nameUser);
             }
-
+            return layerFile;
         }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/mapserver/MapfileGenerator.java	Wed Feb 20 21:00:33 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/mapserver/MapfileGenerator.java	Mon Feb 25 11:51:17 2013 +0100
@@ -240,6 +240,7 @@
         File   baseDir      = getShapefileBaseDir();
         File[] artifactDirs = baseDir.listFiles();
 
+        logger.debug("getProjectDirs(): found " + artifactDirs.length + " project directories");
         return artifactDirs;
     }
 
@@ -257,9 +258,10 @@
             File[] layerFiles = dir.listFiles(new FilenameFilter() {
                 @Override
                 public boolean accept(File directory, String name) {
-                    return name.startsWith(MS_PREFIX_BARRIERS) ||
-                           name.startsWith(MS_PREFIX_USER) ||
-                           name.startsWith(MS_PREFIX_WSPLGEN);
+                    return name.endsWith(".shp") &&
+                            (name.startsWith(MS_PREFIX_BARRIERS) ||
+                             name.startsWith(MS_PREFIX_USER)     ||
+                             name.startsWith(MS_PREFIX_WSPLGEN));
                 }
             });
 
@@ -268,6 +270,7 @@
             }
         }
 
+        logger.debug("searchForLayerShapes(): found " + shapes.size() + " shapefiles");
         return shapes;
     }
 

http://dive4elements.wald.intevation.org