From fa5c6323b73fb6dc90e4374caec85d1bf000dfc9 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 21 Mar 2022 17:29:03 +0100 Subject: [PATCH] Build Absolute schema node identifier along with YangInstanceIdentifier The nested notification transformation algorithm is rather lacking -- it does not really deal with anything but 'container' and 'list'. This makes it borderline-trivial to eliminate the use of SchemaNode.getPath() by keeping a List which is a companion to YangInstanceIdentifierBuilder. JIRA: NETCONF-817 Change-Id: I95290d7399ae1d729bb68e76e3bf902a930add4f Signed-off-by: Robert Varga --- .../mapping/NetconfMessageTransformer.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java index 38071653df..591a940279 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java @@ -29,6 +29,7 @@ import java.net.URISyntaxException; import java.time.Instant; import java.util.AbstractMap; import java.util.ArrayDeque; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Deque; @@ -222,40 +223,43 @@ public class NetconfMessageTransformer implements MessageTransformer(), YangInstanceIdentifier.builder())); } } return Optional.empty(); } + // FIXME: this method is using QNames which are not bound to a Revision. Why is that? + // FIXME: furthermore this does not handle the entirety of schema layout: notably missing a choice/case schema nodes private NestedNotificationInfo traverseXmlNodeContainingNotification(final Node xmlNode, - final SchemaNode schemaNode, final InstanceIdentifierBuilder instanceBuilder) { + final SchemaNode schemaNode, final List schemaBuilder, + final InstanceIdentifierBuilder instanceBuilder) { if (schemaNode instanceof ContainerSchemaNode) { - ContainerSchemaNode dataContainerNode = (ContainerSchemaNode) schemaNode; + final var containerSchema = (ContainerSchemaNode) schemaNode; instanceBuilder.node(QName.create(xmlNode.getNamespaceURI(), xmlNode.getLocalName())); + schemaBuilder.add(containerSchema.getQName()); - Entry xmlContainerChildPair = findXmlContainerChildPair(xmlNode, dataContainerNode); + Entry xmlContainerChildPair = findXmlContainerChildPair(xmlNode, containerSchema); return traverseXmlNodeContainingNotification(xmlContainerChildPair.getKey(), - xmlContainerChildPair.getValue(), instanceBuilder); + xmlContainerChildPair.getValue(), schemaBuilder, instanceBuilder); } else if (schemaNode instanceof ListSchemaNode) { - ListSchemaNode listSchemaNode = (ListSchemaNode) schemaNode; + final var listSchema = (ListSchemaNode) schemaNode; instanceBuilder.node(QName.create(xmlNode.getNamespaceURI(), xmlNode.getLocalName())); + schemaBuilder.add(listSchema.getQName()); - Map listKeys = findXmlListKeys(xmlNode, listSchemaNode); + Map listKeys = findXmlListKeys(xmlNode, listSchema); instanceBuilder.nodeWithKey(QName.create(xmlNode.getNamespaceURI(), xmlNode.getLocalName()), listKeys); - Entry xmlListChildPair = findXmlListChildPair(xmlNode, listSchemaNode); + Entry xmlListChildPair = findXmlListChildPair(xmlNode, listSchema); return traverseXmlNodeContainingNotification(xmlListChildPair.getKey(), - xmlListChildPair.getValue(), instanceBuilder); + xmlListChildPair.getValue(), schemaBuilder, instanceBuilder); } else if (schemaNode instanceof NotificationDefinition) { // FIXME: this should not be here: it does not form a valid YangInstanceIdentifier instanceBuilder.node(QName.create(xmlNode.getNamespaceURI(), xmlNode.getLocalName())); + schemaBuilder.add(schemaNode.getQName()); - final var notificationDefinition = (NotificationDefinition) schemaNode; - // FIXME: do not use SchemaNode.getPath() here. We should have a companion project to 'builder' to carry - // the same things - return new NestedNotificationInfo(notificationDefinition.getPath().asAbsolute(), + return new NestedNotificationInfo(Absolute.of(schemaBuilder), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, instanceBuilder.build()), xmlNode); } throw new IllegalStateException("No notification found"); @@ -274,7 +278,7 @@ public class NetconfMessageTransformer implements MessageTransformer(currentNode, schemaChildNode); + return Map.entry(currentNode, schemaChildNode); } } } -- 2.36.6