import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_PATH_PART;
import com.google.common.base.Optional;
+import com.google.common.collect.Iterables;
import com.google.common.primitives.Ints;
import com.google.common.util.concurrent.CheckedFuture;
import java.net.URI;
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.LeafNode;
+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;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
if (!depth.get(0).equals(RestconfDataServiceConstant.ReadData.UNBOUNDED)) {
final Integer value = Ints.tryParse(depth.get(0));
- if ((value == null)
- || (!((value >= RestconfDataServiceConstant.ReadData.MIN_DEPTH)
- && (value <= RestconfDataServiceConstant.ReadData.MAX_DEPTH)))) {
+ if (value == null
+ || !(value >= RestconfDataServiceConstant.ReadData.MIN_DEPTH
+ && value <= RestconfDataServiceConstant.ReadData.MAX_DEPTH)) {
throw new RestconfDocumentedException(
new RestconfError(RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
"Invalid depth parameter: " + depth, null,
final List<NotificationListenerAdapter> notifiStreamJSON =
CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContextRef,
NotificationOutputType.JSON.getName());
- notifiStreamJSON.addAll(notifiStreamXML);
-
- for (final NotificationListenerAdapter listener : notifiStreamJSON) {
+ for (final NotificationListenerAdapter listener : Iterables.concat(notifiStreamXML, notifiStreamJSON)) {
final URI uri = SubscribeToStreamUtil.prepareUriByStreamName(uriInfo, listener.getStreamName());
final NormalizedNode mapToStreams =
RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring(
((ListSchemaNode) childSchema).getKeyDefinition());
builder.withChild(childBuilder.build());
} else if (child instanceof LeafNode) {
- final String defaultVal = ((LeafSchemaNode) childSchema).getDefault();
- final String nodeVal = ((LeafNode<String>) child).getValue();
+ final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null);
+ final Object nodeVal = ((LeafNode<?>) child).getValue();
final NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>> leafBuilder =
Builders.leafBuilder((LeafSchemaNode) childSchema);
if (keys.contains(child.getNodeType())) {
builder.withChild(leafBuilder.build());
} else {
if (trim) {
- if ((defaultVal == null) || !defaultVal.equals(nodeVal)) {
+ if (defaultVal == null || !defaultVal.equals(nodeVal)) {
leafBuilder.withValue(((LeafNode) child).getValue());
builder.withChild(leafBuilder.build());
}
} else {
- if ((defaultVal != null) && defaultVal.equals(nodeVal)) {
+ if (defaultVal != null && defaultVal.equals(nodeVal)) {
leafBuilder.withValue(((LeafNode) child).getValue());
builder.withChild(leafBuilder.build());
}
((ListSchemaNode) childSchema).getKeyDefinition());
builder.withChild(childBuilder.build());
} else if (child instanceof LeafNode) {
- final String defaultVal = ((LeafSchemaNode) childSchema).getDefault();
- final String nodeVal = ((LeafNode<String>) child).getValue();
+ final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null);
+ final Object nodeVal = ((LeafNode<?>) child).getValue();
final NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>> leafBuilder =
Builders.leafBuilder((LeafSchemaNode) childSchema);
if (trim) {
- if ((defaultVal == null) || !defaultVal.equals(nodeVal)) {
+ if (defaultVal == null || !defaultVal.equals(nodeVal)) {
leafBuilder.withValue(((LeafNode) child).getValue());
builder.withChild(leafBuilder.build());
}
} else {
- if ((defaultVal != null) && defaultVal.equals(nodeVal)) {
+ if (defaultVal != null && defaultVal.equals(nodeVal)) {
leafBuilder.withValue(((LeafNode) child).getValue());
builder.withChild(leafBuilder.build());
}
}
// if no data exists
- if ((stateDataNode == null) && (configDataNode == null)) {
+ if (stateDataNode == null && configDataNode == null) {
return null;
}
* 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 MapNode) {
+ if (configDataNode instanceof OrderedMapNode) {
+ final CollectionNodeBuilder<MapEntryNode, OrderedMapNode> builder = Builders
+ .orderedMapBuilder().withNodeIdentifier(((MapNode) configDataNode).getIdentifier());
+
+ mapValueToBuilder(
+ ((OrderedMapNode) configDataNode).getValue(), ((OrderedMapNode) stateDataNode).getValue(), builder);
+
+ return builder.build();
+ } else if (configDataNode instanceof MapNode) {
final CollectionNodeBuilder<MapEntryNode, MapNode> builder = ImmutableNodes
.mapNodeBuilder().withNodeIdentifier(((MapNode) configDataNode).getIdentifier());
return builder.build();
} else if (configDataNode instanceof LeafNode) {
return ImmutableNodes.leafNode(configDataNode.getNodeType(), configDataNode.getValue());
+ } else if (configDataNode instanceof OrderedLeafSetNode) {
+ final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder = Builders
+ .orderedLeafSetBuilder().withNodeIdentifier(((OrderedLeafSetNode<?>) configDataNode).getIdentifier());
+
+ mapValueToBuilder(((OrderedLeafSetNode<Object>) configDataNode).getValue(),
+ ((OrderedLeafSetNode<Object>) stateDataNode).getValue(), builder);
+ return builder.build();
+ } else if (configDataNode instanceof LeafSetNode) {
+ final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder = Builders
+ .leafSetBuilder().withNodeIdentifier(((LeafSetNode<?>) configDataNode).getIdentifier());
+
+ mapValueToBuilder(((LeafSetNode<Object>) configDataNode).getValue(),
+ ((LeafSetNode<Object>) stateDataNode).getValue(), builder);
+ return builder.build();
+ } else if (configDataNode instanceof UnkeyedListNode) {
+ final CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> builder = Builders
+ .unkeyedListBuilder().withNodeIdentifier(((UnkeyedListNode) configDataNode).getIdentifier());
+
+ mapValueToBuilder(((UnkeyedListNode) configDataNode).getValue(),
+ ((UnkeyedListNode) stateDataNode).getValue(), builder);
+ return builder.build();
+ } else if (configDataNode instanceof UnkeyedListEntryNode) {
+ final DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> builder = Builders
+ .unkeyedListEntryBuilder().withNodeIdentifier(((UnkeyedListEntryNode) configDataNode).getIdentifier());
+
+ mapValueToBuilder(((UnkeyedListEntryNode) configDataNode).getValue(),
+ ((UnkeyedListEntryNode) stateDataNode).getValue(), builder);
+ return builder.build();
} else {
- throw new RestconfDocumentedException("Bad type of node.");
+ throw new RestconfDocumentedException("Unexpected node type: " + configDataNode.getClass().getName());
}
}