2 * ============LICENSE_START========================================================================
\r
3 * ONAP : tr-069-adapter
\r
4 * =================================================================================================
\r
5 * Copyright (C) 2020 CommScope Inc Intellectual Property.
\r
6 * =================================================================================================
\r
7 * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
\r
8 * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
\r
9 * may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
\r
14 * either express or implied. See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
16 * ===============LICENSE_END=======================================================================
\r
19 package org.commscope.tr069adapter.netconf.rpc;
\r
21 import java.io.IOException;
\r
23 import org.commscope.tr069adapter.mapper.model.ErrorCodeDetails;
\r
24 import org.commscope.tr069adapter.mapper.model.NetConfResponse;
\r
25 import org.commscope.tr069adapter.netconf.boot.NetConfServiceBooter;
\r
26 import org.commscope.tr069adapter.netconf.config.NetConfServerProperties;
\r
27 import org.opendaylight.netconf.api.DocumentedException;
\r
28 import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
\r
29 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
\r
30 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
\r
31 import org.opendaylight.netconf.api.xml.XmlElement;
\r
32 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
\r
33 import org.opendaylight.netconf.api.xml.XmlUtil;
\r
34 import org.opendaylight.netconf.test.tool.rpc.DataList;
\r
35 import org.opendaylight.netconf.util.mapping.AbstractLastNetconfOperation;
\r
36 import org.slf4j.Logger;
\r
37 import org.slf4j.LoggerFactory;
\r
38 import org.w3c.dom.Document;
\r
39 import org.w3c.dom.Element;
\r
40 import org.xml.sax.SAXException;
\r
42 public class GetOperation extends AbstractLastNetconfOperation {
\r
43 private static final Logger logger = LoggerFactory.getLogger(GetOperation.class);
\r
45 private final DataList storage;
\r
46 private String deviceID;
\r
48 public GetOperation(final String netconfSessionIdForReporting, final DataList storage,
\r
50 super(netconfSessionIdForReporting);
\r
51 this.deviceID = deviceID;
\r
52 this.storage = storage;
\r
56 protected Element handleWithNoSubsequentOperations(final Document document,
\r
57 final XmlElement operationElement) throws DocumentedException {
\r
58 final Element element = document.createElement(XmlNetconfConstants.DATA_KEY);
\r
60 for (final XmlElement e : storage.getConfigList()) {
\r
61 final Element domElement = e.getDomElement();
\r
62 element.appendChild(element.getOwnerDocument().importNode(domElement, true));
\r
65 String requestXml = XmlUtility.convertDocumentToString(operationElement);
\r
66 logger.debug("netconf request recevied : {}", requestXml);
\r
67 NetConfServerProperties config =
\r
68 NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
\r
70 final String baseUrl = config.getMapperPath() + "/get";
\r
71 NetConfResponse restResponse = XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID);
\r
73 if (restResponse != null) {
\r
74 ErrorCodeDetails errorCode = restResponse.getErrorCode();
\r
75 if (errorCode != null && errorCode.getFaultCode() != null
\r
76 && !errorCode.getFaultCode().equalsIgnoreCase("0")) {
\r
77 throw new DocumentedException(errorCode.getErrorMessage(),
\r
78 ErrorType.from(errorCode.getErrorType()), ErrorTag.from(errorCode.getErrorTag()),
\r
79 ErrorSeverity.from(errorCode.getErrorSeverity()));
\r
80 } else if (restResponse.getNetconfResponseXml() != null) {
\r
81 Element element1 = null;
\r
83 element1 = XmlUtil.readXmlToElement(restResponse.getNetconfResponseXml());
\r
84 XmlElement xmlElement = XmlElement.fromDomElement(element1);
\r
85 Element domElement = xmlElement.getDomElement();
\r
86 element.appendChild(element.getOwnerDocument().importNode(domElement, true));
\r
87 } catch (SAXException | IOException e1) {
\r
88 logger.error("Error while constructing the reponse {}", e1.toString());
\r
92 logger.error("received the null response from mapper ");
\r
93 throw new DocumentedException("Unable to perform Operation", ErrorType.from("application"),
\r
94 ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
\r
100 protected String getOperationName() {
\r
101 return XmlNetconfConstants.GET;
\r