annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 788:e8a9e84a0328

Corrected JavaDoc errors in Chart Package. gnv-artifacts/trunk@870 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 31 Mar 2010 08:01:56 +0000
parents 6cd8492019d8
children feae2f9d6c6f
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
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
31
222
3e82b4f1c455 Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents: 173
diff changeset
32 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
33
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
34 /**
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
35 * Constructor
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
36 */
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
37 public InputValidator() {
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
38 super();
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
39 }
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
40
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
41 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
42 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
43 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
44 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
45 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
46 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
47 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
48 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
49 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
50 } 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
51 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
52 }
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
53 } 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
54 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
55 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
56 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
57 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
58 } 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
59 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
60 }
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 }
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 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
63 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
64 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
65
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
66 public static boolean isInputValid(String input, String type) {
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
67 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
68
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
69 // Let's check polygons and linestrings first, because they might
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
70 // 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
71 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
72 {
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
73 try {
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
74 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
75 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
76
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
77 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
78 }
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
79 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
80 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
81 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
82 }
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
83 }
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
84
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
85 // 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
86 boolean returnValue = false;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
87 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
88
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
89 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
90 boolean valid;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
91
222
3e82b4f1c455 Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents: 173
diff changeset
92 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
93 valid = true;
3e82b4f1c455 Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents: 173
diff changeset
94 } else if ("Integer".equalsIgnoreCase(type)) {
115
158e89c2263b Removed needless imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 113
diff changeset
95 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
96 } 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
97 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
98 } 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
99 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
100 // FIXME:
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
101 // VALIDATE
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
102 // REGEXP
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
103 } 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
104 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
105 DateUtils.DATE_PATTERN, true);
731
1efb6a66c7d9 Added Objecttype Geometry for the Validation of Inputdata.
Tim Englich <tim.englich@intevation.de>
parents: 461
diff changeset
106 } 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
107 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
108 // FIXME:
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
109 // VALIDATE
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
110 // REGEXP
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
111 } 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
112 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
113 .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
114 // VALIDATE
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
115 // REGEXP
173
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
116 } else if ("Coordinate".equalsIgnoreCase(type)) {
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
117 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
118 valid = getPointValue(values[i]) != null;
173
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
119 } catch (ValidationException e) {
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
120 log.debug(e.getMessage());
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
121 valid = false;
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
122 }
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
123 } else {
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
124 valid = false;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
125 }
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
126 if (!valid) {
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
127 returnValue = false;
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
128 break;
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
129 } else {
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
130 returnValue = true;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
131 }
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
132 }
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
133 log.debug("Is valid? " + returnValue);
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
134 return returnValue;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
135 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
136
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
137
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
138 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
139 log.debug("InputValidator.getPointValue " + value);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
140
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
141 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
142 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
143 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
144 } 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
145 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
146 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
147 }
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
148 }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
149 String[] s, p;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
150
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
151 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
152 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
153 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
154 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
155 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
156 }
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
157 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
158 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
159 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
160 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
161 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
162 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
163 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
164 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
165 }
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
166 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
167 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
168
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
169 }
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
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 }
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 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
180 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
181 }
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
182 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
183 }
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
184 }
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
185
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
186
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
187 public static boolean isDateValid(Date tmp, Date lo, Date up) {
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
188 // we need to transform the given dates into seconds, because
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
189 // they differ in milliseconds -> that's why we cannot use the
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
190 // Date.compareTo(Date) method.
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
191 long tmpTime = tmp.getTime() / 1000;
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
192 long tmpLow = lo.getTime() / 1000;
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
193 long tmpUp = up.getTime() / 1000;
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
194
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
195 if (tmpTime < tmpLow || tmpTime > tmpUp) {
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
196 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
197 "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
198 + 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
199 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
200 }
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
201
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
202 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
203 }
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
204 }

http://dive4elements.wald.intevation.org