Expose the canonical constructor and adjust callers to use ApiPath.of().
JIRA: NETCONF-1264
Change-Id: I74f0e17b15d363f096cb7d4a369519a7ba879e7a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import java.io.ObjectStreamException;
import java.text.ParseException;
import java.util.HexFormat;
+import java.util.List;
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
* as a series of {@link Step}s.
*/
@NonNullByDefault
-public final class ApiPath implements HierarchicalIdentifier<ApiPath> {
+public record ApiPath(ImmutableList<Step> steps) implements HierarchicalIdentifier<ApiPath> {
@java.io.Serial
private static final long serialVersionUID = 1L;
private static final ApiPath EMPTY = new ApiPath(ImmutableList.of());
- private final ImmutableList<Step> steps;
-
- private ApiPath(final ImmutableList<Step> steps) {
- this.steps = requireNonNull(steps);
+ public ApiPath {
+ requireNonNull(steps);
}
/**
return EMPTY;
}
+ public static ApiPath of(final List<Step> steps) {
+ return steps.isEmpty() ? EMPTY : new ApiPath(ImmutableList.copyOf(steps));
+ }
+
/**
* Parse an {@link ApiPath} from a raw Request URI fragment or another source. The string is expected to contain
* percent-encoded bytes. Any sequence of such bytes is interpreted as a {@code UTF-8}-encoded string. Invalid
public ApiPath subPath(final int fromIndex, final int toIndex) {
final var subList = steps.subList(fromIndex, toIndex);
- if (subList == steps) {
- return this;
- } else if (subList.isEmpty()) {
- return EMPTY;
- } else {
- return new ApiPath(subList);
- }
+ return subList == steps ? this : of(subList);
}
@Override
}
private static ApiPath parseString(final ApiPathParser parser, final String str) throws ParseException {
- final var steps = parser.parseSteps(str);
- return steps.isEmpty() ? EMPTY : new ApiPath(steps);
+ return of(parser.parseSteps(str));
}
}
import org.opendaylight.restconf.server.api.ResourceBody;
import org.opendaylight.restconf.server.spi.ApiPathNormalizer;
import org.opendaylight.restconf.server.spi.ApiPathNormalizer.InstanceReference;
-import org.opendaylight.restconf.server.spi.ApiPathNormalizer.OperationPath;
+import org.opendaylight.restconf.server.spi.ApiPathNormalizer.Path.Action;
import org.opendaylight.restconf.server.spi.ApiPathNormalizer.Path.Data;
import org.opendaylight.restconf.server.spi.ApiPathNormalizer.Path.Rpc;
import org.opendaylight.restconf.server.spi.OperationInput;
public @NonNull RestconfFuture<OperationsPostResult> operationsPOST(final URI restconfURI, final ApiPath apiPath,
final OperationInputBody body) {
- final OperationPath.Rpc path;
+ final Rpc path;
try {
path = pathNormalizer.normalizeRpcPath(apiPath);
} catch (RestconfDocumentedException e) {
resourceBody, queryParameters);
}
}
- if (path instanceof OperationPath.Action actionPath) {
+ if (path instanceof Action actionPath) {
try (var inputBody = body.toOperationInput()) {
return dataInvokePOST(actionPath, inputBody);
}
return ret;
}
- private @NonNull RestconfFuture<InvokeOperation> dataInvokePOST(final OperationPath.Action path,
- final OperationInputBody body) {
+ private @NonNull RestconfFuture<InvokeOperation> dataInvokePOST(final Action path, final OperationInputBody body) {
final var inference = path.inference();
final ContainerNode input;
try {
* @return {@link DOMActionResult}
*/
private static RestconfFuture<DOMActionResult> dataInvokePOST(final DOMActionService actionService,
- final OperationPath.Action path, final @NonNull ContainerNode input) {
+ final Action path, final @NonNull ContainerNode input) {
final var ret = new SettableRestconfFuture<DOMActionResult>();
Futures.addCallback(actionService.invokeAction(
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.nb.rfc8040.Insert.PointNormalizer;
import org.opendaylight.restconf.server.api.DatabindContext;
+import org.opendaylight.restconf.server.spi.ApiPathNormalizer.Path.Action;
import org.opendaylight.restconf.server.spi.ApiPathNormalizer.Path.Data;
import org.opendaylight.restconf.server.spi.ApiPathNormalizer.Path.Rpc;
import org.opendaylight.yangtools.yang.common.ErrorTag;
final var stack = SchemaInferenceStack.of(modelContext);
final var stmt = stack.enterSchemaTree(rpc.argument());
verify(rpc.equals(stmt), "Expecting %s, inferred %s", rpc, stmt);
- return new OperationPath.Rpc(stack.toInference(), rpc);
+ return new Rpc(stack.toInference(), rpc);
}
final var stack = SchemaInferenceStack.of(modelContext);
final var actionStmt = action.asEffectiveStatement();
verify(actionStmt.equals(stmt), "Expecting %s, inferred %s", actionStmt, stmt);
- return new OperationPath.Action(stack.toInference(), YangInstanceIdentifier.of(path), actionStmt);
+ return new Action(stack.toInference(), YangInstanceIdentifier.of(path), actionStmt);
}
}
if (path instanceof Data dataPath) {
return dataPath;
}
- if (path instanceof OperationPath.Action actionPath) {
+ if (path instanceof Action actionPath) {
return actionPath;
}
throw new RestconfDocumentedException("Unexpected path " + path, ErrorType.PROTOCOL, ErrorTag.DATA_MISSING);