Search in sources :

Example 6 with UserLeafSetNode

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

the class ParameterAwareNormalizedNodeWriter method wasProcessedAsCompositeNode.

private boolean wasProcessedAsCompositeNode(final NormalizedNode node) throws IOException {
    boolean processedAsCompositeNode = false;
    if (node instanceof ContainerNode) {
        final ContainerNode n = (ContainerNode) node;
        if (!n.getIdentifier().getNodeType().withoutRevision().equals(ROOT_DATA_QNAME)) {
            writer.startContainerNode(n.getIdentifier(), childSizeHint(n.body()));
            currentDepth++;
            processedAsCompositeNode = writeChildren(n.body(), false);
            currentDepth--;
        } else {
            // write child nodes of data root container
            for (final NormalizedNode child : n.body()) {
                currentDepth++;
                if (selectedByParameters(child, false)) {
                    write(child);
                }
                currentDepth--;
            }
            processedAsCompositeNode = true;
        }
    } 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(), false);
        currentDepth--;
    } else if (node instanceof ChoiceNode) {
        final ChoiceNode n = (ChoiceNode) node;
        writer.startChoiceNode(n.getIdentifier(), childSizeHint(n.body()));
        processedAsCompositeNode = writeChildren(n.body(), true);
    } else if (node instanceof AugmentationNode) {
        final AugmentationNode n = (AugmentationNode) node;
        writer.startAugmentationNode(n.getIdentifier());
        processedAsCompositeNode = writeChildren(n.body(), true);
    } else if (node instanceof UnkeyedListNode) {
        final UnkeyedListNode n = (UnkeyedListNode) node;
        writer.startUnkeyedList(n.getIdentifier(), childSizeHint(n.body()));
        processedAsCompositeNode = writeChildren(n.body(), false);
    } else if (node instanceof UserMapNode) {
        final UserMapNode n = (UserMapNode) node;
        writer.startOrderedMapNode(n.getIdentifier(), childSizeHint(n.body()));
        processedAsCompositeNode = writeChildren(n.body(), true);
    } else if (node instanceof MapNode) {
        final MapNode n = (MapNode) node;
        writer.startMapNode(n.getIdentifier(), childSizeHint(n.body()));
        processedAsCompositeNode = writeChildren(n.body(), true);
    } 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(), true);
        currentDepth--;
    }
    return processedAsCompositeNode;
}
Also used : UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) 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) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode) LeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode) 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) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)

Example 7 with UserLeafSetNode

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

the class BrokerFacade method putData.

// FIXME: This is doing correct put for container and list children, not sure if this will work for choice case
private void putData(final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, final EffectiveModelContext schemaContext, final String insert, final String point) {
    if (insert == null) {
        makePut(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());
                if (readList == null || readList.isEmpty()) {
                    simplePut(datastore, path, rwTransaction, schemaContext, payload);
                } else {
                    rwTransaction.delete(datastore, path.getParent());
                    simplePut(datastore, path, rwTransaction, schemaContext, payload);
                    makePut(rwTransaction, datastore, path.getParent(), readList, schemaContext);
                }
            } else {
                final UserLeafSetNode<?> readLeafList = (UserLeafSetNode<?>) readConfigurationData(path.getParent());
                if (readLeafList == null || readLeafList.isEmpty()) {
                    simplePut(datastore, path, rwTransaction, schemaContext, payload);
                } else {
                    rwTransaction.delete(datastore, path.getParent());
                    simplePut(datastore, path, rwTransaction, schemaContext, payload);
                    makePut(rwTransaction, datastore, path.getParent(), readLeafList, schemaContext);
                }
            }
            break;
        case "last":
            simplePut(datastore, path, rwTransaction, schemaContext, payload);
            break;
        case "before":
            if (schemaNode instanceof ListSchemaNode) {
                final UserMapNode readList = (UserMapNode) this.readConfigurationData(path.getParent());
                if (readList == null || readList.isEmpty()) {
                    simplePut(datastore, path, rwTransaction, schemaContext, payload);
                } else {
                    insertWithPointListPut(rwTransaction, datastore, path, payload, schemaContext, point, readList, true);
                }
            } else {
                final UserLeafSetNode<?> readLeafList = (UserLeafSetNode<?>) readConfigurationData(path.getParent());
                if (readLeafList == null || readLeafList.isEmpty()) {
                    simplePut(datastore, path, rwTransaction, schemaContext, payload);
                } else {
                    insertWithPointLeafListPut(rwTransaction, datastore, path, payload, schemaContext, point, readLeafList, true);
                }
            }
            break;
        case "after":
            if (schemaNode instanceof ListSchemaNode) {
                final UserMapNode readList = (UserMapNode) this.readConfigurationData(path.getParent());
                if (readList == null || readList.isEmpty()) {
                    simplePut(datastore, path, rwTransaction, schemaContext, payload);
                } else {
                    insertWithPointListPut(rwTransaction, datastore, path, payload, schemaContext, point, readList, false);
                }
            } else {
                final UserLeafSetNode<?> readLeafList = (UserLeafSetNode<?>) readConfigurationData(path.getParent());
                if (readLeafList == null || readLeafList.isEmpty()) {
                    simplePut(datastore, path, rwTransaction, schemaContext, payload);
                } else {
                    insertWithPointLeafListPut(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)

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