changeset 3739:0edc05642fa4

Add new artifact service for the gauge overview flys-artifacts/trunk@5416 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Mon, 10 Sep 2012 08:23:08 +0000 (2012-09-10)
parents 34da25796c21
children c3d3b2760a75
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/GaugeOverviewInfoService.java
diffstat 3 files changed, 142 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Sun Sep 09 21:05:53 2012 +0000
+++ b/flys-artifacts/ChangeLog	Mon Sep 10 08:23:08 2012 +0000
@@ -1,3 +1,9 @@
+2012-09-10	Bj�rn Ricks	<bjoern.ricks@intevation.de>
+
+	* doc/conf/conf.xml,
+	  src/main/java/de/intevation/flys/artifacts/services/GaugeOverviewInfoService.java:
+	  Add new artifact service for the gauge overview
+
 2012-09-09	Christian Lins 	<christian.lins@intevation.de>
 
 	* doc/conf/second-themes.xml,
--- a/flys-artifacts/doc/conf/conf.xml	Sun Sep 09 21:05:53 2012 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Mon Sep 10 08:23:08 2012 +0000
@@ -186,6 +186,10 @@
                 name="modules"
                 service="de.intevation.flys.artifacts.services.ModuleService"
                 description="Returns a list of available modules.">de.intevation.artifactdatabase.DefaultServiceFactory</service-factory>
+            <service-factory
+                name="gaugeoverviewinfo"
+                service="de.intevation.flys.artifacts.services.GaugeOverviewInfoService"
+                description="Returns an overview of the fixings of a given river.">de.intevation.artifactdatabase.DefaultServiceFactory</service-factory>
         </service-factories>
 
     </factories>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/GaugeOverviewInfoService.java	Mon Sep 10 08:23:08 2012 +0000
@@ -0,0 +1,132 @@
+package de.intevation.flys.artifacts.services;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import de.intevation.artifacts.CallMeta;
+import de.intevation.artifacts.GlobalContext;
+import de.intevation.artifacts.common.ArtifactNamespaceContext;
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.flys.artifacts.model.RiverFactory;
+import de.intevation.flys.model.Gauge;
+import de.intevation.flys.model.MinMaxWQ;
+import de.intevation.flys.model.Range;
+import de.intevation.flys.model.River;
+
+/**
+ * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
+ */
+public class GaugeOverviewInfoService extends FLYSService {
+
+    private static final Logger logger = Logger.getLogger(
+            GaugeOverviewInfoService.class);
+
+    public static final String RIVER_XPATH = "/art:river/text()";
+
+    @Override
+    public Document doProcess(
+        Document      data,
+        GlobalContext globalContext,
+        CallMeta      callMeta
+    ) {
+        logger.debug("GaugeOverviewInfoService.process");
+
+        String riverstr = XMLUtils.xpathString(
+            data, RIVER_XPATH, ArtifactNamespaceContext.INSTANCE);
+
+        River river = RiverFactory.getRiver(riverstr);
+
+        Document result = XMLUtils.newDocument();
+
+        if (river == null) {
+            logger.warn("No river with name " + riverstr + " found.");
+            return result;
+        }
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            result,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element go = ec.create("gauge-info");
+
+        double[] minmax = river.determineMinMaxDistance();
+
+        Element r = ec.create("river");
+        ec.addAttr(r, "name", river.getName(), true);
+        ec.addAttr(r, "start", Double.toString(minmax[0]), true);
+        ec.addAttr(r, "end", Double.toString(minmax[1]), true);
+        ec.addAttr(r, "wstunit", river.getWstUnit().getName(), true);
+        ec.addAttr(r, "kmup", Boolean.toString(river.getKmUp()), true);
+        //TODO
+        /* ec.addAttr(r, "qmin", , true); */
+        /* ec.addAttr(r, "qmax", , true); */
+
+        Element egs = ec.create("gauges");
+
+        List<Gauge> gauges = river.getGauges();
+        logger.debug("Loaded gauges: " + gauges);
+        for (Gauge gauge: river.getGauges()) {
+            Element eg = ec.create("gauge");
+            String name = gauge.getName();
+            if (name != null) {
+                ec.addAttr(eg, "name", gauge.getName(), true);
+            }
+
+            Range range = gauge.getRange();
+            if (range != null) {
+                double min = range.getA().doubleValue();
+                ec.addAttr(eg, "start", Double.toString(min), true);
+
+                BigDecimal b = range.getB();
+                if (b != null) {
+                    double max = range.getB().doubleValue();
+                    ec.addAttr(eg, "end", Double.toString(max), true);
+                }
+            }
+            MinMaxWQ minmaxwq = gauge.fetchMaxMinWQ();
+            String minw = getGaugeValue(minmaxwq.getMinW());
+            String maxw = getGaugeValue(minmaxwq.getMaxW());
+            String minq = getGaugeValue(minmaxwq.getMinQ());
+            String maxq = getGaugeValue(minmaxwq.getMaxQ());
+
+            if (minw != null) {
+                ec.addAttr(eg, "minw", minw, true);
+            }
+            if (maxw != null) {
+                ec.addAttr(eg, "maxw", maxw, true);
+            }
+            if (minq != null) {
+                ec.addAttr(eg, "minq", minq, true);
+            }
+            if (maxq != null) {
+                ec.addAttr(eg, "maxq", maxq, true);
+            }
+
+            ec.addAttr(eg, "aeo", Double.toString(gauge.getAeo().doubleValue()), true);
+            ec.addAttr(eg, "datum", Double.toString(gauge.getDatum().doubleValue()), true);
+
+            egs.appendChild(eg);
+        }
+
+        go.appendChild(r);
+        go.appendChild(egs);
+        result.appendChild(go);
+
+        return result;
+    }
+
+    private String getGaugeValue(BigDecimal value) {
+        if (value == null) {
+            return null;
+        }
+        return Double.toString(value.doubleValue());
+    }
+
+}

http://dive4elements.wald.intevation.org