diff options
Diffstat (limited to 'common-parameters/src/main')
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(); +} |