Refactored Android plugin code

revert-dabc3590
harshanL 10 years ago
parent 7c2a25a1c9
commit 4455f284f8

@ -95,8 +95,8 @@ public class AndroidFeatureManager implements FeatureManager {
} catch (MobileDeviceManagementDAOException e1) {
log.warn("Error occurred while roll-backing the transaction", e);
}
throw new DeviceManagementException("Error occurred while retrieving the list of features registered " +
"for Android platform", e);
throw new DeviceManagementException("Error occurred while retrieving the list of " +
"features registered for Android platform", e);
}
}

@ -58,16 +58,17 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
try {
conn = this.getConnection();
String selectDBQuery =
"SELECT ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, VENDOR, MAC_ADDRESS, " +
"DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION FROM AD_DEVICE WHERE" +
" ANDROID_DEVICE_ID = ?";
"SELECT ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " +
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION" +
" FROM AD_DEVICE WHERE ANDROID_DEVICE_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, mblDeviceId);
ResultSet resultSet = stmt.executeQuery();
if (resultSet.next()) {
mobileDevice = new MobileDevice();
mobileDevice.setMobileDeviceId(resultSet.getString(AndroidPluginConstants.ANDROID_DEVICE_ID));
mobileDevice.setMobileDeviceId(resultSet.getString(AndroidPluginConstants.
ANDROID_DEVICE_ID));
mobileDevice.setModel(resultSet.getString(AndroidPluginConstants.DEVICE_MODEL));
mobileDevice.setSerial(resultSet.getString(AndroidPluginConstants.SERIAL));
mobileDevice.setVendor(resultSet.getString(AndroidPluginConstants.VENDOR));
@ -88,7 +89,8 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
mobileDevice.setDeviceProperties(propertyMap);
if (log.isDebugEnabled()) {
log.debug("Android device " + mblDeviceId + " data has been fetched from Android database.");
log.debug("Android device " + mblDeviceId + " data has been fetched from " +
"Android database.");
}
}
} catch (SQLException e) {
@ -112,8 +114,8 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
conn = this.getConnection();
String createDBQuery =
"INSERT INTO AD_DEVICE(ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, SERIAL, " +
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION, DEVICE_MODEL)" +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, " +
"OS_VERSION, DEVICE_MODEL) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(createDBQuery);
stmt.setString(1, mobileDevice.getMobileDeviceId());
@ -142,8 +144,8 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
if (rows > 0) {
status = true;
if (log.isDebugEnabled()) {
log.debug("Android device " + mobileDevice.getMobileDeviceId() + " data has been added" +
" to the Android database.");
log.debug("Android device " + mobileDevice.getMobileDeviceId() + " data has been" +
" added to the Android database.");
}
}
} catch (SQLException e) {
@ -166,9 +168,9 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
try {
conn = this.getConnection();
String updateDBQuery =
"UPDATE AD_DEVICE SET GCM_TOKEN = ?, DEVICE_INFO = ?, SERIAL = ?, VENDOR = ?, MAC_ADDRESS = ?, " +
"DEVICE_NAME = ?, LATITUDE = ?, LONGITUDE = ?, IMEI = ?, IMSI = ?, OS_VERSION = ?, DEVICE_MODEL = ? " +
"WHERE ANDROID_DEVICE_ID = ?";
"UPDATE AD_DEVICE SET GCM_TOKEN = ?, DEVICE_INFO = ?, SERIAL = ?, VENDOR = ?, " +
"MAC_ADDRESS = ?, DEVICE_NAME = ?, LATITUDE = ?, LONGITUDE = ?, IMEI = ?, " +
"IMSI = ?, OS_VERSION = ?, DEVICE_MODEL = ? WHERE ANDROID_DEVICE_ID = ?";
stmt = conn.prepareStatement(updateDBQuery);
@ -252,13 +254,15 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
try {
conn = this.getConnection();
String selectDBQuery =
"SELECT ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, VENDOR, " +
"MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, 0S_VERSION FROM AD_DEVICE";
"SELECT ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " +
"VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION " +
"FROM AD_DEVICE";
stmt = conn.prepareStatement(selectDBQuery);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
mobileDevice = new MobileDevice();
mobileDevice.setMobileDeviceId(resultSet.getString(AndroidPluginConstants.ANDROID_DEVICE_ID));
mobileDevice.setMobileDeviceId(resultSet.getString(AndroidPluginConstants.
ANDROID_DEVICE_ID));
mobileDevice.setModel(resultSet.getString(AndroidPluginConstants.DEVICE_MODEL));
mobileDevice.setSerial(resultSet.getString(AndroidPluginConstants.SERIAL));
mobileDevice.setVendor(resultSet.getString(AndroidPluginConstants.VENDOR));

@ -46,7 +46,8 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
public boolean addFeature(MobileFeature mobileFeature) throws
MobileDeviceManagementDAOException {
PreparedStatement stmt = null;
boolean status = false;
try {
@ -70,7 +71,8 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
public boolean updateFeature(MobileFeature mobileFeature) throws
MobileDeviceManagementDAOException {
boolean status = false;
Connection conn = null;
PreparedStatement stmt = null;
@ -89,7 +91,8 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
if (rows > 0) {
status = true;
if (log.isDebugEnabled()) {
log.debug("Android Feature " + mobileFeature.getCode() + " data has been modified.");
log.debug("Android Feature " + mobileFeature.getCode() + " data has been " +
"modified.");
}
}
} catch (SQLException e) {
@ -125,7 +128,8 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException {
public boolean deleteFeatureByCode(String mblFeatureCode) throws
MobileDeviceManagementDAOException {
PreparedStatement stmt = null;
boolean status = false;
try {
@ -146,7 +150,8 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
public MobileFeature getFeatureById(int mblFeatureId) throws
MobileDeviceManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@ -162,7 +167,8 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
mobileFeature.setId(rs.getInt(AndroidPluginConstants.ANDROID_FEATURE_ID));
mobileFeature.setCode(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_CODE));
mobileFeature.setName(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_NAME));
mobileFeature.setDescription(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_DESCRIPTION));
mobileFeature.setDescription(rs.getString(AndroidPluginConstants.
ANDROID_FEATURE_DESCRIPTION));
mobileFeature.setDeviceType(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
}
@ -177,7 +183,8 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
}
@Override
public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException {
public MobileFeature getFeatureByCode(String mblFeatureCode) throws
MobileDeviceManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@ -193,7 +200,8 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
mobileFeature.setId(rs.getInt(AndroidPluginConstants.ANDROID_FEATURE_ID));
mobileFeature.setCode(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_CODE));
mobileFeature.setName(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_NAME));
mobileFeature.setDescription(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_DESCRIPTION));
mobileFeature.setDescription(rs.getString(AndroidPluginConstants.
ANDROID_FEATURE_DESCRIPTION));
mobileFeature.setDeviceType(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
}
@ -231,15 +239,16 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
mobileFeature.setId(rs.getInt(AndroidPluginConstants.ANDROID_FEATURE_ID));
mobileFeature.setCode(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_CODE));
mobileFeature.setName(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_NAME));
mobileFeature.setDescription(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_DESCRIPTION));
mobileFeature.setDescription(rs.getString(AndroidPluginConstants.
ANDROID_FEATURE_DESCRIPTION));
mobileFeature.setDeviceType(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
features.add(mobileFeature);
}
return features;
} catch (SQLException e) {
throw new AndroidFeatureManagementDAOException("Error occurred while retrieving all android " +
"features from the android database.", e);
throw new AndroidFeatureManagementDAOException("Error occurred while retrieving all " +
"android features from the android database.", e);
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
}

@ -78,9 +78,11 @@ public class MobileDeviceManagementServiceComponent {
Map<String, MobileDataSourceConfig> dsConfigMap =
config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap();
MobileDeviceManagementDAOFactory.setMobileDataSourceConfigMap(dsConfigMap);
IOSDAOFactory.init(dsConfigMap.get(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS));
IOSDAOFactory.init(dsConfigMap.get(DeviceManagementConstants.MobileDeviceTypes.
MOBILE_DEVICE_TYPE_IOS));
AndroidDAOFactory
.init(dsConfigMap.get(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID));
.init(dsConfigMap.get(DeviceManagementConstants.MobileDeviceTypes.
MOBILE_DEVICE_TYPE_ANDROID));
String setupOption = System.getProperty("setup");
if (setupOption != null) {
@ -90,7 +92,8 @@ public class MobileDeviceManagementServiceComponent {
"to begin");
}
try {
Map<String, DataSource> dataSourceMap = MobileDeviceManagementDAOFactory.getDataSourceMap();
Map<String, DataSource> dataSourceMap = MobileDeviceManagementDAOFactory.
getDataSourceMap();
for (DataSource dataSource : dataSourceMap.values()) {
MobileDeviceManagementDAOUtil
.setupMobileDeviceManagementSchema(dataSource);

Loading…
Cancel
Save