예제 #1
0
  private void ensureParentsByMerge(
      final LogicalDatastoreType store,
      final YangInstanceIdentifier normalizedPath,
      final DOMDataReadWriteTransaction rwTx,
      final SchemaContext schemaContext) {
    final List<PathArgument> normalizedPathWithoutChildArgs = new ArrayList<>();
    YangInstanceIdentifier rootNormalizedPath = null;

    final Iterator<PathArgument> it = normalizedPath.getPathArguments().iterator();

    while (it.hasNext()) {
      final PathArgument pathArgument = it.next();
      if (rootNormalizedPath == null) {
        rootNormalizedPath = YangInstanceIdentifier.create(pathArgument);
      }

      // Skip last element, its not a parent
      if (it.hasNext()) {
        normalizedPathWithoutChildArgs.add(pathArgument);
      }
    }

    // No parent structure involved, no need to ensure parents
    if (normalizedPathWithoutChildArgs.isEmpty()) {
      return;
    }

    Preconditions.checkArgument(rootNormalizedPath != null, "Empty path received");

    final NormalizedNode<?, ?> parentStructure =
        ImmutableNodes.fromInstanceId(
            schemaContext, YangInstanceIdentifier.create(normalizedPathWithoutChildArgs));
    rwTx.merge(store, rootNormalizedPath, parentStructure);
  }
예제 #2
0
 private void postDataWithinTransaction(
     final DOMDataReadWriteTransaction rWTransaction,
     final LogicalDatastoreType datastore,
     final YangInstanceIdentifier path,
     final NormalizedNode<?, ?> payload,
     final SchemaContext schemaContext) {
   // FIXME: This is doing correct post for container and list children
   //        not sure if this will work for choice case
   if (payload instanceof MapNode) {
     LOG.trace(
         "POST {} within Restconf PATCH: {} with payload {}", datastore.name(), path, payload);
     final NormalizedNode<?, ?> emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path);
     rWTransaction.merge(
         datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
     ensureParentsByMerge(datastore, path, rWTransaction, schemaContext);
     for (final MapEntryNode child : ((MapNode) payload).getValue()) {
       final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
       checkItemDoesNotExists(rWTransaction, datastore, childPath);
       rWTransaction.put(datastore, childPath, child);
     }
   } else {
     checkItemDoesNotExists(rWTransaction, datastore, path);
     ensureParentsByMerge(datastore, path, rWTransaction, schemaContext);
     rWTransaction.put(datastore, path, payload);
   }
 }