- if URI has bad format then error status 400 is returned
- corrected xtend conventions: triple equals for null
Change-Id: Idfa58e21942506b7483ca6ecf19aedfd1c1de827
Signed-off-by: Martin Sunal <msunal@cisco.com>
private DataBrokerService dataService;
private new() {
private DataBrokerService dataService;
private new() {
- if (INSTANCE != null) {
+ if (INSTANCE !== null) {
throw new IllegalStateException("Already instantiated");
}
}
throw new IllegalStateException("Already instantiated");
}
}
}
private def void checkPreconditions() {
}
private def void checkPreconditions() {
- if (context == null || dataService == null) {
+ if (context === null || dataService === null) {
throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE)
.entity(RestconfProvider::NOT_INITALIZED_MSG).build())
}
throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE)
.entity(RestconfProvider::NOT_INITALIZED_MSG).build())
}
- if (INSTANCE != null) {
+ if (INSTANCE !== null) {
throw new IllegalStateException("Already instantiated");
}
}
throw new IllegalStateException("Already instantiated");
}
}
}
private def void checkPreconditions() {
}
private def void checkPreconditions() {
+ if (schemas === null) {
throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE)
.entity(RestconfProvider::NOT_INITALIZED_MSG).build())
}
throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE)
.entity(RestconfProvider::NOT_INITALIZED_MSG).build())
}
pathArgs.remove(0)
}
val schemaNode = ret.collectPathArguments(pathArgs, restconfInstance.findModule);
pathArgs.remove(0)
}
val schemaNode = ret.collectPathArguments(pathArgs, restconfInstance.findModule);
- if (schemaNode == null) {
+ if (schemaNode === null) {
return null
}
new InstanceIdWithSchemaNode(ret.toInstance, schemaNode)
return null
}
new InstanceIdWithSchemaNode(ret.toInstance, schemaNode)
private def getLatestModule(SchemaContext schema, String moduleName) {
checkNotNull(schema)
private def getLatestModule(SchemaContext schema, String moduleName) {
checkNotNull(schema)
- checkArgument(moduleName != null && !moduleName.empty)
+ checkArgument(moduleName !== null && !moduleName.empty)
val modules = schema.modules.filter[m|m.name == moduleName]
var latestModule = modules.head
for (module : modules) {
val modules = schema.modules.filter[m|m.name == moduleName]
var latestModule = modules.head
for (module : modules) {
def CharSequence toRestconfIdentifier(QName qname) {
checkPreconditions
var module = uriToModuleName.get(qname.namespace)
def CharSequence toRestconfIdentifier(QName qname) {
checkPreconditions
var module = uriToModuleName.get(qname.namespace)
val moduleSchema = schemas.findModuleByNamespaceAndRevision(qname.namespace, qname.revision);
val moduleSchema = schemas.findModuleByNamespaceAndRevision(qname.namespace, qname.revision);
- if(moduleSchema == null) throw new IllegalArgumentException()
+ if(moduleSchema === null) throw new IllegalArgumentException()
uriToModuleName.put(qname.namespace, moduleSchema.name)
module = moduleSchema.name;
}
uriToModuleName.put(qname.namespace, moduleSchema.name)
module = moduleSchema.name;
}
}
private def toUriString(Object object) {
}
private def toUriString(Object object) {
- if(object == null) return "";
+ if(object === null) return "";
return URLEncoder.encode(object.toString)
}
return URLEncoder.encode(object.toString)
}
val nodeName = nodeRef.toNodeName();
val targetNode = parentNode.getDataChildByName(nodeName);
val nodeName = nodeRef.toNodeName();
val targetNode = parentNode.getDataChildByName(nodeName);
- if (targetNode == null) {
+ 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);
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);
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 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 {
class RestconfImpl implements RestconfService {
extension ControllerContext controllerContext
private new() {
extension ControllerContext controllerContext
private new() {
- if (INSTANCE != null) {
+ if (INSTANCE !== null) {
throw new IllegalStateException("Already instantiated");
}
}
throw new IllegalStateException("Already instantiated");
}
}
}
override readData(String identifier) {
}
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 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 {
val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode)
val status = broker.commitConfigurationDataPut(identifierWithSchemaNode.instanceIdentifier,value).get();
switch status.result {
}
override updateConfigurationData(String identifier, CompositeNode payload) {
}
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 {
val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode)
val status = broker.commitConfigurationDataPut(identifierWithSchemaNode.instanceIdentifier,value).get();
switch status.result {
}
override readConfigurationData(String identifier) {
}
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 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)
}
val data = broker.readOperationalData(instanceIdentifierWithSchemaNode.getInstanceIdentifier);
return new StructuredData(data, instanceIdentifierWithSchemaNode.schemaNode)
}
}
override createOperationalData(String identifier, CompositeNode payload) {
}
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 {
val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode)
val status = broker.commitOperationalDataPut(identifierWithSchemaNode.instanceIdentifier,value).get();
switch status.result {
}
override updateOperationalData(String identifier, CompositeNode payload) {
}
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 {
val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode)
val status = broker.commitOperationalDataPut(identifierWithSchemaNode.instanceIdentifier,value).get();
switch status.result {
+ 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)
private def CompositeNode resolveNodeNamespaceBySchema(CompositeNode node, DataSchemaNode schema) {
if (node instanceof CompositeNodeWrapper) {
addNamespaceToNodeFromSchemaRecursively(node as CompositeNodeWrapper, schema)
}
private def void addNamespaceToNodeFromSchemaRecursively(NodeWrapper<?> nodeBuilder, DataSchemaNode schema) {
}
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) {
nodeBuilder.namespace = schema.QName.namespace
}
if (nodeBuilder instanceof CompositeNodeWrapper) {
assertEquals(404, response.getStatus());
}
assertEquals(404, response.getStatus());
}
+ @Test
+ public void testXmlToCompositeNode400() throws UnsupportedEncodingException, URISyntaxException {
+ String uri = createUri("/datastore/", "simple-nodes:user/name");
+
+ when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(null);
+
+ Response response = target(uri).request(MediaTypes.API+RestconfService.XML).get();
+ assertEquals(400, response.getStatus());
+ }
+
@Test
public void testRpcResultCommitedToStatusCodes() throws UnsupportedEncodingException {
InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml");
@Test
public void testRpcResultCommitedToStatusCodes() throws UnsupportedEncodingException {
InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml");