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%2Frestconf%2Fimpl%2FControllerContext.java;h=e3beaa2287d01f5734b50a467b4e5cdd47cfcf6f;hp=7df760115c168abd00806a50de61426ea471e81c;hb=e631dc96f0461b2270377dc072b9f969a875667a;hpb=4fc158fdb5e38ad492c1bccc6b1e70f0c0255560 diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java index 7df760115c..e3beaa2287 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java @@ -27,7 +27,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import javax.ws.rs.core.Response.Status; @@ -42,17 +41,15 @@ import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType; import org.opendaylight.yangtools.concepts.Codec; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; -import org.opendaylight.yangtools.yang.model.api.ChoiceNode; +import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; @@ -445,7 +442,7 @@ public class ControllerContext implements SchemaContextListener { return null; } - private static DataSchemaNode childByQName(final ChoiceNode container, final QName name) { + private static DataSchemaNode childByQName(final ChoiceSchemaNode container, final QName name) { for (final ChoiceCaseNode caze : container.getCases()) { final DataSchemaNode ret = ControllerContext.childByQName(caze, name); if (ret != null) { @@ -480,8 +477,8 @@ public class ControllerContext implements SchemaContextListener { final DataSchemaNode ret = container.getDataChildByName(name); if (ret == null) { for (final DataSchemaNode node : container.getChildNodes()) { - if ((node instanceof ChoiceNode)) { - final ChoiceNode choiceNode = ((ChoiceNode) node); + if ((node instanceof ChoiceSchemaNode)) { + final ChoiceSchemaNode choiceNode = ((ChoiceSchemaNode) node); final DataSchemaNode childByQName = ControllerContext.childByQName(choiceNode, name); if (childByQName != null) { return childByQName; @@ -529,7 +526,7 @@ public class ControllerContext implements SchemaContextListener { ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED); } - final YangInstanceIdentifier partialPath = builder.toInstance(); + final YangInstanceIdentifier partialPath = dataNormalizer.toNormalized(builder.build()); final Optional mountOpt = mountService.getMountPoint(partialPath); if (!mountOpt.isPresent()) { LOG.debug("Instance identifier to missing mount point: {}", partialPath); @@ -544,12 +541,7 @@ public class ControllerContext implements SchemaContextListener { ErrorType.APPLICATION, ErrorTag.UNKNOWN_ELEMENT); } - if (returnJustMountPoint) { - final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance(); - return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema); - } - - if (strings.size() == 1) { + if (returnJustMountPoint || strings.size() == 1) { final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance(); return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema); } @@ -713,9 +705,9 @@ public class ControllerContext implements SchemaContextListener { return instantiatedDataNodeContainers; } - private static final Function> CHOICE_FUNCTION = new Function>() { + private static final Function> CHOICE_FUNCTION = new Function>() { @Override - public Set apply(final ChoiceNode node) { + public Set apply(final ChoiceSchemaNode node) { return node.getCases(); } }; @@ -740,7 +732,7 @@ public class ControllerContext implements SchemaContextListener { } } - final Iterable choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceNode.class); + final Iterable choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceSchemaNode.class); final Iterable> map = Iterables.transform(choiceNodes, CHOICE_FUNCTION); final Iterable allCases = Iterables. concat(map); @@ -927,8 +919,8 @@ public class ControllerContext implements SchemaContextListener { private static DataSchemaNode childByQName(final Object container, final QName name) { if (container instanceof ChoiceCaseNode) { return childByQName((ChoiceCaseNode) container, name); - } else if (container instanceof ChoiceNode) { - return childByQName((ChoiceNode) container, name); + } else if (container instanceof ChoiceSchemaNode) { + return childByQName((ChoiceSchemaNode) container, name); } else if (container instanceof ContainerSchemaNode) { return childByQName((ContainerSchemaNode) container, name); } else if (container instanceof ListSchemaNode) { @@ -943,15 +935,6 @@ public class ControllerContext implements SchemaContextListener { } } - public Entry> toNormalized(final YangInstanceIdentifier legacy, - final CompositeNode compositeNode) { - try { - return dataNormalizer.toNormalized(legacy, compositeNode); - } catch (final NullPointerException e) { - throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e); - } - } - public YangInstanceIdentifier toNormalized(final YangInstanceIdentifier legacy) { try { return dataNormalizer.toNormalized(legacy); @@ -960,15 +943,6 @@ public class ControllerContext implements SchemaContextListener { } } - public CompositeNode toLegacy(final YangInstanceIdentifier instanceIdentifier, - final NormalizedNode normalizedNode) { - try { - return dataNormalizer.toLegacy(instanceIdentifier, normalizedNode); - } catch (final NullPointerException e) { - throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e); - } - } - public YangInstanceIdentifier toXpathRepresentation(final YangInstanceIdentifier instanceIdentifier) { try { return dataNormalizer.toLegacy(instanceIdentifier);