From: Ivan Hrasko Date: Fri, 20 Jan 2023 09:10:21 +0000 (+0100) Subject: Remove target schema node X-Git-Tag: v5.0.1~1 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;ds=inline;h=239a0b7ecedfa623e9d233e2ff74e8a8cd365516;p=netconf.git Remove target schema node Searching for target schema node is used only to verify that we have "parsed" a schema node from input. Its not needed to be processed in XMLPatchBodyReader and if payload is invalid we get errors from other places. Change-Id: I777999b61e3c6bd891f255d0bc301a65b1628034 Signed-off-by: Ivan Hrasko --- diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java index 2a566a8a49..0e9fd3703b 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java @@ -7,8 +7,6 @@ */ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch; -import static com.google.common.base.Verify.verify; - import com.google.common.collect.ImmutableList; import java.io.IOException; import java.io.InputStream; @@ -41,8 +39,6 @@ import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree; -import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,14 +90,11 @@ public class XmlPatchBodyReader extends AbstractPatchBodyReader { final List values = readValueNodes(element, oper); final Element firstValueElement = values != null ? values.get(0) : null; - // find complete path to target and target schema node - // target can be also empty (only slash) - YangInstanceIdentifier targetII; - final SchemaNode targetNode; + // find complete path to target, it can be also empty (only slash) + final YangInstanceIdentifier targetII; final Inference inference; if (target.equals("/")) { targetII = pathContext.getInstanceIdentifier(); - targetNode = pathContext.getSchemaContext(); inference = pathContext.inference(); } else { // interpret as simple context @@ -116,20 +109,6 @@ public class XmlPatchBodyReader extends AbstractPatchBodyReader { if (!stack.isEmpty()) { stack.exit(); } - - if (stack.isEmpty()) { - targetNode = pathContext.getSchemaContext(); - } else { - final EffectiveStatement parentStmt = stack.currentStatement(); - verify(parentStmt instanceof SchemaNode, "Unexpected parent %s", parentStmt); - targetNode = (SchemaNode) parentStmt; - } - } - - if (targetNode == null) { - LOG.debug("Target node {} not found in path {} ", target, pathContext.getSchemaNode()); - throw new RestconfDocumentedException("Error parsing input", ErrorType.PROTOCOL, - ErrorTag.MALFORMED_MESSAGE); } if (oper.isWithValue()) { @@ -137,11 +116,13 @@ public class XmlPatchBodyReader extends AbstractPatchBodyReader { final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder); final XmlParserStream xmlParser = XmlParserStream.create(writer, inference); xmlParser.traverse(new DOMSource(firstValueElement)); + // for lists allow to manipulate with list items through their parent if (targetII.getLastPathArgument() instanceof NodeIdentifierWithPredicates) { - targetII = targetII.getParent(); + resultCollection.add(new PatchEntity(editId, oper, targetII.getParent(), resultHolder.getResult())); + } else { + resultCollection.add(new PatchEntity(editId, oper, targetII, resultHolder.getResult())); } - resultCollection.add(new PatchEntity(editId, oper, targetII, resultHolder.getResult())); } else { resultCollection.add(new PatchEntity(editId, oper, targetII)); }