Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxDateState.java @ 857:482317922c8b
Added a very simple wrapper to export the mapfile path for MapServer (issue220).
gnv-artifacts/trunk@975 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 23 Apr 2010 13:16:30 +0000 |
parents | 499cfbbb61bc |
children | f953c9a559d8 |
rev | line source |
---|---|
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.state; |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.util.Collection; |
784
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
4 import java.util.Date; |
823
499cfbbb61bc
Removed obsolet SuppressWarnings-Annotations.
Tim Englich <tim.englich@intevation.de>
parents:
796
diff
changeset
|
5 import java.util.GregorianCalendar; |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import java.util.Iterator; |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import java.util.Locale; |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import org.apache.log4j.Logger; |
823
499cfbbb61bc
Removed obsolet SuppressWarnings-Annotations.
Tim Englich <tim.englich@intevation.de>
parents:
796
diff
changeset
|
10 import org.w3c.dom.Document; |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 |
823
499cfbbb61bc
Removed obsolet SuppressWarnings-Annotations.
Tim Englich <tim.englich@intevation.de>
parents:
796
diff
changeset
|
12 import de.intevation.artifacts.CallContext; |
499cfbbb61bc
Removed obsolet SuppressWarnings-Annotations.
Tim Englich <tim.englich@intevation.de>
parents:
796
diff
changeset
|
13 import de.intevation.gnv.artifacts.ressource.RessourceFactory; |
499cfbbb61bc
Removed obsolet SuppressWarnings-Annotations.
Tim Englich <tim.englich@intevation.de>
parents:
796
diff
changeset
|
14 import de.intevation.gnv.geobackend.util.DateUtils; |
499cfbbb61bc
Removed obsolet SuppressWarnings-Annotations.
Tim Englich <tim.englich@intevation.de>
parents:
796
diff
changeset
|
15 import de.intevation.gnv.state.describedata.DefaultMinMaxDescribeData; |
499cfbbb61bc
Removed obsolet SuppressWarnings-Annotations.
Tim Englich <tim.englich@intevation.de>
parents:
796
diff
changeset
|
16 import de.intevation.gnv.state.describedata.DescribeData; |
499cfbbb61bc
Removed obsolet SuppressWarnings-Annotations.
Tim Englich <tim.englich@intevation.de>
parents:
796
diff
changeset
|
17 import de.intevation.gnv.state.describedata.MinMaxDescribeData; |
499cfbbb61bc
Removed obsolet SuppressWarnings-Annotations.
Tim Englich <tim.englich@intevation.de>
parents:
796
diff
changeset
|
18 import de.intevation.gnv.state.exception.StateException; |
499cfbbb61bc
Removed obsolet SuppressWarnings-Annotations.
Tim Englich <tim.englich@intevation.de>
parents:
796
diff
changeset
|
19 import de.intevation.gnv.utils.InputValidator; |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 /** |
796
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
22 * This state handles date input. The resulting describe document of this state |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
23 * contains two fields in the user interface description to define a time range. |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
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:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 */ |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 public class MinMaxDateState extends MinMaxState { |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 |
796
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
30 /** |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
31 * |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
32 */ |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 public static final String EXCEPTION_DATE_REQUIRED = |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 "input.is.not.valid.date.required"; |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 |
796
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
36 /** |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
37 * |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
38 */ |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 public static final String EXCEPTION_START_AFTER_END = |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 "start.date.after.end.date"; |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 |
796
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
42 /** |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
43 * |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
44 */ |
784
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
45 public static final String EXCEPTION_DATE_OUT_OF_RANGE = |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
46 "date.out.of.range"; |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
47 |
796
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
48 /** |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
49 * |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
50 */ |
784
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
51 public static final String EXCEPTION_MISSING_DATE = |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
52 "missing.data.field"; |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
53 |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 private static Logger logger = Logger.getLogger(MinMaxDateState.class); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 |
796
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
57 /** |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
58 * |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
59 */ |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 public MinMaxDateState() { |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 super(); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 } |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 /** |
796
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
66 * This feed method needs a collection of two InputData objects. These |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
67 * objects' values need to be a datetime string which is turned into a Date |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
68 * object. Afterwards, the given dates are validated. Min and max date need |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
69 * to be in range of the min and max date retrieved by |
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
70 * {@link #getDescibeData(java.lang.String)}. |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 */ |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 @Override |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 public Document feed( |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 CallContext context, |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 Collection<InputData> inputData, |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 String uuid) |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 throws StateException { |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 RessourceFactory resFactory = RessourceFactory.getInstance(); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 Locale[] serverLocales = resFactory.getLocales(); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 Locale locale = context.getMeta().getPreferredLocale( |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 serverLocales); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 if (inputData == null) { |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 String msg = "No input data given."; |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 logger.warn(msg); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 return feedFailure(msg); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 } |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 Iterator iter = inputData.iterator(); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 |
784
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
91 MinMaxDescribeData data = |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
92 (MinMaxDescribeData) getDescibeData(uuid).get(0); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
93 Object min = data.getMinValue(); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
94 Object max = data.getMaxValue(); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
95 |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
96 Object tmpMin = null; |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
97 Object tmpMax = null; |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 while (iter.hasNext()) { |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 InputData tmp = (InputData) iter.next(); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 InputValue meta = inputValues.get(tmp.getName()); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 String type = meta.getType(); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 String value = tmp.getValue(); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 String name = tmp.getName(); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 if (meta == null) { |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 String msg = "Input data not expected here. Data will be ignored."; |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 logger.warn(msg); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 return feedFailure(msg); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 } |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
111 |
796
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
112 if (!InputValidator.isInputValid(value, type)) { |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 String msg = resFactory.getRessource( |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 locale, EXCEPTION_DATE_REQUIRED, EXCEPTION_DATE_REQUIRED); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
115 logger.error(msg); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 return feedFailure(msg); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
117 } |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
118 |
784
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
119 Date lower = null; |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
120 if (min instanceof GregorianCalendar) { |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
121 lower = ((GregorianCalendar)min).getTime(); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
122 } |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
123 |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
124 Date upper = null; |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
125 if (max instanceof GregorianCalendar) { |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
126 upper = ((GregorianCalendar)max).getTime(); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
127 } |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
128 |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
129 Date d = null; |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
130 try { |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
131 d = DateUtils.getDateFromString(value,DateUtils.DATE_PATTERN); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
132 } |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
133 catch (Exception e) { |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
134 logger.warn(e, e); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
135 } |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
136 |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
137 if (d == null || lower == null || upper == null) { |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
138 String msg = resFactory.getRessource( |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
139 locale, |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
140 EXCEPTION_MISSING_DATE, |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
141 EXCEPTION_MISSING_DATE); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
142 logger.warn(msg); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
143 } |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
144 else { |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
145 if (logger.isDebugEnabled()) { |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
146 logger.debug("Date to validate: " + d.toString()); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
147 logger.debug("Lower date bound: " + lower.toString()); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
148 logger.debug("Upper date bound: " + upper.toString()); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
149 } |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
150 |
796
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
151 if (!InputValidator.isDateValid(d, lower, upper)) { |
784
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
152 String msg = resFactory.getRessource( |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
153 locale, |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
154 EXCEPTION_DATE_OUT_OF_RANGE, |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
155 EXCEPTION_DATE_OUT_OF_RANGE); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
156 logger.error(msg); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
157 return feedFailure(msg); |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
158 } |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
159 } |
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
160 |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
161 if (name.equals(MINVALUEFIELDNAME)) { |
784
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
162 tmpMin = value; |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
163 } |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
164 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
165 if (name.equals(MAXVALUEFIELDNAME)) { |
784
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
166 tmpMax = value; |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
167 } |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
168 |
784
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
169 if (tmpMin != null && tmpMax != null) { |
796
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
170 if (!InputValidator.isInputValid((String) tmpMin, (String) tmpMax, type)) { |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
171 String msg = resFactory.getRessource( |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
172 locale, |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
173 EXCEPTION_START_AFTER_END, |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
174 EXCEPTION_START_AFTER_END); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
175 logger.error(msg); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
176 return feedFailure(msg); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
177 } |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
178 } |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
179 } |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
180 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
181 DescribeData values = new DefaultMinMaxDescribeData( |
784
7b81d563c8c0
Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
182 dataName, tmpMin, tmpMax, getID()); |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
183 |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
725
diff
changeset
|
184 this.inputData.put(dataName, new DefaultInputData(dataName, values)); |
725
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
185 |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
186 return feedSuccess(); |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
187 } |
dde7f51dbe1e
Improved exception handling while feeding an artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
188 } |
796
a5526908f92f
Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
784
diff
changeset
|
189 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |