From 69299b69e8ddfba9945c8367feb058f8a748a5a6 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Tue, 2 Feb 2016 18:00:01 +0530 Subject: [PATCH] fixed code issues --- .../impl/windows/WindowsFeatureManager.java | 2 +- .../impl/windows/dao/WindowsDAOFactory.java | 3 +- .../dao/impl/WindowsDeviceDAOImpl.java | 23 ++----------- .../impl/windows/util/WindowsUtils.java | 34 ++++++++++++++++++- 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java index 00e1d5e00..8bd2bac39 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java @@ -116,13 +116,13 @@ public class WindowsFeatureManager implements FeatureManager { featureDAO.deleteFeatureByCode(code); WindowsDAOFactory.commitTransaction(); status = true; + return status; } catch (MobileDeviceManagementDAOException e) { WindowsDAOFactory.rollbackTransaction(); throw new DeviceManagementException("Error occurred while removing the feature", e); } finally { WindowsDAOFactory.closeConnection(); } - 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/WindowsDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java index 40f8cc46e..7fd0461c4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java @@ -39,7 +39,8 @@ public class WindowsDAOFactory extends AbstractMobileDeviceManagementDAOFactory private static ThreadLocal currentConnection = new ThreadLocal<>(); public WindowsDAOFactory() { - this.dataSource = getDataSourceMap().get(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + this.dataSource = getDataSourceMap().get( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); } @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 478942b03..c65e01e1f 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 @@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; 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.impl.windows.util.WindowsPluginConstants; +import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsUtils; import java.sql.Connection; import java.sql.PreparedStatement; @@ -60,17 +61,7 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { rs = stmt.executeQuery(); while (rs.next()) { - mobileDevice = new MobileDevice(); - mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.DEVICE_ID)); - mobileDevice.setImei(rs.getString(WindowsPluginConstants.IMEI)); - mobileDevice.setImsi(rs.getString(WindowsPluginConstants.IMSI)); - mobileDevice.setModel(rs.getString(WindowsPluginConstants.DEVICE_MODEL)); - mobileDevice.setVendor(rs.getString(WindowsPluginConstants.VENDOR)); - mobileDevice.setLatitude(rs.getString(WindowsPluginConstants.LATITUDE)); - mobileDevice.setLongitude(rs.getString(WindowsPluginConstants.LONGITUDE)); - mobileDevice.setSerial(rs.getString(WindowsPluginConstants.SERIAL)); - mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE)); - + mobileDevice = WindowsUtils.loadMobileDevices(rs); Map propertyMap = new HashMap<>(); propertyMap.put(WindowsPluginConstants.CHANNEL_URI, rs.getString(WindowsPluginConstants.CHANNEL_URI)); propertyMap.put(WindowsPluginConstants.DEVICE_INFO, rs.getString(WindowsPluginConstants.DEVICE_INFO)); @@ -225,15 +216,7 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { rs = stmt.executeQuery(); while (rs.next()) { - mobileDevice = new MobileDevice(); - mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.DEVICE_ID)); - mobileDevice.setVendor(rs.getString(WindowsPluginConstants.IMEI)); - mobileDevice.setLatitude(rs.getString(WindowsPluginConstants.IMSI)); - mobileDevice.setLongitude(rs.getString(WindowsPluginConstants.OS_VERSION)); - mobileDevice.setImei(rs.getString(WindowsPluginConstants.DEVICE_MODEL)); - mobileDevice.setImsi(rs.getString(WindowsPluginConstants.VENDOR)); - mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE)); - + mobileDevice = WindowsUtils.loadMatchingMobileDevices(rs); Map propertyMap = new HashMap<>(); propertyMap.put(WindowsPluginConstants.CHANNEL_URI, rs.getString(WindowsPluginConstants.CHANNEL_URI)); propertyMap.put(WindowsPluginConstants.DEVICE_INFO, rs.getString(WindowsPluginConstants.DEVICE_INFO)); 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 fabcbc70e..346be69de 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 @@ -18,12 +18,17 @@ package org.wso2.carbon.device.mgt.mobile.impl.windows.util; +import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; + +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.Map; /** - * Contains utility methods used by Windows plugin. + * Contains utility methods which are used by Windows plugin. */ public class WindowsUtils { + public static String getDeviceProperty(Map deviceProperties, String property) { String deviceProperty = deviceProperties.get(property); @@ -32,4 +37,31 @@ public class WindowsUtils { } return deviceProperty; } + + public static MobileDevice loadMobileDevices(ResultSet rs) throws SQLException { + + MobileDevice mobileDevice = new MobileDevice(); + mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.DEVICE_ID)); + mobileDevice.setImei(rs.getString(WindowsPluginConstants.IMEI)); + mobileDevice.setImsi(rs.getString(WindowsPluginConstants.IMSI)); + mobileDevice.setModel(rs.getString(WindowsPluginConstants.DEVICE_MODEL)); + mobileDevice.setVendor(rs.getString(WindowsPluginConstants.VENDOR)); + mobileDevice.setLatitude(rs.getString(WindowsPluginConstants.LATITUDE)); + mobileDevice.setLongitude(rs.getString(WindowsPluginConstants.LONGITUDE)); + mobileDevice.setSerial(rs.getString(WindowsPluginConstants.SERIAL)); + mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE)); + return mobileDevice; + } + + public static MobileDevice loadMatchingMobileDevices(ResultSet rs) throws SQLException { + MobileDevice mobileDevice = new MobileDevice(); + mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.DEVICE_ID)); + mobileDevice.setVendor(rs.getString(WindowsPluginConstants.IMEI)); + mobileDevice.setLatitude(rs.getString(WindowsPluginConstants.IMSI)); + mobileDevice.setLongitude(rs.getString(WindowsPluginConstants.OS_VERSION)); + mobileDevice.setImei(rs.getString(WindowsPluginConstants.DEVICE_MODEL)); + mobileDevice.setImsi(rs.getString(WindowsPluginConstants.VENDOR)); + mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE)); + return mobileDevice; + } }