2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.restful.utils;
10 import com.google.common.util.concurrent.CheckedFuture;
11 import javax.ws.rs.core.Response;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
15 import org.opendaylight.restconf.restful.transaction.TransactionVarsWrapper;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 * Util class for delete specific data in config DS.
22 public final class DeleteDataTransactionUtil {
24 private DeleteDataTransactionUtil() {
25 throw new UnsupportedOperationException("Util class.");
29 * Delete data from DS via transaction.
31 * @param transactionNode
32 * - Wrapper for data of transaction
33 * @return {@link Response}
36 public static Response deleteData(final TransactionVarsWrapper transactionNode) {
37 final CheckedFuture<Void, TransactionCommitFailedException> future = submitData(
38 transactionNode.getTransaction(), transactionNode.getInstanceIdentifier().getInstanceIdentifier());
39 final ResponseFactory response = new ResponseFactory();
40 FutureCallbackTx.addCallback(future, RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE, response);
41 return response.build();
45 * Delete data via transaction
50 * - path of data to delete
51 * @return {@link CheckedFuture}
53 private static CheckedFuture<Void, TransactionCommitFailedException> submitData(
54 final DOMDataWriteTransaction writeTx, final YangInstanceIdentifier path) {
55 writeTx.delete(LogicalDatastoreType.CONFIGURATION, path);
56 return writeTx.submit();