Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/state/SingleInputState.java @ 1066:bf9e95141ce0
Added vector support for timeseries points on meshes.
gnv-artifacts/trunk@1160 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 07 Jun 2010 08:26:37 +0000 |
parents | 9981452c7e75 |
children | f953c9a559d8 |
rev | line source |
---|---|
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.state; |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
2 |
860
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
3 import de.intevation.artifacts.CallContext; |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
4 |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
5 import de.intevation.gnv.artifacts.ressource.RessourceFactory; |
779
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
6 import de.intevation.gnv.geobackend.base.Result; |
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
7 import de.intevation.gnv.state.describedata.DefaultSingleValueDescribeData; |
860
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
8 import de.intevation.gnv.state.exception.StateException; |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
9 import de.intevation.gnv.utils.InputValidator; |
779
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
10 |
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
11 import java.util.ArrayList; |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
12 import java.util.Collection; |
860
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
13 import java.util.Iterator; |
470
b7bb66440cc8
Added mechanism for advancing to previous states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
335
diff
changeset
|
14 import java.util.List; |
860
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
15 import java.util.Locale; |
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
16 |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
17 import org.apache.log4j.Logger; |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
18 |
860
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
19 import org.w3c.dom.Document; |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
20 |
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
21 /** |
796
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
22 * This state handles single user input. The user is allowed to select just one |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
23 * value. |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
24 * |
780
c4156275c1e1
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
779
diff
changeset
|
25 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
607
diff
changeset
|
26 * |
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
27 */ |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
28 public class SingleInputState extends StateBase { |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
29 |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
30 /** |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
31 * the logger, used to log exceptions and additonaly information |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
32 */ |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
33 private static Logger log = Logger.getLogger(SingleInputState.class); |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
34 |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
35 private static final long serialVersionUID = -6169497306324917318L; |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
36 |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
37 /** |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
38 * Constructor |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
39 */ |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
40 public SingleInputState() { |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
41 } |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
42 |
815
22c18083225e
Removed compiler warnings while JavaDoc generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
796
diff
changeset
|
43 |
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
44 @Override |
607
292fbcd5e9ac
Parted the cache blob into pieces and changed the way how user input is stored on each state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
473
diff
changeset
|
45 protected List<Object> purifyResult(Collection<Result> result, String uuid) { |
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
46 log.debug("SingleInputState.purifyResult"); |
607
292fbcd5e9ac
Parted the cache blob into pieces and changed the way how user input is stored on each state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
473
diff
changeset
|
47 List<Object> describeData = new ArrayList<Object>(); |
292fbcd5e9ac
Parted the cache blob into pieces and changed the way how user input is stored on each state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
473
diff
changeset
|
48 |
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
49 String value = null; |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
50 if (result != null && result.size() == 1) { |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
51 Result tmpItem = result.iterator().next(); |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
52 value = tmpItem.getObject("MAX").toString(); |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
53 } else { |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
54 value = ""; |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
55 } |
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
56 |
473
a6a33ef35809
Added support to step back to previous states. Add state names to xform nodes in describe document and append old targets to list of reachable targets.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
470
diff
changeset
|
57 describeData.add(new DefaultSingleValueDescribeData( |
a6a33ef35809
Added support to step back to previous states. Add state names to xform nodes in describe document and append old targets to list of reachable targets.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
470
diff
changeset
|
58 this.dataName, value, getID())); |
607
292fbcd5e9ac
Parted the cache blob into pieces and changed the way how user input is stored on each state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
473
diff
changeset
|
59 |
292fbcd5e9ac
Parted the cache blob into pieces and changed the way how user input is stored on each state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
473
diff
changeset
|
60 return describeData; |
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
61 } |
860
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
62 |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
63 /** |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
64 * This feed method needs a collection of two InputData objects. These |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
65 * objects' values need to be a datetime string which is turned into a Date |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
66 * object. Afterwards, the given dates are validated. Min and max date need |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
67 * to be in range of the min and max date retrieved by |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
68 * {@link #getDescibeData(java.lang.String)}. |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
69 */ |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
70 @Override |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
71 public Document feed( |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
72 CallContext context, |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
73 Collection<InputData> inputData, |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
74 String uuid) |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
75 throws StateException { |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
76 RessourceFactory resFactory = RessourceFactory.getInstance(); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
77 Locale[] serverLocales = resFactory.getLocales(); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
78 Locale locale = context.getMeta().getPreferredLocale( |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
79 serverLocales); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
80 |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
81 if (inputData == null) { |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
82 String msg = "No input data given."; |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
83 log.warn(msg); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
84 return feedFailure(msg); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
85 } |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
86 |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
87 Iterator<InputData> it = inputData.iterator(); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
88 InputData tmpItem = it.next(); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
89 InputValue inputValue = inputValues.get(tmpItem.getName()); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
90 |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
91 if (inputValue == null) { |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
92 String msg = resFactory.getRessource( |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
93 locale, |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
94 EXCEPTION_INVALID_INPUT, |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
95 EXCEPTION_INVALID_INPUT); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
96 log.warn(msg); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
97 return feedFailure(msg); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
98 } |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
99 |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
100 boolean valid = InputValidator.isInputValid( |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
101 tmpItem.getValue(), inputValue.getType()); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
102 |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
103 if (valid) { |
1038
9981452c7e75
First step: Added a new state handling the selection between vector or scalar and a new transition in timeseries to provide vector values (issue27).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
860
diff
changeset
|
104 String[] desc = getDescriptionForInputData(tmpItem, context, uuid); |
860
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
105 tmpItem.setDescription(desc); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
106 |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
107 this.inputData.put(tmpItem.getName(), tmpItem); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
108 return feedSuccess(); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
109 } |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
110 |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
111 else { |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
112 String msg = resFactory.getRessource( |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
113 locale, |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
114 EXCEPTION_INVALID_INPUT, |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
115 EXCEPTION_INVALID_INPUT); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
116 log.warn(msg); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
117 return feedFailure(msg); |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
118 } |
f94a95009423
Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
119 } |
335
e964a3d8f7bc
Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
120 } |
836
05bf8534a35a
Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
815
diff
changeset
|
121 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |