mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Added device type to DB when registering the plugin
This commit is contained in:
parent
7f089b2a30
commit
0cd90fc349
@ -15,13 +15,18 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core;
|
package org.wso2.carbon.device.mgt.core;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class DeviceManagementRepository {
|
public class DeviceManagementRepository {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceManagerUtil.class);
|
||||||
private Map<String, DeviceManagerService> providers;
|
private Map<String, DeviceManagerService> providers;
|
||||||
|
|
||||||
public DeviceManagementRepository() {
|
public DeviceManagementRepository() {
|
||||||
@ -29,7 +34,13 @@ public class DeviceManagementRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addDeviceManagementProvider(DeviceManagerService provider) {
|
public void addDeviceManagementProvider(DeviceManagerService provider) {
|
||||||
providers.put(provider.getProviderType(), provider);
|
String deviceType = provider.getProviderType();
|
||||||
|
try {
|
||||||
|
DeviceManagerUtil.registerDeviceType(deviceType);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error("Exception occured while registering the device type.",e);
|
||||||
|
}
|
||||||
|
providers.put(deviceType, provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceManagerService getDeviceManagementProvider(String type) {
|
public DeviceManagerService getDeviceManagementProvider(String type) {
|
||||||
|
|||||||
@ -29,126 +29,131 @@ import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DeviceManagerImpl implements DeviceManager{
|
public class DeviceManagerImpl implements DeviceManager {
|
||||||
|
|
||||||
private DeviceDAO deviceDAO;
|
private DeviceDAO deviceDAO;
|
||||||
private DeviceTypeDAO deviceTypeDAO;
|
private DeviceTypeDAO deviceTypeDAO;
|
||||||
private DeviceManagementConfig config;
|
private DeviceManagementConfig config;
|
||||||
private DeviceManagementRepository pluginRepository;
|
private DeviceManagementRepository pluginRepository;
|
||||||
|
|
||||||
public DeviceManagerImpl(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) {
|
public DeviceManagerImpl(DeviceManagementConfig config,
|
||||||
this.config = config;
|
DeviceManagementRepository pluginRepository) {
|
||||||
this.pluginRepository = pluginRepository;
|
this.config = config;
|
||||||
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
this.pluginRepository = pluginRepository;
|
||||||
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||||
}
|
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms =
|
||||||
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||||
boolean status = dms.enrollDevice(device);
|
boolean status = dms.enrollDevice(device);
|
||||||
try {
|
try {
|
||||||
this.getDeviceTypeDAO().getDeviceType();
|
this.getDeviceTypeDAO().getDeviceType();
|
||||||
org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(
|
org.wso2.carbon.device.mgt.core.dto.Device deviceDto =
|
||||||
device);
|
DeviceManagementDAOUtil.convertDevice(
|
||||||
|
device);
|
||||||
|
|
||||||
Integer deviceTypeId = this.getDeviceDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
Integer deviceTypeId =
|
||||||
deviceDto.setDeviceType(deviceTypeId);
|
this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
||||||
this.getDeviceDAO().addDevice(deviceDto);
|
deviceDto.setDeviceType(deviceTypeId);
|
||||||
} catch (DeviceManagementDAOException e) {
|
this.getDeviceDAO().addDevice(deviceDto);
|
||||||
throw new DeviceManagementException("Error occurred while enrolling the device '" +
|
} catch (DeviceManagementDAOException e) {
|
||||||
device.getId() + "'", e);
|
throw new DeviceManagementException("Error occurred while enrolling the device '" +
|
||||||
}
|
device.getId() + "'", e);
|
||||||
return status;
|
}
|
||||||
}
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms =
|
||||||
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||||
boolean status = dms.modifyEnrollment(device);
|
boolean status = dms.modifyEnrollment(device);
|
||||||
try {
|
try {
|
||||||
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
|
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
throw new DeviceManagementException("Error occurred while modifying the device '" +
|
throw new DeviceManagementException("Error occurred while modifying the device '" +
|
||||||
device.getId() + "'", e);
|
device.getId() + "'", e);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms =
|
||||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
return dms.disenrollDevice(deviceId);
|
return dms.disenrollDevice(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms =
|
||||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
return dms.isEnrolled(deviceId);
|
return dms.isEnrolled(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms =
|
||||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
return dms.isActive(deviceId);
|
return dms.isActive(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||||
DeviceManagerService dms =
|
throws DeviceManagementException {
|
||||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
DeviceManagerService dms =
|
||||||
return dms.setActive(deviceId, status);
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
}
|
return dms.setActive(deviceId, status);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getAllDevices(String type) throws DeviceManagementException {
|
public List<Device> getAllDevices(String type) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms =
|
||||||
this.getPluginRepository().getDeviceManagementProvider(type);
|
this.getPluginRepository().getDeviceManagementProvider(type);
|
||||||
return dms.getAllDevices();
|
return dms.getAllDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms =
|
||||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
return dms.getDevice(deviceId);
|
return dms.getDevice(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms =
|
||||||
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||||
return dms.updateDeviceInfo(device);
|
return dms.updateDeviceInfo(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||||
DeviceManagerService dms =
|
throws DeviceManagementException {
|
||||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
DeviceManagerService dms =
|
||||||
return dms.setOwnership(deviceId, ownershipType);
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
}
|
return dms.setOwnership(deviceId, ownershipType);
|
||||||
|
}
|
||||||
|
|
||||||
public OperationManager getOperationManager(String type) throws DeviceManagementException {
|
public OperationManager getOperationManager(String type) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms =
|
||||||
this.getPluginRepository().getDeviceManagementProvider(type);
|
this.getPluginRepository().getDeviceManagementProvider(type);
|
||||||
return dms.getOperationManager();
|
return dms.getOperationManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceDAO getDeviceDAO() {
|
public DeviceDAO getDeviceDAO() {
|
||||||
return deviceDAO;
|
return deviceDAO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceTypeDAO getDeviceTypeDAO() {
|
public DeviceTypeDAO getDeviceTypeDAO() {
|
||||||
return deviceTypeDAO;
|
return deviceTypeDAO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceManagementRepository getPluginRepository() {
|
public DeviceManagementRepository getPluginRepository() {
|
||||||
return pluginRepository;
|
return pluginRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,4 @@ public interface DeviceDAO {
|
|||||||
Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException;
|
Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
List<Device> getDevices() throws DeviceManagementDAOException;
|
List<Device> getDevices() throws DeviceManagementDAOException;
|
||||||
|
|
||||||
Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,4 +36,6 @@ public interface DeviceTypeDAO {
|
|||||||
|
|
||||||
DeviceIdentifier getDeviceType() throws DeviceManagementDAOException;
|
DeviceIdentifier getDeviceType() throws DeviceManagementDAOException;
|
||||||
|
|
||||||
|
Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -102,38 +102,6 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException {
|
|
||||||
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet resultSet = null;
|
|
||||||
Integer deviceTypeId = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String createDBQuery =
|
|
||||||
"SELECT * From DM_DEVICE_TYPE DT WHERE DT.NAME=?";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(createDBQuery);
|
|
||||||
stmt.setString(1, type);
|
|
||||||
resultSet = stmt.executeQuery();
|
|
||||||
|
|
||||||
while(resultSet.next()){
|
|
||||||
deviceTypeId = resultSet.getInt(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while fetch device type id for device type '" + type + "'";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementDAOException(msg, e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return deviceTypeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Connection getConnection() throws DeviceManagementDAOException {
|
private Connection getConnection() throws DeviceManagementDAOException {
|
||||||
try {
|
try {
|
||||||
return dataSource.getConnection();
|
return dataSource.getConnection();
|
||||||
|
|||||||
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.dao.impl;
|
package org.wso2.carbon.device.mgt.core.dao.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||||
@ -24,55 +26,113 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
||||||
|
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceTypeDAOImpl.class);
|
||||||
|
|
||||||
public DeviceTypeDAOImpl(DataSource dataSource) {
|
public DeviceTypeDAOImpl(DataSource dataSource) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addDeviceType(DeviceType deviceType) throws DeviceManagementDAOException {
|
public void addDeviceType(DeviceType deviceType) throws DeviceManagementDAOException {
|
||||||
Connection conn = this.getConnection();
|
Connection conn = this.getConnection();
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_TYPE (NAME) VALUES (?)");
|
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_TYPE (NAME) VALUES (?)");
|
||||||
stmt.setString(1, deviceType.getName());
|
stmt.setString(1, deviceType.getName());
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while registering the device type '" +
|
String msg = "Error occurred while registering the device type '" +
|
||||||
deviceType.getName() + "'", e);
|
deviceType.getName() + "'";
|
||||||
} finally {
|
log.error(msg, e);
|
||||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
throw new DeviceManagementDAOException(msg, e);
|
||||||
}
|
} finally {
|
||||||
}
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDeviceType(DeviceType deviceType) throws DeviceManagementDAOException {
|
public void updateDeviceType(DeviceType deviceType) throws DeviceManagementDAOException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
|
public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
|
||||||
return null;
|
Connection conn = this.getConnection();
|
||||||
}
|
PreparedStatement stmt = null;
|
||||||
|
List<DeviceType> deviceTypes = new ArrayList<DeviceType>();
|
||||||
|
try {
|
||||||
|
stmt = conn.prepareStatement(
|
||||||
|
"SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE");
|
||||||
|
ResultSet results = stmt.executeQuery();
|
||||||
|
while (results.next()) {
|
||||||
|
DeviceType deviceType = new DeviceType();
|
||||||
|
deviceType.setId(results.getLong("DEVICE_TYPE_ID"));
|
||||||
|
deviceType.setName(results.getString("DEVICE_TYPE"));
|
||||||
|
deviceTypes.add(deviceType);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while fetching the registered device types";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||||
|
}
|
||||||
|
return deviceTypes;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DeviceIdentifier getDeviceType() throws DeviceManagementDAOException {
|
public DeviceIdentifier getDeviceType() throws DeviceManagementDAOException {
|
||||||
return new DeviceIdentifier();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection getConnection() throws DeviceManagementDAOException {
|
@Override
|
||||||
try {
|
public Integer getDeviceTypeIdByDeviceTypeName(String type)
|
||||||
return dataSource.getConnection();
|
throws DeviceManagementDAOException {
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DeviceManagementDAOException("Error occurred while obtaining a connection from the device " +
|
|
||||||
"management metadata repository datasource", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
Integer deviceTypeId = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String createDBQuery =
|
||||||
|
"SELECT * From DM_DEVICE_TYPE DT WHERE DT.NAME=?";
|
||||||
|
stmt = conn.prepareStatement(createDBQuery);
|
||||||
|
stmt.setString(1, type);
|
||||||
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
deviceTypeId = resultSet.getInt(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while fetch device type id for device type '" + type + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return deviceTypeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Connection getConnection() throws DeviceManagementDAOException {
|
||||||
|
try {
|
||||||
|
return dataSource.getConnection();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while obtaining a connection from the device " +
|
||||||
|
"management metadata repository datasource";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,11 @@ import org.w3c.dom.Document;
|
|||||||
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;
|
||||||
|
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.dao.util.DeviceManagementDAOUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
@ -80,4 +84,21 @@ public final class DeviceManagerUtil {
|
|||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean registerDeviceType(String deviceTypeName) throws DeviceManagementException{
|
||||||
|
boolean status = false;
|
||||||
|
try {
|
||||||
|
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||||
|
Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceTypeName);
|
||||||
|
if(deviceTypeId == null){
|
||||||
|
DeviceType deviceType = new DeviceType();
|
||||||
|
deviceType.setName(deviceTypeName);
|
||||||
|
deviceTypeDAO.addDeviceType(deviceType);
|
||||||
|
}
|
||||||
|
status = true;
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while registering the device type " + deviceTypeName;
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2014, 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.
|
||||||
|
-->
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import javax.xml.bind.Unmarshaller;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class responsible for the mobile device manager configuration initialization
|
* Class responsible for the mobile device manager configuration initialization.
|
||||||
*/
|
*/
|
||||||
public class MobileDeviceConfigurationManager {
|
public class MobileDeviceConfigurationManager {
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import javax.xml.bind.annotation.XmlElement;
|
|||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for holding management repository data
|
* Class for holding management repository data.
|
||||||
*/
|
*/
|
||||||
@XmlRootElement(name = "ManagementRepository")
|
@XmlRootElement(name = "ManagementRepository")
|
||||||
public class MobileDeviceManagementRepository {
|
public class MobileDeviceManagementRepository {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import javax.xml.bind.annotation.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for hold JndiLookupDefinition of mobile-config.xml at parsing with JAXB
|
* Class for hold JndiLookupDefinition of mobile-config.xml at parsing with JAXB.
|
||||||
*/
|
*/
|
||||||
@XmlRootElement(name = "JndiLookupDefinition")
|
@XmlRootElement(name = "JndiLookupDefinition")
|
||||||
public class JNDILookupDefinition {
|
public class JNDILookupDefinition {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import javax.xml.bind.annotation.XmlElement;
|
|||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for holding data source configuration in mobile-config.xml at parsing with JAXB
|
* Class for holding data source configuration in mobile-config.xml at parsing with JAXB.
|
||||||
*/
|
*/
|
||||||
@XmlRootElement(name = "DataSourceConfiguration")
|
@XmlRootElement(name = "DataSourceConfiguration")
|
||||||
public class MobileDataSourceConfig {
|
public class MobileDataSourceConfig {
|
||||||
|
|||||||
@ -49,7 +49,7 @@ public class MobileDeviceManagementDAOException extends Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new MobileDeviceManagementDAOException with the specified detail message
|
* Constructs a new MobileDeviceManagementDAOException with the specified detail message.
|
||||||
*
|
*
|
||||||
* @param message the detail message.
|
* @param message the detail message.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public class MobileDeviceManagementDAOUtil {
|
|||||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOUtil.class);
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOUtil.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve data source from the data source definition
|
* Resolve data source from the data source definition.
|
||||||
*
|
*
|
||||||
* @param config Mobile data source configuration
|
* @param config Mobile data source configuration
|
||||||
* @return data source resolved from the data source definition
|
* @return data source resolved from the data source definition
|
||||||
@ -128,7 +128,7 @@ public class MobileDeviceManagementDAOUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the creation of mobile device management schema if -Dsetup has provided
|
* Initializes the creation of mobile device management schema if -Dsetup has provided.
|
||||||
*
|
*
|
||||||
* @param dataSource Mobile data source
|
* @param dataSource Mobile data source
|
||||||
*/
|
*/
|
||||||
@ -151,7 +151,7 @@ public class MobileDeviceManagementDAOUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the mobile device management schema
|
* Creates the mobile device management schema.
|
||||||
*
|
*
|
||||||
* @param dataSource Mobile data source
|
* @param dataSource Mobile data source
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This represents the iOS implementation of DeviceManagerService. *
|
* This represents the iOS implementation of DeviceManagerService.
|
||||||
*/
|
*/
|
||||||
public class IOSDeviceManagerService implements DeviceManagerService {
|
public class IOSDeviceManagerService implements DeviceManagerService {
|
||||||
|
|
||||||
|
|||||||
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.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.DeviceManagementException;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class DeviceManagementUtil {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DeviceManagementUtil.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
~ Copyright 2011-2012 WSO2, Inc. (http://wso2.com)
|
~ Copyright 2014 WSO2, Inc. (http://wso2.com)
|
||||||
~
|
~
|
||||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
~ you may not use this file except in compliance with the License.
|
~ you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -142,4 +142,38 @@ public class Device {
|
|||||||
}
|
}
|
||||||
return responseMessage;
|
return responseMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/operations/{id}")
|
||||||
|
public org.wso2.carbon.device.mgt.common.Device getOperations(@PathParam("id") String id) {
|
||||||
|
String msg = "";
|
||||||
|
DeviceManagementService dmService;
|
||||||
|
org.wso2.carbon.device.mgt.common.Device device =
|
||||||
|
new org.wso2.carbon.device.mgt.common.Device();
|
||||||
|
|
||||||
|
try {
|
||||||
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
||||||
|
} finally {
|
||||||
|
PrivilegedCarbonContext.endTenantFlow();
|
||||||
|
}
|
||||||
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
||||||
|
try {
|
||||||
|
if (dmService != null) {
|
||||||
|
device = dmService.getDevice(deviceIdentifier);
|
||||||
|
if (device == null) {
|
||||||
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
msg = "Error occurred while fetching the device information.";
|
||||||
|
log.error(msg, e);
|
||||||
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE
|
||||||
(
|
(
|
||||||
ID INT(11) NOT NULL,
|
ID INT(11) auto_increment NOT NULL,
|
||||||
NAME VARCHAR(300) NULL DEFAULT NULL,
|
NAME VARCHAR(300) NULL DEFAULT NULL,
|
||||||
PRIMARY KEY (ID)
|
PRIMARY KEY (ID)
|
||||||
);
|
);
|
||||||
@ -22,5 +22,3 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE
|
|||||||
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
|
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
|
||||||
REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION
|
REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
-- TO:DO - Remove this INSERT sql statement.
|
|
||||||
Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (1, 'android');
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user