summaryrefslogtreecommitdiffstats
path: root/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-03-07 19:51:59 -0500
committerJim Hahn <jrh3@att.com>2019-03-08 08:40:51 -0500
commit0af104298947b796ebd511dcabd17209bf452a06 (patch)
tree06d30f95f4afa20e4735ecb2ac195715fa9e3dde /common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java
parentc6b9fe817369db9c5fc824ab49f0f04b83d72756 (diff)
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 <jrh3@att.com>
Diffstat (limited to 'common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java')
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java28
1 files changed, 11 insertions, 17 deletions
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);
}
/**