X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fnb%2Frfc8040%2FInsert.java;h=3959a74867c1c071b64763bdde83a4cbffa630c0;hb=195a977a0581c025fcd6dc33da7b3f2fef1123de;hp=30a44726bec34c84aa0f39565af5fd1232a9ce30;hpb=df7615b3f88eb60d9ef960b32fa916d19a2833d9;p=netconf.git diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/Insert.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/Insert.java index 30a44726be..3959a74867 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/Insert.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/Insert.java @@ -8,18 +8,20 @@ package org.opendaylight.restconf.nb.rfc8040; import static java.util.Objects.requireNonNull; -import static org.opendaylight.restconf.nb.rfc8040.ReceiveEventsParams.optionalParam; +import static org.opendaylight.restconf.server.api.EventStreamGetParams.optionalParam; import com.google.common.annotations.Beta; import com.google.common.base.MoreObjects; +import java.text.ParseException; import java.util.Map; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.restconf.api.ApiPath; import org.opendaylight.restconf.api.query.InsertParam; import org.opendaylight.restconf.api.query.PointParam; -import org.opendaylight.restconf.nb.rfc8040.utils.parser.YangInstanceIdentifierDeserializer; import org.opendaylight.restconf.server.api.DatabindContext; +import org.opendaylight.restconf.server.spi.ApiPathNormalizer; import org.opendaylight.yangtools.concepts.Immutable; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; @@ -35,9 +37,9 @@ public final class Insert implements Immutable { @Beta @NonNullByDefault @FunctionalInterface - public interface PointParser { + public interface PointNormalizer { - PathArgument parseValue(String value); + PathArgument normalizePoint(ApiPath value); } private final @NonNull InsertParam insert; @@ -77,12 +79,11 @@ public final class Insert implements Immutable { } } - return Insert.forParams(insert, point, - value -> YangInstanceIdentifierDeserializer.create(databind, value).path.getLastPathArgument()); + return Insert.forParams(insert, point, new ApiPathNormalizer(databind)); } public static @Nullable Insert forParams(final @Nullable InsertParam insert, final @Nullable PointParam point, - final PointParser pointParser) { + final PointNormalizer pointParser) { if (insert == null) { if (point != null) { throw invalidPointIAE(); @@ -100,7 +101,7 @@ public final class Insert implements Immutable { throw new IllegalArgumentException( "Insert parameter " + insert.paramValue() + " cannot be used without a Point parameter."); } - yield new Insert(insert, pointParser.parseValue(point.value())); + yield new Insert(insert, parsePoint(pointParser, point.value())); } case FIRST, LAST -> { // https://www.rfc-editor.org/rfc/rfc8040#section-4.8.6: @@ -116,6 +117,16 @@ public final class Insert implements Immutable { }; } + private static PathArgument parsePoint(final PointNormalizer pointParser, final String value) { + final ApiPath pointPath; + try { + pointPath = ApiPath.parse(value); + } catch (ParseException e) { + throw new IllegalArgumentException("Malformed point parameter '" + value + "': " + e.getMessage(), e); + } + return pointParser.normalizePoint(pointPath); + } + private static IllegalArgumentException invalidPointIAE() { return new IllegalArgumentException( "Point parameter can be used only with 'after' or 'before' values of Insert parameter.");