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);
}
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));
}
}
}
}
}
Aggregations