[Dive4elements-commits] [PATCH 2 of 2] Artifacts: Scan the official lines associated with a main value if it applies for the current river

Wald Commits scm-commit at wald.intevation.org
Mon Jun 17 21:51:16 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1371498664 -7200
# Node ID 4c791a458305804a5ecbcd78aa4ab93872f7743c
# Parent  d6ae01d6a7cb5bcfc267524bdc7c0f170bcf5c8a
Artifacts: Scan the official lines associated with a main value if it applies for the current river.

diff -r d6ae01d6a7cb -r 4c791a458305 artifacts/src/main/java/org/dive4elements/river/artifacts/services/MainValuesService.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/MainValuesService.java	Mon Jun 17 21:49:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/MainValuesService.java	Mon Jun 17 21:51:04 2013 +0200
@@ -26,6 +26,7 @@
 import org.dive4elements.river.model.MainValue;
 import org.dive4elements.river.model.MainValueType;
 import org.dive4elements.river.model.NamedMainValue;
+import org.dive4elements.river.model.OfficialLine;
 import org.dive4elements.river.model.Range;
 import org.dive4elements.river.model.River;
 
@@ -205,7 +206,7 @@
         doc.appendChild(rootEl);
 
         appendMetaInformation(doc, rootEl, river, gauge, context);
-        appendMainValues(doc, rootEl, mainValues, context);
+        appendMainValues(doc, rootEl, mainValues, river.getName(), context);
 
         return doc;
     }
@@ -250,10 +251,22 @@
     }
 
 
+    /** Checks i a main value has an official associated, */
+    protected static boolean hasOfficialLine(NamedMainValue nmv, String river) {
+        for (OfficialLine ol: nmv.getOfficialLines()) {
+            if (river.equals(ol.getWstColumn().getWst().getRiver().getName())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
     protected void appendMainValues(
         Document        doc,
         Element         root,
         List<MainValue> mainValues,
+        String          river,
         Object          context)
     {
         logger.debug("MainValuesService.appendMainValues");
@@ -266,7 +279,7 @@
         Element list = cr.create("mainvalues");
 
         for (MainValue mainValue: mainValues) {
-            Element newEl = buildMainValueElement(doc, mainValue, context);
+            Element newEl = buildMainValueElement(doc, mainValue, river, context);
 
             if (newEl != null) {
                 list.appendChild(newEl);
@@ -290,6 +303,7 @@
     protected Element buildMainValueElement(
         Document  doc,
         MainValue mainValue,
+        String    river,
         Object    context)
     {
         ElementCreator cr = new ElementCreator(
@@ -306,6 +320,11 @@
         cr.addAttr(el, "name", namedMainValue.getName());
         cr.addAttr(el, "type", mainValueType.getName());
 
+        if (hasOfficialLine(namedMainValue, river)) {
+            cr.addAttr(el, "official", "true");
+        }
+
+
         return el;
     }
 }


More information about the Dive4elements-commits mailing list