dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39277
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19908: use ValueType for ValidationUtils
------------------------------------------------------------
revno: 19908
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-08-31 16:10:26 +0700
message:
use ValueType for ValidationUtils
modified:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2015-07-12 15:01:19 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2015-08-31 09:10:26 +0000
@@ -28,34 +28,22 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_BOOL;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_DATE;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_DATETIME;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_NEGATIVE_INT;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_NUMBER;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_PERCENTAGE;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_POSITIVE_INT;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_TRUE_ONLY;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_UNIT_INTERVAL;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_ZERO_OR_POSITIVE_INT;
-
-import java.awt.geom.Point2D;
-import java.util.Locale;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
+import com.google.common.collect.Sets;
import org.apache.commons.validator.routines.DateValidator;
import org.apache.commons.validator.routines.EmailValidator;
import org.apache.commons.validator.routines.UrlValidator;
+import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.commons.util.TextUtils;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.datavalue.DataValue;
-import com.google.common.collect.Sets;
+import java.awt.geom.Point2D;
+import java.util.Locale;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static org.hisp.dhis.dataelement.DataElement.*;
/**
* @author Lars Helge Overland
@@ -73,17 +61,17 @@
private static int LAT_MAX = 90;
private static int LAT_MIN = -90;
- private static final Set<Character> SQL_VALID_CHARS = Sets.newHashSet(
+ private static final Set<Character> SQL_VALID_CHARS = Sets.newHashSet(
'&', '|', '=', '!', '<', '>', '/', '%', '"', '\'', '*', '+', '-', '^', ',', '.' );
- public static final Set<String> ILLEGAL_SQL_KEYWORDS = Sets.newHashSet( "alter", "before", "case",
- "commit", "copy", "create", "createdb", "createrole", "createuser", "close", "delete", "destroy", "drop",
+ public static final Set<String> ILLEGAL_SQL_KEYWORDS = Sets.newHashSet( "alter", "before", "case",
+ "commit", "copy", "create", "createdb", "createrole", "createuser", "close", "delete", "destroy", "drop",
"escape", "insert", "select", "rename", "replace", "restore", "return", "update", "when", "write" );
-
+
/**
- * Validates whether a filter expression contains malicious code such as SQL
+ * Validates whether a filter expression contains malicious code such as SQL
* injection attempts.
- *
+ *
* @param filter the filter string.
* @return true if the filter string is valid, false otherwise.
*/
@@ -98,20 +86,20 @@
{
return false;
}
-
- for ( int i = 0; i < filter.length(); i++ )
+
+ for ( int i = 0; i < filter.length(); i++ )
{
char ch = filter.charAt( i );
-
- if ( !( Character.isWhitespace( ch ) || Character.isLetterOrDigit( ch ) || SQL_VALID_CHARS.contains( ch ) ) )
+
+ if ( !(Character.isWhitespace( ch ) || Character.isLetterOrDigit( ch ) || SQL_VALID_CHARS.contains( ch )) )
{
return false;
}
}
-
+
return true;
}
-
+
/**
* Validates whether an email string is valid.
*
@@ -159,7 +147,7 @@
/**
* Validates whether a password is valid. A password must:
- * <p/>
+ * <p>
* <ul>
* <li>Be between 8 and 80 characters long</li>
* <li>Include at least one digit</li>
@@ -295,7 +283,7 @@
* given data element. Considers the value to be valid if null or empty.
* Returns a string if the valid is invalid, possible
* values are:
- * <p/>
+ * <p>
* <ul>
* <li>data_element_or_type_null_or_empty</li>
* <li>value_length_greater_than_max_length</li>
@@ -326,64 +314,64 @@
return "data_element_or_type_null_or_empty";
}
- String type = dataElement.getDetailedNumberType();
+ ValueType valueType = dataElement.getValueType();
if ( value.length() > VALUE_MAX_LENGTH )
{
return "value_length_greater_than_max_length";
}
- if ( VALUE_TYPE_NUMBER.equals( type ) && !MathUtils.isNumeric( value ) )
+ if ( ValueType.NUMBER == valueType && !MathUtils.isNumeric( value ) )
{
return "value_not_numeric";
}
- if ( VALUE_TYPE_UNIT_INTERVAL.equals( type ) && !MathUtils.isUnitInterval( value ) )
+ if ( ValueType.UNIT_INTERVAL == valueType && !MathUtils.isUnitInterval( value ) )
{
return "value_not_unit_interval";
}
- if ( VALUE_TYPE_PERCENTAGE.equals( type ) && !MathUtils.isPercentage( value ) )
+ if ( ValueType.PERCENTAGE == valueType && !MathUtils.isPercentage( value ) )
{
return "value_not_percentage";
}
- if ( VALUE_TYPE_INT.equals( type ) && !MathUtils.isInteger( value ) )
+ if ( ValueType.INTEGER == valueType && !MathUtils.isInteger( value ) )
{
return "value_not_integer";
}
- if ( VALUE_TYPE_POSITIVE_INT.equals( type ) && !MathUtils.isPositiveInteger( value ) )
+ if ( ValueType.INTEGER_POSITIVE == valueType && !MathUtils.isPositiveInteger( value ) )
{
return "value_not_positive_integer";
}
- if ( VALUE_TYPE_NEGATIVE_INT.equals( type ) && !MathUtils.isNegativeInteger( value ) )
+ if ( ValueType.INTEGER_NEGATIVE == valueType && !MathUtils.isNegativeInteger( value ) )
{
return "value_not_negative_integer";
}
- if ( VALUE_TYPE_ZERO_OR_POSITIVE_INT.equals( type ) && !MathUtils.isZeroOrPositiveInteger( value ) )
+ if ( ValueType.INTEGER_ZERO_OR_POSITIVE == valueType && !MathUtils.isZeroOrPositiveInteger( value ) )
{
return "value_not_zero_or_positive_integer";
}
- if ( VALUE_TYPE_BOOL.equals( type ) && !MathUtils.isBool( value ) )
+ if ( ValueType.BOOLEAN == valueType && !MathUtils.isBool( value ) )
{
return "value_not_bool";
}
- if ( VALUE_TYPE_TRUE_ONLY.equals( type ) && !DataValue.TRUE.equals( value ) )
+ if ( ValueType.TRUE_ONLY == valueType && !DataValue.TRUE.equals( value ) )
{
return "value_not_true_only";
}
- if ( VALUE_TYPE_DATE.equals( type ) && !DateUtils.dateIsValid( value ) )
+ if ( ValueType.DATE == valueType && !DateUtils.dateIsValid( value ) )
{
return "value_not_valid_date";
}
- if ( VALUE_TYPE_DATETIME.equals( type ) && !DateUtils.dateTimeIsValid( value ) )
+ if ( ValueType.DATETIME == valueType && !DateUtils.dateTimeIsValid( value ) )
{
return "value_not_valid_datetime";
}
@@ -449,12 +437,12 @@
{
return null;
}
-
+
if ( storedBy.length() > 31 )
{
return "stored_by_length_greater_than_max_length";
}
-
+
return null;
}