comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java @ 81:9b41f3688610

Added Support for TimeSeriesMesh gnv-artifacts/trunk@106 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 21 Sep 2009 11:50:47 +0000
parents e33c61735a4e
children 5eb62df21f9a
comparison
equal deleted inserted replaced
80:29a7ba731838 81:9b41f3688610
8 import java.util.Date; 8 import java.util.Date;
9 import java.util.GregorianCalendar; 9 import java.util.GregorianCalendar;
10 import java.util.HashMap; 10 import java.util.HashMap;
11 import java.util.HashSet; 11 import java.util.HashSet;
12 import java.util.Iterator; 12 import java.util.Iterator;
13 import java.util.List;
13 import java.util.Map; 14 import java.util.Map;
14 import java.util.Set; 15 import java.util.Set;
15 16
16 import org.apache.log4j.Logger; 17 import org.apache.log4j.Logger;
17 import org.w3c.dom.Document; 18 import org.w3c.dom.Document;
29 import de.intevation.gnv.transition.describedata.DefaultKeyValueDescribeData; 30 import de.intevation.gnv.transition.describedata.DefaultKeyValueDescribeData;
30 import de.intevation.gnv.transition.describedata.KeyValueDescibeData; 31 import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
31 import de.intevation.gnv.transition.describedata.MinMaxDescribeData; 32 import de.intevation.gnv.transition.describedata.MinMaxDescribeData;
32 import de.intevation.gnv.transition.describedata.NamedArrayList; 33 import de.intevation.gnv.transition.describedata.NamedArrayList;
33 import de.intevation.gnv.transition.describedata.NamedCollection; 34 import de.intevation.gnv.transition.describedata.NamedCollection;
35 import de.intevation.gnv.transition.describedata.SingleValueDescribeData;
34 import de.intevation.gnv.transition.exception.TransitionException; 36 import de.intevation.gnv.transition.exception.TransitionException;
35 import de.intevation.gnv.utils.ArtifactXMLUtilities; 37 import de.intevation.gnv.utils.ArtifactXMLUtilities;
36 38
37 /** 39 /**
38 * @author Tim Englich <tim.englich@intevation.de> 40 * @author Tim Englich <tim.englich@intevation.de>
52 54
53 private String id = null; 55 private String id = null;
54 56
55 private String description = null; 57 private String description = null;
56 58
57 private String dataName = null; 59 protected String dataName = null;
58 60
59 private boolean dataMultiSelect = false; 61 private boolean dataMultiSelect = false;
60 62
61 protected String queryID = null; 63 protected String queryID = null;
62 64
128 NodeList inputValuesNodes = Config.getNodeSetXPath(configuration,"inputvalues/inputvalue"); 130 NodeList inputValuesNodes = Config.getNodeSetXPath(configuration,"inputvalues/inputvalue");
129 this.inputValues = new HashMap<String,InputValue>(inputValuesNodes.getLength()); 131 this.inputValues = new HashMap<String,InputValue>(inputValuesNodes.getLength());
130 this.inputValueNames = new ArrayList<String>(inputValuesNodes.getLength()); 132 this.inputValueNames = new ArrayList<String>(inputValuesNodes.getLength());
131 for (int i = 0 ; i < inputValuesNodes.getLength(); i++){ 133 for (int i = 0 ; i < inputValuesNodes.getLength(); i++){
132 Node inputValueNode = inputValuesNodes.item(i); 134 Node inputValueNode = inputValuesNodes.item(i);
133 InputValue inputValue = new DefaultInputValue(Config.getStringXPath(inputValueNode,"@name"), Config.getStringXPath(inputValueNode,"@type"), Boolean.parseBoolean(Config.getStringXPath(inputValueNode,"@multiselect"))); 135 String usedinQueryValue = Config.getStringXPath(inputValueNode,"@usedinquery");
136 int usedinQuery = 1;
137 if (usedinQueryValue != null){
138 try {
139 usedinQuery = Integer.parseInt(usedinQueryValue);
140 } catch (NumberFormatException e) {
141 log.warn("Used in Query Value cannot be transformed into a Number");
142 }
143 }
144 InputValue inputValue = new DefaultInputValue(
145 Config.getStringXPath(inputValueNode,"@name"),
146 Config.getStringXPath(inputValueNode,"@type"),
147 Boolean.parseBoolean(Config.getStringXPath(inputValueNode,"@multiselect")),
148 usedinQuery);
134 log.debug(inputValue.toString()); 149 log.debug(inputValue.toString());
135 this.inputValues.put(inputValue.getName(),inputValue); 150 this.inputValues.put(inputValue.getName(),inputValue);
136 this.inputValueNames.add(inputValue.getName()); 151 this.inputValueNames.add(inputValue.getName());
137 } 152 }
138 153
270 * @see de.intevation.gnv.transition.Transition#advance() 285 * @see de.intevation.gnv.transition.Transition#advance()
271 */ 286 */
272 public void advance() throws TransitionException { 287 public void advance() throws TransitionException {
273 log.debug("TransitionBase.advance"); 288 log.debug("TransitionBase.advance");
274 try { 289 try {
275 String[] filterValues = new String[this.inputValueNames.size()]; 290 List<String> list = new ArrayList<String>();
291
292
276 Iterator<String> it = this.inputValueNames.iterator(); 293 Iterator<String> it = this.inputValueNames.iterator();
277 int i = 0; 294 int i = 0;
278 while (it.hasNext()){ 295 while (it.hasNext()){
279 String value = it.next(); 296 String value = it.next();
280 InputData data = this.inputData.get(value); 297 InputData data = this.inputData.get(value);
281 filterValues[i++] = data.getValue(); 298 int size = this.inputValues.get(data.getName()).usedInQueries();
282 } 299 for (int j = 0; j < size; j++){
283 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); 300 list.add(data.getValue());
284 Collection<Result> result = queryExecutor.executeQuery(this.queryID, filterValues); 301 }
285 this.purifyResult(result); 302 }
303 String[] filterValues = list.toArray(new String[0]);
304 Collection<Result> result = null;
305 try {
306 if (this.queryID != null){
307 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor();
308 result = queryExecutor.executeQuery(this.queryID, filterValues);
309 }
310 this.purifyResult(result);
311 } catch (RuntimeException e) {
312 log.error(e,e);
313 }
286 } catch (QueryException e) { 314 } catch (QueryException e) {
287 log.error(e,e); 315 log.error(e,e);
288 throw new TransitionException(e); 316 throw new TransitionException(e);
289 } 317 }
290 } 318 }
412 dynamic.appendChild(inputMaxNode); 440 dynamic.appendChild(inputMaxNode);
413 }else{ 441 }else{
414 staticNode.appendChild(inputMinNode); 442 staticNode.appendChild(inputMinNode);
415 staticNode.appendChild(inputMaxNode); 443 staticNode.appendChild(inputMaxNode);
416 } 444 }
445 }else if (o instanceof SingleValueDescribeData){
446
447 SingleValueDescribeData svdb = (SingleValueDescribeData)o;
448
449 Element inputNode = xmlutilities.createXFormElement(document, "input");
450 inputNode.setAttribute("ref", svdb.getName());
451
452 Element inputLableNode = xmlutilities.createXFormElement(document, "label");
453 inputLableNode.setTextContent(svdb.getName());
454 inputNode.appendChild(inputLableNode);
455
456 Element inputValueNode = xmlutilities.createXFormElement(document, "value");
457 inputValueNode.setTextContent(svdb.getValue());
458 inputNode.appendChild(inputValueNode);
459
460
461 if (!it.hasNext()){
462 dynamic.appendChild(inputNode);
463 }else{
464 staticNode.appendChild(inputNode);
465 }
417 } 466 }
467
418 } 468 }
419 } 469 }
420 } 470 }
421 471
422 /** 472 /**
436 486
437 /** 487 /**
438 * @see de.intevation.gnv.transition.Transition#getInputData() 488 * @see de.intevation.gnv.transition.Transition#getInputData()
439 */ 489 */
440 public Collection<InputData> getInputData() throws TransitionException { 490 public Collection<InputData> getInputData() throws TransitionException {
441 return this.inputData.values(); 491 return this.inputData != null ? this.inputData.values() : null;
442 } 492 }
443 } 493 }

http://dive4elements.wald.intevation.org