Initial source code
[oam/tr069-adapter.git] / acs / nbi / src / main / java / org / commscope / tr069adapter / acs / nbi / mapper / service / DeviceEventsMapperNotificationService.java
diff --git a/acs/nbi/src/main/java/org/commscope/tr069adapter/acs/nbi/mapper/service/DeviceEventsMapperNotificationService.java b/acs/nbi/src/main/java/org/commscope/tr069adapter/acs/nbi/mapper/service/DeviceEventsMapperNotificationService.java
new file mode 100644 (file)
index 0000000..7c53e7d
--- /dev/null
@@ -0,0 +1,75 @@
+/*\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.mapper.service;\r
+\r
+import org.commscope.tr069adapter.acs.common.DeviceInform;\r
+import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;\r
+import org.commscope.tr069adapter.acs.nbi.util.MapperSrvcDependencyConfig;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.http.ResponseEntity;\r
+import org.springframework.stereotype.Component;\r
+import org.springframework.web.client.RestTemplate;\r
+\r
+@Component\r
+public class DeviceEventsMapperNotificationService {\r
+\r
+  private static final Logger logger =\r
+      LoggerFactory.getLogger(DeviceEventsMapperNotificationService.class);\r
+\r
+  @Autowired\r
+  RestTemplate restTemplate;\r
+\r
+  @Autowired\r
+  MapperSrvcDependencyConfig mapperSrvcDependencyConfig;\r
+\r
+  public void processOperationResponse(DeviceRPCResponse opResult) {\r
+    logger.debug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++");\r
+    logger.debug("Received Operation result from NBI");\r
+    logger.debug("Posting the operation request to WebService: {}",\r
+        mapperSrvcDependencyConfig.getMapperDeviceRPCResponseNotificationServiceURL());\r
+    try {\r
+      restTemplate.postForEntity(\r
+          mapperSrvcDependencyConfig.getMapperDeviceRPCResponseNotificationServiceURL(), opResult,\r
+          ResponseEntity.class);\r
+      logger.debug("Successfully posted the NBI operation request to SBI Service");\r
+    } catch (Exception e) {\r
+      logger.error("Unable to post the operation result, Reason: {}", e.getMessage());\r
+    }\r
+    logger.debug("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");\r
+\r
+  }\r
+\r
+  public void processDeviceNotification(DeviceInform notification) {\r
+    logger.debug("++++++++++++++++++++++++++++++++++++++++++++++++++++++");\r
+    logger.debug("Received Notification from NBI");\r
+    logger.debug("Posting the Device Notification to WebService: {}",\r
+        mapperSrvcDependencyConfig.getMapperInformNotificationServiceURL());\r
+    try {\r
+      restTemplate.postForEntity(mapperSrvcDependencyConfig.getMapperInformNotificationServiceURL(),\r
+          notification, ResponseEntity.class);\r
+      logger.debug("Successfully posted the Device Notification to SBI Service");\r
+    } catch (Exception e) {\r
+      logger.error("Unable to post the Device Notification, Reason: {}", e.getMessage());\r
+    }\r
+    logger.debug("+++++++++++++++++++++++++++++++++++++++++++++++++++++");\r
+  }\r
+\r
+}\r