From e4c64afdd38d0f39ceb0c8ee745dd10cbdb3cb6b Mon Sep 17 00:00:00 2001 From: mharindu Date: Tue, 19 May 2015 11:22:19 +0530 Subject: [PATCH 1/2] Refactored device info --- .../impl/android/AndroidDeviceManager.java | 17 ++++++++++++++--- .../android/dao/impl/AndroidDeviceDAOImpl.java | 7 +++---- .../android/util/AndroidPluginConstants.java | 2 +- .../impl/windows/WindowsDeviceManager.java | 2 +- .../mobile/util/MobileDeviceManagementUtil.java | 16 ++++++++-------- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java index 871cc21b3..2760df449 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java @@ -192,9 +192,20 @@ public class AndroidDeviceManager implements DeviceMgtService { } @Override - public boolean updateDeviceInfo(Device device, List applicationList) throws DeviceManagementException { + public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { boolean status; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + Device deviceDB = this.getDevice(deviceIdentifier); + // This object holds the current persisted device object + MobileDevice mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB); + + // This object holds the newly received device object from response + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + + // Updating current object features using newer ones + mobileDeviceDB.setLatitude(mobileDevice.getLatitude()); + mobileDeviceDB.setLongitude(mobileDevice.getLongitude()); + mobileDeviceDB.setDeviceProperties(mobileDevice.getDeviceProperties()); + try { if (log.isDebugEnabled()) { log.debug( @@ -202,7 +213,7 @@ public class AndroidDeviceManager implements DeviceMgtService { } AndroidDAOFactory.beginTransaction(); status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .updateMobileDevice(mobileDevice); + .updateMobileDevice(mobileDeviceDB); AndroidDAOFactory.commitTransaction(); } catch (MobileDeviceManagementDAOException e) { try { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java index bec580a5b..b980e3c0a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java @@ -123,11 +123,10 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{ mobileDevice.setDeviceProperties(new HashMap()); } - stmt.setString(2, AndroidUtils.getDeviceProperty( - mobileDevice.getDeviceProperties(), + stmt.setString(2, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), AndroidPluginConstants.GCM_TOKEN)); stmt.setString(3, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), - AndroidPluginConstants.DEVICE_INFO)); + AndroidPluginConstants.DEVICE_INFO)); stmt.setString(4, mobileDevice.getSerial()); stmt.setString(5, mobileDevice.getVendor()); stmt.setString(6, mobileDevice.getMobileDeviceId()); @@ -135,7 +134,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{ AndroidPluginConstants.DEVICE_NAME)); stmt.setString(8, mobileDevice.getLongitude()); stmt.setString(9, mobileDevice.getLongitude()); - stmt.setString(10, mobileDevice.getImsi()); + stmt.setString(10, mobileDevice.getImei()); stmt.setString(11, mobileDevice.getImsi()); stmt.setString(12, mobileDevice.getOsVersion()); stmt.setString(13, mobileDevice.getModel()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java index ea658bd72..56837f259 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java @@ -33,7 +33,7 @@ public class AndroidPluginConstants { public static final String LATITUDE = "LATITUDE"; public static final String LONGITUDE = "LONGITUDE"; public static final String IMEI = "IMEI"; - public static final String IMSI = "IMEI"; + public static final String IMSI = "IMSI"; public static final String VENDOR = "VENDOR"; public static final String OS_VERSION = "OS_VERSION"; public static final String MAC_ADDRESS = "MAC_ADDRESS"; 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 d84f2c6f2..006cbe178 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 @@ -97,7 +97,7 @@ public class WindowsDeviceManager implements DeviceMgtService { } @Override - public boolean updateDeviceInfo(Device device, List applicationList) throws DeviceManagementException { + public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { return true; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java index 4e75bebbe..5d7f8b35f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java @@ -38,14 +38,14 @@ import java.util.*; public class MobileDeviceManagementUtil { private static final Log log = LogFactory.getLog(MobileDeviceManagementUtil.class); - private static final String MOBILE_DEVICE_IMEI = "imei"; - private static final String MOBILE_DEVICE_IMSI = "imsi"; - private static final String MOBILE_DEVICE_VENDOR = "vendor"; - private static final String MOBILE_DEVICE_OS_VERSION = "osVersion"; - private static final String MOBILE_DEVICE_MODEL = "model"; - private static final String MOBILE_DEVICE_LATITUDE = "latitude"; - private static final String MOBILE_DEVICE_LONGITUDE = "longitude"; - private static final String MOBILE_DEVICE_SERIAL = "serial"; + private static final String MOBILE_DEVICE_IMEI = "IMEI"; + private static final String MOBILE_DEVICE_IMSI = "IMSI"; + private static final String MOBILE_DEVICE_VENDOR = "VENDOR"; + private static final String MOBILE_DEVICE_OS_VERSION = "OS_VERSION"; + private static final String MOBILE_DEVICE_MODEL = "DEVICE_MODEL"; + private static final String MOBILE_DEVICE_LATITUDE = "LATITUDE"; + private static final String MOBILE_DEVICE_LONGITUDE = "LONGITUDE"; + private static final String MOBILE_DEVICE_SERIAL = "SERIAL"; public static Document convertToDocument(File file) throws DeviceManagementException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); From 679cc35265b079e2ba57c0d8c52c71422c910351 Mon Sep 17 00:00:00 2001 From: Milan Perera Date: Tue, 19 May 2015 17:45:39 +0530 Subject: [PATCH 2/2] Update AndroidDeviceManager.java --- .../device/mgt/mobile/impl/android/AndroidDeviceManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java index 2760df449..a6e2165c5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java @@ -196,7 +196,7 @@ public class AndroidDeviceManager implements DeviceMgtService { boolean status; Device deviceDB = this.getDevice(deviceIdentifier); // This object holds the current persisted device object - MobileDevice mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB); + MobileDevice mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB); // This object holds the newly received device object from response MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); @@ -259,4 +259,4 @@ public class AndroidDeviceManager implements DeviceMgtService { throws AppManagerConnectorException { } -} \ No newline at end of file +}