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=4645a411c17c88baa7d55d94c21fcb944faf4d2f;hb=6eb461f54fe6705b07f34b6cee197ea968de4991;hp=94a7756da65cefd02adbe3a00eecb69efe9a8dab;hpb=9e85339874f4a57af8cf6d0b3a60e144596e32e5;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 94a7756da6..4645a411c1 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 @@ -6,18 +6,20 @@ import java.util.Set import javax.ws.rs.core.Response import org.opendaylight.controller.md.sal.common.api.TransactionStatus import org.opendaylight.controller.sal.rest.api.RestconfService +import org.opendaylight.yangtools.yang.common.QName import org.opendaylight.yangtools.yang.data.api.CompositeNode import org.opendaylight.yangtools.yang.data.api.Node import org.opendaylight.yangtools.yang.data.impl.NodeFactory import org.opendaylight.yangtools.yang.model.api.ChoiceNode +import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode import org.opendaylight.yangtools.yang.model.api.DataNodeContainer import org.opendaylight.yangtools.yang.model.api.DataSchemaNode -import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec -import org.opendaylight.yangtools.yang.model.api.TypeDefinition -import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode -import org.opendaylight.yangtools.yang.common.QName -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode +import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode +import org.opendaylight.yangtools.yang.model.api.ListSchemaNode +import org.opendaylight.yangtools.yang.model.api.TypeDefinition +import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition + import static javax.ws.rs.core.Response.Status.* class RestconfImpl implements RestconfService { @@ -148,7 +150,7 @@ class RestconfImpl implements RestconfService { } val moduleName = controllerContext.findModuleByNamespace(validQName.namespace); if (nodeBuilder.namespace === null || nodeBuilder.namespace == validQName.namespace || - nodeBuilder.namespace.path == moduleName) { + nodeBuilder.namespace.toString == moduleName) { nodeBuilder.qname = validQName } else { throw new ResponseException(BAD_REQUEST, @@ -164,12 +166,34 @@ class RestconfImpl implements RestconfService { findFirstSchemaByLocalName(child.localName, (schema as DataNodeContainer).childNodes), currentAugment) } + if(schema instanceof ListSchemaNode) { + val listKeys = (schema as ListSchemaNode).keyDefinition + for (listKey : listKeys) { + var foundKey = false + for (child : children) { + if (child.unwrap.nodeType.localName == listKey.localName) { + foundKey = true; + } + } + if (!foundKey) { + throw new ResponseException(BAD_REQUEST, + "Missing key \"" + listKey.localName + "\" of list \"" + schema.QName.localName + "\"") + } + } + } } else if (nodeBuilder instanceof SimpleNodeWrapper) { val simpleNode = (nodeBuilder as SimpleNodeWrapper) - val stringValue = simpleNode.value as String; - - val objectValue = TypeDefinitionAwareCodec.from(schema.typeDefinition)?.deserialize(stringValue); - simpleNode.setValue(objectValue) + val value = simpleNode.value + var inputValue = value; + + if (schema.typeDefinition instanceof IdentityrefTypeDefinition) { + if (value instanceof String) { + inputValue = new IdentityValuesDTO(validQName.namespace.toString, value as String, null) + } // else value is instance of ValuesDTO + } + + val outputValue = RestCodec.from(schema.typeDefinition)?.deserialize(inputValue); + simpleNode.setValue(outputValue) } else if (nodeBuilder instanceof EmptyNodeWrapper) { val emptyNodeBuilder = nodeBuilder as EmptyNodeWrapper if (schema instanceof LeafSchemaNode) { @@ -183,11 +207,19 @@ class RestconfImpl implements RestconfService { } private def dispatch TypeDefinition typeDefinition(LeafSchemaNode node) { - node.type + var baseType = node.type + while (baseType.baseType !== null) { + baseType = baseType.baseType; + } + baseType } private def dispatch TypeDefinition typeDefinition(LeafListSchemaNode node) { - node.type + var TypeDefinition baseType = node.type + while (baseType.baseType !== null) { + baseType = baseType.baseType; + } + baseType } private def DataSchemaNode findFirstSchemaByLocalName(String localName, Set schemas) {