From b58b8c931b3308dc6ea50ec977a5cc87c92fff98 Mon Sep 17 00:00:00 2001 From: Gimhan-minion Date: Mon, 29 May 2023 23:05:01 +0530 Subject: [PATCH 1/2] Implement DeleteDeviceLocation method for deleting location from a device --- .../details/mgt/DeviceInformationManager.java | 2 ++ .../impl/DeviceInformationManagerImpl.java | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/DeviceInformationManager.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/DeviceInformationManager.java index 1da701f09e..fdf98a86a5 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/DeviceInformationManager.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/DeviceInformationManager.java @@ -80,6 +80,8 @@ public interface DeviceInformationManager { void addDeviceLocation(Device device, DeviceLocation deviceLocation) throws DeviceDetailsMgtException; + void deleteDeviceLocation(Device device) throws DeviceDetailsMgtException; + void addDeviceLocations(Device device, List deviceLocations) throws DeviceDetailsMgtException; diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java index a719273d1f..5c54bc8ea1 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java @@ -53,7 +53,6 @@ import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutionException; public class DeviceInformationManagerImpl implements DeviceInformationManager { @@ -417,6 +416,29 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { } } + @Override + public void deleteDeviceLocation(Device device) throws DeviceDetailsMgtException { + try { + DeviceManagementDAOFactory.beginTransaction(); + DeviceLocation deviceLocation = deviceDetailsDAO.getDeviceLocation(device.getId(), + device.getEnrolmentInfo().getId()); + if (deviceLocation != null) { + deviceDetailsDAO.deleteDeviceLocation(device.getId(), device.getEnrolmentInfo().getId()); + } else { + throw new DeviceDetailsMgtException("Device location not found."); + } + DeviceManagementDAOFactory.commitTransaction(); + } catch (TransactionManagementException e) { + throw new DeviceDetailsMgtException("Transactional error occurred while deleting the device location " + "information.", e); + } catch (DeviceDetailsMgtDAOException e) { + DeviceManagementDAOFactory.rollbackTransaction(); + throw new DeviceDetailsMgtException("Error occurred while deleting the device location information.", e); + } finally { + DeviceManagementDAOFactory.closeConnection(); + } + } + + @Override public void addDeviceLocations(Device device, List deviceLocations) throws DeviceDetailsMgtException { try { From a6a9e82c35a2069ac9865096476c0d158cc9d0f2 Mon Sep 17 00:00:00 2001 From: Gimhan-minion Date: Thu, 1 Jun 2023 21:57:05 +0530 Subject: [PATCH 2/2] Update debug and error logs --- .../mgt/impl/DeviceInformationManagerImpl.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java index 5c54bc8ea1..13867d1d4d 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java @@ -419,26 +419,32 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { @Override public void deleteDeviceLocation(Device device) throws DeviceDetailsMgtException { try { + if (log.isDebugEnabled()) { + log.debug("Deleting device location for device: " + device.getId()); + } DeviceManagementDAOFactory.beginTransaction(); DeviceLocation deviceLocation = deviceDetailsDAO.getDeviceLocation(device.getId(), device.getEnrolmentInfo().getId()); if (deviceLocation != null) { deviceDetailsDAO.deleteDeviceLocation(device.getId(), device.getEnrolmentInfo().getId()); } else { - throw new DeviceDetailsMgtException("Device location not found."); + log.error("Device location not found for device: " + device.getId()); + throw new DeviceDetailsMgtException("Device location not found for device: " + device.getId()); } DeviceManagementDAOFactory.commitTransaction(); } catch (TransactionManagementException e) { - throw new DeviceDetailsMgtException("Transactional error occurred while deleting the device location " + "information.", e); + log.error("Transactional error occurred while deleting the device location information. Device ID: " + device.getId(), e); + throw new DeviceDetailsMgtException("Transactional error occurred while deleting the device location " + + "information.", e); } catch (DeviceDetailsMgtDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); + log.error("Error occurred while deleting the device location information. Device ID: " + device.getId(), e); throw new DeviceDetailsMgtException("Error occurred while deleting the device location information.", e); } finally { DeviceManagementDAOFactory.closeConnection(); } } - @Override public void addDeviceLocations(Device device, List deviceLocations) throws DeviceDetailsMgtException { try {