Initial source code
[oam/tr069-adapter.git] / mapper / src / main / java / org / commscope / tr069adapter / mapper / ves / VESNotificationSender.java
diff --git a/mapper/src/main/java/org/commscope/tr069adapter/mapper/ves/VESNotificationSender.java b/mapper/src/main/java/org/commscope/tr069adapter/mapper/ves/VESNotificationSender.java
new file mode 100644 (file)
index 0000000..6ced95d
--- /dev/null
@@ -0,0 +1,72 @@
+/*\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.mapper.ves;\r
+\r
+import org.commscope.tr069adapter.acs.common.DeviceInform;\r
+import org.commscope.tr069adapter.mapper.MapperConfigProperties;\r
+import org.commscope.tr069adapter.mapper.acs.impl.PnPPreProvisioningHandler;\r
+import org.commscope.tr069adapter.mapper.model.NetConfServerDetails;\r
+import org.commscope.tr069adapter.mapper.model.VESNotification;\r
+import org.commscope.tr069adapter.mapper.model.VESNotificationResponse;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.stereotype.Component;\r
+import org.springframework.web.client.RestTemplate;\r
+\r
+@Component\r
+public class VESNotificationSender {\r
+\r
+  private static final Logger LOG = LoggerFactory.getLogger(VESNotificationSender.class);\r
+\r
+  @Autowired\r
+  MapperConfigProperties config;\r
+\r
+  @Autowired\r
+  PnPPreProvisioningHandler pnpPreProvisioningHandler;\r
+\r
+  @Autowired\r
+  VESNotificationSender vesnotiSender;\r
+\r
+  @Autowired\r
+  RestTemplate restTemplate;\r
+\r
+  public VESNotificationResponse sendNotification(DeviceInform deviceInform,\r
+      NetConfServerDetails serverInfo) {\r
+    final String uri = getUri();\r
+    LOG.debug("Posting ves event to ves notifier {}", uri);\r
+\r
+    VESNotification vesNotifi = new VESNotification();\r
+    if (deviceInform != null) {\r
+      vesNotifi.seteNodeBName(\r
+          pnpPreProvisioningHandler.getEnodeBName(deviceInform.getDeviceDetails().getDeviceId()));\r
+    } else {\r
+      vesNotifi.seteNodeBName(serverInfo.getEnodeBName());\r
+    }\r
+    vesNotifi.setNetconfDetails(serverInfo);\r
+    vesNotifi.setDevnotification(deviceInform);\r
+\r
+    return restTemplate.postForObject(uri, vesNotifi, VESNotificationResponse.class);\r
+  }\r
+\r
+  private String getUri() {\r
+    return config.getVesUri();\r
+  }\r
+\r
+}\r