Java Code Examples for org.apache.commons.validator.GenericValidator#isInRange()

The following examples show how to use org.apache.commons.validator.GenericValidator#isInRange() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultSchemaValidator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private List<? extends ErrorReport> validateInteger( Class<?> klass, Object propertyObject, Property property )
{
    List<ErrorReport> errorReports = new ArrayList<>();

    if ( !Integer.class.isInstance( propertyObject ) )
    {
        return errorReports;
    }

    Integer value = (Integer) propertyObject;

    if ( !GenericValidator.isInRange( value, property.getMin(), property.getMax() ) )
    {
        errorReports.add( new ErrorReport( klass, ErrorCode.E4008, property.getName(), property.getMin(), property.getMax(), value )
            .setErrorKlass( property.getKlass() ).setErrorProperty( property.getName() ) );
    }

    return errorReports;
}
 
Example 2
Source File: DefaultSchemaValidator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private List<? extends ErrorReport> validateFloat( Class<?> klass, Object propertyObject, Property property )
{
    List<ErrorReport> errorReports = new ArrayList<>();

    if ( !Float.class.isInstance( propertyObject ) )
    {
        return errorReports;
    }

    Float value = (Float) propertyObject;

    if ( !GenericValidator.isInRange( value, property.getMin(), property.getMax() ) )
    {
        errorReports.add( new ErrorReport( klass, ErrorCode.E4008, property.getName(), property.getMin(), property.getMax(), value )
            .setErrorKlass( property.getKlass() ).setErrorProperty( property.getName() ) );
    }

    return errorReports;
}
 
Example 3
Source File: DefaultSchemaValidator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private List<? extends ErrorReport> validateDouble( Class<?> klass, Object propertyObject, Property property )
{
    List<ErrorReport> errorReports = new ArrayList<>();

    if ( !Double.class.isInstance( propertyObject ) )
    {
        return errorReports;
    }

    Double value = (Double) propertyObject;

    if ( !GenericValidator.isInRange( value, property.getMin(), property.getMax() ) )
    {
        errorReports.add( new ErrorReport( klass, ErrorCode.E4008, property.getName(), property.getMin(), property.getMax(), value )
            .setErrorKlass( property.getKlass() ).setErrorProperty( property.getName() ) );
    }

    return errorReports;
}
 
Example 4
Source File: GenericModelChecks.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
public static boolean validateIntRange(Object bean, Field field, ValidatorResults results, ValidatorAction action) {
	String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
	if (value == null) {
		return true;
	}
	int intValue = Integer.parseInt(value);
	int min = Integer.parseInt(field.getVarValue("min"));
	int max = Integer.parseInt(field.getVarValue("max"));

	boolean valid = GenericValidator.isInRange(intValue, min, max);
	results.add(field, action.getName(), valid, value);
	return valid;
}
 
Example 5
Source File: BLValidator.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * Validates that the given input is not a negative number.
 * 
 * @param member
 *            The indicator of the field to be validated.
 * @param inputValue
 *            The value to be validated.
 * @throws ValidationException
 *             Thrown in case the value is negative.
 */
public static void isNonNegativeNumber(String member, long inputValue)
        throws ValidationException {
    if (!GenericValidator.isInRange(inputValue, 0L, Long.MAX_VALUE)) {
        ValidationException vf = new ValidationException(
                ReasonEnum.POSITIVE_NUMBER, member,
                new Object[] { Long.valueOf(inputValue) });
        logValidationFailure(vf);
        throw vf;
    }
}
 
Example 6
Source File: ValidateUtil.java    From primecloud-controller with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 最小値、最大値チェック(int)
 *
 * @param value 入力チェック対象の値
 * @param min 最小値
 * @param max 最大値
 * @param code 入力チェックエラー時のメッセージコード
 * @param params 入力チェックエラー時のメッセージパラメータ
 */
public static void intInRange(String value, int min, int max, String code, Object[] params) {
    if (GenericValidator.isInt(value) == false) {
        throw new AutoApplicationException(code, params);
    }
    if (GenericValidator.isInRange(Integer.valueOf(value), min, max) == false) {
        throw new AutoApplicationException(code, params);
    }
}
 
Example 7
Source File: ValidateUtil.java    From primecloud-controller with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 最小値、最大値チェック(long)
 *
 * @param value 入力チェック対象の値
 * @param min 最小値
 * @param max 最大値
 * @param code 入力チェックエラー時のメッセージコード
 * @param params 入力チェックエラー時のメッセージパラメータ
 */
public static void longInRange(String value, long min, long max, String code, Object... params) {
    if (GenericValidator.isLong(value) == false) {
        throw new AutoApplicationException(code, params);
    }
    if (GenericValidator.isInRange(Long.parseLong(value), min, max) == false) {
        throw new AutoApplicationException(code, params);
    }
}