From 7de35b93e379dce95e06150f0ef87694b03f393c Mon Sep 17 00:00:00 2001 From: Samuel Schneider Date: Tue, 6 Feb 2024 10:29:02 +0100 Subject: [PATCH] Create overloaded constructors for PathEntity Create overloaded constructors for PathEntity. This was done to avoid using null for PathEntity creation. JIRA: NETCONF-1240 Change-Id: I231a596537fca238990fb231f7015f24c9931aed Signed-off-by: lubos-cicut Signed-off-by: Ivan Hrasko --- .../restconf/openapi/impl/PathsStream.java | 33 ++++----- .../restconf/openapi/model/PathEntity.java | 73 ++++++++++++++++--- 2 files changed, 78 insertions(+), 28 deletions(-) diff --git a/restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/impl/PathsStream.java b/restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/impl/PathsStream.java index 8a07b30a15..a8f8911934 100644 --- a/restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/impl/PathsStream.java +++ b/restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/impl/PathsStream.java @@ -160,13 +160,11 @@ public final class PathsStream extends InputStream { final var result = new ArrayDeque(); if (includeDataStore && !hasAddedDataStore) { final var dataPath = basePath + DATA + urlPrefix; - result.add(new PathEntity(dataPath, null, null, null, - new GetEntity(null, deviceName, "data", null, null, false), - null)); + result.add(new PathEntity(dataPath, + new GetEntity(null, deviceName, "data", null, null, false))); final var operationsPath = basePath + OPERATIONS + urlPrefix; - result.add(new PathEntity(operationsPath, null, null, null, - new GetEntity(null, deviceName, "operations", null, null, false), - null)); + result.add(new PathEntity(operationsPath, + new GetEntity(null, deviceName, "operations", null, null, false))); hasAddedDataStore = true; } // RPC operations (via post) - RPCs have their own path @@ -174,7 +172,7 @@ public final class PathsStream extends InputStream { final var localName = rpc.getQName().getLocalName(); final var post = new PostEntity(rpc, deviceName, module.getName(), new ArrayList<>(), localName, null); final var resolvedPath = basePath + OPERATIONS + urlPrefix + "/" + module.getName() + ":" + localName; - final var entity = new PathEntity(resolvedPath, post, null, null, null, null); + final var entity = new PathEntity(resolvedPath, post); result.add(entity); } for (final var node : module.getChildNodes()) { @@ -185,8 +183,8 @@ public final class PathsStream extends InputStream { if (node instanceof ListSchemaNode || node instanceof ContainerSchemaNode) { if (isConfig && !hasRootPostLink && isForSingleModule) { final var resolvedPath = basePath + DATA + urlPrefix; - result.add(new PathEntity(resolvedPath, new PostEntity(node, deviceName, moduleName, - new ArrayList<>(), nodeLocalName, module), null, null, null, null)); + result.add(new PathEntity(resolvedPath, + new PostEntity(node, deviceName, moduleName, new ArrayList<>(), nodeLocalName, module))); hasRootPostLink = true; } //process first node @@ -221,7 +219,7 @@ public final class PathsStream extends InputStream { final var resourceActionPath = path + "/" + resolvePathArgumentsName(actionDef.getQName(), node.getQName(), schemaContext); final var childPath = basePath + OPERATIONS + resourceActionPath; - result.add(processRootAndActionPathEntity(actionDef, childPath, actionParams, moduleName, + result.add(processActionPathEntity(actionDef, childPath, actionParams, moduleName, refPath, deviceName, parentNode)); }); } @@ -248,14 +246,14 @@ public final class PathsStream extends InputStream { final List pathParams, final String moduleName, final String refPath, final boolean isConfig, final String fullName, final String deviceName) { if (isConfig) { - return new PathEntity(resourcePath, null, + return new PathEntity(resourcePath, new PatchEntity(node, deviceName, moduleName, pathParams, refPath, fullName), new PutEntity(node, deviceName, moduleName, pathParams, refPath, fullName), new GetEntity(node, deviceName, moduleName, pathParams, refPath, true), new DeleteEntity(node, deviceName, moduleName, pathParams, refPath)); } else { - return new PathEntity(resourcePath, null, null, null, - new GetEntity(node, deviceName, moduleName, pathParams, refPath, false), null); + return new PathEntity(resourcePath, + new GetEntity(node, deviceName, moduleName, pathParams, refPath, false)); } } @@ -274,17 +272,16 @@ public final class PathsStream extends InputStream { new GetEntity(node, deviceName, moduleName, pathParams, refPath, true), new DeleteEntity(node, deviceName, moduleName, pathParams, refPath)); } else { - return new PathEntity(resourcePath, null, null, null, - new GetEntity(node, deviceName, moduleName, pathParams, refPath, false), null); + return new PathEntity(resourcePath, + new GetEntity(node, deviceName, moduleName, pathParams, refPath, false)); } } - private static PathEntity processRootAndActionPathEntity(final SchemaNode node, final String resourcePath, + private static PathEntity processActionPathEntity(final SchemaNode node, final String resourcePath, final List pathParams, final String moduleName, final String refPath, final String deviceName, final SchemaNode parentNode) { return new PathEntity(resourcePath, - new PostEntity(node, deviceName, moduleName, pathParams, refPath, parentNode), - null, null, null, null); + new PostEntity(node, deviceName, moduleName, pathParams, refPath, parentNode)); } private static String processPath(final DataSchemaNode node, final List pathParams, diff --git a/restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/model/PathEntity.java b/restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/model/PathEntity.java index cd0ff861dc..c3c8a7afac 100644 --- a/restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/model/PathEntity.java +++ b/restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/model/PathEntity.java @@ -7,9 +7,10 @@ */ package org.opendaylight.restconf.openapi.model; +import static java.util.Objects.requireNonNull; + import com.fasterxml.jackson.core.JsonGenerator; import java.io.IOException; -import java.util.Objects; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -17,18 +18,70 @@ public final class PathEntity extends OpenApiEntity { private final @NonNull String path; private final @Nullable PostEntity post; private final @Nullable PatchEntity patch; - private final @Nullable GetEntity get; private final @Nullable PutEntity put; + private final @Nullable GetEntity get; private final @Nullable DeleteEntity delete; - public PathEntity(final String path, final PostEntity post, final PatchEntity patch, - final PutEntity put, final GetEntity get, final DeleteEntity delete) { - this.path = Objects.requireNonNull(path); - this.post = post; - this.patch = patch; - this.put = put; - this.delete = delete; - this.get = get; + /** + * Construct new path instance pointing to top level config data. + * + *

+ * Paths to top level configuration data allows full CRUD operations (including POST). + */ + public PathEntity(final @NonNull String path, final @NonNull PostEntity post, final @NonNull PatchEntity patch, + final @NonNull PutEntity put, final @NonNull GetEntity get, final @NonNull DeleteEntity delete) { + this.path = requireNonNull(path); + this.post = requireNonNull(post); + this.patch = requireNonNull(patch); + this.put = requireNonNull(put); + this.get = requireNonNull(get); + this.delete = requireNonNull(delete); + } + + /** + * Construct new path instance pointing child level config data. + * + *

+ * Paths to child level configuration data allows full CRUD operations (except of POST). + */ + public PathEntity(final @NonNull String path, final @NonNull PatchEntity patch, + final @NonNull PutEntity put, final @NonNull GetEntity get, final @NonNull DeleteEntity delete) { + this.path = requireNonNull(path); + this.post = null; + this.patch = requireNonNull(patch); + this.put = requireNonNull(put); + this.get = requireNonNull(get); + this.delete = requireNonNull(delete); + } + + /** + * Construct new path instance pointing to non-config data. + * + *

+ * Paths to non-configuration data are allowed to be read only. + */ + public PathEntity(final @NonNull String path, final @NonNull GetEntity get) { + this.path = requireNonNull(path); + this.post = null; + this.patch = null; + this.put = null; + this.get = requireNonNull(get); + this.delete = null; + } + + /** + * Construct new path instance pointing to operation (RPC/action). + * + *

+ * Operations are allowed to be invoked only. + */ + public PathEntity(final @NonNull String path, final @NonNull PostEntity post) { + this.path = requireNonNull(path); + this.get = null; + this.post = requireNonNull(post); + this.put = null; + this.patch = null; + this.delete = null; } @Override -- 2.36.6