+ private @NonNull ResourceRequest bindResourceRequest(final @Nullable String identifier, final ResourceBody body) {
+ final var dataBind = databindProvider.currentContext();
+ final var context = ParserIdentifier.toInstanceIdentifier(identifier, dataBind.modelContext(),
+ mountPointService);
+ final var inference = context.inference();
+ final var path = context.getInstanceIdentifier();
+ final var data = body.toNormalizedNode(path, inference, context.getSchemaNode());
+
+ return new ResourceRequest(getRestconfStrategy(context.getMountPoint()), inference.getEffectiveModelContext(),
+ path, data);
+ }
+
+ /**
+ * Ordered list of edits that are applied to the target datastore by the server, as defined in
+ * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
+ *
+ * @param identifier path to target
+ * @param body YANG Patch body
+ * @return {@link PatchStatusContext}
+ */
+ @PATCH
+ @Path("/data/{identifier:.+}")
+ @Consumes(MediaTypes.APPLICATION_YANG_PATCH_XML)
+ @Produces({
+ MediaTypes.APPLICATION_YANG_DATA_JSON,
+ MediaTypes.APPLICATION_YANG_DATA_XML
+ })
+ public PatchStatusContext yangPatchDataXML(@Encoded @PathParam("identifier") final String identifier,
+ final InputStream body) {
+ try (var xmlBody = new XmlPatchBody(body)) {
+ return yangPatchData(identifier, xmlBody);
+ }
+ }
+
+ /**
+ * Ordered list of edits that are applied to the datastore by the server, as defined in
+ * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
+ *
+ * @param body YANG Patch body
+ * @return {@link PatchStatusContext}
+ */
+ @PATCH
+ @Path("/data")
+ @Consumes(MediaTypes.APPLICATION_YANG_PATCH_XML)
+ @Produces({
+ MediaTypes.APPLICATION_YANG_DATA_JSON,
+ MediaTypes.APPLICATION_YANG_DATA_XML
+ })
+ public PatchStatusContext yangPatchDataXML(final InputStream body) {
+ try (var xmlBody = new XmlPatchBody(body)) {
+ return yangPatchData(xmlBody);
+ }
+ }
+
+ /**
+ * Ordered list of edits that are applied to the target datastore by the server, as defined in
+ * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
+ *
+ * @param identifier path to target
+ * @param body YANG Patch body
+ * @return {@link PatchStatusContext}
+ */
+ @PATCH
+ @Path("/data/{identifier:.+}")
+ @Consumes(MediaTypes.APPLICATION_YANG_PATCH_JSON)
+ @Produces({
+ MediaTypes.APPLICATION_YANG_DATA_JSON,
+ MediaTypes.APPLICATION_YANG_DATA_XML
+ })
+ public PatchStatusContext yangPatchDataJSON(@Encoded @PathParam("identifier") final String identifier,
+ final InputStream body) {
+ try (var jsonBody = new JsonPatchBody(body)) {
+ return yangPatchData(identifier, jsonBody);
+ }
+ }
+
+ /**
+ * Ordered list of edits that are applied to the datastore by the server, as defined in
+ * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
+ *
+ * @param body YANG Patch body
+ * @return {@link PatchStatusContext}
+ */
+ @PATCH
+ @Path("/data")
+ @Consumes(MediaTypes.APPLICATION_YANG_PATCH_JSON)
+ @Produces({
+ MediaTypes.APPLICATION_YANG_DATA_JSON,
+ MediaTypes.APPLICATION_YANG_DATA_XML
+ })
+ public PatchStatusContext yangPatchDataJSON(final InputStream body) {
+ try (var jsonBody = new JsonPatchBody(body)) {
+ return yangPatchData(jsonBody);
+ }
+ }
+
+ private PatchStatusContext yangPatchData(final @NonNull PatchBody body) {
+ return yangPatchData(InstanceIdentifierContext.ofLocalRoot(databindProvider.currentContext().modelContext()),
+ body);
+ }
+
+ private PatchStatusContext yangPatchData(final String identifier, final @NonNull PatchBody body) {
+ return yangPatchData(ParserIdentifier.toInstanceIdentifier(identifier,
+ databindProvider.currentContext().modelContext(), mountPointService), body);
+ }
+
+ private PatchStatusContext yangPatchData(final @NonNull InstanceIdentifierContext targetResource,
+ final @NonNull PatchBody body) {
+ try {
+ return yangPatchData(targetResource, body.toPatchContext(targetResource));
+ } catch (IOException e) {
+ LOG.debug("Error parsing YANG Patch input", e);
+ throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
+ ErrorTag.MALFORMED_MESSAGE, e);
+ }
+ }
+
+ @VisibleForTesting
+ PatchStatusContext yangPatchData(final InstanceIdentifierContext targetResource, final PatchContext context) {
+ return PatchDataTransactionUtil.patchData(context, getRestconfStrategy(targetResource.getMountPoint()),
+ targetResource.getSchemaContext());
+ }
+