Merge pull request 'Implement DeleteDeviceLocation method for deleting location from a device' (#128) from Gimhan-minion/device-mgt-core:dev into master

Reviewed-on: community/device-mgt-core#128
vpp-v2
commit 743d5c09ec

@ -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<DeviceLocation> deviceLocations) throws
DeviceDetailsMgtException;

@ -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,35 @@ 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 {
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) {
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<DeviceLocation> deviceLocations) throws DeviceDetailsMgtException {
try {

Loading…
Cancel
Save