changeset 1116:05e4ef0f9489

Improved stub for CrossSections (including Factory and Facet). flys-artifacts/trunk@2623 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 31 Aug 2011 12:23:05 +0000
parents eaf32c767bac
children ea80e652f033
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFactory.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java
diffstat 6 files changed, 141 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Aug 31 12:20:23 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Aug 31 12:23:05 2011 +0000
@@ -1,3 +1,18 @@
+2011-08-31  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	More bones to CrossSection sceleton.
+
+	* src/main/java/de/intevation/flys/artifacts/model/CrossSectionFactory.java,
+	  src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java:
+	  New, yet trivial implementations of Factory and Facet for CrossSections.
+
+	* src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java:
+	  Add new CrossSection- (instead of Default-)Facet.
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java,
+	  src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java:
+	  Adjusted to use (touch) new Factory and Facet.
+
 2011-08-31  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	Cosmetics.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Aug 31 12:20:23 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Aug 31 12:23:05 2011 +0000
@@ -25,6 +25,7 @@
 import de.intevation.flys.artifacts.model.Calculation4;
 import de.intevation.flys.artifacts.model.Calculation;
 import de.intevation.flys.artifacts.model.CalculationResult;
+import de.intevation.flys.artifacts.model.CrossSectionFactory;
 import de.intevation.flys.artifacts.model.DischargeTables;
 import de.intevation.flys.artifacts.model.MainValuesFactory;
 import de.intevation.flys.artifacts.model.Segment;
@@ -37,6 +38,7 @@
 
 import de.intevation.flys.model.Gauge;
 import de.intevation.flys.model.River;
+import de.intevation.flys.model.CrossSection;
 
 import de.intevation.flys.utils.DoubleUtil;
 import de.intevation.flys.utils.FLYSUtils;
@@ -597,6 +599,15 @@
         return Segment.parseSegments(input);
     }
 
+    public List<CrossSection> getCrossSections() {
+        River river = FLYSUtils.getRiver(this);
+        if (river == null) {
+            logger.warn("No river in WINFO found");
+            return null;
+        }
+        return CrossSectionFactory.getCrossSections(river);
+    }
+
 
     /**
      * Returns the Qs for a number of Ws. This method makes use of
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java	Wed Aug 31 12:23:05 2011 +0000
@@ -0,0 +1,51 @@
+package de.intevation.flys.artifacts.model;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.state.DefaultFacet;
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.artifacts.WINFOArtifact;
+
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+
+/**
+ * Trival Facet for Cross Sections.
+ */
+public class CrossSectionFacet
+extends      DefaultFacet
+implements   FacetTypes {
+
+    private static Logger logger = Logger.getLogger(CrossSectionFacet.class);
+
+
+    /** Trivial constructor, set (maybe localized) description. */
+    public CrossSectionFacet(String description) {
+        super(0, CROSS_SECTION, description);
+    }
+
+
+    /**
+     * Gets dummy data.
+     */
+    public Object getData(Artifact artifact, CallContext context) {
+        logger.debug("Get data for cross section");
+
+        WINFOArtifact winfo = (WINFOArtifact)artifact;
+
+        return winfo.getCrossSections();
+    }
+
+    @Override 
+    public Facet deepCopy() {
+        CrossSectionFacet copy = new CrossSectionFacet(this.description);
+        copy.set(this);
+        return copy;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFactory.java	Wed Aug 31 12:23:05 2011 +0000
@@ -0,0 +1,49 @@
+package de.intevation.flys.artifacts.model;
+
+import java.math.BigDecimal;
+
+import java.util.List;
+import java.util.Iterator;
+
+import de.intevation.flys.backend.SessionHolder;
+import de.intevation.flys.model.CrossSection;
+import de.intevation.flys.model.Range;
+import de.intevation.flys.model.River;
+
+import org.hibernate.Session;
+import org.hibernate.Query;
+
+/**
+ * Get Cross Sections.
+ */
+public class CrossSectionFactory {
+
+    /**
+     * Get CrossSections for an instantiated River.
+     *
+     * @param river river object.
+     *
+     * @return List of Cross Sections of river.
+     */
+    public static List<CrossSection> getCrossSections(River river) {
+        return getCrossSections(river.getName());
+    }
+
+
+    /**
+     * Get Cross Sections for a river by name.
+     *
+     * @param river name of the river of interest.
+     *
+     * @return List of Cross Sections of river.
+     */
+    public static List<CrossSection> getCrossSections(String riverName) {
+        Session session = SessionHolder.HOLDER.get();
+        Query query = session.createQuery(
+                "from CrossSection where river.name = :rivername");
+        query.setParameter("rivername", riverName);
+        return query.list();
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
+
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Wed Aug 31 12:20:23 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Wed Aug 31 12:23:05 2011 +0000
@@ -16,6 +16,7 @@
 import de.intevation.flys.artifacts.model.WQKms;
 
 import de.intevation.flys.artifacts.model.DataFacet;
+import de.intevation.flys.artifacts.model.CrossSectionFacet;
 import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.artifactdatabase.state.DefaultFacet;
 
@@ -95,7 +96,8 @@
             facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id));
         }
 
-        facets.add(new DefaultFacet(0, "cross_section", "facet.cross_section"));
+        // Also register the CrossSectionFacet (added to respective out).
+        facets.add(new CrossSectionFacet("facet.cross_section"));
         return res;
     }
 }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Wed Aug 31 12:20:23 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Wed Aug 31 12:23:05 2011 +0000
@@ -8,6 +8,7 @@
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.chart.title.TextTitle;
 import org.jfree.data.Range;
+import org.jfree.data.xy.XYSeries;
 
 import org.w3c.dom.Document;
 
@@ -147,6 +148,9 @@
     }
 
 
+    /**
+     * Let one facet do its job.
+     */
     public void doOut(Artifact artifact, Facet facet, Document attr) {
         String name = facet.getName();
 
@@ -175,17 +179,18 @@
 
 
     /**
-     * Register annotations available for the diagram.
+     * Do cross sections out.
      *
-     * @param o     list of annotations (data of facet).
-     * @param theme yet ignored.
+     * @param theme Theme for the data series.
      */
     protected void doCrossSectionOut(Object o, Document theme) {
-        logger.debug("LongitudinalSectionGenerator.doCrossSectionOut");
+        logger.debug("CrossSectionGenerator.doCrossSectionOut");
 
-        /*Object[] args = new Object[] {getRiverName()};
-        String label = msg(I18N_ANNOTATIONS_LABEL, "", args);
-        pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme));*/
+        XYSeries series = new StyledXYSeries("bogus", theme);
+        // Add increadibly sophisticated values.
+        series.add(4, 4);
+        series.add(5, 14);
+        addFirstAxisSeries(series);
     }
 
 

http://dive4elements.wald.intevation.org