changeset 7638:21adafca6441

issue1020: Avoid some traps, use WKms and handle data from StaticArtifact.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 03 Dec 2013 15:09:17 +0100
parents 49a92f7e2017
children 11bc2d6a2059
files artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelSelectState.java
diffstat 1 files changed, 26 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelSelectState.java	Tue Dec 03 12:25:57 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelSelectState.java	Tue Dec 03 15:09:17 2013 +0100
@@ -21,8 +21,9 @@
 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
 
 import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.StaticWKmsArtifact;
 import org.dive4elements.river.artifacts.model.CalculationResult;
-import org.dive4elements.river.artifacts.model.WQKms;
+import org.dive4elements.river.artifacts.model.WKms;
 import org.dive4elements.river.artifacts.model.extreme.ExtremeResult;
 import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult;
 import org.dive4elements.river.artifacts.resources.Resources;
@@ -134,37 +135,50 @@
             ComputeType.ADVANCE,
             false);
 
-        WQKms[] wqkms;
+        WKms[] wkms = null;
 
         // TODO issue1020: Fetch cases in which only WKms or
         // other weird stuff arrives.
         if (rawData instanceof CalculationResult) {
             CalculationResult calcResult = (CalculationResult) rawData;
             if (calcResult.getData() instanceof ExtremeResult) {
-                wqkms = ((ExtremeResult) calcResult.getData()).getWQKms();
+                wkms = ((ExtremeResult) calcResult.getData()).getWQKms();
             }
             else if (calcResult.getData() instanceof FixRealizingResult) {
-                wqkms = ((FixRealizingResult) calcResult.getData()).getWQKms();
+                wkms = ((FixRealizingResult) calcResult.getData()).getWQKms();
             }
             else {
-                wqkms = (WQKms[]) calcResult.getData();
+                wkms = (WKms[]) calcResult.getData();
             }
         }
-        else if (rawData instanceof WQKms) {
-            wqkms = new WQKms[] {(WQKms) rawData};
+        else if (rawData instanceof WKms) {
+            wkms = new WKms[] {(WKms) rawData};
         }
-        else if (rawData instanceof WQKms[]) {
-            wqkms = (WQKms[]) rawData;
+        else if (rawData instanceof WKms[]) {
+            wkms = (WKms[]) rawData;
+        }
+        else if (artifact instanceof StaticWKmsArtifact) {
+            wkms = new WKms[] {((StaticWKmsArtifact) artifact).getWKms(0)};
         }
         else {
-            logger.error("Do not know how to handle " + rawData.getClass());
-            wqkms = null;
+            if (rawData == null) {
+                logger.error("Null data arrived at WaterlevelSelectState.");
+            }
+            else {
+                logger.error("Do not know how to handle " + rawData.getClass());
+            }
+
+            wkms = null;
         }
 
         int idx = -1;
         try {
             idx = Integer.parseInt(parts[2]);
-            String name = wqkms[idx].getName();
+            if (wkms[idx] == null) {
+                logger.warn("null label for " + value + " (" + parts[2] + ")");
+                return new String[] {""};
+            }
+            String name = wkms[idx].getName();
 
             return new String[] { StringUtil.wWrap(name) };
         }

http://dive4elements.wald.intevation.org