From 394d841d4bfe4727cb28556feeae99af27f49331 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 23 Jan 2015 11:22:34 +0530 Subject: [PATCH 1/3] Changed the Map implementations to List since Map implementations are not very well supported by CFX --- .../wso2/carbon/device/mgt/common/Device.java | 277 +++++++++--------- 1 file changed, 142 insertions(+), 135 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 4e083cedaa7..c71f24b1c98 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,140 +18,147 @@ 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 { - - private int id; - private String type; - private String description; - private String name; - private Long dateOfEnrolment; - private Long dateOfLastUpdate; - private String ownership; - private boolean status; - private int deviceTypeId; - private String deviceIdentifier; - private String owner; - private List features; - private Map properties; - - @XmlElement - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - @XmlElement - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlElement - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @XmlElement - public Long getDateOfEnrolment() { - return dateOfEnrolment; - } - - public void setDateOfEnrolment(Long dateOfEnrolment) { - this.dateOfEnrolment = dateOfEnrolment; - } - - @XmlElement - public Long getDateOfLastUpdate() { - return dateOfLastUpdate; - } - - public void setDateOfLastUpdate(Long dateOfLastUpdate) { - this.dateOfLastUpdate = dateOfLastUpdate; - } - - @XmlElement - public String getOwnership() { - return ownership; - } - - public void setOwnership(String ownership) { - this.ownership = ownership; - } - - @XmlElement - public boolean isStatus() { - return status; - } - - public void setStatus(boolean status) { - this.status = status; - } - - @XmlElement - public int getDeviceTypeId() { - return deviceTypeId; - } - - public void setDeviceTypeId(int deviceTypeId) { - this.deviceTypeId = deviceTypeId; - } - - @XmlElement - public String getDeviceIdentifier() { - return deviceIdentifier; - } - - public void setDeviceIdentifier(String deviceIdentifier) { - this.deviceIdentifier = deviceIdentifier; - } - - @XmlElement - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - - @XmlElement - public List getFeatures() { - return features; - } - - public void setFeatures(List features) { - this.features = features; - } - - @XmlElement - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - @XmlElement - public Map getProperties() { - return properties; - } - - public void setProperties(Map properties) { - this.properties = properties; - } + +@XmlRootElement public class Device { + + private int id; + private String type; + private String description; + private String name; + private Long dateOfEnrolment; + private Long dateOfLastUpdate; + private String ownership; + private boolean status; + private int deviceTypeId; + private String deviceIdentifier; + private String owner; + private List features; + private List properties; + + @XmlElement public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @XmlElement public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlElement public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlElement public Long getDateOfEnrolment() { + return dateOfEnrolment; + } + + public void setDateOfEnrolment(Long dateOfEnrolment) { + this.dateOfEnrolment = dateOfEnrolment; + } + + @XmlElement public Long getDateOfLastUpdate() { + return dateOfLastUpdate; + } + + public void setDateOfLastUpdate(Long dateOfLastUpdate) { + this.dateOfLastUpdate = dateOfLastUpdate; + } + + @XmlElement public String getOwnership() { + return ownership; + } + + public void setOwnership(String ownership) { + this.ownership = ownership; + } + + @XmlElement public boolean isStatus() { + return status; + } + + public void setStatus(boolean status) { + this.status = status; + } + + @XmlElement public int getDeviceTypeId() { + return deviceTypeId; + } + + public void setDeviceTypeId(int deviceTypeId) { + this.deviceTypeId = deviceTypeId; + } + + @XmlElement public String getDeviceIdentifier() { + return deviceIdentifier; + } + + public void setDeviceIdentifier(String deviceIdentifier) { + this.deviceIdentifier = deviceIdentifier; + } + + @XmlElement public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + @XmlElement public List getFeatures() { + return features; + } + + public void setFeatures(List features) { + this.features = features; + } + + @XmlElement public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @XmlElement public List getProperties() { + return properties; + } + + public void setProperties(List 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; + } + } } From 6f2053995de32d9e5fc4cdd716210d6af4f526d6 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 23 Jan 2015 11:22:34 +0530 Subject: [PATCH 2/3] Changed the Map implementations to List since Map implementations are not very well supported by CXF --- .../wso2/carbon/device/mgt/common/Device.java | 277 +++++++++--------- 1 file changed, 142 insertions(+), 135 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 4e083cedaa7..c71f24b1c98 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,140 +18,147 @@ 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 { - - private int id; - private String type; - private String description; - private String name; - private Long dateOfEnrolment; - private Long dateOfLastUpdate; - private String ownership; - private boolean status; - private int deviceTypeId; - private String deviceIdentifier; - private String owner; - private List features; - private Map properties; - - @XmlElement - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - @XmlElement - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlElement - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @XmlElement - public Long getDateOfEnrolment() { - return dateOfEnrolment; - } - - public void setDateOfEnrolment(Long dateOfEnrolment) { - this.dateOfEnrolment = dateOfEnrolment; - } - - @XmlElement - public Long getDateOfLastUpdate() { - return dateOfLastUpdate; - } - - public void setDateOfLastUpdate(Long dateOfLastUpdate) { - this.dateOfLastUpdate = dateOfLastUpdate; - } - - @XmlElement - public String getOwnership() { - return ownership; - } - - public void setOwnership(String ownership) { - this.ownership = ownership; - } - - @XmlElement - public boolean isStatus() { - return status; - } - - public void setStatus(boolean status) { - this.status = status; - } - - @XmlElement - public int getDeviceTypeId() { - return deviceTypeId; - } - - public void setDeviceTypeId(int deviceTypeId) { - this.deviceTypeId = deviceTypeId; - } - - @XmlElement - public String getDeviceIdentifier() { - return deviceIdentifier; - } - - public void setDeviceIdentifier(String deviceIdentifier) { - this.deviceIdentifier = deviceIdentifier; - } - - @XmlElement - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - - @XmlElement - public List getFeatures() { - return features; - } - - public void setFeatures(List features) { - this.features = features; - } - - @XmlElement - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - @XmlElement - public Map getProperties() { - return properties; - } - - public void setProperties(Map properties) { - this.properties = properties; - } + +@XmlRootElement public class Device { + + private int id; + private String type; + private String description; + private String name; + private Long dateOfEnrolment; + private Long dateOfLastUpdate; + private String ownership; + private boolean status; + private int deviceTypeId; + private String deviceIdentifier; + private String owner; + private List features; + private List properties; + + @XmlElement public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @XmlElement public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlElement public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlElement public Long getDateOfEnrolment() { + return dateOfEnrolment; + } + + public void setDateOfEnrolment(Long dateOfEnrolment) { + this.dateOfEnrolment = dateOfEnrolment; + } + + @XmlElement public Long getDateOfLastUpdate() { + return dateOfLastUpdate; + } + + public void setDateOfLastUpdate(Long dateOfLastUpdate) { + this.dateOfLastUpdate = dateOfLastUpdate; + } + + @XmlElement public String getOwnership() { + return ownership; + } + + public void setOwnership(String ownership) { + this.ownership = ownership; + } + + @XmlElement public boolean isStatus() { + return status; + } + + public void setStatus(boolean status) { + this.status = status; + } + + @XmlElement public int getDeviceTypeId() { + return deviceTypeId; + } + + public void setDeviceTypeId(int deviceTypeId) { + this.deviceTypeId = deviceTypeId; + } + + @XmlElement public String getDeviceIdentifier() { + return deviceIdentifier; + } + + public void setDeviceIdentifier(String deviceIdentifier) { + this.deviceIdentifier = deviceIdentifier; + } + + @XmlElement public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + @XmlElement public List getFeatures() { + return features; + } + + public void setFeatures(List features) { + this.features = features; + } + + @XmlElement public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @XmlElement public List getProperties() { + return properties; + } + + public void setProperties(List 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; + } + } } From 49a46ca909e839a484fed660c78288c508076213 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 23 Jan 2015 12:46:35 +0530 Subject: [PATCH 3/3] Fixed indentation --- .../wso2/carbon/device/mgt/common/Device.java | 42 ++-- .../mgt/core/util/DeviceManagerUtil.java | 187 +++++++++--------- 2 files changed, 126 insertions(+), 103 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 c71f24b1c98..b54d418c297 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 @@ -19,7 +19,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import java.util.List; -@XmlRootElement public class Device { +@XmlRootElement +public class Device { private int id; private String type; @@ -35,7 +36,8 @@ import java.util.List; private List features; private List properties; - @XmlElement public int getId() { + @XmlElement + public int getId() { return id; } @@ -43,7 +45,8 @@ import java.util.List; this.id = id; } - @XmlElement public String getDescription() { + @XmlElement + public String getDescription() { return description; } @@ -51,7 +54,8 @@ import java.util.List; this.description = description; } - @XmlElement public String getName() { + @XmlElement + public String getName() { return name; } @@ -59,7 +63,8 @@ import java.util.List; this.name = name; } - @XmlElement public Long getDateOfEnrolment() { + @XmlElement + public Long getDateOfEnrolment() { return dateOfEnrolment; } @@ -67,7 +72,8 @@ import java.util.List; this.dateOfEnrolment = dateOfEnrolment; } - @XmlElement public Long getDateOfLastUpdate() { + @XmlElement + public Long getDateOfLastUpdate() { return dateOfLastUpdate; } @@ -75,7 +81,8 @@ import java.util.List; this.dateOfLastUpdate = dateOfLastUpdate; } - @XmlElement public String getOwnership() { + @XmlElement + public String getOwnership() { return ownership; } @@ -83,7 +90,8 @@ import java.util.List; this.ownership = ownership; } - @XmlElement public boolean isStatus() { + @XmlElement + public boolean isStatus() { return status; } @@ -91,7 +99,8 @@ import java.util.List; this.status = status; } - @XmlElement public int getDeviceTypeId() { + @XmlElement + public int getDeviceTypeId() { return deviceTypeId; } @@ -99,7 +108,8 @@ import java.util.List; this.deviceTypeId = deviceTypeId; } - @XmlElement public String getDeviceIdentifier() { + @XmlElement + public String getDeviceIdentifier() { return deviceIdentifier; } @@ -107,7 +117,8 @@ import java.util.List; this.deviceIdentifier = deviceIdentifier; } - @XmlElement public String getOwner() { + @XmlElement + public String getOwner() { return owner; } @@ -115,7 +126,8 @@ import java.util.List; this.owner = owner; } - @XmlElement public List getFeatures() { + @XmlElement + public List getFeatures() { return features; } @@ -123,7 +135,8 @@ import java.util.List; this.features = features; } - @XmlElement public String getType() { + @XmlElement + public String getType() { return type; } @@ -131,7 +144,8 @@ import java.util.List; this.type = type; } - @XmlElement public List getProperties() { + @XmlElement + public List getProperties() { return properties; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index b973ebd06e2..1f0c936e30e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; +import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; @@ -31,103 +32,111 @@ import javax.sql.DataSource; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.File; +import java.util.HashMap; import java.util.Hashtable; import java.util.List; +import java.util.Map; public final class DeviceManagerUtil { - private static final Log log = LogFactory.getLog(DeviceManagerUtil.class); + private static final Log log = LogFactory.getLog(DeviceManagerUtil.class); - public static Document convertToDocument(File file) throws DeviceManagementException { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - try { - 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); - } - } + public static Document convertToDocument(File file) throws DeviceManagementException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + try { + 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); + } + } - /** - * Resolve data source from the data source definition. - * - * @param config data source configuration - * @return data source resolved from the data source definition - */ - public static DataSource resolveDataSource(DataSourceConfig config) { - DataSource dataSource = null; - if (config == null) { - throw new RuntimeException("Device Management Repository data source configuration " + - "is null and thus, is not initialized"); - } - JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion(); - if (jndiConfig != null) { - if (log.isDebugEnabled()) { - log.debug("Initializing Device Management Repository data source using the JNDI " + - "Lookup Definition"); - } - List jndiPropertyList = - jndiConfig.getJndiProperties(); - if (jndiPropertyList != null) { - Hashtable jndiProperties = new Hashtable(); - for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { - jndiProperties.put(prop.getName(), prop.getValue()); - } - dataSource = - DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); - } else { - dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); - } - } - return dataSource; - } + /** + * Resolve data source from the data source definition. + * + * @param config data source configuration + * @return data source resolved from the data source definition + */ + public static DataSource resolveDataSource(DataSourceConfig config) { + DataSource dataSource = null; + if (config == null) { + throw new RuntimeException( + "Device Management Repository data source configuration " + "is null and thus, is not initialized"); + } + JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion(); + if (jndiConfig != null) { + if (log.isDebugEnabled()) { + log.debug( + "Initializing Device Management Repository data source using the JNDI " + "Lookup Definition"); + } + List jndiPropertyList = jndiConfig.getJndiProperties(); + if (jndiPropertyList != null) { + Hashtable jndiProperties = new Hashtable(); + for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { + jndiProperties.put(prop.getName(), prop.getValue()); + } + dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + } else { + dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); + } + } + return dataSource; + } - /** - * Adds a new device type to the database if it does not exists. - * - * @param deviceType device type - * @return status of the operation - */ - public static boolean registerDeviceType(String deviceType) throws DeviceManagementException { - boolean status; - try { - DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); - Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType); - if (deviceTypeId == null) { - DeviceType dt = new DeviceType(); - dt.setName(deviceType); - deviceTypeDAO.addDeviceType(dt); - } - status = true; - } catch (DeviceManagementDAOException e) { - String msg = "Error occurred while registering the device type " + deviceType; - throw new DeviceManagementException(msg, e); - } - return status; - } + /** + * Adds a new device type to the database if it does not exists. + * + * @param deviceType device type + * @return status of the operation + */ + public static boolean registerDeviceType(String deviceType) throws DeviceManagementException { + boolean status; + try { + DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); + Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType); + if (deviceTypeId == null) { + DeviceType dt = new DeviceType(); + dt.setName(deviceType); + deviceTypeDAO.addDeviceType(dt); + } + status = true; + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while registering the device type " + deviceType; + throw new DeviceManagementException(msg, e); + } + return status; + } - /** - * Unregisters an existing device type from the device management metadata repository. - * - * @param deviceType device type - * @return status of the operation - */ - public static boolean unregisterDeviceType(String deviceType) throws DeviceManagementException { - try { - DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); - Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType); - if (deviceTypeId == null) { - DeviceType dt = new DeviceType(); - dt.setName(deviceType); - deviceTypeDAO.removeDeviceType(dt); - } - return true; - } catch (DeviceManagementDAOException e) { - String msg = "Error occurred while registering the device type " + deviceType; - throw new DeviceManagementException(msg, e); - } - } + /** + * Unregisters an existing device type from the device management metadata repository. + * + * @param deviceType device type + * @return status of the operation + */ + public static boolean unregisterDeviceType(String deviceType) throws DeviceManagementException { + try { + DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); + Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType); + if (deviceTypeId == null) { + DeviceType dt = new DeviceType(); + dt.setName(deviceType); + deviceTypeDAO.removeDeviceType(dt); + } + return true; + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while registering the device type " + deviceType; + throw new DeviceManagementException(msg, e); + } + } + + public static Map convertPropertiesToMap(List properties) { + Map propertiesMap = new HashMap(); + for (Device.Property prop : properties) { + propertiesMap.put(prop.getName(), prop.getValue()); + } + return propertiesMap; + } }