}
protected Map<InstanceIdentifier<?>, DataObject> toBinding(
+ InstanceIdentifier<?> path,
final Map<YangInstanceIdentifier, ? extends NormalizedNode<?, ?>> normalized) {
Map<InstanceIdentifier<?>, DataObject> newMap = new HashMap<>();
if (potential.isPresent()) {
Entry<InstanceIdentifier<? extends DataObject>, DataObject> binding = potential.get();
newMap.put(binding.getKey(), binding.getValue());
+ } else if (entry.getKey().getLastPathArgument() instanceof YangInstanceIdentifier.AugmentationIdentifier) {
+ DataObject bindingDataObject = getCodec().toBinding(path, entry.getValue());
+ if (bindingDataObject != null) {
+ newMap.put(path, bindingDataObject);
+ }
}
} catch (DeserializationException e) {
LOG.warn("Failed to transform {}, omitting it", entry, e);
}
}
- protected Set<InstanceIdentifier<?>> toBinding(
+ protected Set<InstanceIdentifier<?>> toBinding(InstanceIdentifier<?> path,
final Set<YangInstanceIdentifier> normalized) {
Set<InstanceIdentifier<?>> hashSet = new HashSet<>();
for (YangInstanceIdentifier normalizedPath : normalized) {
if (potential.isPresent()) {
InstanceIdentifier<? extends DataObject> binding = potential.get();
hashSet.add(binding);
+ } else if (normalizedPath.getLastPathArgument() instanceof YangInstanceIdentifier.AugmentationIdentifier) {
+ hashSet.add(path);
}
} catch (DeserializationException e) {
LOG.warn("Failed to transform {}, omitting it", normalizedPath, e);
@Override
public Map<InstanceIdentifier<?>, DataObject> getCreatedData() {
if (createdCache == null) {
- createdCache = Collections.unmodifiableMap(toBinding(domEvent.getCreatedData()));
+ createdCache = Collections.unmodifiableMap(toBinding(path, domEvent.getCreatedData()));
}
return createdCache;
}
@Override
public Map<InstanceIdentifier<?>, DataObject> getUpdatedData() {
if (updatedCache == null) {
- updatedCache = Collections.unmodifiableMap(toBinding(domEvent.getUpdatedData()));
+ updatedCache = Collections.unmodifiableMap(toBinding(path, domEvent.getUpdatedData()));
}
return updatedCache;
@Override
public Set<InstanceIdentifier<?>> getRemovedPaths() {
if (removedCache == null) {
- removedCache = Collections.unmodifiableSet(toBinding(domEvent.getRemovedPaths()));
+ removedCache = Collections.unmodifiableSet(toBinding(path, domEvent.getRemovedPaths()));
}
return removedCache;
}
@Override
public Map<InstanceIdentifier<?>, DataObject> getOriginalData() {
if (originalCache == null) {
- originalCache = Collections.unmodifiableMap(toBinding(domEvent.getOriginalData()));
+ originalCache = Collections.unmodifiableMap(toBinding(path, domEvent.getOriginalData()));
}
return originalCache;
--- /dev/null
+package org.opendaylight.controller.md.sal.binding.impl.test;
+
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeLeafOnlyUsesAugment;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUses;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUsesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertContains;
+import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertEmpty;
+import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.top;
+import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
+import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList;
+import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.leafOnlyUsesAugment;
+import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.complexUsesAugment;
+
+public class Bug1418AugmentationTest extends AbstractDataChangeListenerTest{
+ private static final InstanceIdentifier<Top> TOP = InstanceIdentifier.create(Top.class);
+ private static final InstanceIdentifier<TopLevelList> TOP_FOO = TOP.child(TopLevelList.class, TOP_FOO_KEY);
+ private static final InstanceIdentifier<TreeLeafOnlyUsesAugment> SIMPLE_AUGMENT =
+ TOP.child(TopLevelList.class, TOP_FOO_KEY).augmentation(TreeLeafOnlyUsesAugment.class);
+ private static final InstanceIdentifier<TreeComplexUsesAugment> COMPLEX_AUGMENT =
+ TOP.child(TopLevelList.class, TOP_FOO_KEY).augmentation(TreeComplexUsesAugment.class);
+ private static final ListViaUsesKey LIST_VIA_USES_KEY =
+ new ListViaUsesKey("list key");
+ private static final ListViaUsesKey LIST_VIA_USES_KEY_MOD =
+ new ListViaUsesKey("list key modified");
+
+ @Test
+ public void leafOnlyAugmentationCreatedTest() {
+ TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT,
+ AsyncDataBroker.DataChangeScope.SUBTREE);
+ WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf"));
+ assertCommit(writeTx.submit());
+ assertTrue(listener.hasEvent());
+ AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
+ assertContains(event.getCreatedData(), SIMPLE_AUGMENT);
+ assertEmpty(event.getUpdatedData());
+ assertEmpty(event.getOriginalData());
+ assertEmpty(event.getRemovedPaths());
+ }
+
+ @Test
+ public void leafOnlyAugmentationUpdatedTest() {
+ WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf"));
+ assertCommit(writeTx.submit());
+ TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT,
+ AsyncDataBroker.DataChangeScope.SUBTREE);
+ writeTx = getDataBroker().newWriteOnlyTransaction();
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf changed"));
+ assertCommit(writeTx.submit());
+ assertTrue(listener.hasEvent());
+ AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
+ assertContains(event.getUpdatedData(), SIMPLE_AUGMENT);
+ assertContains(event.getOriginalData(), SIMPLE_AUGMENT);
+ assertEmpty(event.getCreatedData());
+ assertEmpty(event.getRemovedPaths());
+ }
+
+ @Test
+ public void leafOnlyAugmentationDeletedTest() {
+ WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf"));
+ assertCommit(writeTx.submit());
+ TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT,
+ AsyncDataBroker.DataChangeScope.SUBTREE);
+ writeTx = getDataBroker().newWriteOnlyTransaction();
+ writeTx.delete(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT);
+ assertCommit(writeTx.submit());
+ assertTrue(listener.hasEvent());
+ AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
+ assertContains(event.getRemovedPaths(), SIMPLE_AUGMENT);
+ assertContains(event.getOriginalData(), SIMPLE_AUGMENT);
+ assertEmpty(event.getCreatedData());
+ assertEmpty(event.getUpdatedData());
+ }
+
+ @Test
+ public void complexAugmentationCreatedTest() {
+ TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT,
+ AsyncDataBroker.DataChangeScope.SUBTREE);
+ WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY));
+ assertCommit(writeTx.submit());
+ assertTrue(listener.hasEvent());
+ AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
+ assertContains(event.getCreatedData(), COMPLEX_AUGMENT);
+ assertContains(event.getCreatedData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY));
+ assertEmpty(event.getUpdatedData());
+ assertEmpty(event.getOriginalData());
+ assertEmpty(event.getRemovedPaths());
+ }
+
+ @Test
+ public void complexAugmentationUpdatedTest() {
+ WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY));
+ assertCommit(writeTx.submit());
+ TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT,
+ AsyncDataBroker.DataChangeScope.SUBTREE);
+ writeTx = getDataBroker().newWriteOnlyTransaction();
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY_MOD));
+ assertCommit(writeTx.submit());
+ assertTrue(listener.hasEvent());
+ AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
+ assertContains(event.getUpdatedData(), COMPLEX_AUGMENT);
+ assertContains(event.getCreatedData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY_MOD));
+ assertContains(event.getRemovedPaths(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY));
+ assertContains(event.getOriginalData(), COMPLEX_AUGMENT);
+ assertContains(event.getOriginalData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY));
+ }
+}
import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import java.io.UnsupportedEncodingException;
private static final Splitter SLASH_SPLITTER = Splitter.on('/');
- private final BiMap<URI, String> uriToModuleName = HashBiMap.<URI, String> create();
-
- private final Map<String, URI> moduleNameToUri = uriToModuleName.inverse();
-
private final AtomicReference<Map<QName, RpcDefinition>> qnameToRpc =
new AtomicReference<>(Collections.<QName, RpcDefinition>emptyMap());
public String findModuleNameByNamespace(final URI namespace) {
this.checkPreconditions();
- String moduleName = this.uriToModuleName.get(namespace);
- if (moduleName == null) {
- final Module module = this.findModuleByNamespace(namespace);
- if (module != null) {
- moduleName = module.getName();
- this.uriToModuleName.put(namespace, moduleName);
- }
- }
-
- return moduleName;
+ final Module module = this.findModuleByNamespace(namespace);
+ return module == null ? null : module.getName();
}
public String findModuleNameByNamespace(final DOMMountPoint mountPoint, final URI namespace) {
}
public URI findNamespaceByModuleName(final String moduleName) {
- URI namespace = this.moduleNameToUri.get(moduleName);
- if (namespace == null) {
- Module module = this.findModuleByName(moduleName);
- if (module != null) {
- URI _namespace = module.getNamespace();
- namespace = _namespace;
- this.uriToModuleName.put(namespace, moduleName);
- }
- }
- return namespace;
+ final Module module = this.findModuleByName(moduleName);
+ return module == null ? null : module.getNamespace();
}
public URI findNamespaceByModuleName(final DOMMountPoint mountPoint, final String moduleName) {
return globalSchema.getModules();
}
+ private static final CharSequence toRestconfIdentifier(final SchemaContext context, final QName qname) {
+ final Module schema = context.findModuleByNamespaceAndRevision(qname.getNamespace(), qname.getRevision());
+ return schema == null ? null : schema.getName() + ':' + qname.getLocalName();
+ }
+
public CharSequence toRestconfIdentifier(final QName qname) {
this.checkPreconditions();
- String module = this.uriToModuleName.get(qname.getNamespace());
- if (module == null) {
- final Module moduleSchema = globalSchema.findModuleByNamespaceAndRevision(qname.getNamespace(),
- qname.getRevision());
- if (moduleSchema == null) {
- return null;
- }
-
- this.uriToModuleName.put(qname.getNamespace(), moduleSchema.getName());
- module = moduleSchema.getName();
- }
-
- StringBuilder builder = new StringBuilder();
- builder.append(module);
- builder.append(":");
- builder.append(qname.getLocalName());
- return builder.toString();
+ return toRestconfIdentifier(globalSchema, qname);
}
public CharSequence toRestconfIdentifier(final DOMMountPoint mountPoint, final QName qname) {
return null;
}
- SchemaContext schemaContext = mountPoint.getSchemaContext();
-
- final Module moduleSchema = schemaContext.findModuleByNamespaceAndRevision(qname.getNamespace(),
- qname.getRevision());
- if (moduleSchema == null) {
- return null;
- }
-
- StringBuilder builder = new StringBuilder();
- builder.append(moduleSchema.getName());
- builder.append(":");
- builder.append(qname.getLocalName());
- return builder.toString();
+ return toRestconfIdentifier(mountPoint.getSchemaContext(), qname);
}
public Module getRestconfModule() {
final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
- List<DataSchemaNode> instanceDataChildrenByName = this.findInstanceDataChildrenByName(restconfGrouping,
+ List<DataSchemaNode> instanceDataChildrenByName = findInstanceDataChildrenByName(restconfGrouping,
Draft02.RestConfModule.ERRORS_CONTAINER_SCHEMA_NODE);
return Iterables.getFirst(instanceDataChildrenByName, null);
}
Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings, GROUPING_FILTER);
final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
- List<DataSchemaNode> instanceDataChildrenByName = this.findInstanceDataChildrenByName(restconfGrouping,
+ List<DataSchemaNode> instanceDataChildrenByName = findInstanceDataChildrenByName(restconfGrouping,
Draft02.RestConfModule.RESTCONF_CONTAINER_SCHEMA_NODE);
final DataSchemaNode restconfContainer = Iterables.getFirst(instanceDataChildrenByName, null);
if (Objects.equal(schemaNodeName, Draft02.RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE)) {
- List<DataSchemaNode> instances = this.findInstanceDataChildrenByName(
+ List<DataSchemaNode> instances = findInstanceDataChildrenByName(
((DataNodeContainer) restconfContainer), Draft02.RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE);
return Iterables.getFirst(instances, null);
} else if (Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE)) {
- List<DataSchemaNode> instances = this.findInstanceDataChildrenByName(
+ List<DataSchemaNode> instances = findInstanceDataChildrenByName(
((DataNodeContainer) restconfContainer), Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
return Iterables.getFirst(instances, null);
} else if (Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE)) {
- List<DataSchemaNode> instances = this.findInstanceDataChildrenByName(
+ List<DataSchemaNode> instances = findInstanceDataChildrenByName(
((DataNodeContainer) restconfContainer), Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
final DataSchemaNode modules = Iterables.getFirst(instances, null);
- instances = this.findInstanceDataChildrenByName(((DataNodeContainer) modules),
+ instances = findInstanceDataChildrenByName(((DataNodeContainer) modules),
Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE);
return Iterables.getFirst(instances, null);
} else if (Objects.equal(schemaNodeName, Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE)) {
- List<DataSchemaNode> instances = this.findInstanceDataChildrenByName(
+ List<DataSchemaNode> instances = findInstanceDataChildrenByName(
((DataNodeContainer) restconfContainer), Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
return Iterables.getFirst(instances, null);
} else if (Objects.equal(schemaNodeName, Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE)) {
- List<DataSchemaNode> instances = this.findInstanceDataChildrenByName(
+ List<DataSchemaNode> instances = findInstanceDataChildrenByName(
((DataNodeContainer) restconfContainer), Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
final DataSchemaNode modules = Iterables.getFirst(instances, null);
- instances = this.findInstanceDataChildrenByName(((DataNodeContainer) modules),
+ instances = findInstanceDataChildrenByName(((DataNodeContainer) modules),
Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE);
return Iterables.getFirst(instances, null);
} else if (Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE)) {
- List<DataSchemaNode> instances = this.findInstanceDataChildrenByName(
+ List<DataSchemaNode> instances = findInstanceDataChildrenByName(
((DataNodeContainer) restconfContainer), Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
return Iterables.getFirst(instances, null);
}
}
}
- targetNode = this.findInstanceDataChildByNameAndNamespace(parentNode, nodeName, module.getNamespace());
+ targetNode = findInstanceDataChildByNameAndNamespace(parentNode, nodeName, module.getNamespace());
if (targetNode == null) {
throw new RestconfDocumentedException("URI has bad format. Possible reasons:\n" + " 1. \"" + head
+ "\" was not found in parent data node.\n" + " 2. \"" + head
ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
} else {
- final List<DataSchemaNode> potentialSchemaNodes = this.findInstanceDataChildrenByName(parentNode, nodeName);
+ final List<DataSchemaNode> potentialSchemaNodes = findInstanceDataChildrenByName(parentNode, nodeName);
if (potentialSchemaNodes.size() > 1) {
final StringBuilder strBuilder = new StringBuilder();
for (final DataSchemaNode potentialNodeSchema : potentialSchemaNodes) {
return new InstanceIdWithSchemaNode(builder.toInstance(), targetNode, mountPoint);
}
- public DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container, final String name,
+ public static DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container, final String name,
final URI namespace) {
Preconditions.<URI> checkNotNull(namespace);
- final List<DataSchemaNode> potentialSchemaNodes = this.findInstanceDataChildrenByName(container, name);
+ final List<DataSchemaNode> potentialSchemaNodes = findInstanceDataChildrenByName(container, name);
Predicate<DataSchemaNode> filter = new Predicate<DataSchemaNode>() {
@Override
return Iterables.getFirst(result, null);
}
- public List<DataSchemaNode> findInstanceDataChildrenByName(final DataNodeContainer container, final String name) {
+ public static List<DataSchemaNode> findInstanceDataChildrenByName(final DataNodeContainer container, final String name) {
Preconditions.<DataNodeContainer> checkNotNull(container);
Preconditions.<String> checkNotNull(name);
List<DataSchemaNode> instantiatedDataNodeContainers = new ArrayList<DataSchemaNode>();
- this.collectInstanceDataNodeContainers(instantiatedDataNodeContainers, container, name);
+ collectInstanceDataNodeContainers(instantiatedDataNodeContainers, container, name);
return instantiatedDataNodeContainers;
}
}
};
- private void collectInstanceDataNodeContainers(final List<DataSchemaNode> potentialSchemaNodes,
+ private static void collectInstanceDataNodeContainers(final List<DataSchemaNode> potentialSchemaNodes,
final DataNodeContainer container, final String name) {
Predicate<DataSchemaNode> filter = new Predicate<DataSchemaNode>() {
// Can't combine this loop with the filter above because the filter is
// lazily-applied by Iterables.filter.
for (final DataSchemaNode potentialNode : nodes) {
- if (this.isInstantiatedDataSchema(potentialNode)) {
+ if (isInstantiatedDataSchema(potentialNode)) {
potentialSchemaNodes.add(potentialNode);
}
}
final Iterable<ChoiceCaseNode> allCases = Iterables.<ChoiceCaseNode> concat(map);
for (final ChoiceCaseNode caze : allCases) {
- this.collectInstanceDataNodeContainers(potentialSchemaNodes, caze, name);
+ collectInstanceDataNodeContainers(potentialSchemaNodes, caze, name);
}
}
- public boolean isInstantiatedDataSchema(final DataSchemaNode node) {
+ public static boolean isInstantiatedDataSchema(final DataSchemaNode node) {
return node instanceof LeafSchemaNode || node instanceof LeafListSchemaNode
|| node instanceof ContainerSchemaNode || node instanceof ListSchemaNode
|| node instanceof AnyXmlSchemaNode;
}
private CharSequence convertToRestconfIdentifier(final NodeIdentifier argument, final ContainerSchemaNode node) {
- StringBuilder builder = new StringBuilder();
- builder.append("/");
- QName nodeType = argument.getNodeType();
- builder.append(this.toRestconfIdentifier(nodeType));
- return builder.toString();
+ return "/" + this.toRestconfIdentifier(argument.getNodeType());
}
private CharSequence convertToRestconfIdentifier(final NodeIdentifierWithPredicates argument,
final Map<QName, Object> keyValues = argument.getKeyValues();
StringBuilder builder = new StringBuilder();
- builder.append("/");
+ builder.append('/');
builder.append(nodeIdentifier);
- builder.append("/");
+ builder.append('/');
List<QName> keyDefinition = node.getKeyDefinition();
boolean hasElements = false;
if (!hasElements) {
hasElements = true;
} else {
- builder.append("/");
+ builder.append('/');
}
try {
for (int i = 0; i < identities.size(); i++) {
IdentityValue identityValue = identities.get(i);
URI validNamespace = resolveValidNamespace(identityValue.getNamespace(), mountPoint);
- DataSchemaNode node = ControllerContext.getInstance().findInstanceDataChildByNameAndNamespace(
+ DataSchemaNode node = ControllerContext.findInstanceDataChildByNameAndNamespace(
parentContainer, identityValue.getValue(), validNamespace);
if (node == null) {
logger.info("'{}' node was not found in {}", identityValue, parentContainer.getChildNodes());
Map<QName, Object> predicatesMap = new HashMap<>();
for (Predicate predicate : identityValue.getPredicates()) {
validNamespace = resolveValidNamespace(predicate.getName().getNamespace(), mountPoint);
- DataSchemaNode listKey = ControllerContext.getInstance()
+ DataSchemaNode listKey = ControllerContext
.findInstanceDataChildByNameAndNamespace(listNode, predicate.getName().getValue(),
validNamespace);
predicatesMap.put(listKey.getQName(), predicate.getValue());
}
result.add(pathArgument);
if (i < identities.size() - 1) { // last element in instance-identifier can be other than
- // DataNodeContainer
+ // DataNodeContainer
if (node instanceof DataNodeContainer) {
parentContainer = (DataNodeContainer) node;
} else {
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
+
import java.net.URI;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+
import org.apache.commons.lang3.StringUtils;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
private CompositeNode toStreamCompositeNode(final String streamName, final DataSchemaNode streamSchemaNode) {
final List<Node<?>> streamNodeValues = new ArrayList<Node<?>>();
- List<DataSchemaNode> instanceDataChildrenByName = this.controllerContext.findInstanceDataChildrenByName(
+ List<DataSchemaNode> instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
((DataNodeContainer) streamSchemaNode), "name");
final DataSchemaNode nameSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
streamNodeValues
- .add(NodeFactory.<String> createImmutableSimpleNode(nameSchemaNode.getQName(), null, streamName));
+ .add(NodeFactory.<String> createImmutableSimpleNode(nameSchemaNode.getQName(), null, streamName));
- instanceDataChildrenByName = this.controllerContext.findInstanceDataChildrenByName(
+ instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
((DataNodeContainer) streamSchemaNode), "description");
final DataSchemaNode descriptionSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
streamNodeValues.add(NodeFactory.<String> createImmutableSimpleNode(descriptionSchemaNode.getQName(), null,
"DESCRIPTION_PLACEHOLDER"));
- instanceDataChildrenByName = this.controllerContext.findInstanceDataChildrenByName(
+ instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
((DataNodeContainer) streamSchemaNode), "replay-support");
final DataSchemaNode replaySupportSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
streamNodeValues.add(NodeFactory.<Boolean> createImmutableSimpleNode(replaySupportSchemaNode.getQName(), null,
Boolean.valueOf(true)));
- instanceDataChildrenByName = this.controllerContext.findInstanceDataChildrenByName(
+ instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
((DataNodeContainer) streamSchemaNode), "replay-log-creation-time");
final DataSchemaNode replayLogCreationTimeSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
streamNodeValues.add(NodeFactory.<String> createImmutableSimpleNode(replayLogCreationTimeSchemaNode.getQName(),
null, ""));
- instanceDataChildrenByName = this.controllerContext.findInstanceDataChildrenByName(
+ instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
((DataNodeContainer) streamSchemaNode), "events");
final DataSchemaNode eventsSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
streamNodeValues.add(NodeFactory.<String> createImmutableSimpleNode(eventsSchemaNode.getQName(), null, ""));
private CompositeNode toModuleCompositeNode(final Module module, final DataSchemaNode moduleSchemaNode) {
final List<Node<?>> moduleNodeValues = new ArrayList<Node<?>>();
- List<DataSchemaNode> instanceDataChildrenByName = this.controllerContext.findInstanceDataChildrenByName(
+ List<DataSchemaNode> instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
((DataNodeContainer) moduleSchemaNode), "name");
final DataSchemaNode nameSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
moduleNodeValues.add(NodeFactory.<String> createImmutableSimpleNode(nameSchemaNode.getQName(), null,
module.getName()));
- instanceDataChildrenByName = this.controllerContext.findInstanceDataChildrenByName(
+ instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
((DataNodeContainer) moduleSchemaNode), "revision");
final DataSchemaNode revisionSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
Date _revision = module.getRevision();
moduleNodeValues.add(NodeFactory.<String> createImmutableSimpleNode(revisionSchemaNode.getQName(), null,
REVISION_FORMAT.format(_revision)));
- instanceDataChildrenByName = this.controllerContext.findInstanceDataChildrenByName(
+ instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
((DataNodeContainer) moduleSchemaNode), "namespace");
final DataSchemaNode namespaceSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
moduleNodeValues.add(NodeFactory.<String> createImmutableSimpleNode(namespaceSchemaNode.getQName(), null,
module.getNamespace().toString()));
- instanceDataChildrenByName = this.controllerContext.findInstanceDataChildrenByName(
+ instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
((DataNodeContainer) moduleSchemaNode), "feature");
final DataSchemaNode featureSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
for (final FeatureDefinition feature : module.getFeatures()) {
}
String payloadName = this.getName(payload);
- final DataSchemaNode schemaNode = this.controllerContext.findInstanceDataChildByNameAndNamespace(
+ final DataSchemaNode schemaNode = ControllerContext.findInstanceDataChildByNameAndNamespace(
parentSchema, payloadName, module.getNamespace());
value = this.normalizeNode(payload, schemaNode, mountPoint);
}
String payloadName = this.getName(payload);
- final DataSchemaNode schemaNode = this.controllerContext.findInstanceDataChildByNameAndNamespace(module,
+ final DataSchemaNode schemaNode = ControllerContext.findInstanceDataChildByNameAndNamespace(module,
payloadName, module.getNamespace());
final CompositeNode value = this.normalizeNode(payload, schemaNode, null);
final InstanceIdWithSchemaNode iiWithData = this.addLastIdentifierFromData(null, value, schemaNode);
private boolean representsMountPointRootData(final Node<?> data) {
URI namespace = this.namespace(data);
return (SchemaContext.NAME.getNamespace().equals(namespace) /*
- * || MOUNT_POINT_MODULE_NAME .equals( namespace .
- * toString( ) )
- */)
- && SchemaContext.NAME.getLocalName().equals(this.localName(data));
+ * || MOUNT_POINT_MODULE_NAME .equals( namespace .
+ * toString( ) )
+ */)
+ && SchemaContext.NAME.getLocalName().equals(this.localName(data));
}
private String addMountPointIdentifier(final String identifier) {
final List<NodeWrapper<?>> children = compositeNodeBuilder.getValues();
checkNodeMultiplicityAccordingToSchema(schema, children);
for (final NodeWrapper<? extends Object> child : children) {
- final List<DataSchemaNode> potentialSchemaNodes = this.controllerContext.findInstanceDataChildrenByName(
+ final List<DataSchemaNode> potentialSchemaNodes = ControllerContext.findInstanceDataChildrenByName(
schema, child.getLocalName());
if (potentialSchemaNodes.size() > 1 && child.getNamespace() == null) {
}
if (nodeBuilder.getNamespace() == null || Objects.equal(nodeBuilder.getNamespace(), validQName.getNamespace())
- || Objects.equal(nodeBuilder.getNamespace().toString(), moduleName) /*
- * || Note : this check is wrong -
- * can never be true as it compares
- * a URI with a String not sure what
- * the intention is so commented out
- * ... Objects . equal ( nodeBuilder
- * . getNamespace ( ) ,
- * MOUNT_POINT_MODULE_NAME )
- */) {
+ || Objects.equal(nodeBuilder.getNamespace().toString(), moduleName)) {
+ /*
+ * || Note : this check is wrong -
+ * can never be true as it compares
+ * a URI with a String not sure what
+ * the intention is so commented out
+ * ... Objects . equal ( nodeBuilder
+ * . getNamespace ( ) ,
+ * MOUNT_POINT_MODULE_NAME )
+ */
nodeBuilder.setQname(validQName);
}
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
expectLeaf("depth3-leaf1", "depth3-leaf1-value")));
}
+ /**
+ * Tests behavior when invalid value of depth URI parameter
+ */
@Test
public void getDataWithInvalidDepthParameterTest() {
private void getDataWithInvalidDepthParameterTest(final UriInfo uriInfo) {
try {
+ QName qNameDepth1Cont = QName.create("urn:nested:module", "2014-06-3", "depth1-cont");
+ YangInstanceIdentifier ii = YangInstanceIdentifier.builder().node(qNameDepth1Cont).build();
+ NormalizedNode value = (NormalizedNode<?,?>)(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(qNameDepth1Cont)).build());
+ when(brokerFacade.readConfigurationData(eq(ii))).thenReturn(value);
restconfImpl.readConfigurationData("nested-module:depth1-cont", uriInfo);
fail("Expected RestconfDocumentedException");
} catch (RestconfDocumentedException e) {
*/
package org.opendaylight.controller.md.sal.test.model.util;
-import java.util.Arrays;
-
+import com.google.common.collect.ImmutableList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeLeafOnlyUsesAugment;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeLeafOnlyUsesAugmentBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUses;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUsesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUsesKey;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import com.google.common.collect.ImmutableList;
+import java.util.Arrays;
public class ListsBindingUtils {
return new TreeComplexUsesAugmentBuilder().setListViaUses(listViaUses.build()).build();
}
+ public static TreeLeafOnlyUsesAugment leafOnlyUsesAugment(String leafFromGroupingValue) {
+
+ return new TreeLeafOnlyUsesAugmentBuilder().setLeafFromGrouping(leafFromGroupingValue).build();
+ }
+
}