comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java @ 222:3e82b4f1c455

Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase. Added the possibility to switch to an alternative Transition. gnv-artifacts/trunk@284 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Thu, 05 Nov 2009 14:45:54 +0000
parents ee2d4134d0b3
children 3d6d89bcbf42
comparison
equal deleted inserted replaced
221:21152e1bf325 222:3e82b4f1c455
54 /** 54 /**
55 * the logger, used to log exceptions and additonaly information 55 * the logger, used to log exceptions and additonaly information
56 */ 56 */
57 private static Logger log = Logger.getLogger(GNVArtifactBase.class); 57 private static Logger log = Logger.getLogger(GNVArtifactBase.class);
58 58
59 private static String MINVALUEFIELDNAME = "minvalue"; 59 private final static String MINVALUEFIELDNAME = "minvalue";
60 private static String MAXVALUEFIELDNAME = "maxvalue"; 60 private final static String MAXVALUEFIELDNAME = "maxvalue";
61
62 private final static String NODATASELECTIONKEY = "n/n";
61 63
62 private final static String DESCRIBEDATAKEY = "_DESCRIBEDATA"; 64 private final static String DESCRIBEDATAKEY = "_DESCRIBEDATA";
63 65
64 private String id = null; 66 private String id = null;
65 67
66 private String description = null; 68 private String description = null;
67 69
68 protected String dataName = null; 70 protected String dataName = null;
69 71
70 protected boolean dataMultiSelect = false; 72 protected boolean dataMultiSelect = false;
73
74 protected boolean dataNoSelect = false;
71 75
72 protected String queryID = null; 76 protected String queryID = null;
73 77
74 private Collection<String> reachableTransitions = null; 78 private Collection<String> reachableTransitions = null;
79
80 private Transition alternativeTransition = null;
75 81
76 protected Collection<String> inputValueNames = null; 82 protected Collection<String> inputValueNames = null;
77 83
78 private Map<String, InputValue> inputValues = null; 84 private Map<String, InputValue> inputValues = null;
79 85
105 111
106 /** 112 /**
107 * @see de.intevation.gnv.transition.Transition#reachableTransitions() 113 * @see de.intevation.gnv.transition.Transition#reachableTransitions()
108 */ 114 */
109 public Collection<String> reachableTransitions() { 115 public Collection<String> reachableTransitions() {
110 return this.reachableTransitions; 116
117 if (this.couldAlternativeTransitionUsed()){
118 return this.alternativeTransition.reachableTransitions();
119 }else{
120 return this.reachableTransitions;
121 }
122
123 }
124
125 /**
126 * @return
127 */
128 private boolean couldAlternativeTransitionUsed() {
129 // TODO das muss hier noch etwas freier gestaltet werden.
130 Object[] inputValues = this.inputValueNames.toArray();
131 String key = (String)inputValues[inputValues.length-1];
132 boolean returnValue= this.alternativeTransition != null &&
133 this.inputData != null &&
134 this.inputData.containsKey(key) &&
135 this.inputData.get(key).getValue().
136 equals(NODATASELECTIONKEY);
137 return returnValue;
111 } 138 }
112 139
113 /** 140 /**
114 * @see de.intevation.gnv.transition.Transition#getRequiredInputValues() 141 * @see de.intevation.gnv.transition.Transition#getRequiredInputValues()
115 */ 142 */
133 String reachableTransition = nodes.item(i).getTextContent(); 160 String reachableTransition = nodes.item(i).getTextContent();
134 log.info("ReachableTransition ==> " + reachableTransition); 161 log.info("ReachableTransition ==> " + reachableTransition);
135 this.reachableTransitions.add(reachableTransition); 162 this.reachableTransitions.add(reachableTransition);
136 163
137 } 164 }
138 165
166 Node alternativeTransitionNode = Config.getNodeXPath(configuration,
167 "alternativeTransition/transition");
168 if (alternativeTransitionNode != null){
169 this.alternativeTransition = TransitionFactory.getInstance()
170 .createTransition(alternativeTransitionNode);
171 }
139 NodeList inputValuesNodes = Config.getNodeSetXPath(configuration, 172 NodeList inputValuesNodes = Config.getNodeSetXPath(configuration,
140 "inputvalues/inputvalue"); 173 "inputvalues/inputvalue");
141 this.inputValues = new HashMap<String, InputValue>(inputValuesNodes 174 this.inputValues = new HashMap<String, InputValue>(inputValuesNodes
142 .getLength()); 175 .getLength());
143 this.inputValueNames = new ArrayList<String>(inputValuesNodes 176 this.inputValueNames = new ArrayList<String>(inputValuesNodes
167 log.info("QueryID ==> " + this.queryID); 200 log.info("QueryID ==> " + this.queryID);
168 201
169 this.dataName = Config.getStringXPath(configuration, "dataname"); 202 this.dataName = Config.getStringXPath(configuration, "dataname");
170 203
171 String dataMultiSelectValue = Config.getStringXPath(configuration, 204 String dataMultiSelectValue = Config.getStringXPath(configuration,
172 "data-multiselect"); 205 "data-multiselect");
173 if (dataMultiSelectValue != null) { 206 if (dataMultiSelectValue != null) {
174 this.dataMultiSelect = Boolean.parseBoolean(dataMultiSelectValue); 207 this.dataMultiSelect = Boolean.parseBoolean(dataMultiSelectValue);
175 } 208 }
176 209
210 String dataNoSelectValue =Config.getStringXPath(configuration,
211 "data-noselect");
212 if (dataNoSelectValue != null) {
213 this. dataNoSelect = Boolean.parseBoolean(dataNoSelectValue);
214 }
215
177 } 216 }
178 217
179 /** 218 /**
180 * @see de.intevation.gnv.transition.Transition#getParent() 219 * @see de.intevation.gnv.transition.Transition#getParent()
181 */ 220 */
296 * @see de.intevation.gnv.transition.Transition#isTransitionReachable(java.lang.String) 335 * @see de.intevation.gnv.transition.Transition#isTransitionReachable(java.lang.String)
297 */ 336 */
298 public boolean isTransitionReachable(String transitionID) { 337 public boolean isTransitionReachable(String transitionID) {
299 log.debug("TransitionBase.isTransitionReachable"); 338 log.debug("TransitionBase.isTransitionReachable");
300 boolean returnValue = false; 339 boolean returnValue = false;
301 Iterator<String> transitions = reachableTransitions.iterator(); 340 if (this.couldAlternativeTransitionUsed()){
302 while (transitions.hasNext()) { 341 return alternativeTransition.isTransitionReachable(transitionID);
303 if (transitions.next().equals(transitionID)) { 342 }else{
304 log.debug("Transition " + transitionID + " wird unterstützt."); 343 Iterator<String> transitions = reachableTransitions.iterator();
305 returnValue = true; 344 while (transitions.hasNext()) {
306 break; 345 if (transitions.next().equals(transitionID)) {
346 log.debug("Transition " + transitionID + " wird unterstützt.");
347 returnValue = true;
348 break;
349 }
307 } 350 }
308 } 351 }
309 return returnValue; 352 return returnValue;
310 } 353 }
311 354
314 * de.intevation.artifacts.CallMeta) 357 * de.intevation.artifacts.CallMeta)
315 */ 358 */
316 public void advance(String uuid, CallMeta callMeta) 359 public void advance(String uuid, CallMeta callMeta)
317 throws TransitionException { 360 throws TransitionException {
318 log.debug("TransitionBase.advance"); 361 log.debug("TransitionBase.advance");
319 try { 362
320 List<String> list = new ArrayList<String>(); 363 if (this.couldAlternativeTransitionUsed()){
321 364 this.alternativeTransition.setParent(this.getParent());
322 Iterator<String> it = this.inputValueNames.iterator(); 365 this.alternativeTransition.putInputData(this.inputData != null ?
323 int i = 0; 366 this.inputData.values() :
324 while (it.hasNext()) { 367 null,uuid);
325 String value = it.next(); 368 this.alternativeTransition.advance(uuid, callMeta);
326 InputData data = this.inputData.get(value); 369 }else{
327 if (data != null
328 && this.inputValues.containsKey(data.getName())) {
329 int size = this.inputValues.get(data.getName())
330 .usedInQueries();
331 String type = this.inputValues.get(data.getName())
332 .getType();
333 String requestValue = data.getValue();
334 if (type.equalsIgnoreCase("string")) {
335 requestValue = this
336 .prepareInputData4DBQuery(requestValue);
337 } else if (type.equalsIgnoreCase("date")) {
338 requestValue = this
339 .prepareInputData4DateDBQuery(requestValue);
340 } else if (type.equalsIgnoreCase("coordinate")){
341 requestValue = this
342 .prepareInputData4RegionDBQuery(requestValue);
343 }
344 for (int j = 0; j < size; j++) {
345 list.add(requestValue);
346 }
347 }
348 }
349 String[] filterValues = list.toArray(new String[0]);
350 Collection<Result> result = null;
351 try { 370 try {
352 if (this.queryID != null) { 371 List<String> list = new ArrayList<String>();
353 QueryExecutor queryExecutor = QueryExecutorFactory 372 Iterator<String> it = this.inputValueNames.iterator();
354 .getInstance().getQueryExecutor(); 373 int i = 0;
355 result = queryExecutor.executeQuery(this.queryID, 374 while (it.hasNext()) {
356 filterValues); 375 String value = it.next();
357 } 376 InputData data = this.inputData.get(value);
358 this.purifyResult(result, uuid); 377 if (data != null
359 } catch (RuntimeException e) { 378 && this.inputValues.containsKey(data.getName())) {
379 int size = this.inputValues.get(data.getName())
380 .usedInQueries();
381 String type = this.inputValues.get(data.getName())
382 .getType();
383 String requestValue = data.getValue();
384 if (type.equalsIgnoreCase("string")) {
385 requestValue = this
386 .prepareInputData4DBQuery(requestValue);
387 } else if (type.equalsIgnoreCase("date")) {
388 requestValue = this
389 .prepareInputData4DateDBQuery(requestValue);
390 } else if (type.equalsIgnoreCase("coordinate")){
391 requestValue = this
392 .prepareInputData4RegionDBQuery(requestValue);
393 }
394 for (int j = 0; j < size; j++) {
395 list.add(requestValue);
396 }
397 }
398 }
399 String[] filterValues = list.toArray(new String[0]);
400 Collection<Result> result = null;
401 try {
402 if (this.queryID != null) {
403 QueryExecutor queryExecutor = QueryExecutorFactory
404 .getInstance().getQueryExecutor();
405 result = queryExecutor.executeQuery(this.queryID,
406 filterValues);
407 }
408 this.purifyResult(result, uuid);
409 } catch (RuntimeException e) {
410 log.error(e, e);
411 }
412 } catch (QueryException e) {
360 log.error(e, e); 413 log.error(e, e);
361 } 414 throw new TransitionException(e);
362 } catch (QueryException e) { 415 }
363 log.error(e, e);
364 throw new TransitionException(e);
365 } 416 }
366 } 417 }
367 418
368 protected String prepareInputData4RegionDBQuery(String value){ 419 protected String prepareInputData4RegionDBQuery(String value){
369 return value; 420 return value;
422 473
423 /** 474 /**
424 * @param result 475 * @param result
425 * @return 476 * @return
426 */ 477 */
427 protected NamedCollection<KeyValueDescibeData> extractKVP( 478 protected NamedCollection<KeyValueDescibeData> extractKVP(Collection<Result> result,
428 Collection<Result> result,
429 String keyid, 479 String keyid,
430 String valueid) { 480 String valueid) {
431 Iterator<Result> rit = result.iterator(); 481 Iterator<Result> rit = result.iterator();
482 int dataSize = (this.dataNoSelect ? result.size()+1 : result.size());
483
432 NamedCollection<KeyValueDescibeData> keyValueDescibeData = new NamedArrayList<KeyValueDescibeData>( 484 NamedCollection<KeyValueDescibeData> keyValueDescibeData = new NamedArrayList<KeyValueDescibeData>(
433 this.dataName, result.size()); 485 this.dataName, dataSize);
434 keyValueDescibeData.setMultiSelect(this.dataMultiSelect); 486 keyValueDescibeData.setMultiSelect(this.dataMultiSelect);
487
488 if (this.dataNoSelect){
489 keyValueDescibeData.add(new DefaultKeyValueDescribeData(NODATASELECTIONKEY,
490 "Keine Auswahl"));
491 }
492 String previousKey = null;
435 while (rit.hasNext()) { 493 while (rit.hasNext()) {
436 Result resultValue = rit.next(); 494 Result resultValue = rit.next();
437 keyValueDescibeData.add(new DefaultKeyValueDescribeData(resultValue 495 String tmpKey = resultValue.getString(keyid);
438 .getString(keyid), resultValue.getString(valueid))); 496 // TODO: HACK da die ARCSDE kein DISTINCT auf räumlichen Anfragen unterstützt.
497 if (previousKey == null || !tmpKey.equals(previousKey)){
498 previousKey = tmpKey;
499 keyValueDescibeData.add(new DefaultKeyValueDescribeData(tmpKey, resultValue.getString(valueid)));
500 }
439 } 501 }
440 return keyValueDescibeData; 502 return keyValueDescibeData;
441 } 503 }
442 504
443 /** 505 /**
651 713
652 /** 714 /**
653 * @see de.intevation.gnv.transition.Transition#getInputData() 715 * @see de.intevation.gnv.transition.Transition#getInputData()
654 */ 716 */
655 public Collection<InputData> getInputData() throws TransitionException { 717 public Collection<InputData> getInputData() throws TransitionException {
656 return this.inputData != null ? this.inputData.values() : null; 718 if (this.couldAlternativeTransitionUsed()){
719 return this.alternativeTransition.getInputData();
720 }else{
721 return this.inputData != null ? this.inputData.values() : null;
722 }
657 } 723 }
658 } 724 }

http://dive4elements.wald.intevation.org