# HG changeset patch # User Ingo Weinzierl # Date 1326196201 0 # Node ID 8cb679d4ec490f4822f1b27abe39513b82e6da76 # Parent 22732713c54d94ff14b851aa70238826eb22dde2 Implemented initialize() in FloodMapState to enable cloning floodmaps. flys-artifacts/trunk@3642 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 22732713c54d -r 8cb679d4ec49 flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/collections/AttributeWriter.java, diff -r 22732713c54d -r 8cb679d4ec49 flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.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 getFacets() { + List all = new ArrayList(); + + Set>> entries = facets.entrySet(); + for (Map.Entry> entry: entries) { + List 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 filterOutputs(List outs) { - if (filterFacets == null || filterFacets.isEmpty()) { logger.debug("No filter for Outputs."); return outs; } + logger.debug("Filter Facets with " + filterFacets.size() + " filters."); + List filtered = new ArrayList(); for (Output out: outs) { + String outName = out.getName(); - List fFacets = filterFacets.get(out.getName()); + logger.debug(" filter Facets for Output: " + outName); + + List 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 resultFacets = new ArrayList(); @@ -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 getOutputs(Object context) { + logger.debug("##### Get Outputs for: " + identifier() + " #####"); + List stateIds = getPreviousStateIds(); List generated = new ArrayList(); @@ -857,20 +889,28 @@ * @return list of output(s) for given state. */ protected List getOutputForState(DefaultState state) { + logger.debug("Find Outputs for State: " + state.getID()); + List list = state.getOutputs(); if (list == null || list.size() == 0) { logger.debug("-> No output modes for this state."); return new ArrayList(); } - List fs = facets.get(state.getID()); + String stateId = state.getID(); + + List fs = facets.get(stateId); if (fs == null || fs.size() == 0) { logger.debug("No facets found."); return new ArrayList(); } - return generateOutputs(list, fs); + List 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>> entries = facets.entrySet(); + + for (Map.Entry> entry: entries) { + String out = entry.getKey(); + List 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>> entries = filterFacets.entrySet(); + for (Map.Entry> entry: entries) { + String out = entry.getKey(); + List 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); diff -r 22732713c54d -r 8cb679d4ec49 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WMSLayerFacet.java --- 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 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; diff -r 22732713c54d -r 8cb679d4ec49 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java --- 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 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 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(