Merge pull request #6 from milanperera/master

Refactored to support device info function
revert-dabc3590
Dilshan Edirisuriya 10 years ago
commit 749a1f6299

@ -192,9 +192,20 @@ public class AndroidDeviceManager implements DeviceMgtService {
} }
@Override @Override
public boolean updateDeviceInfo(Device device) throws DeviceManagementException { public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
boolean status; boolean status;
Device deviceDB = this.getDevice(deviceIdentifier);
// This object holds the current persisted device object
MobileDevice mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB);
// This object holds the newly received device object from response
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
// Updating current object features using newer ones
mobileDeviceDB.setLatitude(mobileDevice.getLatitude());
mobileDeviceDB.setLongitude(mobileDevice.getLongitude());
mobileDeviceDB.setDeviceProperties(mobileDevice.getDeviceProperties());
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( log.debug(
@ -202,7 +213,7 @@ public class AndroidDeviceManager implements DeviceMgtService {
} }
AndroidDAOFactory.beginTransaction(); AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.updateMobileDevice(mobileDevice); .updateMobileDevice(mobileDeviceDB);
AndroidDAOFactory.commitTransaction(); AndroidDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
try { try {

@ -21,7 +21,6 @@ package org.wso2.carbon.device.mgt.mobile.impl.android.dao;
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.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
import org.wso2.carbon.device.mgt.mobile.dao.*; import org.wso2.carbon.device.mgt.mobile.dao.*;
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.AndroidDeviceDAOImpl; import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.AndroidDeviceDAOImpl;
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.AndroidFeatureDAOImpl; import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.AndroidFeatureDAOImpl;

@ -123,8 +123,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
mobileDevice.setDeviceProperties(new HashMap<String, String>()); mobileDevice.setDeviceProperties(new HashMap<String, String>());
} }
stmt.setString(2, AndroidUtils.getDeviceProperty( stmt.setString(2, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(),
mobileDevice.getDeviceProperties(),
AndroidPluginConstants.GCM_TOKEN)); AndroidPluginConstants.GCM_TOKEN));
stmt.setString(3, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), stmt.setString(3, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(),
AndroidPluginConstants.DEVICE_INFO)); AndroidPluginConstants.DEVICE_INFO));
@ -135,7 +134,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
AndroidPluginConstants.DEVICE_NAME)); AndroidPluginConstants.DEVICE_NAME));
stmt.setString(8, mobileDevice.getLongitude()); stmt.setString(8, mobileDevice.getLongitude());
stmt.setString(9, mobileDevice.getLongitude()); stmt.setString(9, mobileDevice.getLongitude());
stmt.setString(10, mobileDevice.getImsi()); stmt.setString(10, mobileDevice.getImei());
stmt.setString(11, mobileDevice.getImsi()); stmt.setString(11, mobileDevice.getImsi());
stmt.setString(12, mobileDevice.getOsVersion()); stmt.setString(12, mobileDevice.getOsVersion());
stmt.setString(13, mobileDevice.getModel()); stmt.setString(13, mobileDevice.getModel());

@ -33,7 +33,7 @@ public class AndroidPluginConstants {
public static final String LATITUDE = "LATITUDE"; public static final String LATITUDE = "LATITUDE";
public static final String LONGITUDE = "LONGITUDE"; public static final String LONGITUDE = "LONGITUDE";
public static final String IMEI = "IMEI"; public static final String IMEI = "IMEI";
public static final String IMSI = "IMEI"; public static final String IMSI = "IMSI";
public static final String VENDOR = "VENDOR"; public static final String VENDOR = "VENDOR";
public static final String OS_VERSION = "OS_VERSION"; public static final String OS_VERSION = "OS_VERSION";
public static final String MAC_ADDRESS = "MAC_ADDRESS"; public static final String MAC_ADDRESS = "MAC_ADDRESS";

@ -28,7 +28,6 @@ public class AndroidUtils {
public static String getDeviceProperty(Map<String, String> deviceProperties, String property) { public static String getDeviceProperty(Map<String, String> deviceProperties, String property) {
String deviceProperty = deviceProperties.get(property); String deviceProperty = deviceProperties.get(property);
if (deviceProperty == null) { if (deviceProperty == null) {
return ""; return "";
} }

@ -97,7 +97,7 @@ public class WindowsDeviceManager implements DeviceMgtService {
} }
@Override @Override
public boolean updateDeviceInfo(Device device) throws DeviceManagementException { public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
return true; return true;
} }

@ -38,14 +38,14 @@ import java.util.*;
public class MobileDeviceManagementUtil { public class MobileDeviceManagementUtil {
private static final Log log = LogFactory.getLog(MobileDeviceManagementUtil.class); private static final Log log = LogFactory.getLog(MobileDeviceManagementUtil.class);
private static final String MOBILE_DEVICE_IMEI = "imei"; private static final String MOBILE_DEVICE_IMEI = "IMEI";
private static final String MOBILE_DEVICE_IMSI = "imsi"; private static final String MOBILE_DEVICE_IMSI = "IMSI";
private static final String MOBILE_DEVICE_VENDOR = "vendor"; private static final String MOBILE_DEVICE_VENDOR = "VENDOR";
private static final String MOBILE_DEVICE_OS_VERSION = "osVersion"; private static final String MOBILE_DEVICE_OS_VERSION = "OS_VERSION";
private static final String MOBILE_DEVICE_MODEL = "model"; private static final String MOBILE_DEVICE_MODEL = "DEVICE_MODEL";
private static final String MOBILE_DEVICE_LATITUDE = "latitude"; private static final String MOBILE_DEVICE_LATITUDE = "LATITUDE";
private static final String MOBILE_DEVICE_LONGITUDE = "longitude"; private static final String MOBILE_DEVICE_LONGITUDE = "LONGITUDE";
private static final String MOBILE_DEVICE_SERIAL = "serial"; private static final String MOBILE_DEVICE_SERIAL = "SERIAL";
public static Document convertToDocument(File file) throws DeviceManagementException { public static Document convertToDocument(File file) throws DeviceManagementException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

@ -5,7 +5,7 @@
CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( CREATE TABLE IF NOT EXISTS `AD_DEVICE` (
`ANDROID_DEVICE_ID` VARCHAR(45) NOT NULL , `ANDROID_DEVICE_ID` VARCHAR(45) NOT NULL ,
`GCM_TOKEN` VARCHAR(45) NULL DEFAULT NULL , `GCM_TOKEN` VARCHAR(45) NULL DEFAULT NULL ,
`DEVICE_INFO` VARCHAR(500) NULL DEFAULT NULL , `DEVICE_INFO` VARCHAR(8000) NULL DEFAULT NULL ,
`IMEI` VARCHAR(45) NULL DEFAULT NULL , `IMEI` VARCHAR(45) NULL DEFAULT NULL ,
`IMSI` VARCHAR(45) NULL DEFAULT NULL , `IMSI` VARCHAR(45) NULL DEFAULT NULL ,
`OS_VERSION` VARCHAR(45) NULL DEFAULT NULL , `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL ,

Loading…
Cancel
Save