Inline checkItemExistsWithinTransaction() 63/93063/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 14 Oct 2020 17:49:31 +0000 (19:49 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 14 Oct 2020 21:23:47 +0000 (23:23 +0200)
This is a very simplistic method, inline it so we can properly
evolve it.

Change-Id: Ic5fefc63c9e095be430bf93b603a970be652a056
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtil.java

index e047dab994d211c7d3126a4211f031e1196a5782..09e3dbcc2f333b45d408abecb66f4ab4d0a49a58 100644 (file)
@@ -179,7 +179,17 @@ public final class PatchDataTransactionUtil {
                                                     final YangInstanceIdentifier path,
                                                     final RestconfStrategy strategy) {
         LOG.trace("Delete {} within Restconf Patch: {}", dataStore.name(), path);
-        checkItemExistsWithinTransaction(strategy, dataStore, path);
+        final FluentFuture<Boolean> future = strategy.exists(dataStore, path);
+        final FutureDataFactory<Boolean> response = new FutureDataFactory<>();
+
+        FutureCallbackTx.addCallback(future, PatchData.PATCH_TX_TYPE, response);
+
+        if (!response.result) {
+            LOG.trace("Operation via Restconf was not executed because data at {} does not exist", path);
+            throw new RestconfDocumentedException("Data does not exist", ErrorType.PROTOCOL, ErrorTag.DATA_MISSING,
+                    path);
+        }
+
         strategy.delete(dataStore, path);
     }
 
@@ -280,29 +290,6 @@ public final class PatchDataTransactionUtil {
         }
     }
 
-    /**
-     * Check if items already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
-     * data does NOT already exists.
-     *
-     * @param strategy      Object that perform the actual DS operations
-     * @param store         Datastore
-     * @param path          Path to be checked
-     */
-    public static void checkItemExistsWithinTransaction(final RestconfStrategy strategy,
-                                                        final LogicalDatastoreType store,
-                                                        final YangInstanceIdentifier path) {
-        final FluentFuture<Boolean> future = strategy.exists(store, path);
-        final FutureDataFactory<Boolean> response = new FutureDataFactory<>();
-
-        FutureCallbackTx.addCallback(future, PatchData.PATCH_TX_TYPE, response);
-
-        if (!response.result) {
-            LOG.trace("Operation via Restconf was not executed because data at {} does not exist", path);
-            throw new RestconfDocumentedException("Data does not exist", ErrorType.PROTOCOL, ErrorTag.DATA_MISSING,
-                    path);
-        }
-    }
-
     /**
      * Check if items do NOT already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
      * data already exists.