Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java @ 61:5f47881f7c97
Implementation of the MIN- / MAX-Value Representation
gnv-artifacts/trunk@44 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Wed, 09 Sep 2009 09:29:39 +0000 |
parents | 2c5d8f5bced1 |
children | 6ae2d4134da3 |
comparison
equal
deleted
inserted
replaced
60:eed1baaeb481 | 61:5f47881f7c97 |
---|---|
3 */ | 3 */ |
4 package de.intevation.gnv.transition; | 4 package de.intevation.gnv.transition; |
5 | 5 |
6 import java.util.ArrayList; | 6 import java.util.ArrayList; |
7 import java.util.Collection; | 7 import java.util.Collection; |
8 import java.util.Date; | |
9 import java.util.GregorianCalendar; | |
8 import java.util.HashMap; | 10 import java.util.HashMap; |
9 import java.util.Iterator; | 11 import java.util.Iterator; |
10 import java.util.Map; | 12 import java.util.Map; |
11 | 13 |
12 import org.apache.log4j.Logger; | 14 import org.apache.log4j.Logger; |
19 import de.intevation.gnv.artifacts.GNVArtifactBase; | 21 import de.intevation.gnv.artifacts.GNVArtifactBase; |
20 import de.intevation.gnv.geobackend.base.Result; | 22 import de.intevation.gnv.geobackend.base.Result; |
21 import de.intevation.gnv.geobackend.base.query.QueryExecutor; | 23 import de.intevation.gnv.geobackend.base.query.QueryExecutor; |
22 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; | 24 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; |
23 import de.intevation.gnv.geobackend.base.query.exception.QueryException; | 25 import de.intevation.gnv.geobackend.base.query.exception.QueryException; |
26 import de.intevation.gnv.geobackend.util.DateUtils; | |
27 import de.intevation.gnv.transition.describedata.MinMaxDescribeData; | |
24 import de.intevation.gnv.transition.exception.TransitionException; | 28 import de.intevation.gnv.transition.exception.TransitionException; |
25 | 29 |
26 /** | 30 /** |
27 * @author Tim Englich <tim.englich@intevation.de> | 31 * @author Tim Englich <tim.englich@intevation.de> |
28 * | 32 * |
52 | 56 |
53 private Transition parent = null; | 57 private Transition parent = null; |
54 | 58 |
55 private Map<String,InputData> inputData = null; | 59 private Map<String,InputData> inputData = null; |
56 | 60 |
57 private Collection<Object> descibeData = null; | 61 protected Collection<Object> descibeData = null; |
62 | |
58 /** | 63 /** |
59 * Constructor | 64 * Constructor |
60 */ | 65 */ |
61 public TransitionBase() { | 66 public TransitionBase() { |
62 super(); | 67 super(); |
198 InputData data = this.inputData.get(value); | 203 InputData data = this.inputData.get(value); |
199 filterValues[i++] = data.getValue(); | 204 filterValues[i++] = data.getValue(); |
200 } | 205 } |
201 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); | 206 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); |
202 Collection<Result> result = queryExecutor.executeQuery(this.queryID, filterValues); | 207 Collection<Result> result = queryExecutor.executeQuery(this.queryID, filterValues); |
203 if (this.descibeData == null){ | 208 this.purifyResult(result); |
204 this.descibeData = new ArrayList<Object>(); | |
205 } | |
206 this.descibeData.add(result); | |
207 } catch (QueryException e) { | 209 } catch (QueryException e) { |
208 log.error(e,e); | 210 log.error(e,e); |
209 throw new TransitionException(e); | 211 throw new TransitionException(e); |
210 } | 212 } |
211 } | 213 } |
214 | |
215 /** | |
216 * @param result | |
217 */ | |
218 protected void purifyResult(Collection<Result> result) { | |
219 if (this.descibeData == null){ | |
220 this.descibeData = new ArrayList<Object>(); | |
221 } | |
222 this.descibeData.add(result); | |
223 } | |
212 | 224 |
213 /** | 225 /** |
214 * @see de.intevation.gnv.transition.Transition#describe(org.w3c.dom.Document, org.w3c.dom.Node) | 226 * @see de.intevation.gnv.transition.Transition#describe(org.w3c.dom.Document, org.w3c.dom.Node) |
215 */ | 227 */ |
216 public void describe(Document document, Node rootNode) { | 228 public void describe(Document document, Node rootNode) { |
217 | 229 |
218 if(this.descibeData != null){ | 230 if(this.descibeData != null){ |
219 Iterator<Object> it = this.descibeData.iterator(); | 231 Iterator<Object> it = this.descibeData.iterator(); |
220 while (it.hasNext()){ | 232 while (it.hasNext()){ |
221 Element selectNode = this.createXFormElement(document,"select"); | |
222 // TODO: HACK: | |
223 // BESSERE LÖSUNG FINDEN | |
224 Object[] names = this.inputValueNames.toArray(); | |
225 String name = names[names.length-1].toString(); | |
226 | |
227 selectNode.setAttribute("ref", name); | |
228 | |
229 Element lableNode = this.createXFormElement(document, "label"); | |
230 lableNode.setTextContent(name); | |
231 Element choiceNode = this.createXFormElement(document, "choices"); | |
232 | |
233 | |
234 Object o = it.next(); | 233 Object o = it.next(); |
235 if (o instanceof Collection<?>){ | 234 if (o instanceof Collection<?>){ |
235 Element selectNode = this.createXFormElement(document,"select"); | |
236 // TODO: HACK: | |
237 // BESSERE LÖSUNG FINDEN | |
238 Object[] names = this.inputValueNames.toArray(); | |
239 String name = names[names.length-1].toString(); | |
240 | |
241 selectNode.setAttribute("ref", name); | |
242 | |
243 Element lableNode = this.createXFormElement(document, "label"); | |
244 lableNode.setTextContent(name); | |
245 Element choiceNode = this.createXFormElement(document, "choices"); | |
246 | |
236 Collection<Result> values = (Collection)o; | 247 Collection<Result> values = (Collection)o; |
237 Iterator<Result> resultIt = values.iterator(); | 248 Iterator<Result> resultIt = values.iterator(); |
238 while (resultIt.hasNext()){ | 249 while (resultIt.hasNext()){ |
239 Result result = resultIt.next(); | 250 Result result = resultIt.next(); |
240 Element itemNode = this.createXFormElement(document, "item"); | 251 Element itemNode = this.createXFormElement(document, "item"); |
241 String lableName = result.getResultDescriptor().getColumnName(1); | 252 |
242 String valueName = result.getResultDescriptor().getColumnName(0); | |
243 | 253 |
244 Element choiceLableNode = this.createXFormElement(document, "label"); | 254 Element choiceLableNode = this.createXFormElement(document, "label"); |
245 choiceLableNode.setTextContent(result.getString(lableName)); | 255 choiceLableNode.setTextContent(result.getString("VALUE")); |
246 itemNode.appendChild(choiceLableNode); | 256 itemNode.appendChild(choiceLableNode); |
247 | 257 |
248 Element choicValueNode = this.createXFormElement(document, "value"); | 258 Element choicValueNode = this.createXFormElement(document, "value"); |
249 choicValueNode.setTextContent(result.getString(valueName)); | 259 choicValueNode.setTextContent(result.getString("KEY")); |
250 itemNode.appendChild(choicValueNode); | 260 itemNode.appendChild(choicValueNode); |
251 | 261 |
252 choiceNode.appendChild(itemNode); | 262 choiceNode.appendChild(itemNode); |
253 } | 263 } |
264 selectNode.appendChild(lableNode); | |
265 selectNode.appendChild(choiceNode); | |
266 rootNode.appendChild(selectNode); | |
267 }else if (o instanceof MinMaxDescribeData){ | |
268 MinMaxDescribeData descibeData = (MinMaxDescribeData)o; | |
269 Object min = descibeData.getMinValue(); | |
270 Object max = descibeData.getMaxValue(); | |
271 if (min instanceof GregorianCalendar){ | |
272 Date d = ((GregorianCalendar)min).getTime(); | |
273 min = DateUtils.getPatternedDateGerm(d); | |
274 } | |
275 | |
276 if (max instanceof GregorianCalendar){ | |
277 Date d = ((GregorianCalendar)max).getTime(); | |
278 max = DateUtils.getPatternedDateGerm(d); | |
279 } | |
280 | |
281 Element inputMinNode = this.createXFormElement(document, "input"); | |
282 inputMinNode.setAttribute("ref", "minvalue"); | |
283 Element inputMinLableNode = this.createXFormElement(document, "label"); | |
284 inputMinLableNode.setTextContent("minvalue"); | |
285 inputMinNode.appendChild(inputMinLableNode); | |
286 | |
287 Element inputMinValueNode = this.createXFormElement(document, "value"); | |
288 inputMinValueNode.setTextContent(min.toString()); | |
289 inputMinNode.appendChild(inputMinValueNode); | |
290 | |
291 Element inputMaxNode = this.createXFormElement(document, "input"); | |
292 inputMaxNode.setAttribute("ref", "maxvalue"); | |
293 Element inputMaxLableNode = this.createXFormElement(document, "label"); | |
294 inputMaxLableNode.setTextContent("maxvalue"); | |
295 inputMaxNode.appendChild(inputMaxLableNode); | |
296 | |
297 Element inputMaxValueNode = this.createXFormElement(document, "value"); | |
298 inputMaxValueNode.setTextContent(max.toString()); | |
299 inputMaxNode.appendChild(inputMaxValueNode); | |
300 | |
301 rootNode.appendChild(inputMinNode); | |
302 rootNode.appendChild(inputMaxNode); | |
303 | |
254 } | 304 } |
255 selectNode.appendChild(lableNode); | 305 |
256 selectNode.appendChild(choiceNode); | |
257 rootNode.appendChild(selectNode); | |
258 } | 306 } |
259 } | 307 } |
260 | 308 |
261 } | 309 } |
262 | 310 |