From d6bfb9c3a0e143d70d5daba6b0f255898b4e9528 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 28 Jul 2022 17:57:48 +0200 Subject: [PATCH] Move restconf.common.util The contents of this package is only used by RestconfOperationsServiceImpl, move them there and mark them as reprecated. JIRA: NETCONF-837 Change-Id: I8624be2d6d55f78e01004da718d93c30399f31f1 Signed-off-by: Robert Varga --- restconf/restconf-common/pom.xml | 16 ----- .../common/util/OperationsResourceUtils.java | 70 ------------------- restconf/restconf-nb-rfc8040/pom.xml | 12 ++++ .../AbstractOperationDataSchemaNode.java | 3 +- .../impl}/AbstractOperationsModule.java | 30 ++++---- .../impl}/OperationsContainerSchemaNode.java | 18 ++--- .../OperationsEffectiveModuleContext.java | 5 +- .../impl}/OperationsImportedModule.java | 3 +- .../impl}/OperationsLeafSchemaNode.java | 7 +- .../impl}/OperationsRestconfModule.java | 3 +- .../impl/RestconfOperationsServiceImpl.java | 56 ++++++++++++++- 11 files changed, 104 insertions(+), 119 deletions(-) delete mode 100644 restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsResourceUtils.java rename restconf/{restconf-common/src/main/java/org/opendaylight/restconf/common/util => restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl}/AbstractOperationDataSchemaNode.java (92%) rename restconf/{restconf-common/src/main/java/org/opendaylight/restconf/common/util => restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl}/AbstractOperationsModule.java (90%) rename restconf/{restconf-common/src/main/java/org/opendaylight/restconf/common/util => restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl}/OperationsContainerSchemaNode.java (89%) rename restconf/{restconf-common/src/main/java/org/opendaylight/restconf/common/util => restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl}/OperationsEffectiveModuleContext.java (88%) rename restconf/{restconf-common/src/main/java/org/opendaylight/restconf/common/util => restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl}/OperationsImportedModule.java (93%) rename restconf/{restconf-common/src/main/java/org/opendaylight/restconf/common/util => restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl}/OperationsLeafSchemaNode.java (90%) rename restconf/{restconf-common/src/main/java/org/opendaylight/restconf/common/util => restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl}/OperationsRestconfModule.java (94%) diff --git a/restconf/restconf-common/pom.xml b/restconf/restconf-common/pom.xml index c74ef8bfd0..ac042efd60 100644 --- a/restconf/restconf-common/pom.xml +++ b/restconf/restconf-common/pom.xml @@ -43,30 +43,14 @@ org.opendaylight.yangtools yang-data-util - - org.opendaylight.yangtools - yang-data-impl - org.opendaylight.yangtools yang-model-api - - org.opendaylight.yangtools - yang-model-ri - - - org.opendaylight.yangtools - yang-model-spi - org.opendaylight.yangtools yang-model-util - - org.opendaylight.yangtools - yang-xpath-api - org.opendaylight.mdsal mdsal-dom-api diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsResourceUtils.java b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsResourceUtils.java deleted file mode 100644 index ada0442bc0..0000000000 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsResourceUtils.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.restconf.common.util; - -import com.google.common.collect.ImmutableSet; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; -import java.util.Map.Entry; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.opendaylight.mdsal.dom.api.DOMMountPoint; -import org.opendaylight.restconf.common.context.InstanceIdentifierContext; -import org.opendaylight.yangtools.yang.common.Empty; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.RpcDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack; - - -// FIXME: remove this class -public final class OperationsResourceUtils { - private OperationsResourceUtils() { - // Hidden on purpose - } - - public static @NonNull Entry - contextForModelContext(final @NonNull SchemaContext context, final @Nullable DOMMountPoint mountPoint) { - // Determine which modules we need and construct leaf schemas to correspond to all RPC definitions - final Collection modules = new ArrayList<>(); - final ArrayList rpcLeafSchemas = new ArrayList<>(); - for (final Module m : context.getModules()) { - final Collection rpcs = m.getRpcs(); - if (!rpcs.isEmpty()) { - modules.add(new OperationsImportedModule(m)); - rpcLeafSchemas.ensureCapacity(rpcLeafSchemas.size() + rpcs.size()); - for (RpcDefinition rpc : rpcs) { - rpcLeafSchemas.add(new OperationsLeafSchemaNode(rpc)); - } - } - } - - // Now generate a module for RESTCONF so that operations contain what they need - final OperationsContainerSchemaNode operatationsSchema = new OperationsContainerSchemaNode(rpcLeafSchemas); - modules.add(new OperationsRestconfModule(operatationsSchema)); - - // Now build the operations container and combine it with the context - final DataContainerNodeBuilder operationsBuilder = Builders.containerBuilder() - .withNodeIdentifier(new NodeIdentifier(OperationsContainerSchemaNode.QNAME)); - for (final OperationsLeafSchemaNode leaf : rpcLeafSchemas) { - operationsBuilder.withChild(ImmutableNodes.leafNode(leaf.getQName(), Empty.value())); - } - - final var opContext = new OperationsEffectiveModuleContext(ImmutableSet.copyOf(modules)); - final var stack = SchemaInferenceStack.of(opContext); - stack.enterSchemaTree(operatationsSchema.getQName()); - - return Map.entry(InstanceIdentifierContext.ofStack(stack, mountPoint), operationsBuilder.build()); - } -} diff --git a/restconf/restconf-nb-rfc8040/pom.xml b/restconf/restconf-nb-rfc8040/pom.xml index 7e18595554..27894c7516 100644 --- a/restconf/restconf-nb-rfc8040/pom.xml +++ b/restconf/restconf-nb-rfc8040/pom.xml @@ -117,6 +117,14 @@ org.opendaylight.yangtools yang-model-api + + org.opendaylight.yangtools + yang-model-ri + + + org.opendaylight.yangtools + yang-model-spi + org.opendaylight.yangtools yang-model-util @@ -129,6 +137,10 @@ org.opendaylight.yangtools yang-repo-api + + org.opendaylight.yangtools + yang-xpath-api + org.opendaylight.mdsal diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/AbstractOperationDataSchemaNode.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/AbstractOperationDataSchemaNode.java similarity index 92% rename from restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/AbstractOperationDataSchemaNode.java rename to restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/AbstractOperationDataSchemaNode.java index 02dc370964..5e6f4fa470 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/AbstractOperationDataSchemaNode.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/AbstractOperationDataSchemaNode.java @@ -5,13 +5,14 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.restconf.common.util; +package org.opendaylight.restconf.nb.rfc8040.rests.services.impl; import java.util.Optional; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.Status; import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression.QualifiedBound; +@Deprecated(forRemoval = true, since = "4.0.0") abstract class AbstractOperationDataSchemaNode implements DataSchemaNode { @Override public final Status getStatus() { diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/AbstractOperationsModule.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/AbstractOperationsModule.java similarity index 90% rename from restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/AbstractOperationsModule.java rename to restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/AbstractOperationsModule.java index ac61f7a50b..b0349162a1 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/AbstractOperationsModule.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/AbstractOperationsModule.java @@ -5,12 +5,13 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.restconf.common.util; +package org.opendaylight.restconf.nb.rfc8040.rests.services.impl; import java.util.Collection; -import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.UnresolvedQName; @@ -36,6 +37,7 @@ import org.opendaylight.yangtools.yang.model.api.meta.StatementOrigin; import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement; +@Deprecated(forRemoval = true, since = "4.0.0") abstract class AbstractOperationsModule implements Module, ModuleEffectiveStatement { @Override public final ModuleStatement getDeclared() { @@ -76,7 +78,7 @@ abstract class AbstractOperationsModule implements Module, ModuleEffectiveStatem @Override public final Collection getImports() { // Yeah, not accurate, but this should not be needed - return Collections.emptySet(); + return Set.of(); } @Override @@ -86,17 +88,17 @@ abstract class AbstractOperationsModule implements Module, ModuleEffectiveStatem @Override public final Collection> getTypeDefinitions() { - return Collections.emptySet(); + return Set.of(); } @Override public final Collection getGroupings() { - return Collections.emptySet(); + return Set.of(); } @Override public final Collection getUses() { - return Collections.emptySet(); + return Set.of(); } @Override @@ -111,7 +113,7 @@ abstract class AbstractOperationsModule implements Module, ModuleEffectiveStatem @Override public final Collection getNotifications() { - return Collections.emptySet(); + return Set.of(); } @Override @@ -126,37 +128,37 @@ abstract class AbstractOperationsModule implements Module, ModuleEffectiveStatem @Override public final Collection getSubmodules() { - return Collections.emptySet(); + return Set.of(); } @Override public final Collection getFeatures() { - return Collections.emptySet(); + return Set.of(); } @Override public final Collection getAugmentations() { - return Collections.emptySet(); + return Set.of(); } @Override public final Collection getRpcs() { - return Collections.emptySet(); + return Set.of(); } @Override public final Collection getDeviations() { - return Collections.emptySet(); + return Set.of(); } @Override public final Collection getIdentities() { - return Collections.emptySet(); + return Set.of(); } @Override public final Collection getExtensionSchemaNodes() { - return Collections.emptyList(); + return List.of(); } @Override diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsContainerSchemaNode.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsContainerSchemaNode.java similarity index 89% rename from restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsContainerSchemaNode.java rename to restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsContainerSchemaNode.java index a61a6632d3..587030ce21 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsContainerSchemaNode.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsContainerSchemaNode.java @@ -5,13 +5,12 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.restconf.common.util; +package org.opendaylight.restconf.nb.rfc8040.rests.services.impl; import static java.util.Objects.requireNonNull; import com.google.common.collect.Maps; import java.util.Collection; -import java.util.Collections; import java.util.Map; import java.util.Set; import org.eclipse.jdt.annotation.NonNull; @@ -27,6 +26,7 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.UsesNode; import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement; +@Deprecated(forRemoval = true, since = "4.0.0") final class OperationsContainerSchemaNode extends AbstractOperationDataSchemaNode implements ContainerSchemaNode { // There is no need to intern this nor add a revision, as we are providing the corresponding context anyway static final @NonNull QName QNAME = QName.create(OperationsRestconfModule.NAMESPACE, "operations"); @@ -55,37 +55,37 @@ final class OperationsContainerSchemaNode extends AbstractOperationDataSchemaNod @Override public Set> getTypeDefinitions() { - return Collections.emptySet(); + return Set.of(); } @Override public Set getGroupings() { - return Collections.emptySet(); + return Set.of(); } @Override public Set getUses() { - return Collections.emptySet(); + return Set.of(); } @Override public Set getAvailableAugmentations() { - return Collections.emptySet(); + return Set.of(); } @Override public Set getNotifications() { - return Collections.emptySet(); + return Set.of(); } @Override public Set getActions() { - return Collections.emptySet(); + return Set.of(); } @Override public Collection<@NonNull MustDefinition> getMustConstraints() { - return Collections.emptySet(); + return Set.of(); } @Override diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsEffectiveModuleContext.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsEffectiveModuleContext.java similarity index 88% rename from restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsEffectiveModuleContext.java rename to restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsEffectiveModuleContext.java index 35fffa052b..c49413e3c9 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsEffectiveModuleContext.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsEffectiveModuleContext.java @@ -5,7 +5,7 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.restconf.common.util; +package org.opendaylight.restconf.nb.rfc8040.rests.services.impl; import static com.google.common.base.Verify.verify; @@ -19,8 +19,9 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement; import org.opendaylight.yangtools.yang.model.spi.SimpleSchemaContext; +@Deprecated(forRemoval = true, since = "4.0.0") final class OperationsEffectiveModuleContext extends SimpleSchemaContext implements EffectiveModelContext { - private final Map modules; + private final ImmutableMap modules; OperationsEffectiveModuleContext(final Set modules) { super(modules); diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsImportedModule.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsImportedModule.java similarity index 93% rename from restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsImportedModule.java rename to restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsImportedModule.java index 5551326fa4..5f9d868528 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsImportedModule.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsImportedModule.java @@ -5,7 +5,7 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.restconf.common.util; +package org.opendaylight.restconf.nb.rfc8040.rests.services.impl; import static java.util.Objects.requireNonNull; @@ -17,6 +17,7 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; +@Deprecated(forRemoval = true, since = "4.0.0") final class OperationsImportedModule extends AbstractOperationsModule { private final Module original; diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsLeafSchemaNode.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsLeafSchemaNode.java similarity index 90% rename from restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsLeafSchemaNode.java rename to restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsLeafSchemaNode.java index a0d231f870..556512f11a 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsLeafSchemaNode.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsLeafSchemaNode.java @@ -5,10 +5,10 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.restconf.common.util; +package org.opendaylight.restconf.nb.rfc8040.rests.services.impl; import java.util.Collection; -import java.util.Collections; +import java.util.Set; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; @@ -18,6 +18,7 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement; import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes; +@Deprecated(forRemoval = true, since = "4.0.0") final class OperationsLeafSchemaNode extends AbstractOperationDataSchemaNode implements LeafSchemaNode { private final QName qname; @@ -43,7 +44,7 @@ final class OperationsLeafSchemaNode extends AbstractOperationDataSchemaNode imp @Override public Collection<@NonNull MustDefinition> getMustConstraints() { - return Collections.emptySet(); + return Set.of(); } @Override diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsRestconfModule.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsRestconfModule.java similarity index 94% rename from restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsRestconfModule.java rename to restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsRestconfModule.java index 467db9b4bf..d14dfdf264 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/OperationsRestconfModule.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/OperationsRestconfModule.java @@ -5,7 +5,7 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.restconf.common.util; +package org.opendaylight.restconf.nb.rfc8040.rests.services.impl; import static java.util.Objects.requireNonNull; @@ -18,6 +18,7 @@ import org.opendaylight.yangtools.yang.common.XMLNamespace; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; +@Deprecated(forRemoval = true, since = "4.0.0") final class OperationsRestconfModule extends AbstractOperationsModule { // There is no need to intern this nor add a revision, as we are providing the corresponding context anyway static final @NonNull QNameModule NAMESPACE = diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java index 8cfa859799..ce95a84fb4 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java @@ -9,24 +9,39 @@ package org.opendaylight.restconf.nb.rfc8040.rests.services.impl; import static java.util.Objects.requireNonNull; +import com.google.common.collect.ImmutableSet; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.Map.Entry; import java.util.Optional; import javax.ws.rs.Path; import javax.ws.rs.core.UriInfo; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.mdsal.dom.api.DOMMountPoint; import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; -import org.opendaylight.restconf.common.util.OperationsResourceUtils; import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfOperationsService; import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants; import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.Builders; +import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.RpcDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,7 +90,7 @@ public class RestconfOperationsServiceImpl implements RestconfOperationsService final InstanceIdentifierContext mountPointIdentifier = ParserIdentifier.toInstanceIdentifier(identifier, schemaContextHandler.get(), Optional.of(mountPointService)); final DOMMountPoint mountPoint = mountPointIdentifier.getMountPoint(); - final var entry = OperationsResourceUtils.contextForModelContext(modelContext(mountPoint), mountPoint); + final var entry = contextForModelContext(modelContext(mountPoint), mountPoint); return NormalizedNodePayload.of(entry.getKey(), entry.getValue()); } @@ -84,4 +99,41 @@ public class RestconfOperationsServiceImpl implements RestconfOperationsService .flatMap(svc -> Optional.ofNullable(svc.getGlobalContext())) .orElse(null); } + + // FIXME: remove this method and everything it uses + @Deprecated(forRemoval = true, since = "4.0.0") + private static @NonNull Entry contextForModelContext( + final @NonNull EffectiveModelContext context, final @Nullable DOMMountPoint mountPoint) { + // Determine which modules we need and construct leaf schemas to correspond to all RPC definitions + final Collection modules = new ArrayList<>(); + final ArrayList rpcLeafSchemas = new ArrayList<>(); + for (final Module m : context.getModules()) { + final Collection rpcs = m.getRpcs(); + if (!rpcs.isEmpty()) { + modules.add(new OperationsImportedModule(m)); + rpcLeafSchemas.ensureCapacity(rpcLeafSchemas.size() + rpcs.size()); + for (RpcDefinition rpc : rpcs) { + rpcLeafSchemas.add(new OperationsLeafSchemaNode(rpc)); + } + } + } + + // Now generate a module for RESTCONF so that operations contain what they need + final OperationsContainerSchemaNode operatationsSchema = new OperationsContainerSchemaNode(rpcLeafSchemas); + modules.add(new OperationsRestconfModule(operatationsSchema)); + + // Now build the operations container and combine it with the context + final DataContainerNodeBuilder operationsBuilder = Builders.containerBuilder() + .withNodeIdentifier(new NodeIdentifier(OperationsContainerSchemaNode.QNAME)); + for (final OperationsLeafSchemaNode leaf : rpcLeafSchemas) { + operationsBuilder.withChild(ImmutableNodes.leafNode(leaf.getQName(), Empty.value())); + } + + final var opContext = new OperationsEffectiveModuleContext(ImmutableSet.copyOf(modules)); + final var stack = SchemaInferenceStack.of(opContext); + stack.enterSchemaTree(operatationsSchema.getQName()); + + return Map.entry(InstanceIdentifierContext.ofStack(stack, mountPoint), operationsBuilder.build()); + } + } -- 2.36.6