use of org.craftercms.commons.validation.ValidationRuntimeException in project commons by craftercms.
the class ValidateParamsAspect method doValidation.
@Before("@within(org.craftercms.commons.validation.annotations.param.ValidateParams) || " + "@annotation(org.craftercms.commons.validation.annotations.param.ValidateParams)")
public void doValidation(JoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();
Method method = AopUtils.getActualMethod(joinPoint);
Annotation[][] allParamAnnotations = method.getParameterAnnotations();
ValidationResult result = new ValidationResult(errorMessageBundle);
if (ArrayUtils.isNotEmpty(allParamAnnotations)) {
for (int i = 0; i < args.length; i++) {
Object param = args[i];
Annotation[] paramAnnotations = allParamAnnotations[i];
for (Annotation annotation : paramAnnotations) {
validateParam(annotation, param, result);
}
}
}
if (result.hasErrors()) {
String methodStr = method.toGenericString();
result.setMessage(ValidationUtils.getErrorMessage(errorMessageBundle, INVALID_METHOD_PARAMS_ERROR_CODE, methodStr));
throw new ValidationRuntimeException(result);
}
}
Aggregations