sonar code issues addressed 91/4791/1
authorravi.setti <Ravi.Setti@commscope.com>
Wed, 30 Sep 2020 07:40:17 +0000 (07:40 +0000)
committerravi.setti <Ravi.Setti@commscope.com>
Wed, 30 Sep 2020 07:41:52 +0000 (07:41 +0000)
code smell issues reported in the sonarqube tool addressed

Issue-Id: OAM-152
Signed-off-by: ravi.setti <Ravi.Setti@commscope.com>
Change-Id: I7c80225c9e0a78784e79822b0100d7200b1ca6ca

23 files changed:
acs/application-booter/src/main/resources/application.properties
acs/common/src/main/java/org/commscope/tr069adapter/acs/common/utils/OperationIdGenerator.java [moved from acs/nbi/src/main/java/org/commscope/tr069adapter/acs/nbi/util/OperationIdGenerator.java with 93% similarity]
acs/cpe/src/main/java/org/commscope/tr069adapter/acs/cpe/TR069RPC.java
acs/cpe/src/main/java/org/commscope/tr069adapter/acs/cpe/handler/DeviceEventHandler.java
acs/cpe/src/main/java/org/commscope/tr069adapter/acs/cpe/handler/DeviceValidator.java
acs/nbi/src/main/java/org/commscope/tr069adapter/acs/nbi/impl/ACSServiceAPIImpl.java
acs/requestprocessor/src/main/java/org/commscope/tr069adapter/acs/requestprocessor/impl/TR069EventNotificationService.java
acs/requestprocessor/src/main/java/org/commscope/tr069adapter/acs/requestprocessor/impl/TR069RequestProcessEngine.java
common/src/main/java/org/commscope/tr069adapter/common/deviceversion/DeviceVersionManagerImpl.java
netconf-server/src/main/java/org/commscope/tr069adapter/netconf/notification/NetConfNotificationQueue.java
netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/AddObjectOperation.java
netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/ConnectionStatus.java
netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/CreateSubscription.java
netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/DeleteObjectOperation.java
netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/DownloadOperation.java
netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/GPAObjectOperation.java
netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/GenericOperation.java [new file with mode: 0644]
netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/RebootOperation.java
netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/ResetOperation.java
netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/SPAObjectOperation.java
netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/SoftwareActivateOperation.java
netconf-server/src/main/java/org/commscope/tr069adapter/netconf/server/NetConfServerManagerImpl.java
ves-agent/src/main/java/org/commscope/tr069adapter/vesagent/service/VesAgentServiceHelper.java

index a834eec..af427e5 100644 (file)
@@ -50,4 +50,5 @@ config.deviceValidationURL=http://${FACTORY_REST_HOST}:${FACTORY_REST_PORT}/vali
 \r
 ## Mapper Configuration\r
 config.mapperInformNotificationServiceURL=http://${MAPPER_REST_HOST}:${MAPPER_REST_PORT}/tr069MapperSBI/notification\r
-config.mapperDeviceRPCResponseNotificationServiceURL=http://${MAPPER_REST_HOST}:${MAPPER_REST_PORT}/tr069MapperSBI/opResult
\ No newline at end of file
+config.mapperDeviceRPCResponseNotificationServiceURL=http://${MAPPER_REST_HOST}:${MAPPER_REST_PORT}/tr069MapperSBI/opResult\r
+config.isDeviceAuthorizationEnabled=true
\ No newline at end of file
@@ -1,30 +1,30 @@
-/*\r
- * ============LICENSE_START========================================================================\r
- * ONAP : tr-069-adapter\r
- * =================================================================================================\r
- * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
- * =================================================================================================\r
- * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
- * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
- * may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
- * either express or implied. See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ===============LICENSE_END=======================================================================\r
- */\r
-\r
-package org.commscope.tr069adapter.acs.nbi.util;\r
-\r
-import org.springframework.stereotype.Component;\r
-\r
-@Component\r
-public class OperationIdGenerator {\r
-\r
-  public Long generateOpId() {\r
-    return System.currentTimeMillis();\r
-  }\r
-\r
-}\r
+/*
+ * ============LICENSE_START========================================================================
+ * ONAP : tr-069-adapter
+ * =================================================================================================
+ * Copyright (C) 2020 CommScope Inc Intellectual Property.
+ * =================================================================================================
+ * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
+ * may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ===============LICENSE_END=======================================================================
+ */
+
+package org.commscope.tr069adapter.acs.common.utils;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class OperationIdGenerator {
+
+  public Long generateOpId() {
+    return System.currentTimeMillis();
+  }
+
+}
index 3aa7669..d3a3a9c 100644 (file)
@@ -169,7 +169,7 @@ public abstract class TR069RPC implements Serializable {
     while (pfxs.hasNext()) {
       String pfx = pfxs.next();
       String uri = env.getNamespaceURI(pfx);
-      if (uri.startsWith("urn:dslforum-org:cwmp-")) {
+      if (CWMP.equalsIgnoreCase(pfx)) {
         urnCWMP = uri;
       }
     }
index 7d1fba0..c7644bd 100644 (file)
@@ -89,7 +89,6 @@ public class DeviceEventHandler {
     List<String> parameters = new ArrayList<>();
     parameters.add("InternetGatewayDevice.DeviceInfo.HardwareVersion");
     parameters.add("InternetGatewayDevice.DeviceInfo.SoftwareVersion");
-    parameters.add("InternetGatewayDevice.DeviceInfo.ProvisioningCode");
     parameters.add("InternetGatewayDevice.ManagementServer.ConnectionRequestURL");
     parameters.add("InternetGatewayDevice.ManagementServer.ParameterKey");
     informParameter.put("InternetGatewayDevice", parameters);
index 5caeb50..f0fb6bd 100644 (file)
@@ -18,6 +18,7 @@
 \r
 package org.commscope.tr069adapter.acs.cpe.handler;\r
 \r
+\r
 import java.nio.charset.StandardCharsets;\r
 import java.util.Base64;\r
 \r
@@ -27,6 +28,7 @@ import org.commscope.tr069adapter.acs.cpe.utils.FactorySrvcDependencyConfig;
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.beans.factory.annotation.Value;\r
 import org.springframework.http.ResponseEntity;\r
 import org.springframework.stereotype.Component;\r
 import org.springframework.web.client.RestTemplate;\r
@@ -42,6 +44,9 @@ public class DeviceValidator {
   @Autowired\r
   RestTemplate restTemplate;\r
 \r
+  @Value("${config.isDeviceAuthorizationEnabled:true}")\r
+  private boolean isDeviceAuthorizationEnabled;\r
+\r
   public void setFactorySrvcDependencyConfig(\r
       FactorySrvcDependencyConfig factorySrvcDependencyConfig) {\r
     this.factorySrvcDependencyConfig = factorySrvcDependencyConfig;\r
@@ -53,6 +58,10 @@ public class DeviceValidator {
    * @return\r
    */\r
   public Boolean isDeviceAuthorized(Inform inform, String authorization) {\r
+    if(!isDeviceAuthorizationEnabled){\r
+      logger.debug("Device authentication is not needed here. Hence always authorizing.");\r
+      return true;\r
+    }\r
     if (authorization == null) {\r
       logger.debug("HTTP Challenge failed as Authorization header does not exist");\r
       return false;\r
index 1e1ff1a..c249249 100644 (file)
@@ -25,7 +25,7 @@ import org.commscope.tr069adapter.acs.common.DeviceRPCRequest;
 import org.commscope.tr069adapter.acs.common.OperationCode;
 import org.commscope.tr069adapter.acs.common.exception.MapperServiceException;
 import org.commscope.tr069adapter.acs.common.mapper.ACSServiceAPI;
-import org.commscope.tr069adapter.acs.nbi.util.OperationIdGenerator;
+import org.commscope.tr069adapter.acs.common.utils.OperationIdGenerator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
index 2f1ac6f..87ea94e 100644 (file)
@@ -30,10 +30,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Profile;
 import org.springframework.jms.core.JmsTemplate;
 import org.springframework.stereotype.Component;
 
 @Component
+//@Profile(value="default")
 public class TR069EventNotificationService {
 
   private static final Logger logger = LoggerFactory.getLogger(TR069EventNotificationService.class);
@@ -50,6 +52,7 @@ public class TR069EventNotificationService {
     String deviceId = deviceNotification.getDeviceDetails().getDeviceId();
     try {
       MDC.put(CLIENT_STR, deviceId);
+
       TR069InformType notificationType = (TR069InformType) deviceNotification.getInformType();
 
       logger.debug("Device Inform Event received: '{}'", notificationType.getNotificationCode());
index 5689a31..75c9437 100644 (file)
@@ -110,7 +110,7 @@ public class TR069RequestProcessEngine extends TR069RequestProcessEngineHelper {
         if (null != deviceRPCResponse) {
           return;
         }
-      } catch (DeviceOperationException | SessionManagerException deo) {
+      } catch (DeviceOperationException deo) {
         logger.error(deo.getMessage());
         deviceRPCResponse = tr069RequestProcessEngineUtility.buildAbortedOperationresult(
             tr069DeviceDetails, deviceRPCRequest, AcsFaultCode.FAULT_CODE_8000);
@@ -164,7 +164,7 @@ public class TR069RequestProcessEngine extends TR069RequestProcessEngineHelper {
   }
 
   private DeviceRPCResponse checkForDeviceAvailabilityRequest(DeviceRPCRequest deviceRPCRequest,
-      TR069DeviceDetails tr069DeviceDetails) throws SessionManagerException {
+      TR069DeviceDetails tr069DeviceDetails) {
     DeviceRPCResponse deviceRPCResponse = null;
 
     if (!deviceRPCRequest.getOpDetails().getOpCode().equals(CustomOperationCode.CONNECT)) {
index 0c712c5..2fdcbff 100644 (file)
@@ -132,13 +132,8 @@ public class DeviceVersionManagerImpl implements DeviceVersionManager {
           if (deviceVersion.getSwVersion().equalsIgnoreCase(profileVersion.getSwVersion())
               || deviceVersion.getSwVersion().matches(profileVersion.getSwVersion())) {
             if (profileVersion.isHwRegex()) {
-              if (deviceVersion.getHwVersion() != null) {
-
-                if ("*".equalsIgnoreCase(profileVersion.getHwVersion())
-                    || deviceVersion.getHwVersion().equalsIgnoreCase(profileVersion.getHwVersion())
-                    || deviceVersion.getHwVersion().matches(profileVersion.getHwVersion())) {
+              if (deviceVersion.getHwVersion() != null && hwVersionCheck(deviceVersion, profileVersion)) {
                   return entry.getValue();
-                }
               }
             } else {
               // Check Strict match of Hardware
@@ -148,17 +143,11 @@ public class DeviceVersionManagerImpl implements DeviceVersionManager {
               }
             }
           }
-        } else if (profileVersion.isHwRegex()) {
-          if (deviceVersion.getHwVersion() != null) {
-            if ("*".equalsIgnoreCase(profileVersion.getHwVersion())
-                || deviceVersion.getHwVersion().equalsIgnoreCase(profileVersion.getHwVersion())
-                || deviceVersion.getHwVersion().matches(profileVersion.getHwVersion())) {
+        } else if (profileVersion.isHwRegex() && (deviceVersion.getHwVersion() != null && hwVersionCheck(deviceVersion, profileVersion)) ) {
               // Add all software version which matching
               if (profileVersion.getSwVersion()
                   .compareToIgnoreCase(deviceVersion.getSwVersion()) <= 0) {
                 mSoftwareList.add(profileVersion);
-              }
-            }
           }
         }
       } else {
@@ -181,4 +170,10 @@ public class DeviceVersionManagerImpl implements DeviceVersionManager {
 
     return null;
   }
+
+  private boolean hwVersionCheck(DeviceVersion deviceVersion, DeviceVersion profileVersion) {
+    return "*".equalsIgnoreCase(profileVersion.getHwVersion()) || deviceVersion.getHwVersion()
+        .equalsIgnoreCase(profileVersion.getHwVersion()) || deviceVersion.getHwVersion()
+        .matches(profileVersion.getHwVersion());
+  }
 }
index d407ed4..6dbaa84 100644 (file)
@@ -34,7 +34,7 @@ public class NetConfNotificationQueue {
   private static final Logger logger = LoggerFactory.getLogger(NetConfNotificationQueue.class);\r
 \r
   @Autowired\r
-  NetConfSessionUtil netConfSessionUtil;;\r
+  NetConfSessionUtil netConfSessionUtil;\r
 \r
   @JmsListener(destination = NetConfServerConstants.NETCONF_NOTIFICATION_Q,\r
       containerFactory = NetConfServerConstants.NETCONF_NOTIFICATION_CF)\r
index 03c1776..40b8e74 100644 (file)
@@ -34,34 +34,22 @@ import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
-import org.opendaylight.netconf.mapping.api.HandlingPriority;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.xml.sax.InputSource;
 
-public class AddObjectOperation implements NetconfOperation {
+public class AddObjectOperation extends GenericOperation {
   private static final Logger logger = LoggerFactory.getLogger(AddObjectOperation.class);
-  public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
-  public static final String OP_NAME = "add-object";
-  private String deviceID;
-  private String swVersion;
-  private String hwVersion;
 
   public AddObjectOperation(String deviceID, String swVersion, String hwVersion) {
     this.deviceID = deviceID;
     this.swVersion = swVersion;
     this.hwVersion = hwVersion;
-  }
-
-  @Override
-  public HandlingPriority canHandle(final Document message) throws DocumentedException {
-    OperationNameAndNamespace operationNameAndNamespace = null;
-    operationNameAndNamespace = new OperationNameAndNamespace(message);
-    return canHandle(operationNameAndNamespace.getOperationName(),
-        operationNameAndNamespace.getNamespace());
+    setOpString("addobject");
+    setOpNamespace("urn:tr069rpc:1.0");
+    setOpName("add-object");
   }
 
   @Override
@@ -81,7 +69,7 @@ public class AddObjectOperation implements NetconfOperation {
     NetConfServerProperties config =
         NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
 
-    final String baseUrl = config.getMapperPath() + "/addobject";
+    final String baseUrl = config.getMapperPath() + "/" + getOpString();
     NetConfResponse restResponse =
         XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
     Document document = null;
@@ -104,7 +92,7 @@ public class AddObjectOperation implements NetconfOperation {
         builder = factory.newDocumentBuilder();
         document =
             builder.parse(new InputSource(new StringReader(restResponse.getNetconfResponseXml())));
-        document.getDocumentElement().setAttribute("xmlns:ns1", getOperationNamespace());
+        document.getDocumentElement().setAttribute("xmlns:ns1", getOpNamespace());
         document.getDocumentElement().setAttribute("xmlns",
             XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
         document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);
@@ -117,55 +105,4 @@ public class AddObjectOperation implements NetconfOperation {
 
     return document;
   }
-
-  protected HandlingPriority canHandle(final String operationName,
-      final String operationNamespace) {
-    return operationName.equals(getOperationName())
-        && operationNamespace.equals(getOperationNamespace())
-            ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
-            : HandlingPriority.CANNOT_HANDLE;
-  }
-
-  public static final class OperationNameAndNamespace {
-    private final String operationName;
-    private final String namespace;
-
-    private final XmlElement operationElement;
-
-    public OperationNameAndNamespace(final Document message) throws DocumentedException {
-      XmlElement requestElement = null;
-      requestElement = getRequestElementWithCheck(message);
-      operationElement = requestElement.getOnlyChildElement();
-      operationName = operationElement.getName();
-      namespace = operationElement.getNamespace();
-    }
-
-    public String getOperationName() {
-      return operationName;
-    }
-
-    public String getNamespace() {
-      return namespace;
-    }
-
-    public XmlElement getOperationElement() {
-      return operationElement;
-    }
-
-  }
-
-  protected static XmlElement getRequestElementWithCheck(final Document message)
-      throws DocumentedException {
-    return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
-        XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
-  }
-
-  protected String getOperationNamespace() {
-    return OP_NAMESPACE;
-  }
-
-  protected String getOperationName() {
-    return OP_NAME;
-  }
-
 }
index 3af3d34..ab776a7 100644 (file)
@@ -34,35 +34,22 @@ import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
-import org.opendaylight.netconf.mapping.api.HandlingPriority;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.xml.sax.InputSource;
 
-public class ConnectionStatus implements NetconfOperation {
+public class ConnectionStatus extends GenericOperation {
   private static final Logger logger = LoggerFactory.getLogger(ConnectionStatus.class);
-  public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
-  public static final String OP_NAME = "connection-status";
-
-  private String deviceID;
-  private String swVersion;
-  private String hwVersion;
 
   public ConnectionStatus(String deviceID, String swVersion, String hwVersion) {
     this.deviceID = deviceID;
     this.swVersion = swVersion;
     this.hwVersion = hwVersion;
-  }
-
-  @Override
-  public HandlingPriority canHandle(final Document message) throws DocumentedException {
-    OperationNameAndNamespace operationNameAndNamespace = null;
-    operationNameAndNamespace = new OperationNameAndNamespace(message);
-    return canHandle(operationNameAndNamespace.getOperationName(),
-        operationNameAndNamespace.getNamespace());
+    setOpString("connectionstatus");
+    setOpNamespace("urn:tr069rpc:1.0");
+    setOpName("connection-status");
   }
 
   @Override
@@ -82,7 +69,7 @@ public class ConnectionStatus implements NetconfOperation {
     NetConfServerProperties config =
         NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
 
-    final String baseUrl = config.getMapperPath() + "/connectionstatus";
+    final String baseUrl = config.getMapperPath() + "/" + getOpString();
     NetConfResponse restResponse =
         XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
     Document document = null;
@@ -105,7 +92,7 @@ public class ConnectionStatus implements NetconfOperation {
         builder = factory.newDocumentBuilder();
         document =
             builder.parse(new InputSource(new StringReader(restResponse.getNetconfResponseXml())));
-        document.getDocumentElement().setAttribute("xmlns:ns1", getOperationNamespace());
+        document.getDocumentElement().setAttribute("xmlns:ns1", getOpNamespace());
         document.getDocumentElement().setAttribute("xmlns",
             XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
         document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);
@@ -118,55 +105,4 @@ public class ConnectionStatus implements NetconfOperation {
 
     return document;
   }
-
-  protected HandlingPriority canHandle(final String operationName,
-      final String operationNamespace) {
-    return operationName.equals(getOperationName())
-        && operationNamespace.equals(getOperationNamespace())
-            ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
-            : HandlingPriority.CANNOT_HANDLE;
-  }
-
-  public static final class OperationNameAndNamespace {
-    private final String operationName;
-    private final String namespace;
-
-    private final XmlElement operationElement;
-
-    public OperationNameAndNamespace(final Document message) throws DocumentedException {
-      XmlElement requestElement = null;
-      requestElement = getRequestElementWithCheck(message);
-      operationElement = requestElement.getOnlyChildElement();
-      operationName = operationElement.getName();
-      namespace = operationElement.getNamespace();
-    }
-
-    public String getOperationName() {
-      return operationName;
-    }
-
-    public String getNamespace() {
-      return namespace;
-    }
-
-    public XmlElement getOperationElement() {
-      return operationElement;
-    }
-
-  }
-
-  protected static XmlElement getRequestElementWithCheck(final Document message)
-      throws DocumentedException {
-    return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
-        XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
-  }
-
-  protected String getOperationNamespace() {
-    return OP_NAMESPACE;
-  }
-
-  protected String getOperationName() {
-    return OP_NAME;
-  }
-
 }
index 70350f8..33ba683 100644 (file)
@@ -119,6 +119,14 @@ public class CreateSubscription extends AbstractLastNetconfOperation
   protected String getOperationNamespace() {
     return "urn:ietf:params:xml:ns:netconf:notification:1.0";
   }
+  
+  public String getSwVersion() {
+    return swVersion;
+  }
+
+  public String getHwVersion() {
+    return hwVersion;
+  }
 
   @Override
   protected Element handleWithNoSubsequentOperations(final Document document,
index 475dbc6..4665276 100644 (file)
@@ -34,35 +34,22 @@ import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
-import org.opendaylight.netconf.mapping.api.HandlingPriority;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.xml.sax.InputSource;
 
-public class DeleteObjectOperation implements NetconfOperation {
+public class DeleteObjectOperation extends GenericOperation {
   private static final Logger logger = LoggerFactory.getLogger(DeleteObjectOperation.class);
-  public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
-  public static final String OP_NAME = "delete-object";
-
-  private String deviceID;
-  private String swVersion;
-  private String hwVersion;
 
   public DeleteObjectOperation(String deviceID, String swVersion, String hwVersion) {
     this.deviceID = deviceID;
     this.swVersion = swVersion;
     this.hwVersion = hwVersion;
-  }
-
-  @Override
-  public HandlingPriority canHandle(final Document message) throws DocumentedException {
-    OperationNameAndNamespace operationNameAndNamespace = null;
-    operationNameAndNamespace = new OperationNameAndNamespace(message);
-    return canHandle(operationNameAndNamespace.getOperationName(),
-        operationNameAndNamespace.getNamespace());
+    setOpString("deleteobject");
+    setOpNamespace("urn:tr069rpc:1.0");
+    setOpName("delete-object");
   }
 
   @Override
@@ -82,7 +69,7 @@ public class DeleteObjectOperation implements NetconfOperation {
     NetConfServerProperties config =
         NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
 
-    final String baseUrl = config.getMapperPath() + "/deleteobject";
+    final String baseUrl = config.getMapperPath() + "/" + getOpString();
     NetConfResponse restResponse =
         XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
     Document document = null;
@@ -105,7 +92,7 @@ public class DeleteObjectOperation implements NetconfOperation {
         builder = factory.newDocumentBuilder();
         document =
             builder.parse(new InputSource(new StringReader(restResponse.getNetconfResponseXml())));
-        document.getDocumentElement().setAttribute("xmlns:ns1", getOperationNamespace());
+        document.getDocumentElement().setAttribute("xmlns:ns1", getOpNamespace());
         document.getDocumentElement().setAttribute("xmlns",
             XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
         document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);
@@ -118,55 +105,4 @@ public class DeleteObjectOperation implements NetconfOperation {
 
     return document;
   }
-
-  protected HandlingPriority canHandle(final String operationName,
-      final String operationNamespace) {
-    return operationName.equals(getOperationName())
-        && operationNamespace.equals(getOperationNamespace())
-            ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
-            : HandlingPriority.CANNOT_HANDLE;
-  }
-
-  public static final class OperationNameAndNamespace {
-    private final String operationName;
-    private final String namespace;
-
-    private final XmlElement operationElement;
-
-    public OperationNameAndNamespace(final Document message) throws DocumentedException {
-      XmlElement requestElement = null;
-      requestElement = getRequestElementWithCheck(message);
-      operationElement = requestElement.getOnlyChildElement();
-      operationName = operationElement.getName();
-      namespace = operationElement.getNamespace();
-    }
-
-    public String getOperationName() {
-      return operationName;
-    }
-
-    public String getNamespace() {
-      return namespace;
-    }
-
-    public XmlElement getOperationElement() {
-      return operationElement;
-    }
-
-  }
-
-  protected static XmlElement getRequestElementWithCheck(final Document message)
-      throws DocumentedException {
-    return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
-        XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
-  }
-
-  protected String getOperationNamespace() {
-    return OP_NAMESPACE;
-  }
-
-  protected String getOperationName() {
-    return OP_NAME;
-  }
-
 }
index 434fe7f..c867c2e 100644 (file)
 
 package org.commscope.tr069adapter.netconf.rpc;
 
-import java.io.StringReader;
-
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.commscope.tr069adapter.mapper.model.ErrorCodeDetails;
-import org.commscope.tr069adapter.mapper.model.NetConfResponse;
-import org.commscope.tr069adapter.netconf.boot.NetConfServiceBooter;
-import org.commscope.tr069adapter.netconf.config.NetConfServerProperties;
-import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
-import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
-import org.opendaylight.netconf.api.DocumentedException.ErrorType;
-import org.opendaylight.netconf.api.xml.XmlElement;
-import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
-import org.opendaylight.netconf.mapping.api.HandlingPriority;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
-import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-
-public class DownloadOperation implements NetconfOperation {
-  private static final Logger logger = LoggerFactory.getLogger(DownloadOperation.class);
-  public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
-  public static final String OP_NAME = "download";
-
-  private String deviceID;
-  private String swVersion;
-  private String hwVersion;
+public class DownloadOperation extends GenericOperation {
 
   public DownloadOperation(String deviceID, String swVersion, String hwVersion) {
     this.deviceID = deviceID;
     this.swVersion = swVersion;
     this.hwVersion = hwVersion;
+    setOpString("download");
+    setOpNamespace("urn:tr069rpc:1.0");
+    setOpName("download");
   }
-
-  @Override
-  public HandlingPriority canHandle(final Document message) throws DocumentedException {
-    OperationNameAndNamespace operationNameAndNamespace = null;
-    operationNameAndNamespace = new OperationNameAndNamespace(message);
-    return canHandle(operationNameAndNamespace.getOperationName(),
-        operationNameAndNamespace.getNamespace());
-  }
-
-  @Override
-  public Document handle(Document requestMessage,
-      NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
-    logger.debug("download rpc is received in netconfserver");
-
-    final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
-
-    final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
-    final Element element =
-        requestMessage.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-            XmlNetconfConstants.RPC_REPLY_KEY);
-    element.setAttribute("xmlns:ns1", getOperationNamespace());
-    element.setAttribute("message-id", msgId);
-
-    String requestXml = XmlUtility.convertDocumentToString(requestElement);
-    logger.debug("download rpc requestXml= {}", requestXml);
-
-
-    NetConfServerProperties config =
-        NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
-
-    final String baseUrl = config.getMapperPath() + "/download";
-    NetConfResponse restResponse =
-        XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
-    Document document = null;
-
-    ErrorCodeDetails errorCode = restResponse.getErrorCode();
-    if (errorCode != null && errorCode.getFaultCode() != null
-        && !errorCode.getFaultCode().equalsIgnoreCase("0")) {
-      logger.error("Error recevied : {}", errorCode);
-      throw new DocumentedException(errorCode.getErrorMessage(),
-          ErrorType.from(errorCode.getErrorType()), ErrorTag.from(errorCode.getErrorTag()),
-          ErrorSeverity.from(errorCode.getErrorSeverity()));
-    } else if (restResponse.getNetconfResponseXml() != null) {
-      logger.debug("download rpc response received from mapper: {}",
-          restResponse.getNetconfResponseXml());
-      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-      factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
-      factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
-      DocumentBuilder builder;
-      try {
-        Node child = requestMessage.createElement(XmlNetconfConstants.OK);
-        element.appendChild(child);
-        String xmlStr = XmlUtility.convertDocumentToString(element);
-        try {
-          builder = factory.newDocumentBuilder();
-          document = builder.parse(new InputSource(new StringReader(xmlStr)));
-        } catch (Exception e) {
-          logger.error("Error while converting String to element: {}", e.getMessage());
-          throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
-              ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
-        }
-      } catch (Exception e) {
-        logger.error("Error while contruscting the response: {}", e.getMessage());
-        throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
-            ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
-      }
-    }
-
-    return document;
-  }
-
-  protected HandlingPriority canHandle(final String operationName,
-      final String operationNamespace) {
-    return operationName.equals(getOperationName())
-        && operationNamespace.equals(getOperationNamespace())
-            ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
-            : HandlingPriority.CANNOT_HANDLE;
-  }
-
-  public static final class OperationNameAndNamespace {
-    private final String operationName;
-    private final String namespace;
-
-    private final XmlElement operationElement;
-
-    public OperationNameAndNamespace(final Document message) throws DocumentedException {
-      XmlElement requestElement = null;
-      requestElement = getRequestElementWithCheck(message);
-      operationElement = requestElement.getOnlyChildElement();
-      operationName = operationElement.getName();
-      namespace = operationElement.getNamespace();
-    }
-
-    public String getOperationName() {
-      return operationName;
-    }
-
-    public String getNamespace() {
-      return namespace;
-    }
-
-    public XmlElement getOperationElement() {
-      return operationElement;
-    }
-
-  }
-
-  protected static XmlElement getRequestElementWithCheck(final Document message)
-      throws DocumentedException {
-    return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
-        XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
-  }
-
-  protected String getOperationNamespace() {
-    return OP_NAMESPACE;
-  }
-
-  protected String getOperationName() {
-    return OP_NAME;
-  }
-
 }
index 3c0040c..205bd78 100644 (file)
@@ -34,35 +34,22 @@ import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
-import org.opendaylight.netconf.mapping.api.HandlingPriority;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.xml.sax.InputSource;
 
-public class GPAObjectOperation implements NetconfOperation {
+public class GPAObjectOperation extends GenericOperation {
   private static final Logger logger = LoggerFactory.getLogger(GPAObjectOperation.class);
-  public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
-  public static final String OP_NAME = "get-parameter-attributes";
-
-  private String deviceID;
-  private String swVersion;
-  private String hwVersion;
 
   public GPAObjectOperation(String deviceID, String swVersion, String hwVersion) {
     this.deviceID = deviceID;
     this.swVersion = swVersion;
     this.hwVersion = hwVersion;
-  }
-
-  @Override
-  public HandlingPriority canHandle(final Document message) throws DocumentedException {
-    OperationNameAndNamespace operationNameAndNamespace = null;
-    operationNameAndNamespace = new OperationNameAndNamespace(message);
-    return canHandle(operationNameAndNamespace.getOperationName(),
-        operationNameAndNamespace.getNamespace());
+    setOpString("gpaobject");
+    setOpNamespace("urn:tr069rpc:1.0");
+    setOpName("get-parameter-attributes");
   }
 
   @Override
@@ -79,7 +66,7 @@ public class GPAObjectOperation implements NetconfOperation {
     NetConfServerProperties config =
         NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
 
-    final String baseUrl = config.getMapperPath() + "/gpaobject";
+    final String baseUrl = config.getMapperPath() + "/" + getOpString();
     NetConfResponse restResponse =
         XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
     Document document = null;
@@ -102,7 +89,7 @@ public class GPAObjectOperation implements NetconfOperation {
         builder = factory.newDocumentBuilder();
         document =
             builder.parse(new InputSource(new StringReader(restResponse.getNetconfResponseXml())));
-        document.getDocumentElement().setAttribute("xmlns:ns1", getOperationNamespace());
+        document.getDocumentElement().setAttribute("xmlns:ns1", getOpNamespace());
         document.getDocumentElement().setAttribute("xmlns",
             XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
         document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);
@@ -116,54 +103,4 @@ public class GPAObjectOperation implements NetconfOperation {
     return document;
   }
 
-  protected HandlingPriority canHandle(final String operationName,
-      final String operationNamespace) {
-    return operationName.equals(getOperationName())
-        && operationNamespace.equals(getOperationNamespace())
-            ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
-            : HandlingPriority.CANNOT_HANDLE;
-  }
-
-  public static final class OperationNameAndNamespace {
-    private final String operationName;
-    private final String namespace;
-
-    private final XmlElement operationElement;
-
-    public OperationNameAndNamespace(final Document message) throws DocumentedException {
-      XmlElement requestElement = null;
-      requestElement = getRequestElementWithCheck(message);
-      operationElement = requestElement.getOnlyChildElement();
-      operationName = operationElement.getName();
-      namespace = operationElement.getNamespace();
-    }
-
-    public String getOperationName() {
-      return operationName;
-    }
-
-    public String getNamespace() {
-      return namespace;
-    }
-
-    public XmlElement getOperationElement() {
-      return operationElement;
-    }
-
-  }
-
-  protected static XmlElement getRequestElementWithCheck(final Document message)
-      throws DocumentedException {
-    return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
-        XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
-  }
-
-  protected String getOperationNamespace() {
-    return OP_NAMESPACE;
-  }
-
-  protected String getOperationName() {
-    return OP_NAME;
-  }
-
 }
diff --git a/netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/GenericOperation.java b/netconf-server/src/main/java/org/commscope/tr069adapter/netconf/rpc/GenericOperation.java
new file mode 100644 (file)
index 0000000..effaccc
--- /dev/null
@@ -0,0 +1,176 @@
+package org.commscope.tr069adapter.netconf.rpc;
+
+import org.commscope.tr069adapter.mapper.model.ErrorCodeDetails;
+import org.commscope.tr069adapter.mapper.model.NetConfResponse;
+import org.commscope.tr069adapter.netconf.boot.NetConfServiceBooter;
+import org.commscope.tr069adapter.netconf.config.NetConfServerProperties;
+import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.xml.XmlElement;
+import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
+import org.opendaylight.netconf.mapping.api.HandlingPriority;
+import org.opendaylight.netconf.mapping.api.NetconfOperation;
+import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.StringReader;
+
+
+public abstract class GenericOperation implements NetconfOperation {
+    private static final Logger logger = LoggerFactory.getLogger(GenericOperation.class);
+
+    private String opNamespace;
+    private String opName;
+    private String opString;
+
+    protected String deviceID;
+    protected String swVersion;
+    protected String hwVersion;
+
+    public HandlingPriority canHandle(final Document message) throws DocumentedException {
+        OperationNameAndNamespace operationNameAndNamespace = new OperationNameAndNamespace(message);
+        return canHandle(operationNameAndNamespace.getOperationName(),
+            operationNameAndNamespace.getNamespace());
+    }
+
+    protected HandlingPriority canHandle(final String operationName,
+        final String operationNamespace) {
+        return operationName.equals(getOpName())
+            && operationNamespace.equals(getOpNamespace())
+            ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
+            : HandlingPriority.CANNOT_HANDLE;
+    }
+
+    public Document handle(Document requestMessage,
+        NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
+        logger.debug("rpc is received in netconfserver");
+
+        final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
+
+        final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
+        final Element element =
+            requestMessage.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
+                XmlNetconfConstants.RPC_REPLY_KEY);
+        element.setAttribute("xmlns:ns1", getOpNamespace());
+        element.setAttribute("message-id", msgId);
+
+        String requestXml = XmlUtility.convertDocumentToString(requestElement);
+        logger.debug("rpc requestXml= {}", requestXml);
+
+        NetConfServerProperties config =
+            NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
+
+        final String baseUrl = config.getMapperPath() + "/" + getOpString();
+        NetConfResponse restResponse =
+            XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
+        Document document = null;
+
+        ErrorCodeDetails errorCode = restResponse.getErrorCode();
+        if (errorCode != null && errorCode.getFaultCode() != null
+            && !errorCode.getFaultCode().equalsIgnoreCase("0")) {
+            logger.error("Error recevied : {}", errorCode);
+            throw new DocumentedException(errorCode.getErrorMessage(),
+                DocumentedException.ErrorType.from(errorCode.getErrorType()), DocumentedException.ErrorTag
+                .from(errorCode.getErrorTag()),
+                DocumentedException.ErrorSeverity.from(errorCode.getErrorSeverity()));
+        } else if (restResponse.getNetconfResponseXml() != null) {
+            logger.debug("rpc response received from mapper: {}",
+                restResponse.getNetconfResponseXml());
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+            factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
+            try {
+                Node child = requestMessage.createElement(XmlNetconfConstants.OK);
+                element.appendChild(child);
+                String xmlStr = XmlUtility.convertDocumentToString(element);
+                document = getDocumentDetails(factory, xmlStr);
+            } catch (Exception e) {
+                logger.error("Error while contruscting the response: {}", e.getMessage());
+                throw new DocumentedException("Operation Aborted", DocumentedException.ErrorType.from("application"),
+                    DocumentedException.ErrorTag.from("operation-failed"), DocumentedException.ErrorSeverity
+                    .from("ERROR"));
+            }
+        }
+        return document;
+    }
+
+    protected Document getDocumentDetails(DocumentBuilderFactory factory, String xmlStr)
+        throws DocumentedException {
+        DocumentBuilder builder;
+        Document document;
+        try {
+            builder = factory.newDocumentBuilder();
+            document = builder.parse(new InputSource(new StringReader(xmlStr)));
+        } catch (Exception e) {
+            logger.error("Error while converting String to element: {}", e.getMessage());
+            throw new DocumentedException("Operation Aborted", DocumentedException.ErrorType.from("application"),
+                DocumentedException.ErrorTag.from("operation-failed"), DocumentedException.ErrorSeverity.from("ERROR"));
+        }
+        return document;
+    }
+
+    public static final class OperationNameAndNamespace {
+        private final String operationName;
+        private final String namespace;
+
+        private final XmlElement operationElement;
+
+        public OperationNameAndNamespace(final Document message) throws DocumentedException {
+            XmlElement requestElement = null;
+            requestElement = getRequestElementWithCheck(message);
+            operationElement = requestElement.getOnlyChildElement();
+            operationName = operationElement.getName();
+            namespace = operationElement.getNamespace();
+        }
+
+        public String getOperationName() {
+            return operationName;
+        }
+
+        public String getNamespace() {
+            return namespace;
+        }
+
+        public XmlElement getOperationElement() {
+            return operationElement;
+        }
+
+    }
+
+    protected static XmlElement getRequestElementWithCheck(final Document message)
+        throws DocumentedException {
+        return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
+            XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+    }
+
+    public String getOpNamespace() {
+        return opNamespace;
+    }
+
+    public void setOpNamespace(String opNamespace) {
+        this.opNamespace = opNamespace;
+    }
+
+    public String getOpName() {
+        return opName;
+    }
+
+    public void setOpName(String opName) {
+        this.opName = opName;
+    }
+
+    public String getOpString() {
+        return opString;
+    }
+
+    public void setOpString(String opString) {
+        this.opString = opString;
+    }
+}
index d5e8066..fbc691e 100644 (file)
 
 package org.commscope.tr069adapter.netconf.rpc;
 
-import java.io.StringReader;
-
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.commscope.tr069adapter.mapper.model.ErrorCodeDetails;
-import org.commscope.tr069adapter.mapper.model.NetConfResponse;
-import org.commscope.tr069adapter.netconf.boot.NetConfServiceBooter;
-import org.commscope.tr069adapter.netconf.config.NetConfServerProperties;
-import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
-import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
-import org.opendaylight.netconf.api.DocumentedException.ErrorType;
-import org.opendaylight.netconf.api.xml.XmlElement;
-import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
-import org.opendaylight.netconf.mapping.api.HandlingPriority;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
-import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-
-public class RebootOperation implements NetconfOperation {
-  private static final Logger logger = LoggerFactory.getLogger(RebootOperation.class);
-  public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
-  public static final String OP_NAME = "reboot";
-
-  private String deviceID;
-  private String swVersion;
-  private String hwVersion;
+public class RebootOperation extends GenericOperation {
 
   public RebootOperation(String deviceID, String swVersion, String hwVersion) {
     this.deviceID = deviceID;
     this.swVersion = swVersion;
     this.hwVersion = hwVersion;
+    setOpString("reboot");
+    setOpNamespace("urn:tr069rpc:1.0");
+    setOpName("reboot");
   }
 
-  @Override
-  public HandlingPriority canHandle(final Document message) throws DocumentedException {
-    OperationNameAndNamespace operationNameAndNamespace = null;
-    operationNameAndNamespace = new OperationNameAndNamespace(message);
-    return canHandle(operationNameAndNamespace.getOperationName(),
-        operationNameAndNamespace.getNamespace());
-  }
-
-  @Override
-  public Document handle(Document requestMessage,
-      NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
-    logger.debug("Reboot rpc is received in netconfserver");
-
-    final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
-
-    final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
-    final Element element =
-        requestMessage.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-            XmlNetconfConstants.RPC_REPLY_KEY);
-    element.setAttribute("xmlns:ns1", getOperationNamespace());
-    element.setAttribute("message-id", msgId);
-
-    String requestXml = XmlUtility.convertDocumentToString(requestElement);
-    logger.debug("reboot rpc requestXml= {}", requestXml);
-
-
-    NetConfServerProperties config =
-        NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
-
-    final String baseUrl = config.getMapperPath() + "/reboot";
-    NetConfResponse restResponse =
-        XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
-    Document respDoc = null;
-
-    ErrorCodeDetails errorCode = restResponse.getErrorCode();
-    if (errorCode != null && errorCode.getFaultCode() != null
-        && !errorCode.getFaultCode().equalsIgnoreCase("0")) {
-      logger.error("Error recevied : {}", errorCode);
-      throw new DocumentedException(errorCode.getErrorMessage(),
-          ErrorType.from(errorCode.getErrorType()), ErrorTag.from(errorCode.getErrorTag()),
-          ErrorSeverity.from(errorCode.getErrorSeverity()));
-    } else {
-      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-      factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
-      factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
-      DocumentBuilder builder;
-      try {
-        Node child = requestMessage.createElement(XmlNetconfConstants.OK);
-        element.appendChild(child);
-        String xmlStr = XmlUtility.convertDocumentToString(element);
-        try {
-          builder = factory.newDocumentBuilder();
-          respDoc = builder.parse(new InputSource(new StringReader(xmlStr)));
-        } catch (Exception e) {
-          logger.error("Error while converting String to element: {}", e.getMessage());
-          throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
-              ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
-        }
-      } catch (Exception e) {
-        logger.error("Error while contruscting the response: {}", e.getMessage());
-        throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
-            ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
-      }
-    }
-
-    return respDoc;
-  }
-
-  protected HandlingPriority canHandle(final String operationName,
-      final String operationNamespace) {
-    return operationName.equals(getOperationName())
-        && operationNamespace.equals(getOperationNamespace())
-            ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
-            : HandlingPriority.CANNOT_HANDLE;
-  }
-
-  public static final class OperationNameAndNamespace {
-    private final String operationName;
-    private final String namespace;
-
-    private final XmlElement operationElement;
-
-    public OperationNameAndNamespace(final Document message) throws DocumentedException {
-      XmlElement requestElement = null;
-      requestElement = getRequestElementWithCheck(message);
-      operationElement = requestElement.getOnlyChildElement();
-      operationName = operationElement.getName();
-      namespace = operationElement.getNamespace();
-    }
-
-    public String getOperationName() {
-      return operationName;
-    }
-
-    public String getNamespace() {
-      return namespace;
-    }
-
-    public XmlElement getOperationElement() {
-      return operationElement;
-    }
-
-  }
-
-  protected static XmlElement getRequestElementWithCheck(final Document message)
-      throws DocumentedException {
-    return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
-        XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
-  }
-
-  protected String getOperationNamespace() {
-    return OP_NAMESPACE;
-  }
-
-  protected String getOperationName() {
-    return OP_NAME;
-  }
 
 }
index 05e30c5..a1b7c32 100644 (file)
 
 package org.commscope.tr069adapter.netconf.rpc;
 
-import java.io.StringReader;
-
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.commscope.tr069adapter.mapper.model.ErrorCodeDetails;
-import org.commscope.tr069adapter.mapper.model.NetConfResponse;
-import org.commscope.tr069adapter.netconf.boot.NetConfServiceBooter;
-import org.commscope.tr069adapter.netconf.config.NetConfServerProperties;
-import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
-import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
-import org.opendaylight.netconf.api.DocumentedException.ErrorType;
-import org.opendaylight.netconf.api.xml.XmlElement;
-import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
-import org.opendaylight.netconf.mapping.api.HandlingPriority;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
-import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-
-public class ResetOperation implements NetconfOperation {
-  private static final Logger logger = LoggerFactory.getLogger(ResetOperation.class);
-  public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
-  public static final String OP_NAME = "reset";
-
-  private String deviceID;
-  private String swVersion;
-  private String hwVersion;
+public class ResetOperation extends GenericOperation {
 
   public ResetOperation(String deviceID, String swVersion, String hwVersion) {
     this.deviceID = deviceID;
     this.swVersion = swVersion;
     this.hwVersion = hwVersion;
+    setOpString("reset");
+    setOpNamespace("urn:tr069rpc:1.0");
+    setOpName("reset");
   }
-
-  @Override
-  public HandlingPriority canHandle(final Document message) throws DocumentedException {
-    OperationNameAndNamespace operationNameAndNamespace = null;
-    operationNameAndNamespace = new OperationNameAndNamespace(message);
-    return canHandle(operationNameAndNamespace.getOperationName(),
-        operationNameAndNamespace.getNamespace());
-  }
-
-  @Override
-  public Document handle(Document requestMessage,
-      NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
-    logger.debug("Reset rpc is received in netconfserver");
-
-    final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
-
-    final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
-    final Element element =
-        requestMessage.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-            XmlNetconfConstants.RPC_REPLY_KEY);
-    element.setAttribute("xmlns:ns1", getOperationNamespace());
-    element.setAttribute("message-id", msgId);
-
-    String requestXml = XmlUtility.convertDocumentToString(requestElement);
-    logger.debug("reset rpc requestXml= {}", requestXml);
-
-    NetConfServerProperties config =
-        NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
-
-    final String baseUrl = config.getMapperPath() + "/reset";
-    NetConfResponse restResponse =
-        XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
-    Document respDoc = null;
-
-    ErrorCodeDetails errorCode = restResponse.getErrorCode();
-    if (errorCode != null && errorCode.getFaultCode() != null
-        && !errorCode.getFaultCode().equalsIgnoreCase("0")) {
-      logger.error("Error recevied : {}", errorCode);
-      throw new DocumentedException(errorCode.getErrorMessage(),
-          ErrorType.from(errorCode.getErrorType()), ErrorTag.from(errorCode.getErrorTag()),
-          ErrorSeverity.from(errorCode.getErrorSeverity()));
-    } else {
-      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-      factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
-      factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
-      DocumentBuilder builder;
-      try {
-        Node child = requestMessage.createElement(XmlNetconfConstants.OK);
-        element.appendChild(child);
-        String xmlStr = XmlUtility.convertDocumentToString(element);
-        try {
-          builder = factory.newDocumentBuilder();
-          respDoc = builder.parse(new InputSource(new StringReader(xmlStr)));
-        } catch (Exception e) {
-          logger.error("Error while converting String to element: {}", e.getMessage());
-          throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
-              ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
-        }
-      } catch (Exception e) {
-        logger.error("Error while contruscting the response: {}", e.getMessage());
-        throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
-            ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
-      }
-    }
-
-    return respDoc;
-  }
-
-  protected HandlingPriority canHandle(final String operationName,
-      final String operationNamespace) {
-    return operationName.equals(getOperationName())
-        && operationNamespace.equals(getOperationNamespace())
-            ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
-            : HandlingPriority.CANNOT_HANDLE;
-  }
-
-  public static final class OperationNameAndNamespace {
-    private final String operationName;
-    private final String namespace;
-
-    private final XmlElement operationElement;
-
-    public OperationNameAndNamespace(final Document message) throws DocumentedException {
-      XmlElement requestElement = null;
-      requestElement = getRequestElementWithCheck(message);
-      operationElement = requestElement.getOnlyChildElement();
-      operationName = operationElement.getName();
-      namespace = operationElement.getNamespace();
-    }
-
-    public String getOperationName() {
-      return operationName;
-    }
-
-    public String getNamespace() {
-      return namespace;
-    }
-
-    public XmlElement getOperationElement() {
-      return operationElement;
-    }
-
-  }
-
-  protected static XmlElement getRequestElementWithCheck(final Document message)
-      throws DocumentedException {
-    return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
-        XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
-  }
-
-  protected String getOperationNamespace() {
-    return OP_NAMESPACE;
-  }
-
-  protected String getOperationName() {
-    return OP_NAME;
-  }
-
 }
index c614d7f..bbba531 100644 (file)
 
 package org.commscope.tr069adapter.netconf.rpc;
 
-import java.io.StringReader;
-
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.commscope.tr069adapter.mapper.model.ErrorCodeDetails;
-import org.commscope.tr069adapter.mapper.model.NetConfResponse;
-import org.commscope.tr069adapter.netconf.boot.NetConfServiceBooter;
-import org.commscope.tr069adapter.netconf.config.NetConfServerProperties;
-import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
-import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
-import org.opendaylight.netconf.api.DocumentedException.ErrorType;
-import org.opendaylight.netconf.api.xml.XmlElement;
-import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
-import org.opendaylight.netconf.mapping.api.HandlingPriority;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
-import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-
-public class SPAObjectOperation implements NetconfOperation {
-  private static final Logger logger = LoggerFactory.getLogger(SPAObjectOperation.class);
-  public static final String OP_NAMESPACE = "urn:tr069rpc:1.0";
-  public static final String OP_NAME = "set-parameter-attributes";
-
-  private String deviceID;
-  private String swVersion;
-  private String hwVersion;
+public class SPAObjectOperation extends GenericOperation {
 
   public SPAObjectOperation(String deviceID, String swVersion, String hwVersion) {
     this.deviceID = deviceID;
     this.swVersion = swVersion;
     this.hwVersion = hwVersion;
+    setOpString("spaobject");
+    setOpNamespace("urn:tr069rpc:1.0");
+    setOpName("set-parameter-attributes");
   }
-
-  @Override
-  public HandlingPriority canHandle(final Document message) throws DocumentedException {
-    OperationNameAndNamespace operationNameAndNamespace = null;
-    operationNameAndNamespace = new OperationNameAndNamespace(message);
-    return canHandle(operationNameAndNamespace.getOperationName(),
-        operationNameAndNamespace.getNamespace());
-  }
-
-  @Override
-  public Document handle(Document requestMessage,
-      NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
-    logger.debug("spaObject rpc is received in netconfserver");
-
-    final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
-
-    final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
-    final Element element =
-        requestMessage.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-            XmlNetconfConstants.RPC_REPLY_KEY);
-    element.setAttribute("xmlns:ns1", getOperationNamespace());
-    element.setAttribute("message-id", msgId);
-
-    String requestXml = XmlUtility.convertDocumentToString(requestElement);
-    logger.debug("spaObject rpc requestXml= {}", requestXml);
-
-
-    NetConfServerProperties config =
-        NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
-
-    final String baseUrl = config.getMapperPath() + "/spaobject";
-    NetConfResponse restResponse =
-        XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
-    Document document = null;
-
-    ErrorCodeDetails errorCode = restResponse.getErrorCode();
-    if (errorCode != null && errorCode.getFaultCode() != null
-        && !errorCode.getFaultCode().equalsIgnoreCase("0")) {
-      logger.error("Error recevied : {}", errorCode);
-      throw new DocumentedException(errorCode.getErrorMessage(),
-          ErrorType.from(errorCode.getErrorType()), ErrorTag.from(errorCode.getErrorTag()),
-          ErrorSeverity.from(errorCode.getErrorSeverity()));
-    } else if (restResponse.getNetconfResponseXml() != null) {
-      logger.debug("spaobject rpc response received from mapper: {}",
-          restResponse.getNetconfResponseXml());
-      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-      factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
-      factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
-      DocumentBuilder builder;
-      try {
-        Node child = requestMessage.createElement(XmlNetconfConstants.OK);
-        element.appendChild(child);
-        String xmlStr = XmlUtility.convertDocumentToString(element);
-        try {
-          builder = factory.newDocumentBuilder();
-          document = builder.parse(new InputSource(new StringReader(xmlStr)));
-        } catch (Exception e) {
-          logger.error("Error while converting String to element: {}", e.getMessage());
-          throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
-              ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
-        }
-      } catch (Exception e) {
-        logger.error("Error while contruscting the response: {}", e.getMessage());
-        throw new DocumentedException("Operation Aborted", ErrorType.from("application"),
-            ErrorTag.from("operation-failed"), ErrorSeverity.from("ERROR"));
-      }
-    }
-
-    return document;
-  }
-
-  protected HandlingPriority canHandle(final String operationName,
-      final String operationNamespace) {
-    return operationName.equals(getOperationName())
-        && operationNamespace.equals(getOperationNamespace())
-            ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
-            : HandlingPriority.CANNOT_HANDLE;
-  }
-
-  public static final class OperationNameAndNamespace {
-    private final String operationName;
-    private final String namespace;
-
-    private final XmlElement operationElement;
-
-    public OperationNameAndNamespace(final Document message) throws DocumentedException {
-      XmlElement requestElement = null;
-      requestElement = getRequestElementWithCheck(message);
-      operationElement = requestElement.getOnlyChildElement();
-      operationName = operationElement.getName();
-      namespace = operationElement.getNamespace();
-    }
-
-    public String getOperationName() {
-      return operationName;
-    }
-
-    public String getNamespace() {
-      return namespace;
-    }
-
-    public XmlElement getOperationElement() {
-      return operationElement;
-    }
-
-  }
-
-  protected static XmlElement getRequestElementWithCheck(final Document message)
-      throws DocumentedException {
-    return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
-        XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
-  }
-
-  protected String getOperationNamespace() {
-    return OP_NAMESPACE;
-  }
-
-  protected String getOperationName() {
-    return OP_NAME;
-  }
-
 }
index a78e5fa..d888038 100644 (file)
@@ -20,41 +20,27 @@ package org.commscope.tr069adapter.netconf.rpc;
 
 import org.commscope.tr069adapter.netconf.boot.NetConfServiceBooter;
 import org.commscope.tr069adapter.netconf.config.NetConfServerProperties;
-import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
-import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
-import org.opendaylight.netconf.mapping.api.HandlingPriority;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 
-public class SoftwareActivateOperation implements NetconfOperation {
+public class SoftwareActivateOperation extends GenericOperation {
   private static final Logger logger = LoggerFactory.getLogger(SoftwareActivateOperation.class);
-  public static final String SOFT_MGMT_NAMESPACE = "urn:o-ran:software-management:1.0";
-
-  private String deviceID;
-  private String swVersion;
-  private String hwVersion;
 
   public SoftwareActivateOperation(String deviceID, String swVersion, String hwVersion) {
     this.deviceID = deviceID;
     this.swVersion = swVersion;
     this.hwVersion = hwVersion;
-  }
-
-  @Override
-  public HandlingPriority canHandle(final Document message) throws DocumentedException {
-    OperationNameAndNamespace operationNameAndNamespace = null;
-    operationNameAndNamespace = new OperationNameAndNamespace(message);
-    return canHandle(operationNameAndNamespace.getOperationName(),
-        operationNameAndNamespace.getNamespace());
+    setOpString("softwareActivate");
+    setOpName("software-activate");
+    setOpNamespace("urn:o-ran:software-management:1.0");
   }
 
   @Override
   public Document handle(Document requestMessage,
-      NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
+      NetconfOperationChainedExecution subsequentOperation) {
 
     logger.debug("sw-activate rpc recevied in netconf server");
     final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
@@ -64,49 +50,8 @@ public class SoftwareActivateOperation implements NetconfOperation {
     NetConfServerProperties config =
         NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);
 
-    final String baseUrl = config.getMapperPath() + "/softwareActivate";
+    final String baseUrl = config.getMapperPath() + "/" + getOpString();
     XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID, swVersion, hwVersion);
     return null;
   }
-
-  protected HandlingPriority canHandle(final String operationName,
-      final String operationNamespace) {
-    return operationName.equals("software-activate")
-        && operationNamespace.equals(SOFT_MGMT_NAMESPACE)
-            ? HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1100)
-            : HandlingPriority.CANNOT_HANDLE;
-  }
-
-  public static final class OperationNameAndNamespace {
-    private final String operationName;
-    private final String namespace;
-
-    private final XmlElement operationElement;
-
-    public OperationNameAndNamespace(final Document message) throws DocumentedException {
-      XmlElement requestElement = null;
-      requestElement = getRequestElementWithCheck(message);
-      operationElement = requestElement.getOnlyChildElement();
-      operationName = operationElement.getName();
-      namespace = operationElement.getNamespace();
-    }
-
-    public String getOperationName() {
-      return operationName;
-    }
-
-    public String getNamespace() {
-      return namespace;
-    }
-
-    public XmlElement getOperationElement() {
-      return operationElement;
-    }
-  }
-
-  protected static XmlElement getRequestElementWithCheck(final Document message)
-      throws DocumentedException {
-    return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
-        XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
-  }
 }
index b1c7460..02c6800 100644 (file)
@@ -82,6 +82,10 @@ public class NetConfServerManagerImpl {
 
   ExecutorService executorService = Executors.newFixedThreadPool(10);
 
+  private static final String ENODEBNAME = "enodeBName";
+
+  private static final String FAIL_DEVICE_UNREGISTER = "Failed to unregister the device ";
+  
   public boolean loadSchemas() {
     LOG.debug("Loading yang schema started");
     List<ProfileDefinition> profiles = versionManager.getSupportedProfileDefinitions();
@@ -100,11 +104,7 @@ public class NetConfServerManagerImpl {
           return false;
         }
 
-        try {
-          FileUtils.copyDirectory(schemaDir, schemaVerDir);
-        } catch (IOException e) {
-          LOG.error("Failed to copy directory {} ", e.getMessage());
-        }
+        copyDir(schemaDir, schemaVerDir);
         boolean isSchemaLoaded = ncServerStarter.loadSchemas(schemaVerDir);
         if (!isSchemaLoaded) {
           LOG.debug("Failed to load schema for profile {}", profile.getProfileId());
@@ -119,6 +119,14 @@ public class NetConfServerManagerImpl {
     return true;
   }
 
+private void copyDir(File schemaDir, File schemaVerDir) {
+    try {
+      FileUtils.copyDirectory(schemaDir, schemaVerDir);
+    } catch (IOException e) {
+      LOG.error("Failed to copy directory {} ", e.getMessage());
+    }
+  }
+  
   public void restartServers() {
     LOG.debug("Restarting all netconf servers during startup...");
     Iterable<NetConfServerDetailsEntity> entities = netconfDAO.findAll();
@@ -324,12 +332,13 @@ public class NetConfServerManagerImpl {
     } else {
       LOG.error(
           "Both deviceID and enodeBName are null. Hence failed to unregister the netconf server.");
-      resultMsg = "Failed to unregister the device " + deviceId + ", enodeBName=" + enodeBName
-          + ". Invalid deviceId/enodeBName specified.";
+      resultMsg = FAIL_DEVICE_UNREGISTER + deviceId + ", " + ENODEBNAME + "=" + enodeBName
+              + ". Invalid deviceId/enodeBName specified.";
+      LOG.info(resultMsg);
     }
     if (entity == null) {
-      resultMsg = "Failed to unregister the device " + deviceId + ", enodeBName=" + enodeBName
-          + ". Invalid deviceId/enodeBName specified.";
+      resultMsg = FAIL_DEVICE_UNREGISTER + deviceId + ", " + ENODEBNAME + "=" + enodeBName
+              + ". Invalid deviceId/enodeBName specified.";
       LOG.info(resultMsg);
       return resultMsg;
     }
@@ -342,7 +351,7 @@ public class NetConfServerManagerImpl {
       LOG.info(resultMsg);
       delteHeartBeatTimer(deviceId);
     } else {
-      resultMsg = "Failed to unregister the device " + deviceId + ", enodeBName=" + enodeBName;
+      resultMsg = FAIL_DEVICE_UNREGISTER + deviceId + ", " + ENODEBNAME + "=" + enodeBName;
       LOG.error(resultMsg);
     }
 
index 2a30b7d..aac9bba 100644 (file)
@@ -97,14 +97,7 @@ public class VesAgentServiceHelper {
                 .equalsIgnoreCase(VesAgentConstants.REMOVE_HEART_BEAT_TIMER_VAL))) {
       return false;
     }
-    if (null != countDownTimer
-        && !countDownTimer.equalsIgnoreCase(VesAgentConstants.COUNT_DOWN_TIMER_ZERO)) {
-      if (null == heartBeatPeriod || heartBeatPeriod.equalsIgnoreCase(existingHeartBeatPeriod)) {
-        String exceptionReason = "Can't change timer value if heartbeat value is same";
-        throw new VesAgentException(VesAgentConstants.INVALID_PARAMETER_VALUE, exceptionReason);
-      }
-
-    }
+    validateTimers(heartBeatPeriod, countDownTimer, existingHeartBeatPeriod);
 
     if (!VesAgentUtils.isNullOrEmpty(heartBeatPeriod)) {
       attrJsonMap.put(VesAgentConstants.HEART_BEAT_PERIOD, heartBeatPeriod);
@@ -117,6 +110,23 @@ public class VesAgentServiceHelper {
     return true;
   }
 
+  private void validateTimers(String heartBeatPeriod, String countDownTimer,
+      String existingHeartBeatPeriod) throws VesAgentException {
+    if (null != countDownTimer
+        && !countDownTimer.equalsIgnoreCase(VesAgentConstants.COUNT_DOWN_TIMER_ZERO)) {
+      validateHeartBeatPeriod(heartBeatPeriod, existingHeartBeatPeriod);
+
+    }
+  }
+
+  private void validateHeartBeatPeriod(String heartBeatPeriod, String existingHeartBeatPeriod)
+      throws VesAgentException {
+    if (null == heartBeatPeriod || heartBeatPeriod.equalsIgnoreCase(existingHeartBeatPeriod)) {
+      String exceptionReason = "Can't change timer value if heartbeat value is same";
+      throw new VesAgentException(VesAgentConstants.INVALID_PARAMETER_VALUE, exceptionReason);
+    }
+  }
+
   public void processHeartBeatSetRequest(DeviceRPCRequest deviceRPCRequest, String heartBeatPeriod,
       String countDownTimer) throws VesAgentException {