+ 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.")
+ }
+
+ return collectPathArguments(InstanceIdentifier.builder(), strings.subList(1, strings.size),
+ moduleBehindMountPoint, mount, returnJustMountPoint);
+ }
+
+ var Module module = null;
+ if (mountPoint === null) {
+ module = globalSchema.getLatestModule(moduleName)
+ if (module === null) {
+ throw new ResponseException(BAD_REQUEST,
+ "URI has bad format. \"" + moduleName + "\" module does not exist.")
+ }
+ } else {
+ module = mountPoint.schemaContext?.getLatestModule(moduleName)
+ if (module === null) {
+ throw new ResponseException(BAD_REQUEST,
+ "URI has bad format. \"" + moduleName + "\" module does not exist in mount point.")
+ }
+ }
+ targetNode = parentNode.findInstanceDataChildByNameAndNamespace(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" +
+ "2. \"" + strings.head + "\" is behind mount point. Then it should be in format \"/" + MOUNT + "/" + strings.head + "\".")
+ }
+ } else { // string without module name
+ val potentialSchemaNodes = parentNode.findInstanceDataChildrenByName(nodeName)
+ if (potentialSchemaNodes.size > 1) {
+ val StringBuilder namespacesOfPotentialModules = new StringBuilder;
+ for (potentialNodeSchema : potentialSchemaNodes) {
+ namespacesOfPotentialModules.append(" ").append(potentialNodeSchema.QName.namespace.toString).append("\n")
+ }
+ throw new ResponseException(BAD_REQUEST, "URI has bad format. Node \"" + nodeName + "\" is added as augment from more than one module. "
+ + "Therefore the node must have module name and it has to be in format \"moduleName:nodeName\"."
+ + "\nThe node is added as augment from modules with namespaces:\n" + namespacesOfPotentialModules)
+ }
+ targetNode = potentialSchemaNodes.head
+ if (targetNode === null) {
+ throw new ResponseException(BAD_REQUEST, "URI has bad format. \"" + nodeName + "\" was not found in parent data node.\n")