Initial source code
[oam/tr069-adapter.git] / acs / cpe / src / main / java / org / commscope / tr069adapter / acs / cpe / handler / ConnectionReqEventHandler.java
diff --git a/acs/cpe/src/main/java/org/commscope/tr069adapter/acs/cpe/handler/ConnectionReqEventHandler.java b/acs/cpe/src/main/java/org/commscope/tr069adapter/acs/cpe/handler/ConnectionReqEventHandler.java
new file mode 100644 (file)
index 0000000..c8e76f7
--- /dev/null
@@ -0,0 +1,69 @@
+/*\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
+\r
+package org.commscope.tr069adapter.acs.cpe.handler;\r
+\r
+import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CR_REQ_CF;\r
+import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CR_REQ_Q;\r
+\r
+import java.io.IOException;\r
+\r
+import org.commscope.tr069adapter.acs.common.dto.TR069DeviceDetails;\r
+import org.commscope.tr069adapter.acs.common.exception.SessionManagerException;\r
+import org.commscope.tr069adapter.acs.cpe.processor.ConnectionReqEventProcessor;\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.annotation.JmsListener;\r
+import org.springframework.stereotype.Component;\r
+import org.springframework.transaction.annotation.Transactional;\r
+\r
+@Component\r
+public class ConnectionReqEventHandler {\r
+\r
+  private static final Logger logger = LoggerFactory.getLogger(ConnectionReqEventHandler.class);\r
+\r
+  private static final String CLIENT_STR = "client";\r
+\r
+  @Autowired\r
+  private ConnectionReqEventProcessor connectionReqEventProcessor;\r
+\r
+  @JmsListener(destination = CR_REQ_Q, containerFactory = CR_REQ_CF)\r
+  @Transactional(rollbackFor = Exception.class)\r
+  public void onMessage(TR069DeviceDetails tr069DeviceDetails) {\r
+    try {\r
+      if (tr069DeviceDetails != null) {\r
+        MDC.put(CLIENT_STR, tr069DeviceDetails.getDeviceId());\r
+        logger.info(\r
+            "Received a JMS message from Request Processor for initiating connection request");\r
+        connectionReqEventProcessor.initiateConnectionRequest(tr069DeviceDetails, false);\r
+        logger.debug("Sent TR069 connection request to device");\r
+      } else {\r
+        logger.warn(\r
+            "Received a JMS message for initiating connection request with no device details, "\r
+                + "hence could not initiate connection request");\r
+      }\r
+    } catch (SessionManagerException | IOException e) {\r
+      logger.error(e.getMessage());\r
+    } finally {\r
+      MDC.remove(CLIENT_STR);\r
+    }\r
+  }\r
+}\r