[PATCH] (issue1732) When duplication wsplgen artificats fix shapefile layers

Wald Commits scm-commit at wald.intevation.org
Tue Oct 28 18:52:45 CET 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1414518755 -3600
# Node ID b9a8463ac636e98f58dd80e89f9c4b17d63e6be2
# Parent  e3e5d6bb4902253eea9524982584c3c9d9bb8239
(issue1732) When duplication wsplgen artificats fix shapefile layers

    The shapefile layers are copied but still contained the old names
    and paths and the wms layer refered to layers from the old
    artifact. This was broken.
    Now the old artificat id is replaced by the new artifact id in the
    mapfiles.
    Duplication most wsplgen artifacts
    should now work.

diff -r e3e5d6bb4902 -r b9a8463ac636 artifacts/pom.xml
--- a/artifacts/pom.xml	Tue Oct 28 16:10:42 2014 +0100
+++ b/artifacts/pom.xml	Tue Oct 28 18:52:35 2014 +0100
@@ -110,6 +110,11 @@
       <version>1.4</version>
     </dependency>
     <dependency>
+        <groupId>commons-io</groupId>
+        <artifactId>commons-io</artifactId>
+        <version>2.4</version>
+    </dependency>
+    <dependency>
       <groupId>org.geotools</groupId>
       <artifactId>gt-shapefile</artifactId>
       <version>2.7.2</version>
diff -r e3e5d6bb4902 -r b9a8463ac636 artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java	Tue Oct 28 16:10:42 2014 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java	Tue Oct 28 18:52:35 2014 +0100
@@ -23,6 +23,7 @@
 
 import org.apache.log4j.Logger;
 import org.apache.velocity.Template;
+import org.apache.commons.io.FileUtils;
 import org.dive4elements.artifactdatabase.state.Facet;
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.CallContext;
@@ -109,6 +110,16 @@
     private static final String HWS_POINT_SHAPE = "hws-points.shp";
     private static final String HWS_POINTS = "hws-points";
 
+
+    /* List of possible map files this state handles . */
+    private static final String[] POSSIBLE_ADDITIONAL_MAPFILES = {HWS_LINES,
+                                                                  HWS_POINTS,
+                                                                  WSPLGEN_USER_RGD,
+                                                                  "barriers-lines",
+                                                                  "barriers-poly"};
+
+
+
     /**
      * @param orig
      * @param owner
@@ -124,7 +135,7 @@
     ) {
         log.info("Initialize State with Artifact: " + orig.identifier());
 
-        copyShapeDir(orig, owner);
+        copyAndFixShapeDir(orig, owner);
         modifyFacets(orig, owner, context, callMeta);
 
         ArtifactMapfileGenerator amfg = new ArtifactMapfileGenerator();
@@ -137,11 +148,28 @@
     }
 
 
-    protected void copyShapeDir(Artifact orig, Artifact owner) {
+    protected void copyAndFixShapeDir(Artifact orig, Artifact owner) {
+        /* We have a lot of generated mapfiles in here possibly.
+         * They use the orig artificact identifier. That has to
+         * be fixed.*/
         File origDir = getDirectory((D4EArtifact) orig);
         File thisDir = getDirectory((D4EArtifact) owner);
 
         FileTools.copyDirectory(origDir, thisDir);
+
+        for (String candidate: POSSIBLE_ADDITIONAL_MAPFILES) {
+            File f = new File(thisDir, MapfileGenerator.MS_LAYER_PREFIX + candidate);
+            if (f.exists()) {
+                log.debug("Fixing artifiact id's in: " + f);
+                try {
+                    String content = FileUtils.readFileToString(f);
+                    FileUtils.writeStringToFile(f,
+                            content.replaceAll(orig.identifier(), owner.identifier()));
+                } catch (IOException e) {
+                    log.debug("failed.");
+                }
+            }
+        }
     }
 
 
@@ -165,11 +193,11 @@
                 List<String> layers = wms.getLayers();
 
                 for (String layer: layers) {
-                    if (layer.startsWith(MapfileGenerator.MS_WSPLGEN_PREFIX)) {
+                    log.debug("Have layer: " + layer);
+                    if (layer.contains(orig.identifier())) {
                         wms.removeLayer(layer);
 
-                        String newLayer = MapfileGenerator.MS_WSPLGEN_PREFIX +
-                            owner.identifier();
+                        String newLayer = layer.replace(orig.identifier(), owner.identifier());
 
                         wms.addLayer(newLayer);
 


More information about the Dive4Elements-commits mailing list