Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java @ 171:7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
gnv-artifacts/trunk@208 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 09 Oct 2009 07:54:48 +0000 |
parents | 5ebc059064a6 |
children | 1b2fc94766c9 |
comparison
equal
deleted
inserted
replaced
170:7be22e76c270 | 171:7fb9441dd8af |
---|---|
39 import de.intevation.gnv.utils.ArtifactXMLUtilities; | 39 import de.intevation.gnv.utils.ArtifactXMLUtilities; |
40 import de.intevation.gnv.utils.InputValidator; | 40 import de.intevation.gnv.utils.InputValidator; |
41 | 41 |
42 /** | 42 /** |
43 * @author Tim Englich <tim.englich@intevation.de> | 43 * @author Tim Englich <tim.englich@intevation.de> |
44 * | 44 * |
45 */ | 45 */ |
46 public abstract class TransitionBase implements Transition { | 46 public abstract class TransitionBase implements Transition { |
47 | 47 |
48 /** | 48 /** |
49 * The UID of this Class | 49 * The UID of this Class |
50 */ | 50 */ |
51 private static final long serialVersionUID = 2411169179001645426L; | 51 private static final long serialVersionUID = 2411169179001645426L; |
52 | 52 |
53 /** | 53 /** |
54 * the logger, used to log exceptions and additonaly information | 54 * the logger, used to log exceptions and additonaly information |
55 */ | 55 */ |
56 private static Logger log = Logger.getLogger(GNVArtifactBase.class); | 56 private static Logger log = Logger.getLogger(GNVArtifactBase.class); |
57 | 57 |
58 private String id = null; | 58 private String id = null; |
59 | 59 |
60 private String description = null; | 60 private String description = null; |
61 | 61 |
62 protected String dataName = null; | 62 protected String dataName = null; |
63 | 63 |
64 protected boolean dataMultiSelect = false; | 64 protected boolean dataMultiSelect = false; |
65 | 65 |
66 protected String queryID = null; | 66 protected String queryID = null; |
67 | 67 |
68 private Collection<String> reachableTransitions = null; | 68 private Collection<String> reachableTransitions = null; |
69 | 69 |
70 protected Collection<String> inputValueNames = null; | 70 protected Collection<String> inputValueNames = null; |
71 | 71 |
72 private Map<String,InputValue> inputValues = null; | 72 private Map<String, InputValue> inputValues = null; |
73 | 73 |
74 private Transition parent = null; | 74 private Transition parent = null; |
75 | 75 |
76 protected Map<String,InputData> inputData = null; | 76 protected Map<String, InputData> inputData = null; |
77 | 77 |
78 protected Collection<Object> descibeData = null; | 78 protected Collection<Object> descibeData = null; |
79 | 79 |
80 /** | 80 /** |
81 * Constructor | 81 * Constructor |
82 */ | 82 */ |
83 public TransitionBase() { | 83 public TransitionBase() { |
84 super(); | 84 super(); |
88 * @see de.intevation.gnv.transition.Transition#getID() | 88 * @see de.intevation.gnv.transition.Transition#getID() |
89 */ | 89 */ |
90 public String getID() { | 90 public String getID() { |
91 return this.id; | 91 return this.id; |
92 } | 92 } |
93 | 93 |
94 /** | 94 /** |
95 * @see de.intevation.gnv.transition.Transition#getDescription() | 95 * @see de.intevation.gnv.transition.Transition#getDescription() |
96 */ | 96 */ |
97 public String getDescription() { | 97 public String getDescription() { |
98 return this.description; | 98 return this.description; |
99 } | 99 } |
100 | 100 |
101 /** | 101 /** |
102 * @see de.intevation.gnv.transition.Transition#reachableTransitions() | 102 * @see de.intevation.gnv.transition.Transition#reachableTransitions() |
103 */ | 103 */ |
104 public Collection<String> reachableTransitions() { | 104 public Collection<String> reachableTransitions() { |
105 return this.reachableTransitions; | 105 return this.reachableTransitions; |
115 /** | 115 /** |
116 * @see de.intevation.gnv.transition.Transition#setup(org.w3c.dom.Node) | 116 * @see de.intevation.gnv.transition.Transition#setup(org.w3c.dom.Node) |
117 */ | 117 */ |
118 public void setup(Node configuration) { | 118 public void setup(Node configuration) { |
119 log.debug("TransitionBase.setup"); | 119 log.debug("TransitionBase.setup"); |
120 this.id = Config.getStringXPath(configuration,"@id"); | 120 this.id = Config.getStringXPath(configuration, "@id"); |
121 this.description = Config.getStringXPath(configuration,"@description"); | 121 this.description = Config.getStringXPath(configuration, "@description"); |
122 | 122 |
123 log.info("Transition-ID = "+ this.id); | 123 log.info("Transition-ID = " + this.id); |
124 NodeList nodes = Config.getNodeSetXPath(configuration,"reachableTransitions/transition"); | 124 NodeList nodes = Config.getNodeSetXPath(configuration, |
125 "reachableTransitions/transition"); | |
125 this.reachableTransitions = new ArrayList<String>(nodes.getLength()); | 126 this.reachableTransitions = new ArrayList<String>(nodes.getLength()); |
126 for (int i = 0 ; i < nodes.getLength(); i++){ | 127 for (int i = 0; i < nodes.getLength(); i++) { |
127 String reachableTransition = nodes.item(i).getTextContent(); | 128 String reachableTransition = nodes.item(i).getTextContent(); |
128 log.info("ReachableTransition ==> "+ reachableTransition); | 129 log.info("ReachableTransition ==> " + reachableTransition); |
129 this.reachableTransitions.add(reachableTransition); | 130 this.reachableTransitions.add(reachableTransition); |
130 | 131 |
131 } | 132 } |
132 | 133 |
133 NodeList inputValuesNodes = Config.getNodeSetXPath(configuration,"inputvalues/inputvalue"); | 134 NodeList inputValuesNodes = Config.getNodeSetXPath(configuration, |
134 this.inputValues = new HashMap<String,InputValue>(inputValuesNodes.getLength()); | 135 "inputvalues/inputvalue"); |
135 this.inputValueNames = new ArrayList<String>(inputValuesNodes.getLength()); | 136 this.inputValues = new HashMap<String, InputValue>(inputValuesNodes |
136 for (int i = 0 ; i < inputValuesNodes.getLength(); i++){ | 137 .getLength()); |
138 this.inputValueNames = new ArrayList<String>(inputValuesNodes | |
139 .getLength()); | |
140 for (int i = 0; i < inputValuesNodes.getLength(); i++) { | |
137 Node inputValueNode = inputValuesNodes.item(i); | 141 Node inputValueNode = inputValuesNodes.item(i); |
138 String usedinQueryValue = Config.getStringXPath(inputValueNode,"@usedinquery"); | 142 String usedinQueryValue = Config.getStringXPath(inputValueNode, |
143 "@usedinquery"); | |
139 int usedinQuery = 1; | 144 int usedinQuery = 1; |
140 if (usedinQueryValue != null){ | 145 if (usedinQueryValue != null) { |
141 try { | 146 try { |
142 usedinQuery = Integer.parseInt(usedinQueryValue); | 147 usedinQuery = Integer.parseInt(usedinQueryValue); |
143 } catch (NumberFormatException e) { | 148 } catch (NumberFormatException e) { |
144 log.warn("Used in Query Value cannot be transformed into a Number"); | 149 log |
145 } | 150 .warn("Used in Query Value cannot be transformed into a Number"); |
146 } | 151 } |
147 InputValue inputValue = new DefaultInputValue( | 152 } |
148 Config.getStringXPath(inputValueNode,"@name"), | 153 InputValue inputValue = new DefaultInputValue(Config |
149 Config.getStringXPath(inputValueNode,"@type"), | 154 .getStringXPath(inputValueNode, "@name"), Config |
150 Boolean.parseBoolean(Config.getStringXPath(inputValueNode,"@multiselect")), | 155 .getStringXPath(inputValueNode, "@type"), Boolean |
151 usedinQuery); | 156 .parseBoolean(Config.getStringXPath(inputValueNode, |
157 "@multiselect")), usedinQuery); | |
152 log.debug(inputValue.toString()); | 158 log.debug(inputValue.toString()); |
153 this.inputValues.put(inputValue.getName(),inputValue); | 159 this.inputValues.put(inputValue.getName(), inputValue); |
154 this.inputValueNames.add(inputValue.getName()); | 160 this.inputValueNames.add(inputValue.getName()); |
155 } | 161 } |
156 | 162 |
157 this.queryID = Config.getStringXPath(configuration,"queryID"); | 163 this.queryID = Config.getStringXPath(configuration, "queryID"); |
158 log.info("QueryID ==> "+ this.queryID); | 164 log.info("QueryID ==> " + this.queryID); |
159 | 165 |
160 this.dataName = Config.getStringXPath(configuration,"dataname"); | 166 this.dataName = Config.getStringXPath(configuration, "dataname"); |
161 | 167 |
162 String dataMultiSelectValue = Config.getStringXPath(configuration,"data-multiselect"); | 168 String dataMultiSelectValue = Config.getStringXPath(configuration, |
163 if (dataMultiSelectValue != null){ | 169 "data-multiselect"); |
164 this.dataMultiSelect = Boolean.parseBoolean(dataMultiSelectValue); | 170 if (dataMultiSelectValue != null) { |
165 } | 171 this.dataMultiSelect = Boolean.parseBoolean(dataMultiSelectValue); |
166 | 172 } |
173 | |
167 } | 174 } |
168 | 175 |
169 /** | 176 /** |
170 * @see de.intevation.gnv.transition.Transition#getParent() | 177 * @see de.intevation.gnv.transition.Transition#getParent() |
171 */ | 178 */ |
181 } | 188 } |
182 | 189 |
183 /** | 190 /** |
184 * @see de.intevation.gnv.transition.Transition#putInputData(java.util.Collection) | 191 * @see de.intevation.gnv.transition.Transition#putInputData(java.util.Collection) |
185 */ | 192 */ |
186 public void putInputData(Collection<InputData> inputData, String uuid) throws TransitionException { | 193 public void putInputData(Collection<InputData> inputData, String uuid) |
194 throws TransitionException { | |
187 log.debug("TransitionBase.putInputData"); | 195 log.debug("TransitionBase.putInputData"); |
188 if (inputData != null){ | 196 if (inputData != null) { |
189 Iterator<InputData> it = inputData.iterator(); | 197 Iterator<InputData> it = inputData.iterator(); |
190 InputValidator iv = new InputValidator(); | 198 InputValidator iv = new InputValidator(); |
191 while(it.hasNext()){ | 199 while (it.hasNext()) { |
192 InputData tmpItem = it.next(); | 200 InputData tmpItem = it.next(); |
193 InputValue inputValue = this.inputValues.get(tmpItem.getName()); | 201 InputValue inputValue = this.inputValues.get(tmpItem.getName()); |
194 if (inputValue != null){ | 202 if (inputValue != null) { |
195 if (this.inputData == null){ | 203 if (this.inputData == null) { |
196 this.inputData = new HashMap<String,InputData>(inputData.size()); | 204 this.inputData = new HashMap<String, InputData>( |
197 } | 205 inputData.size()); |
198 boolean valid = iv.isInputValid(tmpItem.getValue(), inputValue.getType()); | 206 } |
199 if (valid){ | 207 boolean valid = iv.isInputValid(tmpItem.getValue(), |
208 inputValue.getType()); | |
209 if (valid) { | |
200 this.setSelection(tmpItem); | 210 this.setSelection(tmpItem); |
201 this.inputData.put(tmpItem.getName(),tmpItem); | 211 this.inputData.put(tmpItem.getName(), tmpItem); |
202 }else{ | 212 } else { |
203 String errMsg = "Wrong input for "+tmpItem.getValue()+"is not an "+inputValue.getType()+" Value."; | 213 String errMsg = "Wrong input for " + tmpItem.getValue() |
214 + "is not an " + inputValue.getType() | |
215 + " Value."; | |
204 log.warn(errMsg); | 216 log.warn(errMsg); |
205 throw new TransitionException(errMsg); | 217 throw new TransitionException(errMsg); |
206 } | 218 } |
207 | 219 |
208 }else{ | 220 } else { |
209 String errMsg = "No Inputvalue given for Inputdata "+ tmpItem.getName(); | 221 String errMsg = "No Inputvalue given for Inputdata " |
210 log.warn(errMsg+ "Value will be ignored"); | 222 + tmpItem.getName(); |
211 | 223 log.warn(errMsg + "Value will be ignored"); |
212 } | 224 |
213 } | 225 } |
214 }else{ | 226 } |
227 } else { | |
215 log.warn("No Inputdata given"); | 228 log.warn("No Inputdata given"); |
216 } | 229 } |
217 } | 230 } |
218 | 231 |
219 private void setSelection(InputData inputData){ | 232 private void setSelection(InputData inputData) { |
220 log.debug("TransitionBase.setSelection"); | 233 log.debug("TransitionBase.setSelection"); |
221 | 234 |
222 Object o = this.getDescribeData(inputData.getName()); | 235 Object o = this.getDescribeData(inputData.getName()); |
223 if(o != null){ | 236 if (o != null) { |
224 if (o instanceof Collection<?>){ | 237 if (o instanceof Collection<?>) { |
225 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>)o; | 238 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o; |
226 | 239 |
227 String value = inputData.getValue(); | 240 String value = inputData.getValue(); |
228 String[] selectedValues = value.split(","); | 241 String[] selectedValues = value.split(","); |
229 Set<String> selectedItems = new HashSet<String>(selectedValues.length); | 242 Set<String> selectedItems = new HashSet<String>( |
230 for (int i = 0; i < selectedValues.length; i++){ | 243 selectedValues.length); |
244 for (int i = 0; i < selectedValues.length; i++) { | |
231 selectedItems.add(selectedValues[i].trim()); | 245 selectedItems.add(selectedValues[i].trim()); |
232 } | 246 } |
233 // Selektion umsetzen | 247 // Selektion umsetzen |
234 Iterator<KeyValueDescibeData> it = values.iterator(); | 248 Iterator<KeyValueDescibeData> it = values.iterator(); |
235 while (it.hasNext()){ | 249 while (it.hasNext()) { |
236 KeyValueDescibeData data = it.next(); | 250 KeyValueDescibeData data = it.next(); |
237 String key = ""+data.getKey(); | 251 String key = "" + data.getKey(); |
238 boolean selected = selectedItems.contains(key); | 252 boolean selected = selectedItems.contains(key); |
239 data.setSelected(selected); | 253 data.setSelected(selected); |
240 } | 254 } |
241 }else if (o instanceof MinMaxDescribeData){ | 255 } else if (o instanceof MinMaxDescribeData) { |
242 MinMaxDescribeData data = (MinMaxDescribeData)o; | 256 MinMaxDescribeData data = (MinMaxDescribeData) o; |
243 if (inputData.getName().equals(data.getMinName())){ | 257 if (inputData.getName().equals(data.getMinName())) { |
244 // TODO: müssen die werte geparst werden? | 258 // TODO: müssen die werte geparst werden? |
245 data.setMinValue(inputData.getValue()); | 259 data.setMinValue(inputData.getValue()); |
246 } | 260 } |
247 if (inputData.getName().equals(data.getMaxName())){ | 261 if (inputData.getName().equals(data.getMaxName())) { |
248 // TODO: müssen die werte geparst werden? | 262 // TODO: müssen die werte geparst werden? |
249 data.setMaxValue(inputData.getValue()); | 263 data.setMaxValue(inputData.getValue()); |
250 } | 264 } |
251 } | 265 } |
252 } | 266 } |
253 } | 267 } |
254 | 268 |
255 private Object getDescribeData(String name){ | 269 private Object getDescribeData(String name) { |
256 log.debug("TransitionBase.getDescribeData"); | 270 log.debug("TransitionBase.getDescribeData"); |
257 if (this.descibeData != null){ | 271 if (this.descibeData != null) { |
258 Iterator<Object> it = this.descibeData.iterator(); | 272 Iterator<Object> it = this.descibeData.iterator(); |
259 while (it.hasNext()){ | 273 while (it.hasNext()) { |
260 Object o = it.next(); | 274 Object o = it.next(); |
261 if (o instanceof NamedCollection<?>){ | 275 if (o instanceof NamedCollection<?>) { |
262 if (name.equals(((NamedCollection<?>)o).getName())){ | 276 if (name.equals(((NamedCollection<?>) o).getName())) { |
263 return o; | 277 return o; |
264 } | 278 } |
265 }else if (o instanceof MinMaxDescribeData){ | 279 } else if (o instanceof MinMaxDescribeData) { |
266 if (name.equals(((MinMaxDescribeData)o).getMinName())){ | 280 if (name.equals(((MinMaxDescribeData) o).getMinName())) { |
267 return o; | 281 return o; |
268 } | 282 } |
269 if (name.equals(((MinMaxDescribeData)o).getMaxName())){ | 283 if (name.equals(((MinMaxDescribeData) o).getMaxName())) { |
270 return o; | 284 return o; |
271 } | 285 } |
272 } | 286 } |
273 } | 287 } |
274 } | 288 } |
275 return null; | 289 return null; |
276 | 290 |
277 } | 291 } |
278 | 292 |
279 /** | 293 /** |
280 * @see de.intevation.gnv.transition.Transition#isTransitionReachable(java.lang.String) | 294 * @see de.intevation.gnv.transition.Transition#isTransitionReachable(java.lang.String) |
281 */ | 295 */ |
282 public boolean isTransitionReachable(String transitionID) { | 296 public boolean isTransitionReachable(String transitionID) { |
283 log.debug("TransitionBase.isTransitionReachable"); | 297 log.debug("TransitionBase.isTransitionReachable"); |
284 boolean returnValue = false; | 298 boolean returnValue = false; |
285 Iterator<String> transitions = reachableTransitions.iterator(); | 299 Iterator<String> transitions = reachableTransitions.iterator(); |
286 while (transitions.hasNext()){ | 300 while (transitions.hasNext()) { |
287 if(transitions.next().equals(transitionID)){ | 301 if (transitions.next().equals(transitionID)) { |
288 log.debug("Transition "+transitionID+" wird unterstützt."); | 302 log.debug("Transition " + transitionID + " wird unterstützt."); |
289 returnValue = true; | 303 returnValue = true; |
290 break; | 304 break; |
291 } | 305 } |
292 } | 306 } |
293 return returnValue; | 307 return returnValue; |
294 } | 308 } |
295 | 309 |
296 /** | 310 /** |
297 * @see de.intevation.gnv.transition.Transition#advance(java.lang.String, de.intevation.artifacts.CallMeta) | 311 * @see de.intevation.gnv.transition.Transition#advance(java.lang.String, |
298 */ | 312 * de.intevation.artifacts.CallMeta) |
299 public void advance(String uuid, CallMeta callMeta) throws TransitionException { | 313 */ |
314 public void advance(String uuid, CallMeta callMeta) | |
315 throws TransitionException { | |
300 log.debug("TransitionBase.advance"); | 316 log.debug("TransitionBase.advance"); |
301 try { | 317 try { |
302 List<String> list = new ArrayList<String>(); | 318 List<String> list = new ArrayList<String>(); |
303 | 319 |
304 | |
305 Iterator<String> it = this.inputValueNames.iterator(); | 320 Iterator<String> it = this.inputValueNames.iterator(); |
306 int i = 0; | 321 int i = 0; |
307 while (it.hasNext()){ | 322 while (it.hasNext()) { |
308 String value = it.next(); | 323 String value = it.next(); |
309 InputData data = this.inputData.get(value); | 324 InputData data = this.inputData.get(value); |
310 if (data != null && this.inputValues.containsKey(data.getName())){ | 325 if (data != null |
311 int size = this.inputValues.get(data.getName()).usedInQueries(); | 326 && this.inputValues.containsKey(data.getName())) { |
312 String type = this.inputValues.get(data.getName()).getType(); | 327 int size = this.inputValues.get(data.getName()) |
328 .usedInQueries(); | |
329 String type = this.inputValues.get(data.getName()) | |
330 .getType(); | |
313 String requestValue = data.getValue(); | 331 String requestValue = data.getValue(); |
314 if (type.equalsIgnoreCase("string")){ | 332 if (type.equalsIgnoreCase("string")) { |
315 requestValue = this.prepareInputData4DBQuery(requestValue); | 333 requestValue = this |
316 }else if (type.equalsIgnoreCase("date")){ | 334 .prepareInputData4DBQuery(requestValue); |
317 requestValue = this.prepareInputData4DateDBQuery(requestValue); | 335 } else if (type.equalsIgnoreCase("date")) { |
318 } | 336 requestValue = this |
319 for (int j = 0; j < size; j++){ | 337 .prepareInputData4DateDBQuery(requestValue); |
338 } | |
339 for (int j = 0; j < size; j++) { | |
320 list.add(requestValue); | 340 list.add(requestValue); |
321 } | 341 } |
322 } | 342 } |
323 } | 343 } |
324 String[] filterValues = list.toArray(new String[0]); | 344 String[] filterValues = list.toArray(new String[0]); |
325 Collection<Result> result = null; | 345 Collection<Result> result = null; |
326 try { | 346 try { |
327 if (this.queryID != null){ | 347 if (this.queryID != null) { |
328 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); | 348 QueryExecutor queryExecutor = QueryExecutorFactory |
329 result = queryExecutor.executeQuery(this.queryID, filterValues); | 349 .getInstance().getQueryExecutor(); |
350 result = queryExecutor.executeQuery(this.queryID, | |
351 filterValues); | |
330 } | 352 } |
331 this.purifyResult(result, uuid); | 353 this.purifyResult(result, uuid); |
332 } catch (RuntimeException e) { | 354 } catch (RuntimeException e) { |
333 log.error(e,e); | 355 log.error(e, e); |
334 } | 356 } |
335 } catch (QueryException e) { | 357 } catch (QueryException e) { |
336 log.error(e,e); | 358 log.error(e, e); |
337 throw new TransitionException(e); | 359 throw new TransitionException(e); |
338 } | 360 } |
339 } | 361 } |
340 | 362 |
341 private String prepareInputData4DateDBQuery(String value){ | 363 private String prepareInputData4DateDBQuery(String value) { |
342 log.debug("TransitionBase.prepareInputData4DateDBQuery"); | 364 log.debug("TransitionBase.prepareInputData4DateDBQuery"); |
343 if (value != null){ | 365 if (value != null) { |
344 String[] values = value.split(","); | 366 String[] values = value.split(","); |
345 String newValue = ""; | 367 String newValue = ""; |
346 for (int i = 0; i < values.length; i++){ | 368 for (int i = 0; i < values.length; i++) { |
347 if (newValue.length() > 0){ | 369 if (newValue.length() > 0) { |
348 newValue= newValue + " , "; | 370 newValue = newValue + " , "; |
349 } | 371 } |
350 // TODO JUST HACK FIND A BETTER RESOLUTION | 372 // TODO JUST HACK FIND A BETTER RESOLUTION |
351 newValue = newValue + "to_date('"+values[i].trim()+"', 'YYYY.MM.DD HH24:MI:SS')"; | 373 newValue = newValue + "to_date('" + values[i].trim() |
374 + "', 'YYYY.MM.DD HH24:MI:SS')"; | |
352 } | 375 } |
353 return newValue; | 376 return newValue; |
354 } | 377 } |
355 | 378 |
356 return value; | 379 return value; |
357 } | 380 } |
358 private String prepareInputData4DBQuery(String value){ | 381 |
382 private String prepareInputData4DBQuery(String value) { | |
359 log.debug("TransitionBase.prepareInputData4DBQuery"); | 383 log.debug("TransitionBase.prepareInputData4DBQuery"); |
360 if (value != null){ | 384 if (value != null) { |
361 String[] values = value.split(","); | 385 String[] values = value.split(","); |
362 String newValue = ""; | 386 String newValue = ""; |
363 for (int i = 0; i < values.length; i++){ | 387 for (int i = 0; i < values.length; i++) { |
364 if (newValue.length() > 0){ | 388 if (newValue.length() > 0) { |
365 newValue= newValue + " , "; | 389 newValue = newValue + " , "; |
366 } | 390 } |
367 newValue = newValue + "'"+values[i].trim()+"'"; | 391 newValue = newValue + "'" + values[i].trim() + "'"; |
368 } | 392 } |
369 return newValue; | 393 return newValue; |
370 } | 394 } |
371 | 395 |
372 return value; | 396 return value; |
373 | 397 |
374 } | 398 } |
375 | 399 |
376 /** | 400 /** |
377 * @param result | 401 * @param result |
378 */ | 402 */ |
379 protected void purifyResult(Collection<Result> result, String uuid) { | 403 protected void purifyResult(Collection<Result> result, String uuid) { |
380 log.debug("TransitionBase.purifyResult"); | 404 log.debug("TransitionBase.purifyResult"); |
381 if (this.descibeData == null){ | 405 if (this.descibeData == null) { |
382 this.descibeData = new ArrayList<Object>(); | 406 this.descibeData = new ArrayList<Object>(); |
383 } | 407 } |
384 Iterator<Result> rit = result.iterator(); | 408 Iterator<Result> rit = result.iterator(); |
385 NamedCollection<KeyValueDescibeData> keyValueDescibeData = new NamedArrayList<KeyValueDescibeData>(this.dataName,result.size()); | 409 NamedCollection<KeyValueDescibeData> keyValueDescibeData = new NamedArrayList<KeyValueDescibeData>( |
410 this.dataName, result.size()); | |
386 keyValueDescibeData.setMultiSelect(this.dataMultiSelect); | 411 keyValueDescibeData.setMultiSelect(this.dataMultiSelect); |
387 while(rit.hasNext()){ | 412 while (rit.hasNext()) { |
388 Result resultValue = rit.next(); | 413 Result resultValue = rit.next(); |
389 keyValueDescibeData.add(new DefaultKeyValueDescribeData(resultValue.getString("KEY"), resultValue.getString("VALUE"))); | 414 keyValueDescibeData.add(new DefaultKeyValueDescribeData(resultValue |
415 .getString("KEY"), resultValue.getString("VALUE"))); | |
390 } | 416 } |
391 this.descibeData.add(keyValueDescibeData); | 417 this.descibeData.add(keyValueDescibeData); |
392 } | 418 } |
393 | 419 |
394 /** | 420 /** |
395 * @see de.intevation.gnv.transition.Transition#describe(org.w3c.dom.Document, org.w3c.dom.Node, de.intevation.artifacts.CallMeta) | 421 * @see de.intevation.gnv.transition.Transition#describe(org.w3c.dom.Document, |
422 * org.w3c.dom.Node, de.intevation.artifacts.CallMeta) | |
396 */ | 423 */ |
397 public void describe(Document document, Node rootNode, CallMeta callMeta) { | 424 public void describe(Document document, Node rootNode, CallMeta callMeta) { |
398 log.debug("TransitionBase.describe"); | 425 log.debug("TransitionBase.describe"); |
399 if(this.descibeData != null){ | 426 if (this.descibeData != null) { |
400 ArtifactXMLUtilities xmlutilities = new ArtifactXMLUtilities(); | 427 ArtifactXMLUtilities xmlutilities = new ArtifactXMLUtilities(); |
401 Iterator<Object> it = this.descibeData.iterator(); | 428 Iterator<Object> it = this.descibeData.iterator(); |
402 Node staticNode = xmlutilities.createArtifactElement(document, "static"); | 429 Node staticNode = xmlutilities.createArtifactElement(document, |
403 Node dynamic = xmlutilities.createArtifactElement(document, "dynamic"); | 430 "static"); |
431 Node dynamic = xmlutilities.createArtifactElement(document, | |
432 "dynamic"); | |
404 rootNode.appendChild(staticNode); | 433 rootNode.appendChild(staticNode); |
405 rootNode.appendChild(dynamic); | 434 rootNode.appendChild(dynamic); |
406 while (it.hasNext()){ | 435 while (it.hasNext()) { |
407 | 436 |
408 Object o = it.next(); | 437 Object o = it.next(); |
409 if (o instanceof Collection<?>){ | 438 if (o instanceof Collection<?>) { |
410 String name = null; | 439 String name = null; |
411 boolean multiselect = false; | 440 boolean multiselect = false; |
412 if (o instanceof NamedCollection<?>){ | 441 if (o instanceof NamedCollection<?>) { |
413 NamedCollection<?> nc = ((NamedCollection<?>)o); | 442 NamedCollection<?> nc = ((NamedCollection<?>) o); |
414 name = nc.getName(); | 443 name = nc.getName(); |
415 multiselect = nc.isMultiSelect(); | 444 multiselect = nc.isMultiSelect(); |
416 }else{ | 445 } else { |
417 Object[] names = this.inputValueNames.toArray(); | 446 Object[] names = this.inputValueNames.toArray(); |
418 name = names[names.length-1].toString(); | 447 name = names[names.length - 1].toString(); |
448 } | |
449 | |
450 Element selectNode = xmlutilities.createXFormElement( | |
451 document, multiselect ? "select" : "select1"); | |
452 selectNode.setAttribute("ref", name); | |
453 | |
454 Element lableNode = xmlutilities.createXFormElement( | |
455 document, "label"); | |
456 lableNode.setTextContent(RessourceFactory.getInstance() | |
457 .getRessource(callMeta.getLanguages(), name, name)); | |
458 Element choiceNode = xmlutilities.createXFormElement( | |
459 document, "choices"); | |
460 | |
461 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o; | |
462 Iterator<KeyValueDescibeData> resultIt = values.iterator(); | |
463 while (resultIt.hasNext()) { | |
464 KeyValueDescibeData result = resultIt.next(); | |
465 Element itemNode = xmlutilities.createXFormElement( | |
466 document, "item"); | |
467 | |
468 if (result.isSelected()) { | |
469 itemNode.setAttribute("selected", "true"); | |
419 } | 470 } |
420 | 471 |
421 | 472 Element choiceLableNode = xmlutilities |
422 Element selectNode = xmlutilities.createXFormElement(document,multiselect ? "select" : "select1"); | 473 .createXFormElement(document, "label"); |
423 selectNode.setAttribute("ref", name); | 474 choiceLableNode.setTextContent(result.getValue()); |
424 | 475 itemNode.appendChild(choiceLableNode); |
425 Element lableNode = xmlutilities.createXFormElement(document, "label"); | 476 |
426 lableNode.setTextContent(RessourceFactory.getInstance().getRessource(callMeta.getLanguages(), name, name)); | 477 Element choicValueNode = xmlutilities |
427 Element choiceNode = xmlutilities.createXFormElement(document, "choices"); | 478 .createXFormElement(document, "value"); |
428 | 479 choicValueNode.setTextContent("" + result.getKey()); |
429 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>)o; | 480 itemNode.appendChild(choicValueNode); |
430 Iterator<KeyValueDescibeData> resultIt = values.iterator(); | 481 choiceNode.appendChild(itemNode); |
431 while (resultIt.hasNext()){ | 482 } |
432 KeyValueDescibeData result = resultIt.next(); | 483 selectNode.appendChild(lableNode); |
433 Element itemNode = xmlutilities.createXFormElement(document, "item"); | 484 selectNode.appendChild(choiceNode); |
434 | 485 |
435 if (result.isSelected()){ | 486 if (!it.hasNext()) { |
436 itemNode.setAttribute("selected", "true"); | 487 dynamic.appendChild(selectNode); |
437 } | 488 } else { |
438 | 489 staticNode.appendChild(selectNode); |
439 | 490 } |
440 Element choiceLableNode = xmlutilities.createXFormElement(document, "label"); | 491 |
441 choiceLableNode.setTextContent(result.getValue()); | 492 } else if (o instanceof MinMaxDescribeData) { |
442 itemNode.appendChild(choiceLableNode); | 493 MinMaxDescribeData descibeData = (MinMaxDescribeData) o; |
443 | 494 Object min = descibeData.getMinValue(); |
444 Element choicValueNode = xmlutilities.createXFormElement(document, "value"); | 495 Object max = descibeData.getMaxValue(); |
445 choicValueNode.setTextContent(""+result.getKey()); | 496 if (min instanceof GregorianCalendar) { |
446 itemNode.appendChild(choicValueNode); | 497 Date d = ((GregorianCalendar) min).getTime(); |
447 choiceNode.appendChild(itemNode); | 498 min = DateUtils.getPatternedDateAmer(d); |
448 } | 499 } |
449 selectNode.appendChild(lableNode); | 500 |
450 selectNode.appendChild(choiceNode); | 501 if (max instanceof GregorianCalendar) { |
451 | 502 Date d = ((GregorianCalendar) max).getTime(); |
452 if (!it.hasNext()){ | 503 max = DateUtils.getPatternedDateAmer(d); |
453 dynamic.appendChild(selectNode); | 504 } |
454 }else{ | 505 |
455 staticNode.appendChild(selectNode); | 506 Element inputMinNode = xmlutilities.createXFormElement( |
456 } | 507 document, "input"); |
457 | 508 inputMinNode.setAttribute("ref", "minvalue"); |
458 }else if (o instanceof MinMaxDescribeData){ | 509 Element inputMinLableNode = xmlutilities |
459 MinMaxDescribeData descibeData = (MinMaxDescribeData)o; | 510 .createXFormElement(document, "label"); |
460 Object min = descibeData.getMinValue(); | 511 inputMinLableNode.setTextContent(RessourceFactory |
461 Object max = descibeData.getMaxValue(); | 512 .getInstance().getRessource( |
462 if (min instanceof GregorianCalendar){ | 513 callMeta.getLanguages(), "minvalue", |
463 Date d = ((GregorianCalendar)min).getTime(); | 514 "minvalue")); |
464 min = DateUtils.getPatternedDateAmer(d); | 515 inputMinNode.appendChild(inputMinLableNode); |
465 } | 516 |
466 | 517 Element inputMinValueNode = xmlutilities |
467 if (max instanceof GregorianCalendar){ | 518 .createXFormElement(document, "value"); |
468 Date d = ((GregorianCalendar)max).getTime(); | 519 inputMinValueNode.setTextContent(min.toString()); |
469 max = DateUtils.getPatternedDateAmer(d); | 520 inputMinNode.appendChild(inputMinValueNode); |
470 } | 521 |
471 | 522 Element inputMaxNode = xmlutilities.createXFormElement( |
472 Element inputMinNode = xmlutilities.createXFormElement(document, "input"); | 523 document, "input"); |
473 inputMinNode.setAttribute("ref", "minvalue"); | 524 inputMaxNode.setAttribute("ref", "maxvalue"); |
474 Element inputMinLableNode = xmlutilities.createXFormElement(document, "label"); | 525 Element inputMaxLableNode = xmlutilities |
475 inputMinLableNode.setTextContent(RessourceFactory.getInstance().getRessource(callMeta.getLanguages(), "minvalue", "minvalue")); | 526 .createXFormElement(document, "label"); |
476 inputMinNode.appendChild(inputMinLableNode); | 527 inputMaxLableNode.setTextContent(RessourceFactory |
477 | 528 .getInstance().getRessource( |
478 Element inputMinValueNode = xmlutilities.createXFormElement(document, "value"); | 529 callMeta.getLanguages(), "maxvalue", |
479 inputMinValueNode.setTextContent(min.toString()); | 530 "maxvalue")); |
480 inputMinNode.appendChild(inputMinValueNode); | 531 inputMaxNode.appendChild(inputMaxLableNode); |
481 | 532 |
482 Element inputMaxNode = xmlutilities.createXFormElement(document, "input"); | 533 Element inputMaxValueNode = xmlutilities |
483 inputMaxNode.setAttribute("ref", "maxvalue"); | 534 .createXFormElement(document, "value"); |
484 Element inputMaxLableNode = xmlutilities.createXFormElement(document, "label"); | 535 inputMaxValueNode.setTextContent(max.toString()); |
485 inputMaxLableNode.setTextContent(RessourceFactory.getInstance().getRessource(callMeta.getLanguages(), "maxvalue", "maxvalue")); | 536 inputMaxNode.appendChild(inputMaxValueNode); |
486 inputMaxNode.appendChild(inputMaxLableNode); | 537 |
487 | 538 if (!it.hasNext()) { |
488 Element inputMaxValueNode = xmlutilities.createXFormElement(document, "value"); | 539 dynamic.appendChild(inputMinNode); |
489 inputMaxValueNode.setTextContent(max.toString()); | 540 dynamic.appendChild(inputMaxNode); |
490 inputMaxNode.appendChild(inputMaxValueNode); | 541 } else { |
491 | 542 staticNode.appendChild(inputMinNode); |
492 | 543 staticNode.appendChild(inputMaxNode); |
493 if (!it.hasNext()){ | 544 } |
494 dynamic.appendChild(inputMinNode); | 545 } else if (o instanceof SingleValueDescribeData) { |
495 dynamic.appendChild(inputMaxNode); | 546 |
496 }else{ | 547 SingleValueDescribeData svdb = (SingleValueDescribeData) o; |
497 staticNode.appendChild(inputMinNode); | 548 |
498 staticNode.appendChild(inputMaxNode); | 549 Element inputNode = xmlutilities.createXFormElement( |
499 } | 550 document, "input"); |
500 }else if (o instanceof SingleValueDescribeData){ | 551 inputNode.setAttribute("ref", svdb.getName()); |
501 | 552 |
502 SingleValueDescribeData svdb = (SingleValueDescribeData)o; | 553 Element inputLableNode = xmlutilities.createXFormElement( |
503 | 554 document, "label"); |
504 Element inputNode = xmlutilities.createXFormElement(document, "input"); | 555 inputLableNode.setTextContent(RessourceFactory |
505 inputNode.setAttribute("ref", svdb.getName()); | 556 .getInstance().getRessource( |
506 | 557 callMeta.getLanguages(), svdb.getName(), |
507 Element inputLableNode = xmlutilities.createXFormElement(document, "label"); | 558 svdb.getName())); |
508 inputLableNode.setTextContent(RessourceFactory.getInstance().getRessource(callMeta.getLanguages(), svdb.getName(), svdb.getName())); | 559 inputNode.appendChild(inputLableNode); |
509 inputNode.appendChild(inputLableNode); | 560 |
510 | 561 Element inputValueNode = xmlutilities.createXFormElement( |
511 Element inputValueNode = xmlutilities.createXFormElement(document, "value"); | 562 document, "value"); |
512 inputValueNode.setTextContent(svdb.getValue()); | 563 inputValueNode.setTextContent(svdb.getValue()); |
513 inputNode.appendChild(inputValueNode); | 564 inputNode.appendChild(inputValueNode); |
514 | 565 |
515 | 566 if (!it.hasNext()) { |
516 if (!it.hasNext()){ | 567 dynamic.appendChild(inputNode); |
517 dynamic.appendChild(inputNode); | 568 } else { |
518 }else{ | 569 staticNode.appendChild(inputNode); |
519 staticNode.appendChild(inputNode); | 570 } |
520 } | 571 } |
521 } | 572 |
522 | 573 } |
523 } | 574 } |
524 } | 575 } |
525 } | |
526 | 576 |
527 /** | 577 /** |
528 * @see de.intevation.gnv.transition.Transition#getDescibeData() | 578 * @see de.intevation.gnv.transition.Transition#getDescibeData() |
529 */ | 579 */ |
530 public Collection<Object> getDescibeData() { | 580 public Collection<Object> getDescibeData() { |
534 /** | 584 /** |
535 * @see de.intevation.gnv.transition.Transition#setDescibeData(java.util.Collection) | 585 * @see de.intevation.gnv.transition.Transition#setDescibeData(java.util.Collection) |
536 */ | 586 */ |
537 public void setDescibeData(Collection<Object> descibeData) { | 587 public void setDescibeData(Collection<Object> descibeData) { |
538 this.descibeData = descibeData; | 588 this.descibeData = descibeData; |
539 | 589 |
540 } | 590 } |
541 | 591 |
542 /** | 592 /** |
543 * @see de.intevation.gnv.transition.Transition#getInputData() | 593 * @see de.intevation.gnv.transition.Transition#getInputData() |
544 */ | 594 */ |
545 public Collection<InputData> getInputData() throws TransitionException { | 595 public Collection<InputData> getInputData() throws TransitionException { |
546 return this.inputData != null ? this.inputData.values() : null; | 596 return this.inputData != null ? this.inputData.values() : null; |
547 } | 597 } |
548 } | 598 } |