import org.opendaylight.restconf.restful.transaction.TransactionVarsWrapper;
import org.opendaylight.restconf.utils.parser.ParserIdentifier;
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.AugmentationNode;
-import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData(),
transactionNode, schemaContextRef.get());
final URI location = PostDataTransactionUtil.resolveLocation(uriInfo, transactionNode, schemaContextRef);
- final ResponseFactory dataFactory = new ResponseFactory(
- ReadDataTransactionUtil.readData(RestconfDataServiceConstant.ReadData.CONFIG, transactionNode),
- location);
+ final ResponseFactory dataFactory = new ResponseFactory(null, location);
FutureCallbackTx.addCallback(future, RestconfDataServiceConstant.PostData.POST_TX_TYPE, dataFactory);
return dataFactory.build();
}
final SchemaContext schemaContext) {
final DOMTransactionChain transactionChain = transactionNode.getTransactionChain();
final DOMDataReadWriteTransaction transaction = transactionChain.newReadWriteTransaction();
- final NormalizedNode<?, ?> node = ImmutableNodes.fromInstanceId(schemaContext, path);
- transaction.put(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.create(node.getIdentifier()), node);
- TransactionUtil.ensureParentsByMerge(path, schemaContext, transaction);
if (data instanceof MapNode) {
+ boolean merge = false;
for (final MapEntryNode child : ((MapNode) data).getValue()) {
- putChild(child, transactionChain, transaction, path);
- }
- } else if (data instanceof AugmentationNode) {
- for (final DataContainerChild<? extends PathArgument, ?> child : ((AugmentationNode) data).getValue()) {
- putChild(child, transactionChain, transaction, path);
- }
- } else if (data instanceof ChoiceNode) {
- for (final DataContainerChild<? extends PathArgument, ?> child : ((ChoiceNode) data).getValue()) {
- putChild(child, transactionChain, transaction, path);
- }
- } else if (data instanceof LeafSetNode<?>) {
- for (final LeafSetEntryNode<?> child : ((LeafSetNode<?>) data).getValue()) {
- putChild(child, transactionChain, transaction, path);
- }
- } else if (data instanceof ContainerNode) {
- for (final DataContainerChild<? extends PathArgument, ?> child : ((ContainerNode) data).getValue()) {
- putChild(child, transactionChain, transaction, path);
+ final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
+ TransactionUtil.checkItemDoesNotExists(
+ transactionChain, transaction, LogicalDatastoreType.CONFIGURATION, childPath,
+ RestconfDataServiceConstant.PostData.POST_TX_TYPE);
+ if (!merge) {
+ merge = true;
+ TransactionUtil.ensureParentsByMerge(path, schemaContext, transaction);
+ final NormalizedNode<?, ?> emptySubTree = ImmutableNodes.fromInstanceId(schemaContext, path);
+ transaction.merge(LogicalDatastoreType.CONFIGURATION,
+ YangInstanceIdentifier.create(emptySubTree.getIdentifier()), emptySubTree);
+ }
+ transaction.put(LogicalDatastoreType.CONFIGURATION, childPath, child);
}
+ } else {
+ TransactionUtil.checkItemDoesNotExists(
+ transactionChain, transaction, LogicalDatastoreType.CONFIGURATION, path,
+ RestconfDataServiceConstant.PostData.POST_TX_TYPE);
+
+ TransactionUtil.ensureParentsByMerge(path, schemaContext, transaction);
+ transaction.put(LogicalDatastoreType.CONFIGURATION, path, data);
}
return transaction.submit();
}
- /**
- * Prepare data for submit
- *
- * @param child
- * - data
- * @param transactionChain
- * - transaction chain
- * @param readWriteTx
- * - transaction
- * @param path
- * - path to data
- */
- private static void putChild(final NormalizedNode<?, ?> child, final DOMTransactionChain transactionChain,
- final DOMDataReadWriteTransaction readWriteTx, final YangInstanceIdentifier path) {
- final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
- TransactionUtil.checkItemDoesNotExists(
- transactionChain, readWriteTx, LogicalDatastoreType.CONFIGURATION, childPath,
- RestconfDataServiceConstant.PostData.POST_TX_TYPE);
- readWriteTx.put(LogicalDatastoreType.CONFIGURATION, childPath, child);
- }
-
/**
* Get location from {@link YangInstanceIdentifier} and {@link UriInfo}
*