From 8e2383e5fd0f14873fb0558ae2545bfe10367f31 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 8 Jul 2020 15:16:57 +0200 Subject: [PATCH] Eliminate RestconfConstants.SLASH This is a rather useless constant, which is just muddling things up. Inline it into users, clearing some very surprising ways of use. Change-Id: I7d98f670238c32fab32681d6084a9fe28bc8f0b3 Signed-off-by: Robert Varga --- .../rests/services/impl/RestconfDataServiceImpl.java | 4 +--- .../rests/services/impl/SubscribeToStreamUtil.java | 3 +-- .../nb/rfc8040/rests/utils/RestconfStreamsConstants.java | 5 ++--- .../restconf/nb/rfc8040/utils/RestconfConstants.java | 3 +-- .../nb/rfc8040/utils/parser/ParserIdentifier.java | 5 ++--- .../utils/parser/YangInstanceIdentifierDeserializer.java | 9 ++++----- .../utils/parser/YangInstanceIdentifierSerializer.java | 5 ++--- 7 files changed, 13 insertions(+), 21 deletions(-) diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java index 819cde9f62..96fca87b4f 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java @@ -60,7 +60,6 @@ import org.opendaylight.restconf.nb.rfc8040.rests.utils.ReadDataTransactionUtil; import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant; import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfInvokeOperationsUtil; import org.opendaylight.restconf.nb.rfc8040.streams.listeners.NotificationListenerAdapter; -import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants; import org.opendaylight.restconf.nb.rfc8040.utils.mapping.RestconfMappingNodeUtil; import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier; import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType; @@ -151,8 +150,7 @@ public class RestconfDataServiceImpl implements RestconfDataService { if (identifier != null && identifier.contains(STREAM_PATH) && identifier.contains(STREAM_ACCESS_PATH_PART) && identifier.contains(STREAM_LOCATION_PATH_PART)) { final String value = (String) node.getValue(); - final String streamName = value.substring( - value.indexOf(NOTIFICATION_STREAM + RestconfConstants.SLASH)); + final String streamName = value.substring(value.indexOf(NOTIFICATION_STREAM + '/')); this.delegRestconfSubscrService.subscribeToStream(streamName, uriInfo); } if (node == null) { diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java index f52eab5b73..9cccbaab01 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java @@ -298,8 +298,7 @@ final class SubscribeToStreamUtil { // Unsecured HTTP and others go to unsecured WebSockets uriBuilder.scheme("ws"); } - return uriBuilder.replacePath(RestconfConstants.BASE_URI_PATTERN + RestconfConstants.SLASH + streamName) - .build(); + return uriBuilder.replacePath(RestconfConstants.BASE_URI_PATTERN + '/' + streamName).build(); } /** diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfStreamsConstants.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfStreamsConstants.java index ffa08159de..659b45a0e8 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfStreamsConstants.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfStreamsConstants.java @@ -11,7 +11,6 @@ import com.google.common.collect.ImmutableSet; import java.net.URI; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.restconf.common.util.DataChangeScope; -import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.Revision; @@ -54,8 +53,8 @@ public final class RestconfStreamsConstants { public static final LogicalDatastoreType DEFAULT_DS = LogicalDatastoreType.CONFIGURATION; public static final char EQUAL = '='; - public static final String DS_URI = RestconfConstants.SLASH + DATASTORE_PARAM_NAME + EQUAL; - public static final String SCOPE_URI = RestconfConstants.SLASH + SCOPE_PARAM_NAME + EQUAL; + public static final String DS_URI = '/' + DATASTORE_PARAM_NAME + EQUAL; + public static final String SCOPE_URI = '/' + SCOPE_PARAM_NAME + EQUAL; public static final String DATA_SUBSCRIPTION = "data-change-event-subscription"; public static final String CREATE_DATA_SUBSCRIPTION = "create-" + DATA_SUBSCRIPTION; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/RestconfConstants.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/RestconfConstants.java index 944b231a4a..96b3d28c3e 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/RestconfConstants.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/RestconfConstants.java @@ -19,8 +19,7 @@ public final class RestconfConstants { public static final String JSON = "+json"; public static final String MOUNT = "yang-ext:mount"; public static final String IDENTIFIER = "identifier"; - public static final char SLASH = '/'; - public static final Splitter SLASH_SPLITTER = Splitter.on(SLASH); + public static final Splitter SLASH_SPLITTER = Splitter.on('/'); public static final String BASE_URI_PATTERN = "rests"; private RestconfConstants() { diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java index 02ab4d765d..e3145cbfef 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java @@ -181,8 +181,7 @@ public final class ParserIdentifier { */ public static Entry makeQNameFromIdentifier(final String identifier) { // check if more than one slash is not used as path separator - if (identifier.contains( - String.valueOf(RestconfConstants.SLASH).concat(String.valueOf(RestconfConstants.SLASH)))) { + if (identifier.contains("//")) { LOG.debug("URI has bad format. It should be \'moduleName/yyyy-MM-dd\' {}", identifier); throw new RestconfDocumentedException( "URI has bad format. End of URI should be in format \'moduleName/yyyy-MM-dd\'", ErrorType.PROTOCOL, @@ -193,7 +192,7 @@ public final class ParserIdentifier { final String moduleNameAndRevision; if (mountIndex >= 0) { moduleNameAndRevision = identifier.substring(mountIndex + RestconfConstants.MOUNT.length()) - .replaceFirst(String.valueOf(RestconfConstants.SLASH), ""); + .replaceFirst("/", ""); } else { moduleNameAndRevision = identifier; } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java index acbb65a60b..2b9bbc778b 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java @@ -8,7 +8,6 @@ package org.opendaylight.restconf.nb.rfc8040.utils.parser; import static java.util.Objects.requireNonNull; -import static org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants.SLASH; import com.google.common.base.CharMatcher; import com.google.common.collect.ImmutableList; @@ -95,7 +94,7 @@ public final class YangInstanceIdentifierDeserializer { final QName qname = prepareQName(); // this is the last identifier (input is consumed) or end of identifier (slash) - if (allCharsConsumed() || currentChar() == SLASH) { + if (allCharsConsumed() || currentChar() == '/') { prepareIdentifier(qname, path); path.add(current == null ? NodeIdentifier.create(qname) : current.getIdentifier()); } else if (currentChar() == '=') { @@ -123,7 +122,7 @@ public final class YangInstanceIdentifierDeserializer { skipCurrentChar(); // read key value separated by comma - while (keys.hasNext() && !allCharsConsumed() && currentChar() != SLASH) { + while (keys.hasNext() && !allCharsConsumed() && currentChar() != '/') { // empty key value if (currentChar() == ',') { @@ -319,11 +318,11 @@ public final class YangInstanceIdentifierDeserializer { private void validArg() { // every identifier except of the first MUST start with slash if (offset != 0) { - checkValid(SLASH == currentChar(), ErrorTag.MALFORMED_MESSAGE, "Identifier must start with '/'."); + checkValid('/' == currentChar(), ErrorTag.MALFORMED_MESSAGE, "Identifier must start with '/'."); // skip consecutive slashes, users often assume restconf URLs behave just as HTTP does by squashing // multiple slashes into a single one - while (!allCharsConsumed() && SLASH == currentChar()) { + while (!allCharsConsumed() && '/' == currentChar()) { skipCurrentChar(); } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializer.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializer.java index 8aa59c61ad..c3623bed48 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializer.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializer.java @@ -15,7 +15,6 @@ import java.util.Map.Entry; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag; import org.opendaylight.restconf.common.errors.RestconfError.ErrorType; -import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants; import org.opendaylight.yangtools.concepts.Serializer; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; @@ -76,12 +75,12 @@ public final class YangInstanceIdentifierSerializer { if (!arg.getNodeType().getModule().equals(parentModule)) { // append slash if it is not the first path argument if (path.length() > 0) { - path.append(RestconfConstants.SLASH); + path.append('/'); } path.append(prefixForNamespace(arg.getNodeType(), schemaContext)).append(':'); } else { - path.append(RestconfConstants.SLASH); + path.append('/'); } if (arg instanceof NodeIdentifierWithPredicates) { -- 2.36.6