- writeTx.merge(LogicalDatastoreType.CONFIGURATION, rootNormalizedPath, parentStructure);
- }
-
- /**
- * Check if items already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
- * data does NOT already exists.
- * @param transactionChainHandler Transaction chain handler
- * @param rwTransaction Transaction
- * @param store Datastore
- * @param path Path to be checked
- * @param operationType Type of operation (READ, POST, PUT, DELETE...)
- */
- public static void checkItemExists(final TransactionChainHandler transactionChainHandler,
- final DOMDataReadWriteTransaction rwTransaction,
- final LogicalDatastoreType store, final YangInstanceIdentifier path,
- final String operationType) {
- final CheckedFuture<Boolean, ReadFailedException> future = rwTransaction.exists(store, path);
- final FutureDataFactory<Boolean> response = new FutureDataFactory<>();
-
- FutureCallbackTx.addCallback(future, operationType, response);
-
- if (!response.result) {
- // close transaction and reset transaction chain
- rwTransaction.cancel();
- transactionChainHandler.reset();
-
- // throw error
- final String errMsg = "Operation via Restconf was not executed because data does not exist";
- LOG.trace("{}:{}", errMsg, 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.
- * @param transactionChainHandler Transaction chain handler
- * @param rwTransaction Transaction
- * @param store Datastore
- * @param path Path to be checked
- * @param operationType Type of operation (READ, POST, PUT, DELETE...)
- */
- public static void checkItemDoesNotExists(final TransactionChainHandler transactionChainHandler,
- final DOMDataReadWriteTransaction rwTransaction,
- final LogicalDatastoreType store, final YangInstanceIdentifier path,
- final String operationType) {
- final CheckedFuture<Boolean, ReadFailedException> future = rwTransaction.exists(store, path);
- final FutureDataFactory<Boolean> response = new FutureDataFactory<>();
-
- FutureCallbackTx.addCallback(future, operationType, response);
-
- if (response.result) {
- // close transaction and reset transaction chain
- rwTransaction.cancel();
- transactionChainHandler.reset();
-
- // throw error
- final String errMsg = "Operation via Restconf was not executed because data already exists";
- LOG.trace("{}:{}", errMsg, path);
- throw new RestconfDocumentedException(
- "Data already exists", ErrorType.PROTOCOL, ErrorTag.DATA_EXISTS, path);
- }