Bug 7231 - Upgrade ietf-restconf draft17 to draft18
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / restconf / rest / services / impl / RestconfModulesServiceImpl.java
index 4ac1750b7fd5401204c82ce10d61e14bbd23a729..6ccc2225ffbddce8b4bd63868efd0e8e0ed76bf8 100644 (file)
@@ -7,18 +7,18 @@
  */
 package org.opendaylight.restconf.rest.services.impl;
 
+import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import java.util.Collections;
 import java.util.Set;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.Draft16;
+import org.opendaylight.restconf.Draft18;
 import org.opendaylight.restconf.common.references.SchemaContextRef;
 import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.handlers.SchemaContextHandler;
@@ -80,11 +80,9 @@ public class RestconfModulesServiceImpl implements RestconfModulesService {
             throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
         }
         final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
-        final InstanceIdentifierContext<?> mountPointIdentifier = ParserIdentifier.toInstanceIdentifier(identifier,
-                schemaContextRef.get());
-        final DOMMountPointService domMointPointService = this.domMountPointServiceHandler.get();
-        final DOMMountPoint mountPoint = domMointPointService
-                .getMountPoint(mountPointIdentifier.getInstanceIdentifier()).get();
+        final InstanceIdentifierContext<?> mountPointIdentifier = ParserIdentifier.toInstanceIdentifier(
+                identifier, schemaContextRef.get(), Optional.of(this.domMountPointServiceHandler.get()));
+        final DOMMountPoint mountPoint = mountPointIdentifier.getMountPoint();
         return getModules(mountPoint.getSchemaContext().getModules(), schemaContextRef, mountPoint);
     }
 
@@ -94,13 +92,15 @@ public class RestconfModulesServiceImpl implements RestconfModulesService {
         Preconditions.checkNotNull(identifier);
         final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
         final QName moduleQname = ParserIdentifier.makeQNameFromIdentifier(identifier);
-        Module module = null;
+        final Module module;
         DOMMountPoint mountPoint = null;
         if (identifier.contains(RestconfConstants.MOUNT)) {
-            final InstanceIdentifierContext<?> point = ParserIdentifier.toInstanceIdentifier(identifier,
-                    schemaContextRef.get());
-            final DOMMountPointService domMointPointService = this.domMountPointServiceHandler.get();
-            mountPoint = domMointPointService.getMountPoint(point.getInstanceIdentifier()).get();
+            // we only need to find mount point itself
+            final String mountPointPath = identifier.substring(
+                    0, identifier.indexOf(RestconfConstants.MOUNT) + RestconfConstants.MOUNT.length());
+            final InstanceIdentifierContext<?> mountPointContext = ParserIdentifier.toInstanceIdentifier(
+                    mountPointPath, schemaContextRef.get(), Optional.of(this.domMountPointServiceHandler.get()));
+            mountPoint = mountPointContext.getMountPoint();
             module = schemaContextRef.findModuleInMountPointByQName(mountPoint, moduleQname);
         } else {
             module = schemaContextRef.findModuleByQName(moduleQname);
@@ -117,7 +117,7 @@ public class RestconfModulesServiceImpl implements RestconfModulesService {
         final MapNode moduleMap = RestconfMappingNodeUtil
                 .restconfMappingNode(schemaContextRef.getRestconfModule(), modules);
         final DataSchemaNode moduleSchemaNode = RestconfSchemaUtil.getRestconfSchemaNode(
-                schemaContextRef.getRestconfModule(), Draft16.RestconfModule.MODULE_LIST_SCHEMA_NODE);
+                schemaContextRef.getRestconfModule(), Draft18.RestconfModule.MODULE_LIST_SCHEMA_NODE);
         Preconditions.checkState(moduleSchemaNode instanceof ListSchemaNode);
         if (mountPoint == null) {
             return new NormalizedNodeContext(
@@ -148,7 +148,7 @@ public class RestconfModulesServiceImpl implements RestconfModulesService {
 
         final MapNode mapNodes = RestconfMappingNodeUtil.restconfMappingNode(restconfModule, modules);
         final DataSchemaNode schemaNode = RestconfSchemaUtil.getRestconfSchemaNode(restconfModule,
-                Draft16.RestconfModule.MODULES_CONTAINER_SCHEMA_NODE);
+                Draft18.RestconfModule.MODULES_CONTAINER_SCHEMA_NODE);
         Preconditions.checkState(schemaNode instanceof ContainerSchemaNode);
         final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> modulContainerSchemaNodeBuilder = Builders
                 .containerBuilder((ContainerSchemaNode) schemaNode);