Conflicts:
	components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java
	components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java
revert-70aa11f8
manoj 10 years ago
commit d790d343a9

@ -24,7 +24,7 @@ public interface FeatureManager {
boolean addFeature(Feature feature) throws DeviceManagementException;
boolean getFeature(String name) throws DeviceManagementException;
Feature getFeature(String name) throws DeviceManagementException;
List<Feature> getFeatures() throws DeviceManagementException;

@ -35,8 +35,8 @@ public interface OperationManager {
* @throws OperationManagementException If some unusual behaviour is observed while adding the
* operation
*/
public boolean addOperation(Operation operation, List<DeviceIdentifier> devices)
throws OperationManagementException;
public boolean addOperation(Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException;
/**
* Method to retrieve the list of all operations to a device.
@ -45,8 +45,7 @@ public interface OperationManager {
* @throws OperationManagementException If some unusual behaviour is observed while fetching the
* operation list.
*/
public List<Operation> getOperations(DeviceIdentifier deviceId)
throws OperationManagementException;
public List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException;
/**
* Method to retrieve the list of available operations to a device.
@ -55,15 +54,6 @@ public interface OperationManager {
* @throws OperationManagementException If some unusual behaviour is observed while fetching the
* operation list.
*/
public List<Operation> getPendingOperations(DeviceIdentifier deviceId)
throws OperationManagementException;
/**
* TODO: Move this into a separate FeatureManager
* @param deviceType - Device type
* @return a list of Feature objects.
* @throws org.wso2.carbon.device.mgt.common.FeatureManagementException
*/
public List<Feature> getFeatures(String deviceType) throws FeatureManagementException;
public List<Operation> getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException;
}

@ -18,6 +18,7 @@
package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
@ -25,8 +26,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.dto.Status;
import org.wso2.carbon.device.mgt.core.dto.*;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
@ -35,6 +35,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.util.ArrayList;
import java.util.List;
@ -128,7 +129,29 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
@Override
public List<Device> getAllDevices() throws DeviceManagementException {
return null;
List<Device> convertedDevicesList = new ArrayList<Device>();
try {
List<org.wso2.carbon.device.mgt.core.dto.Device> devicesList = this.deviceDAO.getDevices();
for (int x = 0; x < devicesList.size(); x++) {
org.wso2.carbon.device.mgt.core.dto.Device device = devicesList.get(x);
device.setDeviceType(deviceTypeDAO.getDeviceType(device.getDeviceTypeId()));
DeviceManager dms =
this.getPluginRepository().getDeviceManagementProvider(device.getDeviceType().getName());
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());
}
convertedDevicesList.add(convertedDevice);
}
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining devices all devices", e);
}
return convertedDevicesList;
}
@Override
@ -161,7 +184,31 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
@Override
public List<Device> getDeviceListOfUser(String username) throws DeviceManagementException {
return null;
List<Device> devicesOfUser = new ArrayList<Device>();
try {
int tenantId = DeviceManagerUtil.getTenantId();
List<org.wso2.carbon.device.mgt.core.dto.Device> devicesList = this.deviceDAO.getDeviceListOfUser(username, tenantId);
for (int x = 0; x < devicesList.size(); x++) {
org.wso2.carbon.device.mgt.core.dto.Device device = devicesList.get(x);
device.setDeviceType(deviceTypeDAO.getDeviceType(device.getDeviceTypeId()));
DeviceManager dms =
this.getPluginRepository().getDeviceManagementProvider(device.getDeviceType().getName());
Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, device.getDeviceType());
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(device.getDeviceIdentificationId());
deviceIdentifier.setType(device.getDeviceType().getName());
Device dmsDevice = dms.getDevice(deviceIdentifier);
if (dmsDevice != null) {
convertedDevice.setProperties(dmsDevice.getProperties());
convertedDevice.setFeatures(dmsDevice.getFeatures());
}
devicesOfUser.add(convertedDevice);
}
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining devices for user " +
"'" + username + "'", e);
}
return devicesOfUser;
}
@Override
@ -247,9 +294,4 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
return operationManager.getPendingOperations(deviceId);
}
@Override
public List<Feature> getFeatures(String deviceType) throws FeatureManagementException {
return operationManager.getFeatures(deviceType);
}
}

@ -58,6 +58,6 @@ public interface DeviceDAO {
* @return List of devices of the user.
* @throws DeviceManagementDAOException
*/
List<Device> getDeviceListOfUser(String username) throws DeviceManagementDAOException;
List<Device> getDeviceListOfUser(String username , int tenantId) throws DeviceManagementDAOException;
}

@ -107,7 +107,7 @@ public class DeviceDAOImpl implements DeviceDAO {
conn = this.getConnection();
String sql =
"SELECT d.ID, d.DESCRIPTION, d.NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, d.OWNERSHIP, d.STATUS, " +
"d.DEVICE_TYPE_ID, d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM DM_DEVICE d, DEVICE_TYPE dt WHERE " +
"d.DEVICE_TYPE_ID, d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM DM_DEVICE d, DM_DEVICE_TYPE dt WHERE " +
"dt.NAME = ? AND d.DEVICE_IDENTIFICATION = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceIdentifier.getType());
@ -140,7 +140,42 @@ public class DeviceDAOImpl implements DeviceDAO {
@Override
public List<Device> getDevices() throws DeviceManagementDAOException {
return null;
Connection conn = null;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<Device> devicesList = null;
try {
conn = this.getConnection();
String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, " +
"DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, " +
"DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE ";
stmt = conn.prepareStatement(selectDBQueryForType);
resultSet = stmt.executeQuery();
devicesList = new ArrayList<Device>();
while (resultSet.next()) {
Device device = new Device();
device.setId(resultSet.getInt(1));
device.setDescription(resultSet.getString(2));
device.setName(resultSet.getString(3));
device.setDateOfEnrollment(resultSet.getLong(4));
device.setDateOfLastUpdate(resultSet.getLong(5));
//TODO:- Ownership is not a enum in DeviceDAO
device.setOwnerShip(resultSet.getString(6));
device.setStatus(Status.valueOf(resultSet.getString(7)));
device.setDeviceTypeId(resultSet.getInt(8));
device.setDeviceIdentificationId(resultSet.getString(9));
device.setOwnerId(resultSet.getString(10));
device.setTenantId(resultSet.getInt(11));
devicesList.add(device);
}
} catch (SQLException e) {
String msg = "Error occurred while listing all devices for type ";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(conn, stmt, resultSet);
}
return devicesList;
}
@Override
@ -178,9 +213,7 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devicesList = null;
try {
conn = this.getConnection();
String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, " +
"DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, " +
"DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE " +
String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE " +
"WHERE DM_DEVICE.DEVICE_TYPE_ID = ?";
stmt = conn.prepareStatement(selectDBQueryForType);
stmt.setInt(1, type);
@ -212,9 +245,50 @@ public class DeviceDAOImpl implements DeviceDAO {
return devicesList;
}
@Override
public List<Device> getDeviceListOfUser(String username) throws DeviceManagementDAOException {
return null;
@Override public List<Device> getDeviceListOfUser(String username, int tenantId) throws DeviceManagementDAOException {
Connection conn = this.getConnection();
PreparedStatement stmt = null;
List<Device> deviceList = new ArrayList<Device>();
try {
stmt = conn.prepareStatement(
"SELECT DM_DEVICE_TYPE.ID, DM_DEVICE_TYPE.NAME, DM_DEVICE.ID, DM_DEVICE.DESCRIPTION, " +
"DM_DEVICE.NAME, DM_DEVICE.DATE_OF_ENROLLMENT, DM_DEVICE.DATE_OF_LAST_UPDATE, " +
"DM_DEVICE.OWNERSHIP, DM_DEVICE.STATUS, DM_DEVICE.DEVICE_TYPE_ID, " +
"DM_DEVICE.DEVICE_IDENTIFICATION, DM_DEVICE.OWNER, DM_DEVICE.TENANT_ID FROM " +
"DM_DEVICE, DM_DEVICE_TYPE WHERE DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID " +
"AND DM_DEVICE.OWNER =? AND DM_DEVICE.TENANT_ID =?");
stmt.setString(1, username);
stmt.setInt(2, tenantId);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
Device device = new Device();
DeviceType deviceType = new DeviceType();
int id = resultSet.getInt(resultSet.getInt(1));
deviceType.setId(id);
deviceType.setName(resultSet.getString(2));
device.setId(resultSet.getInt(3));
device.setDescription(resultSet.getString(4));
device.setName(resultSet.getString(5));
device.setDateOfEnrollment(resultSet.getLong(6));
device.setDateOfLastUpdate(resultSet.getLong(7));
//TODO:- Ownership is not a enum in DeviceDAO
device.setOwnerShip(resultSet.getString(8));
device.setStatus(Status.valueOf(resultSet.getString(9)));
device.setDeviceTypeId(resultSet.getInt(10));
device.setDeviceIdentificationId(resultSet.getString(11));
device.setOwnerId(resultSet.getString(12));
device.setTenantId(resultSet.getInt(13));
deviceList.add(device);
}
} catch (SQLException e) {
String msg = "Error occurred while fetching the list of devices belongs to " + username;
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
}
return deviceList;
}
private Connection getConnection() throws DeviceManagementDAOException {

@ -22,21 +22,22 @@ import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfigurationManager;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
import org.wso2.carbon.registry.core.service.RegistryService;
@ -94,6 +95,8 @@ public class DeviceManagementServiceComponent {
DeviceManagementDataHolder.getInstance().setLicenseManager(licenseManager);
DeviceManagementDataHolder.getInstance().setLicenseConfig(licenseConfig);
OperationManagementDAOFactory.init(dsConfig);
/* If -Dsetup option enabled then create device management database schema */
String setupOption =
System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);

@ -85,11 +85,6 @@ public class OperationManagerImpl implements OperationManager {
return null;
}
@Override
public List<Feature> getFeatures(String deviceType) throws FeatureManagementException {
return null;
}
private OperationDAO lookupOperationDAO(Operation operation) {
if (operation instanceof CommandOperation) {
return commandOperationDAO;

@ -59,6 +59,9 @@ public class OperationManagementDAOFactory {
public static void init(DataSource dtSource) {
dataSource = dtSource;
}
public static void init(DataSourceConfig config) {
dataSource = resolveDataSource(config);
}
public static void beginTransaction() throws OperationManagementDAOException {
try {

@ -34,6 +34,8 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager,
List<Device> getAllDevices(String type) throws DeviceManagementException;
List<Device> getAllDevices() throws DeviceManagementException;
List<Device> getDeviceListOfUser(String username) throws DeviceManagementException;
}

@ -17,7 +17,10 @@
*/
package org.wso2.carbon.device.mgt.core.service;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
@ -70,7 +73,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@Override
public List<Device> getAllDevices() throws DeviceManagementException {
return null;
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getAllDevices();
}
@Override
@ -78,9 +81,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getAllDevices(type);
}
@Override
public List<Device> getDeviceListOfUser(String username) throws DeviceManagementException {
return null;
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDeviceListOfUser(username);
}
@Override
@ -127,9 +129,4 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getPendingOperations(deviceId);
}
@Override
public List<Feature> getFeatures(String deviceType) throws FeatureManagementException {
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getFeatures(deviceType);
}
}

@ -20,6 +20,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.context.PrivilegedCarbonContext;
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;
@ -39,103 +40,111 @@ 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);
}
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);
}
}
/**
* 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, " +
/**
* 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.getJndiLookupDefinition();
if (jndiConfig != null) {
if (log.isDebugEnabled()) {
log.debug("Initializing Device Management Repository data source using the JNDI Lookup Definition");
}
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
jndiConfig.getJndiProperties();
if (jndiPropertyList != null) {
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
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;
}
}
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
if (jndiConfig != null) {
if (log.isDebugEnabled()) {
log.debug("Initializing Device Management Repository data source using the JNDI Lookup Definition");
}
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
jndiConfig.getJndiProperties();
if (jndiPropertyList != null) {
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
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();
DeviceType deviceTypeId = deviceTypeDAO.getDeviceType(deviceType);
if (deviceTypeId == null) {
DeviceType dt = new DeviceType();
dt.setName(deviceType);
deviceTypeDAO.addDeviceType(dt);
}
status = true;
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while registering the device type '" +
/**
* 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();
DeviceType deviceTypeId = deviceTypeDAO.getDeviceType(deviceType);
if (deviceTypeId == null) {
DeviceType dt = new DeviceType();
dt.setName(deviceType);
deviceTypeDAO.addDeviceType(dt);
}
status = true;
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while registering the device type '" +
deviceType + "'", e);
}
return status;
}
}
return status;
}
/**
* Un-registers 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();
DeviceType deviceTypeId = deviceTypeDAO.getDeviceType(deviceType);
if (deviceTypeId == null) {
DeviceType dt = new DeviceType();
dt.setName(deviceType);
deviceTypeDAO.removeDeviceType(deviceType);
}
return true;
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while registering the device type '" +
/**
* Un-registers 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();
DeviceType deviceTypeId = deviceTypeDAO.getDeviceType(deviceType);
if (deviceTypeId == null) {
DeviceType dt = new DeviceType();
dt.setName(deviceType);
deviceTypeDAO.removeDeviceType(deviceType);
}
return true;
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while registering the device type '" +
deviceType + "'", e);
}
}
public static void sendEmail(){
}
}
public static Map<String, String> convertDevicePropertiesToMap(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;
}
public static int getTenantId() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
return ctx.getTenantId();
}
}

Loading…
Cancel
Save