Initial source code
[oam/tr069-adapter.git] / acs / requestprocessor / src / main / java / org / commscope / tr069adapter / acs / requestprocessor / custom / CheckDeviceAvailability.java
diff --git a/acs/requestprocessor/src/main/java/org/commscope/tr069adapter/acs/requestprocessor/custom/CheckDeviceAvailability.java b/acs/requestprocessor/src/main/java/org/commscope/tr069adapter/acs/requestprocessor/custom/CheckDeviceAvailability.java
new file mode 100644 (file)
index 0000000..231530a
--- /dev/null
@@ -0,0 +1,84 @@
+/*\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.acs.requestprocessor.custom;\r
+\r
+import org.commscope.tr069adapter.acs.common.DeviceRPCRequest;\r
+import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;\r
+import org.commscope.tr069adapter.acs.common.OperationResponse;\r
+import org.commscope.tr069adapter.acs.common.dto.TR069DeviceDetails;\r
+import org.commscope.tr069adapter.acs.common.dto.TR069OperationCode;\r
+import org.commscope.tr069adapter.acs.common.exception.TR069EventProcessingException;\r
+import org.commscope.tr069adapter.acs.requestprocessor.dao.DeviceRPCRequestRepositoryHelper;\r
+import org.commscope.tr069adapter.acs.requestprocessor.dto.CustomOperationData;\r
+import org.commscope.tr069adapter.acs.requestprocessor.impl.TR069EventNotificationService;\r
+import org.commscope.tr069adapter.acs.requestprocessor.impl.TR069RequestProcessEngine;\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("CheckDeviceAvailability")\r
+public class CheckDeviceAvailability implements CustomOperation {\r
+\r
+  private static final Logger logger = LoggerFactory.getLogger(CheckDeviceAvailability.class);\r
+\r
+  @Autowired\r
+  protected DeviceRPCRequestRepositoryHelper deviceRPCRequestRepositoryHelper;\r
+\r
+  @Autowired\r
+  TR069RequestProcessEngine tr069RequestProcessEngine;\r
+\r
+  @Autowired\r
+  TR069EventNotificationService eventNotificationService;\r
+\r
+  @Override\r
+  public CustomOperationData executeCustomLogic(CustomOperationData customOperationData)\r
+      throws TR069EventProcessingException {\r
+\r
+    TR069DeviceDetails deviceDetails = customOperationData.getDeviceDetails();\r
+    DeviceRPCRequest deviceRPCRequest = customOperationData.getDeviceRPCRequest();\r
+\r
+    logger.debug("Started processing Check device availability");\r
+\r
+    DeviceRPCResponse deviceRPCResponse = new DeviceRPCResponse();\r
+    OperationResponse operationResponse = new OperationResponse();\r
+    operationResponse.setOperationCode(TR069OperationCode.INITIATE_CR);\r
+    Long operationId = deviceRPCRequest.getOperationId();\r
+    deviceRPCResponse.setDeviceDetails(deviceDetails);\r
+    deviceRPCResponse.setOperationId(operationId);\r
+    deviceRPCResponse.setOperationResponse(operationResponse);\r
+\r
+    logger.debug("Marking as processed the corresponding NBI Operation request record");\r
+    deviceRPCRequestRepositoryHelper.markDeviceRPCRequestAsProcessed(deviceDetails.getDeviceId(),\r
+        operationId);\r
+\r
+    logger.debug("Sending the operation response for check device availability");\r
+    // Sending the operation response to NBI\r
+    eventNotificationService.sendOperationResultToNBI(deviceRPCResponse);\r
+    customOperationData.setDeviceRPCResponse(null);\r
+    customOperationData.setDeviceRPCRequest(null);\r
+\r
+    logger.debug("Stopping request timer if any running for operation ID : {}", operationId);\r
+    tr069RequestProcessEngine.stopDeviceRPCRequestTimer(deviceDetails.getDeviceId(),\r
+        deviceRPCRequest.getOperationId());\r
+    logger.debug("Finished processing Check device availability");\r
+    return customOperationData;\r
+  }\r
+\r
+}\r