From 191693041f1f0214b104ec826dce839cb61f2bc4 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 21 Mar 2022 10:18:04 +0100 Subject: [PATCH] Revert "Remove SchemaNode#getPath from ControllerContext" This reverts commit 7815d63f3d34f7a7664a2e551d2bdfdb844b6a95. The assumptsions being made are just not correct. Change-Id: I8d45c765f5f24a72ce5f43e511c8f8fb0b4978d0 Signed-off-by: Robert Varga --- .../sal/restconf/impl/ControllerContext.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java index 4ce6f060f5..313b71d704 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java @@ -533,10 +533,9 @@ public final class ControllerContext implements EffectiveModelContextListener, C return null; } - final EffectiveModelContext modelContext = mountPoint != null ? getModelContext(mountPoint) : globalSchema; - if (strings.isEmpty()) { - return createContext(builder.build(), (DataSchemaNode) parentNode, mountPoint, modelContext); + return createContext(builder.build(), (DataSchemaNode) parentNode, mountPoint, + mountPoint != null ? getModelContext(mountPoint) : globalSchema); } final String head = strings.iterator().next(); @@ -634,7 +633,8 @@ public final class ControllerContext implements EffectiveModelContextListener, C rpc = getRpcDefinition(module, rpcName); } if (rpc != null) { - return new InstanceIdentifierContext<>(builder.build(), rpc, mountPoint, modelContext); + return new InstanceIdentifierContext<>(builder.build(), rpc, mountPoint, + mountPoint != null ? getModelContext(mountPoint) : globalSchema); } } @@ -695,12 +695,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); } - final SchemaInferenceStack stack = SchemaInferenceStack.of(modelContext); - final YangInstanceIdentifier identifier = builder.build(); - identifier.getPathArguments().forEach(p -> stack.enterSchemaTree(p.getNodeType())); - stack.enterSchemaTree(targetNode.getQName()); - stack.enterSchemaTree(key); - addKeyValue(keyValues, listNode.getDataChildByName(key), uriKeyValue, mountPoint, stack); + addKeyValue(keyValues, listNode.getDataChildByName(key), uriKeyValue, mountPoint); index++; } } @@ -717,7 +712,8 @@ public final class ControllerContext implements EffectiveModelContextListener, C returnJustMountPoint); } - return createContext(builder.build(), targetNode, mountPoint, modelContext); + return createContext(builder.build(), targetNode, mountPoint, + mountPoint != null ? getModelContext(mountPoint) : globalSchema); } private static InstanceIdentifierContext createContext(final YangInstanceIdentifier instance, @@ -774,21 +770,23 @@ public final class ControllerContext implements EffectiveModelContextListener, C } private void addKeyValue(final HashMap map, final DataSchemaNode node, final String uriValue, - final DOMMountPoint mountPoint, final SchemaInferenceStack stack) { + final DOMMountPoint mountPoint) { checkArgument(node instanceof LeafSchemaNode); + final EffectiveModelContext schemaContext = mountPoint == null ? globalSchema : getModelContext(mountPoint); final String urlDecoded = urlPathArgDecode(requireNonNull(uriValue)); TypeDefinition typedef = ((LeafSchemaNode) node).getType(); final TypeDefinition baseType = RestUtil.resolveBaseTypeFrom(typedef); if (baseType instanceof LeafrefTypeDefinition) { - typedef = stack.resolveLeafref((LeafrefTypeDefinition) baseType); + typedef = SchemaInferenceStack.ofInstantiatedPath(schemaContext, node.getPath()) + .resolveLeafref((LeafrefTypeDefinition) baseType); } final IllegalArgumentCodec codec = RestCodec.from(typedef, mountPoint, this); Object decoded = codec.deserialize(urlDecoded); String additionalInfo = ""; if (decoded == null) { if (typedef instanceof IdentityrefTypeDefinition) { - decoded = toQName(stack.getEffectiveModelContext(), urlDecoded); + decoded = toQName(schemaContext, urlDecoded); additionalInfo = "For key which is of type identityref it should be in format module_name:identity_name."; } -- 2.36.6