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;
@Beta
@NonNullByDefault
@FunctionalInterface
- public interface PointParser {
+ public interface PointNormalizer {
- PathArgument parseValue(String value);
+ PathArgument normalizePoint(ApiPath value);
}
private final @NonNull InsertParam insert;
}
}
- 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();
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:
};
}
+ 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.");