refactored code issues

revert-dabc3590
hasuniea 9 years ago
parent f32bdf4021
commit 7aeecf7345

@ -69,7 +69,7 @@ public class WindowsDeviceManager implements DeviceManager {
} catch (LicenseManagementException e) { } catch (LicenseManagementException e) {
log.error("Error occurred while adding default license for Windows devices", e); log.error("Error occurred while adding default license for Windows devices", e);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while adding supported device features for Windows platform", e); throw new IllegalStateException("Error occurred while adding windows features to the DB.");
} }
} }
@ -79,8 +79,7 @@ public class WindowsDeviceManager implements DeviceManager {
} }
@Override @Override
public boolean saveConfiguration(TenantConfiguration tenantConfiguration) public boolean saveConfiguration(TenantConfiguration tenantConfiguration) throws DeviceManagementException {
throws DeviceManagementException {
boolean status; boolean status;
Resource resource; Resource resource;
try { try {
@ -88,8 +87,7 @@ public class WindowsDeviceManager implements DeviceManager {
log.debug("Persisting windows configurations in Registry"); log.debug("Persisting windows configurations in Registry");
} }
String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath( String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath(
DeviceManagementConstants. DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
Marshaller marshaller = context.createMarshaller(); Marshaller marshaller = context.createMarshaller();
@ -143,14 +141,16 @@ public class WindowsDeviceManager implements DeviceManager {
@Override @Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException { public boolean modifyEnrollment(Device device) throws DeviceManagementException {
boolean status; boolean status = false;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Modifying the Windows device enrollment data"); log.debug("Modifying the Windows device enrollment data");
} }
WindowsDAOFactory.beginTransaction(); WindowsDAOFactory.beginTransaction();
status = daoFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice); if (daoFactory.getMobileDeviceDAO() != null) {
status = daoFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice);
}
WindowsDAOFactory.commitTransaction(); WindowsDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
WindowsDAOFactory.rollbackTransaction(); WindowsDAOFactory.rollbackTransaction();
@ -170,22 +170,21 @@ public class WindowsDeviceManager implements DeviceManager {
@Override @Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
boolean isEnrolled = false; MobileDevice mobileDevice;
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Checking the enrollment of Windows device : " + deviceId.getId()); log.debug("Checking the enrollment of Windows device : " + deviceId.getId());
} }
MobileDevice mobileDevice = if (daoFactory.getMobileDeviceDAO() != null) {
daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId()); mobileDevice = daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
if (mobileDevice != null) { } else {
isEnrolled = true; throw new DeviceManagementException("Error occurred while getting DAO object.");
} }
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while checking the enrollment status of Windows device : " + String msg = "Error occurred while checking the enrollment status of Windows device : " + deviceId.getId();
deviceId.getId();
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
return isEnrolled; return (mobileDevice != null);
} }
@Override @Override
@ -201,12 +200,15 @@ public class WindowsDeviceManager implements DeviceManager {
public List<Device> getAllDevices() throws DeviceManagementException { public List<Device> getAllDevices() throws DeviceManagementException {
List<Device> devices = null; List<Device> devices = null;
List<MobileDevice> mobileDevices = null;
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Fetching the details of all Windows devices"); log.debug("Fetching the details of all Windows devices");
} }
WindowsDAOFactory.openConnection(); WindowsDAOFactory.openConnection();
List<MobileDevice> mobileDevices = daoFactory.getMobileDeviceDAO().getAllMobileDevices(); if (daoFactory.getMobileDeviceDAO() != null) {
mobileDevices = daoFactory.getMobileDeviceDAO().getAllMobileDevices();
}
if (mobileDevices != null) { if (mobileDevices != null) {
devices = new ArrayList<>(mobileDevices.size()); devices = new ArrayList<>(mobileDevices.size());
for (MobileDevice mobileDevice : mobileDevices) { for (MobileDevice mobileDevice : mobileDevices) {
@ -224,13 +226,15 @@ public class WindowsDeviceManager implements DeviceManager {
@Override @Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
Device device = null; Device device = null;
MobileDevice mobileDevice = null;
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting the details of Windows device : '" + deviceId.getId() + "'"); log.debug("Getting the details of Windows device : '" + deviceId.getId() + "'");
} }
WindowsDAOFactory.openConnection(); WindowsDAOFactory.openConnection();
MobileDevice mobileDevice = daoFactory.getMobileDeviceDAO(). if (daoFactory.getMobileDeviceDAO() != null) {
getMobileDevice(deviceId.getId()); mobileDevice = daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
}
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
throw new DeviceManagementException( throw new DeviceManagementException(
@ -293,7 +297,9 @@ public class WindowsDeviceManager implements DeviceManager {
this.modifyEnrollment(device); this.modifyEnrollment(device);
} else { } else {
WindowsDAOFactory.beginTransaction(); WindowsDAOFactory.beginTransaction();
status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice); if (daoFactory.getMobileDeviceDAO() != null) {
status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice);
}
WindowsDAOFactory.commitTransaction(); WindowsDAOFactory.commitTransaction();
} }
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {

@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory; import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory;
import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsUtils;
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
import java.util.ArrayList; import java.util.ArrayList;
@ -145,48 +146,49 @@ public class WindowsFeatureManager implements FeatureManager {
* @return Supported features. * @return Supported features.
*/ */
public static List<Feature> getSupportedFeatures() { public static List<Feature> getSupportedFeatures() {
List<Feature> supportedFeatures = new ArrayList<Feature>(); List<Feature> supportedFeatures = new ArrayList<>();
Feature feature = new Feature(); Feature feature;
feature = WindowsUtils.getMobileFeature();
feature.setCode("DEVICE_LOCK"); feature.setCode("DEVICE_LOCK");
feature.setName("Device Lock"); feature.setName("Device Lock");
feature.setDescription("Lock the device"); feature.setDescription("Lock the device");
supportedFeatures.add(feature); supportedFeatures.add(feature);
feature = new Feature(); feature = WindowsUtils.getMobileFeature();
feature.setCode("CAMERA"); feature.setCode("CAMERA");
feature.setName("camera"); feature.setName("camera");
feature.setDescription("Enable or disable camera"); feature.setDescription("Enable or disable camera");
supportedFeatures.add(feature); supportedFeatures.add(feature);
feature = new Feature(); feature = WindowsUtils.getMobileFeature();
feature.setCode("DEVICE_INFO"); feature.setCode("DEVICE_INFO");
feature.setName("Device info"); feature.setName("Device info");
feature.setDescription("Request device information"); feature.setDescription("Request device information");
supportedFeatures.add(feature); supportedFeatures.add(feature);
feature = new Feature(); feature = WindowsUtils.getMobileFeature();
feature.setCode("WIPE_DATA"); feature.setCode("WIPE_DATA");
feature.setName("Wipe Data"); feature.setName("Wipe Data");
feature.setDescription("Factory reset the device"); feature.setDescription("Factory reset the device");
supportedFeatures.add(feature); supportedFeatures.add(feature);
feature = new Feature(); feature = WindowsUtils.getMobileFeature();
feature.setCode("ENCRYPT_STORAGE"); feature.setCode("ENCRYPT_STORAGE");
feature.setName("Encrypt storage"); feature.setName("Encrypt storage");
feature.setDescription("Encrypt storage"); feature.setDescription("Encrypt storage");
supportedFeatures.add(feature); supportedFeatures.add(feature);
feature = new Feature(); feature = WindowsUtils.getMobileFeature();
feature.setCode("DEVICE_RING"); feature.setCode("DEVICE_RING");
feature.setName("Ring"); feature.setName("Ring");
feature.setDescription("Ring the device"); feature.setDescription("Ring the device");
supportedFeatures.add(feature); supportedFeatures.add(feature);
feature = new Feature(); feature = WindowsUtils.getMobileFeature();
feature.setCode("PASSCODE_POLICY"); feature.setCode("PASSCODE_POLICY");
feature.setName("Password Policy"); feature.setName("Password Policy");
feature.setDescription("Set passcode policy"); feature.setDescription("Set passcode policy");
supportedFeatures.add(feature); supportedFeatures.add(feature);
feature = new Feature(); feature = WindowsUtils.getMobileFeature();
feature.setCode("DISENROLL"); feature.setCode("DISENROLL");
feature.setName("DisEnroll"); feature.setName("DisEnroll");
feature.setDescription("DisEnroll the device"); feature.setDescription("DisEnroll the device");
supportedFeatures.add(feature); supportedFeatures.add(feature);
feature = new Feature(); feature = WindowsUtils.getMobileFeature();
feature.setCode("LOCK_RESET"); feature.setCode("LOCK_RESET");
feature.setName("LockReset"); feature.setName("LockReset");
feature.setDescription("Lock Reset device"); feature.setDescription("Lock Reset device");

@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.mobile.impl.windows.dao;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
/** /**
* Implement Exception class for Windows Device Features. * This class responsible for wrapping exceptions related on Windows device features.
*/ */
public class WindowsFeatureManagementDAOException extends MobileDeviceManagementDAOException { public class WindowsFeatureManagementDAOException extends MobileDeviceManagementDAOException {

@ -43,10 +43,6 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO {
private static final Log log = LogFactory.getLog(WindowsFeatureDAOImpl.class); private static final Log log = LogFactory.getLog(WindowsFeatureDAOImpl.class);
public WindowsFeatureDAOImpl() {
}
@Override @Override
public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;

@ -18,6 +18,7 @@
package org.wso2.carbon.device.mgt.mobile.impl.windows.util; package org.wso2.carbon.device.mgt.mobile.impl.windows.util;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -41,4 +42,8 @@ public class WindowsUtils {
mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE)); mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE));
return mobileDevice; return mobileDevice;
} }
public static Feature getMobileFeature() {
Feature feature = new Feature();
return feature;
}
} }

Loading…
Cancel
Save