Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java @ 725:dde7f51dbe1e
Improved exception handling while feeding an artifact.
gnv-artifacts/trunk@757 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 10 Mar 2010 13:27:14 +0000 |
parents | 078ba6799bd2 |
children | 18dc6a99f4f4 |
comparison
equal
deleted
inserted
replaced
724:9ba6bb85d6dd | 725:dde7f51dbe1e |
---|---|
27 import de.intevation.gnv.state.describedata.NamedCollection; | 27 import de.intevation.gnv.state.describedata.NamedCollection; |
28 import de.intevation.gnv.state.describedata.SingleValueDescribeData; | 28 import de.intevation.gnv.state.describedata.SingleValueDescribeData; |
29 | 29 |
30 import de.intevation.gnv.state.exception.StateException; | 30 import de.intevation.gnv.state.exception.StateException; |
31 | 31 |
32 import de.intevation.gnv.utils.ArtifactXMLUtilities; | |
32 import de.intevation.gnv.utils.InputValidator; | 33 import de.intevation.gnv.utils.InputValidator; |
33 | 34 |
34 import java.util.ArrayList; | 35 import java.util.ArrayList; |
35 import java.util.Arrays; | 36 import java.util.Arrays; |
36 import java.util.Collection; | 37 import java.util.Collection; |
37 import java.util.Date; | 38 import java.util.Date; |
38 import java.util.GregorianCalendar; | 39 import java.util.GregorianCalendar; |
39 import java.util.HashMap; | 40 import java.util.HashMap; |
40 import java.util.Iterator; | 41 import java.util.Iterator; |
41 import java.util.List; | 42 import java.util.List; |
43 import java.util.Locale; | |
42 import java.util.Map; | 44 import java.util.Map; |
43 | 45 |
44 import javax.xml.xpath.XPathConstants; | 46 import javax.xml.xpath.XPathConstants; |
45 | 47 |
46 import net.sf.ehcache.Cache; | 48 import net.sf.ehcache.Cache; |
76 | 78 |
77 public final static String DESCRIBEDATAKEY = "_DESCRIBEDATA"; | 79 public final static String DESCRIBEDATAKEY = "_DESCRIBEDATA"; |
78 | 80 |
79 public final static String XPATH_STATIC_UI = "art:static"; | 81 public final static String XPATH_STATIC_UI = "art:static"; |
80 public final static String XPATH_DYNAMIC_UI = "art:dynamic"; | 82 public final static String XPATH_DYNAMIC_UI = "art:dynamic"; |
83 | |
84 public static final String EXCEPTION_NO_INPUT = "no.input.data"; | |
85 public static final String EXCEPTION_INVALID_INPUT = | |
86 "input.is.not.valid"; | |
81 | 87 |
82 /** input value names which should not be rendered from State itself */ | 88 /** input value names which should not be rendered from State itself */ |
83 public final static String[] BLACKLIST = {"sourceid", "fisname"}; | 89 public final static String[] BLACKLIST = {"sourceid", "fisname"}; |
84 | 90 |
85 private String id = null; | 91 private String id = null; |
213 public void setParent(State state) { | 219 public void setParent(State state) { |
214 this.parent = state; | 220 this.parent = state; |
215 } | 221 } |
216 | 222 |
217 | 223 |
218 public void feed(Collection<InputData> inputData, String uuid) | 224 public Document feed( |
225 CallContext context, | |
226 Collection<InputData> inputData, | |
227 String uuid) | |
219 throws StateException | 228 throws StateException |
220 { | 229 { |
230 RessourceFactory resFactory = RessourceFactory.getInstance(); | |
231 Locale[] serverLocales = resFactory.getLocales(); | |
232 Locale locale = context.getMeta().getPreferredLocale( | |
233 serverLocales); | |
234 | |
221 if (inputData != null) { | 235 if (inputData != null) { |
222 Iterator<InputData> it = inputData.iterator(); | 236 Iterator<InputData> it = inputData.iterator(); |
223 InputValidator iv = new InputValidator(); | 237 InputValidator iv = new InputValidator(); |
224 while (it.hasNext()) { | 238 while (it.hasNext()) { |
225 InputData tmpItem = it.next(); | 239 InputData tmpItem = it.next(); |
235 if (valid) { | 249 if (valid) { |
236 String[] desc = getDescriptionForInputData(tmpItem, uuid); | 250 String[] desc = getDescriptionForInputData(tmpItem, uuid); |
237 tmpItem.setDescription(desc); | 251 tmpItem.setDescription(desc); |
238 this.inputData.put(tmpItem.getName(), tmpItem); | 252 this.inputData.put(tmpItem.getName(), tmpItem); |
239 } else { | 253 } else { |
240 String errMsg = "Wrong input for " + tmpItem.getValue() | 254 String msg = resFactory.getRessource( |
241 + " is not an " + inputValue.getType() | 255 locale, |
242 + " Value."; | 256 EXCEPTION_INVALID_INPUT, |
243 log.warn(errMsg); | 257 EXCEPTION_INVALID_INPUT); |
244 throw new StateException(errMsg); | 258 log.warn(msg); |
259 return feedFailure(msg); | |
245 } | 260 } |
246 | 261 |
247 } else { | 262 } else { |
248 String errMsg = "No Inputvalue given for Inputdata " | 263 String msg = resFactory.getRessource( |
249 + tmpItem.getName(); | 264 locale, |
250 log.warn(errMsg + "Value will be ignored"); | 265 EXCEPTION_INVALID_INPUT, |
251 | 266 EXCEPTION_INVALID_INPUT); |
252 } | 267 log.warn(msg); |
253 } | 268 return feedFailure(msg); |
269 | |
270 } | |
271 } | |
272 | |
273 return feedSuccess(); | |
254 } else { | 274 } else { |
255 log.warn("No Inputdata given"); | 275 String msg = resFactory.getRessource( |
256 } | 276 locale, |
277 EXCEPTION_NO_INPUT, | |
278 EXCEPTION_NO_INPUT); | |
279 log.warn(msg); | |
280 return feedFailure(msg); | |
281 } | |
282 } | |
283 | |
284 | |
285 protected Document feedSuccess() { | |
286 return ArtifactXMLUtilities.createSuccessReport( | |
287 "Initialize success", XMLUtils.newDocument()); | |
288 } | |
289 | |
290 | |
291 protected Document feedFailure(String msg) { | |
292 return ArtifactXMLUtilities.createInputExceptionReport( | |
293 msg, XMLUtils.newDocument()); | |
257 } | 294 } |
258 | 295 |
259 | 296 |
260 private String[] getDescriptionForInputData(InputData data, String uuid) { | 297 private String[] getDescriptionForInputData(InputData data, String uuid) { |
261 // there is only one element in the list, so take the first | 298 // there is only one element in the list, so take the first |