changeset 5023:1da61095040c mapgenfix

Renaming methods and fields. Start refactoring with ArtifactMapfileGenerator.generate() which should be the main entry point.
author Christian Lins <christian.lins@intevation.de>
date Tue, 19 Feb 2013 14:25:38 +0100
parents a9243df307b1
children cc50e1b9fc60
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java flys-artifacts/src/main/java/de/intevation/flys/mapserver/ArtifactMapfileGenerator.java flys-artifacts/src/main/java/de/intevation/flys/mapserver/MapfileGenerator.java flys-artifacts/src/main/java/de/intevation/flys/wsplgen/FacetCreator.java
diffstat 4 files changed, 66 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Tue Feb 19 13:41:20 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Tue Feb 19 14:25:38 2013 +0100
@@ -143,10 +143,10 @@
                 List<String> layers = wms.getLayers();
 
                 for (String layer: layers) {
-                    if (layer.startsWith(MapfileGenerator.MS_WSPLGEN_PREFIX)) {
+                    if (layer.startsWith(MapfileGenerator.MS_PREFIX_WSPLGEN)) {
                         wms.removeLayer(layer);
 
-                        String newLayer = MapfileGenerator.MS_WSPLGEN_PREFIX +
+                        String newLayer = MapfileGenerator.MS_PREFIX_WSPLGEN +
                             owner.identifier();
 
                         wms.addLayer(newLayer);
--- a/flys-artifacts/src/main/java/de/intevation/flys/mapserver/ArtifactMapfileGenerator.java	Tue Feb 19 13:41:20 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/mapserver/ArtifactMapfileGenerator.java	Tue Feb 19 14:25:38 2013 +0100
@@ -14,6 +14,7 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.log4j.Logger;
@@ -42,17 +43,35 @@
     }
 
     /**
-     * Method which starts searching for meta information file and mapfile
-     * generation.
+     * Generates flys.map file that contains layers of all
+     * projects and types (floodmap, user defined, barriers).
      */
     @Override
     public void generate() throws IOException
     {
-        File[] userDirs = getUserDirs();
-        List<String> layers = parseLayers(userDirs);
-        logger.info("Found " + layers.size() + " layers for user mapfile.");
+        // Get all directories below "shapefiles/"
+        File[] prjDirs = getProjectDirs();
 
-        writeMapfile(layers);
+        // Look for appropriate shapefiles that we can use as layers
+        List<File> layerShapes = searchForLayerShapes(prjDirs);
+
+        List<String> layerSnippets = new ArrayList<String>();
+
+        // Generate layer snippet for each shapefile
+        for (File layerShape : layerShapes) {
+            String fileName = layerShape.getName();
+            if (fileName.startsWith(MS_PREFIX_BARRIERS)) {
+
+            }
+            else if (fileName.startsWith(MS_PREFIX_USER)) {
+
+            }
+            else if (fileName.startsWith(MS_PREFIX_WSPLGEN)) {
+
+            }
+        }
+
+        writeMapfile(layerSnippets);
     }
 
     /**
@@ -62,7 +81,7 @@
      * @param flys The FLYSArtifact that owns <i>wms</i>.
      * @param wms The WMSLayerFacet that contains information for the layer.
      */
-    public void createUeskLayer(
+    protected void createUeskLayer(
         FLYSArtifact  flys,
         WSPLGENLayerFacet wms,
         String        style,
@@ -110,7 +129,7 @@
      * @param flys The FLYSArtifact that owns <i>wms</i>.
      * @param wms The WMSLayerFacet that contains information for the layer.
      */
-    public void createBarriersLayer(FLYSArtifact flys, WMSLayerFacet wms)
+    protected void createBarriersLayer(FLYSArtifact flys, WMSLayerFacet wms)
     throws FileNotFoundException, IOException
     {
         logger.debug("createBarriersLayer");
@@ -221,7 +240,7 @@
          * @param flys The FLYSArtifact that owns <i>wms</i>.
          * @param wms The WMSLayerFacet that contains information for the layer.
          */
-        public void createUserShapeLayer(FLYSArtifact flys, WMSLayerFacet wms)
+        protected void createUserShapeLayer(FLYSArtifact flys, WMSLayerFacet wms)
         throws FileNotFoundException, IOException
         {
             logger.debug("createUserShapeLayer");
@@ -287,7 +306,7 @@
          * @param flys The FLYSArtifact that owns <i>wms</i>.
          * @param wms The WMSLayerFacet that contains information for the layer.
          */
-        public void createDatabaseLayer(
+        protected void createDatabaseLayer(
             FLYSArtifact    flys,
             WMSDBLayerFacet wms,
             String          style
--- a/flys-artifacts/src/main/java/de/intevation/flys/mapserver/MapfileGenerator.java	Tue Feb 19 13:41:20 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/mapserver/MapfileGenerator.java	Tue Feb 19 14:25:38 2013 +0100
@@ -39,12 +39,12 @@
     public static final String DB_LAYER_TEMPLATE  = "db_layer.vm";
     public static final String RIVERAXIS_LAYER_TEMPLATE = "riveraxis-layer.vm";
 
-    public static final String MS_WSPLGEN_PREFIX   = "wsplgen-";
-    public static final String MS_BARRIERS_PREFIX  = "barriers-";
-    public static final String MS_LINE_PREFIX      = "lines-";
-    public static final String MS_POLYGONS_PREFIX  = "polygons-";
-    public static final String MS_LAYER_PREFIX     = "ms_layer-";
-    public static final String MS_USERSHAPE_PREFIX = "user-";
+    public static final String MS_PREFIX_WSPLGEN   = "wsplgen-";
+    public static final String MS_PREFIX_BARRIERS  = "barriers-";
+ //   public static final String MS_LINE_PREFIX      = "lines-";
+ //   public static final String MS_POLYGONS_PREFIX  = "polygons-";
+//    public static final String MS_LAYER_PREFIX     = "ms_layer-";
+    public static final String MS_PREFIX_USER = "user-";
 
     private static Logger logger = Logger.getLogger(MapfileGenerator.class);
 
@@ -63,12 +63,18 @@
      * @param templateID The name of a template.
      * @return true, of the template exists - otherwise false.
      */
-    public boolean templateExists(String templateID){
+    protected boolean templateExists(String templateID){
         Template template = getTemplateByName(templateID);
         return template != null;
     }
 
 
+    /**
+     * Starts the mapfile generation. This is the main entry point for
+     * the mapfile generation, all other methods of this class/package
+     * *should* be non-public.
+     * @throws Exception
+     */
     public abstract void generate() throws Exception;
 
 
@@ -228,40 +234,41 @@
     }
 
 
-    protected File[] getUserDirs()
+    protected File[] getProjectDirs()
             throws FileNotFoundException, IOException
     {
         File   baseDir      = getShapefileBaseDir();
         File[] artifactDirs = baseDir.listFiles();
 
-        // TODO ONLY RETURN DIRECTORIES OF THE SPECIFIED USER
-
         return artifactDirs;
     }
 
 
-    protected List<String> parseLayers(File[] dirs) {
-        List<String> layers = new ArrayList<String>();
+    /**
+     * Search in all given directories for shapefiles that can be used
+     * as barrier, user oder wsplgen layers.
+     * @param dirs
+     * @return
+     */
+    protected List<File> searchForLayerShapes(File[] dirs) {
+        List<File> shapes = new ArrayList<File>();
 
         for (File dir: dirs) {
             File[] layerFiles = dir.listFiles(new FilenameFilter() {
                 @Override
                 public boolean accept(File directory, String name) {
-                    return name.startsWith(MS_LAYER_PREFIX);
+                    return name.startsWith(MS_PREFIX_BARRIERS) ||
+                           name.startsWith(MS_PREFIX_USER) ||
+                           name.startsWith(MS_PREFIX_WSPLGEN);
                 }
             });
 
             for (File layer: layerFiles) {
-                try {
-                    layers.add(layer.getCanonicalPath());
-                }
-                catch (IOException ioe) {
-                    logger.warn(ioe, ioe);
-                }
+                shapes.add(layer);
             }
         }
 
-        return layers;
+        return shapes;
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/FacetCreator.java	Tue Feb 19 13:41:20 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/FacetCreator.java	Tue Feb 19 14:25:38 2013 +0100
@@ -1,16 +1,11 @@
 package de.intevation.flys.wsplgen;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
 import com.vividsolutions.jts.geom.Envelope;
 
 import de.intevation.artifactdatabase.state.Facet;
 import de.intevation.artifacts.CallContext;
+import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.access.RangeAccess;
-import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.map.WMSLayerFacet;
 import de.intevation.flys.artifacts.model.map.WSPLGENLayerFacet;
@@ -21,6 +16,11 @@
 import de.intevation.flys.utils.FLYSUtils;
 import de.intevation.flys.utils.GeometryUtils;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
 
 public class FacetCreator implements FacetTypes {
 
@@ -138,7 +138,7 @@
         }
 
         wsplgen.addLayer(
-            MapfileGenerator.MS_WSPLGEN_PREFIX + artifact.identifier());
+            MapfileGenerator.MS_PREFIX_WSPLGEN + artifact.identifier());
         wsplgen.setSrid(getSrid());
         wsplgen.setOriginalExtent(bounds);
         wsplgen.setExtent(bounds);
@@ -160,7 +160,7 @@
             getUrl());
 
         barriers.addLayer(
-            MapfileGenerator.MS_BARRIERS_PREFIX + artifact.identifier());
+            MapfileGenerator.MS_PREFIX_WSPLGEN + artifact.identifier());
         barriers.setSrid(getSrid());
         barriers.setExtent(getBounds());
 

http://dive4elements.wald.intevation.org