mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
CDMF-8 fixes
This commit is contained in:
parent
98ac04479d
commit
1736d5db3e
@ -41,7 +41,8 @@ public interface DeviceManager {
|
|||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -49,7 +50,8 @@ public interface DeviceManager {
|
|||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
|||||||
@ -44,7 +44,8 @@ public class DeviceManagerImpl implements DeviceManager {
|
|||||||
private DeviceManagementConfig config;
|
private DeviceManagementConfig config;
|
||||||
private DeviceManagementRepository pluginRepository;
|
private DeviceManagementRepository pluginRepository;
|
||||||
|
|
||||||
public DeviceManagerImpl(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) {
|
public DeviceManagerImpl(DeviceManagementConfig config,
|
||||||
|
DeviceManagementRepository pluginRepository) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.pluginRepository = pluginRepository;
|
this.pluginRepository = pluginRepository;
|
||||||
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||||
@ -53,16 +54,20 @@ public class DeviceManagerImpl implements DeviceManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||||
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
DeviceManagerService dms =
|
||||||
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||||
boolean status = dms.enrollDevice(device);
|
boolean status = dms.enrollDevice(device);
|
||||||
try {
|
try {
|
||||||
org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device);
|
org.wso2.carbon.device.mgt.core.dto.Device deviceDto =
|
||||||
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
DeviceManagementDAOUtil.convertDevice(device);
|
||||||
|
Integer deviceTypeId =
|
||||||
|
this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
||||||
deviceDto.setStatus(Status.ACTIVE);
|
deviceDto.setStatus(Status.ACTIVE);
|
||||||
deviceDto.setDeviceTypeId(deviceTypeId);
|
deviceDto.setDeviceTypeId(deviceTypeId);
|
||||||
this.getDeviceDAO().addDevice(deviceDto);
|
this.getDeviceDAO().addDevice(deviceDto);
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'",
|
throw new DeviceManagementException(
|
||||||
|
"Error occurred while enrolling the device '" + device.getId() + "'",
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
@ -70,12 +75,14 @@ public class DeviceManagerImpl implements DeviceManager {
|
|||||||
|
|
||||||
@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 =
|
||||||
|
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 '" + device.getId() + "'",
|
throw new DeviceManagementException(
|
||||||
|
"Error occurred while modifying the device '" + device.getId() + "'",
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
@ -83,25 +90,30 @@ public class DeviceManagerImpl implements DeviceManager {
|
|||||||
|
|
||||||
@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 =
|
||||||
|
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 = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
DeviceManagerService dms =
|
||||||
|
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 = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
DeviceManagerService dms =
|
||||||
|
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 = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
throws DeviceManagementException {
|
||||||
|
DeviceManagerService dms =
|
||||||
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
return dms.setActive(deviceId, status);
|
return dms.setActive(deviceId, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,12 +123,14 @@ public class DeviceManagerImpl implements DeviceManager {
|
|||||||
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 =
|
||||||
|
DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType);
|
||||||
Device dmsDevice = dms.getDevice(deviceIdentifier);
|
Device dmsDevice = dms.getDevice(deviceIdentifier);
|
||||||
if (dmsDevice != null) {
|
if (dmsDevice != null) {
|
||||||
convertedDevice.setProperties(dmsDevice.getProperties());
|
convertedDevice.setProperties(dmsDevice.getProperties());
|
||||||
@ -125,17 +139,20 @@ public class DeviceManagerImpl implements DeviceManager {
|
|||||||
devicesList.add(convertedDevice);
|
devicesList.add(convertedDevice);
|
||||||
}
|
}
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + "'", e);
|
throw new DeviceManagementException(
|
||||||
|
"Error occurred while obtaining the device for type '" + type + "'", e);
|
||||||
}
|
}
|
||||||
return devicesList;
|
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 =
|
||||||
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
Device convertedDevice = null;
|
Device convertedDevice = null;
|
||||||
try {
|
try {
|
||||||
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType());
|
Integer deviceTypeId =
|
||||||
|
this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType());
|
||||||
org.wso2.carbon.device.mgt.core.dto.Device device =
|
org.wso2.carbon.device.mgt.core.dto.Device device =
|
||||||
this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId());
|
this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId());
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
@ -149,21 +166,24 @@ public class DeviceManagerImpl implements DeviceManager {
|
|||||||
}
|
}
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
throw new DeviceManagementException(
|
throw new DeviceManagementException(
|
||||||
"Error occurred while obtaining the device for id '" + deviceId.getId() + "'", e);
|
"Error occurred while obtaining the device for id '" + deviceId.getId() + "'",
|
||||||
|
e);
|
||||||
}
|
}
|
||||||
return convertedDevice;
|
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 =
|
||||||
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||||
return dms.updateDeviceInfo(device);
|
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 =
|
||||||
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
return dms.setOwnership(deviceId, ownershipType);
|
return dms.setOwnership(deviceId, ownershipType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,14 +30,15 @@ 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 =
|
||||||
|
CarbonUtils.getCarbonConfigDirPath() + File.separator +
|
||||||
DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME;
|
DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME;
|
||||||
|
|
||||||
public static DeviceConfigurationManager getInstance() {
|
public static DeviceConfigurationManager getInstance() {
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -35,7 +35,8 @@ 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 =
|
||||||
|
CarbonUtils.getCarbonConfigDirPath() + File.separator +
|
||||||
DeviceManagementConstants.Common.DEFAULT_LICENSE_CONFIG_XML_NAME;
|
DeviceManagementConstants.Common.DEFAULT_LICENSE_CONFIG_XML_NAME;
|
||||||
|
|
||||||
public static LicenseConfigurationManager getInstance() {
|
public static LicenseConfigurationManager getInstance() {
|
||||||
@ -69,5 +70,4 @@ public class LicenseConfigurationManager {
|
|||||||
return licenseMgtConfig;
|
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,6 +25,7 @@ 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;
|
||||||
@ -59,7 +60,8 @@ public class DeviceManagementDAOFactory {
|
|||||||
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(
|
||||||
|
"Device Management Repository data source configuration " + "is null and " +
|
||||||
"thus, is not initialized");
|
"thus, is not initialized");
|
||||||
}
|
}
|
||||||
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
|
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
|
||||||
@ -68,15 +70,18 @@ public class DeviceManagementDAOFactory {
|
|||||||
log.debug("Initializing Device Management Repository data source using the JNDI " +
|
log.debug("Initializing Device Management Repository data source using the JNDI " +
|
||||||
"Lookup Definition");
|
"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;
|
||||||
|
|||||||
@ -22,7 +22,8 @@ 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 {
|
||||||
|
|
||||||
|
|||||||
@ -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,7 +191,8 @@ 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(
|
||||||
|
"Error occurred while obtaining a connection from the device " +
|
||||||
"management metadata repository datasource", e);
|
"management metadata repository datasource", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,13 +87,15 @@ public final class DeviceManagementDAOUtil {
|
|||||||
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 =
|
||||||
|
"Error occurred while retrieving id from the domain of tenant " + tenantDomain;
|
||||||
throw new DeviceManagementDAOException(msg);
|
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,
|
||||||
|
final Hashtable<Object, Object> jndiProperties) {
|
||||||
try {
|
try {
|
||||||
if (jndiProperties == null || jndiProperties.isEmpty()) {
|
if (jndiProperties == null || jndiProperties.isEmpty()) {
|
||||||
return (DataSource) InitialContext.doLookup(dataSourceName);
|
return (DataSource) InitialContext.doLookup(dataSourceName);
|
||||||
@ -110,7 +112,8 @@ public final class DeviceManagementDAOUtil {
|
|||||||
* @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,
|
||||||
|
DeviceType deviceType) {
|
||||||
org.wso2.carbon.device.mgt.common.Device deviceBO =
|
org.wso2.carbon.device.mgt.common.Device deviceBO =
|
||||||
new org.wso2.carbon.device.mgt.common.Device();
|
new org.wso2.carbon.device.mgt.common.Device();
|
||||||
deviceBO.setDateOfEnrolment(device.getDateOfEnrollment());
|
deviceBO.setDateOfEnrolment(device.getDateOfEnrollment());
|
||||||
|
|||||||
@ -62,7 +62,8 @@ public class DeviceManagementServiceComponent {
|
|||||||
}
|
}
|
||||||
/* 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);
|
||||||
@ -71,11 +72,13 @@ public class DeviceManagementServiceComponent {
|
|||||||
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 =
|
||||||
|
System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);
|
||||||
if (setupOption != null) {
|
if (setupOption != null) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("-Dsetup is enabled. Device management repository schema initialization is about " +
|
log.debug(
|
||||||
"to begin");
|
"-Dsetup is enabled. Device management repository schema initialization " +
|
||||||
|
"is about to begin");
|
||||||
}
|
}
|
||||||
this.setupDeviceManagementSchema(dsConfig);
|
this.setupDeviceManagementSchema(dsConfig);
|
||||||
}
|
}
|
||||||
@ -95,23 +98,28 @@ public class DeviceManagementServiceComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException {
|
private void setupDeviceManagementSchema(DataSourceConfig config)
|
||||||
DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config);
|
throws DeviceManagementException {
|
||||||
|
DeviceManagementSchemaInitializer initializer =
|
||||||
|
new DeviceManagementSchemaInitializer(config);
|
||||||
log.info("Initializing device management repository database schema");
|
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(
|
||||||
|
"Error occurred while initializing Device Management " +
|
||||||
"database schema", e);
|
"database schema", e);
|
||||||
}
|
}
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Device management metadata repository schema has been successfully initialized");
|
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) {
|
protected void setDeviceManagerService(DeviceManagerService deviceManagerService) {
|
||||||
@ -124,6 +132,7 @@ public class DeviceManagementServiceComponent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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) {
|
protected void unsetDeviceManagerService(DeviceManagerService deviceManagerService) {
|
||||||
@ -136,6 +145,7 @@ public class DeviceManagementServiceComponent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets Realm Service.
|
* Sets Realm Service.
|
||||||
|
*
|
||||||
* @param realmService An instance of RealmService
|
* @param realmService An instance of RealmService
|
||||||
*/
|
*/
|
||||||
protected void setRealmService(RealmService realmService) {
|
protected void setRealmService(RealmService realmService) {
|
||||||
@ -147,6 +157,7 @@ public class DeviceManagementServiceComponent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsets Realm Service.
|
* Unsets Realm Service.
|
||||||
|
*
|
||||||
* @param realmService An instance of RealmService
|
* @param realmService An instance of RealmService
|
||||||
*/
|
*/
|
||||||
protected void unsetRealmService(RealmService realmService) {
|
protected void unsetRealmService(RealmService realmService) {
|
||||||
|
|||||||
@ -55,8 +55,10 @@ public class DeviceManagementService implements DeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@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
|
||||||
@ -68,7 +70,8 @@ public class DeviceManagementService implements DeviceManager {
|
|||||||
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 =
|
||||||
|
DeviceManagementDataHolder.getInstance().getDeviceManager().getDevice(deviceId);
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,9 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,8 @@ 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));
|
||||||
|
|||||||
@ -50,7 +50,8 @@ 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(
|
||||||
|
"Error occurred while parsing file, while converting " +
|
||||||
"to a org.w3c.dom.Document : " + e.getMessage(), e);
|
"to a org.w3c.dom.Document : " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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