Bug 5528 - Impl Post data
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / restconf / restful / utils / PutDataTransactionUtil.java
index 9b919f762ee3b3b8db74a90af7ca56443bd238be..698a4787cb559ea5ef5ce8ffd9b5e50b2e633b08 100644 (file)
@@ -7,11 +7,8 @@
  */
 package org.opendaylight.restconf.restful.utils;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
 import com.google.common.util.concurrent.CheckedFuture;
-import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import javax.ws.rs.core.Response;
@@ -32,9 +29,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 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.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 
@@ -166,52 +161,8 @@ public final class PutDataTransactionUtil {
     private static CheckedFuture<Void, TransactionCommitFailedException> submitData(final YangInstanceIdentifier path,
             final SchemaContext schemaContext,
             final DOMDataWriteTransaction writeTx, final NormalizedNode<?, ?> data) {
-        ensureParentsByMerge(path, schemaContext, writeTx);
+        TransactionUtil.ensureParentsByMerge(path, schemaContext, writeTx);
         writeTx.put(LogicalDatastoreType.CONFIGURATION, path, data);
         return writeTx.submit();
     }
-
-    /**
-     * Merged parents of data
-     *
-     * @param path
-     *            - path of data
-     * @param schemaContext
-     *            - {@link SchemaContext}
-     * @param writeTx
-     *            - write transaction
-     */
-    private static void ensureParentsByMerge(final YangInstanceIdentifier path, final SchemaContext schemaContext,
-            final DOMDataWriteTransaction writeTx) {
-        final List<PathArgument> normalizedPathWithoutChildArgs = new ArrayList<>();
-        boolean hasList = false;
-        YangInstanceIdentifier rootNormalizedPath = null;
-
-        final Iterator<PathArgument> it = path.getPathArguments().iterator();
-        final Module module = schemaContext.findModuleByNamespaceAndRevision(
-                path.getLastPathArgument().getNodeType().getModule().getNamespace(),
-                path.getLastPathArgument().getNodeType().getModule().getRevision());
-
-        while (it.hasNext()) {
-            final PathArgument pathArgument = it.next();
-            if (rootNormalizedPath == null) {
-                rootNormalizedPath = YangInstanceIdentifier.create(pathArgument);
-            }
-            if (it.hasNext()) {
-                normalizedPathWithoutChildArgs.add(pathArgument);
-                if (module.getDataChildByName(pathArgument.getNodeType()) instanceof ListSchemaNode) {
-                    hasList = true;
-                }
-            }
-        }
-        if (normalizedPathWithoutChildArgs.isEmpty()) {
-            return;
-        }
-        if (hasList) {
-            Preconditions.checkArgument(rootNormalizedPath != null, "Empty path received");
-            final NormalizedNode<?, ?> parentStructure = ImmutableNodes.fromInstanceId(schemaContext,
-                    YangInstanceIdentifier.create(normalizedPathWithoutChildArgs));
-            writeTx.merge(LogicalDatastoreType.CONFIGURATION, rootNormalizedPath, parentStructure);
-        }
-    }
 }