--- /dev/null
+/*\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.impl;\r
+\r
+import org.commscope.tr069adapter.acs.common.DeviceDetails;\r
+import org.commscope.tr069adapter.acs.common.dto.TR069DeviceDetails;\r
+import org.commscope.tr069adapter.acs.common.exception.DeviceOperationException;\r
+import org.commscope.tr069adapter.acs.common.utils.ErrorCode;\r
+import org.commscope.tr069adapter.acs.requestprocessor.DeviceOperationInterface;\r
+import org.commscope.tr069adapter.acs.requestprocessor.dao.DeviceRepository;\r
+import org.commscope.tr069adapter.acs.requestprocessor.entity.TR069DeviceEntity;\r
+import org.commscope.tr069adapter.acs.requestprocessor.util.TR069NBIUtility;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.slf4j.MDC;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.stereotype.Component;\r
+import org.springframework.transaction.annotation.Isolation;\r
+import org.springframework.transaction.annotation.Propagation;\r
+import org.springframework.transaction.annotation.Transactional;\r
+\r
+@Component\r
+public class DeviceOperationManager implements DeviceOperationInterface {\r
+\r
+ private static final Logger logger = LoggerFactory.getLogger(DeviceOperationManager.class);\r
+\r
+ private static final String CLIENT_STR = "client";\r
+\r
+ @Autowired\r
+ private DeviceRepository deviceRepository;\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see org.commscope.tr069adapter.acs.requestprocessor.DeviceOperationInterface#getDeviceDetails(\r
+ * java.lang.String)\r
+ */\r
+ @Override\r
+ @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 300,\r
+ rollbackFor = RuntimeException.class)\r
+ public TR069DeviceDetails getDeviceDetails(String deviceId) throws DeviceOperationException {\r
+ TR069DeviceDetails tr069DeviceDetails = null;\r
+ TR069DeviceEntity tr069DeviceEntity = deviceRepository.findByDeviceId(deviceId);\r
+ if (tr069DeviceEntity == null) {\r
+ throw new DeviceOperationException(ErrorCode.DEVICE_NOT_EXISTS, deviceId);\r
+ }\r
+ tr069DeviceDetails = TR069NBIUtility.convertToDTO(tr069DeviceEntity);\r
+\r
+\r
+ return tr069DeviceDetails;\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * org.commscope.tr069adapter.acs.requestprocessor.DeviceOperationInterface#updateDeviceDetails(\r
+ * org.commscope.tr069adapter.acs.DeviceDetails)\r
+ */\r
+ @Override\r
+ @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 300,\r
+ rollbackFor = RuntimeException.class)\r
+ public void updateDeviceDetails(DeviceDetails deviceDetails) throws DeviceOperationException {\r
+ try {\r
+ if (deviceDetails != null && deviceDetails.getDeviceId() != null\r
+ && deviceDetails instanceof TR069DeviceDetails) {\r
+ TR069DeviceDetails tr069DeviceDetails = (TR069DeviceDetails) deviceDetails;\r
+ String deviceId = tr069DeviceDetails.getDeviceId();\r
+ MDC.put(CLIENT_STR, deviceId);\r
+ logger.debug("Updating the TR069 device: {}", deviceId);\r
+\r
+ TR069DeviceEntity tr069DeviceEntity =\r
+ deviceRepository.findByDeviceId(tr069DeviceDetails.getDeviceId());\r
+\r
+ TR069DeviceEntity updatedEntity = TR069NBIUtility.convertToEntity(tr069DeviceDetails);\r
+ if (tr069DeviceEntity != null)\r
+ updatedEntity.setId(tr069DeviceEntity.getId());\r
+\r
+ deviceRepository.save(updatedEntity);\r
+\r
+ } else {\r
+ logger.error(\r
+ "The device cannot be null or should be of type TR069DeviceDetails, wrong request for device un-register");\r
+ throw new DeviceOperationException(\r
+ "Invalid device update request, device should be of type TR069DeviceDetails");\r
+ }\r
+ logger.debug("Successfully updated the device");\r
+ } finally {\r
+ MDC.remove(CLIENT_STR);\r
+ }\r
+ }\r
+\r
+}\r