Search in sources :

Example 1 with UserLeafSetNode

use of org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode in project yangtools by opendaylight.

the class NormalizedNodeWriter method wasProcessedAsCompositeNode.

protected boolean wasProcessedAsCompositeNode(final NormalizedNode node) throws IOException {
    if (node instanceof ContainerNode) {
        final ContainerNode n = (ContainerNode) node;
        writer.startContainerNode(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof MapEntryNode) {
        return writeMapEntryNode((MapEntryNode) node);
    }
    if (node instanceof UnkeyedListEntryNode) {
        final UnkeyedListEntryNode n = (UnkeyedListEntryNode) node;
        writer.startUnkeyedListItem(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof ChoiceNode) {
        final ChoiceNode n = (ChoiceNode) node;
        writer.startChoiceNode(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof AugmentationNode) {
        final AugmentationNode n = (AugmentationNode) node;
        writer.startAugmentationNode(n.getIdentifier());
        return writeChildren(n.body());
    }
    if (node instanceof UnkeyedListNode) {
        final UnkeyedListNode n = (UnkeyedListNode) node;
        writer.startUnkeyedList(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof UserMapNode) {
        final UserMapNode n = (UserMapNode) node;
        writer.startOrderedMapNode(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof SystemMapNode) {
        final SystemMapNode n = (SystemMapNode) node;
        writer.startMapNode(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof UserLeafSetNode) {
        final UserLeafSetNode<?> n = (UserLeafSetNode<?>) node;
        writer.startOrderedLeafSet(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof SystemLeafSetNode) {
        final SystemLeafSetNode<?> n = (SystemLeafSetNode<?>) node;
        writer.startLeafSet(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    return false;
}
Also used : SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode)

Example 2 with UserLeafSetNode

use of org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode in project netconf by opendaylight.

the class BrokerFacade method postData.

private void postData(final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, final EffectiveModelContext schemaContext, final String insert, final String point) {
    if (insert == null) {
        makeNormalPost(rwTransaction, datastore, path, payload, schemaContext);
        return;
    }
    final DataSchemaNode schemaNode = checkListAndOrderedType(schemaContext, path);
    checkItemDoesNotExists(rwTransaction, datastore, path);
    switch(insert) {
        case "first":
            if (schemaNode instanceof ListSchemaNode) {
                final UserMapNode readList = (UserMapNode) this.readConfigurationData(path.getParent().getParent());
                if (readList == null || readList.isEmpty()) {
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                } else {
                    rwTransaction.delete(datastore, path.getParent().getParent());
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                    makeNormalPost(rwTransaction, datastore, path.getParent().getParent(), readList, schemaContext);
                }
            } else {
                final UserLeafSetNode<?> readLeafList = (UserLeafSetNode<?>) readConfigurationData(path.getParent());
                if (readLeafList == null || readLeafList.isEmpty()) {
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                } else {
                    rwTransaction.delete(datastore, path.getParent());
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                    makeNormalPost(rwTransaction, datastore, path.getParent().getParent(), readLeafList, schemaContext);
                }
            }
            break;
        case "last":
            simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
            break;
        case "before":
            if (schemaNode instanceof ListSchemaNode) {
                final UserMapNode readList = (UserMapNode) this.readConfigurationData(path.getParent().getParent());
                if (readList == null || readList.isEmpty()) {
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                } else {
                    insertWithPointListPost(rwTransaction, datastore, path, payload, schemaContext, point, readList, true);
                }
            } else {
                final UserLeafSetNode<?> readLeafList = (UserLeafSetNode<?>) readConfigurationData(path.getParent());
                if (readLeafList == null || readLeafList.isEmpty()) {
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                } else {
                    insertWithPointLeafListPost(rwTransaction, datastore, path, payload, schemaContext, point, readLeafList, true);
                }
            }
            break;
        case "after":
            if (schemaNode instanceof ListSchemaNode) {
                final UserMapNode readList = (UserMapNode) this.readConfigurationData(path.getParent().getParent());
                if (readList == null || readList.isEmpty()) {
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                } else {
                    insertWithPointListPost(rwTransaction, datastore, path, payload, schemaContext, point, readList, false);
                }
            } else {
                final UserLeafSetNode<?> readLeafList = (UserLeafSetNode<?>) readConfigurationData(path.getParent());
                if (readLeafList == null || readLeafList.isEmpty()) {
                    simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                } else {
                    insertWithPointLeafListPost(rwTransaction, datastore, path, payload, schemaContext, point, readLeafList, false);
                }
            }
            break;
        default:
            throw new RestconfDocumentedException("Used bad value of insert parameter. Possible values are first, last, before or after, " + "but was: " + insert);
    }
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode)

Example 3 with UserLeafSetNode

use of org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode in project netconf by opendaylight.

the class DepthAwareNormalizedNodeWriter method wasProcessedAsCompositeNode.

private boolean wasProcessedAsCompositeNode(final NormalizedNode node) throws IOException {
    boolean processedAsCompositeNode = false;
    if (node instanceof ContainerNode) {
        final ContainerNode n = (ContainerNode) node;
        writer.startContainerNode(n.getIdentifier(), childSizeHint(n.body()));
        currentDepth++;
        processedAsCompositeNode = writeChildren(n.body());
        currentDepth--;
    } else if (node instanceof MapEntryNode) {
        processedAsCompositeNode = writeMapEntryNode((MapEntryNode) node);
    } else if (node instanceof UnkeyedListEntryNode) {
        final UnkeyedListEntryNode n = (UnkeyedListEntryNode) node;
        writer.startUnkeyedListItem(n.getIdentifier(), childSizeHint(n.body()));
        currentDepth++;
        processedAsCompositeNode = writeChildren(n.body());
        currentDepth--;
    } else if (node instanceof ChoiceNode) {
        final ChoiceNode n = (ChoiceNode) node;
        writer.startChoiceNode(n.getIdentifier(), childSizeHint(n.body()));
        processedAsCompositeNode = writeChildren(n.body());
    } else if (node instanceof AugmentationNode) {
        final AugmentationNode n = (AugmentationNode) node;
        writer.startAugmentationNode(n.getIdentifier());
        processedAsCompositeNode = writeChildren(n.body());
    } else if (node instanceof UnkeyedListNode) {
        final UnkeyedListNode n = (UnkeyedListNode) node;
        writer.startUnkeyedList(n.getIdentifier(), childSizeHint(n.body()));
        processedAsCompositeNode = writeChildren(n.body());
    } else if (node instanceof UserMapNode) {
        final UserMapNode n = (UserMapNode) node;
        writer.startOrderedMapNode(n.getIdentifier(), childSizeHint(n.body()));
        processedAsCompositeNode = writeChildren(n.body());
    } else if (node instanceof MapNode) {
        final MapNode n = (MapNode) node;
        writer.startMapNode(n.getIdentifier(), childSizeHint(n.body()));
        processedAsCompositeNode = writeChildren(n.body());
    } else if (node instanceof LeafSetNode) {
        final LeafSetNode<?> n = (LeafSetNode<?>) node;
        if (node instanceof UserLeafSetNode) {
            writer.startOrderedLeafSet(n.getIdentifier(), childSizeHint(n.body()));
        } else {
            writer.startLeafSet(n.getIdentifier(), childSizeHint(n.body()));
        }
        currentDepth++;
        processedAsCompositeNode = writeChildren(n.body());
        currentDepth--;
    }
    return processedAsCompositeNode;
}
Also used : UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode) LeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode)

Example 4 with UserLeafSetNode

use of org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode in project yangtools by opendaylight.

the class BuilderTest method immutableUserLeafSetNodeBuilderTest.

@Test
public void immutableUserLeafSetNodeBuilderTest() {
    final UserLeafSetNode<String> orderedLeafSet = ImmutableUserLeafSetNodeBuilder.<String>create().withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST).withChild(LEAF_SET_ENTRY_NODE).withChildValue("baz").removeChild(BAR_PATH).build();
    final LinkedList<LeafSetNode<?>> mapEntryNodeColl = new LinkedList<>();
    mapEntryNodeColl.add(orderedLeafSet);
    final UnmodifiableCollection<?> leafSetCollection = (UnmodifiableCollection<?>) orderedLeafSet.body();
    final NormalizedNode orderedMapNodeSchemaAware = ImmutableUserLeafSetNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST).withChildValue("baz").build();
    final UnmodifiableCollection<?> SchemaAwareleafSetCollection = (UnmodifiableCollection<?>) orderedMapNodeSchemaAware.body();
    assertNotNull(Builders.anyXmlBuilder());
    assertEquals(1, ((UserLeafSetNode<?>) orderedLeafSet).size());
    assertEquals("baz", orderedLeafSet.childAt(0).body());
    assertNull(orderedLeafSet.childByArg(BAR_PATH));
    assertEquals(1, leafSetCollection.size());
    assertEquals(1, SchemaAwareleafSetCollection.size());
}
Also used : NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode) SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) LeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode) LinkedList(java.util.LinkedList) UnmodifiableCollection(org.opendaylight.yangtools.util.UnmodifiableCollection) Test(org.junit.Test)

Example 5 with UserLeafSetNode

use of org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode in project netconf by opendaylight.

the class ReadDataTransactionUtil method prepareData.

/**
 * Prepare and map all data from DS.
 *
 * @param configDataNode data node of config data
 * @param stateDataNode  data node of state data
 * @return {@link NormalizedNode}
 */
@SuppressWarnings("unchecked")
@NonNull
private static NormalizedNode prepareData(@NonNull final NormalizedNode configDataNode, @NonNull final NormalizedNode stateDataNode) {
    if (configDataNode instanceof UserMapNode) {
        final CollectionNodeBuilder<MapEntryNode, UserMapNode> builder = Builders.orderedMapBuilder().withNodeIdentifier(((MapNode) configDataNode).getIdentifier());
        mapValueToBuilder(((UserMapNode) configDataNode).body(), ((UserMapNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof MapNode) {
        final CollectionNodeBuilder<MapEntryNode, SystemMapNode> builder = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(((MapNode) configDataNode).getIdentifier());
        mapValueToBuilder(((MapNode) configDataNode).body(), ((MapNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof MapEntryNode) {
        final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = ImmutableNodes.mapEntryBuilder().withNodeIdentifier(((MapEntryNode) configDataNode).getIdentifier());
        mapValueToBuilder(((MapEntryNode) configDataNode).body(), ((MapEntryNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof ContainerNode) {
        final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder = Builders.containerBuilder().withNodeIdentifier(((ContainerNode) configDataNode).getIdentifier());
        mapValueToBuilder(((ContainerNode) configDataNode).body(), ((ContainerNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof AugmentationNode) {
        final DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> builder = Builders.augmentationBuilder().withNodeIdentifier(((AugmentationNode) configDataNode).getIdentifier());
        mapValueToBuilder(((AugmentationNode) configDataNode).body(), ((AugmentationNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof ChoiceNode) {
        final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> builder = Builders.choiceBuilder().withNodeIdentifier(((ChoiceNode) configDataNode).getIdentifier());
        mapValueToBuilder(((ChoiceNode) configDataNode).body(), ((ChoiceNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof LeafNode) {
        return ImmutableNodes.leafNode(configDataNode.getIdentifier().getNodeType(), configDataNode.body());
    } else if (configDataNode instanceof UserLeafSetNode) {
        final ListNodeBuilder<Object, UserLeafSetNode<Object>> builder = Builders.orderedLeafSetBuilder().withNodeIdentifier(((UserLeafSetNode<?>) configDataNode).getIdentifier());
        mapValueToBuilder(((UserLeafSetNode<Object>) configDataNode).body(), ((UserLeafSetNode<Object>) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof LeafSetNode) {
        final ListNodeBuilder<Object, SystemLeafSetNode<Object>> builder = Builders.leafSetBuilder().withNodeIdentifier(((LeafSetNode<?>) configDataNode).getIdentifier());
        mapValueToBuilder(((LeafSetNode<Object>) configDataNode).body(), ((LeafSetNode<Object>) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof LeafSetEntryNode) {
        return Builders.leafSetEntryBuilder().withNodeIdentifier(((LeafSetEntryNode<?>) configDataNode).getIdentifier()).withValue(configDataNode.body()).build();
    } else if (configDataNode instanceof UnkeyedListNode) {
        final CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> builder = Builders.unkeyedListBuilder().withNodeIdentifier(((UnkeyedListNode) configDataNode).getIdentifier());
        mapValueToBuilder(((UnkeyedListNode) configDataNode).body(), ((UnkeyedListNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof UnkeyedListEntryNode) {
        final DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> builder = Builders.unkeyedListEntryBuilder().withNodeIdentifier(((UnkeyedListEntryNode) configDataNode).getIdentifier());
        mapValueToBuilder(((UnkeyedListEntryNode) configDataNode).body(), ((UnkeyedListEntryNode) stateDataNode).body(), builder);
        return builder.build();
    } else {
        throw new RestconfDocumentedException("Unexpected node type: " + configDataNode.getClass().getName());
    }
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode) ListNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) LeafSetEntryNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) LeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode) CollectionNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder) DataContainerNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

UserLeafSetNode (org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode)7 UserMapNode (org.opendaylight.yangtools.yang.data.api.schema.UserMapNode)6 AugmentationNode (org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode)4 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)4 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 LeafSetNode (org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode)4 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)4 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)4 UnkeyedListNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)4 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)3 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)3 SystemLeafSetNode (org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)2 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)2 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)2 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)2 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)2 LinkedList (java.util.LinkedList)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Test (org.junit.Test)1