X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FControllerContext.java;h=91e24541994487089be96a7ce3586d09320c4a32;hb=b268243d7b907ea36f15e2baf6b50e44789797d8;hp=dad7a2cda2ff3f647d58d66fcd6a37dd36b10c62;hpb=c222e37f2a0f0f3f6266242fbea2d3b018f4e6e3;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java index dad7a2cda2..91e2454199 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java @@ -143,7 +143,7 @@ public class ControllerContext implements SchemaContextListener { } InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder(); - Module latestModule = this.getLatestModule(globalSchema, startModule); + Module latestModule = globalSchema.findModuleByName(startModule, null); InstanceIdWithSchemaNode iiWithSchemaNode = this.collectPathArguments(builder, pathArgs, latestModule, null, toMountPointIdentifier); @@ -175,59 +175,38 @@ public class ControllerContext implements SchemaContextListener { return list; } - - private Module getLatestModule(final SchemaContext schema, final String moduleName) { - Preconditions.checkArgument(schema != null); - Preconditions.checkArgument(moduleName != null && !moduleName.isEmpty()); - - Predicate filter = new Predicate() { - @Override - public boolean apply(final Module m) { - return Objects.equal(m.getName(), moduleName); - } - }; - - Iterable modules = Iterables.filter(schema.getModules(), filter); - return this.filterLatestModule(modules); - } - - private Module filterLatestModule(final Iterable modules) { - Module latestModule = modules.iterator().hasNext() ? modules.iterator().next() : null; - for (final Module module : modules) { - if (module.getRevision().after(latestModule.getRevision())) { - latestModule = module; - } - } - return latestModule; - } - public Module findModuleByName(final String moduleName) { this.checkPreconditions(); Preconditions.checkArgument(moduleName != null && !moduleName.isEmpty()); - return this.getLatestModule(globalSchema, moduleName); + return globalSchema.findModuleByName(moduleName, null); } public Module findModuleByName(final MountInstance mountPoint, final String moduleName) { Preconditions.checkArgument(moduleName != null && mountPoint != null); final SchemaContext mountPointSchema = mountPoint.getSchemaContext(); - return mountPointSchema == null ? null : this.getLatestModule(mountPointSchema, moduleName); + if (mountPointSchema == null) { + return null; + } + + return mountPointSchema.findModuleByName(moduleName, null); } public Module findModuleByNamespace(final URI namespace) { this.checkPreconditions(); Preconditions.checkArgument(namespace != null); - - final Set moduleSchemas = globalSchema.findModuleByNamespace(namespace); - return moduleSchemas == null ? null : this.filterLatestModule(moduleSchemas); + return globalSchema.findModuleByNamespaceAndRevision(namespace, null); } public Module findModuleByNamespace(final MountInstance mountPoint, final URI namespace) { Preconditions.checkArgument(namespace != null && mountPoint != null); final SchemaContext mountPointSchema = mountPoint.getSchemaContext(); - Set moduleSchemas = mountPointSchema == null ? null : mountPointSchema.findModuleByNamespace(namespace); - return moduleSchemas == null ? null : this.filterLatestModule(moduleSchemas); + if (mountPointSchema == null) { + return null; + } + + return mountPointSchema.findModuleByNamespaceAndRevision(namespace, null); } public Module findModuleByNameAndRevision(final QName module) { @@ -387,6 +366,13 @@ public class ControllerContext implements SchemaContextListener { return findModuleByNameAndRevision(Draft02.RestConfModule.IETF_RESTCONF_QNAME); } + private static final Predicate ERRORS_GROUPING_FILTER = new Predicate() { + @Override + public boolean apply(final GroupingDefinition g) { + return Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName()); + } + }; + public DataSchemaNode getRestconfModuleErrorsSchemaNode() { Module restconfModule = getRestconfModule(); if (restconfModule == null) { @@ -395,14 +381,7 @@ public class ControllerContext implements SchemaContextListener { Set groupings = restconfModule.getGroupings(); - final Predicate filter = new Predicate() { - @Override - public boolean apply(final GroupingDefinition g) { - return Objects.equal(g.getQName().getLocalName(), Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE); - } - }; - - Iterable filteredGroups = Iterables.filter(groupings, filter); + Iterable filteredGroups = Iterables.filter(groupings, ERRORS_GROUPING_FILTER); final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null); @@ -411,6 +390,13 @@ public class ControllerContext implements SchemaContextListener { return Iterables.getFirst(instanceDataChildrenByName, null); } + private static final Predicate GROUPING_FILTER = new Predicate() { + @Override + public boolean apply(final GroupingDefinition g) { + return Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName()); + } + }; + public DataSchemaNode getRestconfModuleRestConfSchemaNode(final Module inRestconfModule, final String schemaNodeName) { Module restconfModule = inRestconfModule; if (restconfModule == null) { @@ -422,16 +408,7 @@ public class ControllerContext implements SchemaContextListener { } Set groupings = restconfModule.getGroupings(); - - final Predicate filter = new Predicate() { - @Override - public boolean apply(final GroupingDefinition g) { - return Objects.equal(g.getQName().getLocalName(), Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE); - } - }; - - Iterable filteredGroups = Iterables.filter(groupings, filter); - + Iterable filteredGroups = Iterables.filter(groupings, GROUPING_FILTER); final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null); List instanceDataChildrenByName = this.findInstanceDataChildrenByName(restconfGrouping, @@ -508,9 +485,9 @@ public class ControllerContext implements SchemaContextListener { DataSchemaNode ret = container.getDataChildByName(name); if (ret == null) { for (final DataSchemaNode node : container.getChildNodes()) { - if ((node instanceof ChoiceCaseNode)) { - final ChoiceCaseNode caseNode = ((ChoiceCaseNode) node); - DataSchemaNode childByQName = ControllerContext.childByQName(caseNode, name); + if ((node instanceof ChoiceNode)) { + final ChoiceNode choiceNode = ((ChoiceNode) node); + DataSchemaNode childByQName = ControllerContext.childByQName(choiceNode, name); if (childByQName != null) { return childByQName; } @@ -587,8 +564,7 @@ public class ControllerContext implements SchemaContextListener { ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); } - final Module moduleBehindMountPoint = this - .getLatestModule(mountPointSchema, moduleNameBehindMountPoint); + final Module moduleBehindMountPoint = mountPointSchema.findModuleByName(moduleNameBehindMountPoint, null); if (moduleBehindMountPoint == null) { throw new RestconfDocumentedException("\"" + moduleName + "\" module does not exist in mount point.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT); @@ -601,14 +577,18 @@ public class ControllerContext implements SchemaContextListener { Module module = null; if (mountPoint == null) { - module = this.getLatestModule(globalSchema, moduleName); + module = globalSchema.findModuleByName(moduleName, null); if (module == null) { throw new RestconfDocumentedException("\"" + moduleName + "\" module does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT); } } else { SchemaContext schemaContext = mountPoint.getSchemaContext(); - module = schemaContext == null ? null : this.getLatestModule(schemaContext, moduleName); + if (schemaContext != null) { + module = schemaContext.findModuleByName(moduleName, null); + } else { + module = null; + } if (module == null) { throw new RestconfDocumentedException("\"" + moduleName + "\" module does not exist in mount point.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT); @@ -719,6 +699,13 @@ public class ControllerContext implements SchemaContextListener { return instantiatedDataNodeContainers; } + private static final Function> CHOICE_FUNCTION = new Function>() { + @Override + public Set apply(final ChoiceNode node) { + return node.getCases(); + } + }; + private void collectInstanceDataNodeContainers(final List potentialSchemaNodes, final DataNodeContainer container, final String name) { @@ -739,17 +726,8 @@ public class ControllerContext implements SchemaContextListener { } } - Iterable choiceNodes = Iterables. filter(container.getChildNodes(), ChoiceNode.class); - - final Function> choiceFunction = new Function>() { - @Override - public Set apply(final ChoiceNode node) { - return node.getCases(); - } - }; - - Iterable> map = Iterables.> transform(choiceNodes, - choiceFunction); + Iterable choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceNode.class); + Iterable> map = Iterables.transform(choiceNodes, CHOICE_FUNCTION); final Iterable allCases = Iterables. concat(map); for (final ChoiceCaseNode caze : allCases) {