changeset 1164:0398c2b8dbaf

Do only create WSPLGEN and barrier facets if the WSPLGEN job has been added to the Scheduler and if there are digitized geometries existing. flys-artifacts/trunk@2701 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 12 Sep 2011 11:40:04 +0000
parents 2e0739853807
children 3b034bb5fce7
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java
diffstat 3 files changed, 117 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Sep 12 11:30:19 2011 +0000
+++ b/flys-artifacts/ChangeLog	Mon Sep 12 11:40:04 2011 +0000
@@ -1,3 +1,14 @@
+2011-09-12  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/utils/GeometryUtils.java: Write
+	  shapefiles only if there are features for it existing.
+
+	* src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java:
+	  A WSPLGEN facet is only created, if the calculation was successfully
+	  added to the Scheduler. A barrier facet is only created if the WSPLGEN
+	  calculation has been added to the scheduler AND if there are digitized
+	  geometries existing.
+
 2011-09-12  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
  Copied and slightly modified implementation of guessWaterIncreasing from
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Mon Sep 12 11:30:19 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Mon Sep 12 11:40:04 2011 +0000
@@ -79,6 +79,85 @@
 
 
 
+    /**
+     * Inner class that is used to create facets. An instance of this class is
+     * used while packaging the data for the WSPLGEN calculation.
+     */
+    private static class FacetCreator {
+        protected FLYSArtifact artifact;
+        protected List<Facet>  facets;
+        protected String url;
+        protected String hash;
+        protected String stateId;
+
+        public FacetCreator(FLYSArtifact artifact, String hash, String sId) {
+            this.facets     = new ArrayList<Facet>(2);
+            this.artifact   = artifact;
+            this.hash       = hash;
+            this.stateId    = sId;
+        }
+
+        protected String getRiver() {
+            return artifact.getDataAsString("river");
+        }
+
+        protected String getUrl() {
+            String url = FLYSUtils.getXPathString(FLYSUtils.XPATH_MAPSERVER_URL);
+            url = url + "user-wms";
+            return url;
+        }
+
+        protected String getSrid() {
+            return FLYSUtils.getRiverSrid(artifact);
+        }
+
+        protected String getBounds() {
+            return GeometryUtils.getRiverBounds(getRiver());
+        }
+
+        public List<Facet> getFacets() {
+            return facets;
+        }
+
+        public void createWSPLGENFacet() {
+            WMSLayerFacet wsplgen = new WMSLayerFacet(
+                0,
+                FLOODMAP_WSPLGEN,
+                "Ergebnis der WSPLGEN Berechnung",
+                ComputeType.ADVANCE,
+                stateId,
+                hash,
+                getUrl());
+
+            wsplgen.addLayer(
+                artifact.identifier() + MapfileGenerator.MS_WSPLGEN_POSTFIX);
+            wsplgen.setSrid(getSrid());
+            wsplgen.setExtent(getBounds());
+
+            facets.add(wsplgen);
+        }
+
+        public void createBarrierFacet() {
+            WMSLayerFacet barriers = new WMSLayerFacet(
+                1,
+                FLOODMAP_WSPLGEN,
+                "Rohre/Graeben/Daemme",
+                ComputeType.ADVANCE,
+                stateId,
+                hash,
+                getUrl());
+
+            barriers.addLayer(
+                artifact.identifier() + MapfileGenerator.MS_BARRIERS_POSTFIX);
+            barriers.setSrid(getSrid());
+            barriers.setExtent(getBounds());
+
+            facets.add(barriers);
+        }
+    } // end of FacetCreator
+
+
+
     @Override
     public Object computeAdvance(
         FLYSArtifact artifact,
@@ -98,8 +177,11 @@
 
         WSPLGENCalculation calculation = new WSPLGENCalculation();
 
+        FacetCreator facetCreator = new FacetCreator(artifact, hash, getID());
+
         WSPLGENJob job = prepareWSPLGENJob(
             artifact,
+            facetCreator,
             artifactDir,
             context,
             calculation);
@@ -117,47 +199,14 @@
         Scheduler scheduler = Scheduler.getInstance();
         scheduler.addJob(job);
 
-        String url = FLYSUtils.getXPathString(FLYSUtils.XPATH_MAPSERVER_URL);
-        url = url + "user-wms";
-
-        WMSLayerFacet wsplgen = new WMSLayerFacet(
-            0,
-            FLOODMAP_WSPLGEN,
-            "Ergebnis der WSPLGEN Berechnung",
-            ComputeType.ADVANCE,
-            getID(),
-            hash,
-            url);
-
-        String srid  = FLYSUtils.getRiverSrid(artifact);
-        String river = artifact.getDataAsString("river");
-
-        wsplgen.addLayer(
-            artifact.identifier() + MapfileGenerator.MS_WSPLGEN_POSTFIX);
-        wsplgen.setSrid(srid);
-        wsplgen.setExtent(GeometryUtils.getRiverBounds(river));
-
-        WMSLayerFacet barriers = new WMSLayerFacet(
-            1,
-            FLOODMAP_WSPLGEN,
-            "Rohre/Graeben/Daemme",
-            ComputeType.ADVANCE,
-            getID(),
-            hash,
-            url);
-
-        barriers.addLayer(
-            artifact.identifier() + MapfileGenerator.MS_BARRIERS_POSTFIX);
-        barriers.setSrid(srid);
-        barriers.setExtent(GeometryUtils.getRiverBounds(river));
+        facetCreator.createWSPLGENFacet();
 
         CalculationResult  res   = new CalculationResult(null, calculation);
         WSPLGENReportFacet report= new WSPLGENReportFacet(
             ComputeType.ADVANCE, hash, getID(), res);
 
-        facets.add(wsplgen);
-        facets.add(barriers);
         facets.add(report);
+        facets.addAll(facetCreator.getFacets());
 
         context.afterCall(CallContext.BACKGROUND);
 
@@ -215,6 +264,7 @@
 
     protected WSPLGENJob prepareWSPLGENJob(
         FLYSArtifact       artifact,
+        FacetCreator       facetCreator,
         File               artifactDir,
         CallContext        context,
         WSPLGENCalculation calculation
@@ -234,7 +284,7 @@
         setDelta(artifact, job);
         setGel(artifact, job);
         setDist(artifact, job);
-        setLine(artifact, artifactDir, job);
+        setLine(artifact, facetCreator, artifactDir, job);
         setAxis(artifact, artifactDir, job);
         setPro(artifact, artifactDir, job);
         setDgm(artifact, job);
@@ -327,11 +377,21 @@
     }
 
 
-    protected void setLine(FLYSArtifact artifact, File dir, WSPLGENJob job) {
+    protected void setLine(
+        FLYSArtifact artifact,
+        FacetCreator facetCreator,
+        File         dir,
+        WSPLGENJob   job
+    ) {
         String geoJSON = artifact.getDataAsString("uesk.barriers");
         String srid    = FLYSUtils.getRiverSrid(artifact);
         String srs     = "EPSG:" + srid;
 
+        if (geoJSON == null || geoJSON.length() == 0) {
+            logger.debug("No barrier features in parameterization existing.");
+            return;
+        }
+
         SimpleFeatureType ft = getBarriersFeatureType(
             "barriers", srs, Geometry.class);
 
@@ -373,6 +433,10 @@
                 "Write shapefile path into WSPLGEN job.");
             job.addLin(shapePolys.getAbsolutePath());
         }
+
+        if (p || l) {
+            facetCreator.createBarrierFacet();
+        }
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java	Mon Sep 12 11:30:19 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java	Mon Sep 12 11:40:04 2011 +0000
@@ -155,6 +155,11 @@
         SimpleFeatureType featureType,
         FeatureCollection collection
     ) {
+        if (collection.isEmpty()) {
+            logger.warn("Shapefile is not written - no features given!");
+            return false;
+        }
+
         Transaction transaction = null;
 
         try {

http://dive4elements.wald.intevation.org