- if (futureDatastoreData.get()) {
- final String errMsg = "Post Configuration via Restconf was not executed because data already exists";
- LOG.trace("{}:{}", errMsg, path);
- rWTransaction.cancel();
- throw new RestconfDocumentedException("Data already exists for path: " + path, ErrorType.PROTOCOL,
- ErrorTag.DATA_EXISTS);
+ responseWaiter.await();
+ } catch (final InterruptedException e) {
+ final String msg = "Problem while waiting for response";
+ LOG.warn(msg);
+ throw new RestconfDocumentedException(msg, e);
+ }
+
+ if (!readData.getResult()) {
+ final String errMsg = "Operation via Restconf was not executed because data does not exist";
+ LOG.trace("{}:{}", errMsg, path);
+ rWTransaction.cancel();
+ throw new RestconfDocumentedException("Data does not exist for path: " + path, ErrorType.PROTOCOL,
+ ErrorTag.DATA_MISSING);
+ }
+ }
+
+ /**
+ * Check if item does NOT already exist. Throws error if it already exists.
+ * @param rWTransaction Current transaction
+ * @param store Used datastore
+ * @param path Path to item to verify its existence
+ */
+ private void checkItemDoesNotExists(final DOMDataReadWriteTransaction rWTransaction,
+ final LogicalDatastoreType store, final YangInstanceIdentifier path) {
+ final CountDownLatch responseWaiter = new CountDownLatch(1);
+ final ReadDataResult<Boolean> readData = new ReadDataResult<>();
+ final CheckedFuture<Boolean, ReadFailedException> future = rWTransaction.exists(store, path);
+
+ Futures.addCallback(future, new FutureCallback<Boolean>() {
+ @Override
+ public void onSuccess(@Nullable final Boolean result) {
+ responseWaiter.countDown();
+ handlingCallback(null, store, path, Optional.of(result), readData);
+ }
+
+ @Override
+ public void onFailure(final Throwable t) {
+ responseWaiter.countDown();
+ handlingCallback(t, store, path, null, null);