X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FControllerContext.xtend;h=882c73d001071dea11ee8bfb1d253887780a0875;hp=c1ee611e07c77241b1346f0683387d503111e1e9;hb=4f4df9918bc2d1447393edac6fbf3a2d4f9d9186;hpb=d490a11b531a724b9f46ca931b2c98e9527dde7f diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend index c1ee611e07..882c73d001 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend @@ -9,7 +9,6 @@ import java.util.HashMap import java.util.List import java.util.Map import java.util.concurrent.ConcurrentHashMap -import javax.ws.rs.WebApplicationException import javax.ws.rs.core.Response import org.opendaylight.controller.sal.core.api.model.SchemaServiceListener import org.opendaylight.controller.sal.rest.impl.RestconfProvider @@ -46,7 +45,7 @@ class ControllerContext implements SchemaServiceListener { private new() { - if (INSTANCE != null) { + if (INSTANCE !== null) { throw new IllegalStateException("Already instantiated"); } } @@ -56,9 +55,8 @@ class ControllerContext implements SchemaServiceListener { } private def void checkPreconditions() { - if (schemas == null) { - throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE) - .entity(RestconfProvider::NOT_INITALIZED_MSG).build()) + if (schemas === null) { + throw new ResponseException(Response.Status.SERVICE_UNAVAILABLE, RestconfProvider::NOT_INITALIZED_MSG) } } @@ -72,7 +70,7 @@ class ControllerContext implements SchemaServiceListener { pathArgs.remove(0) } val schemaNode = ret.collectPathArguments(pathArgs, restconfInstance.findModule); - if (schemaNode == null) { + if (schemaNode === null) { return null } new InstanceIdWithSchemaNode(ret.toInstance, schemaNode) @@ -92,7 +90,7 @@ class ControllerContext implements SchemaServiceListener { private def getLatestModule(SchemaContext schema, String moduleName) { checkNotNull(schema) - checkArgument(moduleName != null && !moduleName.empty) + checkArgument(moduleName !== null && !moduleName.empty) val modules = schema.modules.filter[m|m.name == moduleName] var latestModule = modules.head for (module : modules) { @@ -130,13 +128,32 @@ class ControllerContext implements SchemaServiceListener { private def dispatch CharSequence toRestconfIdentifier(PathArgument argument, DataSchemaNode node) { throw new IllegalArgumentException("Conversion of generic path argument is not supported"); } + + def findModuleByNamespace(URI namespace) { + checkPreconditions + var module = uriToModuleName.get(namespace) + if (module === null) { + val moduleSchemas = schemas.findModuleByNamespace(namespace); + if(moduleSchemas === null) throw new IllegalArgumentException() + var latestModule = moduleSchemas.head + for (m : moduleSchemas) { + if (m.revision.after(latestModule.revision)) { + latestModule = m + } + } + if(latestModule === null) throw new IllegalArgumentException() + uriToModuleName.put(namespace, latestModule.name) + module = latestModule.name; + } + return module + } def CharSequence toRestconfIdentifier(QName qname) { checkPreconditions var module = uriToModuleName.get(qname.namespace) - if (module == null) { + if (module === null) { val moduleSchema = schemas.findModuleByNamespaceAndRevision(qname.namespace, qname.revision); - if(moduleSchema == null) throw new IllegalArgumentException() + if(moduleSchema === null) throw new IllegalArgumentException() uriToModuleName.put(qname.namespace, moduleSchema.name) module = moduleSchema.name; } @@ -189,13 +206,16 @@ class ControllerContext implements SchemaServiceListener { } private def toUriString(Object object) { - if(object == null) return ""; + if(object === null) return ""; return URLEncoder.encode(object.toString) } private def DataSchemaNode collectPathArguments(InstanceIdentifierBuilder builder, List strings, DataNodeContainer parentNode) { checkNotNull(strings) + if (parentNode === null) { + return null; + } if (strings.empty) { return parentNode as DataSchemaNode; } @@ -203,14 +223,14 @@ class ControllerContext implements SchemaServiceListener { val nodeName = nodeRef.toNodeName(); val targetNode = parentNode.getDataChildByName(nodeName); - if (targetNode == null) { + if (targetNode === null) { val children = parentNode.childNodes for (child : children) { if (child instanceof ChoiceNode) { val choice = child as ChoiceNode for (caze : choice.cases) { val result = builder.collectPathArguments(strings, caze as DataNodeContainer); - if (result != null) + if (result !== null) return result } }