VES Heartbeat and Software Management Feature
[oam/tr069-adapter.git] / acs / requestprocessor / src / main / java / org / commscope / tr069adapter / acs / requestprocessor / impl / TR069RequestProcessEngine.java
index 8ad7f2b..91dacb3 100644 (file)
@@ -28,6 +28,7 @@ import org.commscope.tr069adapter.acs.common.DeviceRPCRequest;
 import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;\r
 import org.commscope.tr069adapter.acs.common.OperationCode;\r
 import org.commscope.tr069adapter.acs.common.OperationDetails;\r
+import org.commscope.tr069adapter.acs.common.OperationResponse;\r
 import org.commscope.tr069adapter.acs.common.dto.CustomOperationCode;\r
 import org.commscope.tr069adapter.acs.common.dto.DeviceOperationRequestDetails;\r
 import org.commscope.tr069adapter.acs.common.dto.TR069DeviceDetails;\r
@@ -99,7 +100,11 @@ public class TR069RequestProcessEngine extends TR069RequestProcessEngineHelper {
       deviceId = deviceRPCRequest.getDeviceDetails().getDeviceId();\r
       try {\r
         tr069DeviceDetails = deviceOperationInterface.getDeviceDetails(deviceId);\r
-      } catch (DeviceOperationException deo) {\r
+        deviceRPCResponse = checkForDeviceAvailabilityRequest(deviceRPCRequest, tr069DeviceDetails);\r
+        if (null != deviceRPCResponse) {\r
+          return;\r
+        }\r
+      } catch (DeviceOperationException | SessionManagerException deo) {\r
         logger.error(deo.getMessage());\r
         deviceRPCResponse = tr069RequestProcessEngineUtility.buildAbortedOperationresult(\r
             tr069DeviceDetails, deviceRPCRequest, AcsFaultCode.FAULT_CODE_8000);\r
@@ -152,6 +157,35 @@ public class TR069RequestProcessEngine extends TR069RequestProcessEngineHelper {
     }\r
   }\r
 \r
+  private DeviceRPCResponse checkForDeviceAvailabilityRequest(DeviceRPCRequest deviceRPCRequest,\r
+      TR069DeviceDetails tr069DeviceDetails) throws SessionManagerException {\r
+    DeviceRPCResponse deviceRPCResponse = null;\r
+\r
+    if (!deviceRPCRequest.getOpDetails().getOpCode().equals(CustomOperationCode.CONNECT)) {\r
+      return deviceRPCResponse;\r
+    }\r
+\r
+    SessionDTO sessionDTO = getSession(tr069DeviceDetails.getDeviceId());\r
+\r
+    if (null != sessionDTO && !SessionState.TERMINATED.equals(sessionDTO.getSessionState())) {\r
+      logger.debug("Device is reachable as device tr069 session is in {} state.",\r
+          sessionDTO.getSessionState());\r
+\r
+      deviceRPCResponse = new DeviceRPCResponse();\r
+      deviceRPCResponse.setDeviceDetails(tr069DeviceDetails);\r
+      deviceRPCResponse.setOperationId(deviceRPCRequest.getOperationId());\r
+\r
+      OperationResponse operationResponse = new OperationResponse();\r
+      // device reachable...change value 1 to some constant or enum\r
+      operationResponse.setStatus(TR069RequestProcessorUtility.DEVICE_REACHABLE_STATUS_CODE);\r
+      operationResponse.setOperationCode(deviceRPCRequest.getOpDetails().getOpCode());\r
+\r
+      deviceRPCResponse.setOperationResponse(operationResponse);\r
+    }\r
+\r
+    return deviceRPCResponse;\r
+  }\r
+\r
   /**\r
    * Common Step 1. Since there can exist only one Inform from any device, which will be the\r
    * initiator of the session, following steps to be followed a. Stop the session timer for this\r
@@ -312,19 +346,8 @@ public class TR069RequestProcessEngine extends TR069RequestProcessEngineHelper {
             DeviceRPCRequest operationRequest = customOperationData.getDeviceRPCRequest();\r
             deviceRPCResponse = customOperationData.getDeviceRPCResponse();\r
             if (operationRequest != null) {\r
-              operationRequest.addContextParam(SESSION_ID, newSessionId);\r
-              updateSessionCurOpId(tr069RequestProcessorData, deviceRPCRequest.getOperationId());\r
-              changeSessionState(tr069RequestProcessorData, SessionState.LOCKED);\r
-              updateSession(session);\r
-              if (deviceRPCResponse != null && operationRequest.getOperationId() != null\r
-                  && !operationRequest.getOperationId()\r
-                      .equals(deviceRPCResponse.getOperationId())) {\r
-                logger.debug(\r
-                    "Sending the Device RPC response for a configure Multiple object prior operation");\r
-                // Sending the operation response to NBI\r
-                tr069EventNotificationService.sendOperationResultToNBI(deviceRPCResponse);\r
-              }\r
-              return operationRequest;\r
+              return handleOperationRequest(deviceRPCResponse, session, deviceRPCRequest,\r
+                  newSessionId, tr069RequestProcessorData, operationRequest);\r
             } else {\r
               logger.debug(PENDING_RPC_CHECK);\r
               deviceRPCRequest =\r
@@ -368,6 +391,23 @@ public class TR069RequestProcessEngine extends TR069RequestProcessEngineHelper {
     return deviceRPCRequest;\r
   }\r
 \r
+  private DeviceRPCRequest handleOperationRequest(DeviceRPCResponse deviceRPCResponse,\r
+      SessionDTO session, DeviceRPCRequest deviceRPCRequest, String newSessionId,\r
+      TR069RequestProcessorData tr069RequestProcessorData, DeviceRPCRequest operationRequest) {\r
+    operationRequest.addContextParam(SESSION_ID, newSessionId);\r
+    updateSessionCurOpId(tr069RequestProcessorData, deviceRPCRequest.getOperationId());\r
+    changeSessionState(tr069RequestProcessorData, SessionState.LOCKED);\r
+    updateSession(session);\r
+    if (deviceRPCResponse != null && operationRequest.getOperationId() != null\r
+        && !operationRequest.getOperationId().equals(deviceRPCResponse.getOperationId())) {\r
+      logger\r
+          .debug("Sending the Device RPC response for a configure Multiple object prior operation");\r
+      // Sending the operation response to NBI\r
+      tr069EventNotificationService.sendOperationResultToNBI(deviceRPCResponse);\r
+    }\r
+    return operationRequest;\r
+  }\r
+\r
   /**\r
    * \r
    * 1. Stop the request timer for this device using the session ID received in the cookie of the\r