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%2Frest%2Fimpl%2FJsonMapper.java;h=a42c468c2af27ea5f2cb84887757ed8057a4466f;hp=351ae6ebbee085614943d7608ec51669a204f1ff;hb=33ff5360d4f3aec58518e22f08c706455865d685;hpb=df1eef1a88c6e96aac7071cae97c4ae41ea72b1d diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java index 351ae6ebbe..a42c468c2a 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java @@ -8,6 +8,7 @@ import java.util.*; import javax.activation.UnsupportedDataTypeException; import org.opendaylight.controller.sal.restconf.impl.ControllerContext; +import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.*; import org.opendaylight.yangtools.yang.model.api.*; import org.opendaylight.yangtools.yang.model.api.type.*; @@ -49,6 +50,7 @@ class JsonMapper { for (Node child : parent.getChildren()) { DataSchemaNode childSchema = findFirstSchemaForNode(child, parentSchema.getChildNodes()); + if (childSchema == null) { throw new UnsupportedDataTypeException("Probably the data node \"" + child.getNodeType().getLocalName() + "\" is not conform to schema"); @@ -96,6 +98,13 @@ class JsonMapper { for (DataSchemaNode dsn : dataSchemaNode) { if (node.getNodeType().getLocalName().equals(dsn.getQName().getLocalName())) { return dsn; + } else if (dsn instanceof ChoiceNode) { + for (ChoiceCaseNode choiceCase : ((ChoiceNode) dsn).getCases()) { + DataSchemaNode foundDsn = findFirstSchemaForNode(node, choiceCase.getChildNodes()); + if (foundDsn != null) { + return foundDsn; + } + } } } return null; @@ -136,25 +145,43 @@ class JsonMapper { List> nodeLeafLists = nodeParent.getSimpleNodesByName(node.getNodeType()); for (SimpleNode nodeLeafList : nodeLeafLists) { - writeValueOfNodeByType(writer, nodeLeafList, schema.getType()); + writeValueOfNodeByType(writer, nodeLeafList, schema.getType(), schema); } - writer.endArray(); } private void writeLeaf(JsonWriter writer, SimpleNode node, LeafSchemaNode schema) throws IOException { writeName(node, schema, writer); - writeValueOfNodeByType(writer, node, schema.getType()); + writeValueOfNodeByType(writer, node, schema.getType(), schema); } - private void writeValueOfNodeByType(JsonWriter writer, SimpleNode node, TypeDefinition type) - throws IOException { + private void writeValueOfNodeByType(JsonWriter writer, SimpleNode node, TypeDefinition type, + DataSchemaNode schema) throws IOException { String value = String.valueOf(node.getValue()); - // TODO check Leafref, InstanceIdentifierTypeDefinition, - // IdentityrefTypeDefinition, UnionTypeDefinition TypeDefinition baseType = resolveBaseTypeFrom(type); - if (baseType instanceof InstanceIdentifierTypeDefinition) { + + // TODO check InstanceIdentifierTypeDefinition, + // IdentityrefTypeDefinition + if (baseType instanceof IdentityrefTypeDefinition) { + if (node.getValue() instanceof QName) { + QName qName = (QName) node.getValue(); + + ControllerContext contContext = ControllerContext.getInstance(); + String moduleName = contContext.findModuleByNamespace(qName.getNamespace()); + + writer.value(moduleName + ":" + qName.getLocalName()); + } + + } else if (baseType instanceof LeafrefTypeDefinition) { + ControllerContext contContext = ControllerContext.getInstance(); + LeafSchemaNode lfSchemaNode = contContext.resolveTypeFromLeafref((LeafrefTypeDefinition) baseType, schema); + if (lfSchemaNode != null) { + writeValueOfNodeByType(writer, node, lfSchemaNode.getType(), lfSchemaNode); + } else { + writer.value(value); + } + } else if (baseType instanceof InstanceIdentifierTypeDefinition) { writer.value(((InstanceIdentifierTypeDefinition) baseType).getPathStatement().toString()); } else if (baseType instanceof UnionTypeDefinition) { processTypeIsUnionType(writer, (UnionTypeDefinition) baseType, value);