Fix checkstyle
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / util / NetconfMessageTransformUtil.java
index 4cc4110653118a2b684b2aa0c42e132ae0e0219f..83d903b686d9ce993a9fb3249d5957b0338ce5d9 100644 (file)
@@ -7,29 +7,32 @@
  */
 package org.opendaylight.netconf.sal.connect.netconf.util;
 
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import java.io.IOException;
 import java.net.URI;
+import java.time.Instant;
 import java.time.format.DateTimeParseException;
 import java.util.AbstractMap;
+import java.util.AbstractMap.SimpleEntry;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Optional;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
-import org.opendaylight.controller.config.util.xml.DocumentedException;
-import org.opendaylight.controller.config.util.xml.XmlElement;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
+import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.FailedNetconfMessage;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.api.NetconfMessage;
+import org.opendaylight.netconf.api.xml.XmlElement;
+import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.notifications.NetconfNotification;
 import org.opendaylight.netconf.sal.connect.util.MessageCounter;
 import org.opendaylight.netconf.util.NetconfUtil;
@@ -41,10 +44,13 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.not
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -56,6 +62,8 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.SchemaOrderedNormalizedNodeWriter;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
+import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
+import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -65,7 +73,7 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-public class NetconfMessageTransformUtil {
+public final class NetconfMessageTransformUtil {
 
     private static final Logger LOG = LoggerFactory.getLogger(NetconfMessageTransformUtil.class);
 
@@ -80,7 +88,9 @@ public class NetconfMessageTransformUtil {
     private static final Document BLANK_DOCUMENT = XmlUtil.newDocument();
     public static final String EVENT_TIME = "eventTime";
 
-    private NetconfMessageTransformUtil() {}
+    private NetconfMessageTransformUtil() {
+
+    }
 
     public static final QName IETF_NETCONF_MONITORING =
             QName.create(NetconfState.QNAME, "ietf-netconf-monitoring").intern();
@@ -105,27 +115,52 @@ public class NetconfMessageTransformUtil {
     public static final URI NETCONF_URI = NETCONF_QNAME.getNamespace();
 
     public static final QName NETCONF_DATA_QNAME = QName.create(NETCONF_QNAME, "data").intern();
+    public static final NodeIdentifier NETCONF_DATA_NODEID = NodeIdentifier.create(NETCONF_DATA_QNAME);
+
     public static final QName NETCONF_RPC_REPLY_QNAME = QName.create(NETCONF_QNAME, "rpc-reply").intern();
     public static final QName NETCONF_OK_QNAME = QName.create(NETCONF_QNAME, "ok").intern();
     public static final QName NETCONF_ERROR_OPTION_QNAME = QName.create(NETCONF_QNAME, "error-option").intern();
+    public static final NodeIdentifier NETCONF_ERROR_OPTION_NODEID = NodeIdentifier.create(NETCONF_ERROR_OPTION_QNAME);
     public static final QName NETCONF_RUNNING_QNAME = QName.create(NETCONF_QNAME, "running").intern();
     public static final QName NETCONF_SOURCE_QNAME = QName.create(NETCONF_QNAME, "source").intern();
+    public static final NodeIdentifier NETCONF_SOURCE_NODEID = NodeIdentifier.create(NETCONF_SOURCE_QNAME);
     public static final QName NETCONF_CANDIDATE_QNAME = QName.create(NETCONF_QNAME, "candidate").intern();
     public static final QName NETCONF_TARGET_QNAME = QName.create(NETCONF_QNAME, "target").intern();
+    public static final NodeIdentifier NETCONF_TARGET_NODEID = NodeIdentifier.create(NETCONF_TARGET_QNAME);
     public static final QName NETCONF_CONFIG_QNAME = QName.create(NETCONF_QNAME, "config").intern();
+    public static final NodeIdentifier NETCONF_CONFIG_NODEID = NodeIdentifier.create(NETCONF_CONFIG_QNAME);
+
     public static final QName NETCONF_COMMIT_QNAME = QName.create(NETCONF_QNAME, "commit").intern();
+    public static final SchemaPath NETCONF_COMMIT_PATH = toPath(NETCONF_COMMIT_QNAME);
     public static final QName NETCONF_VALIDATE_QNAME = QName.create(NETCONF_QNAME, "validate").intern();
+    public static final NodeIdentifier NETCONF_VALIDATE_NODEID = NodeIdentifier.create(NETCONF_VALIDATE_QNAME);
+    public static final SchemaPath NETCONF_VALIDATE_PATH = toPath(NETCONF_VALIDATE_QNAME);
     public static final QName NETCONF_COPY_CONFIG_QNAME = QName.create(NETCONF_QNAME, "copy-config").intern();
+    public static final NodeIdentifier NETCONF_COPY_CONFIG_NODEID = NodeIdentifier.create(NETCONF_COPY_CONFIG_QNAME);
+    public static final SchemaPath NETCONF_COPY_CONFIG_PATH = toPath(NETCONF_COPY_CONFIG_QNAME);
+
     public static final QName NETCONF_OPERATION_QNAME = QName.create(NETCONF_QNAME, "operation").intern();
     public static final QName NETCONF_DEFAULT_OPERATION_QNAME =
             QName.create(NETCONF_OPERATION_QNAME, "default-operation").intern();
+    public static final NodeIdentifier NETCONF_DEFAULT_OPERATION_NODEID =
+            NodeIdentifier.create(NETCONF_DEFAULT_OPERATION_QNAME);
     public static final QName NETCONF_EDIT_CONFIG_QNAME = QName.create(NETCONF_QNAME, "edit-config").intern();
+    public static final NodeIdentifier NETCONF_EDIT_CONFIG_NODEID = NodeIdentifier.create(NETCONF_EDIT_CONFIG_QNAME);
+    public static final SchemaPath NETCONF_EDIT_CONFIG_PATH = toPath(NETCONF_EDIT_CONFIG_QNAME);
     public static final QName NETCONF_GET_CONFIG_QNAME = QName.create(NETCONF_QNAME, "get-config");
+    public static final NodeIdentifier NETCONF_GET_CONFIG_NODEID = NodeIdentifier.create(NETCONF_GET_CONFIG_QNAME);
+    public static final SchemaPath NETCONF_GET_CONFIG_PATH = toPath(NETCONF_GET_CONFIG_QNAME);
     public static final QName NETCONF_DISCARD_CHANGES_QNAME = QName.create(NETCONF_QNAME, "discard-changes");
+    public static final SchemaPath NETCONF_DISCARD_CHANGES_PATH = toPath(NETCONF_DISCARD_CHANGES_QNAME);
     public static final QName NETCONF_TYPE_QNAME = QName.create(NETCONF_QNAME, "type").intern();
     public static final QName NETCONF_FILTER_QNAME = QName.create(NETCONF_QNAME, "filter").intern();
     public static final QName NETCONF_GET_QNAME = QName.create(NETCONF_QNAME, "get").intern();
+    public static final NodeIdentifier NETCONF_GET_NODEID = NodeIdentifier.create(NETCONF_GET_QNAME);
+    public static final SchemaPath NETCONF_GET_PATH = toPath(NETCONF_GET_QNAME);
     public static final QName NETCONF_RPC_QNAME = QName.create(NETCONF_QNAME, "rpc").intern();
+    public static final QName YANG_QNAME = null;
+    public static final URI NETCONF_ACTION_NAMESPACE = URI.create("urn:ietf:params:xml:ns:yang:1");
+    public static final String NETCONF_ACTION = "action";
 
     public static final URI NETCONF_ROLLBACK_ON_ERROR_URI = URI
             .create("urn:ietf:params:netconf:capability:rollback-on-error:1.0");
@@ -141,30 +176,39 @@ public class NetconfMessageTransformUtil {
             .create("urn:ietf:params:netconf:capability:writable-running:1.0");
 
     public static final QName NETCONF_LOCK_QNAME = QName.create(NETCONF_QNAME, "lock").intern();
+    public static final NodeIdentifier NETCONF_LOCK_NODEID = NodeIdentifier.create(NETCONF_LOCK_QNAME);
+    public static final SchemaPath NETCONF_LOCK_PATH = toPath(NETCONF_LOCK_QNAME);
     public static final QName NETCONF_UNLOCK_QNAME = QName.create(NETCONF_QNAME, "unlock").intern();
+    public static final NodeIdentifier NETCONF_UNLOCK_NODEID = NodeIdentifier.create(NETCONF_UNLOCK_QNAME);
+    public static final SchemaPath NETCONF_UNLOCK_PATH = toPath(NETCONF_UNLOCK_QNAME);
+
+    public static final NodeIdentifier EDIT_CONTENT_NODEID = NodeIdentifier.create(EditContent.QNAME);
 
     // Discard changes message
-    public static final ContainerNode DISCARD_CHANGES_RPC_CONTENT =
-            Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(NETCONF_DISCARD_CHANGES_QNAME)).build();
+    public static final ContainerNode DISCARD_CHANGES_RPC_CONTENT = Builders.containerBuilder()
+            .withNodeIdentifier(NodeIdentifier.create(NETCONF_DISCARD_CHANGES_QNAME)).build();
 
     // Commit changes message
-    public static final ContainerNode COMMIT_RPC_CONTENT =
-            Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(NETCONF_COMMIT_QNAME)).build();
+    public static final ContainerNode COMMIT_RPC_CONTENT = Builders.containerBuilder()
+            .withNodeIdentifier(NodeIdentifier.create(NETCONF_COMMIT_QNAME)).build();
 
     // Get message
-    public static final ContainerNode GET_RPC_CONTENT =
-            Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(NETCONF_GET_QNAME)).build();
+    public static final ContainerNode GET_RPC_CONTENT = Builders.containerBuilder()
+            .withNodeIdentifier(NETCONF_GET_NODEID).build();
 
     // Create-subscription changes message
-    public static final ContainerNode CREATE_SUBSCRIPTION_RPC_CONTENT =
-            Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(CREATE_SUBSCRIPTION_RPC_QNAME)).build();
+    public static final ContainerNode CREATE_SUBSCRIPTION_RPC_CONTENT = Builders.containerBuilder()
+            .withNodeIdentifier(NodeIdentifier.create(CREATE_SUBSCRIPTION_RPC_QNAME)).build();
+
+    private static final NodeIdentifier NETCONF_FILTER_NODEID = NodeIdentifier.create(NETCONF_FILTER_QNAME);
+    private static final Map<QName, String> SUBTREE_FILTER_ATTRIBUTES = ImmutableMap.of(NETCONF_TYPE_QNAME, SUBTREE);
 
     public static final DataContainerChild<?, ?> EMPTY_FILTER;
 
     static {
         final NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> anyXmlBuilder =
-                Builders.anyXmlBuilder().withNodeIdentifier(toId(NETCONF_FILTER_QNAME));
-        anyXmlBuilder.withAttributes(Collections.singletonMap(NETCONF_TYPE_QNAME, SUBTREE));
+                Builders.anyXmlBuilder().withNodeIdentifier(NETCONF_FILTER_NODEID)
+                .withAttributes(SUBTREE_FILTER_ATTRIBUTES);
 
         final Element element = XmlUtil.createElement(BLANK_DOCUMENT, NETCONF_FILTER_QNAME.getLocalName(),
                 Optional.of(NETCONF_FILTER_QNAME.getNamespace().toString()));
@@ -178,19 +222,15 @@ public class NetconfMessageTransformUtil {
 
     public static DataContainerChild<?, ?> toFilterStructure(final YangInstanceIdentifier identifier,
                                                              final SchemaContext ctx) {
-        final NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> anyXmlBuilder =
-                Builders.anyXmlBuilder().withNodeIdentifier(toId(NETCONF_FILTER_QNAME));
-        anyXmlBuilder.withAttributes(Collections.singletonMap(NETCONF_TYPE_QNAME, SUBTREE));
-
-        final NormalizedNode<?, ?> filterContent = ImmutableNodes.fromInstanceId(ctx, identifier);
-
+        final NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> anyXmlBuilder = Builders.anyXmlBuilder()
+                .withNodeIdentifier(NETCONF_FILTER_NODEID).withAttributes(SUBTREE_FILTER_ATTRIBUTES);
         final Element element = XmlUtil.createElement(BLANK_DOCUMENT, NETCONF_FILTER_QNAME.getLocalName(),
                 Optional.of(NETCONF_FILTER_QNAME.getNamespace().toString()));
         element.setAttributeNS(NETCONF_FILTER_QNAME.getNamespace().toString(), NETCONF_TYPE_QNAME.getLocalName(),
                 "subtree");
 
         try {
-            NetconfUtil.writeNormalizedNode(filterContent, new DOMResult(element), SchemaPath.ROOT, ctx);
+            NetconfUtil.writeFilter(identifier, new DOMResult(element), SchemaPath.ROOT, ctx);
         } catch (IOException | XMLStreamException e) {
             throw new IllegalStateException("Unable to serialize filter element for path " + identifier, e);
         }
@@ -204,7 +244,7 @@ public class NetconfMessageTransformUtil {
         final String inputMsgId = input.getDocument().getDocumentElement().getAttribute(MESSAGE_ID_ATTR);
         final String outputMsgId = output.getDocument().getDocumentElement().getAttribute(MESSAGE_ID_ATTR);
 
-        if (inputMsgId.equals(outputMsgId) == false) {
+        if (!inputMsgId.equals(outputMsgId)) {
             final Map<String, String> errorInfo = ImmutableMap.<String, String>builder()
                     .put("actual-message-id", outputMsgId)
                     .put("expected-message-id", inputMsgId)
@@ -266,7 +306,7 @@ public class NetconfMessageTransformUtil {
     }
 
     public static NodeIdentifier toId(final PathArgument qname) {
-        return toId(qname.getNodeType());
+        return qname instanceof NodeIdentifier ? (NodeIdentifier) qname : toId(qname.getNodeType());
     }
 
     public static NodeIdentifier toId(final QName nodeType) {
@@ -291,13 +331,19 @@ public class NetconfMessageTransformUtil {
         return new NodeContainerProxy(next.getQName(), next.getChildNodes(), next.getAvailableAugmentations());
     }
 
+    @Deprecated
     public static ContainerNode wrap(final QName name, final DataContainerChild<?, ?>... node) {
-        return Builders.containerBuilder().withNodeIdentifier(toId(name)).withValue(ImmutableList.copyOf(node)).build();
+        return wrap(toId(name), node);
+    }
+
+    public static ContainerNode wrap(final NodeIdentifier name, final DataContainerChild<?, ?>... node) {
+        return Builders.containerBuilder().withNodeIdentifier(name).withValue(ImmutableList.copyOf(node)).build();
     }
 
     public static AnyXmlNode createEditConfigAnyxml(
-            final SchemaContext ctx, final YangInstanceIdentifier dataPath, final Optional<ModifyAction> operation,
-            final Optional<NormalizedNode<?, ?>> lastChildOverride) {
+            final SchemaContext ctx, final YangInstanceIdentifier dataPath,
+            final java.util.Optional<ModifyAction> operation,
+            final java.util.Optional<NormalizedNode<?, ?>> lastChildOverride) {
         final NormalizedNode<?, ?> configContent;
 
         if (dataPath.isEmpty()) {
@@ -310,8 +356,8 @@ public class NetconfMessageTransformUtil {
         } else {
             final Entry<QName, ModifyAction> modifyOperation = operation.isPresent()
                     ? new AbstractMap.SimpleEntry<>(NETCONF_OPERATION_QNAME, operation.get()) : null;
-            configContent = ImmutableNodes
-                    .fromInstanceId(ctx, dataPath, lastChildOverride, Optional.fromNullable(modifyOperation));
+            configContent = ImmutableNodes.fromInstanceId(ctx, dataPath, lastChildOverride,
+                java.util.Optional.ofNullable(modifyOperation));
         }
 
         final Element element = XmlUtil.createElement(BLANK_DOCUMENT, NETCONF_CONFIG_QNAME.getLocalName(),
@@ -321,23 +367,23 @@ public class NetconfMessageTransformUtil {
         } catch (IOException | XMLStreamException e) {
             throw new IllegalStateException("Unable to serialize edit config content element for path " + dataPath, e);
         }
-        final DOMSource value = new DOMSource(element);
 
-        return Builders.anyXmlBuilder().withNodeIdentifier(toId(NETCONF_CONFIG_QNAME)).withValue(value).build();
+        return Builders.anyXmlBuilder().withNodeIdentifier(NETCONF_CONFIG_NODEID).withValue(new DOMSource(element))
+                .build();
     }
 
-    public static DataContainerChild<?, ?> createEditConfigStructure(
-            final SchemaContext ctx, final YangInstanceIdentifier dataPath, final Optional<ModifyAction> operation,
-            final Optional<NormalizedNode<?, ?>> lastChildOverride) {
-        return Builders.choiceBuilder().withNodeIdentifier(toId(EditContent.QNAME))
+    public static DataContainerChild<?, ?> createEditConfigStructure(final SchemaContext ctx,
+            final YangInstanceIdentifier dataPath, final java.util.Optional<ModifyAction> operation,
+            final java.util.Optional<NormalizedNode<?, ?>> lastChildOverride) {
+        return Builders.choiceBuilder().withNodeIdentifier(EDIT_CONTENT_NODEID)
                 .withChild(createEditConfigAnyxml(ctx, dataPath, operation, lastChildOverride)).build();
     }
 
     public static SchemaPath toPath(final QName rpc) {
-        return SchemaPath.create(true, rpc);
+        return SchemaPath.ROOT.createChild(rpc);
     }
 
-    public static Map.Entry<Date, XmlElement> stripNotification(final NetconfMessage message) {
+    public static Map.Entry<Instant, XmlElement> stripNotification(final NetconfMessage message) {
         final XmlElement xmlElement = XmlElement.fromDomDocument(message.getDocument());
         final List<XmlElement> childElements = xmlElement.getChildElements();
         Preconditions.checkArgument(childElements.size() == 2, "Unable to parse notification %s, unexpected format."
@@ -357,15 +403,17 @@ public class NetconfMessageTransformUtil {
         }
 
         try {
-            return new AbstractMap.SimpleEntry<>(
-                    NetconfNotification.RFC3339_DATE_PARSER.apply(eventTimeElement.getTextContent()),
+            return new SimpleEntry<>(
+                    NetconfNotification.RFC3339_DATE_PARSER.apply(eventTimeElement.getTextContent()).toInstant(),
                     notificationElement);
         } catch (final DocumentedException e) {
-            throw new IllegalArgumentException("Notification payload does not contain " + EVENT_TIME + " " + message);
+            throw new IllegalArgumentException("Notification payload does not contain " + EVENT_TIME + " " + message,
+                    e);
         } catch (final DateTimeParseException e) {
             LOG.warn("Unable to parse event time from {}. Setting time to {}", eventTimeElement,
                     NetconfNotification.UNKNOWN_EVENT_TIME, e);
-            return new AbstractMap.SimpleEntry<>(NetconfNotification.UNKNOWN_EVENT_TIME, notificationElement);
+            return new SimpleEntry<>(NetconfNotification.UNKNOWN_EVENT_TIME.toInstant(),
+                    notificationElement);
         }
     }
 
@@ -381,6 +429,60 @@ public class NetconfMessageTransformUtil {
         return new DOMResult(elementNS);
     }
 
+    public static DOMResult prepareDomResultForActionRequest(final DataSchemaContextTree dataSchemaContextTree,
+            final DOMDataTreeIdentifier domDataTreeIdentifier, final SchemaPath actionSchemaPath,
+            final MessageCounter counter, final String action) {
+        final Document document = XmlUtil.newDocument();
+        final Element rpcNS =
+                document.createElementNS(NETCONF_RPC_QNAME.getNamespace().toString(), NETCONF_RPC_QNAME.getLocalName());
+        // set msg id
+        rpcNS.setAttribute(MESSAGE_ID_ATTR, counter.getNewMessageId(MESSAGE_ID_PREFIX));
+
+        final Element actionNS = document.createElementNS(NETCONF_ACTION_NAMESPACE.toString(), NETCONF_ACTION);
+        final DataSchemaContextNode<?> rootSchemaContextNode = dataSchemaContextTree.getRoot();
+        final Element actionData = prepareActionData(rootSchemaContextNode, actionNS,
+                domDataTreeIdentifier.getRootIdentifier().getPathArguments().iterator(), document);
+
+        Element specificActionElement = document.createElement(action);
+        actionData.appendChild(specificActionElement);
+        rpcNS.appendChild(actionNS);
+        document.appendChild(rpcNS);
+        return new DOMResult(specificActionElement);
+    }
+
+    private static Element prepareActionData(final DataSchemaContextNode<?> currentParentSchemaNode,
+            final Element actionNS, final Iterator<PathArgument> iterator, final Document document) {
+        if (iterator.hasNext()) {
+            final PathArgument next = iterator.next();
+
+            DataSchemaContextNode<?> current = currentParentSchemaNode.getChild(next);
+            Preconditions.checkArgument(current != null, "Invalid input: schema for argument %s not found", next);
+
+            if (current.isMixin()) {
+                return prepareActionData(current, actionNS, iterator, document);
+            }
+
+            final QName actualNS = next.getNodeType();
+            final Element actualElement = document.createElementNS(actualNS.getNamespace().toString(),
+                    actualNS.getLocalName());
+            if (next instanceof NodeWithValue) {
+                actualElement.setNodeValue(((NodeWithValue) next).getValue().toString());
+            } else if (next instanceof NodeIdentifierWithPredicates) {
+                for (Entry<QName, Object> entry : ((NodeIdentifierWithPredicates) next).getKeyValues().entrySet()) {
+                    final Element entryElement = document.createElementNS(entry.getKey().getNamespace().toString(),
+                            entry.getKey().getLocalName());
+                    entryElement.setTextContent(entry.getValue().toString());
+                    entryElement.setNodeValue(entry.getValue().toString());
+                    actualElement.appendChild(entryElement);
+                }
+            }
+            actionNS.appendChild(actualElement);
+            return prepareActionData(current, actualElement, iterator, document);
+        } else {
+            return actionNS;
+        }
+    }
+
     @SuppressWarnings("checkstyle:IllegalCatch")
     public static void writeNormalizedRpc(final ContainerNode normalized, final DOMResult result,
                                           final SchemaPath schemaPath,
@@ -404,4 +506,16 @@ public class NetconfMessageTransformUtil {
             }
         }
     }
+
+    public static RpcResult<NetconfMessage> toRpcResult(final FailedNetconfMessage message) {
+        return RpcResultBuilder.<NetconfMessage>failed()
+                .withRpcError(
+                        toRpcError(
+                                new NetconfDocumentedException(
+                                        message.getException().getMessage(),
+                                        DocumentedException.ErrorType.APPLICATION,
+                                        DocumentedException.ErrorTag.MALFORMED_MESSAGE,
+                                        DocumentedException.ErrorSeverity.ERROR)))
+                .build();
+    }
 }