mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge pull request #2 from dulichan/master
Implements the getDevice method of DeviceManager
This commit is contained in:
commit
0ffa15f463
@ -35,136 +35,140 @@ import java.util.List;
|
|||||||
|
|
||||||
public class DeviceManagerImpl implements DeviceManager {
|
public class DeviceManagerImpl implements DeviceManager {
|
||||||
|
|
||||||
private DeviceDAO deviceDAO;
|
private DeviceDAO deviceDAO;
|
||||||
private DeviceTypeDAO deviceTypeDAO;
|
private DeviceTypeDAO deviceTypeDAO;
|
||||||
private DeviceManagementConfig config;
|
private DeviceManagementConfig config;
|
||||||
private DeviceManagementRepository pluginRepository;
|
private DeviceManagementRepository pluginRepository;
|
||||||
|
|
||||||
public DeviceManagerImpl(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) {
|
public DeviceManagerImpl(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.pluginRepository = pluginRepository;
|
this.pluginRepository = pluginRepository;
|
||||||
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||||
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
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 = 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 = DeviceManagementDAOUtil.convertDevice(device);
|
||||||
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
||||||
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() + "'", e);
|
throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'",
|
||||||
}
|
e);
|
||||||
return status;
|
}
|
||||||
}
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
DeviceManagerService dms = 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;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@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 {
|
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 =
|
List<Device> devicesList = new ArrayList<Device>();
|
||||||
this.getPluginRepository().getDeviceManagementProvider(type);
|
try {
|
||||||
List<Device> devicesList = new ArrayList<Device>();
|
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type);
|
||||||
try {
|
List<org.wso2.carbon.device.mgt.core.dto.Device> devices = this.getDeviceDAO().getDevices(deviceTypeId);
|
||||||
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type);
|
|
||||||
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 =
|
DeviceIdentifier deviceIdentifier = DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType);
|
||||||
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());
|
convertedDevice.setFeatures(dmsDevice.getFeatures());
|
||||||
convertedDevice.setFeatures(dmsDevice.getFeatures());
|
}
|
||||||
}
|
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;
|
||||||
return dms.getDevice(deviceId);
|
try {
|
||||||
}
|
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType());
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.Device device =
|
||||||
|
this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId());
|
||||||
|
if (device != null) {
|
||||||
|
convertedDevice = DeviceManagementDAOUtil
|
||||||
|
.convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId));
|
||||||
|
Device dmsDevice = dms.getDevice(deviceId);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,22 +28,30 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface DeviceDAO {
|
public interface DeviceDAO {
|
||||||
|
|
||||||
void addDevice(Device device) throws DeviceManagementDAOException;
|
void addDevice(Device device) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
void updateDevice(Device device) throws DeviceManagementDAOException;
|
void updateDevice(Device device) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
void updateDeviceStatus(Long deviceId, Status status) throws DeviceManagementDAOException;
|
void updateDeviceStatus(Long deviceId, Status status) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
void deleteDevice(Long deviceId) throws DeviceManagementDAOException;
|
void deleteDevice(Long deviceId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException;
|
Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
List<Device> getDevices() throws DeviceManagementDAOException;
|
/**
|
||||||
|
* @param type - Device type.
|
||||||
|
* @param identifier - Device identifier.
|
||||||
|
* @return
|
||||||
|
* @throws DeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
Device getDeviceByDeviceIdentifier(Integer type, String identifier) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
List<Device> getDevices() throws DeviceManagementDAOException;
|
||||||
* @param type - The device type id.
|
|
||||||
* @return a list of devices based on the type id.
|
/**
|
||||||
* @throws DeviceManagementDAOException
|
* @param type - The device type id.
|
||||||
*/
|
* @return a list of devices based on the type id.
|
||||||
List<Device> getDevices(Integer type) throws DeviceManagementDAOException;
|
* @throws DeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
List<Device> getDevices(Integer type) throws DeviceManagementDAOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,8 +21,8 @@ package org.wso2.carbon.device.mgt.core.dao.impl;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.Status;
|
import org.wso2.carbon.device.mgt.core.dto.Status;
|
||||||
|
|
||||||
@ -37,120 +37,153 @@ import java.util.List;
|
|||||||
|
|
||||||
public class DeviceDAOImpl implements DeviceDAO {
|
public class DeviceDAOImpl implements DeviceDAO {
|
||||||
|
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
private static final Log log = LogFactory.getLog(DeviceDAOImpl.class);
|
private static final Log log = LogFactory.getLog(DeviceDAOImpl.class);
|
||||||
|
|
||||||
|
public DeviceDAOImpl(DataSource dataSource) {
|
||||||
|
this.dataSource = dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
public DeviceDAOImpl(DataSource dataSource) {
|
@Override public void addDevice(Device device) throws DeviceManagementDAOException {
|
||||||
this.dataSource = dataSource;
|
Connection conn = null;
|
||||||
}
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String createDBQuery =
|
||||||
|
"INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DATE_OF_ENROLLMENT, DATE_OF_LAST_UPDATE, OWNERSHIP," +
|
||||||
|
"STATUS, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, OWNER, TENANT_ID) VALUES " +
|
||||||
|
"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
|
||||||
@Override
|
stmt = conn.prepareStatement(createDBQuery);
|
||||||
public void addDevice(Device device) throws DeviceManagementDAOException {
|
stmt.setString(1, device.getDescription());
|
||||||
Connection conn = null;
|
stmt.setString(2, device.getName());
|
||||||
PreparedStatement stmt = null;
|
stmt.setLong(3, new Date().getTime());
|
||||||
try {
|
stmt.setLong(4, new Date().getTime());
|
||||||
conn = this.getConnection();
|
stmt.setString(5, device.getOwnerShip());
|
||||||
String createDBQuery =
|
stmt.setString(6, device.getStatus().toString());
|
||||||
"INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DATE_OF_ENROLLMENT, DATE_OF_LAST_UPDATE, OWNERSHIP," +
|
stmt.setInt(7, device.getDeviceTypeId());
|
||||||
"STATUS, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, OWNER, TENANT_ID) VALUES " +
|
stmt.setString(8, device.getDeviceIdentificationId());
|
||||||
"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
stmt.setString(9, device.getOwnerId());
|
||||||
|
stmt.setInt(10, device.getTenantId());
|
||||||
|
stmt.executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while enrolling device '" + device.getName() + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stmt = conn.prepareStatement(createDBQuery);
|
@Override public void updateDevice(Device device) throws DeviceManagementDAOException {
|
||||||
stmt.setString(1, device.getDescription());
|
|
||||||
stmt.setString(2, device.getName());
|
|
||||||
stmt.setLong(3, new Date().getTime());
|
|
||||||
stmt.setLong(4, new Date().getTime());
|
|
||||||
stmt.setString(5, device.getOwnerShip());
|
|
||||||
stmt.setString(6, device.getStatus().toString());
|
|
||||||
stmt.setInt(7, device.getDeviceTypeId());
|
|
||||||
stmt.setString(8, device.getDeviceIdentificationId());
|
|
||||||
stmt.setString(9, device.getOwnerId());
|
|
||||||
stmt.setInt(10, device.getTenantId());
|
|
||||||
stmt.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while enrolling device '" + device.getName() + "'";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementDAOException(msg, e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Device getDeviceByDeviceIdentifier(Integer type, String identifier)
|
||||||
public Device getDeviceByDeviceId(Long deviceId)
|
throws DeviceManagementDAOException {
|
||||||
throws DeviceManagementDAOException {
|
Connection conn = null;
|
||||||
return null;
|
PreparedStatement stmt = null;
|
||||||
}
|
ResultSet resultSet = null;
|
||||||
|
Device device = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, " +
|
||||||
|
"DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, " +
|
||||||
|
"DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE " +
|
||||||
|
"WHERE DM_DEVICE.DEVICE_TYPE_ID=? AND DM_DEVICE.DEVICE_IDENTIFICATION=?";
|
||||||
|
stmt = conn.prepareStatement(selectDBQueryForType);
|
||||||
|
stmt.setInt(1, type);
|
||||||
|
stmt.setString(2, identifier);
|
||||||
|
resultSet = stmt.executeQuery();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
device = new Device();
|
||||||
|
device.setId(resultSet.getInt(1));
|
||||||
|
device.setDescription(resultSet.getString(2));
|
||||||
|
device.setName(resultSet.getString(3));
|
||||||
|
device.setDateOfEnrollment(resultSet.getLong(4));
|
||||||
|
device.setDateOfLastUpdate(resultSet.getLong(5));
|
||||||
|
//TODO:- Ownership is not a enum in DeviceDAO
|
||||||
|
device.setOwnerShip(resultSet.getString(6));
|
||||||
|
device.setStatus(Status.valueOf(resultSet.getString(7)));
|
||||||
|
device.setDeviceTypeId(resultSet.getInt(8));
|
||||||
|
device.setDeviceIdentificationId(resultSet.getString(9));
|
||||||
|
device.setOwnerId(resultSet.getString(10));
|
||||||
|
device.setTenantId(resultSet.getInt(11));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while listing devices for type '" + type + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, resultSet);
|
||||||
|
}
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<Device> getDevices() throws DeviceManagementDAOException {
|
||||||
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;
|
||||||
List<Device> devicesList = null;
|
List<Device> devicesList = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
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=?";
|
"WHERE DM_DEVICE.DEVICE_TYPE_ID=?";
|
||||||
stmt = conn.prepareStatement(selectDBQueryForType);
|
stmt = conn.prepareStatement(selectDBQueryForType);
|
||||||
stmt.setInt(1, type);
|
stmt.setInt(1, type);
|
||||||
resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
devicesList = new ArrayList<Device>();
|
devicesList = new ArrayList<Device>();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
Device device = new Device();
|
Device device = new Device();
|
||||||
device.setId(resultSet.getInt(1));
|
device.setId(resultSet.getInt(1));
|
||||||
device.setDescription(resultSet.getString(2));
|
device.setDescription(resultSet.getString(2));
|
||||||
device.setName(resultSet.getString(3));
|
device.setName(resultSet.getString(3));
|
||||||
device.setDateOfEnrollment(resultSet.getLong(4));
|
device.setDateOfEnrollment(resultSet.getLong(4));
|
||||||
device.setDateOfLastUpdate(resultSet.getLong(5));
|
device.setDateOfLastUpdate(resultSet.getLong(5));
|
||||||
//TODO:- Ownership is not a enum in DeviceDAO
|
//TODO:- Ownership is not a enum in DeviceDAO
|
||||||
device.setOwnerShip(resultSet.getString(6));
|
device.setOwnerShip(resultSet.getString(6));
|
||||||
device.setStatus(Status.valueOf(resultSet.getString(7)));
|
device.setStatus(Status.valueOf(resultSet.getString(7)));
|
||||||
device.setDeviceTypeId(resultSet.getInt(8));
|
device.setDeviceTypeId(resultSet.getInt(8));
|
||||||
device.setDeviceIdentificationId(resultSet.getString(9));
|
device.setDeviceIdentificationId(resultSet.getString(9));
|
||||||
device.setOwnerId(resultSet.getString(10));
|
device.setOwnerId(resultSet.getString(10));
|
||||||
device.setTenantId(resultSet.getInt(11));
|
device.setTenantId(resultSet.getInt(11));
|
||||||
devicesList.add(device);
|
devicesList.add(device);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while listing devices for type '" + type + "'";
|
String msg = "Error occurred while listing devices for type '" + type + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementDAOException(msg, e);
|
throw new DeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, resultSet);
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, resultSet);
|
||||||
}
|
}
|
||||||
return devicesList;
|
return devicesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection getConnection() throws DeviceManagementDAOException {
|
private Connection getConnection() throws DeviceManagementDAOException {
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -223,13 +223,15 @@
|
|||||||
<outputDirectory>${project.artifactId}-${project.version}/repository/resources
|
<outputDirectory>${project.artifactId}-${project.version}/repository/resources
|
||||||
</outputDirectory>
|
</outputDirectory>
|
||||||
</fileSet>
|
</fileSet>
|
||||||
<!-- copy cdm jaggery app -->
|
<!-- copy cdm jaggery app
|
||||||
<fileSet>
|
Commented the section since the repo was moved to MDM
|
||||||
<directory>src/repository/jaggeryapps</directory>
|
-->
|
||||||
<outputDirectory>wso2cdm-${project.version}/repository/deployment/server/jaggeryapps
|
<!--<fileSet>-->
|
||||||
</outputDirectory>
|
<!--<directory>src/repository/jaggeryapps</directory>-->
|
||||||
<fileMode>755</fileMode>
|
<!--<outputDirectory>wso2cdm-${project.version}/repository/deployment/server/jaggeryapps-->
|
||||||
</fileSet>
|
<!--</outputDirectory>-->
|
||||||
|
<!--<fileMode>755</fileMode>-->
|
||||||
|
<!--</fileSet>-->
|
||||||
</fileSets>
|
</fileSets>
|
||||||
|
|
||||||
<dependencySets>
|
<dependencySets>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user