Development of NETCONF RPCs for tr-069 adapter to
[oam/tr069-adapter.git] / netconf-server / src / main / java / org / commscope / tr069adapter / netconf / restapi / NetConfServerManagerRestApi.java
index 6057c67..5418a8c 100644 (file)
@@ -1,86 +1,93 @@
-/*\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.netconf.restapi;\r
-\r
-import java.util.List;\r
-\r
-import org.commscope.tr069adapter.mapper.model.NetConfServerDetails;\r
-import org.commscope.tr069adapter.netconf.server.NetConfServerManagerImpl;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.web.bind.annotation.GetMapping;\r
-import org.springframework.web.bind.annotation.PostMapping;\r
-import org.springframework.web.bind.annotation.RequestMapping;\r
-import org.springframework.web.bind.annotation.RequestParam;\r
-import org.springframework.web.bind.annotation.RestController;\r
-\r
-@RestController\r
-@RequestMapping("/netConfServerManagerService")\r
-public class NetConfServerManagerRestApi {\r
-\r
-  private static final Logger LOG = LoggerFactory.getLogger(NetConfServerManagerRestApi.class);\r
-\r
-  @Autowired\r
-  NetConfServerManagerImpl manager;\r
-\r
-  @PostMapping("/createServer")\r
-  public NetConfServerDetails createNetConfServerInstance(@RequestParam String deviceId,\r
-      @RequestParam String enodeBName, @RequestParam String swVersion,\r
-      @RequestParam String hwVersion) {\r
-    LOG.info("Received Create NetConf Server request for deviceID: {}, enodeBName: {}, swversion: {}", deviceId,\r
-        enodeBName, swVersion);\r
-    NetConfServerDetails serverDetails =\r
-        manager.createServer(deviceId, enodeBName, swVersion, hwVersion);\r
-    LOG.info("Successfully processed NetConf Server wit server details : {}", serverDetails);\r
-    return serverDetails;\r
-  }\r
-\r
-  @PostMapping("/restartOnVersionChange")\r
-  public NetConfServerDetails restartOnVersionChange(@RequestParam String deviceId,\r
-      @RequestParam String enodeBName, @RequestParam String swVersion,\r
-      @RequestParam String hwVersion) {\r
-    LOG.info("Received Create NetConf Server request for deviceID: {}, enodeBName: {}", deviceId,\r
-        enodeBName);\r
-    NetConfServerDetails serverDetails =\r
-        manager.restartOnVersionChange(deviceId, enodeBName, swVersion, hwVersion);\r
-    LOG.info("Successfully processed NetConf Server wit server details : {}", serverDetails);\r
-    return serverDetails;\r
-  }\r
-  \r
-  @GetMapping("/listServers")\r
-  public List<NetConfServerDetails> listNetConfServersInfo() {\r
-    LOG.info("Received request to list all NetConf Servers information");\r
-    List<NetConfServerDetails> serverDetails = manager.getServersInfo();\r
-    LOG.info("Successfully processed request to list all NetConf Servers information");\r
-    return serverDetails;\r
-  }\r
-\r
-  @PostMapping("/unregisterServer")\r
-  public String unregisterNetConfServerInstance(@RequestParam String deviceId,\r
-      @RequestParam String enodeBName) {\r
-    LOG.info("Received request for Unregister NetConf Server for deviceID: {}, enodeBName: {} ",\r
-        deviceId, enodeBName);\r
-    String result = manager.unregister(deviceId, enodeBName);\r
-    LOG.info("Unregister request is processed. NetConf Server for deviceID: {} , unregisted= {}",\r
-        deviceId, result);\r
-    return result;\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.netconf.restapi;
+
+import java.util.List;
+
+import org.commscope.tr069adapter.mapper.model.NetConfServerDetails;
+import org.commscope.tr069adapter.netconf.server.NetConfServerManagerImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/netConfServerManagerService")
+public class NetConfServerManagerRestApi {
+
+  private static final Logger LOG = LoggerFactory.getLogger(NetConfServerManagerRestApi.class);
+  public static final String PATTERN = "[\n|\r|\t]";
+
+  @Autowired
+  NetConfServerManagerImpl manager;
+
+  @PostMapping("/createServer")
+  public NetConfServerDetails createNetConfServerInstance(@RequestParam String deviceId,
+      @RequestParam String enodeBName, @RequestParam String swVersion,
+      @RequestParam String hwVersion) {
+         deviceId = deviceId.replaceAll(PATTERN, "_");
+         enodeBName = enodeBName.replaceAll(PATTERN, "_");
+    LOG.info("Received Create NetConf Server request for deviceID: {}, enodeBName: {}, swversion: {}", deviceId,
+        enodeBName, swVersion);
+    NetConfServerDetails serverDetails =
+        manager.createServer(deviceId, enodeBName, swVersion, hwVersion);
+    LOG.info("Successfully processed NetConf Server wit server details : {}", serverDetails);
+    return serverDetails;
+  }
+
+  @PostMapping("/restartOnVersionChange")
+  public NetConfServerDetails restartOnVersionChange(@RequestParam String deviceId,
+      @RequestParam String enodeBName, @RequestParam String swVersion,
+      @RequestParam String hwVersion) {
+         deviceId = deviceId.replaceAll(PATTERN, "_");
+         enodeBName = enodeBName.replaceAll(PATTERN, "_");  
+    LOG.info("Received Create NetConf Server request for deviceID: {}, enodeBName: {}", deviceId,
+        enodeBName);
+    NetConfServerDetails serverDetails =
+        manager.restartOnVersionChange(deviceId, enodeBName, swVersion, hwVersion);
+    LOG.info("Successfully processed NetConf Server wit server details : {}", serverDetails);
+    return serverDetails;
+  }
+  
+  @GetMapping("/listServers")
+  public List<NetConfServerDetails> listNetConfServersInfo() {
+    LOG.info("Received request to list all NetConf Servers information");
+    List<NetConfServerDetails> serverDetails = manager.getServersInfo();
+    LOG.info("Successfully processed request to list all NetConf Servers information");
+    return serverDetails;
+  }
+
+  @PostMapping("/unregisterServer")
+  public String unregisterNetConfServerInstance(@RequestParam String deviceId,
+      @RequestParam String enodeBName) {
+         deviceId = deviceId.replaceAll(PATTERN, "_");
+         enodeBName = enodeBName.replaceAll(PATTERN, "_");  
+    LOG.info("Received request for Unregister NetConf Server for deviceID: {}, enodeBName: {} ",
+        deviceId, enodeBName);
+    String result = manager.unregister(deviceId, enodeBName);
+    LOG.info("Unregister request is processed. NetConf Server for deviceID: {} , unregisted= {}",
+        deviceId, result);
+    return result;
+  }
+
+}