From ea01d09861289ff162dff318713d1c24eba89259 Mon Sep 17 00:00:00 2001 From: sourabh_sourabh Date: Mon, 28 Mar 2022 13:21:55 +0100 Subject: Async: NCMP Rest impl. including Request ID generation - Restructured code and moved some of them at controller and service layer. - Unit is fixed and organized to it's belonging classes. Issue-ID: CPS-828 Signed-off-by: sourabh_sourabh Change-Id: I0919218e35b1d11cb579d707f376b76de80409da --- .../src/main/java/org/onap/cps/utils/CpsValidator.java | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'cps-service/src/main/java') diff --git a/cps-service/src/main/java/org/onap/cps/utils/CpsValidator.java b/cps-service/src/main/java/org/onap/cps/utils/CpsValidator.java index dd1649563..28b49c966 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/CpsValidator.java +++ b/cps-service/src/main/java/org/onap/cps/utils/CpsValidator.java @@ -22,6 +22,7 @@ package org.onap.cps.utils; import com.google.common.collect.Lists; import java.util.Collection; +import java.util.regex.Pattern; import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -32,6 +33,8 @@ import org.onap.cps.spi.exceptions.DataValidationException; public final class CpsValidator { private static final char[] UNSUPPORTED_NAME_CHARACTERS = "!\" #$%&'()*+,./\\:;<=>?@[]^`{|}~".toCharArray(); + private static final Pattern TOPIC_NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9]([._-](?![._-])|" + + "[a-zA-Z0-9]){0,120}[a-zA-Z0-9]$"); /** * Validate characters in names within cps. @@ -48,4 +51,12 @@ public final class CpsValidator { } } } + + /** + * Validate kafka topic name pattern. + * @param topicName name of the topic to be validated + */ + public static boolean validateTopicName(final String topicName) { + return topicName != null && TOPIC_NAME_PATTERN.matcher(topicName).matches(); + } } -- cgit 1.2.3-korg