Fix Server-Sent Events routing
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / utils / RestconfDataServiceConstant.java
index a39ec65bc08ece3f8654cbb72db0be183579b08f..c7ec32a140ca3fbbfb9d7de07415407e9a3f7104 100644 (file)
@@ -7,18 +7,23 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.rests.utils;
 
-import java.net.URI;
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import java.util.Arrays;
+import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /**
  * Constants for RestconfDataService.
  *
  */
 public final class RestconfDataServiceConstant {
-
-    public static final QName NETCONF_BASE_QNAME  = QName.create(QNameModule.create(URI.create(PutData.NETCONF_BASE)),
-        PutData.NETCONF_BASE_PAYLOAD_NAME);
+    public static final QName NETCONF_BASE_QNAME = SchemaContext.NAME;
 
     private RestconfDataServiceConstant() {
         throw new UnsupportedOperationException("Util class.");
@@ -44,61 +49,105 @@ public final class RestconfDataServiceConstant {
         public static final int MIN_DEPTH = 1;
         public static final int MAX_DEPTH = 65535;
 
-        public static final String READ_TYPE_TX = "READ";
         public static final String WITH_DEFAULTS = "with-defaults";
 
-        private ReadData() {
-            throw new UnsupportedOperationException("Util class.");
+        /**
+         * With-default values, as per
+         * <a href="https://tools.ietf.org/html/rfc8040#section-4.8.9">RFC8040 section 4.8.9</a>.
+         */
+        enum WithDefaults {
+            /**
+             * All data nodes are reported.
+             */
+            REPORT_ALL("report-all"),
+            /**
+             * Data nodes set to the YANG default are not reported.
+             */
+            TRIM("trim"),
+            /**
+             * Data nodes set to the YANG default by the client are reported.
+             */
+            EXPLICIT("explicit"),
+            /**
+             * All data nodes are reported, and defaults are tagged.
+             */
+            REPORT_ALL_TAGGED("report-all-tagged");
+
+            private static final ImmutableMap<String, WithDefaults> VALUES =
+                Maps.uniqueIndex(Arrays.asList(values()), WithDefaults::value);
+
+            private @NonNull String value;
+
+            WithDefaults(final @NonNull String value) {
+                this.value = value;
+            }
+
+            public @NonNull String value() {
+                return value;
+            }
+
+            static @Nullable WithDefaults forValue(final String value) {
+                return VALUES.get(requireNonNull(value));
+            }
+
+            static @Nullable Set<String> possibleValues() {
+                return VALUES.keySet();
+            }
         }
-    }
-
-    /**
-     * Constants for data to put.
-     *
-     */
-    public static final class PutData {
-        public static final String NETCONF_BASE = "urn:ietf:params:xml:ns:netconf:base:1.0";
-        public static final String NETCONF_BASE_PAYLOAD_NAME = "data";
-        public static final String PUT_TX_TYPE = "PUT";
-
-        private PutData() {
-            throw new UnsupportedOperationException("Util class.");
-        }
-    }
-
-    /**
-     * Constants for data to post.
-     *
-     */
-    public static final class PostData {
-        public static final String POST_TX_TYPE = "POST";
 
-        private PostData() {
+        private ReadData() {
             throw new UnsupportedOperationException("Util class.");
         }
     }
 
     /**
-     * Constants for data to delete.
-     *
+     * Common for PostData and PutData.
      */
-    public static final class DeleteData {
-        public static final String DELETE_TX_TYPE = "DELETE";
-
-        private DeleteData() {
-            throw new UnsupportedOperationException("Util class.");
+    public static final class PostPutQueryParameters {
+        public static final String INSERT = "insert";
+        public static final String POINT = "point";
+
+        /**
+         * Insert values, as per <a href="https://tools.ietf.org/html/rfc8040#section-4.8.5">RFC8040 section 4.8.5</a>.
+         */
+        public enum Insert {
+            /**
+             * Insert the new data as the new first entry.
+             */
+            FIRST("first"),
+            /**
+             * Insert the new data as the new last entry.
+             */
+            LAST("last"),
+            /**
+             * Insert the new data before the insertion point, as specified by the value of the "point" parameter.
+             */
+            BEFORE("before"),
+            /**
+             * Insert the new data after the insertion point, as specified by the value of the "point" parameter.
+             */
+            AFTER("after");
+
+            private static final ImmutableMap<String, Insert> VALUES =
+                Maps.uniqueIndex(Arrays.asList(values()), Insert::value);
+
+            private @NonNull String value;
+
+            Insert(final @NonNull String value) {
+                this.value = value;
+            }
+
+            public @NonNull String value() {
+                return value;
+            }
+
+            public static @Nullable Insert forValue(final String value) {
+                return VALUES.get(requireNonNull(value));
+            }
         }
-    }
-
-    /**
-     * Constants for data to yang patch.
-     *
-     */
-    public static final class PatchData {
-        public static final String PATCH_TX_TYPE = "Patch";
 
-        private PatchData() {
-            throw new UnsupportedOperationException("Util class.");
+        private PostPutQueryParameters() {
+            // Hidden on purpose
         }
     }
 }