X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FRestconfImpl.xtend;h=a4587fa787fdff3af7b5dedab4b22505375fe37c;hb=f062dc05cc7caaf0c1811856370f1c9e2f1e5c34;hp=d9ac53589fa5415bcba3e59467576fcbb98d069e;hpb=c57785bd755dfdeaf829ce80a4b8b383d8c04602;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend index d9ac53589f..a4587fa787 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend @@ -7,6 +7,7 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode import org.opendaylight.yangtools.yang.model.api.DataNodeContainer import org.opendaylight.yangtools.yang.model.api.DataSchemaNode import org.opendaylight.controller.md.sal.common.api.TransactionStatus +import javax.ws.rs.WebApplicationException class RestconfImpl implements RestconfService { @@ -19,7 +20,7 @@ class RestconfImpl implements RestconfService { extension ControllerContext controllerContext private new() { - if (INSTANCE != null) { + if (INSTANCE !== null) { throw new IllegalStateException("Already instantiated"); } } @@ -42,13 +43,13 @@ class RestconfImpl implements RestconfService { } override readData(String identifier) { - val instanceIdentifierWithSchemaNode = identifier.toInstanceIdentifier + val instanceIdentifierWithSchemaNode = identifier.resolveInstanceIdentifier val data = broker.readOperationalData(instanceIdentifierWithSchemaNode.getInstanceIdentifier); return new StructuredData(data, instanceIdentifierWithSchemaNode.schemaNode) } override createConfigurationData(String identifier, CompositeNode payload) { - val identifierWithSchemaNode = identifier.toInstanceIdentifier + val identifierWithSchemaNode = identifier.resolveInstanceIdentifier val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode) val status = broker.commitConfigurationDataPut(identifierWithSchemaNode.instanceIdentifier,value).get(); switch status.result { @@ -58,7 +59,7 @@ class RestconfImpl implements RestconfService { } override updateConfigurationData(String identifier, CompositeNode payload) { - val identifierWithSchemaNode = identifier.toInstanceIdentifier + val identifierWithSchemaNode = identifier.resolveInstanceIdentifier val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode) val status = broker.commitConfigurationDataPut(identifierWithSchemaNode.instanceIdentifier,value).get(); switch status.result { @@ -76,13 +77,13 @@ class RestconfImpl implements RestconfService { } override readConfigurationData(String identifier) { - val instanceIdentifierWithSchemaNode = identifier.toInstanceIdentifier + val instanceIdentifierWithSchemaNode = identifier.resolveInstanceIdentifier val data = broker.readOperationalData(instanceIdentifierWithSchemaNode.getInstanceIdentifier); return new StructuredData(data, instanceIdentifierWithSchemaNode.schemaNode) } override readOperationalData(String identifier) { - val instanceIdentifierWithSchemaNode = identifier.toInstanceIdentifier + val instanceIdentifierWithSchemaNode = identifier.resolveInstanceIdentifier val data = broker.readOperationalData(instanceIdentifierWithSchemaNode.getInstanceIdentifier); return new StructuredData(data, instanceIdentifierWithSchemaNode.schemaNode) } @@ -96,7 +97,7 @@ class RestconfImpl implements RestconfService { } override createOperationalData(String identifier, CompositeNode payload) { - val identifierWithSchemaNode = identifier.toInstanceIdentifier + val identifierWithSchemaNode = identifier.resolveInstanceIdentifier val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode) val status = broker.commitOperationalDataPut(identifierWithSchemaNode.instanceIdentifier,value).get(); switch status.result { @@ -106,7 +107,7 @@ class RestconfImpl implements RestconfService { } override updateOperationalData(String identifier, CompositeNode payload) { - val identifierWithSchemaNode = identifier.toInstanceIdentifier + val identifierWithSchemaNode = identifier.resolveInstanceIdentifier val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode) val status = broker.commitOperationalDataPut(identifierWithSchemaNode.instanceIdentifier,value).get(); switch status.result { @@ -115,6 +116,15 @@ class RestconfImpl implements RestconfService { } } + private def InstanceIdWithSchemaNode resolveInstanceIdentifier(String identifier) { + val identifierWithSchemaNode = identifier.toInstanceIdentifier + if (identifierWithSchemaNode === null) { + throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("URI has bad format") + .build()); + } + return identifierWithSchemaNode + } + private def CompositeNode resolveNodeNamespaceBySchema(CompositeNode node, DataSchemaNode schema) { if (node instanceof CompositeNodeWrapper) { addNamespaceToNodeFromSchemaRecursively(node as CompositeNodeWrapper, schema) @@ -124,7 +134,7 @@ class RestconfImpl implements RestconfService { } private def void addNamespaceToNodeFromSchemaRecursively(NodeWrapper nodeBuilder, DataSchemaNode schema) { - if (nodeBuilder.namespace == null) { + if (nodeBuilder.namespace === null) { nodeBuilder.namespace = schema.QName.namespace } if (nodeBuilder instanceof CompositeNodeWrapper) {