634f9df105dcae18b4ed5d407a440ab005ae3336
[oam/tr069-adapter.git] / acs / requestprocessor / src / main / java / org / commscope / tr069adapter / acs / requestprocessor / impl / TR069EventNotificationService.java
1 /*\r
2  * ============LICENSE_START========================================================================\r
3  * ONAP : tr-069-adapter\r
4  * =================================================================================================\r
5  * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
6  * =================================================================================================\r
7  * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
8  * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
9  * may obtain a copy of the License at\r
10  *\r
11  * http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
14  * either express or implied. See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  * ===============LICENSE_END=======================================================================\r
17  */\r
18 \r
19 package org.commscope.tr069adapter.acs.requestprocessor.impl;\r
20 \r
21 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.NBI_NOTIFICATION_Q;\r
22 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.NBI_OP_RESULT_Q;\r
23 \r
24 import org.commscope.tr069adapter.acs.common.DeviceInform;\r
25 import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;\r
26 import org.commscope.tr069adapter.acs.common.dto.CustomOperationCode;\r
27 import org.commscope.tr069adapter.acs.common.dto.TR069InformType;\r
28 import org.commscope.tr069adapter.acs.common.dto.TR069OperationCode;\r
29 import org.slf4j.Logger;\r
30 import org.slf4j.LoggerFactory;\r
31 import org.slf4j.MDC;\r
32 import org.springframework.beans.factory.annotation.Autowired;\r
33 import org.springframework.jms.core.JmsTemplate;\r
34 import org.springframework.stereotype.Component;\r
35 \r
36 @Component\r
37 public class TR069EventNotificationService {\r
38 \r
39   private static final Logger logger = LoggerFactory.getLogger(TR069EventNotificationService.class);\r
40 \r
41   private static final String CLIENT_STR = "client";\r
42 \r
43   @Autowired\r
44   private JmsTemplate jmsTemplate;\r
45 \r
46   /**\r
47    * @param deviceNotification\r
48    */\r
49   public void sendDeviceInformToNBI(DeviceInform deviceNotification) {\r
50     String deviceId = deviceNotification.getDeviceDetails().getDeviceId();\r
51     try {\r
52       MDC.put(CLIENT_STR, deviceId);\r
53       TR069InformType notificationType = (TR069InformType) deviceNotification.getInformType();\r
54 \r
55       logger.debug("Device Inform Event received: '{}'", notificationType.getNotificationCode());\r
56       jmsTemplate.convertAndSend(NBI_NOTIFICATION_Q, deviceNotification);\r
57       logger.debug("Successfully posted the device inform event to DM to forward to NBI");\r
58     } catch (Exception e) {\r
59       logger.error("Posting Device Inform event to mapper failed, Reason: {}", e.getMessage());\r
60     } finally {\r
61       MDC.remove(CLIENT_STR);\r
62     }\r
63   }\r
64 \r
65   /**\r
66    * @param deviceRPCResponse\r
67    */\r
68   public void sendOperationResultToNBI(DeviceRPCResponse deviceRPCResponse) {\r
69     String deviceId = deviceRPCResponse.getDeviceDetails().getDeviceId();\r
70     try {\r
71       MDC.put(CLIENT_STR, deviceId);\r
72       if (deviceRPCResponse.getOperationResponse()\r
73           .getOperationCode() instanceof TR069OperationCode) {\r
74         TR069OperationCode operCode =\r
75             (TR069OperationCode) deviceRPCResponse.getOperationResponse().getOperationCode();\r
76         logger.debug("Device RPC Response received for operation: '" + operCode.name()\r
77             + "' with operation ID:" + deviceRPCResponse.getOperationId());\r
78       } else if (deviceRPCResponse.getOperationResponse()\r
79           .getOperationCode() instanceof CustomOperationCode) {\r
80         CustomOperationCode operCode =\r
81             (CustomOperationCode) deviceRPCResponse.getOperationResponse().getOperationCode();\r
82         logger.debug("Device RPC Response received for operation: '" + operCode.getJndiName()\r
83             + "' with operation ID:" + deviceRPCResponse.getOperationId());\r
84       }\r
85       jmsTemplate.convertAndSend(NBI_OP_RESULT_Q, deviceRPCResponse);\r
86       logger.debug("Successfully posted the operation result event to DM to forward to NBI");\r
87     } catch (Exception e) {\r
88       logger.error("Posting Device RPC response event to mapper failed, Reason: {}",\r
89           e.getMessage());\r
90     } finally {\r
91       MDC.remove(CLIENT_STR);\r
92     }\r
93   }\r
94 \r
95 }\r