changeset 6356:4c791a458305

Artifacts: Scan the official lines associated with a main value if it applies for the current river.
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 17 Jun 2013 21:51:04 +0200
parents d6ae01d6a7cb
children 673e146e7793 a8b065038c0c
files artifacts/src/main/java/org/dive4elements/river/artifacts/services/MainValuesService.java
diffstat 1 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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;
     }
 }

http://dive4elements.wald.intevation.org