changeset 443:da21c256a0ba

"horizontale Schnittprofile" are now configured via conf.xml gnv-artifacts/trunk@491 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 29 Dec 2009 14:54:17 +0000 (2009-12-29)
parents 52e031261eaa
children 85f48e287fb3
files gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/conf.xml gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContext.java gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java
diffstat 6 files changed, 128 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Tue Dec 29 10:09:26 2009 +0000
+++ b/gnv-artifacts/ChangeLog	Tue Dec 29 14:54:17 2009 +0000
@@ -1,3 +1,24 @@
+2009-12-29	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* doc/conf/conf.xml: Added a gnv/horizontal-cross-section-profile
+	  section to configure the "horizontalen Schnittprofile".
+	  <samples number=".."/> gives the number of samples the
+	  interpolation track is divided into. Defaults to 250
+
+	* src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContext.java:
+	  The names of the keys for fetching informations from the 
+	  configuration context are stored here now instead of the factory.
+
+	* src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java:
+	  Removed the lookup keys. Configure the "horizontalen Schnittprofile".
+
+	* src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java:
+	  Fetch number of samples from config now instead of no longer supported
+	  system property.
+
+	* src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java:
+	  The key from chart template config is now in GNVArtifactContext, too.
+
 2009-12-29	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* doc/conf/conf.xml: Moved chart template and palette config
--- a/gnv-artifacts/doc/conf/conf.xml	Tue Dec 29 10:09:26 2009 +0000
+++ b/gnv-artifacts/doc/conf/conf.xml	Tue Dec 29 14:54:17 2009 +0000
@@ -412,6 +412,10 @@
                      description="Palette for water temperature"
                      file="${artifacts.config.dir}/palette/water-temperature.xml"/>
         </palettes>
+        <horizontal-cross-section-profile>
+            <!-- This section configures the "horizontales Schnittprofil" -->
+            <samples number="200"/>
+        </horizontal-cross-section-profile>
     </gnv>
     <ehcache>
         <!--  In this Section the Path to Configurationfile for the EHCache,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContext.java	Tue Dec 29 10:09:26 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContext.java	Tue Dec 29 14:54:17 2009 +0000
@@ -9,15 +9,29 @@
 import de.intevation.artifactdatabase.DefaultArtifactContext;
 
 /**
- * @author Tim Englich <tim.englich@intevation.de>
- * 
+ * @author Tim Englich         (tim.englich@intevation.de)
+ * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
  */
-public class GNVArtifactContext extends DefaultArtifactContext {
+public class GNVArtifactContext 
+extends      DefaultArtifactContext
+{
     /**
      * the logger, used to log exceptions and additonaly information
      */
     private static Logger log = Logger.getLogger(GNVArtifactContext.class);
 
+    public static final String CHART_TEMPLATE_KEY =
+        "gnv.chart.template";
+
+    public static final String HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES_KEY =
+        "gnv.horizontal.cross.section.profile.samples";
+
+    public static final Integer 
+        DEFAULT_HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES = Integer.valueOf(250);
+
+    public static final String PALETTES_KEY =
+        "gnv.color.palettes";
+
     public GNVArtifactContext() {
         super();
         log.debug("GNVArtifactContext.Constructor");
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java	Tue Dec 29 10:09:26 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java	Tue Dec 29 14:54:17 2009 +0000
@@ -18,7 +18,6 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
-import org.w3c.dom.Node;
 
 import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory;
 
@@ -66,10 +65,8 @@
     public final static String PALETTE_ITEMS =
         "palette";
 
-    public final static String PALETTES =
-        "gnv.color.palettes";
-
-    public final static String CHARTTEMPLATE = "gnv.chart.template";
+    public final static String HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES =
+        "/artifact-database/gnv/horizontal-cross-section-profile/samples/@number";
 
     /**
      * Constructor
@@ -121,6 +118,7 @@
 
             configureChartTemplate(config, returnValue);
 
+            configureHorizontalCrossSectionProfile(config, returnValue);
 
         } catch (FileNotFoundException e) {
             log.error(e, e);
@@ -132,6 +130,39 @@
         return returnValue;
     }
 
+    protected void configureHorizontalCrossSectionProfile(
+        Document           config,
+        GNVArtifactContext context
+    )
+    {
+        log.info("configuration of horizontal cross section profile");
+
+        String numSamples = Config.getStringXPath(
+            config,
+            HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES);
+
+        Integer samples =
+            GNVArtifactContext.DEFAULT_HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES;
+
+        if (numSamples == null) {
+            log.warn("No number of samples found.");
+        }
+        else {
+            try {
+                samples = Integer.valueOf(numSamples);
+            }
+            catch (NumberFormatException nfe) {
+                log.warn("Invalid integer for number of samples");
+            }
+        }
+
+        log.info("# horizontal cross section profile samples: " + samples);
+
+        context.put(
+            GNVArtifactContext.HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES_KEY,
+            samples);
+    }
+
     protected void configureChartTemplate(
         Document           config,
         GNVArtifactContext context
@@ -140,21 +171,28 @@
         String chartConfigFile = Config.getStringXPath(
             config, CHARTCONFIGNODEPATH
         );
-        chartConfigFile = Config.replaceConfigDir(chartConfigFile);
-        log.debug("Parse xml configuration of " + chartConfigFile);
 
-        Document tmpl = XMLUtils.parseDocument(new File(chartConfigFile));
         XMLChartTheme theme = new XMLChartTheme("XMLChartTheme");
-        if (tmpl != null) {
-            theme.applyXMLConfiguration(tmpl);
+
+        if (chartConfigFile == null) {
+            log.warn("no configuration file for chart template found");
         }
         else {
-            log.error(
-                "Cannot load chart template from '" +
-                chartConfigFile + "'");
+            chartConfigFile = Config.replaceConfigDir(chartConfigFile);
+            log.debug("Parse xml configuration of " + chartConfigFile);
+
+            Document tmpl = XMLUtils.parseDocument(new File(chartConfigFile));
+            if (tmpl != null) {
+                theme.applyXMLConfiguration(tmpl);
+            }
+            else {
+                log.error(
+                    "Cannot load chart template from '" +
+                    chartConfigFile + "'");
+            }
         }
 
-        context.put(CHARTTEMPLATE, theme);
+        context.put(GNVArtifactContext.CHART_TEMPLATE_KEY, theme);
     }
 
     protected void configurePalettes(
@@ -221,7 +259,7 @@
             } // for all palettes
         }
 
-        context.put(PALETTES, palettes);
+        context.put(GNVArtifactContext.PALETTES_KEY, palettes);
     }
 
     /**
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java	Tue Dec 29 10:09:26 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java	Tue Dec 29 14:54:17 2009 +0000
@@ -36,6 +36,8 @@
 import de.intevation.gnv.utils.WKTUtils;
 import de.intevation.gnv.utils.StringUtils;
 
+import de.intevation.gnv.artifacts.context.GNVArtifactContext;
+
 import de.intevation.artifacts.CallContext;
 
 import org.jfree.chart.ChartTheme;
@@ -43,8 +45,9 @@
 import com.vividsolutions.jts.geom.Coordinate;
 
 /**
- * @author Tim Englich <tim.englich@intevation.de>
- *
+ * @author Tim Englich         (tim.englich@intevation.de)
+ * @author Ingo Weinzierl      (iweinzierl@intevation.de)
+ * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
  */
 public class HorizontalProfileMeshCrossOutputState extends
                                                   HorizontalProfileOutputState {
@@ -127,6 +130,16 @@
         return chart;
     }
 
+	private static int numSamples(CallContext callContext) {
+		GNVArtifactContext context =
+            (GNVArtifactContext)callContext.globalContext();
+		Integer samples = (Integer)context.get(
+			GNVArtifactContext.HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES_KEY);
+		return samples != null
+			? samples.intValue()
+			: GNVArtifactContext.DEFAULT_HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES;
+	}
+
     @Override
     protected Object getChartResult(String uuid, CallContext callContext) {
         log.debug("HorizontalProfileMeshCrossOutputState.getChartResult");
@@ -177,6 +190,7 @@
 
                     result = process(
                         Arrays.asList(coords),
+						numSamples(callContext),
                         queryExecutor.executeQuery(
                         queryID,
                         addedFilterValues));
@@ -206,9 +220,16 @@
 
     public static Collection<Result> process(
         List<Coordinate>   path,
+		int                numSamples,
         Collection<Result> input
     ) {
-        log.debug("------  number of points before processing: " + input.size());
+		boolean debug = log.isDebugEnabled();
+
+		if (debug) {
+			log.debug("--- number of points before processing: " + input.size());
+			log.debug("    number samples: " + numSamples);
+		}
+
         ArrayList<Result> output = new ArrayList<Result>();
 
         Result last = null;
@@ -239,6 +260,7 @@
 
                 sectionHandler = new SectionHandler(
                     path,
+					numSamples,
                     output,
                     resultDescriptor);
 
@@ -259,7 +281,9 @@
             sectionHandler.finish();
         }
 
-        log.debug("------  number of points after processing: " + output.size());
+		if (debug) {
+			log.debug("--- number of points after processing: " + output.size());
+		}
 
         return output;
     }
@@ -278,9 +302,6 @@
 
     public static final double EPSILON = 1e-5d;
 
-    public static final int    INTERPOLATION_STEPS =
-        Integer.getInteger("interpolation.steps", 500).intValue();
-
     public static final class SectionHandler
     implements                Interpolation2D.Consumer
     {
@@ -290,16 +311,19 @@
         private Result             prototyp;
         private ResultDescriptor   descriptor;
         private boolean            lastWasSuccess;
+		private int                numSamples;
 
         public SectionHandler() {
         }
 
         public SectionHandler(
             List<Coordinate>   path,
+			int                numSamples,
             Collection<Result> output,
             ResultDescriptor   descriptor
         ) {
             this.path       = path;
+			this.numSamples = numSamples;
             this.output     = output;
             this.descriptor = descriptor;
             points          = new ArrayList<Point2d>();
@@ -318,7 +342,7 @@
                         points,
                         0d,
                         distance,
-                        INTERPOLATION_STEPS,
+                        numSamples,
                         LinearMetrics.INSTANCE,
                         this);
                 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Tue Dec 29 10:09:26 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Tue Dec 29 14:54:17 2009 +0000
@@ -38,7 +38,6 @@
 import de.intevation.artifacts.CallContext;
 import de.intevation.artifacts.PreferredLocale;
 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
-import de.intevation.gnv.artifacts.context.GNVArtifactContextFactory;
 import de.intevation.gnv.artifacts.ressource.RessourceFactory;
 import de.intevation.gnv.chart.Chart;
 import de.intevation.gnv.chart.ChartLabels;
@@ -769,8 +768,7 @@
             (GNVArtifactContext) callContext.globalContext();
 
         XMLChartTheme theme = (XMLChartTheme) context.get(
-            GNVArtifactContextFactory.CHARTTEMPLATE
-        );
+            GNVArtifactContext.CHART_TEMPLATE_KEY);
 
         return theme;
     }

http://dive4elements.wald.intevation.org