Simplify trimming
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / utils / ReadDataTransactionUtil.java
index 843f65c024bb0a5ee081c4461bf32a8df81240ca..76f0d6f1a27f72bdc0767b512a68045977cd0667 100644 (file)
@@ -20,8 +20,8 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.nb.rfc8040.ContentParameter;
-import org.opendaylight.restconf.nb.rfc8040.WithDefaultsParameter;
+import org.opendaylight.restconf.nb.rfc8040.ContentParam;
+import org.opendaylight.restconf.nb.rfc8040.WithDefaultsParam;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
@@ -88,10 +88,10 @@ public final class ReadDataTransactionUtil {
      * @param ctx            schema context
      * @return {@link NormalizedNode}
      */
-    public static @Nullable NormalizedNode readData(final @NonNull ContentParameter content,
+    public static @Nullable NormalizedNode readData(final @NonNull ContentParam content,
                                                     final @NonNull YangInstanceIdentifier path,
                                                     final @NonNull RestconfStrategy strategy,
-                                                    final WithDefaultsParameter withDefa,
+                                                    final WithDefaultsParam withDefa,
                                                     final EffectiveModelContext ctx) {
         // FIXME: use a switch expression when they are available, removing source of RestconfDocumentedException
         switch (content) {
@@ -105,7 +105,7 @@ public final class ReadDataTransactionUtil {
             default:
                 throw new RestconfDocumentedException(
                         new RestconfError(ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
-                                "Invalid content parameter: " + content.uriValue(), null,
+                                "Invalid content parameter: " + content.paramValue(), null,
                                 "The content parameter value must be either config, nonconfig or all (default)"));
         }
     }
@@ -122,9 +122,9 @@ public final class ReadDataTransactionUtil {
      * @param fields         paths to selected subtrees which should be read, relative to to the parent path
      * @return {@link NormalizedNode}
      */
-    public static @Nullable NormalizedNode readData(final @NonNull ContentParameter content,
+    public static @Nullable NormalizedNode readData(final @NonNull ContentParam content,
             final @NonNull YangInstanceIdentifier path, final @NonNull RestconfStrategy strategy,
-            final @Nullable WithDefaultsParameter withDefa, @NonNull final EffectiveModelContext ctx,
+            final @Nullable WithDefaultsParam withDefa, @NonNull final EffectiveModelContext ctx,
             final @NonNull List<YangInstanceIdentifier> fields) {
         // FIXME: use a switch expression when they are available, removing source of RestconfDocumentedException
         switch (content) {
@@ -138,13 +138,13 @@ public final class ReadDataTransactionUtil {
                 return readDataViaTransaction(strategy, LogicalDatastoreType.OPERATIONAL, path, fields);
             default:
                 throw new RestconfDocumentedException(new RestconfError(ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
-                        "Invalid content parameter: " + content.uriValue(), null,
+                        "Invalid content parameter: " + content.paramValue(), null,
                         "The content parameter value must be either config, nonconfig or all (default)"));
         }
     }
 
     private static NormalizedNode prepareDataByParamWithDef(final NormalizedNode result,
-            final YangInstanceIdentifier path, final WithDefaultsParameter withDefa, final EffectiveModelContext ctx) {
+            final YangInstanceIdentifier path, final WithDefaultsParam withDefa, final EffectiveModelContext ctx) {
         boolean trim;
         switch (withDefa) {
             case TRIM:
@@ -154,7 +154,7 @@ public final class ReadDataTransactionUtil {
                 trim = false;
                 break;
             default:
-                throw new RestconfDocumentedException("Unsupported with-defaults value " + withDefa.uriValue());
+                throw new RestconfDocumentedException("Unsupported with-defaults value " + withDefa.paramValue());
         }
 
         final DataSchemaContextTree baseSchemaCtxTree = DataSchemaContextTree.from(ctx);
@@ -199,18 +199,14 @@ public final class ReadDataTransactionUtil {
                 if (keys.contains(child.getIdentifier().getNodeType())) {
                     leafBuilder.withValue(((LeafNode<?>) child).body());
                     builder.withChild(leafBuilder.build());
-                } else {
-                    if (trim) {
-                        if (defaultVal == null || !defaultVal.equals(nodeVal)) {
-                            leafBuilder.withValue(((LeafNode<?>) child).body());
-                            builder.withChild(leafBuilder.build());
-                        }
-                    } else {
-                        if (defaultVal != null && defaultVal.equals(nodeVal)) {
-                            leafBuilder.withValue(((LeafNode<?>) child).body());
-                            builder.withChild(leafBuilder.build());
-                        }
+                } else if (trim) {
+                    if (defaultVal == null || !defaultVal.equals(nodeVal)) {
+                        leafBuilder.withValue(((LeafNode<?>) child).body());
+                        builder.withChild(leafBuilder.build());
                     }
+                } else if (defaultVal != null && defaultVal.equals(nodeVal)) {
+                    leafBuilder.withValue(((LeafNode<?>) child).body());
+                    builder.withChild(leafBuilder.build());
                 }
             }
         }
@@ -257,11 +253,9 @@ public final class ReadDataTransactionUtil {
                         leafBuilder.withValue(((LeafNode<?>) child).body());
                         builder.withChild(leafBuilder.build());
                     }
-                } else {
-                    if (defaultVal != null && defaultVal.equals(nodeVal)) {
-                        leafBuilder.withValue(((LeafNode<?>) child).body());
-                        builder.withChild(leafBuilder.build());
-                    }
+                } else if (defaultVal != null && defaultVal.equals(nodeVal)) {
+                    leafBuilder.withValue(((LeafNode<?>) child).body());
+                    builder.withChild(leafBuilder.build());
                 }
             }
         }
@@ -316,7 +310,7 @@ public final class ReadDataTransactionUtil {
      * @return {@link NormalizedNode}
      */
     private static @Nullable NormalizedNode readAllData(final @NonNull RestconfStrategy strategy,
-            final YangInstanceIdentifier path, final WithDefaultsParameter withDefa, final EffectiveModelContext ctx) {
+            final YangInstanceIdentifier path, final WithDefaultsParam withDefa, final EffectiveModelContext ctx) {
         // PREPARE STATE DATA NODE
         final NormalizedNode stateDataNode = readDataViaTransaction(strategy, LogicalDatastoreType.OPERATIONAL, path);
         // PREPARE CONFIG DATA NODE
@@ -339,7 +333,7 @@ public final class ReadDataTransactionUtil {
      * @return {@link NormalizedNode}
      */
     private static @Nullable NormalizedNode readAllData(final @NonNull RestconfStrategy strategy,
-            final @NonNull YangInstanceIdentifier path, final @Nullable WithDefaultsParameter withDefa,
+            final @NonNull YangInstanceIdentifier path, final @Nullable WithDefaultsParam withDefa,
             final @NonNull EffectiveModelContext ctx, final @NonNull List<YangInstanceIdentifier> fields) {
         // PREPARE STATE DATA NODE
         final NormalizedNode stateDataNode = readDataViaTransaction(strategy, LogicalDatastoreType.OPERATIONAL, path,