Development of NETCONF RPCs for tr-069 adapter to
[oam/tr069-adapter.git] / mapper / src / main / java / org / commscope / tr069adapter / mapper / acs / impl / ACSNotificationHandlerImpl.java
index 4d39d57..f761c90 100644 (file)
-/*\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.acs.impl;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import org.commscope.tr069adapter.acs.common.DeviceInform;\r
-import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;\r
-import org.commscope.tr069adapter.acs.common.InformType;\r
-import org.commscope.tr069adapter.acs.common.ParameterDTO;\r
-import org.commscope.tr069adapter.acs.common.dto.TR069InformType;\r
-import org.commscope.tr069adapter.acs.common.inform.BootInform;\r
-import org.commscope.tr069adapter.acs.common.inform.BootstrapInform;\r
-import org.commscope.tr069adapter.acs.common.inform.ConnectionRequestInform;\r
-import org.commscope.tr069adapter.acs.common.inform.PeriodicInform;\r
-import org.commscope.tr069adapter.acs.common.inform.TransferCompleteInform;\r
-import org.commscope.tr069adapter.acs.common.inform.ValueChangeInform;\r
-import org.commscope.tr069adapter.mapper.MOMetaData;\r
-import org.commscope.tr069adapter.mapper.MapperConfigProperties;\r
-import org.commscope.tr069adapter.mapper.acs.ACSNotificationHandler;\r
-import org.commscope.tr069adapter.mapper.dao.DeviceOperationsDAO;\r
-import org.commscope.tr069adapter.mapper.entity.DeviceOperationDetails;\r
-import org.commscope.tr069adapter.mapper.model.NetConfServerDetails;\r
-import org.commscope.tr069adapter.mapper.model.NetconfServerManagementError;\r
-import org.commscope.tr069adapter.mapper.netconf.NetConfNotificationSender;\r
-import org.commscope.tr069adapter.mapper.netconf.NetConfServerManager;\r
-import org.commscope.tr069adapter.mapper.sync.SynchronizedRequestHandler;\r
-import org.commscope.tr069adapter.mapper.util.FirwareUpgradeErrorCode;\r
-import org.commscope.tr069adapter.mapper.util.FirwareUpgradeStatus;\r
-import org.commscope.tr069adapter.mapper.util.MOMetaDataUtil;\r
-import org.commscope.tr069adapter.mapper.ves.VESNotificationSender;\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
-\r
-@Component\r
-public class ACSNotificationHandlerImpl implements ACSNotificationHandler {\r
-\r
-  private static final Logger logger = LoggerFactory.getLogger(ACSNotificationHandlerImpl.class);\r
-  private static final String SOFT_MGMT_NS_URI = "urn:o-ran:software-management:1.0";\r
-\r
-  @Autowired\r
-  SynchronizedRequestHandler syncHandler;\r
-\r
-  @Autowired\r
-  MOMetaDataUtil metaDataUtil;\r
-\r
-  @Autowired\r
-  PnPPreProvisioningHandler pnpPreProvisioningHandler;\r
-\r
-  @Autowired\r
-  VESNotificationSender vesnotiSender;\r
-\r
-  @Autowired\r
-  NetConfNotificationSender notiSender;\r
-\r
-  @Autowired\r
-  MapperConfigProperties config;\r
-\r
-  @Autowired\r
-  NetConfServerManager netconfManager;\r
-\r
-  @Autowired\r
-  DeviceOperationsDAO deviceOperDAO;\r
-\r
-  @Override\r
-  public void handleOperationResponse(DeviceRPCResponse opResult) {\r
-    opResult.getOperationResponse().setParameterDTOs(\r
-        filterUnsupportedParameters(opResult.getOperationResponse().getParameterDTOs(),\r
-            opResult.getDeviceDetails().getSoftwareVersion(),\r
-            opResult.getDeviceDetails().getHardwareVersion()));\r
-    syncHandler.notifyResult(opResult);\r
-  }\r
-\r
-  @Override\r
-  public void handleNotification(DeviceInform notification) {\r
-    boolean isAlarmVC = isAlarmVC(notification);\r
-\r
-    if (notification instanceof BootstrapInform) {\r
-      logger.info("BootStrap notification received");\r
-      BootstrapInform bootstrapNotification = (BootstrapInform) notification;\r
-\r
-      DeviceOperationDetails deviceDetails =\r
-          deviceOperDAO.findByDeviceId(notification.getDeviceDetails().getDeviceId());\r
-      if (deviceDetails == null) {\r
-        deviceDetails = new DeviceOperationDetails();\r
-        deviceDetails.setDeviceId(notification.getDeviceDetails().getDeviceId());\r
-        deviceDetails.setSwVersion(notification.getDeviceDetails().getSoftwareVersion());\r
-        deviceOperDAO.save(deviceDetails);\r
-      }\r
-\r
-      checkForActivateNotification(notification);\r
-\r
-      // send request to create the netconf server instance for the bootstrap device\r
-      // id\r
-      NetConfServerDetails serverInfo = createNtConfServer(bootstrapNotification);\r
-      if (serverInfo == null)\r
-        return;\r
-\r
-      vesnotiSender.sendNotification(bootstrapNotification, serverInfo);\r
-      BootstrapInform bsInform =\r
-          getDeviceBootStrapNotification(bootstrapNotification, TR069InformType.BOOTSTRAP);\r
-      ValueChangeInform vcInform = null;\r
-      if (bootstrapNotification.getValueChangeNotification() != null) {\r
-        logger.info("Bootstrap notification received along with VC");\r
-        vcInform =\r
-            getDeviceValueChangeNotification(bootstrapNotification, TR069InformType.VALUECHANGE);\r
-        processVCNotification(vcInform, isAlarmVC);\r
-      }\r
-      notiSender.sendNotification(bsInform);\r
-      if (vcInform != null)\r
-        processVCNotification(vcInform, isAlarmVC);\r
-    } else if (notification instanceof BootInform) {\r
-      logger.info("Boot notification received");\r
-\r
-      NetConfServerDetails serverInfo = createNtConfServer(notification);\r
-      if (serverInfo == null)\r
-        return;\r
-\r
-      checkForActivateNotification(notification);\r
-      BootInform bootNotification = (BootInform) notification;\r
-      BootInform bInform = getDeviceBootNotification(bootNotification, TR069InformType.BOOT);\r
-      ValueChangeInform vcInform = null;\r
-      if (bootNotification.getValueChangeNotification() != null) {\r
-        logger.info("Boot notification received along with VC");\r
-        vcInform = getDeviceValueChangeNotification(bootNotification, TR069InformType.VALUECHANGE);\r
-      }\r
-      notiSender.sendNotification(bInform);\r
-      processVCNotification(vcInform, isAlarmVC);\r
-    } else if (notification instanceof PeriodicInform) {\r
-      PeriodicInform pINotificaiton = (PeriodicInform) notification;\r
-      vesnotiSender.sendNotification(pINotificaiton, null);\r
-      notiSender.sendNotification(pINotificaiton);\r
-      logger.info("PI notification received");\r
-    } else if (notification instanceof ConnectionRequestInform) {\r
-      ConnectionRequestInform crNotificaiton = (ConnectionRequestInform) notification;\r
-      vesnotiSender.sendNotification(crNotificaiton, null);\r
-      logger.info("ConnectionRequestInform notification received");\r
-    } else if (notification instanceof ValueChangeInform) {\r
-      ValueChangeInform valueChgNotificaiton = (ValueChangeInform) notification;\r
-      processVCNotification(valueChgNotificaiton, isAlarmVC);\r
-    } else if (notification instanceof TransferCompleteInform) {\r
-      TransferCompleteInform tfNotificaiton = (TransferCompleteInform) notification;\r
-      if (tfNotificaiton.getCommandKey() != null && tfNotificaiton.getCommandKey()\r
-          .equalsIgnoreCase(tfNotificaiton.getDeviceDetails().getDeviceId())) {\r
-        logger.debug("TransferCompleteInform is recevied at mapper");\r
-        processTransferCompleteInform(tfNotificaiton);\r
-        logger.debug("TransferCompleteInform processing completed at mapper");\r
-      }\r
-    }\r
-\r
-    pnpPreProvisioningHandler.onDeviceNotification(notification);\r
-  }\r
-\r
-  private NetConfServerDetails createNtConfServer(DeviceInform inform) {\r
-    String eNodeBName = pnpPreProvisioningHandler.getEnodeBName(\r
-        inform.getDeviceDetails().getDeviceId(), inform.getDeviceDetails().getSoftwareVersion(),\r
-        inform.getDeviceDetails().getHardwareVersion());\r
-    if (eNodeBName == null)\r
-      eNodeBName = inform.getDeviceDetails().getDeviceId();\r
-    NetConfServerDetails serverInfo =\r
-        netconfManager.createNetconfServer(inform.getDeviceDetails().getDeviceId(), eNodeBName,\r
-            inform.getDeviceDetails().getSoftwareVersion(),\r
-            inform.getDeviceDetails().getHardwareVersion());\r
-    if (serverInfo != null && !NetconfServerManagementError.SUCCESS.equals(serverInfo.getError())) {\r
-      logger.error("Failed to handle boot/bootstrap notification. Server INFO: {}", serverInfo);\r
-      logger.error("Failed to create the netconf server for device ID: {}  Error: {}",\r
-          inform.getDeviceDetails().getDeviceId(), serverInfo.getError());\r
-      return null;\r
-    } else if (serverInfo == null) {\r
-      logger.error(\r
-          "Failed to handle bootstrap notification. Failed to create netconf server. serverInfo is null");\r
-      return null;\r
-    }\r
-    return serverInfo;\r
-  }\r
-\r
-  private void processVCNotification(ValueChangeInform valueChgNotificaiton, boolean isAlarmVC) {\r
-    if (isAlarmVC) {\r
-      logger.debug("Alarm VC received forwarding to VES Collector");\r
-      vesnotiSender.sendNotification(valueChgNotificaiton, null);\r
-    } else {\r
-      logger.info("VC notification received");\r
-      notiSender.sendNotification(valueChgNotificaiton);\r
-    }\r
-  }\r
-\r
-  private boolean isAlarmVC(DeviceInform notification) {\r
-    if (null != notification && null != notification.getParameters()) {\r
-      for (ParameterDTO param : notification.getParameters()) {\r
-        if (param.getParamName().matches(config.getAlarmMORegex())) {\r
-          logger.debug("This VC contains alarm MOs");\r
-          return true;\r
-        }\r
-      }\r
-    }\r
-    return false;\r
-  }\r
-\r
-  public List<ParameterDTO> filterUnsupportedParameters(List<ParameterDTO> parameters,\r
-      String swVersion, String hwVersion) {\r
-    List<ParameterDTO> result = new ArrayList<>();\r
-    if (null != parameters) {\r
-      for (ParameterDTO param : parameters) {\r
-        MOMetaData metaData =\r
-            metaDataUtil.getMetaDataByTR69Name(param.getParamName(), swVersion, hwVersion);\r
-        if (null != metaData) {\r
-          result.add(param);\r
-        }\r
-      }\r
-    }\r
-    return result;\r
-  }\r
-\r
-  public static BootstrapInform getDeviceBootStrapNotification(DeviceInform devNotification,\r
-      TR069InformType notificationType) {\r
-    BootstrapInform bsInform = new BootstrapInform();\r
-    List<InformType> informTypeList = new ArrayList<>();\r
-    informTypeList.add(notificationType);\r
-    bsInform.setDeviceDetails(devNotification.getDeviceDetails());\r
-    bsInform.setInformTypeList(informTypeList);\r
-    List<ParameterDTO> paramList = new ArrayList<>();\r
-    for (ParameterDTO param : devNotification.getParameters()) {\r
-      paramList.add(new ParameterDTO(param.getParamName(), param.getParamValue()));\r
-    }\r
-    bsInform.setParameters(paramList);\r
-    return bsInform;\r
-  }\r
-\r
-  public static BootInform getDeviceBootNotification(DeviceInform devNotification,\r
-      TR069InformType notificationType) {\r
-    BootInform bInform = new BootInform();\r
-    List<InformType> informTypeList = new ArrayList<>();\r
-    informTypeList.add(notificationType);\r
-    bInform.setDeviceDetails(devNotification.getDeviceDetails());\r
-    bInform.setInformTypeList(informTypeList);\r
-    List<ParameterDTO> paramList = new ArrayList<>();\r
-    for (ParameterDTO param : devNotification.getParameters()) {\r
-      paramList.add(new ParameterDTO(param.getParamName(), param.getParamValue()));\r
-    }\r
-    bInform.setParameters(paramList);\r
-    return bInform;\r
-  }\r
-\r
-  public static ValueChangeInform getDeviceValueChangeNotification(DeviceInform devNotification,\r
-      TR069InformType notificationType) {\r
-    ValueChangeInform devValChangeNotif = new ValueChangeInform();\r
-    List<InformType> informTypeList = new ArrayList<>();\r
-    informTypeList.add(notificationType);\r
-    devValChangeNotif.setDeviceDetails(devNotification.getDeviceDetails());\r
-    devValChangeNotif.setInformTypeList(informTypeList);\r
-    List<ParameterDTO> paramList = new ArrayList<>();\r
-    for (ParameterDTO param : devNotification.getParameters()) {\r
-      paramList.add(new ParameterDTO(param.getParamName(), param.getParamValue()));\r
-    }\r
-    devValChangeNotif.setParameters(paramList);\r
-    devValChangeNotif.setExternalIPAddress(getExternalIPAddress(devNotification.getParameters()));\r
-    return devValChangeNotif;\r
-  }\r
-\r
-  private static String getExternalIPAddress(List<ParameterDTO> params) {\r
-    ParameterDTO[] nbiParam = params.toArray(new ParameterDTO[params.size()]);\r
-    String externalIpAddress = "";\r
-    boolean isIPv6 = isIPv6Enabled(nbiParam);\r
-\r
-    for (int index1 = 0; index1 < nbiParam.length; index1++) {\r
-\r
-      if (isIPv6) {\r
-        if (nbiParam[index1].getParamName().contains("IPv6Address")\r
-            || nbiParam[index1].getParamName().contains(".1.IPInterfaceIPAddress")) {\r
-          externalIpAddress = nbiParam[index1].getParamValue();\r
-          logger.debug("device communicating is with IPV6 address");\r
-        }\r
-      } else {\r
-        if (nbiParam[index1].getParamName().contains("IPv4Address")\r
-            || nbiParam[index1].getParamName().contains("ExternalIPAddress")\r
-            || nbiParam[index1].getParamName().contains(".1.IPInterfaceIPAddress")) {\r
-          externalIpAddress = nbiParam[index1].getParamValue();\r
-        }\r
-      }\r
-      if (externalIpAddress.trim().length() > 0)\r
-        break;\r
-    }\r
-    return externalIpAddress;\r
-  }\r
-\r
-  private static boolean isIPv6Enabled(ParameterDTO[] nbiParam) {\r
-    boolean isIPv6 = false;\r
-    for (int index1 = 0; index1 < nbiParam.length; index1++) {\r
-      if (nbiParam[index1].getParamName().contains("IPv6Enable")\r
-          && nbiParam[index1].getParamValue().equalsIgnoreCase("1")) {\r
-        isIPv6 = true;\r
-        break;\r
-      }\r
-    }\r
-    return isIPv6;\r
-  }\r
-\r
-  private void processTransferCompleteInform(TransferCompleteInform notification) {\r
-\r
-    try {\r
-      ArrayList<ParameterDTO> paramList = new ArrayList<ParameterDTO>();\r
-      DeviceOperationDetails fwDetails =\r
-          deviceOperDAO.findByDeviceId(notification.getDeviceDetails().getDeviceId());\r
-      if (fwDetails == null || fwDetails.getFileName() == null) {\r
-        logger.debug(\r
-            "TransferCompleteInform recevied for invaild device, there is no entry exist in the database");\r
-        return;\r
-      }\r
-      if (fwDetails.getDownLoadStatus() == FirwareUpgradeStatus.DOWNLOAD_INTIATED.getStatus()) {\r
-        paramList.add(new ParameterDTO("download-event.file-name", fwDetails.getFileName()));\r
-\r
-        String status = FirwareUpgradeErrorCode.getErrorCodeMapping(notification.getFaultCode());\r
-        paramList.add(new ParameterDTO("download-event.status", status));\r
-        if (notification.getFaultCode() != 0) {\r
-          fwDetails.setDownLoadStatus(FirwareUpgradeStatus.DOWNLOAD_FAILED.getStatus());\r
-          paramList\r
-              .add(new ParameterDTO("download-event.error-message", notification.getFaultString()));\r
-        } else {\r
-          fwDetails.setDownLoadStatus(FirwareUpgradeStatus.DOWNLOAD_COMPLETED.getStatus());\r
-          logger.debug("downloading file completed on the device successfully.");\r
-        }\r
-        deviceOperDAO.save(fwDetails);\r
-\r
-        logger.debug("sending download-event notification to netconfserver");\r
-\r
-        if (notiSender.sendCustomNotification(notification.getDeviceDetails().getDeviceId(),\r
-            paramList, SOFT_MGMT_NS_URI).getStatusCode().is2xxSuccessful()) {\r
-          logger.debug("sending download-event notification to netconfserver sucess");\r
-        } else {\r
-          logger.error("sending download-event notification to netconfserver failed");\r
-        }\r
-      } else {\r
-        logger.debug(\r
-            "TransferCompleteInform recevied after boot is received; already software is activated");\r
-      }\r
-    } catch (Exception e) {\r
-      logger.debug("Exception occured while processing TransferCompleteInform " + e.toString());\r
-    }\r
-  }\r
-\r
-  private void checkForActivateNotification(DeviceInform notification) {\r
-\r
-    try {\r
-      ArrayList<ParameterDTO> paramList = new ArrayList<ParameterDTO>();\r
-      DeviceOperationDetails devDetails =\r
-          deviceOperDAO.findByDeviceId(notification.getDeviceDetails().getDeviceId());\r
-\r
-      if (devDetails == null\r
-          || devDetails.getDownLoadStatus() == FirwareUpgradeStatus.NOT_STARTED.getStatus()) {\r
-        logger.debug("firmware upgrade is not in progress");\r
-        return;\r
-      }\r
-\r
-      if (!notification.getDeviceDetails().getSoftwareVersion()\r
-          .equalsIgnoreCase(devDetails.getSwVersion())\r
-          && devDetails.getDownLoadStatus() == FirwareUpgradeStatus.DOWNLOAD_INTIATED.getStatus()) {\r
-        logger.debug("received the boot/bootstrap before the transfer complete recevied");\r
-        TransferCompleteInform inform = new TransferCompleteInform();\r
-        inform.setDeviceDetails(notification.getDeviceDetails());\r
-        inform.setFaultCode(0);\r
-        processTransferCompleteInform(inform);\r
-      }\r
-\r
-      devDetails = deviceOperDAO.findByDeviceId(notification.getDeviceDetails().getDeviceId());\r
-      if (devDetails.getDownLoadStatus() == FirwareUpgradeStatus.DOWNLOAD_COMPLETED.getStatus()) {\r
-        paramList.add(new ParameterDTO("activation-event.slot-name", "Active-Partion"));\r
-        // check for software change\r
-        if (notification.getDeviceDetails().getSoftwareVersion()\r
-            .equalsIgnoreCase(devDetails.getSwVersion())) {\r
-          paramList.add(new ParameterDTO("activation-event.status", "APPLICATION_ERROR"));\r
-          paramList.add(new ParameterDTO("activation-event.error-message",\r
-              "Same Software Version is reported after upgrade"));\r
-          devDetails.setDownLoadStatus(FirwareUpgradeStatus.ACTIVATION_ERROR.getStatus());\r
-        } else {\r
-          devDetails.setSwVersion(notification.getDeviceDetails().getSoftwareVersion());\r
-          devDetails.setDownLoadStatus(FirwareUpgradeStatus.ACTIVATION_COMPLETED.getStatus());\r
-          paramList.add(new ParameterDTO("activation-event.status", "COMPLETED"));\r
-        }\r
-        deviceOperDAO.save(devDetails);\r
-\r
-        logger.debug("sending activation-event notification to netconfserver");\r
-\r
-        if (notiSender.sendCustomNotification(notification.getDeviceDetails().getDeviceId(),\r
-            paramList, SOFT_MGMT_NS_URI).getStatusCode().is2xxSuccessful()) {\r
-          logger.debug("sending activation-event notification to netconfserver sucess");\r
-        } else {\r
-          logger.error("sending activation-event notification to netconfserver failed");\r
-        }\r
-      }\r
-    } catch (Exception e) {\r
-      logger.debug(\r
-          "Exception occured while processing ProcessFirmWareActivateNotification " + e.toString());\r
-    }\r
-  }\r
-}\r
+/*
+ * ============LICENSE_START========================================================================
+ * ONAP : tr-069-adapter
+ * =================================================================================================
+ * Copyright (C) 2020 CommScope Inc Intellectual Property.
+ * =================================================================================================
+ * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
+ * may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ===============LICENSE_END=======================================================================
+ */
+
+package org.commscope.tr069adapter.mapper.acs.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.commscope.tr069adapter.acs.common.DeviceInform;
+import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;
+import org.commscope.tr069adapter.acs.common.InformType;
+import org.commscope.tr069adapter.acs.common.ParameterDTO;
+import org.commscope.tr069adapter.acs.common.dto.TR069InformType;
+import org.commscope.tr069adapter.acs.common.inform.BootInform;
+import org.commscope.tr069adapter.acs.common.inform.BootstrapInform;
+import org.commscope.tr069adapter.acs.common.inform.ConnectionRequestInform;
+import org.commscope.tr069adapter.acs.common.inform.PeriodicInform;
+import org.commscope.tr069adapter.acs.common.inform.TransferCompleteInform;
+import org.commscope.tr069adapter.acs.common.inform.ValueChangeInform;
+import org.commscope.tr069adapter.mapper.MOMetaData;
+import org.commscope.tr069adapter.mapper.MapperConfigProperties;
+import org.commscope.tr069adapter.mapper.acs.ACSNotificationHandler;
+import org.commscope.tr069adapter.mapper.dao.DeviceOperationsDAO;
+import org.commscope.tr069adapter.mapper.entity.DeviceOperationDetails;
+import org.commscope.tr069adapter.mapper.model.NetConfServerDetails;
+import org.commscope.tr069adapter.mapper.model.NetconfServerManagementError;
+import org.commscope.tr069adapter.mapper.netconf.NetConfNotificationSender;
+import org.commscope.tr069adapter.mapper.netconf.NetConfServerManager;
+import org.commscope.tr069adapter.mapper.sync.SynchronizedRequestHandler;
+import org.commscope.tr069adapter.mapper.util.FirwareUpgradeErrorCode;
+import org.commscope.tr069adapter.mapper.util.FirwareUpgradeStatus;
+import org.commscope.tr069adapter.mapper.util.MOMetaDataUtil;
+import org.commscope.tr069adapter.mapper.ves.VESNotificationSender;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ACSNotificationHandlerImpl implements ACSNotificationHandler {
+
+  private static final Logger logger = LoggerFactory.getLogger(ACSNotificationHandlerImpl.class);
+  private static final String SOFT_MGMT_NS_URI = "urn:o-ran:software-management:1.0";
+
+  @Autowired
+  SynchronizedRequestHandler syncHandler;
+
+  @Autowired
+  MOMetaDataUtil metaDataUtil;
+
+  @Autowired
+  PnPPreProvisioningHandler pnpPreProvisioningHandler;
+
+  @Autowired
+  VESNotificationSender vesnotiSender;
+
+  @Autowired
+  NetConfNotificationSender notiSender;
+
+  @Autowired
+  MapperConfigProperties config;
+
+  @Autowired
+  NetConfServerManager netconfManager;
+
+  @Autowired
+  DeviceOperationsDAO deviceOperDAO;
+
+  @Override
+  public void handleOperationResponse(DeviceRPCResponse opResult) {
+    opResult.getOperationResponse().setParameterDTOs(
+        filterUnsupportedParameters(opResult.getOperationResponse().getParameterDTOs(),
+            opResult.getDeviceDetails().getSoftwareVersion(),
+            opResult.getDeviceDetails().getHardwareVersion()));
+    syncHandler.notifyResult(opResult);
+  }
+
+  @Override
+  public void handleNotification(DeviceInform notification) {
+    boolean isAlarmVC = isAlarmVC(notification);
+
+    if (notification instanceof BootstrapInform) {
+      logger.info("BootStrap notification received");
+      BootstrapInform bootstrapNotification = (BootstrapInform) notification;
+
+      DeviceOperationDetails deviceDetails =
+          deviceOperDAO.findByDeviceId(notification.getDeviceDetails().getDeviceId());
+      if (deviceDetails == null) {
+        deviceDetails = new DeviceOperationDetails();
+        deviceDetails.setDeviceId(notification.getDeviceDetails().getDeviceId());
+        deviceDetails.setSwVersion(notification.getDeviceDetails().getSoftwareVersion());
+        deviceOperDAO.save(deviceDetails);
+      }
+
+      checkForActivateNotification(notification);
+
+      // send request to create the netconf server instance for the bootstrap device
+      // id
+      NetConfServerDetails serverInfo = createNtConfServer(bootstrapNotification);
+      if (serverInfo == null)
+        return;
+
+      vesnotiSender.sendNotification(bootstrapNotification, serverInfo);
+      BootstrapInform bsInform =
+          getDeviceBootStrapNotification(bootstrapNotification, TR069InformType.BOOTSTRAP);
+      ValueChangeInform vcInform = null;
+      if (bootstrapNotification.getValueChangeNotification() != null) {
+        logger.info("Bootstrap notification received along with VC");
+        vcInform =
+            getDeviceValueChangeNotification(bootstrapNotification, TR069InformType.VALUECHANGE);
+        processVCNotification(vcInform, isAlarmVC);
+      }
+      notiSender.sendNotification(bsInform);
+      if (vcInform != null)
+        processVCNotification(vcInform, isAlarmVC);
+    } else if (notification instanceof BootInform) {
+      logger.info("Boot notification received");
+
+      NetConfServerDetails serverInfo = createNtConfServer(notification);
+      if (serverInfo == null)
+        return;
+
+      checkForActivateNotification(notification);
+      BootInform bootNotification = (BootInform) notification;
+      BootInform bInform = getDeviceBootNotification(bootNotification, TR069InformType.BOOT);
+      ValueChangeInform vcInform = null;
+      if (bootNotification.getValueChangeNotification() != null) {
+        logger.info("Boot notification received along with VC");
+        vcInform = getDeviceValueChangeNotification(bootNotification, TR069InformType.VALUECHANGE);
+      }
+      notiSender.sendNotification(bInform);
+      processVCNotification(vcInform, isAlarmVC);
+    } else if (notification instanceof PeriodicInform) {
+      PeriodicInform pINotificaiton = (PeriodicInform) notification;
+      vesnotiSender.sendNotification(pINotificaiton, null);
+      notiSender.sendNotification(pINotificaiton);
+      logger.info("PI notification received");
+    } else if (notification instanceof ConnectionRequestInform) {
+      ConnectionRequestInform crNotificaiton = (ConnectionRequestInform) notification;
+      vesnotiSender.sendNotification(crNotificaiton, null);
+      logger.info("ConnectionRequestInform notification received");
+    } else if (notification instanceof ValueChangeInform) {
+      ValueChangeInform valueChgNotificaiton = (ValueChangeInform) notification;
+      processVCNotification(valueChgNotificaiton, isAlarmVC);
+    } else if (notification instanceof TransferCompleteInform) {
+      TransferCompleteInform tfNotificaiton = (TransferCompleteInform) notification;
+      if (tfNotificaiton.getCommandKey() != null && tfNotificaiton.getCommandKey()
+          .equalsIgnoreCase(tfNotificaiton.getDeviceDetails().getDeviceId())) {
+        logger.debug("TransferCompleteInform is recevied at mapper");
+        processTransferCompleteInform(tfNotificaiton);
+        logger.debug("TransferCompleteInform processing completed at mapper");
+      }
+    }
+
+    pnpPreProvisioningHandler.onDeviceNotification(notification);
+  }
+
+  private NetConfServerDetails createNtConfServer(DeviceInform inform) {
+    String eNodeBName = pnpPreProvisioningHandler.getEnodeBName(
+        inform.getDeviceDetails().getDeviceId(), inform.getDeviceDetails().getSoftwareVersion(),
+        inform.getDeviceDetails().getHardwareVersion());
+    if (eNodeBName == null)
+      eNodeBName = inform.getDeviceDetails().getDeviceId();
+    NetConfServerDetails serverInfo =
+        netconfManager.createNetconfServer(inform.getDeviceDetails().getDeviceId(), eNodeBName,
+            inform.getDeviceDetails().getSoftwareVersion(),
+            inform.getDeviceDetails().getHardwareVersion());
+    if (serverInfo != null && !NetconfServerManagementError.SUCCESS.equals(serverInfo.getError())) {
+      logger.error("Failed to handle boot/bootstrap notification. Server INFO: {}", serverInfo);
+      logger.error("Failed to create the netconf server for device ID: {}  Error: {}",
+          inform.getDeviceDetails().getDeviceId(), serverInfo.getError());
+      return null;
+    } else if (serverInfo == null) {
+      logger.error(
+          "Failed to handle bootstrap notification. Failed to create netconf server. serverInfo is null");
+      return null;
+    }
+    return serverInfo;
+  }
+
+       private void processVCNotification(ValueChangeInform valueChgNotificaiton, boolean isAlarmVC) {
+               if (isAlarmVC) {
+                       logger.debug("Alarm VC received forwarding to VES Collector");
+                       vesnotiSender.sendNotification(valueChgNotificaiton, null);
+               }
+               logger.info("VC notification received");
+               notiSender.sendNotification(valueChgNotificaiton);
+       }
+
+  private boolean isAlarmVC(DeviceInform notification) {
+    if (null != notification && null != notification.getParameters()) {
+      for (ParameterDTO param : notification.getParameters()) {
+        if (param.getParamName().matches(config.getAlarmMORegex())) {
+          logger.debug("This VC contains alarm MOs");
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+
+  public List<ParameterDTO> filterUnsupportedParameters(List<ParameterDTO> parameters,
+      String swVersion, String hwVersion) {
+    List<ParameterDTO> result = new ArrayList<>();
+    if (null != parameters) {
+      for (ParameterDTO param : parameters) {
+        MOMetaData metaData =
+            metaDataUtil.getMetaDataByTR69Name(param.getParamName(), swVersion, hwVersion);
+        if (null != metaData) {
+          result.add(param);
+        }
+      }
+    }
+    return result;
+  }
+
+  public static BootstrapInform getDeviceBootStrapNotification(DeviceInform devNotification,
+      TR069InformType notificationType) {
+    BootstrapInform bsInform = new BootstrapInform();
+    List<InformType> informTypeList = new ArrayList<>();
+    informTypeList.add(notificationType);
+    bsInform.setDeviceDetails(devNotification.getDeviceDetails());
+    bsInform.setInformTypeList(informTypeList);
+    List<ParameterDTO> paramList = new ArrayList<>();
+    for (ParameterDTO param : devNotification.getParameters()) {
+      paramList.add(new ParameterDTO(param.getParamName(), param.getParamValue()));
+    }
+    bsInform.setParameters(paramList);
+    return bsInform;
+  }
+
+  public static BootInform getDeviceBootNotification(DeviceInform devNotification,
+      TR069InformType notificationType) {
+    BootInform bInform = new BootInform();
+    List<InformType> informTypeList = new ArrayList<>();
+    informTypeList.add(notificationType);
+    bInform.setDeviceDetails(devNotification.getDeviceDetails());
+    bInform.setInformTypeList(informTypeList);
+    List<ParameterDTO> paramList = new ArrayList<>();
+    for (ParameterDTO param : devNotification.getParameters()) {
+      paramList.add(new ParameterDTO(param.getParamName(), param.getParamValue()));
+    }
+    bInform.setParameters(paramList);
+    return bInform;
+  }
+
+  public static ValueChangeInform getDeviceValueChangeNotification(DeviceInform devNotification,
+      TR069InformType notificationType) {
+    ValueChangeInform devValChangeNotif = new ValueChangeInform();
+    List<InformType> informTypeList = new ArrayList<>();
+    informTypeList.add(notificationType);
+    devValChangeNotif.setDeviceDetails(devNotification.getDeviceDetails());
+    devValChangeNotif.setInformTypeList(informTypeList);
+    List<ParameterDTO> paramList = new ArrayList<>();
+    for (ParameterDTO param : devNotification.getParameters()) {
+      paramList.add(new ParameterDTO(param.getParamName(), param.getParamValue()));
+    }
+    devValChangeNotif.setParameters(paramList);
+    devValChangeNotif.setExternalIPAddress(getExternalIPAddress(devNotification.getParameters()));
+    return devValChangeNotif;
+  }
+
+  private static String getExternalIPAddress(List<ParameterDTO> params) {
+    ParameterDTO[] nbiParam = params.toArray(new ParameterDTO[params.size()]);
+    String externalIpAddress = "";
+    boolean isIPv6 = isIPv6Enabled(nbiParam);
+
+    for (int index1 = 0; index1 < nbiParam.length; index1++) {
+
+      if (isIPv6) {
+        if (nbiParam[index1].getParamName().contains("IPv6Address")
+            || nbiParam[index1].getParamName().contains(".1.IPInterfaceIPAddress")) {
+          externalIpAddress = nbiParam[index1].getParamValue();
+          logger.debug("device communicating is with IPV6 address");
+        }
+      } else {
+        if (nbiParam[index1].getParamName().contains("IPv4Address")
+            || nbiParam[index1].getParamName().contains("ExternalIPAddress")
+            || nbiParam[index1].getParamName().contains(".1.IPInterfaceIPAddress")) {
+          externalIpAddress = nbiParam[index1].getParamValue();
+        }
+      }
+      if (externalIpAddress.trim().length() > 0)
+        break;
+    }
+    return externalIpAddress;
+  }
+
+  private static boolean isIPv6Enabled(ParameterDTO[] nbiParam) {
+    boolean isIPv6 = false;
+    for (int index1 = 0; index1 < nbiParam.length; index1++) {
+      if (nbiParam[index1].getParamName().contains("IPv6Enable")
+          && nbiParam[index1].getParamValue().equalsIgnoreCase("1")) {
+        isIPv6 = true;
+        break;
+      }
+    }
+    return isIPv6;
+  }
+
+  private void processTransferCompleteInform(TransferCompleteInform notification) {
+
+    try {
+      ArrayList<ParameterDTO> paramList = new ArrayList<>();
+      DeviceOperationDetails fwDetails =
+          deviceOperDAO.findByDeviceId(notification.getDeviceDetails().getDeviceId());
+      if (fwDetails == null || fwDetails.getFileName() == null) {
+        logger.debug(
+            "TransferCompleteInform recevied for invaild device, there is no entry exist in the database");
+        return;
+      }
+      if (fwDetails.getDownLoadStatus() == FirwareUpgradeStatus.DOWNLOAD_INTIATED.getStatus()) {
+        paramList.add(new ParameterDTO("download-event.file-name", fwDetails.getFileName()));
+
+        String status = FirwareUpgradeErrorCode.getErrorCodeMapping(notification.getFaultCode());
+        paramList.add(new ParameterDTO("download-event.status", status));
+        if (notification.getFaultCode() != 0) {
+          fwDetails.setDownLoadStatus(FirwareUpgradeStatus.DOWNLOAD_FAILED.getStatus());
+          paramList
+              .add(new ParameterDTO("download-event.error-message", notification.getFaultString()));
+        } else {
+          fwDetails.setDownLoadStatus(FirwareUpgradeStatus.DOWNLOAD_COMPLETED.getStatus());
+          logger.debug("downloading file completed on the device successfully.");
+        }
+        deviceOperDAO.save(fwDetails);
+      
+        if(fwDetails.getOrigin().equals("csem"))
+        {
+               logger.debug("sending transferComplete-event notification to netconfserver");
+               notiSender.sendTransferCompleteNotification(notification);
+        }
+        logger.debug("sending download-event notification to netconfserver");
+        if (notiSender.sendCustomNotification(notification.getDeviceDetails().getDeviceId(),
+            paramList, SOFT_MGMT_NS_URI).getStatusCode().is2xxSuccessful()) {
+          logger.debug("sending download-event notification to netconfserver sucess");
+        } else {
+          logger.error("sending download-event notification to netconfserver failed");
+        }
+      } else {
+        logger.debug(
+            "TransferCompleteInform recevied after boot is received; already software is activated");
+      }
+    } catch (Exception e) {
+      logger.debug("Exception occured while processing TransferCompleteInform: {}" , e.getMessage());
+    }
+  }
+
+  private void checkForActivateNotification(DeviceInform notification) {
+
+    try {
+      ArrayList<ParameterDTO> paramList = new ArrayList<>();
+      DeviceOperationDetails devDetails =
+          deviceOperDAO.findByDeviceId(notification.getDeviceDetails().getDeviceId());
+
+      if (devDetails == null
+          || devDetails.getDownLoadStatus() == FirwareUpgradeStatus.NOT_STARTED.getStatus()) {
+        logger.debug("firmware upgrade is not in progress");
+        return;
+      }
+
+      if (!notification.getDeviceDetails().getSoftwareVersion()
+          .equalsIgnoreCase(devDetails.getSwVersion())
+          && devDetails.getDownLoadStatus() == FirwareUpgradeStatus.DOWNLOAD_INTIATED.getStatus()) {
+        logger.debug("received the boot/bootstrap before the transfer complete recevied");
+        TransferCompleteInform inform = new TransferCompleteInform();
+        inform.setDeviceDetails(notification.getDeviceDetails());
+        inform.setFaultCode(0);
+        processTransferCompleteInform(inform);
+      }
+
+      devDetails = deviceOperDAO.findByDeviceId(notification.getDeviceDetails().getDeviceId());
+      if (devDetails.getDownLoadStatus() == FirwareUpgradeStatus.DOWNLOAD_COMPLETED.getStatus()) {
+        paramList.add(new ParameterDTO("activation-event.slot-name", "Active-Partion"));
+        // check for software change
+        if (notification.getDeviceDetails().getSoftwareVersion()
+            .equalsIgnoreCase(devDetails.getSwVersion())) {
+          paramList.add(new ParameterDTO("activation-event.status", "APPLICATION_ERROR"));
+          paramList.add(new ParameterDTO("activation-event.error-message",
+              "Same Software Version is reported after upgrade"));
+          devDetails.setDownLoadStatus(FirwareUpgradeStatus.ACTIVATION_ERROR.getStatus());
+        } else {
+          devDetails.setSwVersion(notification.getDeviceDetails().getSoftwareVersion());
+          devDetails.setDownLoadStatus(FirwareUpgradeStatus.ACTIVATION_COMPLETED.getStatus());
+          paramList.add(new ParameterDTO("activation-event.status", "COMPLETED"));
+        }
+        deviceOperDAO.save(devDetails);
+
+        logger.debug("sending activation-event notification to netconfserver");
+
+        if (notiSender.sendCustomNotification(notification.getDeviceDetails().getDeviceId(),
+            paramList, SOFT_MGMT_NS_URI).getStatusCode().is2xxSuccessful()) {
+          logger.debug("sending activation-event notification to netconfserver sucess");
+        } else {
+          logger.error("sending activation-event notification to netconfserver failed");
+        }
+      }
+    } catch (Exception e) {
+      logger.debug(
+          "Exception occured while processing ProcessFirmWareActivateNotification {}" , e.getMessage());
+    }
+  }
+}