import org.opendaylight.controller.sal.core.api.mount.MountService
import org.opendaylight.controller.sal.rest.impl.RestUtil
import org.opendaylight.controller.sal.rest.impl.RestconfProvider
import org.opendaylight.controller.sal.core.api.mount.MountService
import org.opendaylight.controller.sal.rest.impl.RestUtil
import org.opendaylight.controller.sal.rest.impl.RestconfProvider
def findModuleByName(String moduleName) {
checkPreconditions
checkArgument(moduleName !== null && !moduleName.empty)
return globalSchema.getLatestModule(moduleName)
}
def findModuleByName(String moduleName) {
checkPreconditions
checkArgument(moduleName !== null && !moduleName.empty)
return globalSchema.getLatestModule(moduleName)
}
def findModuleByName(MountInstance mountPoint, String moduleName) {
checkArgument(moduleName !== null && mountPoint !== null)
val mountPointSchema = mountPoint.schemaContext;
return mountPointSchema?.getLatestModule(moduleName);
}
def findModuleByName(MountInstance mountPoint, String moduleName) {
checkArgument(moduleName !== null && mountPoint !== null)
val mountPointSchema = mountPoint.schemaContext;
return mountPointSchema?.getLatestModule(moduleName);
}
def findModuleByNamespace(URI namespace) {
checkPreconditions
checkArgument(namespace !== null)
val moduleSchemas = globalSchema.findModuleByNamespace(namespace)
return moduleSchemas?.filterLatestModule
}
def findModuleByNamespace(URI namespace) {
checkPreconditions
checkArgument(namespace !== null)
val moduleSchemas = globalSchema.findModuleByNamespace(namespace)
return moduleSchemas?.filterLatestModule
}
def findModuleByNamespace(MountInstance mountPoint, URI namespace) {
checkArgument(namespace !== null && mountPoint !== null)
val mountPointSchema = mountPoint.schemaContext;
def findModuleByNamespace(MountInstance mountPoint, URI namespace) {
checkArgument(namespace !== null && mountPoint !== null)
val mountPointSchema = mountPoint.schemaContext;
def findModuleNameByNamespace(MountInstance mountPoint, URI namespace) {
val module = mountPoint.findModuleByNamespace(namespace);
return module?.name
def findModuleNameByNamespace(MountInstance mountPoint, URI namespace) {
val module = mountPoint.findModuleByNamespace(namespace);
return module?.name
def findNamespaceByModuleName(MountInstance mountPoint, String moduleName) {
val module = mountPoint.findModuleByName(moduleName)
return module?.namespace
def findNamespaceByModuleName(MountInstance mountPoint, String moduleName) {
val module = mountPoint.findModuleByName(moduleName)
return module?.namespace
private def InstanceIdWithSchemaNode collectPathArguments(InstanceIdentifierBuilder builder, List<String> strings,
DataNodeContainer parentNode, MountInstance mountPoint) {
checkNotNull(strings)
private def InstanceIdWithSchemaNode collectPathArguments(InstanceIdentifierBuilder builder, List<String> strings,
DataNodeContainer parentNode, MountInstance mountPoint) {
checkNotNull(strings)
val nodeName = strings.head.toNodeName
val moduleName = strings.head.toModuleName
var DataSchemaNode targetNode = null
val nodeName = strings.head.toNodeName
val moduleName = strings.head.toModuleName
var DataSchemaNode targetNode = null
if (mountPoint !== null) {
throw new ResponseException(BAD_REQUEST, "Restconf supports just one mount point in URI.")
}
if (mountPoint !== null) {
throw new ResponseException(BAD_REQUEST, "Restconf supports just one mount point in URI.")
}
val partialPath = builder.toInstance;
val mount = mountService.getMountPoint(partialPath)
if (mount === null) {
LOG.debug("Instance identifier to missing mount point: {}", partialPath)
throw new ResponseException(BAD_REQUEST, "Mount point does not exist.")
}
val partialPath = builder.toInstance;
val mount = mountService.getMountPoint(partialPath)
if (mount === null) {
LOG.debug("Instance identifier to missing mount point: {}", partialPath)
throw new ResponseException(BAD_REQUEST, "Mount point does not exist.")
}
val mountPointSchema = mount.schemaContext;
if (mountPointSchema === null) {
throw new ResponseException(BAD_REQUEST, "Mount point does not contain any schema with modules.")
}
val mountPointSchema = mount.schemaContext;
if (mountPointSchema === null) {
throw new ResponseException(BAD_REQUEST, "Mount point does not contain any schema with modules.")
}
if (strings.size == 1) { // any data node is not behind mount point
return new InstanceIdWithSchemaNode(InstanceIdentifier.builder().toInstance, mountPointSchema, mount)
}
if (strings.size == 1) { // any data node is not behind mount point
return new InstanceIdWithSchemaNode(InstanceIdentifier.builder().toInstance, mountPointSchema, mount)
}
val moduleNameBehindMountPoint = strings.get(1).toModuleName()
if (moduleNameBehindMountPoint === null) {
throw new ResponseException(BAD_REQUEST,
"First node after mount point in URI has to be in format \"moduleName:nodeName\"")
}
val moduleNameBehindMountPoint = strings.get(1).toModuleName()
if (moduleNameBehindMountPoint === null) {
throw new ResponseException(BAD_REQUEST,
"First node after mount point in URI has to be in format \"moduleName:nodeName\"")
}
val moduleBehindMountPoint = mountPointSchema.getLatestModule(moduleNameBehindMountPoint)
if (moduleBehindMountPoint === null) {
throw new ResponseException(BAD_REQUEST,
"URI has bad format. \"" + moduleName + "\" module does not exist in mount point.")
}
val moduleBehindMountPoint = mountPointSchema.getLatestModule(moduleNameBehindMountPoint)
if (moduleBehindMountPoint === null) {
throw new ResponseException(BAD_REQUEST,
"URI has bad format. \"" + moduleName + "\" module does not exist in mount point.")
}
return collectPathArguments(InstanceIdentifier.builder(), strings.subList(1, strings.size),
moduleBehindMountPoint, mount);
}
return collectPathArguments(InstanceIdentifier.builder(), strings.subList(1, strings.size),
moduleBehindMountPoint, mount);
}
var Module module = null;
if (mountPoint === null) {
module = globalSchema.getLatestModule(moduleName)
var Module module = null;
if (mountPoint === null) {
module = globalSchema.getLatestModule(moduleName)
}
targetNode = parentNode.findInstanceDataChild(nodeName, module.namespace)
if (targetNode === null) {
}
targetNode = parentNode.findInstanceDataChild(nodeName, module.namespace)
if (targetNode === null) {
- throw new ResponseException(BAD_REQUEST, "URI has bad format. Possible reasons:\n" +
- "1. \"" + strings.head + "\" was not found in parent data node.\n" +
+ throw new ResponseException(BAD_REQUEST, "URI has bad format. Possible reasons:\n" +
+ "1. \"" + strings.head + "\" was not found in parent data node.\n" +
"2. \"" + strings.head + "\" is behind mount point. Then it should be in format \"/" + MOUNT + "/" + strings.head + "\".")
}
} else { // string without module name
"2. \"" + strings.head + "\" is behind mount point. Then it should be in format \"/" + MOUNT + "/" + strings.head + "\".")
}
} else { // string without module name
checkArgument(node instanceof LeafSchemaNode);
val urlDecoded = URLDecoder.decode(uriValue);
val typedef = (node as LeafSchemaNode).type;
checkArgument(node instanceof LeafSchemaNode);
val urlDecoded = URLDecoder.decode(uriValue);
val typedef = (node as LeafSchemaNode).type;
var decoded = TypeDefinitionAwareCodec.from(typedef)?.deserialize(urlDecoded)
if(decoded === null) {
var baseType = RestUtil.resolveBaseTypeFrom(typedef)
var decoded = TypeDefinitionAwareCodec.from(typedef)?.deserialize(urlDecoded)
if(decoded === null) {
var baseType = RestUtil.resolveBaseTypeFrom(typedef)