當前位置: 首頁>>代碼示例>>Java>>正文


Java ValidationUtils類代碼示例

本文整理匯總了Java中org.kuali.rice.krad.datadictionary.validation.ValidationUtils的典型用法代碼示例。如果您正苦於以下問題:Java ValidationUtils類的具體用法?Java ValidationUtils怎麽用?Java ValidationUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ValidationUtils類屬於org.kuali.rice.krad.datadictionary.validation包,在下文中一共展示了ValidationUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validateRange

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
/**
 * validates the date value using the range constraint provided
 *
 * @param result - a holder for any already run validation results
 * @param value - the value to validate
 * @param constraint - the range constraint to use
 * @param attributeValueReader - provides access to the attribute being validated
 * @return the passed in result, updated with the results of the processing
 * @throws IllegalArgumentException
 */
protected ConstraintValidationResult validateRange(DictionaryValidationResult result, Date value,
        RangeConstraint constraint, AttributeValueReader attributeValueReader) throws IllegalArgumentException {

    Date date = value != null ? ValidationUtils.getDate(value, dateTimeService) : null;

    String inclusiveMaxText = constraint.getInclusiveMax();
    String exclusiveMinText = constraint.getExclusiveMin();

    Date inclusiveMax = inclusiveMaxText != null ? ValidationUtils.getDate(inclusiveMaxText, dateTimeService) :
            null;
    Date exclusiveMin = exclusiveMinText != null ? ValidationUtils.getDate(exclusiveMinText, dateTimeService) :
            null;

    return isInRange(result, date, inclusiveMax, inclusiveMaxText, exclusiveMin, exclusiveMinText,
            attributeValueReader);
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:27,代碼來源:RangeConstraintProcessor.java

示例2: processSingleExistenceConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
protected ConstraintValidationResult processSingleExistenceConstraint(DictionaryValidationResult result,
        Object value, ExistenceConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {
    // If it's not set, then there's no constraint
    if (constraint.isRequired() == null) {
        return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
    }

    if (constraint.isRequired().booleanValue() && !skipConstraint(attributeValueReader)) {
        // If this attribute is required and the value is null then
        if (ValidationUtils.isNullOrEmpty(value)) {
            String errorParameter = attributeValueReader.getLabel(attributeValueReader.getAttributeName());
            if (ValidationUtils.isNullOrEmpty(errorParameter)) {
                errorParameter = attributeValueReader.getAttributeName();
            }
            return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_REQUIRED,
                    errorParameter);
        }
        return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
    }

    return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:24,代碼來源:ExistenceConstraintProcessor.java

示例3: processSingleLengthConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
protected ConstraintValidationResult processSingleLengthConstraint(DictionaryValidationResult result, Object value,
        LengthConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {
    // Can't process any range constraints on null values
    if (ValidationUtils.isNullOrEmpty(value)) {
        return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
    }

    DataType dataType = constraint.getDataType();
    Object typedValue = value;

    if (dataType != null) {
        typedValue = ValidationUtils.convertToDataType(value, dataType, dateTimeService);
    }

    // The only thing that can have a length constraint currently is a string.
    if (typedValue instanceof String) {
        return validateLength(result, (String) typedValue, constraint, attributeValueReader);
    }

    return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:23,代碼來源:LengthConstraintProcessor.java

示例4: process

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public ProcessorResult process(DictionaryValidationResult result, Object value, PrerequisiteConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {

    if (ValidationUtils.isNullOrEmpty(value)) {
        return new ProcessorResult(result.addSkipped(attributeValueReader, CONSTRAINT_NAME));
    }

    ConstraintValidationResult constraintValidationResult = processPrerequisiteConstraint(constraint,
            attributeValueReader);

    if (constraint != null) {
        if (StringUtils.isNotBlank(constraint.getMessageKey())) {
            constraintValidationResult.setConstraintLabelKey(constraint.getMessageKey());
        } else {
            constraintValidationResult.setConstraintLabelKey(
                    UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + FALLBACK_KEY);
        }
        constraintValidationResult.setErrorParameters(constraint.getValidationMessageParamsArray());
    }

    result.addConstraintValidationResult(attributeValueReader, constraintValidationResult);

    return new ProcessorResult(constraintValidationResult);
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:29,代碼來源:PrerequisiteConstraintProcessor.java

示例5: processSingleExistenceConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
protected ConstraintValidationResult processSingleExistenceConstraint(DictionaryValidationResult result,
        Object value, ExistenceConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {
    // If it's not set, then there's no constraint
    if (constraint.isRequired() == null) {
        return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
    }

    if (constraint.isRequired().booleanValue() && !skipConstraint(attributeValueReader)) {
        // If this attribute is required and the value is null then
        if (ValidationUtils.isNullOrEmpty(value)) {
            return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_REQUIRED,
                    attributeValueReader.getLabel(attributeValueReader.getAttributeName()));
        }
        return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
    }

    return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
 
開發者ID:aapotts,項目名稱:kuali_rice,代碼行數:20,代碼來源:ExistenceConstraintProcessor.java

示例6: process

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
/**
 * @see org.kuali.rice.krad.datadictionary.validation.processor.ConstraintProcessor#process(DictionaryValidationResult,
 *      Object, org.kuali.rice.krad.datadictionary.validation.capability.Validatable,
 *      org.kuali.rice.krad.datadictionary.validation.AttributeValueReader)
 */
@Override
public ProcessorResult process(DictionaryValidationResult result, Object value, PrerequisiteConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {

    if (ValidationUtils.isNullOrEmpty(value)) {
        return new ProcessorResult(result.addSkipped(attributeValueReader, CONSTRAINT_NAME));
    }

    ConstraintValidationResult constraintValidationResult = processPrerequisiteConstraint(constraint,
            attributeValueReader);

    if (constraint != null) {
        if (StringUtils.isNotBlank(constraint.getMessageKey())) {
            constraintValidationResult.setConstraintLabelKey(constraint.getMessageKey());
        } else {
            constraintValidationResult.setConstraintLabelKey(
                    UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + FALLBACK_KEY);
        }
        constraintValidationResult.setErrorParameters(constraint.getValidationMessageParamsArray());
    }

    result.addConstraintValidationResult(attributeValueReader, constraintValidationResult);

    return new ProcessorResult(constraintValidationResult);
}
 
開發者ID:aapotts,項目名稱:kuali_rice,代碼行數:31,代碼來源:PrerequisiteConstraintProcessor.java

示例7: processDataTypeConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
/**
 * validates the value provided using {@code DataTypeConstraint}
 *
 * @param result - a holder for any already run validation results
 * @param dataType - the expected data type
 * @param value - the value to validate
 * @param attributeValueReader - provides access to the attribute being validated
 * @return the passed in result, updated with the results of the processing
 */
protected ConstraintValidationResult processDataTypeConstraint(DictionaryValidationResult result, DataType dataType,
        Object value, AttributeValueReader attributeValueReader) {
    if (dataType == null) {
        return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
    }

    if (ValidationUtils.isNullOrEmpty(value)) {
        return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
    }

    try {
        ValidationUtils.convertToDataType(value, dataType, dateTimeService);
    } catch (Exception e) {
        switch (dataType) {
            case BOOLEAN:
                return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_BOOLEAN);
            case INTEGER:
                return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_INTEGER);
            case LONG:
                return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_LONG);
            case DOUBLE:
                return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_BIG_DECIMAL);
            case FLOAT:
                return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_BIG_DECIMAL);
            case TRUNCATED_DATE:
            case DATE:
                return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_BIG_DECIMAL);
            case STRING:
        }
    }

    // If we get here then it was a success!
    return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:44,代碼來源:DataTypeConstraintProcessor.java

示例8: processSingleRangeConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
/**
 * validates the value provided using {@code RangeConstraint}
 *
 * @param result - a holder for any already run validation results
 * @param value - the value to validate
 * @param constraint - the range constraint to use
 * @param attributeValueReader - provides access to the attribute being validated
 * @return the passed in result, updated with the results of the processing
 * @throws AttributeValidationException if validation fails
 */
protected ConstraintValidationResult processSingleRangeConstraint(DictionaryValidationResult result, Object value,
        RangeConstraint constraint, AttributeValueReader attributeValueReader) throws AttributeValidationException {
    // Can't process any range constraints on null values
    if (ValidationUtils.isNullOrEmpty(value) || (constraint.getExclusiveMin() == null
            && constraint.getInclusiveMax() == null)) {
        return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
    }

    // This is necessary because sometimes we'll be getting a string, for example, that represents a date.
    DataType dataType = constraint.getDataType();
    Object typedValue = value;

    if (dataType != null) {
        typedValue = ValidationUtils.convertToDataType(value, dataType, dateTimeService);
    } else if (value instanceof String) {
        //assume string is a number of type double
        try {
            Double d = Double.parseDouble((String) value);
            typedValue = d;
        } catch (NumberFormatException n) {
            //do nothing, typedValue is never reset
        }
    }

    // TODO: decide if there is any reason why the following would be insufficient - i.e. if something numeric could still be cast to String at this point
    if (typedValue instanceof Date) {
        return validateRange(result, (Date) typedValue, constraint, attributeValueReader);
    } else if (typedValue instanceof Number) {
        return validateRange(result, (Number) typedValue, constraint, attributeValueReader);
    }

    return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:44,代碼來源:RangeConstraintProcessor.java

示例9: isInRange

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
/**
 * checks whether the value provided is in the range specified by inclusiveMax and exclusiveMin
 *
 * @param result a holder for any already run validation results
 * @param value the value to check
 * @param inclusiveMax the maximum value of the attribute
 * @param inclusiveMaxText the string representation of inclusiveMax
 * @param exclusiveMin the minimum value of the attribute
 * @param exclusiveMinText the string representation of exclusiveMin
 * @param attributeValueReader provides access to the attribute being validated
 * @return the passed in result, updated with the results of the range check
 */
private <T> ConstraintValidationResult isInRange(DictionaryValidationResult result, T value,
        Comparable<T> inclusiveMax, String inclusiveMaxText, Comparable<T> exclusiveMin, String exclusiveMinText,
        AttributeValueReader attributeValueReader) {
    // What we want to know is that the maximum value is greater than or equal to the number passed (the number can be equal to the max, i.e. it's 'inclusive')
    Result lessThanMax = ValidationUtils.isLessThanOrEqual(value, inclusiveMax);
    // On the other hand, since the minimum is exclusive, we just want to make sure it's less than the number (the number can't be equal to the min, i.e. it's 'exclusive')
    Result greaterThanMin = ValidationUtils.isGreaterThan(value, exclusiveMin);

    // It's okay for one end of the range to be undefined - that's not an error. It's only an error if one of them is actually invalid. 
    if (lessThanMax != Result.INVALID && greaterThanMin != Result.INVALID) {
        // Of course, if they're both undefined then we didn't actually have a real constraint
        if (lessThanMax == Result.UNDEFINED && greaterThanMin == Result.UNDEFINED) {
            return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
        }

        // In this case, we've succeeded
        return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
    }

    // If both comparisons happened then if either comparison failed we can show the end user the expected range on both sides.
    if (lessThanMax != Result.UNDEFINED && greaterThanMin != Result.UNDEFINED) {
        return result.addError(RANGE_KEY, attributeValueReader, CONSTRAINT_NAME,
                RiceKeyConstants.ERROR_OUT_OF_RANGE, exclusiveMinText, inclusiveMaxText);
    }
    // If it's the max comparison that fails, then just tell the end user what the max can be
    else if (lessThanMax == Result.INVALID) {
        return result.addError(MAX_INCLUSIVE_KEY, attributeValueReader, CONSTRAINT_NAME,
                RiceKeyConstants.ERROR_INCLUSIVE_MAX, inclusiveMaxText);
    }
    // Otherwise, just tell them what the min can be
    else {
        return result.addError(MIN_EXCLUSIVE_KEY, attributeValueReader, CONSTRAINT_NAME,
                RiceKeyConstants.ERROR_EXCLUSIVE_MIN, exclusiveMinText);
    }
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:48,代碼來源:RangeConstraintProcessor.java

示例10: process

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
/**
 * @see org.kuali.rice.krad.datadictionary.validation.processor.ConstraintProcessor#process(org.kuali.rice.krad.datadictionary.validation.result.DictionaryValidationResult,
 *      Object, org.kuali.rice.krad.datadictionary.validation.constraint.Constraint,
 *      org.kuali.rice.krad.datadictionary.validation.AttributeValueReader)
 */
@Override
public ProcessorResult process(DictionaryValidationResult result, Object value, MustOccurConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {

    if (ValidationUtils.isNullOrEmpty(value)) {
        return new ProcessorResult(result.addSkipped(attributeValueReader, CONSTRAINT_NAME));
    }

    ConstraintValidationResult constraintValidationResult = new ConstraintValidationResult(CONSTRAINT_NAME);
    if (StringUtils.isNotBlank(constraint.getMessageKey())) {
        constraintValidationResult.setConstraintLabelKey(constraint.getMessageKey());
    } else {
        constraintValidationResult.setConstraintLabelKey(
                UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + FALLBACK_KEY);
    }

    constraintValidationResult.setErrorParameters(constraint.getValidationMessageParamsArray());

    // If the processing of this constraint is not successful then it's an error
    if (!processMustOccurConstraint(constraintValidationResult, constraint, attributeValueReader)) {
        // if attributeName is null, use the entry name since we are processing a must occur constraint that may be referencing multiple attributes
        if (attributeValueReader.getAttributeName() == null) {
            constraintValidationResult.setAttributeName(attributeValueReader.getEntryName());
        } else {
            constraintValidationResult.setAttributeName(attributeValueReader.getAttributeName());
            constraintValidationResult.setAttributePath(attributeValueReader.getPath());
        }
        constraintValidationResult.setError(RiceKeyConstants.ERROR_OCCURS);
    }

    // Store the label key (if one exists) for this constraint on the constraint validation result so it can be shown later

    // Add it to the DictionaryValidationResult object
    result.addConstraintValidationResult(attributeValueReader, constraintValidationResult);

    return new ProcessorResult(constraintValidationResult);

}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:44,代碼來源:MustOccurConstraintProcessor.java

示例11: processSingleValidCharacterConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
protected ConstraintValidationResult processSingleValidCharacterConstraint(DictionaryValidationResult result,
        Object value, ValidCharactersConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {

    if (constraint == null) {
        return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
    }

    if (ValidationUtils.isNullOrEmpty(value)) {
        return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
    }

    // This mix-in interface is here to allow some definitions to avoid the extra processing that goes on in KNS
    // to decipher and validate things like date range strings -- something that looks like "02/02/2002..03/03/2003"
    Constrainable definition = attributeValueReader.getDefinition(attributeValueReader.getAttributeName());
    if (definition instanceof Formatable) {
        return doProcessFormattableValidCharConstraint(result, constraint, (Formatable) definition, value,
                attributeValueReader);
    }

    ConstraintValidationResult constraintValidationResult = doProcessValidCharConstraint(constraint, value);
    if (constraintValidationResult == null) {
        return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
    }

    result.addConstraintValidationResult(attributeValueReader, constraintValidationResult);
    constraintValidationResult.setConstraintLabelKey(constraint.getMessageKey());
    constraintValidationResult.setErrorParameters(constraint.getValidationMessageParamsArray());
    return constraintValidationResult;
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:31,代碼來源:ValidCharactersConstraintProcessor.java

示例12: doProcessValidCharConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
protected ConstraintValidationResult doProcessValidCharConstraint(ValidCharactersConstraint validCharsConstraint,
        Object value) {

    StringBuilder fieldValue = new StringBuilder();
    String validChars = validCharsConstraint.getValue();

    if (value instanceof java.sql.Date) {
        fieldValue.append(getDateTimeService().toDateString((java.sql.Date) value));
    } else {
        fieldValue.append(ValidationUtils.getString(value));
    }

    //        int typIdx = validChars.indexOf(":");
    //        String processorType = "regex";
    //        if (-1 == typIdx) {
    //            validChars = "[" + validChars + "]*";
    //        } else {
    //            processorType = validChars.substring(0, typIdx);
    //            validChars = validChars.substring(typIdx + 1);
    //        }

    //        if ("regex".equalsIgnoreCase(processorType) && !validChars.equals(".*")) {
    if (!fieldValue.toString().matches(validChars)) {
        ConstraintValidationResult constraintValidationResult = new ConstraintValidationResult(CONSTRAINT_NAME);
        constraintValidationResult.setError(RiceKeyConstants.ERROR_INVALID_FORMAT, fieldValue.toString());
        constraintValidationResult.setConstraintLabelKey(validCharsConstraint.getMessageKey());
        constraintValidationResult.setErrorParameters(validCharsConstraint.getValidationMessageParamsArray());
        return constraintValidationResult;
    }
    //        }

    return null;
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:34,代碼來源:ValidCharactersConstraintProcessor.java

示例13: processSingleRangeConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
/**
 * validates the value provided using {@code RangeConstraint}
 *
 * @param result - a holder for any already run validation results
 * @param value - the value to validate
 * @param constraint - the range constraint to use
 * @param attributeValueReader - provides access to the attribute being validated
 * @return the passed in result, updated with the results of the processing
 */
protected ConstraintValidationResult processSingleRangeConstraint(DictionaryValidationResult result, Object value,
        RangeConstraint constraint, AttributeValueReader attributeValueReader) throws AttributeValidationException {
    // Can't process any range constraints on null values
    if (ValidationUtils.isNullOrEmpty(value) || (constraint.getExclusiveMin() == null
            && constraint.getInclusiveMax() == null)) {
        return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
    }

    // This is necessary because sometimes we'll be getting a string, for example, that represents a date.
    DataType dataType = constraint.getDataType();
    Object typedValue = value;

    if (dataType != null) {
        typedValue = ValidationUtils.convertToDataType(value, dataType, dateTimeService);
    } else if (value instanceof String) {
        //assume string is a number of type double
        try {
            Double d = Double.parseDouble((String) value);
            typedValue = d;
        } catch (NumberFormatException n) {
            //do nothing, typedValue is never reset
        }
    }

    // TODO: decide if there is any reason why the following would be insufficient - i.e. if something numeric could still be cast to String at this point
    if (typedValue instanceof Date) {
        return validateRange(result, (Date) typedValue, constraint, attributeValueReader);
    } else if (typedValue instanceof Number) {
        return validateRange(result, (Number) typedValue, constraint, attributeValueReader);
    }

    return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
 
開發者ID:aapotts,項目名稱:kuali_rice,代碼行數:43,代碼來源:RangeConstraintProcessor.java

示例14: isInRange

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
/**
 * checks whether the value provided is in the range specified by inclusiveMax and exclusiveMin
 *
 * @param - a holder for any already run validation results
 * @param value - the value to check
 * @param inclusiveMax - the maximum value of the attribute
 * @param inclusiveMaxText - the string representation of inclusiveMax
 * @param exclusiveMin -  the minimum value of the attribute
 * @param exclusiveMinText - the string representation of exclusiveMin
 * @param attributeValueReader - provides access to the attribute being validated
 * @return the passed in result, updated with the results of the range check
 */
private <T> ConstraintValidationResult isInRange(DictionaryValidationResult result, T value,
        Comparable<T> inclusiveMax, String inclusiveMaxText, Comparable<T> exclusiveMin, String exclusiveMinText,
        AttributeValueReader attributeValueReader) {
    // What we want to know is that the maximum value is greater than or equal to the number passed (the number can be equal to the max, i.e. it's 'inclusive')
    Result lessThanMax = ValidationUtils.isLessThanOrEqual(value, inclusiveMax);
    // On the other hand, since the minimum is exclusive, we just want to make sure it's less than the number (the number can't be equal to the min, i.e. it's 'exclusive')
    Result greaterThanMin = ValidationUtils.isGreaterThan(value, exclusiveMin);

    // It's okay for one end of the range to be undefined - that's not an error. It's only an error if one of them is actually invalid. 
    if (lessThanMax != Result.INVALID && greaterThanMin != Result.INVALID) {
        // Of course, if they're both undefined then we didn't actually have a real constraint
        if (lessThanMax == Result.UNDEFINED && greaterThanMin == Result.UNDEFINED) {
            return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
        }

        // In this case, we've succeeded
        return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
    }

    // If both comparisons happened then if either comparison failed we can show the end user the expected range on both sides.
    if (lessThanMax != Result.UNDEFINED && greaterThanMin != Result.UNDEFINED) {
        return result.addError(RANGE_KEY, attributeValueReader, CONSTRAINT_NAME,
                RiceKeyConstants.ERROR_OUT_OF_RANGE, exclusiveMinText, inclusiveMaxText);
    }
    // If it's the max comparison that fails, then just tell the end user what the max can be
    else if (lessThanMax == Result.INVALID) {
        return result.addError(MAX_INCLUSIVE_KEY, attributeValueReader, CONSTRAINT_NAME,
                RiceKeyConstants.ERROR_INCLUSIVE_MAX, inclusiveMaxText);
    }
    // Otherwise, just tell them what the min can be
    else {
        return result.addError(MIN_EXCLUSIVE_KEY, attributeValueReader, CONSTRAINT_NAME,
                RiceKeyConstants.ERROR_EXCLUSIVE_MIN, exclusiveMinText);
    }
}
 
開發者ID:aapotts,項目名稱:kuali_rice,代碼行數:48,代碼來源:RangeConstraintProcessor.java

示例15: processSingleCollectionSizeConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入依賴的package包/類
protected ConstraintValidationResult processSingleCollectionSizeConstraint(DictionaryValidationResult result,
        Collection<?> collection, CollectionSizeConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {
    Integer sizeOfCollection = new Integer(0);
    if (collection != null) {
        sizeOfCollection = Integer.valueOf(collection.size());
    }

    Integer maxOccurances = constraint.getMaximumNumberOfElements();
    Integer minOccurances = constraint.getMinimumNumberOfElements();

    Result lessThanMax = ValidationUtils.isLessThanOrEqual(sizeOfCollection, maxOccurances);
    Result greaterThanMin = ValidationUtils.isGreaterThanOrEqual(sizeOfCollection, minOccurances);

    // It's okay for one end of the range to be undefined - that's not an error. It's only an error if one of them is invalid
    if (lessThanMax != Result.INVALID && greaterThanMin != Result.INVALID) {
        // Of course, if they're both undefined then we didn't actually have a real constraint
        if (lessThanMax == Result.UNDEFINED && greaterThanMin == Result.UNDEFINED) {
            return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
        }

        // In this case, we've succeeded
        return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
    }

    String maxErrorParameter = maxOccurances != null ? maxOccurances.toString() : null;
    String minErrorParameter = minOccurances != null ? minOccurances.toString() : null;

    // If both comparisons happened then if either comparison failed we can show the end user the expected range on both sides.
    if (lessThanMax != Result.UNDEFINED && greaterThanMin != Result.UNDEFINED) {
        return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_QUANTITY_RANGE,
                minErrorParameter, maxErrorParameter);
    }
    // If it's the max comparison that fails, then just tell the end user what the max can be
    else if (lessThanMax == Result.INVALID) {
        return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_MAX_OCCURS,
                maxErrorParameter);
    }
    // Otherwise, just tell them what the min can be
    else {
        return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_MIN_OCCURS,
                minErrorParameter);
    }

    // Obviously the last else above is unnecessary, since anything after it is dead code, but keeping it seems clearer than dropping it
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:47,代碼來源:CollectionSizeConstraintProcessor.java


注:本文中的org.kuali.rice.krad.datadictionary.validation.ValidationUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。