X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fserver%2Fspi%2FApiPathNormalizer.java;h=b54c081d96324a9514c1dd335759cb7ad7cbad04;hb=732d5d9adaca633bd850aef0cc07c157c90050b8;hp=22105bef840185aa74cbf7b36305560c978990f1;hpb=17af1d6ea63ba764d847ef8bd8068a802463b7a7;p=netconf.git diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/ApiPathNormalizer.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/ApiPathNormalizer.java index 22105bef84..b54c081d96 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/ApiPathNormalizer.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/ApiPathNormalizer.java @@ -15,6 +15,7 @@ import com.google.common.base.VerifyException; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.io.IOException; +import java.text.ParseException; import java.util.ArrayList; import java.util.List; import org.eclipse.jdt.annotation.NonNull; @@ -210,6 +211,29 @@ public final class ApiPathNormalizer implements PointNormalizer { ErrorType.PROTOCOL, ErrorTag.DATA_MISSING); } + public static @NonNull Data normalizeSubResource(final Data resource, final ApiPath subResource) { + // If subResource is empty just return the resource + final var urlPath = resource.instance(); + if (subResource.steps().isEmpty()) { + return resource; + } + final var normalizer = new ApiPathNormalizer(resource.databind()); + if (urlPath.isEmpty()) { + // URL indicates the datastore resource, let's just normalize targetPath + return normalizer.normalizeDataPath(subResource); + } + + // FIXME: We are re-parsing the concatenation. We should provide enough context for the bottom half of + // normalizePath() logic instead + final String targetUrl = normalizer.canonicalize(urlPath).toString() + "/" + subResource.toString(); + try { + return normalizer.normalizeDataPath(ApiPath.parse(targetUrl)); + } catch (ParseException e) { + throw new RestconfDocumentedException("Failed to parse target " + targetUrl, + ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE, e); + } + } + @Override public PathArgument normalizePoint(final ApiPath value) { final var path = normalizePath(value);