From a195844042606af8ecc6cc09770a613bf43ac1d5 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Wed, 21 Jan 2015 16:55:37 +0530 Subject: [PATCH] Changed the properties implementation to a Map from List. Removed unnecessary utility methods. Changed the conversion util methods. --- .../wso2/carbon/device/mgt/common/Device.java | 29 ++------- .../util/MobileDeviceManagementUtil.java | 65 +++++++------------ 2 files changed, 27 insertions(+), 67 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java index 94786b4191..4e083cedaa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.common; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import java.util.List; +import java.util.Map; @XmlRootElement public class Device { @@ -34,7 +35,7 @@ public class Device { private String deviceIdentifier; private String owner; private List features; - private List properties; + private Map properties; @XmlElement public int getId() { @@ -145,34 +146,12 @@ public class Device { } @XmlElement - public List getProperties() { + public Map getProperties() { return properties; } - public void setProperties(List properties) { + public void setProperties(Map properties) { this.properties = properties; } - public static class Property { - - private String name; - private String value; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - } - } 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 d170379eea..60ad0e4503 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 @@ -60,39 +60,19 @@ public class MobileDeviceManagementUtil { } } - 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(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)); + 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)); } return mobileDevice; } @@ -101,16 +81,16 @@ public class MobileDeviceManagementUtil { Device device = null; if (mobileDevice != null) { device = new Device(); - 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); + 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); device.setDeviceIdentifier(mobileDevice.getMobileDeviceId()); } return device; @@ -137,18 +117,19 @@ public class MobileDeviceManagementUtil { public static List getMobileOperationIdsFromMobileDeviceOperations( List mobileDeviceOperations) { List mobileOperationIds = new ArrayList(); - for(MobileDeviceOperation mobileDeviceOperation:mobileDeviceOperations){ + for (MobileDeviceOperation mobileDeviceOperation : mobileDeviceOperations) { mobileOperationIds.add(mobileDeviceOperation.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;