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