Revert "Fix nested YANG 1.1 Action invocation"
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / utils / RestconfInvokeOperationsUtil.java
index 8e1304ea5bfb8682b4683746c4dcd2da6f3d4959..0970f014a63d201425d2bf691bc8fbca45a47e62 100644 (file)
@@ -13,6 +13,7 @@ import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.CancellationException;
 import javax.ws.rs.core.Response.Status;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMActionResult;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
@@ -25,20 +26,20 @@ import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.restconf.nb.rfc8040.handlers.ActionServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
+import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * Util class for rpc.
- *
  */
 public final class RestconfInvokeOperationsUtil {
-
     private static final Logger LOG = LoggerFactory.getLogger(RestconfInvokeOperationsUtil.class);
 
     private RestconfInvokeOperationsUtil() {
@@ -60,8 +61,7 @@ public final class RestconfInvokeOperationsUtil {
             final SchemaPath schemaPath) {
         final Optional<DOMRpcService> mountPointService = mountPoint.getService(DOMRpcService.class);
         if (mountPointService.isPresent()) {
-            final ListenableFuture<DOMRpcResult> rpc = mountPointService.get().invokeRpc(schemaPath, data);
-            return prepareResult(rpc);
+            return prepareResult(mountPointService.get().invokeRpc(schemaPath, nonnullInput(schemaPath, data)));
         }
         final String errmsg = "RPC service is missing.";
         LOG.debug(errmsg);
@@ -86,8 +86,12 @@ public final class RestconfInvokeOperationsUtil {
             throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE);
         }
 
-        final ListenableFuture<DOMRpcResult> rpc = rpcService.invokeRpc(schemaPath, data);
-        return prepareResult(rpc);
+        return prepareResult(rpcService.invokeRpc(schemaPath, nonnullInput(schemaPath, data)));
+    }
+
+    private static @NonNull NormalizedNode<?, ?> nonnullInput(final SchemaPath type, final NormalizedNode<?, ?> input) {
+        return input != null ? input
+                : ImmutableNodes.containerNode(YangConstants.operationInputQName(type.getLastComponent().getModule()));
     }
 
     /**
@@ -114,7 +118,7 @@ public final class RestconfInvokeOperationsUtil {
         }
     }
 
-    private static DOMRpcResult prepareResult(final ListenableFuture<DOMRpcResult> rpc) {
+    private static DOMRpcResult prepareResult(final ListenableFuture<? extends DOMRpcResult> rpc) {
         final RpcResultFactory dataFactory = new RpcResultFactory();
         FutureCallbackTx.addCallback(rpc, RestconfDataServiceConstant.PostData.POST_TX_TYPE, dataFactory);
         return dataFactory.build();