ValidationUtils { public static String dataValueIsValid( String value, DataElement dataElement ) { if ( dataElement == null || dataElement.getValueType() == null ) { return "data_element_or_type_null_or_empty"; } return dataValueIsValid( value, dataElement.getValueType() ); }  static boolean expressionIsValidSQl( String filter ); static boolean emailIsValid( String email ); static boolean dateIsValid( String date, Locale locale ); static boolean dateIsValid( String date ); static boolean timeIsValid( String time ); static boolean urlIsValid( String url ); static boolean uuidIsValid( String uuid ); static boolean usernameIsValid( String username ); static boolean passwordIsValid( String password ); static boolean coordinateIsValid( String coordinate ); static boolean bboxIsValid( String bbox ); static String getLongitude( String coordinate ); static String getLatitude( String coordinate ); static Point2D getCoordinatePoint2D( String coordinate ); static String getCoordinate( String longitude, String latitude ); static String dataValueIsValid( String value, DataElement dataElement ); static String dataValueIsValid( String value, ValueType valueType ); static boolean dataValueIsZeroAndInsignificant( String value, DataElement dataElement ); static String commentIsValid( String comment ); static String storedByIsValid( String storedBy ); static boolean isValidHexColor( String value ); static Object getSubstitutionValue( ValueType valueType ); static String normalizeBoolean( String bool, ValueType valueType ); static boolean validateRenderingType( Class<?> clazz, ValueType valueType, boolean optionSet, ValueTypeRenderingType type ); static boolean validateWhatsapp( String whatsapp ); static boolean validateInternationalPhoneNumber( String phoneNumber ); static final ImmutableSet<String> ILLEGAL_SQL_KEYWORDS; }
@Test public void testDataValueIsValid() { DataElement de = new DataElement( "DEA" ); de.setValueType( ValueType.INTEGER ); assertNull( dataValueIsValid( null, de ) ); assertNull( dataValueIsValid( "", de ) ); assertNull( dataValueIsValid( "34", de ) ); assertNotNull( dataValueIsValid( "Yes", de ) ); de.setValueType( ValueType.NUMBER ); assertNull( dataValueIsValid( "3.7", de ) ); assertNotNull( dataValueIsValid( "No", de ) ); de.setValueType( ValueType.INTEGER_POSITIVE ); assertNull( dataValueIsValid( "3", de ) ); assertNotNull( dataValueIsValid( "-4", de ) ); de.setValueType( ValueType.INTEGER_ZERO_OR_POSITIVE ); assertNull( dataValueIsValid( "3", de ) ); assertNotNull( dataValueIsValid( "-4", de ) ); de.setValueType( ValueType.INTEGER_NEGATIVE ); assertNull( dataValueIsValid( "-3", de ) ); assertNotNull( dataValueIsValid( "4", de ) ); de.setValueType( ValueType.TEXT ); assertNull( dataValueIsValid( "0", de ) ); de.setValueType( ValueType.BOOLEAN ); assertNull( dataValueIsValid( "true", de ) ); assertNull( dataValueIsValid( "false", de ) ); assertNull( dataValueIsValid( "FALSE", de ) ); assertNotNull( dataValueIsValid( "yes", de ) ); de.setValueType( ValueType.TRUE_ONLY ); assertNull( dataValueIsValid( "true", de ) ); assertNull( dataValueIsValid( "TRUE", de ) ); assertNotNull( dataValueIsValid( "false", de ) ); de.setValueType( ValueType.DATE ); assertNull( dataValueIsValid( "2013-04-01", de ) ); assertNotNull( dataValueIsValid( "2012304-01", de ) ); assertNotNull( dataValueIsValid( "Date", de ) ); de.setValueType( ValueType.DATETIME ); assertNull( dataValueIsValid( "2013-04-01T11:00:00.000Z", de ) ); assertNotNull( dataValueIsValid( "2013-04-01", de ) ); assertNotNull( dataValueIsValid( "abcd", de ) ); }