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) { } catch (MobileDeviceManagementDAOException e1) {
log.warn("Error occurred while roll-backing the transaction", e); log.warn("Error occurred while roll-backing the transaction", e);
} }
throw new DeviceManagementException("Error occurred while retrieving the list of features registered " + throw new DeviceManagementException("Error occurred while retrieving the list of " +
"for Android platform", e); "features registered for Android platform", e);
} }
} }
@ -119,4 +119,4 @@ public class AndroidFeatureManager implements FeatureManager {
return status; return status;
} }
} }

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

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

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

Loading…
Cancel
Save