- return parentNode as DataSchemaNode;
- }
- val nodeRef = strings.head;
-
- val nodeName = nodeRef.toNodeName();
- val targetNode = parentNode.getDataChildByName(nodeName);
- 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)
- return result
- }
+ return new InstanceIdWithSchemaNode(builder.toInstance, parentNode as DataSchemaNode, mountPoint)
+ }
+
+ val nodeName = strings.head.toNodeName
+ val moduleName = strings.head.toModuleName
+ var DataSchemaNode targetNode = null
+ if (!moduleName.nullOrEmpty) {
+ // if it is mount point
+ if (moduleName == MOUNT_MODULE && nodeName == MOUNT_NODE) {
+ if (mountPoint !== null) {
+ throw new ResponseException(BAD_REQUEST, "Restconf supports just one mount point in URI.")
+ }
+
+ if (mountService === null) {
+ throw new ResponseException(SERVICE_UNAVAILABLE, "MountService was not found. "
+ + "Finding behind mount points does not work."
+ )
+ }
+
+ 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.")
+ }
+
+ if (returnJustMountPoint) {
+ 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 moduleBehindMountPoint = mountPointSchema.getLatestModule(moduleNameBehindMountPoint)
+ if (moduleBehindMountPoint === null) {
+ throw new ResponseException(BAD_REQUEST,
+ "URI has bad format. \"" + moduleName + "\" module does not exist in mount point.")