Initial source code
[oam/tr069-adapter.git] / acs / requestprocessor / src / main / java / org / commscope / tr069adapter / acs / requestprocessor / impl / TR069EventNotificationService.java
diff --git a/acs/requestprocessor/src/main/java/org/commscope/tr069adapter/acs/requestprocessor/impl/TR069EventNotificationService.java b/acs/requestprocessor/src/main/java/org/commscope/tr069adapter/acs/requestprocessor/impl/TR069EventNotificationService.java
new file mode 100644 (file)
index 0000000..b6025f0
--- /dev/null
@@ -0,0 +1,86 @@
+/*\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.requestprocessor.impl;\r
+\r
+import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.NBI_NOTIFICATION_Q;\r
+import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.NBI_OP_RESULT_Q;\r
+\r
+import org.commscope.tr069adapter.acs.common.DeviceInform;\r
+import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;\r
+import org.commscope.tr069adapter.acs.common.dto.TR069InformType;\r
+import org.commscope.tr069adapter.acs.common.dto.TR069OperationCode;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.slf4j.MDC;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.jms.core.JmsTemplate;\r
+import org.springframework.stereotype.Component;\r
+\r
+@Component\r
+public class TR069EventNotificationService {\r
+\r
+  private static final Logger logger = LoggerFactory.getLogger(TR069EventNotificationService.class);\r
+\r
+  private static final String CLIENT_STR = "client";\r
+\r
+  @Autowired\r
+  private JmsTemplate jmsTemplate;\r
+\r
+  /**\r
+   * @param deviceNotification\r
+   */\r
+  public void sendDeviceInformToNBI(DeviceInform deviceNotification) {\r
+    String deviceId = deviceNotification.getDeviceDetails().getDeviceId();\r
+    try {\r
+      MDC.put(CLIENT_STR, deviceId);\r
+      TR069InformType notificationType = (TR069InformType) deviceNotification.getInformType();\r
+\r
+      logger.debug("Device Inform Event received: '{}'", notificationType.getNotificationCode());\r
+      jmsTemplate.convertAndSend(NBI_NOTIFICATION_Q, deviceNotification);\r
+      logger.debug("Successfully posted the device inform event to DM to forward to NBI");\r
+    } catch (Exception e) {\r
+      logger.error("Posting Device Inform event to mapper failed, Reason: {}", e.getMessage());\r
+    } finally {\r
+      MDC.remove(CLIENT_STR);\r
+    }\r
+  }\r
+\r
+  /**\r
+   * @param deviceRPCResponse\r
+   */\r
+  public void sendOperationResultToNBI(DeviceRPCResponse deviceRPCResponse) {\r
+    String deviceId = deviceRPCResponse.getDeviceDetails().getDeviceId();\r
+    try {\r
+      MDC.put(CLIENT_STR, deviceId);\r
+      TR069OperationCode operCode =\r
+          (TR069OperationCode) deviceRPCResponse.getOperationResponse().getOperationCode();\r
+      String opCodeName = operCode.name();\r
+      logger.debug("Device RPC Response received for operation: '{}' with operation ID: {}",\r
+          opCodeName, deviceRPCResponse.getOperationId());\r
+      jmsTemplate.convertAndSend(NBI_OP_RESULT_Q, deviceRPCResponse);\r
+      logger.debug("Successfully posted the operation result event to DM to forward to NBI");\r
+    } catch (Exception e) {\r
+      logger.error("Posting Device RPC response event to mapper failed, Reason: {}",\r
+          e.getMessage());\r
+    } finally {\r
+      MDC.remove(CLIENT_STR);\r
+    }\r
+  }\r
+\r
+}\r