changeset 2095:8cb679d4ec49

Implemented initialize() in FloodMapState to enable cloning floodmaps. flys-artifacts/trunk@3642 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 10 Jan 2012 11:50:01 +0000
parents 22732713c54d
children bf598599782a
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WMSLayerFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java
diffstat 4 files changed, 179 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jan 10 11:44:46 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jan 10 11:50:01 2012 +0000
@@ -1,3 +1,18 @@
+2012-01-10  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/WMSLayerFacet.java: Added
+	  methods getLayers() and removeLayer().
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Added a
+	  method getFacets() which returns a list of Facets supported by this
+	  Artifact. In addition, the FLYSArtifact is now more verbose while
+	  filtering Facets for Outputs.
+
+	* src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java:
+	  Implemented initialize() which now copies the shapefile directory of the
+	  model Artifact and modifies its Facets (adapts the shapepath which is the
+	  uuid of the Artifact).
+
 2012-01-10  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/collections/AttributeWriter.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Tue Jan 10 11:44:46 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Tue Jan 10 11:50:01 2012 +0000
@@ -262,7 +262,7 @@
             State state = getState(context, stateId);
 
             if (state != null) {
-                state.initialize(artifact, context, callMeta);
+                state.initialize(artifact, this, context, callMeta);
             }
         }
     }
@@ -620,6 +620,21 @@
     }
 
 
+    public List<Facet> getFacets() {
+        List<Facet> all = new ArrayList<Facet>();
+
+        Set<Map.Entry<String, List<Facet>>> entries = facets.entrySet();
+        for (Map.Entry<String, List<Facet>> entry: entries) {
+            List<Facet> fs = entry.getValue();
+            for (Facet f: fs) {
+                all.add(f);
+            }
+        }
+
+        return all;
+    }
+
+
     /**
      * Get facet as stored internally, with equalling name and index than given
      * facet.
@@ -772,18 +787,29 @@
      * @return filtered Outputlist.
      */
     protected List<Output> filterOutputs(List<Output> outs) {
-
         if (filterFacets == null || filterFacets.isEmpty()) {
             logger.debug("No filter for Outputs.");
             return outs;
         }
 
+        logger.debug("Filter Facets with " + filterFacets.size() + " filters.");
+
         List<Output> filtered = new ArrayList<Output>();
 
         for (Output out: outs) {
+            String outName = out.getName();
 
-            List<Facet> fFacets = filterFacets.get(out.getName());
+            logger.debug("  filter Facets for Output: " + outName);
+
+            List<Facet> fFacets = filterFacets.get(outName);
             if (fFacets != null) {
+                logger.debug("" + fFacets.size() + " filters for: " + outName);
+
+                if (logger.isDebugEnabled()) {
+                    for (Facet tmp: fFacets) {
+                        logger.debug("   filter = '" + tmp.getName() + "'");
+                    }
+                }
 
                 List<Facet> resultFacets = new ArrayList<Facet>();
 
@@ -797,6 +823,8 @@
                     }
                 }
 
+                logger.debug("Facets after filtering = " + resultFacets.size());
+
                 if (!resultFacets.isEmpty()) {
                     DefaultOutput nout = new DefaultOutput(
                         out.getName(),
@@ -808,6 +836,8 @@
             }
         }
 
+        logger.debug("All Facets after filtering = " + filtered.size());
+
         return filtered;
     }
 
@@ -819,6 +849,8 @@
      * @return list of outputs
      */
     public List<Output> getOutputs(Object context) {
+        logger.debug("##### Get Outputs for: " + identifier() + " #####");
+
         List<String> stateIds  = getPreviousStateIds();
         List<Output> generated = new ArrayList<Output>();
 
@@ -857,20 +889,28 @@
      * @return list of output(s) for given state.
      */
     protected List<Output> getOutputForState(DefaultState state) {
+        logger.debug("Find Outputs for State: " + state.getID());
+
         List<Output> list = state.getOutputs();
         if (list == null || list.size() == 0) {
             logger.debug("-> No output modes for this state.");
             return new ArrayList<Output>();
         }
 
-        List<Facet> fs = facets.get(state.getID());
+        String stateId = state.getID();
+
+        List<Facet> fs = facets.get(stateId);
 
         if (fs == null || fs.size() == 0) {
             logger.debug("No facets found.");
             return new ArrayList<Output>();
         }
 
-        return generateOutputs(list, fs);
+        List<Output> gen = generateOutputs(list, fs);
+
+        logger.debug("State '" + stateId + "' has " + gen.size() + " outs");
+
+        return gen;
     }
 
 
@@ -1077,11 +1117,54 @@
 
             logger.debug("CURRENT STATE: " + getCurrentStateId());
 
+            debugFacets();
+            dumpFilterFacets();
+
             logger.debug("++++++++++++++ END ARTIFACT DUMP +++++++++++++++++");
         }
     }
 
 
+    protected void debugFacets() {
+        logger.debug("######### FACETS #########");
+        Set<Map.Entry<String, List<Facet>>> entries = facets.entrySet();
+
+        for (Map.Entry<String, List<Facet>> entry: entries) {
+            String out = entry.getKey();
+            List<Facet> fs = entry.getValue();
+            for (Facet f: fs) {
+                logger.debug("  # " + out + " : " + f.getName());
+            }
+        }
+
+        logger.debug("######## FACETS END ########");
+    }
+
+
+    protected void dumpFilterFacets() {
+        logger.debug("######## FILTER FACETS ########");
+
+        if (filterFacets == null || filterFacets.isEmpty()) {
+            logger.debug("No Filter Facets defined.");
+            return;
+        }
+
+        Set<Map.Entry<String, List<Facet>>> entries = filterFacets.entrySet();
+        for (Map.Entry<String, List<Facet>> entry: entries) {
+            String      out     = entry.getKey();
+            List<Facet> filters = entry.getValue();
+
+            logger.debug("There are " + filters.size() + " filters for: " +out);
+
+            for (Facet filter: filters) {
+                logger.debug("  filter: " + filter.getName());
+            }
+        }
+
+        logger.debug("######## FILTER FACETS END ########");
+    }
+
+
     protected void destroyState(String id, Object context) {
         State s = getState(context, id);
         s.endOfLife(this, context);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WMSLayerFacet.java	Tue Jan 10 11:44:46 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WMSLayerFacet.java	Tue Jan 10 11:50:01 2012 +0000
@@ -85,6 +85,18 @@
     }
 
 
+    public List<String> getLayers() {
+        return layers;
+    }
+
+
+    public void removeLayer(String layer) {
+        if (layers != null) {
+            layers.remove(layer);
+        }
+    }
+
+
     public void setExtent(Envelope extent) {
         if (extent != null) {
             this.extent = extent;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Tue Jan 10 11:44:46 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Tue Jan 10 11:50:01 2012 +0000
@@ -40,6 +40,7 @@
 import de.intevation.flys.artifacts.model.CalculationMessage;
 import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.WMSLayerFacet;
 import de.intevation.flys.artifacts.model.WQKms;
 import de.intevation.flys.artifacts.model.WSPLGENCalculation;
 import de.intevation.flys.artifacts.model.WSPLGENJob;
@@ -67,6 +68,8 @@
         System.getProperty("flys.uesk.keep.artifactsdir", "false");
 
 
+    public static final String OUTPUT_NAME = "floodmap";
+
     public static final String WSP_ARTIFACT = "wsp";
 
     public static final String WINFO_WSP_STATE_ID = "state.winfo.waterlevel";
@@ -83,12 +86,72 @@
     public static final int WSPLGEN_DEFAULT_OUTPUT = 0;
 
 
+    /**
+     * @param orig
+     * @param owner
+     * @param context
+     * @param callMeta
+     */
     @Override
-    public void initialize(Artifact orig, Object context, CallMeta callMeta) {
+    public void initialize(
+        Artifact orig,
+        Artifact owner,
+        Object   context,
+        CallMeta callMeta
+    ) {
         logger.info("Initialize State with Artifact: " + orig.identifier());
+
+        copyShapeDir(orig, owner);
+        modifyFacets(orig, owner, context, callMeta);
+
+        MapfileGenerator.getInstance().update();
     }
 
 
+    protected void copyShapeDir(Artifact orig, Artifact owner) {
+        File origDir = getDirectory((FLYSArtifact) orig);
+        File thisDir = getDirectory((FLYSArtifact) owner);
+
+        FileTools.copyDirectory(origDir, thisDir);
+    }
+
+
+    protected void modifyFacets(
+        Artifact orig,
+        Artifact owner,
+        Object   context,
+        CallMeta callMeta
+    ) {
+        FLYSArtifact flys  = (FLYSArtifact) owner;
+        List<Facet> facets = flys.getFacets();
+        if (facets == null || facets.size() == 0) {
+            logger.warn("No facets for '" + OUTPUT_NAME + "' given!");
+            return;
+        }
+
+        for (Facet facet: facets) {
+            if (facet instanceof WMSLayerFacet) {
+                WMSLayerFacet wms = (WMSLayerFacet) facet;
+
+                List<String> layers = wms.getLayers();
+
+                for (String layer: layers) {
+                    if (layer.startsWith(MapfileGenerator.MS_WSPLGEN_PREFIX)) {
+                        wms.removeLayer(layer);
+
+                        String newLayer = MapfileGenerator.MS_WSPLGEN_PREFIX +
+                            owner.identifier();
+
+                        wms.addLayer(newLayer);
+
+                        logger.debug(
+                            "Replaced layer: " + layer + " with " + newLayer);
+                    }
+                }
+            }
+        }
+    }
+
 
     @Override
     public Object computeAdvance(

http://dive4elements.wald.intevation.org