From dcf222d2c16bcb3002899afa81968ee473b53f67 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 23 Jan 2015 11:29:33 +0530 Subject: [PATCH 1/3] Reverted changes back to the list implementation. The Map conversion is not properly supported in CFX --- .../util/MobileDeviceManagementUtil.java | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) 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 78b120e48..482136f08 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 @@ -59,20 +59,38 @@ public class MobileDeviceManagementUtil { "to a org.w3c.dom.Document : " + e.getMessage(), e); } } + private static String getPropertyValue(Device device, String property) { + for (Device.Property prop : device.getProperties()) { + if (property.equals(prop.getName())) { + return prop.getValue(); + } + } + return null; + } + private static Device.Property getProperty(String property, String value) { + Device.Property prop = null; + if (property != null) { + prop = new Device.Property(); + prop.setName(property); + prop.setValue(value); + return prop; + } + return prop; + } public static MobileDevice convertToMobileDevice(Device device) { MobileDevice mobileDevice = null; if (device != null) { mobileDevice = new MobileDevice(); mobileDevice.setMobileDeviceId(device.getDeviceIdentifier()); - mobileDevice.setImei(device.getProperties().get(MOBILE_DEVICE_IMEI)); - mobileDevice.setImsi(device.getProperties().get(MOBILE_DEVICE_IMSI)); - mobileDevice.setRegId(device.getProperties().get(MOBILE_DEVICE_REG_ID)); - mobileDevice.setModel(device.getProperties().get(MOBILE_DEVICE_MODEL)); - mobileDevice.setOsVersion(device.getProperties().get(MOBILE_DEVICE_OS_VERSION)); - mobileDevice.setVendor(device.getProperties().get(MOBILE_DEVICE_VENDOR)); - mobileDevice.setLatitude(device.getProperties().get(MOBILE_DEVICE_LATITUDE)); - mobileDevice.setLongitude(device.getProperties().get(MOBILE_DEVICE_LONGITUDE)); + mobileDevice.setImei(getPropertyValue(device, MOBILE_DEVICE_IMEI)); + mobileDevice.setImsi(getPropertyValue(device, MOBILE_DEVICE_IMSI)); + mobileDevice.setRegId(getPropertyValue(device, MOBILE_DEVICE_REG_ID)); + mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL)); + mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION)); + mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR)); + mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE)); + mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE)); } return mobileDevice; } @@ -81,16 +99,16 @@ public class MobileDeviceManagementUtil { Device device = null; if (mobileDevice != null) { device = new Device(); - Map propertyMap = new HashMap(); - propertyMap.put(MOBILE_DEVICE_IMEI, mobileDevice.getImei()); - propertyMap.put(MOBILE_DEVICE_IMSI, mobileDevice.getImsi()); - propertyMap.put(MOBILE_DEVICE_REG_ID, mobileDevice.getRegId()); - propertyMap.put(MOBILE_DEVICE_MODEL, mobileDevice.getModel()); - propertyMap.put(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion()); - propertyMap.put(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor()); - propertyMap.put(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude()); - propertyMap.put(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude()); - device.setProperties(propertyMap); + List propertyList = new ArrayList(); + propertyList.add(getProperty(MOBILE_DEVICE_IMEI, mobileDevice.getImei())); + propertyList.add(getProperty(MOBILE_DEVICE_IMSI, mobileDevice.getImsi())); + propertyList.add(getProperty(MOBILE_DEVICE_REG_ID, mobileDevice.getRegId())); + propertyList.add(getProperty(MOBILE_DEVICE_MODEL, mobileDevice.getModel())); + propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion())); + propertyList.add(getProperty(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor())); + propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude())); + propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude())); + device.setProperties(propertyList); device.setDeviceIdentifier(mobileDevice.getMobileDeviceId()); } return device; From 24184b48a7ebe31a0b98835c12753b144e9db707 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 23 Jan 2015 11:29:33 +0530 Subject: [PATCH 2/3] Reverted changes back to the list implementation. The Map conversion is not properly supported in CXF --- .../util/MobileDeviceManagementUtil.java | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) 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 78b120e48..482136f08 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 @@ -59,20 +59,38 @@ public class MobileDeviceManagementUtil { "to a org.w3c.dom.Document : " + e.getMessage(), e); } } + private static String getPropertyValue(Device device, String property) { + for (Device.Property prop : device.getProperties()) { + if (property.equals(prop.getName())) { + return prop.getValue(); + } + } + return null; + } + private static Device.Property getProperty(String property, String value) { + Device.Property prop = null; + if (property != null) { + prop = new Device.Property(); + prop.setName(property); + prop.setValue(value); + return prop; + } + return prop; + } public static MobileDevice convertToMobileDevice(Device device) { MobileDevice mobileDevice = null; if (device != null) { mobileDevice = new MobileDevice(); mobileDevice.setMobileDeviceId(device.getDeviceIdentifier()); - mobileDevice.setImei(device.getProperties().get(MOBILE_DEVICE_IMEI)); - mobileDevice.setImsi(device.getProperties().get(MOBILE_DEVICE_IMSI)); - mobileDevice.setRegId(device.getProperties().get(MOBILE_DEVICE_REG_ID)); - mobileDevice.setModel(device.getProperties().get(MOBILE_DEVICE_MODEL)); - mobileDevice.setOsVersion(device.getProperties().get(MOBILE_DEVICE_OS_VERSION)); - mobileDevice.setVendor(device.getProperties().get(MOBILE_DEVICE_VENDOR)); - mobileDevice.setLatitude(device.getProperties().get(MOBILE_DEVICE_LATITUDE)); - mobileDevice.setLongitude(device.getProperties().get(MOBILE_DEVICE_LONGITUDE)); + mobileDevice.setImei(getPropertyValue(device, MOBILE_DEVICE_IMEI)); + mobileDevice.setImsi(getPropertyValue(device, MOBILE_DEVICE_IMSI)); + mobileDevice.setRegId(getPropertyValue(device, MOBILE_DEVICE_REG_ID)); + mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL)); + mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION)); + mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR)); + mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE)); + mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE)); } return mobileDevice; } @@ -81,16 +99,16 @@ public class MobileDeviceManagementUtil { Device device = null; if (mobileDevice != null) { device = new Device(); - Map propertyMap = new HashMap(); - propertyMap.put(MOBILE_DEVICE_IMEI, mobileDevice.getImei()); - propertyMap.put(MOBILE_DEVICE_IMSI, mobileDevice.getImsi()); - propertyMap.put(MOBILE_DEVICE_REG_ID, mobileDevice.getRegId()); - propertyMap.put(MOBILE_DEVICE_MODEL, mobileDevice.getModel()); - propertyMap.put(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion()); - propertyMap.put(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor()); - propertyMap.put(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude()); - propertyMap.put(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude()); - device.setProperties(propertyMap); + List propertyList = new ArrayList(); + propertyList.add(getProperty(MOBILE_DEVICE_IMEI, mobileDevice.getImei())); + propertyList.add(getProperty(MOBILE_DEVICE_IMSI, mobileDevice.getImsi())); + propertyList.add(getProperty(MOBILE_DEVICE_REG_ID, mobileDevice.getRegId())); + propertyList.add(getProperty(MOBILE_DEVICE_MODEL, mobileDevice.getModel())); + propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion())); + propertyList.add(getProperty(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor())); + propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude())); + propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude())); + device.setProperties(propertyList); device.setDeviceIdentifier(mobileDevice.getMobileDeviceId()); } return device; From f1193b56472193ae6c3e1d5391610be3eb0a8cb2 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 23 Jan 2015 12:47:25 +0530 Subject: [PATCH 3/3] Fixed indentation. UI module changes --- .../util/MobileDeviceManagementUtil.java | 18 +++++++-------- .../jaggeryapps/cdm/modules/device.js | 23 ++++++++++++------- 2 files changed, 24 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/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 482136f08..7bd38fee9 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 @@ -54,11 +54,11 @@ public class MobileDeviceManagementUtil { DocumentBuilder docBuilder = factory.newDocumentBuilder(); return docBuilder.parse(file); } catch (Exception e) { - throw new DeviceManagementException( - "Error occurred while parsing file, while converting " + - "to a org.w3c.dom.Document : " + e.getMessage(), e); + throw new DeviceManagementException("Error occurred while parsing file, while converting " + + "to a org.w3c.dom.Document : " + e.getMessage(), e); } } + private static String getPropertyValue(Device device, String property) { for (Device.Property prop : device.getProperties()) { if (property.equals(prop.getName())) { @@ -78,6 +78,7 @@ public class MobileDeviceManagementUtil { } return prop; } + public static MobileDevice convertToMobileDevice(Device device) { MobileDevice mobileDevice = null; if (device != null) { @@ -114,8 +115,7 @@ public class MobileDeviceManagementUtil { return device; } - public static MobileOperation convertToMobileOperation( - org.wso2.carbon.device.mgt.common.Operation operation) { + public static MobileOperation convertToMobileOperation(org.wso2.carbon.device.mgt.common.Operation operation) { MobileOperation mobileOperation = new MobileOperation(); MobileOperationProperty operationProperty = null; List properties = new LinkedList(); @@ -135,18 +135,18 @@ public class MobileDeviceManagementUtil { public static List getMobileOperationIdsFromMobileDeviceOperations( List mobileDeviceOperationMappings) { List mobileOperationIds = new ArrayList(); - for(MobileDeviceOperationMapping mobileDeviceOperationMapping : mobileDeviceOperationMappings){ + for (MobileDeviceOperationMapping mobileDeviceOperationMapping : mobileDeviceOperationMappings) { mobileOperationIds.add(mobileDeviceOperationMapping.getOperationId()); } return mobileOperationIds; } - public static Operation convertMobileOperationToOperation(MobileOperation mobileOperation){ + public static Operation convertMobileOperationToOperation(MobileOperation mobileOperation) { Operation operation = new Operation(); Properties properties = new Properties(); operation.setCode(mobileOperation.getFeatureCode()); - for(MobileOperationProperty mobileOperationProperty:mobileOperation.getProperties()){ - properties.put(mobileOperationProperty.getProperty(),mobileOperationProperty.getValue()); + for (MobileOperationProperty mobileOperationProperty : mobileOperation.getProperties()) { + properties.put(mobileOperationProperty.getProperty(), mobileOperationProperty.getValue()); } operation.setProperties(properties); return operation; diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/device.js b/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/device.js index c208c91a4..13d77bc29 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/device.js +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/device.js @@ -18,25 +18,30 @@ var utility = require("/modules/utility.js"); var DeviceIdentifier = Packages.org.wso2.carbon.device.mgt.common.DeviceIdentifier; +var DeviceManagerUtil = Packages.org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; var log = new Log(); - var deviceManagementService = utility.getDeviceManagementService(); var listDevices = function () { + var devices = deviceManagementService.getAllDevices("android"); + var deviceList = []; + for (i = 0; i < devices.size(); i++) { var device = devices.get(i); + + var propertiesList = DeviceManagerUtil.convertPropertiesToMap(device.getProperties()); deviceList.push({ "identifier": device.getDeviceIdentifier(), "name": device.getName(), "ownership": device.getOwnership(), "owner": device.getOwner(), "deviceType": device.getType(), - "vendor": device.getProperties().get("vendor"), - "model": device.getProperties().get("model"), - "osVersion": device.getProperties().get("osVersion") + "vendor": propertiesList.get("vendor"), + "model": propertiesList.get("model"), + "osVersion": propertiesList.get("osVersion") }); } return deviceList; @@ -50,9 +55,11 @@ var getDevice = function(type, deviceId){ } var viewDevice = function(type, deviceId){ + var device = this.getDevice(type, deviceId); - var entries = device.getProperties().entrySet(); + var propertiesList = DeviceManagerUtil.convertPropertiesToMap(device.getProperties()); + var entries = propertiesList.entrySet(); var iterator = entries.iterator(); var properties = {}; while(iterator.hasNext()){ @@ -67,9 +74,9 @@ var viewDevice = function(type, deviceId){ "ownership": device.getOwnership(), "owner": device.getOwner(), "deviceType": device.getType(), - "vendor": device.getProperties().get("vendor"), - "model": device.getProperties().get("model"), - "osVersion": device.getProperties().get("osVersion"), + "vendor": propertiesList.get("vendor"), + "model": propertiesList.get("model"), + "osVersion": propertiesList.get("osVersion"), "properties": properties }; } \ No newline at end of file