Bug 5509 - HTTP Patch in Restconf doesn't support general absolute or relative target...
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / netconf / sal / restconf / impl / PATCHEditOperation.java
index e0bdfd5893863848c2a991e0449f904b014a8d38..da98193f230090aec00010cb013adae2a9944804 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.netconf.sal.restconf.impl;
 
+import javax.annotation.Nonnull;
+
 /**
  *
  * Each YANG patch edit specifies one edit operation on the target data
@@ -15,12 +17,32 @@ package org.opendaylight.netconf.sal.restconf.impl;
  * operations, but also includes some new operations.
  *
  */
-enum PATCHEditOperation {
+public enum PATCHEditOperation {
     CREATE,  //post
     DELETE,  //delete
     INSERT,  //post
     MERGE,
     MOVE,    //delete+post
     REPLACE, //put
-    REMOVE   //delete
-}
+    REMOVE;  //delete
+
+    /**
+     * Not all patch operations support value node. Check if operation requires value or not.
+     * @param operation Name of the operation to be checked
+     * @return true if operation requires value, false otherwise
+     */
+    public static final boolean isPatchOperationWithValue(@Nonnull final String operation) {
+        switch (PATCHEditOperation.valueOf(operation.toUpperCase())) {
+            case CREATE:
+                // fall through
+            case MERGE:
+                // fall through
+            case REPLACE:
+                // fall through
+            case INSERT:
+                return true;
+            default:
+                return false;
+        }
+    }
+}
\ No newline at end of file