Create NetconfDataTreeService with base and additional operations for netconf
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / utils / DeleteDataTransactionUtil.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.restconf.nb.rfc8040.rests.utils;
9
10 import com.google.common.util.concurrent.FluentFuture;
11 import javax.ws.rs.core.Response;
12 import javax.ws.rs.core.Response.Status;
13 import org.opendaylight.mdsal.common.api.CommitInfo;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17
18 /**
19  * Util class for delete specific data in config DS.
20  */
21 public final class DeleteDataTransactionUtil {
22
23     private DeleteDataTransactionUtil() {
24         throw new UnsupportedOperationException("Util class.");
25     }
26
27     /**
28      * Delete data from DS via transaction.
29      *
30      * @param strategy object that perform the actual DS operations
31      * @return {@link Response}
32      */
33     public static Response deleteData(final RestconfStrategy strategy) {
34         strategy.prepareReadWriteExecution();
35         final YangInstanceIdentifier path = strategy.getInstanceIdentifier().getInstanceIdentifier();
36         TransactionUtil.checkItemExists(strategy, LogicalDatastoreType.CONFIGURATION, path,
37                 RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE);
38         strategy.delete(LogicalDatastoreType.CONFIGURATION, path);
39         final FluentFuture<? extends CommitInfo> future = strategy.commit();
40         final ResponseFactory response = new ResponseFactory(Status.NO_CONTENT);
41         //This method will close transactionChain if any
42         FutureCallbackTx.addCallback(future, RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE, response,
43                 strategy.getTransactionChain());
44         return response.build();
45     }
46 }