annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 1051:8f836fb6f592

Introduced an epsilon (750ms) to be more tolerant while comparing two data objects (issue286). gnv-artifacts/trunk@1125 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 25 May 2010 17:46:28 +0000
parents f94a95009423
children 46cc1ab1ee15
rev   line source
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.utils;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
2
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
3 import com.vividsolutions.jts.geom.Coordinate;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
4 import com.vividsolutions.jts.geom.GeometryFactory;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
5 import com.vividsolutions.jts.geom.Point;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
6
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
7 import com.vividsolutions.jts.io.ParseException;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
8 import com.vividsolutions.jts.io.WKTReader;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
9
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
10 import de.intevation.gnv.geobackend.util.DateUtils;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
11
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
12 import de.intevation.gnv.utils.exception.ValidationException;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
13
252
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
14 import java.util.Date;
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
15
116
820238357bab Added Horizontal-Profile-Support for Meshes.
Tim Englich <tim.englich@intevation.de>
parents: 115
diff changeset
16 import org.apache.commons.validator.GenericValidator;
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
17
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
18 import org.apache.log4j.Logger;
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
19
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
20 /**
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
21 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
785
e764cab8c885 Save the relation between selected measurement and the parameter it belongs to (issue210). TODO: Adapt sql statements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 784
diff changeset
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
23 *
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
24 */
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
25 public class InputValidator {
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
26 /**
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
27 * the logger, used to log exceptions and additonaly information
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
28 */
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
29 private static Logger log = Logger.getLogger(InputValidator.class);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
30
1051
8f836fb6f592 Introduced an epsilon (750ms) to be more tolerant while comparing two data objects (issue286).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 860
diff changeset
31 /**
8f836fb6f592 Introduced an epsilon (750ms) to be more tolerant while comparing two data objects (issue286).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 860
diff changeset
32 * Epsilon for handling unprecise date objects (in ms).
8f836fb6f592 Introduced an epsilon (750ms) to be more tolerant while comparing two data objects (issue286).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 860
diff changeset
33 */
8f836fb6f592 Introduced an epsilon (750ms) to be more tolerant while comparing two data objects (issue286).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 860
diff changeset
34 public final static long DATE_EPSILON = 750;
8f836fb6f592 Introduced an epsilon (750ms) to be more tolerant while comparing two data objects (issue286).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 860
diff changeset
35
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
36
222
3e82b4f1c455 Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents: 173
diff changeset
37 public final static String NODATASELECTEDVALUE = "n/n";
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
38
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
39 /**
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
40 * Constructor
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
41 */
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
42 public InputValidator() {
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
43 super();
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
44 }
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
45
806
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
46 /**
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
47 * Validates the input of a range of double or date values. The input values
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
48 * need to be valid double or date values. <i>minInput</i> needs to be
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
49 * smaller or equal <i>maxInput</i>.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
50 *
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
51 * @param minInput The lower bound.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
52 * @param maxInput The upper bound.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
53 * @param type One of 'Date' or 'Double'.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
54 * @return true, if the input is valid, otherwise false.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
55 */
785
e764cab8c885 Save the relation between selected measurement and the parameter it belongs to (issue210). TODO: Adapt sql statements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 784
diff changeset
56 public static boolean isInputValid(String minInput, String maxInput, String type) {
252
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
57 log.debug("InputValidator.isInputValid " + minInput + " " + maxInput + " " +type);
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
58 boolean returnValue = false;
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
59 if ("Date".equalsIgnoreCase(type)) {
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
60 try {
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
61 Date min = DateUtils.getDateFromString(minInput,DateUtils.DATE_PATTERN);
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
62 Date max = DateUtils.getDateFromString(maxInput,DateUtils.DATE_PATTERN);
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
63 int value = max.compareTo(min);
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
64 returnValue = value >= 0;
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
65 } catch (Exception e) {
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
66 log.error(e,e);
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
67 }
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
68 } else if ("Double".equalsIgnoreCase(type)) {
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
69 try {
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
70 double min = Double.parseDouble(minInput);
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
71 double max = Double.parseDouble(maxInput);
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
72 returnValue = max >= min;
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
73 } catch (Exception e) {
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
74 log.error(e,e);
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
75 }
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
76 }
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
77 log.debug("Is valid? " + returnValue);
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
78 return returnValue;
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
79 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
80
806
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
81 /**
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
82 * Validates an input.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
83 *
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
84 * @param input The input value.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
85 * @param type The input value type.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
86 * @return true if the input is valid, otherwise false.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
87 */
785
e764cab8c885 Save the relation between selected measurement and the parameter it belongs to (issue210). TODO: Adapt sql statements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 784
diff changeset
88 public static boolean isInputValid(String input, String type) {
860
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
89 if (input.length() == 0 || input.equals("")) {
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
90 return false;
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
91 }
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
92
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
93 log.debug("InputValidator.isInputValid " + input + " " + type);
787
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
94
803
feae2f9d6c6f Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
95 // Let's check polygons and linestrings first, because they might
787
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
96 // contain comma. A splitting at comma characters wouldn't be good here.
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
97 if ("Polygon".equalsIgnoreCase(type) || "Linestring".equalsIgnoreCase(type))
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
98 {
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
99 try {
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
100 WKTReader reader = new WKTReader();
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
101 reader.read(input);
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
102
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
103 return true;
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
104 }
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
105 catch (ParseException pe) {
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
106 log.warn(pe, pe);
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
107 return false;
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
108 }
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
109 }
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
110
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
111 // Check all the other input here
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
112 boolean returnValue = false;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
113 String[] values = input.split(",");
787
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
114
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
115 for (int i = 0; i < values.length; i++) {
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
116 boolean valid;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
117
222
3e82b4f1c455 Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents: 173
diff changeset
118 if (NODATASELECTEDVALUE.equals(values[i].trim())){
3e82b4f1c455 Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents: 173
diff changeset
119 valid = true;
3e82b4f1c455 Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents: 173
diff changeset
120 } else if ("Integer".equalsIgnoreCase(type)) {
115
158e89c2263b Removed needless imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 113
diff changeset
121 valid = GenericValidator.isInt(values[i].trim());
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
122 } else if ("Double".equalsIgnoreCase(type)) {
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
123 valid = GenericValidator.isDouble(values[i].trim());
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
124 } else if ("String".equalsIgnoreCase(type)) {
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
125 valid = GenericValidator.matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO:
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
126 // FIXME:
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
127 // VALIDATE
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
128 // REGEXP
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
129 } else if ("Date".equalsIgnoreCase(type)) {
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
130 valid = GenericValidator.isDate(values[i].trim(),
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
131 DateUtils.DATE_PATTERN, true);
731
1efb6a66c7d9 Added Objecttype Geometry for the Validation of Inputdata.
Tim Englich <tim.englich@intevation.de>
parents: 461
diff changeset
132 } else if ("Point".equalsIgnoreCase(type) || "Geometry".equals(type)) {
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
133 valid = GenericValidator.matchRegexp(values[i], "[0-9]"); // TODO:
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
134 // FIXME:
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
135 // VALIDATE
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
136 // REGEXP
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
137 } else if ("AttributeName".equalsIgnoreCase(type)) {
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
138 valid = org.apache.commons.validator.GenericValidator
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
139 .matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO: FIXME:
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
140 // VALIDATE
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
141 // REGEXP
173
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
142 } else if ("Coordinate".equalsIgnoreCase(type)) {
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
143 try {
785
e764cab8c885 Save the relation between selected measurement and the parameter it belongs to (issue210). TODO: Adapt sql statements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 784
diff changeset
144 valid = getPointValue(values[i]) != null;
173
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
145 } catch (ValidationException e) {
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
146 log.debug(e.getMessage());
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
147 valid = false;
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
148 }
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
149 } else {
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
150 valid = false;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
151 }
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
152 if (!valid) {
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
153 returnValue = false;
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
154 break;
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
155 } else {
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
156 returnValue = true;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
157 }
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
158 }
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
159 log.debug("Is valid? " + returnValue);
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
160 return returnValue;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
161 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
162
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
163
806
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
164 /**
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
165 * Returns a point from wkt string.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
166 *
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
167 * @param value The wkt string.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
168 * @return a point.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
169 * @throws ValidationException if <i>value</i> is not valid.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
170 */
785
e764cab8c885 Save the relation between selected measurement and the parameter it belongs to (issue210). TODO: Adapt sql statements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 784
diff changeset
171 public static Point getPointValue(String value) throws ValidationException{
173
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
172 log.debug("InputValidator.getPointValue " + value);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
173
746
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
174 if (value.toLowerCase().startsWith("point")){
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
175 try {
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
176 return (Point)new WKTReader().read(value);
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
177 } catch (ParseException e) {
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
178 log.error(e,e);
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
179 throw new ValidationException(e);
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
180 }
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
181 }else{
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
182 String[] s, p;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
183
746
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
184 double x=0,y=0;
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
185 log.info("Position :"+value);
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
186 s = value.split(" ");
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
187 if (s.length != 2) {
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
188 throw new ValidationException("Kein Blank separiert Breite und Länge");
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
189 }
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
190 p = s[0].split("[nNsS]");
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
191 try {
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
192 if (p.length == 1)
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
193 y = new Double(p[0]);
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
194 else
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
195 y = new Double(p[0]) + new Double(p[1]) / new Double(60.);
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
196 if (s[0].toLowerCase().contains("s"))
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
197 y = -y;
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
198 }
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
199 catch (Exception e) {
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
200 throw new ValidationException("Kein N|S oder nicht im ersten Substring, zB 56n42");
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
201
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
202 }
746
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
203 p = s[1].split("[eEwW]");
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
204 try {
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
205 if (p.length ==1)
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
206 x = new Double(p[0]);
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
207 else
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
208 x = new Double(p[0]) + new Double(p[1]) / new Double(60.) ;
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
209 if (s[1].toLowerCase().contains("w"))
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
210 x = -x;
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
211 }
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
212 catch (Exception e) {
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
213 throw new ValidationException("Kein E|W oder nicht im zweiten Substring");
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
214 }
746
b81f6f896668 Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents: 731
diff changeset
215 return new GeometryFactory().createPoint(new Coordinate(x,y));
173
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
216 }
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
217 }
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
218
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
219
806
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
220 /**
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
221 * Makes sure that <i>tmp</i> is between <i>lo</i> and <i>up</i>.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
222 *
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
223 * @param tmp The value to validate.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
224 * @param lo The lower range bound.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
225 * @param up The upper range bound.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
226 * @return true, if tmp is valid, otherwise false.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
227 */
785
e764cab8c885 Save the relation between selected measurement and the parameter it belongs to (issue210). TODO: Adapt sql statements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 784
diff changeset
228 public static boolean isDateValid(Date tmp, Date lo, Date up) {
1051
8f836fb6f592 Introduced an epsilon (750ms) to be more tolerant while comparing two data objects (issue286).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 860
diff changeset
229 long tmpTime = tmp.getTime();
8f836fb6f592 Introduced an epsilon (750ms) to be more tolerant while comparing two data objects (issue286).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 860
diff changeset
230 long tmpLow = lo.getTime();
8f836fb6f592 Introduced an epsilon (750ms) to be more tolerant while comparing two data objects (issue286).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 860
diff changeset
231 long tmpUp = up.getTime();
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
232
1051
8f836fb6f592 Introduced an epsilon (750ms) to be more tolerant while comparing two data objects (issue286).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 860
diff changeset
233 if (tmpTime < tmpLow - DATE_EPSILON || tmpTime > tmpUp + DATE_EPSILON) {
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
234 log.warn(
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
235 "Date [" + tmp.toString() + "] is 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
236 + lo.toString() + " to "+ up.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
237 return false;
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
238 }
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
239
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
240 return true;
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
241 }
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
242 }
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 806
diff changeset
243 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org