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;
+import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
@SuppressWarnings("checkstyle:IllegalCatch")
- public PatchContext readFrom(final String uriPath, final InputStream entityStream) throws
- RestconfDocumentedException {
+ public PatchContext readFrom(final String uriPath, final InputStream entityStream)
+ throws RestconfDocumentedException {
try {
return readFrom(
ParserIdentifier.toInstanceIdentifier(uriPath, getSchemaContext(),
Optional.ofNullable(getMountPointService())), entityStream);
} catch (final Exception e) {
- propagateExceptionAs(e);
- return null; // no-op
+ throw propagateExceptionAs(e);
}
}
- private static RuntimeException propagateExceptionAs(final Exception exception) throws RestconfDocumentedException {
+ private static RestconfDocumentedException propagateExceptionAs(final Exception exception)
+ throws RestconfDocumentedException {
Throwables.throwIfInstanceOf(exception, RestconfDocumentedException.class);
LOG.debug("Error parsing json input", exception);
final String target = in.nextString();
if (target.equals("/")) {
edit.setTarget(path.getInstanceIdentifier());
- edit.setTargetSchemaNode(path.getSchemaContext());
+ edit.setTargetSchemaNode(SchemaInferenceStack.of(path.getSchemaContext()).toInference());
} else {
edit.setTarget(ParserIdentifier.parserPatchTarget(path, target));
- final EffectiveStatement<?, ?> parentStmt = SchemaInferenceStack.ofInstantiatedPath(
- path.getSchemaContext(),
- schemaTree.findChild(edit.getTarget()).orElseThrow().getDataSchemaNode()
- .getPath().getParent())
- .currentStatement();
- verify(parentStmt instanceof SchemaNode, "Unexpected parent %s", parentStmt);
- edit.setTargetSchemaNode((SchemaNode) parentStmt);
+ final var stack = schemaTree.enterPath(edit.getTarget()).orElseThrow().stack();
+ if (!stack.isEmpty()) {
+ stack.exit();
+ }
+
+ if (!stack.isEmpty()) {
+ final EffectiveStatement<?, ?> parentStmt = stack.currentStatement();
+ verify(parentStmt instanceof SchemaNode, "Unexpected parent %s", parentStmt);
+ }
+ edit.setTargetSchemaNode(stack.toInference());
}
break;
* @return NormalizedNode representing data
*/
private static NormalizedNode readEditData(final @NonNull JsonReader in,
- final @NonNull SchemaNode targetSchemaNode, final @NonNull InstanceIdentifierContext path) {
+ final @NonNull Inference targetSchemaNode, final @NonNull InstanceIdentifierContext path) {
final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
JsonParserStream.create(writer, JSONCodecFactorySupplier.RFC7951.getShared(path.getSchemaContext()),
- SchemaInferenceStack.ofInstantiatedPath(path.getSchemaContext(), targetSchemaNode.getPath()).toInference())
- .parse(in);
+ targetSchemaNode).parse(in);
return resultHolder.getResult();
}
private String id;
private PatchEditOperation operation;
private YangInstanceIdentifier target;
- private SchemaNode targetSchemaNode;
+ private Inference targetSchemaNode;
private NormalizedNode data;
String getId() {
this.target = requireNonNull(target);
}
- SchemaNode getTargetSchemaNode() {
+ Inference getTargetSchemaNode() {
return targetSchemaNode;
}
- void setTargetSchemaNode(final SchemaNode targetSchemaNode) {
+ void setTargetSchemaNode(final Inference targetSchemaNode) {
this.targetSchemaNode = requireNonNull(targetSchemaNode);
}