[PATCH 3 of 6] (issue1353) Add river name handling

Wald Commits scm-commit at wald.intevation.org
Thu Aug 15 16:51:15 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1376575517 -7200
# Node ID fe03337c8011c2899d1bdd528c34e74e6e7be475
# Parent  a895eb07a7dc8c8b47a7386b1c28388d22862650
(issue1353) Add river name handling

diff -r a895eb07a7dc -r fe03337c8011 artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation6.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation6.java	Thu Aug 15 15:57:54 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation6.java	Thu Aug 15 16:05:17 2013 +0200
@@ -37,6 +37,7 @@
     private long []   timerange;
     private double [] values;
     private Long      officialGaugeNumber;
+    private String    riverName;
 
 
     public Calculation6(HistoricalDischargeAccess access) {
@@ -45,6 +46,7 @@
         double [] vs = mode != null && mode == EvaluationMode.W
             ? access.getWs()
             : access.getQs();
+        riverName = access.getRiver();
 
         Long officialGaugeNumber = access.getOfficialGaugeNumber();
 
@@ -98,7 +100,8 @@
             return null;
         }
 
-        Gauge gauge = Gauge.getGaugeByOfficialNumber(officialGaugeNumber);
+        Gauge gauge = Gauge.getGaugeByOfficialNumber(officialGaugeNumber,
+                riverName);
         if (gauge == null) {
             // TODO: i18n
             return error("hist.discharge.gauge.not.found");
diff -r a895eb07a7dc -r fe03337c8011 artifacts/src/main/java/org/dive4elements/river/artifacts/services/DischargeInfoService.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DischargeInfoService.java	Thu Aug 15 15:57:54 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DischargeInfoService.java	Thu Aug 15 16:05:17 2013 +0200
@@ -40,6 +40,8 @@
 
     public static final String GAUGE_XPATH = "/art:gauge/text()";
 
+    public static final String RIVER_NAME_XPATH = "/art:gauge/art:river/text()";
+
     public DischargeInfoService() {
     }
 
@@ -58,30 +60,39 @@
         String gaugeNumber = XMLUtils.xpathString(
             data, GAUGE_XPATH, ArtifactNamespaceContext.INSTANCE);
 
+        String river = XMLUtils.xpathString(
+            data, RIVER_NAME_XPATH, ArtifactNamespaceContext.INSTANCE);
+
         if (gaugeNumber == null ||
            (gaugeNumber = gaugeNumber.trim()).length() == 0) {
             logger.warn("No gauge specified. Cannot return discharge info.");
             return XMLUtils.newDocument();
         }
 
-        logger.debug("Getting discharge for gauge: " + gaugeNumber);
+        logger.debug("Getting discharge for gauge: " + gaugeNumber + " at river: " + river);
 
         long gn;
         try {
             gn = Long.parseLong(gaugeNumber);
         }
         catch (NumberFormatException nfe) {
-            logger.warn("Invalid gauge number. Cannot return discharg info.");
+            logger.warn("Invalid gauge number. Cannot return discharge info.");
             return XMLUtils.newDocument();
         }
 
-        Gauge gauge = Gauge.getGaugeByOfficialNumber(gn);
+        Gauge gauge;
+        if (river == null || river.isEmpty()) {
+            gauge = Gauge.getGaugeByOfficialNumber(gn);
+        } else {
+            gauge = Gauge.getGaugeByOfficialNumber(gn, river);
+        }
+
         if (gauge == null) {
             logger.warn("No such gauge found.");
             return XMLUtils.newDocument();
         }
 
-        logger.debug("Found gauge: " + gauge.getName());
+        logger.debug("Found gauge: " + gauge.getName() + " id: " + gauge.getId());
 
         return buildDocument(gauge);
     }


More information about the Dive4elements-commits mailing list