From a10d7ff04f562724e8487c964de09c654f9e9203 Mon Sep 17 00:00:00 2001 From: harshanL Date: Fri, 27 Mar 2015 23:00:43 +0530 Subject: [PATCH] Added Android-sql scripts & Fixed FeatureManager --- .../impl/android/AndroidDeviceManager.java | 343 +++++++++--------- .../src/test/resources/sql/h2.sql | 2 +- .../dbscripts/plugins/h2_android.sql | 33 +- 3 files changed, 188 insertions(+), 190 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java index 70256e52be..02cfac9e8d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java @@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; import java.util.ArrayList; @@ -35,176 +36,180 @@ import java.util.List; */ public class AndroidDeviceManager implements DeviceManager { - private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; + private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; private static final Log log = LogFactory.getLog(AndroidDeviceManager.class); - public AndroidDeviceManager() { - mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - } - - @Override - public String getProviderType() { - return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID; - } - - @Override - public FeatureManager getFeatureManager() { - return new AndroidFeatureManager(); - } - - @Override - public boolean enrollDevice(Device device) throws DeviceManagementException { - boolean status; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); - } - status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( - mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while enrolling the Android device : " + - device.getDeviceIdentifier(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public boolean modifyEnrollment(Device device) throws DeviceManagementException { - boolean status; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("Modifying the Android device enrollment data"); - } - status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .updateMobileDevice(mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while updating the enrollment of the Android device : " + - device.getDeviceIdentifier(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - boolean status; - try { - if (log.isDebugEnabled()) { - log.debug("Dis-enrolling Android device : " + deviceId); - } - status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .deleteMobileDevice(deviceId.getId()); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while removing the Android device : " + deviceId.getId(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { - boolean isEnrolled = false; - try { - if (log.isDebugEnabled()) { - log.debug("Checking the enrollment of Android device : " + deviceId.getId()); - } - MobileDevice mobileDevice = - mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( - deviceId.getId()); - if (mobileDevice != null) { - isEnrolled = true; - } - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while checking the enrollment status of Android device : " + - deviceId.getId(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return isEnrolled; - } - - @Override - public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - return true; - } - - @Override - public boolean setActive(DeviceIdentifier deviceId, boolean status) - throws DeviceManagementException { - return true; - } - - @Override - public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - Device device; - try { - if (log.isDebugEnabled()) { - log.debug("Getting the details of Android device : " + deviceId.getId()); - } - MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO(). - getMobileDevice(deviceId.getId()); - device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while fetching the Android device : " + deviceId.getId(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return device; - } - - @Override - public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) - throws DeviceManagementException { - return true; - } - - @Override - public boolean updateDeviceInfo(Device device) throws DeviceManagementException { - boolean status; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("updating the details of Android device : " + device.getDeviceIdentifier()); - } - status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .updateMobileDevice(mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while updating the Android device : " + device.getDeviceIdentifier(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public List getAllDevices() throws DeviceManagementException { - List devices = null; - try { - if (log.isDebugEnabled()) { - log.debug("Fetching the details of all Android devices"); - } - List mobileDevices = - mobileDeviceManagementDAOFactory.getMobileDeviceDAO(). - getAllMobileDevices(); - if (mobileDevices != null) { - devices = new ArrayList(); - for (MobileDevice mobileDevice : mobileDevices) { - devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); - } - } - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while fetching all Android devices."; - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return devices; - } + public AndroidDeviceManager() { + mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + FeatureManagementDAOFactory + .init(mobileDeviceManagementDAOFactory.getDataSource(this.getProviderType())); + } + + @Override + public String getProviderType() { + return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID; + } + + @Override + public FeatureManager getFeatureManager() { + return new AndroidFeatureManager(); + } + + @Override + public boolean enrollDevice(Device device) throws DeviceManagementException { + boolean status; + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); + } + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( + mobileDevice); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while enrolling the Android device : " + + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + boolean status; + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Modifying the Android device enrollment data"); + } + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() + .updateMobileDevice(mobileDevice); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while updating the enrollment of the Android device : " + + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + boolean status; + try { + if (log.isDebugEnabled()) { + log.debug("Dis-enrolling Android device : " + deviceId); + } + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() + .deleteMobileDevice(deviceId.getId()); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while removing the Android device : " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + boolean isEnrolled = false; + try { + if (log.isDebugEnabled()) { + log.debug("Checking the enrollment of Android device : " + deviceId.getId()); + } + MobileDevice mobileDevice = + mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( + deviceId.getId()); + if (mobileDevice != null) { + isEnrolled = true; + } + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while checking the enrollment status of Android device : " + + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return isEnrolled; + } + + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + return true; + } + + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { + return true; + } + + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + Device device; + try { + if (log.isDebugEnabled()) { + log.debug("Getting the details of Android device : " + deviceId.getId()); + } + MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO(). + getMobileDevice(deviceId.getId()); + device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while fetching the Android device : " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return device; + } + + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return true; + } + + @Override + public boolean updateDeviceInfo(Device device) throws DeviceManagementException { + boolean status; + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug( + "updating the details of Android device : " + device.getDeviceIdentifier()); + } + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() + .updateMobileDevice(mobileDevice); + } catch (MobileDeviceManagementDAOException e) { + String msg = + "Error while updating the Android device : " + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public List getAllDevices() throws DeviceManagementException { + List devices = null; + try { + if (log.isDebugEnabled()) { + log.debug("Fetching the details of all Android devices"); + } + List mobileDevices = + mobileDeviceManagementDAOFactory.getMobileDeviceDAO(). + getAllMobileDevices(); + if (mobileDevices != null) { + devices = new ArrayList(); + for (MobileDevice mobileDevice : mobileDevices) { + devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); + } + } + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while fetching all Android devices."; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return devices; + } } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/h2.sql index c0c2cebbaa..e10ec1da8d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/h2.sql @@ -1,6 +1,6 @@ -- ----------------------------------------------------- --- Table `MBL_DEVICE` +-- Table `AD_DEVICE` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL , diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_android.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_android.sql index e63252d4a6..54f11fc35d 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_android.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_android.sql @@ -1,8 +1,8 @@ -- ----------------------------------------------------- --- Table `MBL_DEVICE` +-- Table `AD_DEVICE` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_DEVICE` ( +CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL , `PUSH_TOKEN` VARCHAR(45) NULL DEFAULT NULL , `IMEI` VARCHAR(45) NULL DEFAULT NULL , @@ -13,37 +13,30 @@ CREATE TABLE IF NOT EXISTS `MBL_DEVICE` ( `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, `CHALLENGE` VARCHAR(45) NULL DEFAULT NULL, - `TOKEN` VARCHAR(50) NULL DEFAULT NULL, - `UNLOCK_TOKEN` VARCHAR(2000) NULL DEFAULT NULL, + `TOKEN` VARCHAR(500) NULL DEFAULT NULL, + `UNLOCK_TOKEN` VARCHAR(500) NULL DEFAULT NULL, `SERIAL` VARCHAR(45) NULL DEFAULT NULL, PRIMARY KEY (`MOBILE_DEVICE_ID`) ); - -- ----------------------------------------------------- --- Table `MBL_FEATURE` +-- Table `AD_FEATURE` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( - `FEATURE_ID` INT NOT NULL AUTO_INCREMENT , - `DEVICE_TYPE` VARCHAR(45) NOT NULL , - `CODE` VARCHAR(45) NOT NULL , +CREATE TABLE IF NOT EXISTS `AD_FEATURE` ( + `ID` INT NOT NULL AUTO_INCREMENT , + `CODE` VARCHAR(45) NOT NULL, `NAME` VARCHAR(100) NULL , `DESCRIPTION` VARCHAR(200) NULL , - PRIMARY KEY (`FEATURE_ID`) ); + PRIMARY KEY (`ID`) ); -- ----------------------------------------------------- --- Table `MBL_FEATURE_PROPERTY` +-- Table `AD_FEATURE_PROPERTY` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` ( +CREATE TABLE IF NOT EXISTS `AD_FEATURE_PROPERTY` ( `PROPERTY` VARCHAR(45) NOT NULL , `FEATURE_ID` INT NOT NULL , PRIMARY KEY (`PROPERTY`) , - CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1` + CONSTRAINT `fk_AD_FEATURE_PROPERTY_AD_FEATURE1` FOREIGN KEY (`FEATURE_ID` ) - REFERENCES `MBL_FEATURE` (`FEATURE_ID` ) + REFERENCES `AD_FEATURE` (`ID` ) ON DELETE NO ACTION ON UPDATE NO ACTION); - --- ----------------------------------------------------- --- Inserts --- ----------------------------------------------------- -INSERT INTO MBL_FEATURE (DEVICE_TYPE,NAME,CODE, DESCRIPTION) VALUES ('android','DEVICE_LOCK','503A','Device Lock'),('android','WIPE','504A','Device Wipe'),('android','CLEARPASSCODE','505A','Clear Passcode'),('android','APPLIST','502A','Get All Applications'),('android','LOCATION','501A','Location'),('android','INFO','500A','Device Information'),('android','NOTIFICATION','506A','Message'),('android','WIFI','507A','Setup Wifi'),('android','CAMERA','508A','Camera Control'),('android','MUTE','513A','Mute Device'),('android','INSTALLAPP','509A','Install Application'),('android','UNINSTALLAPP','510A','Uninstall Application'),('android','ENCRYPT','511A','Encrypt Storage'),('android','APN','512A','APN'),('android','WEBCLIP','518A','Create Webclips'),('android','PASSWORDPOLICY','519A','Passcode Policy'),('android','EMAIL','520A','Email Configuration'),('android','GOOGLECALENDAR','521A','Calender Subscription'),('android','VPN','523A','VPN'),('android','LDAP','524A','LDAP'),('android','CHANGEPASSWORD','526A','Set Passcode'),('android','ENTERPRISEWIPE','527A','Enterprise Wipe'),('android','POLICY','500P','Policy Enforcement'),('android','MONITORING','501P','Policy Monitoring '),('android','BLACKLISTAPPS','528B','Blacklist Apps'),('android','REVOKEPOLICY','502P','Revoke Policy'); \ No newline at end of file