Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java @ 207:d87347142702
Store the Results of an Artifact not in the Artifact but in an ehcache instance. issue3
gnv-artifacts/trunk@263 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 23 Oct 2009 08:50:50 +0000 |
parents | 734ac082c8d1 |
children | ee2d4134d0b3 |
comparison
equal
deleted
inserted
replaced
206:01ac348ac4a4 | 207:d87347142702 |
---|---|
21 import org.w3c.dom.NodeList; | 21 import org.w3c.dom.NodeList; |
22 | 22 |
23 import de.intevation.artifactdatabase.Config; | 23 import de.intevation.artifactdatabase.Config; |
24 import de.intevation.artifacts.CallMeta; | 24 import de.intevation.artifacts.CallMeta; |
25 import de.intevation.gnv.artifacts.GNVArtifactBase; | 25 import de.intevation.gnv.artifacts.GNVArtifactBase; |
26 import de.intevation.gnv.artifacts.cache.CacheFactory; | |
26 import de.intevation.gnv.artifacts.ressource.RessourceFactory; | 27 import de.intevation.gnv.artifacts.ressource.RessourceFactory; |
27 import de.intevation.gnv.geobackend.base.Result; | 28 import de.intevation.gnv.geobackend.base.Result; |
28 import de.intevation.gnv.geobackend.base.query.QueryExecutor; | 29 import de.intevation.gnv.geobackend.base.query.QueryExecutor; |
29 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; | 30 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; |
30 import de.intevation.gnv.geobackend.base.query.exception.QueryException; | 31 import de.intevation.gnv.geobackend.base.query.exception.QueryException; |
52 | 53 |
53 /** | 54 /** |
54 * the logger, used to log exceptions and additonaly information | 55 * the logger, used to log exceptions and additonaly information |
55 */ | 56 */ |
56 private static Logger log = Logger.getLogger(GNVArtifactBase.class); | 57 private static Logger log = Logger.getLogger(GNVArtifactBase.class); |
58 | |
59 private final static String DESCRIBEDATAKEY = "_DESCRIBEDATA"; | |
57 | 60 |
58 private String id = null; | 61 private String id = null; |
59 | 62 |
60 private String description = null; | 63 private String description = null; |
61 | 64 |
72 private Map<String, InputValue> inputValues = null; | 75 private Map<String, InputValue> inputValues = null; |
73 | 76 |
74 private Transition parent = null; | 77 private Transition parent = null; |
75 | 78 |
76 protected Map<String, InputData> inputData = null; | 79 protected Map<String, InputData> inputData = null; |
77 | 80 |
78 protected Collection<Object> descibeData = null; | |
79 | 81 |
80 /** | 82 /** |
81 * Constructor | 83 * Constructor |
82 */ | 84 */ |
83 public TransitionBase() { | 85 public TransitionBase() { |
203 inputData.size()); | 205 inputData.size()); |
204 } | 206 } |
205 boolean valid = iv.isInputValid(tmpItem.getValue(), | 207 boolean valid = iv.isInputValid(tmpItem.getValue(), |
206 inputValue.getType()); | 208 inputValue.getType()); |
207 if (valid) { | 209 if (valid) { |
208 this.setSelection(tmpItem); | 210 this.setSelection(tmpItem, uuid); |
209 this.inputData.put(tmpItem.getName(), tmpItem); | 211 this.inputData.put(tmpItem.getName(), tmpItem); |
210 } else { | 212 } else { |
211 String errMsg = "Wrong input for " + tmpItem.getValue() | 213 String errMsg = "Wrong input for " + tmpItem.getValue() |
212 + " is not an " + inputValue.getType() | 214 + " is not an " + inputValue.getType() |
213 + " Value."; | 215 + " Value."; |
225 } else { | 227 } else { |
226 log.warn("No Inputdata given"); | 228 log.warn("No Inputdata given"); |
227 } | 229 } |
228 } | 230 } |
229 | 231 |
230 private void setSelection(InputData inputData) { | 232 private void setSelection(InputData inputData, String uuid) { |
231 log.debug("TransitionBase.setSelection"); | 233 log.debug("TransitionBase.setSelection"); |
232 | 234 |
233 Object o = this.getDescribeData(inputData.getName()); | 235 Object o = this.getDescribeData(inputData.getName(),uuid); |
234 if (o != null) { | 236 if (o != null) { |
235 if (o instanceof Collection<?>) { | 237 if (o instanceof Collection<?>) { |
236 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o; | 238 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o; |
237 | 239 |
238 String value = inputData.getValue(); | 240 String value = inputData.getValue(); |
262 } | 264 } |
263 } | 265 } |
264 } | 266 } |
265 } | 267 } |
266 | 268 |
267 private Object getDescribeData(String name) { | 269 private Object getDescribeData(String name, String uuid) { |
268 log.debug("TransitionBase.getDescribeData"); | 270 log.debug("TransitionBase.getDescribeData"); |
269 if (this.descibeData != null) { | 271 Collection<Object> descibeData = this.getDescibeData(uuid); |
270 Iterator<Object> it = this.descibeData.iterator(); | 272 if (descibeData != null) { |
273 Iterator<Object> it = descibeData.iterator(); | |
271 while (it.hasNext()) { | 274 while (it.hasNext()) { |
272 Object o = it.next(); | 275 Object o = it.next(); |
273 if (o instanceof NamedCollection<?>) { | 276 if (o instanceof NamedCollection<?>) { |
274 if (name.equals(((NamedCollection<?>) o).getName())) { | 277 if (name.equals(((NamedCollection<?>) o).getName())) { |
275 return o; | 278 return o; |
405 /** | 408 /** |
406 * @param result | 409 * @param result |
407 */ | 410 */ |
408 protected void purifyResult(Collection<Result> result, String uuid) { | 411 protected void purifyResult(Collection<Result> result, String uuid) { |
409 log.debug("TransitionBase.purifyResult"); | 412 log.debug("TransitionBase.purifyResult"); |
410 if (this.descibeData == null) { | 413 Collection<Object> describeData = this.getDescibeData(uuid); |
411 this.descibeData = new ArrayList<Object>(); | 414 if (describeData == null) { |
415 describeData = new ArrayList<Object>(); | |
412 } | 416 } |
413 NamedCollection<KeyValueDescibeData> keyValueDescibeData = extractKVP(result, "KEY", "VALUE"); | 417 NamedCollection<KeyValueDescibeData> keyValueDescibeData = extractKVP(result, "KEY", "VALUE"); |
414 this.descibeData.add(keyValueDescibeData); | 418 describeData.add(keyValueDescibeData); |
419 this.setDescibeData(uuid, describeData); | |
415 } | 420 } |
416 | 421 |
417 /** | 422 /** |
418 * @param result | 423 * @param result |
419 * @return | 424 * @return |
434 return keyValueDescibeData; | 439 return keyValueDescibeData; |
435 } | 440 } |
436 | 441 |
437 /** | 442 /** |
438 * @see de.intevation.gnv.transition.Transition#describe(org.w3c.dom.Document, | 443 * @see de.intevation.gnv.transition.Transition#describe(org.w3c.dom.Document, |
439 * org.w3c.dom.Node, de.intevation.artifacts.CallMeta) | 444 * org.w3c.dom.Node, de.intevation.artifacts.CallMeta, |
440 */ | 445 * java.lang.String) |
441 public void describe(Document document, Node rootNode, CallMeta callMeta) { | 446 */ |
447 public void describe(Document document, Node rootNode, CallMeta callMeta,String uuid) { | |
442 log.debug("TransitionBase.describe"); | 448 log.debug("TransitionBase.describe"); |
443 if (this.descibeData != null) { | 449 Collection<Object> descibeData = this.getDescibeData(uuid); |
450 if (descibeData != null) { | |
444 ArtifactXMLUtilities xmlutilities = new ArtifactXMLUtilities(); | 451 ArtifactXMLUtilities xmlutilities = new ArtifactXMLUtilities(); |
445 Iterator<Object> it = this.descibeData.iterator(); | 452 Iterator<Object> it = descibeData.iterator(); |
446 Node staticNode = xmlutilities.createArtifactElement(document, | 453 Node staticNode = xmlutilities.createArtifactElement(document, |
447 "static"); | 454 "static"); |
448 Node dynamic = xmlutilities.createArtifactElement(document, | 455 Node dynamic = xmlutilities.createArtifactElement(document, |
449 "dynamic"); | 456 "dynamic"); |
450 rootNode.appendChild(staticNode); | 457 rootNode.appendChild(staticNode); |
505 } else { | 512 } else { |
506 staticNode.appendChild(selectNode); | 513 staticNode.appendChild(selectNode); |
507 } | 514 } |
508 | 515 |
509 } else if (o instanceof MinMaxDescribeData) { | 516 } else if (o instanceof MinMaxDescribeData) { |
510 MinMaxDescribeData descibeData = (MinMaxDescribeData) o; | 517 MinMaxDescribeData minMaxDescibeData = (MinMaxDescribeData) o; |
511 Object min = descibeData.getMinValue(); | 518 Object min = minMaxDescibeData.getMinValue(); |
512 Object max = descibeData.getMaxValue(); | 519 Object max = minMaxDescibeData.getMaxValue(); |
513 if (min instanceof GregorianCalendar) { | 520 if (min instanceof GregorianCalendar) { |
514 Date d = ((GregorianCalendar) min).getTime(); | 521 Date d = ((GregorianCalendar) min).getTime(); |
515 min = DateUtils.getPatternedDateAmer(d); | 522 min = DateUtils.getPatternedDateAmer(d); |
516 } | 523 } |
517 | 524 |
520 max = DateUtils.getPatternedDateAmer(d); | 527 max = DateUtils.getPatternedDateAmer(d); |
521 } | 528 } |
522 | 529 |
523 Element groupNode = xmlutilities.createXFormElement( | 530 Element groupNode = xmlutilities.createXFormElement( |
524 document, "group"); | 531 document, "group"); |
525 groupNode.setAttribute("ref", descibeData.getMinName()); | 532 groupNode.setAttribute("ref", minMaxDescibeData.getMinName()); |
526 Element groupNodeLableNode = xmlutilities | 533 Element groupNodeLableNode = xmlutilities |
527 .createXFormElement(document, "label"); | 534 .createXFormElement(document, "label"); |
528 groupNodeLableNode.setTextContent(RessourceFactory | 535 groupNodeLableNode.setTextContent(RessourceFactory |
529 .getInstance().getRessource( | 536 .getInstance().getRessource( |
530 callMeta.getLanguages(), | 537 callMeta.getLanguages(), |
531 descibeData.getMinName(), | 538 minMaxDescibeData.getMinName(), |
532 descibeData.getMinName())); | 539 minMaxDescibeData.getMinName())); |
533 groupNode.appendChild(groupNodeLableNode); | 540 groupNode.appendChild(groupNodeLableNode); |
534 | 541 |
535 Element inputMinNode = xmlutilities.createXFormElement( | 542 Element inputMinNode = xmlutilities.createXFormElement( |
536 document, "input"); | 543 document, "input"); |
537 inputMinNode.setAttribute("ref", "minvalue"); | 544 inputMinNode.setAttribute("ref", "minvalue"); |
615 } | 622 } |
616 | 623 |
617 /** | 624 /** |
618 * @see de.intevation.gnv.transition.Transition#getDescibeData() | 625 * @see de.intevation.gnv.transition.Transition#getDescibeData() |
619 */ | 626 */ |
620 public Collection<Object> getDescibeData() { | 627 protected Collection<Object> getDescibeData(String uuid) { |
621 return this.descibeData; | 628 if (CacheFactory.getInstance().isInitialized()) { |
622 } | 629 String key = uuid + DESCRIBEDATAKEY; |
623 | 630 log.debug("Hash for Queryelements: " + key); |
624 /** | 631 net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); |
625 * @see de.intevation.gnv.transition.Transition#setDescibeData(java.util.Collection) | 632 if (value != null) { |
626 */ | 633 return (Collection<Object>) (value.getObjectValue()); |
627 public void setDescibeData(Collection<Object> descibeData) { | 634 } |
628 this.descibeData = descibeData; | 635 } |
629 | 636 return null; |
637 } | |
638 | |
639 /** | |
640 * @see de.intevation.gnv.transition.Transition#getDescibeData() | |
641 */ | |
642 protected void setDescibeData(String uuid, Collection<Object> describeData) { | |
643 | |
644 if (CacheFactory.getInstance().isInitialized()) { | |
645 String key = uuid + DESCRIBEDATAKEY; | |
646 log.debug("Hash for Queryelements: " + key); | |
647 CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, describeData)); | |
648 } | |
630 } | 649 } |
631 | 650 |
632 /** | 651 /** |
633 * @see de.intevation.gnv.transition.Transition#getInputData() | 652 * @see de.intevation.gnv.transition.Transition#getInputData() |
634 */ | 653 */ |