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) {
log.error("Error occurred while adding default license for Windows devices", 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
public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
throws DeviceManagementException {
public boolean saveConfiguration(TenantConfiguration tenantConfiguration) throws DeviceManagementException {
boolean status;
Resource resource;
try {
@ -88,8 +87,7 @@ public class WindowsDeviceManager implements DeviceManager {
log.debug("Persisting windows configurations in Registry");
}
String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath(
DeviceManagementConstants.
MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
StringWriter writer = new StringWriter();
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
Marshaller marshaller = context.createMarshaller();
@ -143,14 +141,16 @@ public class WindowsDeviceManager implements DeviceManager {
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
boolean status;
boolean status = false;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try {
if (log.isDebugEnabled()) {
log.debug("Modifying the Windows device enrollment data");
}
WindowsDAOFactory.beginTransaction();
if (daoFactory.getMobileDeviceDAO() != null) {
status = daoFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice);
}
WindowsDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) {
WindowsDAOFactory.rollbackTransaction();
@ -170,22 +170,21 @@ public class WindowsDeviceManager implements DeviceManager {
@Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
boolean isEnrolled = false;
MobileDevice mobileDevice;
try {
if (log.isDebugEnabled()) {
log.debug("Checking the enrollment of Windows device : " + deviceId.getId());
}
MobileDevice mobileDevice =
daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
if (mobileDevice != null) {
isEnrolled = true;
if (daoFactory.getMobileDeviceDAO() != null) {
mobileDevice = daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
} else {
throw new DeviceManagementException("Error occurred while getting DAO object.");
}
} catch (MobileDeviceManagementDAOException e) {
String msg = "Error while checking the enrollment status of Windows device : " +
deviceId.getId();
String msg = "Error occurred while checking the enrollment status of Windows device : " + deviceId.getId();
throw new DeviceManagementException(msg, e);
}
return isEnrolled;
return (mobileDevice != null);
}
@Override
@ -201,12 +200,15 @@ public class WindowsDeviceManager implements DeviceManager {
public List<Device> getAllDevices() throws DeviceManagementException {
List<Device> devices = null;
List<MobileDevice> mobileDevices = null;
try {
if (log.isDebugEnabled()) {
log.debug("Fetching the details of all Windows devices");
}
WindowsDAOFactory.openConnection();
List<MobileDevice> mobileDevices = daoFactory.getMobileDeviceDAO().getAllMobileDevices();
if (daoFactory.getMobileDeviceDAO() != null) {
mobileDevices = daoFactory.getMobileDeviceDAO().getAllMobileDevices();
}
if (mobileDevices != null) {
devices = new ArrayList<>(mobileDevices.size());
for (MobileDevice mobileDevice : mobileDevices) {
@ -224,13 +226,15 @@ public class WindowsDeviceManager implements DeviceManager {
@Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
Device device = null;
MobileDevice mobileDevice = null;
try {
if (log.isDebugEnabled()) {
log.debug("Getting the details of Windows device : '" + deviceId.getId() + "'");
}
WindowsDAOFactory.openConnection();
MobileDevice mobileDevice = daoFactory.getMobileDeviceDAO().
getMobileDevice(deviceId.getId());
if (daoFactory.getMobileDeviceDAO() != null) {
mobileDevice = daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
}
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
} catch (MobileDeviceManagementDAOException e) {
throw new DeviceManagementException(
@ -293,7 +297,9 @@ public class WindowsDeviceManager implements DeviceManager {
this.modifyEnrollment(device);
} else {
WindowsDAOFactory.beginTransaction();
if (daoFactory.getMobileDeviceDAO() != null) {
status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice);
}
WindowsDAOFactory.commitTransaction();
}
} 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.dto.MobileFeature;
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 java.util.ArrayList;
@ -145,48 +146,49 @@ public class WindowsFeatureManager implements FeatureManager {
* @return Supported features.
*/
public static List<Feature> getSupportedFeatures() {
List<Feature> supportedFeatures = new ArrayList<Feature>();
Feature feature = new Feature();
List<Feature> supportedFeatures = new ArrayList<>();
Feature feature;
feature = WindowsUtils.getMobileFeature();
feature.setCode("DEVICE_LOCK");
feature.setName("Device Lock");
feature.setDescription("Lock the device");
supportedFeatures.add(feature);
feature = new Feature();
feature = WindowsUtils.getMobileFeature();
feature.setCode("CAMERA");
feature.setName("camera");
feature.setDescription("Enable or disable camera");
supportedFeatures.add(feature);
feature = new Feature();
feature = WindowsUtils.getMobileFeature();
feature.setCode("DEVICE_INFO");
feature.setName("Device info");
feature.setDescription("Request device information");
supportedFeatures.add(feature);
feature = new Feature();
feature = WindowsUtils.getMobileFeature();
feature.setCode("WIPE_DATA");
feature.setName("Wipe Data");
feature.setDescription("Factory reset the device");
supportedFeatures.add(feature);
feature = new Feature();
feature = WindowsUtils.getMobileFeature();
feature.setCode("ENCRYPT_STORAGE");
feature.setName("Encrypt storage");
feature.setDescription("Encrypt storage");
supportedFeatures.add(feature);
feature = new Feature();
feature = WindowsUtils.getMobileFeature();
feature.setCode("DEVICE_RING");
feature.setName("Ring");
feature.setDescription("Ring the device");
supportedFeatures.add(feature);
feature = new Feature();
feature = WindowsUtils.getMobileFeature();
feature.setCode("PASSCODE_POLICY");
feature.setName("Password Policy");
feature.setDescription("Set passcode policy");
supportedFeatures.add(feature);
feature = new Feature();
feature = WindowsUtils.getMobileFeature();
feature.setCode("DISENROLL");
feature.setName("DisEnroll");
feature.setDescription("DisEnroll the device");
supportedFeatures.add(feature);
feature = new Feature();
feature = WindowsUtils.getMobileFeature();
feature.setCode("LOCK_RESET");
feature.setName("LockReset");
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;
/**
* Implement Exception class for Windows Device Features.
* This class responsible for wrapping exceptions related on Windows device features.
*/
public class WindowsFeatureManagementDAOException extends MobileDeviceManagementDAOException {

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

@ -18,6 +18,7 @@
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 java.sql.ResultSet;
@ -41,4 +42,8 @@ public class WindowsUtils {
mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE));
return mobileDevice;
}
public static Feature getMobileFeature() {
Feature feature = new Feature();
return feature;
}
}

Loading…
Cancel
Save