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.java;h=6cc62e859c9bade70e4125d2fea72a8addc6f875;hp=e3beaa2287d01f5734b50a467b4e5cdd47cfcf6f;hb=1447e0132075bbd3013aa41b98384a373bd82d1a;hpb=55d223f2e807077b5c876b8e3ef853628f9ca697 diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java index e3beaa2287..6cc62e859c 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java @@ -119,7 +119,7 @@ public class ControllerContext implements SchemaContextListener { onGlobalContextUpdated(schemas); } - public InstanceIdentifierContext toInstanceIdentifier(final String restconfInstance) { + public InstanceIdentifierContext toInstanceIdentifier(final String restconfInstance) { return toIdentifier(restconfInstance, false); } @@ -127,11 +127,11 @@ public class ControllerContext implements SchemaContextListener { return globalSchema; } - public InstanceIdentifierContext toMountPointIdentifier(final String restconfInstance) { + public InstanceIdentifierContext toMountPointIdentifier(final String restconfInstance) { return toIdentifier(restconfInstance, true); } - private InstanceIdentifierContext toIdentifier(final String restconfInstance, final boolean toMountPointIdentifier) { + private InstanceIdentifierContext toIdentifier(final String restconfInstance, final boolean toMountPointIdentifier) { checkPreconditions(); if(restconfInstance == null) { @@ -153,7 +153,12 @@ public class ControllerContext implements SchemaContextListener { final InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder(); final Module latestModule = globalSchema.findModuleByName(startModule, null); - final InstanceIdentifierContext iiWithSchemaNode = collectPathArguments(builder, pathArgs, latestModule, null, + + if (latestModule == null) { + throw new RestconfDocumentedException("The module named '" + startModule + "' does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT); + } + + final InstanceIdentifierContext iiWithSchemaNode = collectPathArguments(builder, pathArgs, latestModule, null, toMountPointIdentifier); if (iiWithSchemaNode == null) { @@ -494,7 +499,7 @@ public class ControllerContext implements SchemaContextListener { return object == null ? "" : URLEncoder.encode(codec.serialize(object).toString(), ControllerContext.URI_ENCODING_CHAR_SET); } - private InstanceIdentifierContext collectPathArguments(final InstanceIdentifierBuilder builder, + private InstanceIdentifierContext collectPathArguments(final InstanceIdentifierBuilder builder, final List strings, final DataNodeContainer parentNode, final DOMMountPoint mountPoint, final boolean returnJustMountPoint) { Preconditions.> checkNotNull(strings); @@ -543,7 +548,7 @@ public class ControllerContext implements SchemaContextListener { if (returnJustMountPoint || strings.size() == 1) { final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance(); - return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema); + return new InstanceIdentifierContext<>(instance, mountPointSchema, mount,mountPointSchema); } final String moduleNameBehindMountPoint = toModuleName(strings.get(1)); @@ -672,11 +677,11 @@ public class ControllerContext implements SchemaContextListener { return createContext(builder.build(), targetNode, mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema); } - private InstanceIdentifierContext createContext(final YangInstanceIdentifier instance, final DataSchemaNode dataSchemaNode, + private InstanceIdentifierContext createContext(final YangInstanceIdentifier instance, final DataSchemaNode dataSchemaNode, final DOMMountPoint mountPoint, final SchemaContext schemaContext) { final YangInstanceIdentifier instanceIdentifier = new DataNormalizer(schemaContext).toNormalized(instance); - return new InstanceIdentifierContext(instanceIdentifier, dataSchemaNode, mountPoint,schemaContext); + return new InstanceIdentifierContext<>(instanceIdentifier, dataSchemaNode, mountPoint,schemaContext); } public static DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container, final String name,