From 394d841d4bfe4727cb28556feeae99af27f49331 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 23 Jan 2015 11:22:34 +0530 Subject: [PATCH 1/9] 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 4e083cedaa..c71f24b1c9 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/9] 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 4e083cedaa..c71f24b1c9 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/9] 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 c71f24b1c9..b54d418c29 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 b973ebd06e..1f0c936e30 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; + } } From 94905bdc770d9f11b5b00493f9a81b6b88b44371 Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Fri, 23 Jan 2015 14:47:24 +0530 Subject: [PATCH 4/9] Changing the read me file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a1819b659..d692947a53 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ WSO2 CONNECTED DEVICE MANAGER WSO2 Connected Device Manager (WSO2 CDM) is a comprehensive platform that helps solve mobile computing challenges enterprises face today when dealing with both corporate owned, personally enabled (COPE) devices and employee owned devices as part of a bring your own device (BYOD) program. -Whether it is device provisioning, device configuration management, policy enforcement, mobile application management, device data security, or compliance monitoring, WSO2 EMM offers a single enterprise-grade platform. \ No newline at end of file +Whether it is device provisioning, device configuration management, policy enforcement, mobile application management, device data security, or compliance monitoring, WSO2 CDM offers a single enterprise-grade platform to develop extensions for IOT related device types. \ No newline at end of file From 277f0341b1281a65a0d7a406b8ca54e4a9e6323d Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 23 Jan 2015 18:29:28 +0530 Subject: [PATCH 5/9] * Add device type to the feature * Added method to operation manager to get features by type * Added an exception for feature management --- .../carbon/device/mgt/common/Feature.java | 9 +++ .../common/FeatureManagementException.java | 58 +++++++++++++++++++ .../device/mgt/common/OperationManager.java | 8 +++ 3 files changed, 75 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManagementException.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java index 388edbb402..dccefdd4bd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java @@ -21,6 +21,7 @@ public class Feature { private int id; private String name; + private String deviceType; private List metadataEntries; public int getId() { @@ -47,6 +48,14 @@ public class Feature { this.metadataEntries = metadataEntries; } + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + public static class MetadataEntry { private int id; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManagementException.java new file mode 100644 index 0000000000..a040caf7de --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManagementException.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.common; + + +public class FeatureManagementException extends Exception { + + private static final long serialVersionUID = 4527364660451105710L; + + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public FeatureManagementException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public FeatureManagementException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public FeatureManagementException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public FeatureManagementException() { + super(); + } + + public FeatureManagementException(Throwable cause) { + super(cause); + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManager.java index 09a14021f1..633f370e05 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManager.java @@ -54,4 +54,12 @@ public interface OperationManager { public List getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException; + /** + * TODO: Move this into a separate FeatureManager + * @param deviceType - Device type + * @return a list of Feature objects. + * @throws FeatureManagementException + */ + public List getFeaturesForDeviceType(String deviceType) throws FeatureManagementException; + } \ No newline at end of file From 4fd229357a28b6769d90abcba97f488e4d676523 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 23 Jan 2015 21:24:02 +0530 Subject: [PATCH 6/9] Enabling logging for test case implementations --- .../org.wso2.carbon.device.mgt.core/pom.xml | 3 ++ .../src/test/resources/log4j.properties | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/log4j.properties diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index fece8a1afb..807357997c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -74,6 +74,9 @@ maven-surefire-plugin 2.18 + + file:src/test/resources/log4j.properties + src/test/resources/testng.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/log4j.properties b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/log4j.properties new file mode 100644 index 0000000000..7da6d6c9e1 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/log4j.properties @@ -0,0 +1,32 @@ +# +# Copyright 2009 WSO2, Inc. (http://wso2.com) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# This is the log4j configuration file used by WSO2 Carbon +# +# IMPORTANT : Please do not remove or change the names of any +# of the Appenders defined here. The layout pattern & log file +# can be changed using the WSO2 Carbon Management Console, and those +# settings will override the settings in this file. +# + +log4j.rootLogger=DEBUG, STD_OUT + +# Redirect log messages to console +log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender +log4j.appender.STD_OUT.Target=System.out +log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout +log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n From 7f3516b2a6f6b9b814b66f8ab4664358dd676c09 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 23 Jan 2015 21:52:00 +0530 Subject: [PATCH 7/9] * Added a description to the feature object * Added the COMMAND enum to the Operation class --- .../java/org/wso2/carbon/device/mgt/common/Feature.java | 9 +++++++++ .../org/wso2/carbon/device/mgt/common/Operation.java | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java index dccefdd4bd..dcc4626c3e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java @@ -21,6 +21,7 @@ public class Feature { private int id; private String name; + private String description; private String deviceType; private List metadataEntries; @@ -56,6 +57,14 @@ public class Feature { this.deviceType = deviceType; } + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + public static class MetadataEntry { private int id; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java index 755be0b5cc..c1e39ba89a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java @@ -24,7 +24,7 @@ import java.util.Properties; public class Operation { public enum Type { - CONFIG, MESSAGE, INFO + CONFIG, MESSAGE, INFO, COMMAND } private String code; From 831cd121a951c935c8ded53b420d5dd12e3d7522 Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Fri, 23 Jan 2015 22:26:40 +0530 Subject: [PATCH 8/9] fixing filter properties --- product/modules/distribution/src/assembly/bin.xml | 6 ++++++ product/modules/distribution/src/assembly/filter.properties | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/product/modules/distribution/src/assembly/bin.xml b/product/modules/distribution/src/assembly/bin.xml index 76382b863e..d9d40d418d 100644 --- a/product/modules/distribution/src/assembly/bin.xml +++ b/product/modules/distribution/src/assembly/bin.xml @@ -474,5 +474,11 @@ 644 --> + + target/wso2carbon-core-${carbon.kernel.version}/repository/conf/carbon.xml + ${pom.artifactId}-${pom.version}/repository/conf/ + true + + diff --git a/product/modules/distribution/src/assembly/filter.properties b/product/modules/distribution/src/assembly/filter.properties index a0ebf6302a..372dd9118a 100644 --- a/product/modules/distribution/src/assembly/filter.properties +++ b/product/modules/distribution/src/assembly/filter.properties @@ -1,5 +1,5 @@ product.name=WSO2 Connected Device Manager -product.version=2.0.0-SNAPSHOT +product.version=1.0.0-SNAPSHOT product.key=CDM hotdeployment=true hotupdate=true From d439691a01744fbdd571d2def91dbc01510a16aa Mon Sep 17 00:00:00 2001 From: prabathabey Date: Tue, 27 Jan 2015 20:27:16 +0530 Subject: [PATCH 9/9] Fixing formatting issues --- .../device/mgt/core/DeviceManagerImpl.java | 280 +++++++++--------- 1 file changed, 145 insertions(+), 135 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java index c65a5478d5..77d9731aa4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java @@ -39,141 +39,151 @@ import java.util.List; public class DeviceManagerImpl implements DeviceManager { private static Log log = LogFactory.getLog(DeviceManagerImpl.class); - private DeviceDAO deviceDAO; - private DeviceTypeDAO deviceTypeDAO; - private DeviceManagementConfig config; - private DeviceManagementRepository pluginRepository; - - public DeviceManagerImpl(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) { - this.config = config; - this.pluginRepository = pluginRepository; - this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); - this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); - } - - @Override public boolean enrollDevice(Device device) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); - boolean status = dms.enrollDevice(device); - - try { - org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device); - Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType()); + private DeviceDAO deviceDAO; + private DeviceTypeDAO deviceTypeDAO; + private DeviceManagementConfig config; + private DeviceManagementRepository pluginRepository; + + public DeviceManagerImpl(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) { + this.config = config; + this.pluginRepository = pluginRepository; + this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); + this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); + } + + @Override + public boolean enrollDevice(Device device) throws DeviceManagementException { + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); + boolean status = dms.enrollDevice(device); + + try { + org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device); + Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType()); deviceDto.setStatus(Status.ACTIVE); - deviceDto.setDeviceTypeId(deviceTypeId); - this.getDeviceDAO().addDevice(deviceDto); - - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'", - e); - } - return status; - } - - @Override public boolean modifyEnrollment(Device device) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); - boolean status = dms.modifyEnrollment(device); - try { - this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device)); - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + "'", - e); - } - return status; - } - - @Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.disenrollDevice(deviceId); - } - - @Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.isEnrolled(deviceId); - } - - @Override public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.isActive(deviceId); - } - - @Override public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.setActive(deviceId, status); - } - - @Override public List getAllDevices(String type) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); - List devicesList = new ArrayList(); - try { - Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type); - List devices = this.getDeviceDAO().getDevices(deviceTypeId); - - for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) { - DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId()); - Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType); - DeviceIdentifier deviceIdentifier = DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType); - Device dmsDevice = dms.getDevice(deviceIdentifier); - if (dmsDevice != null) { - convertedDevice.setProperties(dmsDevice.getProperties()); - convertedDevice.setFeatures(dmsDevice.getFeatures()); - } - devicesList.add(convertedDevice); - } - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + "'", e); - } - return devicesList; - } - - @Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - Device convertedDevice = null; - try { - Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType()); - org.wso2.carbon.device.mgt.core.dto.Device device = - this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId()); - if (device != null) { - convertedDevice = DeviceManagementDAOUtil - .convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId)); - Device dmsDevice = dms.getDevice(deviceId); - if (dmsDevice != null) { - convertedDevice.setProperties(dmsDevice.getProperties()); - convertedDevice.setFeatures(dmsDevice.getFeatures()); - } - } - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException( - "Error occurred while obtaining the device for id '" + deviceId.getId() + "'", e); - } - return convertedDevice; - } - - @Override public boolean updateDeviceInfo(Device device) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); - return dms.updateDeviceInfo(device); - } - - @Override public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) - throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.setOwnership(deviceId, ownershipType); - } - - public OperationManager getOperationManager(String type) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); - return dms.getOperationManager(); - } - - public DeviceDAO getDeviceDAO() { - return deviceDAO; - } - - public DeviceTypeDAO getDeviceTypeDAO() { - return deviceTypeDAO; - } - - public DeviceManagementRepository getPluginRepository() { - return pluginRepository; - } + deviceDto.setDeviceTypeId(deviceTypeId); + this.getDeviceDAO().addDevice(deviceDto); + + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'", + e); + } + return status; + } + + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); + boolean status = dms.modifyEnrollment(device); + try { + this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device)); + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + "'", + e); + } + return status; + } + + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.disenrollDevice(deviceId); + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.isEnrolled(deviceId); + } + + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.isActive(deviceId); + } + + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.setActive(deviceId, status); + } + + @Override + public List getAllDevices(String type) throws DeviceManagementException { + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); + List devicesList = new ArrayList(); + try { + Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type); + List devices = this.getDeviceDAO().getDevices(deviceTypeId); + + for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) { + DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId()); + Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType); + DeviceIdentifier deviceIdentifier = DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType); + Device dmsDevice = dms.getDevice(deviceIdentifier); + if (dmsDevice != null) { + convertedDevice.setProperties(dmsDevice.getProperties()); + convertedDevice.setFeatures(dmsDevice.getFeatures()); + } + devicesList.add(convertedDevice); + } + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + "'", e); + } + return devicesList; + } + + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + Device convertedDevice = null; + try { + Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType()); + org.wso2.carbon.device.mgt.core.dto.Device device = + this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId()); + if (device != null) { + convertedDevice = DeviceManagementDAOUtil + .convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId)); + Device dmsDevice = dms.getDevice(deviceId); + if (dmsDevice != null) { + convertedDevice.setProperties(dmsDevice.getProperties()); + convertedDevice.setFeatures(dmsDevice.getFeatures()); + } + } + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException( + "Error occurred while obtaining the device for id '" + deviceId.getId() + "'", e); + } + return convertedDevice; + } + + @Override + public boolean updateDeviceInfo(Device device) throws DeviceManagementException { + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); + return dms.updateDeviceInfo(device); + } + + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.setOwnership(deviceId, ownershipType); + } + + public OperationManager getOperationManager(String type) throws DeviceManagementException { + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); + return dms.getOperationManager(); + } + + public DeviceDAO getDeviceDAO() { + return deviceDAO; + } + + public DeviceTypeDAO getDeviceTypeDAO() { + return deviceTypeDAO; + } + + public DeviceManagementRepository getPluginRepository() { + return pluginRepository; + } }