refactored windows device disenrollment

revert-dabc3590
hasuniea 9 years ago
parent 2177d2b987
commit e394783668

@ -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;

@ -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

@ -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

@ -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<String, String> deviceProperties, String property) {

Loading…
Cancel
Save