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 1da701f09e7..fdf98a86a59 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 a719273d1f6..5c54bc8ea16 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 {