Migrate restconf to MD-SAL APIs
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / utils / mapping / RestconfMappingNodeUtil.java
index 4f645edf9a842467852259dbbacca93946f79905..a37f65850cbf8533faf0e45c9825a51537852c2d 100644 (file)
@@ -7,13 +7,13 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.utils.mapping;
 
-import com.google.common.base.Optional;
 import java.net.URI;
 import java.time.Instant;
 import java.time.OffsetDateTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.Collection;
+import java.util.Optional;
 import java.util.Set;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
@@ -22,6 +22,7 @@ import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MonitoringModule.QueryParams
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.Module.ConformanceType;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@@ -119,19 +120,20 @@ public final class RestconfMappingNodeUtil {
         addCommonLeafs(module, mapEntryBuilder, ietfYangLibraryModule);
         addChildOfModuleBySpecificModuleInternal(
                 IetfYangLibrary.SPECIFIC_MODULE_SCHEMA_LEAF_QNAME, mapEntryBuilder, IetfYangLibrary.BASE_URI_OF_SCHEMA
-                        + module.getName() + "/" + module.getQNameModule().getFormattedRevision(),
+                        + module.getName() + "/"
+                        + module.getQNameModule().getRevision().map(Revision::toString).orElse(null),
                 ietfYangLibraryModule);
         if (!isSubmodule) {
             addChildOfModuleBySpecificModuleOfListChild(IetfYangLibrary.SPECIFIC_MODULE_NAMESPACE_LEAF_QNAME,
                     mapEntryBuilder, module.getNamespace().toString(), ietfYangLibraryModule);
 
             // features - not mandatory
-            if ((module.getFeatures() != null) && !module.getFeatures().isEmpty()) {
+            if (module.getFeatures() != null && !module.getFeatures().isEmpty()) {
                 addFeatureLeafList(IetfYangLibrary.SPECIFIC_MODULE_FEATURE_LEAF_LIST_QNAME, mapEntryBuilder,
                         module.getFeatures(), ietfYangLibraryModule);
             }
             // deviations - not mandatory
-            if ((module.getDeviations() != null) && !module.getDeviations().isEmpty()) {
+            if (module.getDeviations() != null && !module.getDeviations().isEmpty()) {
                 addDeviationList(module, mapEntryBuilder, ietfYangLibraryModule, context);
                 addChildOfModuleBySpecificModuleOfListChild(IetfYangLibrary.SPECIFIC_MODULE_CONFORMANCE_LEAF_QNAME,
                         mapEntryBuilder, ConformanceType.Implement.getName(), ietfYangLibraryModule);
@@ -140,7 +142,7 @@ public final class RestconfMappingNodeUtil {
                         mapEntryBuilder, ConformanceType.Import.getName(), ietfYangLibraryModule);
             }
             // submodules - not mandatory
-            if ((module.getSubmodules() != null) && !module.getSubmodules().isEmpty()) {
+            if (module.getSubmodules() != null && !module.getSubmodules().isEmpty()) {
                 addSubmodules(module, mapEntryBuilder, ietfYangLibraryModule, context);
             }
         }
@@ -196,8 +198,7 @@ public final class RestconfMappingNodeUtil {
                     Builders.mapEntryBuilder((ListSchemaNode) deviationsSchema);
             final QName lastComponent = deviation.getTargetPath().getLastComponent();
             addChildOfModuleBySpecificModule(IetfYangLibrary.SPECIFIC_MODULE_NAME_LEAF_QNAME, deviationEntryNode,
-                    context.findModuleByNamespaceAndRevision(lastComponent.getNamespace(), lastComponent.getRevision())
-                            .getName(),
+                    context.findModule(lastComponent.getModule()).get().getName(),
                     ietfYangLibraryModule);
             addChildOfModuleBySpecificModule(IetfYangLibrary.SPECIFIC_MODULE_REVISION_LEAF_QNAME, deviationEntryNode,
                     lastComponent.getRevision(), ietfYangLibraryModule);
@@ -249,7 +250,7 @@ public final class RestconfMappingNodeUtil {
         addChildOfModuleBySpecificModuleInternal(IetfYangLibrary.SPECIFIC_MODULE_NAME_LEAF_QNAME, mapEntryBuilder,
                 module.getName(), ietfYangLibraryModule);
         addChildOfModuleBySpecificModuleInternal(IetfYangLibrary.SPECIFIC_MODULE_REVISION_LEAF_QNAME, mapEntryBuilder,
-                module.getQNameModule().getFormattedRevision(), ietfYangLibraryModule);
+                module.getQNameModule().getRevision().map(Revision::toString).orElse(""), ietfYangLibraryModule);
     }
 
     /**
@@ -486,15 +487,15 @@ public final class RestconfMappingNodeUtil {
                 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> streamEntry =
                         Builders.mapEntryBuilder((ListSchemaNode) streamListSchema);
 
-                final ListSchemaNode listSchema = ((ListSchemaNode) streamListSchema);
+                final ListSchemaNode listSchema = (ListSchemaNode) streamListSchema;
                 prepareLeafAndFillEntryBuilder(streamEntry,
                         listSchema.getDataChildByName(MonitoringModule.LEAF_NAME_STREAM_QNAME),
                         notificationDefinition.getQName().getLocalName());
-                if ((notificationDefinition.getDescription() != null)
-                        && !notificationDefinition.getDescription().equals("")) {
+
+                final java.util.Optional<String> optDesc = notificationDefinition.getDescription();
+                if (optDesc.isPresent()) {
                     prepareLeafAndFillEntryBuilder(streamEntry,
-                            listSchema.getDataChildByName(MonitoringModule.LEAF_DESCR_STREAM_QNAME),
-                            notificationDefinition.getDescription());
+                            listSchema.getDataChildByName(MonitoringModule.LEAF_DESCR_STREAM_QNAME), optDesc.get());
                 }
                 prepareLeafAndFillEntryBuilder(streamEntry,
                         listSchema.getDataChildByName(MonitoringModule.LEAF_REPLAY_SUPP_STREAM_QNAME), true);
@@ -580,7 +581,7 @@ public final class RestconfMappingNodeUtil {
             final Module monitoringModule, final boolean existParent, final SchemaContext schemaContext) {
         final SchemaNode schemaNode = ParserIdentifier
                 .toInstanceIdentifier(ParserIdentifier.stringFromYangInstanceIdentifier(path, schemaContext),
-                        schemaContext, Optional.absent())
+                        schemaContext, Optional.empty())
                 .getSchemaNode();
         final DataSchemaNode streamListSchema = ((ContainerSchemaNode) ((ContainerSchemaNode) monitoringModule
                 .getDataChildByName(MonitoringModule.CONT_RESTCONF_STATE_QNAME))
@@ -589,14 +590,15 @@ public final class RestconfMappingNodeUtil {
         final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> streamEntry =
                 Builders.mapEntryBuilder((ListSchemaNode) streamListSchema);
 
-        final ListSchemaNode listSchema = ((ListSchemaNode) streamListSchema);
+        final ListSchemaNode listSchema = (ListSchemaNode) streamListSchema;
         prepareLeafAndFillEntryBuilder(streamEntry,
                 listSchema.getDataChildByName(MonitoringModule.LEAF_NAME_STREAM_QNAME),
                 schemaNode.getQName().getLocalName());
-        if ((schemaNode.getDescription() != null) && !schemaNode.getDescription().equals("")) {
+
+        final java.util.Optional<String> optDesc = schemaNode.getDescription();
+        if (optDesc.isPresent()) {
             prepareLeafAndFillEntryBuilder(streamEntry,
-                    listSchema.getDataChildByName(MonitoringModule.LEAF_DESCR_STREAM_QNAME),
-                    schemaNode.getDescription());
+                    listSchema.getDataChildByName(MonitoringModule.LEAF_DESCR_STREAM_QNAME), optDesc.get());
         }
         prepareLeafAndFillEntryBuilder(streamEntry,
                 listSchema.getDataChildByName(MonitoringModule.LEAF_REPLAY_SUPP_STREAM_QNAME), true);