mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
This commit is contained in:
commit
d13ffbb7c0
@ -31,26 +31,28 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface DeviceManager {
|
public interface DeviceManager {
|
||||||
|
|
||||||
public boolean enrollDevice(Device device) throws DeviceManagementException;
|
public boolean enrollDevice(Device device) throws DeviceManagementException;
|
||||||
|
|
||||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException;
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException;
|
||||||
|
|
||||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||||
|
|
||||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException;
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||||
|
|
||||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException;
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||||
|
|
||||||
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException;
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||||
|
throws DeviceManagementException;
|
||||||
|
|
||||||
public List<Device> getAllDevices(String type) throws DeviceManagementException;
|
public List<Device> getAllDevices(String type) throws DeviceManagementException;
|
||||||
|
|
||||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||||
|
|
||||||
public boolean updateDeviceInfo(Device device) throws DeviceManagementException;
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException;
|
||||||
|
|
||||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException;
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||||
|
throws DeviceManagementException;
|
||||||
|
|
||||||
public OperationManager getOperationManager(String type) throws DeviceManagementException;
|
public OperationManager getOperationManager(String type) throws DeviceManagementException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,149 +38,169 @@ import java.util.List;
|
|||||||
|
|
||||||
public class DeviceManagerImpl implements DeviceManager {
|
public class DeviceManagerImpl implements DeviceManager {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceManagerImpl.class);
|
private static Log log = LogFactory.getLog(DeviceManagerImpl.class);
|
||||||
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 = this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
DeviceManagerService dms =
|
||||||
boolean status = dms.enrollDevice(device);
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||||
try {
|
boolean status = dms.enrollDevice(device);
|
||||||
org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device);
|
try {
|
||||||
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
org.wso2.carbon.device.mgt.core.dto.Device deviceDto =
|
||||||
deviceDto.setStatus(Status.ACTIVE);
|
DeviceManagementDAOUtil.convertDevice(device);
|
||||||
deviceDto.setDeviceTypeId(deviceTypeId);
|
Integer deviceTypeId =
|
||||||
this.getDeviceDAO().addDevice(deviceDto);
|
this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
||||||
} catch (DeviceManagementDAOException e) {
|
deviceDto.setStatus(Status.ACTIVE);
|
||||||
throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'",
|
deviceDto.setDeviceTypeId(deviceTypeId);
|
||||||
e);
|
this.getDeviceDAO().addDevice(deviceDto);
|
||||||
}
|
} catch (DeviceManagementDAOException e) {
|
||||||
return status;
|
throw new DeviceManagementException(
|
||||||
}
|
"Error occurred while enrolling the device '" + device.getId() + "'",
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||||
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
DeviceManagerService dms =
|
||||||
boolean status = dms.modifyEnrollment(device);
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||||
try {
|
boolean status = dms.modifyEnrollment(device);
|
||||||
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
|
try {
|
||||||
} catch (DeviceManagementDAOException e) {
|
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
|
||||||
throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + "'",
|
} catch (DeviceManagementDAOException e) {
|
||||||
e);
|
throw new DeviceManagementException(
|
||||||
}
|
"Error occurred while modifying the device '" + device.getId() + "'",
|
||||||
return status;
|
e);
|
||||||
}
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
DeviceManagerService dms =
|
||||||
return dms.disenrollDevice(deviceId);
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
}
|
return dms.disenrollDevice(deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
DeviceManagerService dms =
|
||||||
return dms.isEnrolled(deviceId);
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
}
|
return dms.isEnrolled(deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
DeviceManagerService dms =
|
||||||
return dms.isActive(deviceId);
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
}
|
return dms.isActive(deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||||
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
throws DeviceManagementException {
|
||||||
return dms.setActive(deviceId, status);
|
DeviceManagerService dms =
|
||||||
}
|
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 = this.getPluginRepository().getDeviceManagementProvider(type);
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type);
|
||||||
List<Device> devicesList = new ArrayList<Device>();
|
List<Device> devicesList = new ArrayList<Device>();
|
||||||
try {
|
try {
|
||||||
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type);
|
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type);
|
||||||
List<org.wso2.carbon.device.mgt.core.dto.Device> devices = this.getDeviceDAO().getDevices(deviceTypeId);
|
List<org.wso2.carbon.device.mgt.core.dto.Device> devices =
|
||||||
|
this.getDeviceDAO().getDevices(deviceTypeId);
|
||||||
|
|
||||||
for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) {
|
for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) {
|
||||||
DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId());
|
DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId());
|
||||||
Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType);
|
Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType);
|
||||||
DeviceIdentifier deviceIdentifier = DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType);
|
DeviceIdentifier deviceIdentifier =
|
||||||
Device dmsDevice = dms.getDevice(deviceIdentifier);
|
DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType);
|
||||||
if (dmsDevice != null) {
|
Device dmsDevice = dms.getDevice(deviceIdentifier);
|
||||||
convertedDevice.setProperties(dmsDevice.getProperties());
|
if (dmsDevice != null) {
|
||||||
convertedDevice.setFeatures(dmsDevice.getFeatures());
|
convertedDevice.setProperties(dmsDevice.getProperties());
|
||||||
}
|
convertedDevice.setFeatures(dmsDevice.getFeatures());
|
||||||
devicesList.add(convertedDevice);
|
}
|
||||||
}
|
devicesList.add(convertedDevice);
|
||||||
} catch (DeviceManagementDAOException e) {
|
}
|
||||||
throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + "'", e);
|
} catch (DeviceManagementDAOException e) {
|
||||||
}
|
throw new DeviceManagementException(
|
||||||
return devicesList;
|
"Error occurred while obtaining the device for type '" + type + "'", e);
|
||||||
}
|
}
|
||||||
|
return devicesList;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
DeviceManagerService dms =
|
||||||
Device convertedDevice = null;
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
try {
|
Device convertedDevice = null;
|
||||||
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType());
|
try {
|
||||||
org.wso2.carbon.device.mgt.core.dto.Device device =
|
Integer deviceTypeId =
|
||||||
this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId());
|
this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType());
|
||||||
if (device != null) {
|
org.wso2.carbon.device.mgt.core.dto.Device device =
|
||||||
convertedDevice = DeviceManagementDAOUtil
|
this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId());
|
||||||
.convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId));
|
if (device != null) {
|
||||||
Device dmsDevice = dms.getDevice(deviceId);
|
convertedDevice = DeviceManagementDAOUtil
|
||||||
if (dmsDevice != null) {
|
.convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId));
|
||||||
convertedDevice.setProperties(dmsDevice.getProperties());
|
Device dmsDevice = dms.getDevice(deviceId);
|
||||||
convertedDevice.setFeatures(dmsDevice.getFeatures());
|
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);
|
} catch (DeviceManagementDAOException e) {
|
||||||
}
|
throw new DeviceManagementException(
|
||||||
return convertedDevice;
|
"Error occurred while obtaining the device for id '" + deviceId.getId() + "'",
|
||||||
}
|
e);
|
||||||
|
}
|
||||||
|
return convertedDevice;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
||||||
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
DeviceManagerService dms =
|
||||||
return dms.updateDeviceInfo(device);
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||||
}
|
return dms.updateDeviceInfo(device);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
DeviceManagerService dms = 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 = this.getPluginRepository().getDeviceManagementProvider(type);
|
DeviceManagerService dms = 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,45 +30,46 @@ import javax.xml.bind.Unmarshaller;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class responsible for the cdm manager configuration initialization
|
* Class responsible for the cdm manager configuration initialization.
|
||||||
*/
|
*/
|
||||||
public class DeviceConfigurationManager {
|
public class DeviceConfigurationManager {
|
||||||
|
|
||||||
private DeviceManagementConfig currentDeviceConfig;
|
private DeviceManagementConfig currentDeviceConfig;
|
||||||
private static DeviceConfigurationManager deviceConfigManager;
|
private static DeviceConfigurationManager deviceConfigManager;
|
||||||
|
|
||||||
private static final String deviceMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
|
private static final String deviceMgtConfigXMLPath =
|
||||||
DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME;
|
CarbonUtils.getCarbonConfigDirPath() + File.separator +
|
||||||
|
DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME;
|
||||||
|
|
||||||
public static DeviceConfigurationManager getInstance() {
|
public static DeviceConfigurationManager getInstance() {
|
||||||
if (deviceConfigManager == null) {
|
if (deviceConfigManager == null) {
|
||||||
synchronized (DeviceConfigurationManager.class) {
|
synchronized (DeviceConfigurationManager.class) {
|
||||||
if (deviceConfigManager == null) {
|
if (deviceConfigManager == null) {
|
||||||
deviceConfigManager = new DeviceConfigurationManager();
|
deviceConfigManager = new DeviceConfigurationManager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return deviceConfigManager;
|
return deviceConfigManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void initConfig() throws DeviceManagementException {
|
public synchronized void initConfig() throws DeviceManagementException {
|
||||||
|
|
||||||
//catch generic exception.if any exception occurs wrap and throw DeviceManagementException
|
//catch generic exception.if any exception occurs wrap and throw DeviceManagementException
|
||||||
try {
|
try {
|
||||||
File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
|
File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
|
||||||
Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
|
Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
|
||||||
|
|
||||||
/* Un-marshaling Device Management configuration */
|
/* Un-marshaling Device Management configuration */
|
||||||
JAXBContext cdmContext = JAXBContext.newInstance(DeviceManagementConfig.class);
|
JAXBContext cdmContext = JAXBContext.newInstance(DeviceManagementConfig.class);
|
||||||
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
|
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
|
||||||
this.currentDeviceConfig = (DeviceManagementConfig) unmarshaller.unmarshal(doc);
|
this.currentDeviceConfig = (DeviceManagementConfig) unmarshaller.unmarshal(doc);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new DeviceManagementException("Error occurred while initializing RSS config", e);
|
throw new DeviceManagementException("Error occurred while initializing RSS config", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceManagementConfig getDeviceManagementConfig() {
|
public DeviceManagementConfig getDeviceManagementConfig() {
|
||||||
return currentDeviceConfig;
|
return currentDeviceConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,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 DeviceManagementRepository {
|
public class DeviceManagementRepository {
|
||||||
|
|||||||
@ -32,42 +32,42 @@ import java.io.File;
|
|||||||
|
|
||||||
public class LicenseConfigurationManager {
|
public class LicenseConfigurationManager {
|
||||||
|
|
||||||
private LicenseManagementConfig licenseMgtConfig;
|
private LicenseManagementConfig licenseMgtConfig;
|
||||||
private static LicenseConfigurationManager licenseConfigManager;
|
private static LicenseConfigurationManager licenseConfigManager;
|
||||||
|
|
||||||
private static final String licenseMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
|
private static final String licenseMgtConfigXMLPath =
|
||||||
DeviceManagementConstants.Common.DEFAULT_LICENSE_CONFIG_XML_NAME;
|
CarbonUtils.getCarbonConfigDirPath() + File.separator +
|
||||||
|
DeviceManagementConstants.Common.DEFAULT_LICENSE_CONFIG_XML_NAME;
|
||||||
|
|
||||||
public static LicenseConfigurationManager getInstance() {
|
public static LicenseConfigurationManager getInstance() {
|
||||||
if (licenseConfigManager == null) {
|
if (licenseConfigManager == null) {
|
||||||
synchronized (LicenseConfigurationManager.class) {
|
synchronized (LicenseConfigurationManager.class) {
|
||||||
if (licenseConfigManager == null) {
|
if (licenseConfigManager == null) {
|
||||||
licenseConfigManager = new LicenseConfigurationManager();
|
licenseConfigManager = new LicenseConfigurationManager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return licenseConfigManager;
|
return licenseConfigManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void initConfig() throws LicenseManagementException {
|
public synchronized void initConfig() throws LicenseManagementException {
|
||||||
|
|
||||||
//catch generic exception.if any exception occurs wrap and throw LicenseManagementException
|
//catch generic exception.if any exception occurs wrap and throw LicenseManagementException
|
||||||
try {
|
try {
|
||||||
File licenseMgtConfig = new File(licenseMgtConfigXMLPath);
|
File licenseMgtConfig = new File(licenseMgtConfigXMLPath);
|
||||||
Document doc = DeviceManagerUtil.convertToDocument(licenseMgtConfig);
|
Document doc = DeviceManagerUtil.convertToDocument(licenseMgtConfig);
|
||||||
|
|
||||||
/* Un-marshaling License Management configuration */
|
/* Un-marshaling License Management configuration */
|
||||||
JAXBContext cdmContext = JAXBContext.newInstance(LicenseManagementConfig.class);
|
JAXBContext cdmContext = JAXBContext.newInstance(LicenseManagementConfig.class);
|
||||||
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
|
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
|
||||||
this.licenseMgtConfig = (LicenseManagementConfig) unmarshaller.unmarshal(doc);
|
this.licenseMgtConfig = (LicenseManagementConfig) unmarshaller.unmarshal(doc);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new LicenseManagementException("Error occurred while initializing RSS config", e);
|
throw new LicenseManagementException("Error occurred while initializing RSS config", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LicenseManagementConfig getLicenseMgtConfig() {
|
|
||||||
return licenseMgtConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public LicenseManagementConfig getLicenseMgtConfig() {
|
||||||
|
return licenseMgtConfig;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,8 @@ 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 malformed-cdm-config-no-mgt-repo.xml at parsing with JAXB
|
* Class for holding data source configuration in malformed-cdm-config-no-mgt-repo.xml at parsing
|
||||||
|
* with JAXB.
|
||||||
*/
|
*/
|
||||||
@XmlRootElement(name = "DataSourceConfiguration")
|
@XmlRootElement(name = "DataSourceConfiguration")
|
||||||
public class DataSourceConfig {
|
public class DataSourceConfig {
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import javax.xml.bind.annotation.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for hold JndiLookupDefinition of rss-manager.xml at parsing with JAXB
|
* Class for hold JndiLookupDefinition of rss-manager.xml at parsing with JAXB.
|
||||||
*/
|
*/
|
||||||
@XmlRootElement(name = "JndiLookupDefinition")
|
@XmlRootElement(name = "JndiLookupDefinition")
|
||||||
public class JNDILookupDefinition {
|
public class JNDILookupDefinition {
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import org.wso2.carbon.device.mgt.core.dto.Status;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the key operations associated with persisting device related information
|
* This class represents the key operations associated with persisting device related information.
|
||||||
*/
|
*/
|
||||||
public interface DeviceDAO {
|
public interface DeviceDAO {
|
||||||
|
|
||||||
@ -44,7 +44,8 @@ public interface DeviceDAO {
|
|||||||
* @return the Device object which matches given data
|
* @return the Device object which matches given data
|
||||||
* @throws DeviceManagementDAOException
|
* @throws DeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
Device getDeviceByDeviceIdentifier(Integer type, String identifier) throws DeviceManagementDAOException;
|
Device getDeviceByDeviceIdentifier(Integer type, String identifier)
|
||||||
|
throws DeviceManagementDAOException;
|
||||||
|
|
||||||
List<Device> getDevices() throws DeviceManagementDAOException;
|
List<Device> getDevices() throws DeviceManagementDAOException;
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
package org.wso2.carbon.device.mgt.core.dao;
|
package org.wso2.carbon.device.mgt.core.dao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom exception class for data access related exceptions
|
* Custom exception class for data access related exceptions.
|
||||||
*/
|
*/
|
||||||
public class DeviceManagementDAOException extends Exception {
|
public class DeviceManagementDAOException extends Exception {
|
||||||
|
|
||||||
|
|||||||
@ -25,64 +25,69 @@ import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
|
|||||||
import org.wso2.carbon.device.mgt.core.dao.impl.DeviceDAOImpl;
|
import org.wso2.carbon.device.mgt.core.dao.impl.DeviceDAOImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl;
|
import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DeviceManagementDAOFactory {
|
public class DeviceManagementDAOFactory {
|
||||||
|
|
||||||
private static DataSource dataSource;
|
private static DataSource dataSource;
|
||||||
private static final Log log = LogFactory.getLog(DeviceManagementDAOFactory.class);
|
private static final Log log = LogFactory.getLog(DeviceManagementDAOFactory.class);
|
||||||
|
|
||||||
public static DeviceDAO getDeviceDAO() {
|
public static DeviceDAO getDeviceDAO() {
|
||||||
return new DeviceDAOImpl(dataSource);
|
return new DeviceDAOImpl(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DeviceTypeDAO getDeviceTypeDAO() {
|
public static DeviceTypeDAO getDeviceTypeDAO() {
|
||||||
return new DeviceTypeDAOImpl(dataSource);
|
return new DeviceTypeDAOImpl(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(DataSourceConfig config) {
|
public static void init(DataSourceConfig config) {
|
||||||
dataSource = resolveDataSource(config);
|
dataSource = resolveDataSource(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(DataSource dtSource) {
|
public static void init(DataSource dtSource) {
|
||||||
dataSource = dtSource;
|
dataSource = dtSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
private static DataSource resolveDataSource(DataSourceConfig config) {
|
private 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 " + "is null and " +
|
throw new RuntimeException(
|
||||||
"thus, is not initialized");
|
"Device Management Repository data source configuration " + "is null and " +
|
||||||
}
|
"thus, is not initialized");
|
||||||
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
|
}
|
||||||
if (jndiConfig != null) {
|
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
|
||||||
if (log.isDebugEnabled()) {
|
if (jndiConfig != null) {
|
||||||
log.debug("Initializing Device Management Repository data source using the JNDI " +
|
if (log.isDebugEnabled()) {
|
||||||
"Lookup Definition");
|
log.debug("Initializing Device Management Repository data source using the JNDI " +
|
||||||
}
|
"Lookup Definition");
|
||||||
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = jndiConfig.getJndiProperties();
|
}
|
||||||
if (jndiPropertyList != null) {
|
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
|
||||||
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
|
jndiConfig.getJndiProperties();
|
||||||
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
if (jndiPropertyList != null) {
|
||||||
jndiProperties.put(prop.getName(), prop.getValue());
|
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
|
||||||
}
|
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
||||||
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
jndiProperties.put(prop.getName(), prop.getValue());
|
||||||
} else {
|
}
|
||||||
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
dataSource = DeviceManagementDAOUtil
|
||||||
}
|
.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
||||||
}
|
} else {
|
||||||
return dataSource;
|
dataSource =
|
||||||
}
|
DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
public static DataSource getDataSource() {
|
public static DataSource getDataSource() {
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,20 +22,21 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the key operations associated with persisting device type related information
|
* This class represents the key operations associated with persisting device type related
|
||||||
|
* information.
|
||||||
*/
|
*/
|
||||||
public interface DeviceTypeDAO {
|
public interface DeviceTypeDAO {
|
||||||
|
|
||||||
void addDeviceType(DeviceType deviceType) throws DeviceManagementDAOException;
|
void addDeviceType(DeviceType deviceType) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
void updateDeviceType(DeviceType deviceType) throws DeviceManagementDAOException;
|
void updateDeviceType(DeviceType deviceType) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException;
|
List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException;
|
||||||
|
|
||||||
DeviceType getDeviceType(Integer id) throws DeviceManagementDAOException;
|
DeviceType getDeviceType(Integer id) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException;
|
Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
void removeDeviceType(DeviceType deviceType) throws DeviceManagementDAOException;
|
void removeDeviceType(DeviceType deviceType) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,15 +44,16 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void addDevice(Device device) throws DeviceManagementDAOException {
|
@Override
|
||||||
|
public void addDevice(Device device) throws DeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String createDBQuery =
|
String createDBQuery =
|
||||||
"INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DATE_OF_ENROLLMENT, DATE_OF_LAST_UPDATE, OWNERSHIP," +
|
"INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DATE_OF_ENROLLMENT, DATE_OF_LAST_UPDATE, " +
|
||||||
"STATUS, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, OWNER, TENANT_ID) VALUES " +
|
"OWNERSHIP, STATUS, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, OWNER, TENANT_ID) " +
|
||||||
"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
|
||||||
stmt = conn.prepareStatement(createDBQuery);
|
stmt = conn.prepareStatement(createDBQuery);
|
||||||
stmt.setString(1, device.getDescription());
|
stmt.setString(1, device.getDescription());
|
||||||
@ -75,23 +76,29 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void updateDevice(Device device) throws DeviceManagementDAOException {
|
@Override
|
||||||
|
public void updateDevice(Device device) throws DeviceManagementDAOException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void updateDeviceStatus(Long deviceId, Status status) throws DeviceManagementDAOException {
|
@Override
|
||||||
|
public void updateDeviceStatus(Long deviceId, Status status)
|
||||||
|
throws DeviceManagementDAOException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void deleteDevice(Long deviceId) throws DeviceManagementDAOException {
|
@Override
|
||||||
|
public void deleteDevice(Long deviceId) throws DeviceManagementDAOException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException {
|
@Override
|
||||||
|
public Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Device getDeviceByDeviceIdentifier(Integer type, String identifier)
|
@Override
|
||||||
|
public Device getDeviceByDeviceIdentifier(Integer type, String identifier)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -102,7 +109,8 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|||||||
String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, " +
|
String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, " +
|
||||||
"DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, " +
|
"DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, " +
|
||||||
"DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE " +
|
"DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE " +
|
||||||
"WHERE DM_DEVICE.DEVICE_TYPE_ID=? AND DM_DEVICE.DEVICE_IDENTIFICATION=?";
|
"WHERE DM_DEVICE.DEVICE_TYPE_ID=? AND " +
|
||||||
|
"DM_DEVICE.DEVICE_IDENTIFICATION=?";
|
||||||
stmt = conn.prepareStatement(selectDBQueryForType);
|
stmt = conn.prepareStatement(selectDBQueryForType);
|
||||||
stmt.setInt(1, type);
|
stmt.setInt(1, type);
|
||||||
stmt.setString(2, identifier);
|
stmt.setString(2, identifier);
|
||||||
@ -132,11 +140,13 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public List<Device> getDevices() throws DeviceManagementDAOException {
|
@Override
|
||||||
|
public List<Device> getDevices() throws DeviceManagementDAOException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public List<Device> getDevices(Integer type) throws DeviceManagementDAOException {
|
@Override
|
||||||
|
public List<Device> getDevices(Integer type) throws DeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
@ -181,8 +191,9 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|||||||
try {
|
try {
|
||||||
return dataSource.getConnection();
|
return dataSource.getConnection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while obtaining a connection from the device " +
|
throw new DeviceManagementDAOException(
|
||||||
"management metadata repository datasource", e);
|
"Error occurred while obtaining a connection from the device " +
|
||||||
|
"management metadata repository datasource", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -40,121 +40,124 @@ import java.util.Hashtable;
|
|||||||
|
|
||||||
public final class DeviceManagementDAOUtil {
|
public final class DeviceManagementDAOUtil {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DeviceManagementDAOUtil.class);
|
private static final Log log = LogFactory.getLog(DeviceManagementDAOUtil.class);
|
||||||
|
|
||||||
public static void cleanupResources(Connection conn, PreparedStatement stmt, ResultSet rs) {
|
public static void cleanupResources(Connection conn, PreparedStatement stmt, ResultSet rs) {
|
||||||
if (rs != null) {
|
if (rs != null) {
|
||||||
try {
|
try {
|
||||||
rs.close();
|
rs.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.warn("Error occurred while closing result set", e);
|
log.warn("Error occurred while closing result set", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (stmt != null) {
|
if (stmt != null) {
|
||||||
try {
|
try {
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.warn("Error occurred while closing prepared statement", e);
|
log.warn("Error occurred while closing prepared statement", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
try {
|
try {
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.warn("Error occurred while closing database connection", e);
|
log.warn("Error occurred while closing database connection", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id of the current tenant.
|
* Get id of the current tenant.
|
||||||
*
|
*
|
||||||
* @return tenant id
|
* @return tenant id
|
||||||
* @throws DeviceManagementDAOException if an error is observed when getting tenant id
|
* @throws DeviceManagementDAOException if an error is observed when getting tenant id
|
||||||
*/
|
*/
|
||||||
public static int getTenantId() throws DeviceManagementDAOException {
|
public static int getTenantId() throws DeviceManagementDAOException {
|
||||||
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
|
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
|
||||||
int tenantId = context.getTenantId();
|
int tenantId = context.getTenantId();
|
||||||
if (tenantId != MultitenantConstants.INVALID_TENANT_ID) {
|
if (tenantId != MultitenantConstants.INVALID_TENANT_ID) {
|
||||||
return tenantId;
|
return tenantId;
|
||||||
}
|
}
|
||||||
String tenantDomain = context.getTenantDomain();
|
String tenantDomain = context.getTenantDomain();
|
||||||
if (tenantDomain == null) {
|
if (tenantDomain == null) {
|
||||||
String msg = "Tenant domain is not properly set and thus, is null";
|
String msg = "Tenant domain is not properly set and thus, is null";
|
||||||
throw new DeviceManagementDAOException(msg);
|
throw new DeviceManagementDAOException(msg);
|
||||||
}
|
}
|
||||||
TenantManager tenantManager = DeviceManagementDataHolder.getInstance().getTenantManager();
|
TenantManager tenantManager = DeviceManagementDataHolder.getInstance().getTenantManager();
|
||||||
try {
|
try {
|
||||||
tenantId = tenantManager.getTenantId(tenantDomain);
|
tenantId = tenantManager.getTenantId(tenantDomain);
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while retrieving id from the domain of tenant " + tenantDomain;
|
String msg =
|
||||||
throw new DeviceManagementDAOException(msg);
|
"Error occurred while retrieving id from the domain of tenant " + tenantDomain;
|
||||||
}
|
throw new DeviceManagementDAOException(msg);
|
||||||
return tenantId;
|
}
|
||||||
}
|
return tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
public static DataSource lookupDataSource(String dataSourceName, final Hashtable<Object, Object> jndiProperties) {
|
public static DataSource lookupDataSource(String dataSourceName,
|
||||||
try {
|
final Hashtable<Object, Object> jndiProperties) {
|
||||||
if (jndiProperties == null || jndiProperties.isEmpty()) {
|
try {
|
||||||
return (DataSource) InitialContext.doLookup(dataSourceName);
|
if (jndiProperties == null || jndiProperties.isEmpty()) {
|
||||||
}
|
return (DataSource) InitialContext.doLookup(dataSourceName);
|
||||||
final InitialContext context = new InitialContext(jndiProperties);
|
}
|
||||||
return (DataSource) context.lookup(dataSourceName);
|
final InitialContext context = new InitialContext(jndiProperties);
|
||||||
} catch (Exception e) {
|
return (DataSource) context.lookup(dataSourceName);
|
||||||
throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
|
} catch (Exception e) {
|
||||||
}
|
throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param device - The DTO device object.
|
* @param device - The DTO device object.
|
||||||
* @param deviceType - The DeviceType object associated with the device
|
* @param deviceType - The DeviceType object associated with the device
|
||||||
* @return A Business Object.
|
* @return A Business Object.
|
||||||
*/
|
*/
|
||||||
public static org.wso2.carbon.device.mgt.common.Device convertDevice(Device device, DeviceType deviceType){
|
public static org.wso2.carbon.device.mgt.common.Device convertDevice(Device device,
|
||||||
org.wso2.carbon.device.mgt.common.Device deviceBO =
|
DeviceType deviceType) {
|
||||||
new org.wso2.carbon.device.mgt.common.Device();
|
org.wso2.carbon.device.mgt.common.Device deviceBO =
|
||||||
deviceBO.setDateOfEnrolment(device.getDateOfEnrollment());
|
new org.wso2.carbon.device.mgt.common.Device();
|
||||||
deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate());
|
deviceBO.setDateOfEnrolment(device.getDateOfEnrollment());
|
||||||
deviceBO.setDescription(device.getDescription());
|
deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate());
|
||||||
deviceBO.setDeviceIdentifier(device.getDeviceIdentificationId());
|
deviceBO.setDescription(device.getDescription());
|
||||||
deviceBO.setDeviceTypeId(device.getDeviceTypeId());
|
deviceBO.setDeviceIdentifier(device.getDeviceIdentificationId());
|
||||||
deviceBO.setType(deviceType.getName());
|
deviceBO.setDeviceTypeId(device.getDeviceTypeId());
|
||||||
deviceBO.setName(device.getName());
|
deviceBO.setType(deviceType.getName());
|
||||||
deviceBO.setId(device.getId());
|
deviceBO.setName(device.getName());
|
||||||
deviceBO.setOwner(device.getOwnerId());
|
deviceBO.setId(device.getId());
|
||||||
deviceBO.setOwnership(device.getOwnerShip());
|
deviceBO.setOwner(device.getOwnerId());
|
||||||
if (device.getStatus() == Status.ACTIVE) {
|
deviceBO.setOwnership(device.getOwnerShip());
|
||||||
deviceBO.setStatus(true);
|
if (device.getStatus() == Status.ACTIVE) {
|
||||||
} else if (device.getStatus() == Status.INACTIVE) {
|
deviceBO.setStatus(true);
|
||||||
deviceBO.setStatus(false);
|
} else if (device.getStatus() == Status.INACTIVE) {
|
||||||
}
|
deviceBO.setStatus(false);
|
||||||
return deviceBO;
|
}
|
||||||
}
|
return deviceBO;
|
||||||
|
}
|
||||||
|
|
||||||
public static Device convertDevice(org.wso2.carbon.device.mgt.common.Device
|
public static Device convertDevice(org.wso2.carbon.device.mgt.common.Device
|
||||||
device) throws DeviceManagementDAOException {
|
device) throws DeviceManagementDAOException {
|
||||||
Device deviceBO = new Device();
|
Device deviceBO = new Device();
|
||||||
deviceBO.setDescription(device.getDescription());
|
deviceBO.setDescription(device.getDescription());
|
||||||
deviceBO.setName(device.getName());
|
deviceBO.setName(device.getName());
|
||||||
deviceBO.setDateOfEnrollment(device.getDateOfEnrolment());
|
deviceBO.setDateOfEnrollment(device.getDateOfEnrolment());
|
||||||
deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate());
|
deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate());
|
||||||
|
|
||||||
if (!device.isStatus()){
|
if (!device.isStatus()) {
|
||||||
deviceBO.setStatus(Status.INACTIVE);
|
deviceBO.setStatus(Status.INACTIVE);
|
||||||
}else{
|
} else {
|
||||||
deviceBO.setStatus(Status.ACTIVE);
|
deviceBO.setStatus(Status.ACTIVE);
|
||||||
}
|
}
|
||||||
deviceBO.setOwnerId(device.getOwner());
|
deviceBO.setOwnerId(device.getOwner());
|
||||||
deviceBO.setOwnerShip(device.getOwnership());
|
deviceBO.setOwnerShip(device.getOwnership());
|
||||||
deviceBO.setTenantId(DeviceManagementDAOUtil.getTenantId());
|
deviceBO.setTenantId(DeviceManagementDAOUtil.getTenantId());
|
||||||
deviceBO.setDeviceIdentificationId(device.getDeviceIdentifier());
|
deviceBO.setDeviceIdentificationId(device.getDeviceIdentifier());
|
||||||
return deviceBO;
|
return deviceBO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DeviceIdentifier createDeviceIdentifier(Device device, DeviceType deviceType) {
|
public static DeviceIdentifier createDeviceIdentifier(Device device, DeviceType deviceType) {
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setType(deviceType.getName());
|
deviceIdentifier.setType(deviceType.getName());
|
||||||
deviceIdentifier.setId(device.getDeviceIdentificationId());
|
deviceIdentifier.setId(device.getDeviceIdentificationId());
|
||||||
return deviceIdentifier;
|
return deviceIdentifier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,112 +52,123 @@ import org.wso2.carbon.user.core.service.RealmService;
|
|||||||
*/
|
*/
|
||||||
public class DeviceManagementServiceComponent {
|
public class DeviceManagementServiceComponent {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
|
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
|
||||||
private DeviceManagementRepository pluginRepository = new DeviceManagementRepository();
|
private DeviceManagementRepository pluginRepository = new DeviceManagementRepository();
|
||||||
|
|
||||||
protected void activate(ComponentContext componentContext) {
|
protected void activate(ComponentContext componentContext) {
|
||||||
try {
|
try {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Initializing device management core bundle");
|
log.debug("Initializing device management core bundle");
|
||||||
}
|
}
|
||||||
/* Initializing Device Management Configuration */
|
/* Initializing Device Management Configuration */
|
||||||
DeviceConfigurationManager.getInstance().initConfig();
|
DeviceConfigurationManager.getInstance().initConfig();
|
||||||
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
DeviceManagementConfig config =
|
||||||
|
DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
||||||
|
|
||||||
DataSourceConfig dsConfig = config.getDeviceMgtRepository().getDataSourceConfig();
|
DataSourceConfig dsConfig = config.getDeviceMgtRepository().getDataSourceConfig();
|
||||||
DeviceManagementDAOFactory.init(dsConfig);
|
DeviceManagementDAOFactory.init(dsConfig);
|
||||||
|
|
||||||
DeviceManager deviceManager = new DeviceManagerImpl(config, this.getPluginRepository());
|
DeviceManager deviceManager = new DeviceManagerImpl(config, this.getPluginRepository());
|
||||||
DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager);
|
DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager);
|
||||||
|
|
||||||
/* If -Dsetup option enabled then create device management database schema */
|
/* If -Dsetup option enabled then create device management database schema */
|
||||||
String setupOption = System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);
|
String setupOption =
|
||||||
if (setupOption != null) {
|
System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);
|
||||||
if (log.isDebugEnabled()) {
|
if (setupOption != null) {
|
||||||
log.debug("-Dsetup is enabled. Device management repository schema initialization is about " +
|
if (log.isDebugEnabled()) {
|
||||||
"to begin");
|
log.debug(
|
||||||
}
|
"-Dsetup is enabled. Device management repository schema initialization " +
|
||||||
this.setupDeviceManagementSchema(dsConfig);
|
"is about to begin");
|
||||||
}
|
}
|
||||||
|
this.setupDeviceManagementSchema(dsConfig);
|
||||||
|
}
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Registering OSGi service DeviceManagementService");
|
log.debug("Registering OSGi service DeviceManagementService");
|
||||||
}
|
}
|
||||||
BundleContext bundleContext = componentContext.getBundleContext();
|
BundleContext bundleContext = componentContext.getBundleContext();
|
||||||
bundleContext.registerService(DeviceManagementService.class.getName(),
|
bundleContext.registerService(DeviceManagementService.class.getName(),
|
||||||
new DeviceManagementService(), null);
|
new DeviceManagementService(), null);
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Device management core bundle has been successfully initialized");
|
log.debug("Device management core bundle has been successfully initialized");
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
String msg = "Error occurred while initializing device management core bundle";
|
String msg = "Error occurred while initializing device management core bundle";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException {
|
private void setupDeviceManagementSchema(DataSourceConfig config)
|
||||||
DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config);
|
throws DeviceManagementException {
|
||||||
log.info("Initializing device management repository database schema");
|
DeviceManagementSchemaInitializer initializer =
|
||||||
|
new DeviceManagementSchemaInitializer(config);
|
||||||
|
log.info("Initializing device management repository database schema");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
initializer.createRegistryDatabase();
|
initializer.createRegistryDatabase();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new DeviceManagementException("Error occurred while initializing Device Management " +
|
throw new DeviceManagementException(
|
||||||
"database schema", e);
|
"Error occurred while initializing Device Management " +
|
||||||
}
|
"database schema", e);
|
||||||
if (log.isDebugEnabled()) {
|
}
|
||||||
log.debug("Device management metadata repository schema has been successfully initialized");
|
if (log.isDebugEnabled()) {
|
||||||
}
|
log.debug(
|
||||||
}
|
"Device management metadata repository schema has been successfully initialized");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets Device Manager service.
|
* Sets Device Manager service.
|
||||||
* @param deviceManagerService An instance of DeviceManagerService
|
*
|
||||||
*/
|
* @param deviceManagerService An instance of DeviceManagerService
|
||||||
protected void setDeviceManagerService(DeviceManagerService deviceManagerService) {
|
*/
|
||||||
if (log.isDebugEnabled()) {
|
protected void setDeviceManagerService(DeviceManagerService deviceManagerService) {
|
||||||
log.debug("Setting Device Management Service Provider : '" +
|
if (log.isDebugEnabled()) {
|
||||||
deviceManagerService.getProviderType() + "'");
|
log.debug("Setting Device Management Service Provider : '" +
|
||||||
}
|
deviceManagerService.getProviderType() + "'");
|
||||||
this.getPluginRepository().addDeviceManagementProvider(deviceManagerService);
|
}
|
||||||
}
|
this.getPluginRepository().addDeviceManagementProvider(deviceManagerService);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsets Device Management service.
|
* Unsets Device Management service.
|
||||||
* @param deviceManagerService An Instance of DeviceManagerService
|
*
|
||||||
*/
|
* @param deviceManagerService An Instance of DeviceManagerService
|
||||||
protected void unsetDeviceManagerService(DeviceManagerService deviceManagerService) {
|
*/
|
||||||
if (log.isDebugEnabled()) {
|
protected void unsetDeviceManagerService(DeviceManagerService deviceManagerService) {
|
||||||
log.debug("Unsetting Device Management Service Provider : '" +
|
if (log.isDebugEnabled()) {
|
||||||
deviceManagerService.getProviderType() + "'");
|
log.debug("Unsetting Device Management Service Provider : '" +
|
||||||
}
|
deviceManagerService.getProviderType() + "'");
|
||||||
this.getPluginRepository().removeDeviceManagementProvider(deviceManagerService);
|
}
|
||||||
}
|
this.getPluginRepository().removeDeviceManagementProvider(deviceManagerService);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets Realm Service.
|
* Sets Realm Service.
|
||||||
* @param realmService An instance of RealmService
|
*
|
||||||
*/
|
* @param realmService An instance of RealmService
|
||||||
protected void setRealmService(RealmService realmService) {
|
*/
|
||||||
if (log.isDebugEnabled()) {
|
protected void setRealmService(RealmService realmService) {
|
||||||
log.debug("Setting Realm Service");
|
if (log.isDebugEnabled()) {
|
||||||
}
|
log.debug("Setting Realm Service");
|
||||||
DeviceManagementDataHolder.getInstance().setRealmService(realmService);
|
}
|
||||||
}
|
DeviceManagementDataHolder.getInstance().setRealmService(realmService);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsets Realm Service.
|
* Unsets Realm Service.
|
||||||
* @param realmService An instance of RealmService
|
*
|
||||||
*/
|
* @param realmService An instance of RealmService
|
||||||
protected void unsetRealmService(RealmService realmService) {
|
*/
|
||||||
if (log.isDebugEnabled()) {
|
protected void unsetRealmService(RealmService realmService) {
|
||||||
log.debug("Unsetting Realm Service");
|
if (log.isDebugEnabled()) {
|
||||||
}
|
log.debug("Unsetting Realm Service");
|
||||||
DeviceManagementDataHolder.getInstance().setRealmService(null);
|
}
|
||||||
}
|
DeviceManagementDataHolder.getInstance().setRealmService(null);
|
||||||
|
}
|
||||||
|
|
||||||
private DeviceManagementRepository getPluginRepository() {
|
private DeviceManagementRepository getPluginRepository() {
|
||||||
return pluginRepository;
|
return pluginRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,66 +28,69 @@ import java.util.List;
|
|||||||
|
|
||||||
public class DeviceManagementService implements DeviceManager {
|
public class DeviceManagementService implements DeviceManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().enrollDevice(device);
|
return DeviceManagementDataHolder.getInstance().getDeviceManager().enrollDevice(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().modifyEnrollment(device);
|
return DeviceManagementDataHolder.getInstance().getDeviceManager().modifyEnrollment(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager()
|
return DeviceManagementDataHolder.getInstance().getDeviceManager()
|
||||||
.disenrollDevice(deviceId);
|
.disenrollDevice(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().isEnrolled(deviceId);
|
return DeviceManagementDataHolder.getInstance().getDeviceManager().isEnrolled(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().isActive(deviceId);
|
return DeviceManagementDataHolder.getInstance().getDeviceManager().isActive(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().setActive(deviceId, status);
|
throws DeviceManagementException {
|
||||||
}
|
return DeviceManagementDataHolder.getInstance().getDeviceManager()
|
||||||
|
.setActive(deviceId, status);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getAllDevices(String type) throws DeviceManagementException {
|
public List<Device> getAllDevices(String type) throws DeviceManagementException {
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().getAllDevices(type);
|
return DeviceManagementDataHolder.getInstance().getDeviceManager().getAllDevices(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId)
|
public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
|
|
||||||
Device device = DeviceManagementDataHolder.getInstance().getDeviceManager().getDevice(deviceId);
|
Device device =
|
||||||
return device;
|
DeviceManagementDataHolder.getInstance().getDeviceManager().getDevice(deviceId);
|
||||||
}
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().updateDeviceInfo(device);
|
return DeviceManagementDataHolder.getInstance().getDeviceManager().updateDeviceInfo(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager()
|
return DeviceManagementDataHolder.getInstance().getDeviceManager()
|
||||||
.setOwnership(deviceId, ownershipType);
|
.setOwnership(deviceId, ownershipType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OperationManager getOperationManager(String type) throws DeviceManagementException {
|
public OperationManager getOperationManager(String type) throws DeviceManagementException {
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().
|
return DeviceManagementDataHolder.getInstance().getDeviceManager().
|
||||||
getOperationManager(type);
|
getOperationManager(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,8 +27,10 @@ import org.wso2.carbon.device.mgt.core.internal.LicenseManagementDataHolder;
|
|||||||
|
|
||||||
public class LicenseManagementService implements LicenseManager {
|
public class LicenseManagementService implements LicenseManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
|
public License getLicense(String deviceType, String languageCode)
|
||||||
return LicenseManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode);
|
throws LicenseManagementException {
|
||||||
}
|
return LicenseManagementDataHolder.getInstance().getLicenseManager()
|
||||||
|
.getLicense(deviceType, languageCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,20 +29,21 @@ import java.io.File;
|
|||||||
|
|
||||||
public final class DeviceManagementSchemaInitializer extends DatabaseCreator {
|
public final class DeviceManagementSchemaInitializer extends DatabaseCreator {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DeviceManagementSchemaInitializer.class);
|
private static final Log log = LogFactory.getLog(DeviceManagementSchemaInitializer.class);
|
||||||
private static final String setupSQLScriptBaseLocation =
|
private static final String setupSQLScriptBaseLocation =
|
||||||
CarbonUtils.getCarbonHome() + File.separator + "dbscripts" + File.separator + "cdm" + File.separator;
|
CarbonUtils.getCarbonHome() + File.separator + "dbscripts" + File.separator + "cdm" +
|
||||||
|
File.separator;
|
||||||
|
|
||||||
public DeviceManagementSchemaInitializer(DataSourceConfig config) {
|
public DeviceManagementSchemaInitializer(DataSourceConfig config) {
|
||||||
super(DeviceManagerUtil.resolveDataSource(config));
|
super(DeviceManagerUtil.resolveDataSource(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getDbScriptLocation(String databaseType) {
|
protected String getDbScriptLocation(String databaseType) {
|
||||||
String scriptName = databaseType + ".sql";
|
String scriptName = databaseType + ".sql";
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Loading database script from :" + scriptName);
|
log.debug("Loading database script from :" + scriptName);
|
||||||
}
|
}
|
||||||
return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName;
|
return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,8 +50,9 @@ public final class DeviceManagerUtil {
|
|||||||
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(
|
||||||
"to a org.w3c.dom.Document : " + e.getMessage(), e);
|
"Error occurred while parsing file, while converting " +
|
||||||
|
"to a org.w3c.dom.Document : " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,23 +66,28 @@ public final class DeviceManagerUtil {
|
|||||||
DataSource dataSource = null;
|
DataSource dataSource = null;
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Device Management Repository data source configuration " + "is null and thus, is not initialized");
|
"Device Management Repository data source configuration " +
|
||||||
|
"is null and thus, is not initialized");
|
||||||
}
|
}
|
||||||
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
|
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
|
||||||
if (jndiConfig != null) {
|
if (jndiConfig != null) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug(
|
log.debug(
|
||||||
"Initializing Device Management Repository data source using the JNDI " + "Lookup Definition");
|
"Initializing Device Management Repository data source using the JNDI " +
|
||||||
|
"Lookup Definition");
|
||||||
}
|
}
|
||||||
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = jndiConfig.getJndiProperties();
|
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
|
||||||
|
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 = DeviceManagementDAOUtil
|
||||||
|
.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
||||||
} else {
|
} else {
|
||||||
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
dataSource =
|
||||||
|
DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dataSource;
|
return dataSource;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user