Search in sources :

Example 1 with CollectionNodeBuilder

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

the class BrokerFacade method buildCont.

private void buildCont(final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder, final ContainerNode result, final DataSchemaContextTree baseSchemaCtxTree, final YangInstanceIdentifier actualPath, final boolean trim) {
    for (final DataContainerChild child : result.body()) {
        final YangInstanceIdentifier path = actualPath.node(child.getIdentifier());
        final DataSchemaNode childSchema = baseSchemaCtxTree.findChild(path).orElseThrow().getDataSchemaNode();
        if (child instanceof ContainerNode) {
            final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builderChild = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) childSchema);
            buildCont(builderChild, result, baseSchemaCtxTree, actualPath, trim);
            builder.withChild(builderChild.build());
        } else if (child instanceof MapNode) {
            final CollectionNodeBuilder<MapEntryNode, SystemMapNode> childBuilder = SchemaAwareBuilders.mapBuilder((ListSchemaNode) childSchema);
            buildList(childBuilder, (MapNode) child, baseSchemaCtxTree, path, trim, ((ListSchemaNode) childSchema).getKeyDefinition());
            builder.withChild(childBuilder.build());
        } else if (child instanceof LeafNode) {
            final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null);
            final Object nodeVal = child.body();
            final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> leafBuilder = SchemaAwareBuilders.leafBuilder((LeafSchemaNode) childSchema);
            if (trim) {
                if (defaultVal == null || !defaultVal.equals(nodeVal)) {
                    leafBuilder.withValue(child.body());
                    builder.withChild(leafBuilder.build());
                }
            } else {
                if (defaultVal != null && defaultVal.equals(nodeVal)) {
                    leafBuilder.withValue(child.body());
                    builder.withChild(leafBuilder.build());
                }
            }
        }
    }
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) 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) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) CollectionNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 2 with CollectionNodeBuilder

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

the class ReadDataTransactionUtil method buildCont.

private static void buildCont(final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder, final ContainerNode result, final DataSchemaContextTree baseSchemaCtxTree, final YangInstanceIdentifier actualPath, final boolean trim) {
    for (final DataContainerChild child : result.body()) {
        final YangInstanceIdentifier path = actualPath.node(child.getIdentifier());
        final DataSchemaNode childSchema = baseSchemaCtxTree.findChild(path).orElseThrow().getDataSchemaNode();
        if (child instanceof ContainerNode) {
            final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builderChild = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) childSchema);
            buildCont(builderChild, result, baseSchemaCtxTree, actualPath, trim);
            builder.withChild(builderChild.build());
        } else if (child instanceof MapNode) {
            final CollectionNodeBuilder<MapEntryNode, SystemMapNode> childBuilder = SchemaAwareBuilders.mapBuilder((ListSchemaNode) childSchema);
            buildList(childBuilder, (MapNode) child, baseSchemaCtxTree, path, trim, ((ListSchemaNode) childSchema).getKeyDefinition());
            builder.withChild(childBuilder.build());
        } else if (child instanceof LeafNode) {
            final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null);
            final Object nodeVal = child.body();
            final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> leafBuilder = SchemaAwareBuilders.leafBuilder((LeafSchemaNode) childSchema);
            if (trim) {
                if (defaultVal == null || !defaultVal.equals(nodeVal)) {
                    leafBuilder.withValue(((LeafNode<?>) child).body());
                    builder.withChild(leafBuilder.build());
                }
            } else {
                if (defaultVal != null && defaultVal.equals(nodeVal)) {
                    leafBuilder.withValue(((LeafNode<?>) child).body());
                    builder.withChild(leafBuilder.build());
                }
            }
        }
    }
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) 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) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) CollectionNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 3 with CollectionNodeBuilder

use of org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder 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)

Example 4 with CollectionNodeBuilder

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

the class ReadDataTransactionUtil method buildMapEntryBuilder.

private static void buildMapEntryBuilder(final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder, final MapEntryNode result, final DataSchemaContextTree baseSchemaCtxTree, final YangInstanceIdentifier actualPath, final boolean trim, final List<QName> keys) {
    for (final DataContainerChild child : result.body()) {
        final YangInstanceIdentifier path = actualPath.node(child.getIdentifier());
        final DataSchemaNode childSchema = baseSchemaCtxTree.findChild(path).orElseThrow().getDataSchemaNode();
        if (child instanceof ContainerNode) {
            final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> childBuilder = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) childSchema);
            buildCont(childBuilder, (ContainerNode) child, baseSchemaCtxTree, path, trim);
            builder.withChild(childBuilder.build());
        } else if (child instanceof MapNode) {
            final CollectionNodeBuilder<MapEntryNode, SystemMapNode> childBuilder = SchemaAwareBuilders.mapBuilder((ListSchemaNode) childSchema);
            buildList(childBuilder, (MapNode) child, baseSchemaCtxTree, path, trim, ((ListSchemaNode) childSchema).getKeyDefinition());
            builder.withChild(childBuilder.build());
        } else if (child instanceof LeafNode) {
            final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null);
            final Object nodeVal = child.body();
            final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> leafBuilder = SchemaAwareBuilders.leafBuilder((LeafSchemaNode) childSchema);
            if (keys.contains(child.getIdentifier().getNodeType())) {
                leafBuilder.withValue(((LeafNode<?>) child).body());
                builder.withChild(leafBuilder.build());
            } else {
                if (trim) {
                    if (defaultVal == null || !defaultVal.equals(nodeVal)) {
                        leafBuilder.withValue(((LeafNode<?>) child).body());
                        builder.withChild(leafBuilder.build());
                    }
                } else {
                    if (defaultVal != null && defaultVal.equals(nodeVal)) {
                        leafBuilder.withValue(((LeafNode<?>) child).body());
                        builder.withChild(leafBuilder.build());
                    }
                }
            }
        }
    }
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) 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) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) CollectionNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 5 with CollectionNodeBuilder

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

the class BrokerFacade method buildMapEntryBuilder.

private void buildMapEntryBuilder(final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder, final MapEntryNode result, final DataSchemaContextTree baseSchemaCtxTree, final YangInstanceIdentifier actualPath, final boolean trim, final List<QName> keys) {
    for (final DataContainerChild child : result.body()) {
        final YangInstanceIdentifier path = actualPath.node(child.getIdentifier());
        final DataSchemaNode childSchema = baseSchemaCtxTree.findChild(path).orElseThrow().getDataSchemaNode();
        if (child instanceof ContainerNode) {
            final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> childBuilder = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) childSchema);
            buildCont(childBuilder, (ContainerNode) child, baseSchemaCtxTree, path, trim);
            builder.withChild(childBuilder.build());
        } else if (child instanceof MapNode) {
            final CollectionNodeBuilder<MapEntryNode, SystemMapNode> childBuilder = SchemaAwareBuilders.mapBuilder((ListSchemaNode) childSchema);
            buildList(childBuilder, (MapNode) child, baseSchemaCtxTree, path, trim, ((ListSchemaNode) childSchema).getKeyDefinition());
            builder.withChild(childBuilder.build());
        } else if (child instanceof LeafNode) {
            final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null);
            final Object nodeVal = child.body();
            final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> leafBuilder = SchemaAwareBuilders.leafBuilder((LeafSchemaNode) childSchema);
            if (keys.contains(child.getIdentifier().getNodeType())) {
                leafBuilder.withValue(child.body());
                builder.withChild(leafBuilder.build());
            } else {
                if (trim) {
                    if (defaultVal == null || !defaultVal.equals(nodeVal)) {
                        leafBuilder.withValue(child.body());
                        builder.withChild(leafBuilder.build());
                    }
                } else {
                    if (defaultVal != null && defaultVal.equals(nodeVal)) {
                        leafBuilder.withValue(child.body());
                        builder.withChild(leafBuilder.build());
                    }
                }
            }
        }
    }
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) 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) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) CollectionNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Aggregations

ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)5 LeafNode (org.opendaylight.yangtools.yang.data.api.schema.LeafNode)5 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)5 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)5 UserMapNode (org.opendaylight.yangtools.yang.data.api.schema.UserMapNode)5 CollectionNodeBuilder (org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)4 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)4 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)4 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)4 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)4 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)2 NonNull (org.eclipse.jdt.annotation.NonNull)1 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)1 AugmentationIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier)1 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)1 AugmentationNode (org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode)1 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)1 LeafSetEntryNode (org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode)1