diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java index 08f686ad2..bdf06bbf0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java @@ -18,19 +18,14 @@ package org.wso2.carbon.device.mgt.mobile.impl.windows; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; -import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; import java.util.List; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java index 0116cb8dc..4564b891f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java @@ -101,10 +101,10 @@ public class WindowsDeviceManager implements DeviceManager { public TenantConfiguration getConfiguration() throws DeviceManagementException { Resource resource; try { - String androidRegPath = + String windowsRegPath = MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants. MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - resource = MobileDeviceManagementUtil.getRegistryResource(androidRegPath); + resource = MobileDeviceManagementUtil.getRegistryResource(windowsRegPath); JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); Unmarshaller unmarshaller = context.createUnmarshaller(); return (TenantConfiguration) unmarshaller.unmarshal( @@ -152,7 +152,27 @@ public class WindowsDeviceManager implements DeviceManager { @Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - return true; + boolean status; + try { + if (log.isDebugEnabled()) { + log.debug("Dis-enrolling windows device : " + deviceId); + } + WindowsDAOFactory.beginTransaction(); + status = daoFactory.getMobileDeviceDAO().deleteMobileDevice(deviceId.getId()); + WindowsDAOFactory.commitTransaction(); + } catch (MobileDeviceManagementDAOException e) { + try { + WindowsDAOFactory.rollbackTransaction(); + } catch (MobileDeviceManagementDAOException mobileDAOEx) { + String msg = "Error occurred while roll back the device dis enrol transaction :" + + deviceId.toString(); + log.warn(msg, mobileDAOEx); + } + String msg = "Error while removing the Windows device : " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java index d28b790ac..1c0e8b301 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java @@ -156,7 +156,30 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { @Override public boolean deleteMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException { - return false; + boolean status = false; + Connection conn; + PreparedStatement stmt = null; + try { + conn = WindowsDAOFactory.getConnection(); + String deleteDBQuery = + "DELETE FROM WINDOWS_DEVICE WHERE MOBILE_DEVICE_ID = ?"; + stmt = conn.prepareStatement(deleteDBQuery); + stmt.setString(1, mblDeviceId); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Windows device " + mblDeviceId + " data has deleted" + + " from the windows database."); + } + } + } catch (SQLException e) { + throw new MobileDeviceManagementDAOException("Error occurred while deleting windows device '" + + mblDeviceId + "'", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsUtils.java index b782d7461..43e41c267 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsUtils.java @@ -19,7 +19,7 @@ import java.util.Map; /** * - * Contains utility methods used by Android plugin. + * Contains utility methods used by Windows plugin. */ public class WindowsUtils { public static String getDeviceProperty(Map deviceProperties, String property) {