From 0af104298947b796ebd511dcabd17209bf452a06 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Thu, 7 Mar 2019 19:51:59 -0500 Subject: Create ParameterGroupImpl Classes that implement ParameterGroup all have to add their own name and validate() fields and methods. Added an "impl" class that provides the standard functionality and modified subclasses to use it. Change-Id: Ic6ee1607fb4fe7164a4e1eeebc480ea7d1e7e4d7 Issue-ID: POLICY-1542 Signed-off-by: Jim Hahn --- .../parameters/ParameterValidationResult.java | 28 +++++++++------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java') diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java index e43c2d17..57232e1c 100644 --- a/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java +++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java @@ -49,12 +49,15 @@ public class ParameterValidationResult implements ValidationResult { this.field = field; this.parameterValue = parameterValue; - if (parameterValue == null && getAnyAnnotation(field, NotNull.class) != null) { - setResult(ValidationStatus.INVALID, "is null"); + if (parameterValue == null) { + if (getAnyAnnotation(field, NotNull.class) != null) { + setResult(ValidationStatus.INVALID, "is null"); + } - } else if (parameterValue instanceof String && getAnyAnnotation(field, NotBlank.class) != null - && parameterValue.toString().trim().isEmpty()) { - setResult(ValidationStatus.INVALID, "must be a non-blank string"); + } else if (parameterValue instanceof String) { + if (getAnyAnnotation(field, NotBlank.class) != null && parameterValue.toString().trim().isEmpty()) { + setResult(ValidationStatus.INVALID, "must be a non-blank string"); + } } else if (parameterValue instanceof Number) { Min minAnnot = field.getAnnotation(Min.class); @@ -66,7 +69,8 @@ public class ParameterValidationResult implements ValidationResult { /** * Gets an annotation for a field, first checking the field, itself, and then checking - * at the class level for the current and superclasses. + * at the class level. Does not check super classes as class-level annotations should + * only apply to the fields within the class. * * @param field field of interest * @param annotClass class of annotation that is desired @@ -78,17 +82,7 @@ public class ParameterValidationResult implements ValidationResult { return annot; } - // check class level - Class clazz = field.getDeclaringClass(); - while (clazz != Object.class) { - if ((annot = clazz.getAnnotation(annotClass)) != null) { - return annot; - } - - clazz = clazz.getSuperclass(); - } - - return null; + return field.getDeclaringClass().getAnnotation(annotClass); } /** -- cgit 1.2.3-korg