Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelSelectState.java @ 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 | 003502ea4854 |
children | 84573d5935be |
comparison
equal
deleted
inserted
replaced
7637:49a92f7e2017 | 7638:21adafca6441 |
---|---|
19 import org.dive4elements.artifactdatabase.data.StateData; | 19 import org.dive4elements.artifactdatabase.data.StateData; |
20 | 20 |
21 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; | 21 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; |
22 | 22 |
23 import org.dive4elements.river.artifacts.D4EArtifact; | 23 import org.dive4elements.river.artifacts.D4EArtifact; |
24 import org.dive4elements.river.artifacts.StaticWKmsArtifact; | |
24 import org.dive4elements.river.artifacts.model.CalculationResult; | 25 import org.dive4elements.river.artifacts.model.CalculationResult; |
25 import org.dive4elements.river.artifacts.model.WQKms; | 26 import org.dive4elements.river.artifacts.model.WKms; |
26 import org.dive4elements.river.artifacts.model.extreme.ExtremeResult; | 27 import org.dive4elements.river.artifacts.model.extreme.ExtremeResult; |
27 import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult; | 28 import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult; |
28 import org.dive4elements.river.artifacts.resources.Resources; | 29 import org.dive4elements.river.artifacts.resources.Resources; |
29 import org.dive4elements.river.utils.RiverUtils; | 30 import org.dive4elements.river.utils.RiverUtils; |
30 import org.dive4elements.river.utils.StringUtil; | 31 import org.dive4elements.river.utils.StringUtil; |
132 //WINFO_WSP_STATE_ID, | 133 //WINFO_WSP_STATE_ID, |
133 artifact.getCurrentStateId(), | 134 artifact.getCurrentStateId(), |
134 ComputeType.ADVANCE, | 135 ComputeType.ADVANCE, |
135 false); | 136 false); |
136 | 137 |
137 WQKms[] wqkms; | 138 WKms[] wkms = null; |
138 | 139 |
139 // TODO issue1020: Fetch cases in which only WKms or | 140 // TODO issue1020: Fetch cases in which only WKms or |
140 // other weird stuff arrives. | 141 // other weird stuff arrives. |
141 if (rawData instanceof CalculationResult) { | 142 if (rawData instanceof CalculationResult) { |
142 CalculationResult calcResult = (CalculationResult) rawData; | 143 CalculationResult calcResult = (CalculationResult) rawData; |
143 if (calcResult.getData() instanceof ExtremeResult) { | 144 if (calcResult.getData() instanceof ExtremeResult) { |
144 wqkms = ((ExtremeResult) calcResult.getData()).getWQKms(); | 145 wkms = ((ExtremeResult) calcResult.getData()).getWQKms(); |
145 } | 146 } |
146 else if (calcResult.getData() instanceof FixRealizingResult) { | 147 else if (calcResult.getData() instanceof FixRealizingResult) { |
147 wqkms = ((FixRealizingResult) calcResult.getData()).getWQKms(); | 148 wkms = ((FixRealizingResult) calcResult.getData()).getWQKms(); |
148 } | 149 } |
149 else { | 150 else { |
150 wqkms = (WQKms[]) calcResult.getData(); | 151 wkms = (WKms[]) calcResult.getData(); |
151 } | 152 } |
152 } | 153 } |
153 else if (rawData instanceof WQKms) { | 154 else if (rawData instanceof WKms) { |
154 wqkms = new WQKms[] {(WQKms) rawData}; | 155 wkms = new WKms[] {(WKms) rawData}; |
155 } | 156 } |
156 else if (rawData instanceof WQKms[]) { | 157 else if (rawData instanceof WKms[]) { |
157 wqkms = (WQKms[]) rawData; | 158 wkms = (WKms[]) rawData; |
159 } | |
160 else if (artifact instanceof StaticWKmsArtifact) { | |
161 wkms = new WKms[] {((StaticWKmsArtifact) artifact).getWKms(0)}; | |
158 } | 162 } |
159 else { | 163 else { |
160 logger.error("Do not know how to handle " + rawData.getClass()); | 164 if (rawData == null) { |
161 wqkms = null; | 165 logger.error("Null data arrived at WaterlevelSelectState."); |
166 } | |
167 else { | |
168 logger.error("Do not know how to handle " + rawData.getClass()); | |
169 } | |
170 | |
171 wkms = null; | |
162 } | 172 } |
163 | 173 |
164 int idx = -1; | 174 int idx = -1; |
165 try { | 175 try { |
166 idx = Integer.parseInt(parts[2]); | 176 idx = Integer.parseInt(parts[2]); |
167 String name = wqkms[idx].getName(); | 177 if (wkms[idx] == null) { |
178 logger.warn("null label for " + value + " (" + parts[2] + ")"); | |
179 return new String[] {""}; | |
180 } | |
181 String name = wkms[idx].getName(); | |
168 | 182 |
169 return new String[] { StringUtil.wWrap(name) }; | 183 return new String[] { StringUtil.wWrap(name) }; |
170 } | 184 } |
171 catch (NumberFormatException nfe) { /* do nothing */ | 185 catch (NumberFormatException nfe) { /* do nothing */ |
172 logger.error("Cannot get label for " + value + " (" + parts[2] + ")"); | 186 logger.error("Cannot get label for " + value + " (" + parts[2] + ")"); |