Remove netconf from commons/opendaylight pom
[controller.git] / opendaylight / netconf / mdsal-netconf-connector / src / main / java / org / opendaylight / controller / netconf / mdsal / connector / ops / Unlock.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.controller.netconf.mdsal.connector.ops;
10
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.config.util.xml.DocumentedException;
13 import org.opendaylight.controller.config.util.xml.XmlElement;
14 import org.opendaylight.controller.config.util.xml.XmlUtil;
15 import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
16 import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19 import org.w3c.dom.Document;
20 import org.w3c.dom.Element;
21
22 public class Unlock extends AbstractSingletonNetconfOperation {
23
24     private static final Logger LOG = LoggerFactory.getLogger(Unlock.class);
25
26     private static final String OPERATION_NAME = "unlock";
27
28     public Unlock(final String netconfSessionIdForReporting) {
29         super(netconfSessionIdForReporting);
30     }
31
32     @Override
33     protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
34         final Datastore targetDatastore = Lock.extractTargetParameter(operationElement);
35         if (targetDatastore == Datastore.candidate) {
36             LOG.debug("Unlocking candidate datastore on session: {}", getNetconfSessionIdForReporting());
37             return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
38         }
39
40         throw new DocumentedException("Unable to unlock " + targetDatastore + " datastore", DocumentedException.ErrorType.application,
41                 DocumentedException.ErrorTag.operation_not_supported, DocumentedException.ErrorSeverity.error);
42     }
43
44     @Override
45     protected String getOperationName() {
46         return OPERATION_NAME;
47     }
48
49 }