diff options
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/validation')
2 files changed, 80 insertions, 0 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/validation/StringValidator.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/validation/StringValidator.java new file mode 100644 index 0000000000..0fc2fd7e82 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/validation/StringValidator.java @@ -0,0 +1,36 @@ +package org.openecomp.sdcrests.vendorsoftwareproducts.types.validation; + +import java.util.ArrayList; +import java.util.List; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class StringValidator implements ConstraintValidator<ValidateString, String> { + + private List<String> valueList; + boolean isCaseSensitive; + + @Override + public void initialize(ValidateString constraintAnnotation) { + valueList = new ArrayList<String>(); + isCaseSensitive = constraintAnnotation.isCaseSensitive(); + for (String val : constraintAnnotation.acceptedValues()) { + if (!isCaseSensitive) { + val = val.toUpperCase(); + } + valueList.add(val); + } + } + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + if (!isCaseSensitive) { + value = value.toUpperCase(); + } + if (value != null && !valueList.contains(value)) { + return false; + } + return true; + } + +}
\ No newline at end of file diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/validation/ValidateString.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/validation/ValidateString.java new file mode 100644 index 0000000000..1218bb1c22 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/validation/ValidateString.java @@ -0,0 +1,44 @@ +package org.openecomp.sdcrests.vendorsoftwareproducts.types.validation; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import javax.validation.Constraint; +import javax.validation.Payload; + +/** + * The interface Validate string. + */ +@Documented +@Constraint(validatedBy = StringValidator.class) +@Target({METHOD, FIELD, ANNOTATION_TYPE, PARAMETER, CONSTRUCTOR}) +@Retention(RUNTIME) +public @interface ValidateString { + /** + * The constant message. + */ + String message = ""; + + /** + * Accepted values string [ ]. + * + * @return the string [ ] + */ + String[] acceptedValues(); + + String message() default "{org.openecomp.sdcrests.vendorsoftwareproducts.types.validation" + + ".message}"; + + boolean isCaseSensitive() default false; + + Class<?>[] groups() default {}; + + Class<? extends Payload>[] payload() default {}; +} |