Search in sources :

Example 1 with Validatable

use of com.thoughtworks.go.config.Validatable in project gocd by gocd.

the class ParamSubstitutionHandler method handleIllegalStateException.

private void handleIllegalStateException(IllegalStateException e) throws IllegalStateException {
    if (Validatable.class.isAssignableFrom(resolvable.getClass())) {
        Validatable validatable = (Validatable) resolvable;
        validatable.addError(fieldName, e.getMessage());
    } else {
        throw e;
    }
    result = new StringBuilder(stringToResolve);
}
Also used : Validatable(com.thoughtworks.go.config.Validatable)

Example 2 with Validatable

use of com.thoughtworks.go.config.Validatable in project gocd by gocd.

the class ErrorCollector method collectFieldErrors.

public static void collectFieldErrors(Map<String, List<String>> errorBucket, String prefix, Object subject) {
    Field[] fields = subject.getClass().getDeclaredFields();
    for (Field field : fields) {
        String fieldName = field.getName();
        Object fieldValue = null;
        try {
            field.setAccessible(true);
            fieldValue = field.get(subject);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        // Object fieldValue = ReflectionUtil.getField(subject, fieldName);
        if (isAConstantField(field) || field.isAnnotationPresent(IgnoreTraversal.class)) {
            continue;
        }
        if (fieldValue != null && fieldValue instanceof Collection && isConfigObject(fieldValue)) {
            // collection to be walked
            Collection collection = (Collection) fieldValue;
            int index = 0;
            for (Object collectionItem : collection) {
                collectFieldErrors(errorBucket, prefix + "[" + fieldName + "][" + (index++) + "]", collectionItem);
            }
        } else if (isConfigObject(fieldValue)) {
            // object to be walked
            collectFieldErrors(errorBucket, prefix + "[" + fieldName + "]", fieldValue);
        } else {
            // basic field
            if (subject instanceof Validatable) {
                ConfigErrors configErrors = ((Validatable) subject).errors();
                if (configErrors != null && configErrors.getAllOn(fieldName) != null) {
                    errorBucket.put(prefix + "[" + fieldName + "]", configErrors.getAllOn(fieldName));
                }
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) IgnoreTraversal(com.thoughtworks.go.config.IgnoreTraversal) Collection(java.util.Collection) Validatable(com.thoughtworks.go.config.Validatable) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors)

Aggregations

Validatable (com.thoughtworks.go.config.Validatable)2 IgnoreTraversal (com.thoughtworks.go.config.IgnoreTraversal)1 ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)1 Field (java.lang.reflect.Field)1 Collection (java.util.Collection)1