Initial source code
[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.TR069InformType;\r
27 import org.commscope.tr069adapter.acs.common.dto.TR069OperationCode;\r
28 import org.slf4j.Logger;\r
29 import org.slf4j.LoggerFactory;\r
30 import org.slf4j.MDC;\r
31 import org.springframework.beans.factory.annotation.Autowired;\r
32 import org.springframework.jms.core.JmsTemplate;\r
33 import org.springframework.stereotype.Component;\r
34 \r
35 @Component\r
36 public class TR069EventNotificationService {\r
37 \r
38   private static final Logger logger = LoggerFactory.getLogger(TR069EventNotificationService.class);\r
39 \r
40   private static final String CLIENT_STR = "client";\r
41 \r
42   @Autowired\r
43   private JmsTemplate jmsTemplate;\r
44 \r
45   /**\r
46    * @param deviceNotification\r
47    */\r
48   public void sendDeviceInformToNBI(DeviceInform deviceNotification) {\r
49     String deviceId = deviceNotification.getDeviceDetails().getDeviceId();\r
50     try {\r
51       MDC.put(CLIENT_STR, deviceId);\r
52       TR069InformType notificationType = (TR069InformType) deviceNotification.getInformType();\r
53 \r
54       logger.debug("Device Inform Event received: '{}'", notificationType.getNotificationCode());\r
55       jmsTemplate.convertAndSend(NBI_NOTIFICATION_Q, deviceNotification);\r
56       logger.debug("Successfully posted the device inform event to DM to forward to NBI");\r
57     } catch (Exception e) {\r
58       logger.error("Posting Device Inform event to mapper failed, Reason: {}", e.getMessage());\r
59     } finally {\r
60       MDC.remove(CLIENT_STR);\r
61     }\r
62   }\r
63 \r
64   /**\r
65    * @param deviceRPCResponse\r
66    */\r
67   public void sendOperationResultToNBI(DeviceRPCResponse deviceRPCResponse) {\r
68     String deviceId = deviceRPCResponse.getDeviceDetails().getDeviceId();\r
69     try {\r
70       MDC.put(CLIENT_STR, deviceId);\r
71       TR069OperationCode operCode =\r
72           (TR069OperationCode) deviceRPCResponse.getOperationResponse().getOperationCode();\r
73       String opCodeName = operCode.name();\r
74       logger.debug("Device RPC Response received for operation: '{}' with operation ID: {}",\r
75           opCodeName, deviceRPCResponse.getOperationId());\r
76       jmsTemplate.convertAndSend(NBI_OP_RESULT_Q, deviceRPCResponse);\r
77       logger.debug("Successfully posted the operation result event to DM to forward to NBI");\r
78     } catch (Exception e) {\r
79       logger.error("Posting Device RPC response event to mapper failed, Reason: {}",\r
80           e.getMessage());\r
81     } finally {\r
82       MDC.remove(CLIENT_STR);\r
83     }\r
84   }\r
85 \r
86 }\r