# HG changeset patch # User Felix Wolfsteller # Date 1386079757 -3600 # Node ID 21adafca6441c83488a0cb6b964ec810d65c7ce7 # Parent 49a92f7e2017d907929c6acabad8a792a53c9983 issue1020: Avoid some traps, use WKms and handle data from StaticArtifact. diff -r 49a92f7e2017 -r 21adafca6441 artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelSelectState.java --- 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) }; }