From f75aa4e1c8b713831ad35a2f37faa487c95fd7ed Mon Sep 17 00:00:00 2001 From: harshanL Date: Tue, 7 Apr 2015 14:24:01 +0530 Subject: [PATCH] Added Android pluging DAO layer & db scripts --- .../impl/android/AndroidFeatureManager.java | 3 - .../impl/android/dao/AndroidDAOFactory.java | 7 +- ...AndroidFeatureManagementDAOException.java} | 10 +- .../mobile/impl/android/dao/FeatureDAO.java | 36 -- .../dao/impl/AndroidDeviceDAOImpl.java | 338 ++++++++++++++++++ .../dao/impl/AndroidFeatureDAOImpl.java | 258 +++++++++++++ .../impl/android/dao/impl/FeatureDAOImpl.java | 165 --------- .../android/util/AndroidPluginConstants.java | 47 +++ .../impl/android/util/AndroidUtils.java | 38 ++ .../util/MobileDeviceManagementUtil.java | 2 - .../src/main/resources/conf/mobile-config.xml | 40 ++- .../dbscripts/plugins/h2_android.sql | 23 +- .../resources/dbscripts/plugins/h2_ios.sql | 5 +- .../dbscripts/plugins/mysql_android.sql | 55 +-- 14 files changed, 745 insertions(+), 282 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/{FeatureManagementDAOException.java => AndroidFeatureManagementDAOException.java} (84%) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidFeatureDAOImpl.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidUtils.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java index a4bc9d3921..0dcf3c0491 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java @@ -23,14 +23,11 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.FeatureManager; -import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; 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.dao.MobileFeatureDAO; import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureDAO; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOException; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; import java.util.ArrayList; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java index 19e8124fab..0ef9139c11 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java @@ -22,7 +22,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; 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.impl.android.dao.impl.FeatureDAOImpl; +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 javax.sql.DataSource; @@ -38,7 +39,7 @@ public class AndroidDAOFactory extends MobileDeviceManagementDAOFactory @Override public MobileDeviceDAO getMobileDeviceDAO() { - return null; + return new AndroidDeviceDAOImpl(dataSource); } @Override @@ -57,7 +58,7 @@ public class AndroidDAOFactory extends MobileDeviceManagementDAOFactory } @Override public MobileFeatureDAO getMobileFeatureDao() { - return new FeatureDAOImpl(); + return new AndroidFeatureDAOImpl(dataSource); } public MobileFeaturePropertyDAO getFeaturePropertyDAO() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidFeatureManagementDAOException.java similarity index 84% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidFeatureManagementDAOException.java index 467f2ea8a6..68d5a17d6b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidFeatureManagementDAOException.java @@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.mobile.impl.android.dao; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -public class FeatureManagementDAOException extends MobileDeviceManagementDAOException { +public class AndroidFeatureManagementDAOException extends MobileDeviceManagementDAOException { private String message; private static final long serialVersionUID = 2021891706072918865L; @@ -32,7 +32,7 @@ public class FeatureManagementDAOException extends MobileDeviceManagementDAOExce * @param message error message * @param nestedException exception */ - public FeatureManagementDAOException(String message, Exception nestedException) { + public AndroidFeatureManagementDAOException(String message, Exception nestedException) { super(message, nestedException); setErrorMessage(message); } @@ -44,7 +44,7 @@ public class FeatureManagementDAOException extends MobileDeviceManagementDAOExce * @param message the detail message. * @param cause the cause of this exception. */ - public FeatureManagementDAOException(String message, Throwable cause) { + public AndroidFeatureManagementDAOException(String message, Throwable cause) { super(message, cause); setErrorMessage(message); } @@ -54,7 +54,7 @@ public class FeatureManagementDAOException extends MobileDeviceManagementDAOExce * * @param message the detail message. */ - public FeatureManagementDAOException(String message) { + public AndroidFeatureManagementDAOException(String message) { super(message); setErrorMessage(message); } @@ -64,7 +64,7 @@ public class FeatureManagementDAOException extends MobileDeviceManagementDAOExce * * @param cause the cause of this exception. */ - public FeatureManagementDAOException(Throwable cause) { + public AndroidFeatureManagementDAOException(Throwable cause) { super(cause); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java deleted file mode 100644 index fbe387fa47..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.mgt.mobile.impl.android.dao; - -import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; - -import java.util.List; - -public interface FeatureDAO { - - void addFeature(MobileFeature feature) throws FeatureManagementDAOException; - - void removeFeature(String name) throws FeatureManagementDAOException; - - MobileFeature getFeature(String name) throws FeatureManagementDAOException; - - List getFeatures() throws FeatureManagementDAOException; - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java new file mode 100644 index 0000000000..690c6d180e --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java @@ -0,0 +1,338 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO; +import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; +import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; +import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginConstants; +import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidUtils; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Implements MobileDeviceDAO for Android Devices. + */ +public class AndroidDeviceDAOImpl implements MobileDeviceDAO{ + + private DataSource dataSource; + private static final Log log = LogFactory.getLog(AndroidDeviceDAOImpl.class); + + public AndroidDeviceDAOImpl(DataSource dataSource) { + this.dataSource = dataSource; + } + + @Override + public MobileDevice getMobileDevice(String mblDeviceId) + throws MobileDeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + MobileDevice mobileDevice = null; + try { + conn = this.getConnection(); + String selectDBQuery = + "SELECT ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, SERIAL, VENDOR, MAC_ADDRESS, " + + "DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, 0S_VERSION FROM AD_DEVICE WHERE" + + " MOBILE_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)); + + Map propertyMap = new HashMap(); + propertyMap.put(AndroidPluginConstants.GCM_TOKEN, + resultSet.getString(AndroidPluginConstants.GCM_TOKEN)); + propertyMap.put(AndroidPluginConstants.DEVICE_INFO, + resultSet.getString(AndroidPluginConstants.DEVICE_INFO)); + propertyMap.put(AndroidPluginConstants.SERIAL, + resultSet.getString(AndroidPluginConstants.SERIAL)); + propertyMap.put(AndroidPluginConstants.VENDOR, + resultSet.getString(AndroidPluginConstants.VENDOR)); + propertyMap.put(AndroidPluginConstants.MAC_ADDRESS, + resultSet.getString(AndroidPluginConstants.MAC_ADDRESS)); + propertyMap.put(AndroidPluginConstants.DEVICE_NAME, + resultSet.getString(AndroidPluginConstants.DEVICE_NAME)); + propertyMap.put(AndroidPluginConstants.LATITUDE, + resultSet.getString(AndroidPluginConstants.LATITUDE)); + propertyMap.put(AndroidPluginConstants.LONGITUDE, + resultSet.getString(AndroidPluginConstants.LONGITUDE)); + propertyMap.put(AndroidPluginConstants.IMEI, + resultSet.getString(AndroidPluginConstants.IMEI)); + propertyMap.put(AndroidPluginConstants.IMSI, + resultSet.getString(AndroidPluginConstants.IMSI)); + propertyMap.put(AndroidPluginConstants.OS_VERSION, + resultSet.getString(AndroidPluginConstants.OS_VERSION)); + + mobileDevice.setDeviceProperties(propertyMap); + + if (log.isDebugEnabled()) { + log.debug("Android device " + mblDeviceId + " data has been fetched from Android database."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while fetching Android device : '" + mblDeviceId + "'"; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + + return mobileDevice; + } + + @Override + public boolean addMobileDevice(MobileDevice mobileDevice) + throws MobileDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + 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)" + + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + stmt = conn.prepareStatement(createDBQuery); + stmt.setString(1, mobileDevice.getMobileDeviceId()); + + if (mobileDevice.getDeviceProperties() == null) { + mobileDevice.setDeviceProperties(new HashMap()); + } + + stmt.setString(2, AndroidUtils.getDeviceProperty( + mobileDevice.getDeviceProperties(), + AndroidPluginConstants.GCM_TOKEN)); + stmt.setString(3, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.DEVICE_INFO)); + stmt.setString(4, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.SERIAL)); + stmt.setString(5, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.VENDOR)); + stmt.setString(6, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.MAC_ADDRESS)); + stmt.setString(7, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.DEVICE_NAME)); + stmt.setString(8, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.LATITUDE)); + stmt.setString(9, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.LONGITUDE)); + stmt.setString(10, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.IMEI)); + stmt.setString(11, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.IMSI)); + stmt.setString(12, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.OS_VERSION)); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Android device " + mobileDevice.getMobileDeviceId() + " data has been added" + + " to the Android database."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while adding the Android device '" + + mobileDevice.getMobileDeviceId() + "' to the Android db."; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return status; + } + + @Override + public boolean updateMobileDevice(MobileDevice mobileDevice) + throws MobileDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + 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 = ? " + + "WHERE ANDROID_DEVICE_ID = ?"; + + stmt = conn.prepareStatement(updateDBQuery); + stmt.setString(1, mobileDevice.getMobileDeviceId()); + + if (mobileDevice.getDeviceProperties() == null) { + mobileDevice.setDeviceProperties(new HashMap()); + } + + stmt.setString(2, AndroidUtils.getDeviceProperty( + mobileDevice.getDeviceProperties(), + AndroidPluginConstants.GCM_TOKEN)); + stmt.setString(3, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.DEVICE_INFO)); + stmt.setString(4, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.SERIAL)); + stmt.setString(5, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.VENDOR)); + stmt.setString(6, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.MAC_ADDRESS)); + stmt.setString(7, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.DEVICE_NAME)); + stmt.setString(8, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.LATITUDE)); + stmt.setString(9, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.LONGITUDE)); + stmt.setString(10, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.IMEI)); + stmt.setString(11, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.IMSI)); + stmt.setString(12, AndroidUtils.getDeviceProperty(mobileDevice.getDeviceProperties(), + AndroidPluginConstants.OS_VERSION)); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Android device " + mobileDevice.getMobileDeviceId() + " data has been" + + " modified."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while modifying the Android device '" + + mobileDevice.getMobileDeviceId() + "' data."; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return status; + } + + @Override + public boolean deleteMobileDevice(String mblDeviceId) + throws MobileDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = this.getConnection(); + String deleteDBQuery = + "DELETE FROM AD_DEVICE WHERE ANDROID_DEVICE_ID = ?"; + stmt = conn.prepareStatement(deleteDBQuery); + stmt.setString(1, mblDeviceId); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Android device " + mblDeviceId + " data has deleted" + + " from the Android database."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while deleting android device " + mblDeviceId; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return status; + } + + @Override + public List getAllMobileDevices() + throws MobileDeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + + List mobileDevices = new ArrayList(); + try { + conn = this.getConnection(); + String selectDBQuery = + "SELECT ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, SERIAL, VENDOR, MAC_ADDRESS," + + "DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, 0S_VERSION FROM AD_DEVICE"; + stmt = conn.prepareStatement(selectDBQuery); + ResultSet resultSet = stmt.executeQuery(); + while (resultSet.next()) { + + MobileDevice mobileDevice = new MobileDevice(); + mobileDevice.setMobileDeviceId + (resultSet.getString(AndroidPluginConstants.ANDROID_DEVICE_ID)); + + Map propertyMap = new HashMap(); + propertyMap.put(AndroidPluginConstants.GCM_TOKEN, + resultSet.getString(AndroidPluginConstants.GCM_TOKEN)); + propertyMap.put(AndroidPluginConstants.DEVICE_INFO, + resultSet.getString(AndroidPluginConstants.DEVICE_INFO)); + propertyMap.put(AndroidPluginConstants.SERIAL, + resultSet.getString(AndroidPluginConstants.SERIAL)); + propertyMap.put(AndroidPluginConstants.VENDOR, + resultSet.getString(AndroidPluginConstants.VENDOR)); + propertyMap.put(AndroidPluginConstants.MAC_ADDRESS, + resultSet.getString(AndroidPluginConstants.MAC_ADDRESS)); + propertyMap.put(AndroidPluginConstants.DEVICE_NAME, + resultSet.getString(AndroidPluginConstants.DEVICE_NAME)); + propertyMap.put(AndroidPluginConstants.LATITUDE, + resultSet.getString(AndroidPluginConstants.LATITUDE)); + propertyMap.put(AndroidPluginConstants.LONGITUDE, + resultSet.getString(AndroidPluginConstants.LONGITUDE)); + propertyMap.put(AndroidPluginConstants.IMEI, + resultSet.getString(AndroidPluginConstants.IMEI)); + propertyMap.put(AndroidPluginConstants.IMSI, + resultSet.getString(AndroidPluginConstants.IMSI)); + propertyMap.put(AndroidPluginConstants.OS_VERSION, + resultSet.getString(AndroidPluginConstants.OS_VERSION)); + + mobileDevice.setDeviceProperties(propertyMap); + + mobileDevices.add(mobileDevice); + } + if (log.isDebugEnabled()) { + log.debug("All Android device details have fetched from Android database."); + } + return mobileDevices; + } catch (SQLException e) { + String msg = "Error occurred while fetching all Android device data'"; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + } + + private Connection getConnection() throws MobileDeviceManagementDAOException { + try { + return dataSource.getConnection(); + } catch (SQLException e) { + String msg = "Error occurred while obtaining a connection from the mobile device " + + "management metadata repository datasource"; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidFeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidFeatureDAOImpl.java new file mode 100644 index 0000000000..43e56ef9f2 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidFeatureDAOImpl.java @@ -0,0 +1,258 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; +import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; +import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidFeatureManagementDAOException; +import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginConstants; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class AndroidFeatureDAOImpl implements MobileFeatureDAO { + + private DataSource dataSource; + private static final Log log = LogFactory.getLog(AndroidFeatureDAOImpl.class); + + public AndroidFeatureDAOImpl(DataSource dataSource) { + this.dataSource = dataSource; + } + + @Override + public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + boolean status = false; + try { + Connection conn = this.getConnection(); + String sql = "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, mobileFeature.getCode()); + stmt.setString(2, mobileFeature.getName()); + stmt.setString(3, mobileFeature.getDescription()); + stmt.executeUpdate(); + status = true; + status = true; + } catch (SQLException e) { + throw new AndroidFeatureManagementDAOException( + "Error occurred while adding android feature '" + + mobileFeature.getName() + "' into the metadata repository", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = this.getConnection(); + String updateDBQuery = + "UPDATE AD_FEATURE SET NAME = ?, DESCRIPTION = ?" + + "WHERE CODE = ?"; + + stmt = conn.prepareStatement(updateDBQuery); + stmt.setString(1, mobileFeature.getName()); + stmt.setString(2, mobileFeature.getDescription()); + stmt.setString(3, mobileFeature.getCode()); + + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Android Feature " + mobileFeature.getCode() + " data has been modified."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while updating the Android Feature '" + + mobileFeature.getCode() + "' to the Android db."; + log.error(msg, e); + throw new AndroidFeatureManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return status; + } + + @Override + public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + boolean status = false; + try { + Connection conn = this.getConnection(); + String sql = "DELETE FROM AD_FEATURE WHERE ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, mblFeatureId); + stmt.execute(); + status = true; + } catch (SQLException e) { + throw new AndroidFeatureManagementDAOException( + "Error occurred while deleting android feature '" + + mblFeatureId + "' from Android database.", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + boolean status = false; + try { + Connection conn = this.getConnection(); + String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, mblFeatureCode); + stmt.execute(); + status = true; + } catch (SQLException e) { + throw new AndroidFeatureManagementDAOException( + "Error occurred while deleting android feature '" + + mblFeatureCode + "' from Android database.", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + try { + Connection conn = this.getConnection(); + String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, mblFeatureId); + rs = stmt.executeQuery(); + + MobileFeature mobileFeature = null; + if (rs.next()) { + mobileFeature = new MobileFeature(); + 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.setDeviceType( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + } + return mobileFeature; + } catch (SQLException e) { + throw new AndroidFeatureManagementDAOException( + "Error occurred while retrieving android feature '" + + mblFeatureId + "' from the Android database.", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); + } + } + + @Override + public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + try { + Connection conn = this.getConnection(); + String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, mblFeatureCode); + rs = stmt.executeQuery(); + + MobileFeature mobileFeature = null; + if (rs.next()) { + mobileFeature = new MobileFeature(); + 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.setDeviceType( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + } + return mobileFeature; + } catch (SQLException e) { + throw new AndroidFeatureManagementDAOException( + "Error occurred while retrieving android feature '" + + mblFeatureCode + "' from the Android database.", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); + } + } + + @Override + public List getFeatureByDeviceType(String deviceType) + throws MobileDeviceManagementDAOException { + return this.getAllFeatures(); + } + + @Override + public List getAllFeatures() throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + List features = new ArrayList(); + + try { + Connection conn = this.getConnection(); + String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE"; + stmt = conn.prepareStatement(sql); + rs = stmt.executeQuery(); + MobileFeature mobileFeature = null; + + while (rs.next()) { + mobileFeature = new MobileFeature(); + 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.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); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); + } + } + + private Connection getConnection() throws MobileDeviceManagementDAOException { + try { + return dataSource.getConnection(); + } catch (SQLException e) { + String msg = "Error occurred while obtaining a connection from the Android mobile device " + + "management metadata repository datasource"; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java deleted file mode 100644 index 4c49a551a0..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl; - -import org.wso2.carbon.device.mgt.common.Feature; -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.dao.MobileFeatureDAO; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -public class FeatureDAOImpl implements MobileFeatureDAO { - - @Override - public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status = false; - try { - Connection conn = MobileDeviceManagementDAOFactory.getConnection(); - String sql = "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mobileFeature.getCode()); - stmt.setString(2, mobileFeature.getName()); - stmt.setString(3, mobileFeature.getDescription()); - stmt.executeUpdate(); - status = true; - status = true; - } catch (SQLException e) { - throw new org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException( - "Error occurred while adding feature '" + - mobileFeature.getName() + "' into the metadata repository", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { - return false; - } - - @Override - public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { - return false; - } - - @Override - public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status = false; - try { - Connection conn = MobileDeviceManagementDAOFactory.getConnection(); - String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mblFeatureCode); - stmt.execute(); - status = true; - } catch (SQLException e) { - throw new org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException( - "Error occurred while adding feature '" + - mblFeatureCode + "' into the metadata repository", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { - return null; - } - - @Override - public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - try { - Connection conn = MobileDeviceManagementDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mblFeatureCode); - rs = stmt.executeQuery(); - - Feature feature = null; - if (rs.next()) { - feature = new Feature(); - feature.setId(rs.getInt("ID")); - feature.setCode(rs.getString("CODE")); - feature.setName(rs.getString("NAME")); - feature.setDescription(rs.getString("DESCRIPTION")); - } - MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature); - return mobileFeature; - } catch (SQLException e) { - throw new org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException( - "Error occurred while retrieving feature metadata '" + - mblFeatureCode + "' from the feature metadata repository", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } - - @Override - public List getFeatureByDeviceType(String deviceType) - throws MobileDeviceManagementDAOException { - return null; - } - - @Override - public List getAllFeatures() throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - List features = new ArrayList(); - - try { - Connection conn = MobileDeviceManagementDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE"; - stmt = conn.prepareStatement(sql); - rs = stmt.executeQuery(); - MobileFeature mobileFeature; - - while (rs.next()) { - Feature feature = new Feature(); - feature.setId(rs.getInt("ID")); - feature.setCode(rs.getString("CODE")); - feature.setName(rs.getString("NAME")); - feature.setDescription(rs.getString("DESCRIPTION")); - mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature); - features.add(mobileFeature); - } - return features; - } catch (SQLException e) { - throw new FeatureManagementDAOException("Error occurred while retrieving all feature metadata from the " + - "feature metadata repository", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java new file mode 100644 index 0000000000..ea658bd727 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.mobile.impl.android.util; + +/** + * Defines constants used by android plugin. + */ +public class AndroidPluginConstants { + + //Properties related to AD_DEVICE table + public static final String ANDROID_DEVICE_ID = "ANDROID_DEVICE_ID"; + public static final String GCM_TOKEN = "GCM_TOKEN"; + public static final String DEVICE_INFO = "DEVICE_INFO"; + public static final String SERIAL = "SERIAL"; + public static final String DEVICE_MODEL = "DEVICE_MODEL"; + public static final String DEVICE_NAME = "DEVICE_NAME"; + public static final String LATITUDE = "LATITUDE"; + public static final String LONGITUDE = "LONGITUDE"; + public static final String IMEI = "IMEI"; + public static final String IMSI = "IMEI"; + public static final String VENDOR = "VENDOR"; + public static final String OS_VERSION = "OS_VERSION"; + public static final String MAC_ADDRESS = "MAC_ADDRESS"; + + //Properties related to AD_FEATURE table + public static final String ANDROID_FEATURE_ID = "ID"; + public static final String ANDROID_FEATURE_CODE = "CODE"; + public static final String ANDROID_FEATURE_NAME = "NAME"; + public static final String ANDROID_FEATURE_DESCRIPTION = "DESCRIPTION"; + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidUtils.java new file mode 100644 index 0000000000..0bf2bd338b --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidUtils.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.mobile.impl.android.util; + +import java.util.Map; + +/** + * Contains utility methods used by Android plugin. + */ +public class AndroidUtils { + + public static String getDeviceProperty(Map deviceProperties, String property) { + + String deviceProperty = deviceProperties.get(property); + + if (deviceProperty == null) { + return ""; + } + + return deviceProperty; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java index 342b68d788..4e75bebbe9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java @@ -174,7 +174,6 @@ public class MobileDeviceManagementUtil { mobileFeature.setCode(feature.getCode()); mobileFeature.setDescription(feature.getDescription()); mobileFeature.setDeviceType(feature.getDeviceType()); - return mobileFeature; } @@ -184,7 +183,6 @@ public class MobileDeviceManagementUtil { feature.setDeviceType(mobileFeature.getDeviceType()); feature.setCode(mobileFeature.getCode()); feature.setName(mobileFeature.getName()); - return feature; } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml index 9daf68724d..ebdbed3d22 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml @@ -39,14 +39,38 @@ - - enrollment - admin - enrollment - 1.0.0 - http://localhost:9763/ - http,https - + + appmanager + admin + /devices + 1.0.0 + http://localhost:9763/test/app + http,https + + + enrol + admin + /enroll + 1.0.0 + http://localhost:9763/mdm-android-agent/enrollment + http,https + + + license + admin + /license + 1.0.0 + http://localhost:9763/mdm-android-agent/devices/license + http,https + + + operation + admin + /operation + 1.0.0 + http://localhost:9763/mdm-android-agent/operations + http,https + 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 54f11fc35d..a3a1145faf 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 @@ -3,8 +3,8 @@ -- Table `AD_DEVICE` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( - `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL , - `PUSH_TOKEN` VARCHAR(45) NULL DEFAULT NULL , + `ANDROID_DEVICE_ID` VARCHAR(45) NOT NULL , + `GCM_TOKEN` VARCHAR(45) NULL DEFAULT NULL , `IMEI` VARCHAR(45) NULL DEFAULT NULL , `IMSI` VARCHAR(45) NULL DEFAULT NULL , `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL , @@ -12,11 +12,10 @@ CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( `VENDOR` VARCHAR(45) NULL DEFAULT NULL , `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, - `CHALLENGE` VARCHAR(45) 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`) ); + `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, + `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, + PRIMARY KEY (`ANDROID_DEVICE_ID`) ); -- ----------------------------------------------------- -- Table `AD_FEATURE` @@ -28,15 +27,3 @@ CREATE TABLE IF NOT EXISTS `AD_FEATURE` ( `DESCRIPTION` VARCHAR(200) NULL , PRIMARY KEY (`ID`) ); --- ----------------------------------------------------- --- Table `AD_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_AD_FEATURE_PROPERTY_AD_FEATURE1` - FOREIGN KEY (`FEATURE_ID` ) - REFERENCES `AD_FEATURE` (`ID` ) - ON DELETE NO ACTION - ON UPDATE NO ACTION); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_ios.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_ios.sql index f3c69a21a0..e04f68c47a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_ios.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_ios.sql @@ -30,7 +30,4 @@ CREATE TABLE IF NOT EXISTS `IOS_FEATURE` ( `ICCID` VARCHAR(45) NULL DEFAULT NULL, `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, - PRIMARY KEY (`MOBILE_DEVICE_ID`) ); - - -long \ No newline at end of file + PRIMARY KEY (`MOBILE_DEVICE_ID`) ); \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_android.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_android.sql index e69dc48ad1..be5895d993 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_android.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_android.sql @@ -1,52 +1,31 @@ -- ----------------------------------------------------- -- Table `MBL_DEVICE` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_DEVICE` ( - `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, - `PUSH_TOKEN` VARCHAR(45) NULL DEFAULT NULL, - `IMEI` VARCHAR(45) NULL DEFAULT NULL, - `IMSI` VARCHAR(45) NULL DEFAULT NULL, - `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL, - `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL, - `VENDOR` VARCHAR(45) NULL DEFAULT NULL, +CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( + `ANDROID_DEVICE_ID` VARCHAR(45) NOT NULL , + `GCM_TOKEN` VARCHAR(45) NULL DEFAULT NULL , + `IMEI` VARCHAR(45) NULL DEFAULT NULL , + `IMSI` VARCHAR(45) NULL DEFAULT NULL , + `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL , + `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL , + `VENDOR` VARCHAR(45) NULL DEFAULT NULL , `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, `SERIAL` VARCHAR(45) NULL DEFAULT NULL, - PRIMARY KEY (`MOBILE_DEVICE_ID`)) + `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, + `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, + PRIMARY KEY (`ANDROID_DEVICE_ID`)) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `MBL_FEATURE` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( - `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, - `DEVICE_TYPE` VARCHAR(45) NOT NULL , - `CODE` VARCHAR(45) NULL, - `NAME` VARCHAR(100) NULL, - `DESCRIPTION` VARCHAR(200) NULL, - PRIMARY KEY (`FEATURE_ID`)) +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 (`ID`)) ENGINE = InnoDB; --- ----------------------------------------------------- --- Table `MBL_FEATURE_PROPERTY` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` ( - `PROPERTY` VARCHAR(45) NOT NULL , - `FEATURE_ID` INT NOT NULL , - PRIMARY KEY (`PROPERTY`), - CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1` - FOREIGN KEY (`FEATURE_ID`) - REFERENCES `MBL_FEATURE` (`FEATURE_ID`) - ON DELETE NO ACTION - ON UPDATE NO ACTION) -ENGINE = InnoDB; - --- ----------------------------------------------------- --- 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'); -