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%2Frest%2Fimpl%2FJsonNormalizedNodeBodyReader.java;h=bacd38720cc1d83196acc652dbe5f0c4cdfc5e92;hb=refs%2Fchanges%2F30%2F19530%2F14;hp=5d63c9c01162733a2b0734f17f5e0890a3346370;hpb=9055581e2aabac7478102c6b05f9118b443a9d64;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonNormalizedNodeBodyReader.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonNormalizedNodeBodyReader.java index 5d63c9c011..bacd38720c 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonNormalizedNodeBodyReader.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonNormalizedNodeBodyReader.java @@ -14,6 +14,8 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.lang.annotation.Annotation; import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; @@ -27,9 +29,11 @@ import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext; import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode; import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; @@ -88,23 +92,35 @@ public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPr final JsonReader reader = new JsonReader(new InputStreamReader(entityStream)); jsonParser.parse(reader); - NormalizedNode partialResult = resultHolder.getResult(); - final NormalizedNode result; + NormalizedNode result = resultHolder.getResult(); + List iiToDataList = new ArrayList<>(); + InstanceIdentifierContext newIIContext; - // FIXME: Also II should be updated unwrap result from augmentation and choice nodes on PUT - if (!isPost()) { - while (partialResult instanceof AugmentationNode || partialResult instanceof ChoiceNode) { - final Object childNode = ((DataContainerNode) partialResult).getValue().iterator().next(); - partialResult = (NormalizedNode) childNode; + if (isPost()) { + while (result instanceof AugmentationNode || result instanceof ChoiceNode) { + final Object childNode = ((DataContainerNode) result).getValue().iterator().next(); + iiToDataList.add(result.getIdentifier()); + result = (NormalizedNode) childNode; + } + if (result instanceof MapEntryNode) { + iiToDataList.add(new YangInstanceIdentifier.NodeIdentifier(result.getNodeType())); + iiToDataList.add(result.getIdentifier()); + } else { + iiToDataList.add(result.getIdentifier()); } - } - - if (partialResult instanceof MapNode && !isPost()) { - result = Iterables.getOnlyElement(((MapNode) partialResult).getValue()); } else { - result = partialResult; + if (result instanceof MapNode) { + result = Iterables.getOnlyElement(((MapNode) result).getValue()); + } } - return new NormalizedNodeContext(path,result); + + YangInstanceIdentifier fullIIToData = YangInstanceIdentifier.create(Iterables.concat( + path.getInstanceIdentifier().getPathArguments(), iiToDataList)); + + newIIContext = new InstanceIdentifierContext<>(fullIIToData, path.getSchemaNode(), path.getMountPoint(), + path.getSchemaContext()); + + return new NormalizedNodeContext(newIIContext, result); } catch (final RestconfDocumentedException e) { throw e; } catch (final ResultAlreadySetException e) {