summaryrefslogtreecommitdiffstats
path: root/common-parameters/src/main/java/org/onap
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-07 10:20:20 -0400
committerJim Hahn <jrh3@att.com>2019-06-07 10:20:20 -0400
commite671e9fa5d09ec696cb24aeefaf10ddbc7c705d7 (patch)
tree11b6367c23d8b689c5120e0d1779f6e23616df3c /common-parameters/src/main/java/org/onap
parentc657a28325092a721f2d8d9bb7991ae88d2b237e (diff)
Add @Max annotation to paramater validation code
Change-Id: I928eeb6bf52cb9e825db456278ce8bff449c692c Issue-ID: POLICY-1762 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'common-parameters/src/main/java/org/onap')
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java6
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/Max.java39
2 files changed, 45 insertions, 0 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 57232e1c..0b66a533 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
@@ -23,6 +23,7 @@ package org.onap.policy.common.parameters;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
+import org.onap.policy.common.parameters.annotations.Max;
import org.onap.policy.common.parameters.annotations.Min;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
@@ -64,6 +65,11 @@ public class ParameterValidationResult implements ValidationResult {
if (minAnnot != null && ((Number) parameterValue).longValue() < minAnnot.value()) {
setResult(ValidationStatus.INVALID, "must be >= " + minAnnot.value());
}
+
+ Max maxAnnot = field.getAnnotation(Max.class);
+ if (maxAnnot != null && ((Number) parameterValue).longValue() > maxAnnot.value()) {
+ setResult(ValidationStatus.INVALID, "must be <= " + maxAnnot.value());
+ }
}
}
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/Max.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/Max.java
new file mode 100644
index 00000000..1d8fd90f
--- /dev/null
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/Max.java
@@ -0,0 +1,39 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.parameters.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Retention(RUNTIME)
+@Target(FIELD)
+public @interface Max {
+
+ /**
+ * The maximum value allowed.
+ *
+ * @return the maximum value allowed
+ */
+ long value();
+}