Merge remote-tracking branch 'upstream/master'

Conflicts:
	components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java
revert-70aa11f8
manoj 10 years ago
commit 505b87a655

@ -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. 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. 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.

@ -18,140 +18,161 @@ package org.wso2.carbon.device.mgt.common;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.util.List; import java.util.List;
import java.util.Map;
@XmlRootElement @XmlRootElement
public class Device { public class Device {
private int id; private int id;
private String type; private String type;
private String description; private String description;
private String name; private String name;
private Long dateOfEnrolment; private Long dateOfEnrolment;
private Long dateOfLastUpdate; private Long dateOfLastUpdate;
private String ownership; private String ownership;
private boolean status; private boolean status;
private int deviceTypeId; private int deviceTypeId;
private String deviceIdentifier; private String deviceIdentifier;
private String owner; private String owner;
private List<Feature> features; private List<Feature> features;
private Map<String, String> properties; private List<Device.Property> properties;
@XmlElement @XmlElement
public int getId() { public int getId() {
return id; return id;
} }
public void setId(int id) { public void setId(int id) {
this.id = id; this.id = id;
} }
@XmlElement @XmlElement
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
@XmlElement @XmlElement
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
@XmlElement @XmlElement
public Long getDateOfEnrolment() { public Long getDateOfEnrolment() {
return dateOfEnrolment; return dateOfEnrolment;
} }
public void setDateOfEnrolment(Long dateOfEnrolment) { public void setDateOfEnrolment(Long dateOfEnrolment) {
this.dateOfEnrolment = dateOfEnrolment; this.dateOfEnrolment = dateOfEnrolment;
} }
@XmlElement @XmlElement
public Long getDateOfLastUpdate() { public Long getDateOfLastUpdate() {
return dateOfLastUpdate; return dateOfLastUpdate;
} }
public void setDateOfLastUpdate(Long dateOfLastUpdate) { public void setDateOfLastUpdate(Long dateOfLastUpdate) {
this.dateOfLastUpdate = dateOfLastUpdate; this.dateOfLastUpdate = dateOfLastUpdate;
} }
@XmlElement @XmlElement
public String getOwnership() { public String getOwnership() {
return ownership; return ownership;
} }
public void setOwnership(String ownership) { public void setOwnership(String ownership) {
this.ownership = ownership; this.ownership = ownership;
} }
@XmlElement @XmlElement
public boolean isStatus() { public boolean isStatus() {
return status; return status;
} }
public void setStatus(boolean status) { public void setStatus(boolean status) {
this.status = status; this.status = status;
} }
@XmlElement @XmlElement
public int getDeviceTypeId() { public int getDeviceTypeId() {
return deviceTypeId; return deviceTypeId;
} }
public void setDeviceTypeId(int deviceTypeId) { public void setDeviceTypeId(int deviceTypeId) {
this.deviceTypeId = deviceTypeId; this.deviceTypeId = deviceTypeId;
} }
@XmlElement @XmlElement
public String getDeviceIdentifier() { public String getDeviceIdentifier() {
return deviceIdentifier; return deviceIdentifier;
} }
public void setDeviceIdentifier(String deviceIdentifier) { public void setDeviceIdentifier(String deviceIdentifier) {
this.deviceIdentifier = deviceIdentifier; this.deviceIdentifier = deviceIdentifier;
} }
@XmlElement @XmlElement
public String getOwner() { public String getOwner() {
return owner; return owner;
} }
public void setOwner(String owner) { public void setOwner(String owner) {
this.owner = owner; this.owner = owner;
} }
@XmlElement @XmlElement
public List<Feature> getFeatures() { public List<Feature> getFeatures() {
return features; return features;
} }
public void setFeatures(List<Feature> features) { public void setFeatures(List<Feature> features) {
this.features = features; this.features = features;
} }
@XmlElement @XmlElement
public String getType() { public String getType() {
return type; return type;
} }
public void setType(String type) { public void setType(String type) {
this.type = type; this.type = type;
} }
@XmlElement @XmlElement
public Map<String, String> getProperties() { public List<Device.Property> getProperties() {
return properties; return properties;
} }
public void setProperties(Map<String, String> properties) { public void setProperties(List<Device.Property> properties) {
this.properties = 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;
}
}
} }

@ -21,6 +21,8 @@ public class Feature {
private int id; private int id;
private String name; private String name;
private String description;
private String deviceType;
private List<MetadataEntry> metadataEntries; private List<MetadataEntry> metadataEntries;
public int getId() { public int getId() {
@ -47,6 +49,22 @@ public class Feature {
this.metadataEntries = metadataEntries; this.metadataEntries = metadataEntries;
} }
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public static class MetadataEntry { public static class MetadataEntry {
private int id; private int id;

@ -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);
}
}

@ -24,7 +24,7 @@ import java.util.Properties;
public class Operation { public class Operation {
public enum Type { public enum Type {
CONFIG, MESSAGE, INFO CONFIG, MESSAGE, INFO, COMMAND
} }
private String code; private String code;

@ -54,4 +54,12 @@ public interface OperationManager {
public List<Operation> getPendingOperations(DeviceIdentifier deviceId) public List<Operation> getPendingOperations(DeviceIdentifier deviceId)
throws OperationManagementException; throws OperationManagementException;
/**
* TODO: Move this into a separate FeatureManager
* @param deviceType - Device type
* @return a list of Feature objects.
* @throws FeatureManagementException
*/
public List<Feature> getFeaturesForDeviceType(String deviceType) throws FeatureManagementException;
} }

@ -74,6 +74,9 @@
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version> <version>2.18</version>
<configuration> <configuration>
<systemPropertyVariables>
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
</systemPropertyVariables>
<suiteXmlFiles> <suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles> </suiteXmlFiles>

@ -53,7 +53,6 @@ public class DeviceManagerImpl implements DeviceManager {
@Override @Override
public boolean enrollDevice(Device device) throws DeviceManagementException { public boolean enrollDevice(Device device) throws DeviceManagementException {
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
boolean status = dms.enrollDevice(device); boolean status = dms.enrollDevice(device);
try { try {

@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.util;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document; 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.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; 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.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File; import java.io.File;
import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
import java.util.Map;
public final class DeviceManagerUtil { 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 { public static Document convertToDocument(File file) throws DeviceManagementException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true); factory.setNamespaceAware(true);
try { try {
DocumentBuilder docBuilder = factory.newDocumentBuilder(); DocumentBuilder docBuilder = factory.newDocumentBuilder();
return docBuilder.parse(file); return docBuilder.parse(file);
} catch (Exception e) { } catch (Exception e) {
throw new DeviceManagementException("Error occurred while parsing file, while converting " + throw new DeviceManagementException("Error occurred while parsing file, while converting " +
"to a org.w3c.dom.Document : " + e.getMessage(), e); "to a org.w3c.dom.Document : " + e.getMessage(), e);
} }
} }
/** /**
* Resolve data source from the data source definition. * Resolve data source from the data source definition.
* *
* @param config data source configuration * @param config data source configuration
* @return data source resolved from the data source definition * @return data source resolved from the data source definition
*/ */
public static DataSource resolveDataSource(DataSourceConfig config) { public static DataSource resolveDataSource(DataSourceConfig config) {
DataSource dataSource = null; DataSource dataSource = null;
if (config == null) { if (config == null) {
throw new RuntimeException("Device Management Repository data source configuration " + throw new RuntimeException(
"is null and thus, is not initialized"); "Device Management Repository data source configuration " + "is null and thus, is not initialized");
} }
JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion(); JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion();
if (jndiConfig != null) { if (jndiConfig != null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Initializing Device Management Repository data source using the JNDI " + log.debug(
"Lookup Definition"); "Initializing Device Management Repository data source using the JNDI " + "Lookup Definition");
} }
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = jndiConfig.getJndiProperties();
jndiConfig.getJndiProperties(); if (jndiPropertyList != null) {
if (jndiPropertyList != null) { Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>(); for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { jndiProperties.put(prop.getName(), prop.getValue());
jndiProperties.put(prop.getName(), prop.getValue()); }
} dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
dataSource = } else {
DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
} else { }
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); }
} return dataSource;
} }
return dataSource;
}
/** /**
* Adds a new device type to the database if it does not exists. * Adds a new device type to the database if it does not exists.
* *
* @param deviceType device type * @param deviceType device type
* @return status of the operation * @return status of the operation
*/ */
public static boolean registerDeviceType(String deviceType) throws DeviceManagementException { public static boolean registerDeviceType(String deviceType) throws DeviceManagementException {
boolean status; boolean status;
try { try {
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType); Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType);
if (deviceTypeId == null) { if (deviceTypeId == null) {
DeviceType dt = new DeviceType(); DeviceType dt = new DeviceType();
dt.setName(deviceType); dt.setName(deviceType);
deviceTypeDAO.addDeviceType(dt); deviceTypeDAO.addDeviceType(dt);
} }
status = true; status = true;
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
String msg = "Error occurred while registering the device type " + deviceType; String msg = "Error occurred while registering the device type " + deviceType;
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
return status; return status;
} }
/** /**
* Unregisters an existing device type from the device management metadata repository. * Unregisters an existing device type from the device management metadata repository.
* *
* @param deviceType device type * @param deviceType device type
* @return status of the operation * @return status of the operation
*/ */
public static boolean unregisterDeviceType(String deviceType) throws DeviceManagementException { public static boolean unregisterDeviceType(String deviceType) throws DeviceManagementException {
try { try {
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType); Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType);
if (deviceTypeId == null) { if (deviceTypeId == null) {
DeviceType dt = new DeviceType(); DeviceType dt = new DeviceType();
dt.setName(deviceType); dt.setName(deviceType);
deviceTypeDAO.removeDeviceType(dt); deviceTypeDAO.removeDeviceType(dt);
} }
return true; return true;
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
String msg = "Error occurred while registering the device type " + deviceType; String msg = "Error occurred while registering the device type " + deviceType;
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
} }
public static Map<String, String> convertPropertiesToMap(List<Device.Property> properties) {
Map<String, String> propertiesMap = new HashMap<String, String>();
for (Device.Property prop : properties) {
propertiesMap.put(prop.getName(), prop.getValue());
}
return propertiesMap;
}
} }

@ -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

@ -466,5 +466,11 @@
<fileMode>644</fileMode> <fileMode>644</fileMode>
</file> --> </file> -->
<file>
<source>target/wso2carbon-core-${carbon.kernel.version}/repository/conf/carbon.xml</source>
<outputDirectory>${pom.artifactId}-${pom.version}/repository/conf/</outputDirectory>
<filtered>true</filtered>
</file>
</files> </files>
</assembly> </assembly>

@ -1,5 +1,5 @@
product.name=WSO2 Connected Device Manager product.name=WSO2 Connected Device Manager
product.version=2.0.0-SNAPSHOT product.version=1.0.0-SNAPSHOT
product.key=CDM product.key=CDM
hotdeployment=true hotdeployment=true
hotupdate=true hotupdate=true

Loading…
Cancel
Save