From a277fd53c22806c2b405c82e2889849ce5db57cc Mon Sep 17 00:00:00 2001 From: hasuniea Date: Wed, 21 Oct 2015 19:29:34 +0530 Subject: [PATCH 01/22] Implemented WindowsFeatureDAOImpl --- .../WindowsFeatureManagementDAOException.java | 80 ++++++ .../dao/impl/WindowsFeatureDAOImpl.java | 258 ++++++++++++++++++ .../windows/util/WindowsPluginConstants.java | 7 + 3 files changed, 345 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsFeatureManagementDAOException.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsFeatureManagementDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsFeatureManagementDAOException.java new file mode 100644 index 0000000000..5444fd2239 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsFeatureManagementDAOException.java @@ -0,0 +1,80 @@ +/* + * 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.windows.dao; + +import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; + +/** + * Implement Exception class for Windows Device Features. + */ +public class WindowsFeatureManagementDAOException extends MobileDeviceManagementDAOException { + + private String message; + private static final long serialVersionUID = 2021891706072918865L; + + /** + * Constructs a new MobileDeviceManagementDAOException with the specified detail message and + * nested exception. + * + * @param message error message + * @param nestedException exception + */ + public WindowsFeatureManagementDAOException(String message, Exception nestedException) { + super(message, nestedException); + } + + /** + * Constructs a new MobileDeviceManagementDAOException with the specified detail message + * and cause. + * + * @param message the detail message. + * @param cause the cause of this exception. + */ + public WindowsFeatureManagementDAOException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + /** + * Constructs a new MobileDeviceManagementDAOException with the specified detail message. + * + * @param message the detail message. + */ + public WindowsFeatureManagementDAOException(String message) { + super(message); + setErrorMessage(message); + } + + /** + * Constructs a new MobileDeviceManagementDAOException with the specified and cause. + * + * @param cause the cause of this exception. + */ + public WindowsFeatureManagementDAOException(Throwable cause) { + super(cause); + } + + public String getMessage() { + return message; + } + + public void setErrorMessage(String errorMessage) { + this.message = errorMessage; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java new file mode 100644 index 0000000000..e69e209974 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.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.windows.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.windows.dao.WindowsDAOFactory; +import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsFeatureManagementDAOException; +import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsPluginConstants; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +/** + * Implement MobileFeatureDAO for Windows devices. + */ +public class WindowsFeatureDAOImpl implements MobileFeatureDAO { + + private static final Log log = LogFactory.getLog(WindowsFeatureDAOImpl.class); + + public WindowsFeatureDAOImpl() { + + } + @Override + public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + boolean status; + Connection conn; + try { + conn = WindowsDAOFactory.getConnection(); + String sql = "INSERT INTO WINDOWS_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 WindowsFeatureManagementDAOException( + "Error occurred while adding windows 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; + PreparedStatement stmt = null; + try { + conn = WindowsDAOFactory.getConnection(); + String updateDBQuery = + "UPDATE WINDOWS_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("Windows Feature " + mobileFeature.getCode() + " data has been " + + "modified."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while updating the Windows Feature '" + + mobileFeature.getCode() + "' to the Android db."; + log.error(msg, e); + throw new WindowsFeatureManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + boolean status = false; + Connection conn = null; + try { + conn = WindowsDAOFactory.getConnection(); + String sql = "DELETE FROM WINDOWS_FEATURE WHERE FEATURE_ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, mblFeatureId); + stmt.execute(); + status = true; + } catch (SQLException e) { + throw new WindowsFeatureManagementDAOException( + "Error occurred while deleting windows feature '" + + mblFeatureId + "' from Windows database.", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + boolean status = false; + Connection conn = null; + try { + conn = WindowsDAOFactory.getConnection(); + String sql = "DELETE FROM WINDOWS_FEATURE WHERE CODE = ?"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, mblFeatureCode); + stmt.execute(); + status = true; + } catch (SQLException e) { + throw new WindowsFeatureManagementDAOException( + "Error occurred while deleting windows feature '" + + mblFeatureCode + "' from Windows database.", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + Connection conn = null; + try { + conn = WindowsDAOFactory.getConnection(); + String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WINDOWS_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(WindowsPluginConstants.WINDOWS_FEATURE_ID)); + mobileFeature.setCode(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_CODE)); + mobileFeature.setName(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_NAME)); + mobileFeature.setDescription(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_DESCRIPTION)); + mobileFeature.setDeviceType( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + } + return mobileFeature; + } catch (SQLException e) { + throw new WindowsFeatureManagementDAOException( + "Error occurred while retrieving windows feature '" + + mblFeatureId + "' from the Windows database.", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); + WindowsDAOFactory.closeConnection(); + } + } + + @Override + public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + Connection conn = null; + + try { + conn = WindowsDAOFactory.getConnection(); + String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WINDOWS_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(WindowsPluginConstants.WINDOWS_FEATURE_ID)); + mobileFeature.setCode(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_CODE)); + mobileFeature.setName(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_NAME)); + mobileFeature.setDescription(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_DESCRIPTION)); + mobileFeature.setDeviceType( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + } + return mobileFeature; + } catch (SQLException e) { + throw new WindowsFeatureManagementDAOException( + "Error occurred while retrieving windows feature '" + + mblFeatureCode + "' from the Windows database.", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); + WindowsDAOFactory.closeConnection(); + } + } + + @Override + public List getFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException { + return this.getAllFeatures(); + } + + @Override + public List getAllFeatures() throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + Connection conn = null; + List features = new ArrayList(); + + try { + conn = WindowsDAOFactory.getConnection(); + String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WINDOWS_FEATURE"; + stmt = conn.prepareStatement(sql); + rs = stmt.executeQuery(); + MobileFeature mobileFeature = null; + + while (rs.next()) { + mobileFeature = new MobileFeature(); + mobileFeature.setId(rs.getInt(WindowsPluginConstants.WINDOWS_FEATURE_ID)); + mobileFeature.setCode(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_CODE)); + mobileFeature.setName(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_NAME)); + mobileFeature.setDescription(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_DESCRIPTION)); + mobileFeature.setDeviceType( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + features.add(mobileFeature); + } + return features; + } catch (SQLException e) { + throw new WindowsFeatureManagementDAOException("Error occurred while retrieving all " + + "windows features from the Windows database.", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); + WindowsDAOFactory.closeConnection(); + } + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java index 50f8f15c3b..53515ccf05 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java @@ -38,4 +38,11 @@ public class WindowsPluginConstants { public static final String MAC_ADDRESS = "MAC_ADDRESS"; public static final String DEVICE_NAME = "DEVICE_NAME"; + //Properties related to AD_FEATURE table + public static final String WINDOWS_FEATURE_ID = "FEATURE_ID"; + public static final String WINDOWS_FEATURE_CODE = "CODE"; + public static final String WINDOWS_FEATURE_NAME = "NAME"; + public static final String WINDOWS_FEATURE_DESCRIPTION = "DESCRIPTION"; + + } From 1abb674b7ef2f289dfa953901397e122fc9dff36 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 23 Oct 2015 14:49:01 +0530 Subject: [PATCH 02/22] refactored WindowsFeatureImpl --- .../mgt/mobile/impl/windows/dao/WindowsDAOFactory.java | 3 ++- .../impl/windows/dao/impl/WindowsFeatureDAOImpl.java | 8 ++++---- .../src/main/resources/dbscripts/plugins/h2_windows.sql | 5 ++++- pom.xml | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java index 3c1ba0424b..170023c693 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.mobile.dao.*; import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsDeviceDAOImpl; +import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsFeatureDAOImpl; import javax.sql.DataSource; import java.sql.Connection; @@ -61,7 +62,7 @@ public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory @Override public MobileFeatureDAO getMobileFeatureDao() { - return null; + return new WindowsFeatureDAOImpl(); } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java index e69e209974..a8c1109425 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java @@ -187,7 +187,7 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; - Connection conn = null; + Connection conn; try { conn = WindowsDAOFactory.getConnection(); @@ -226,15 +226,15 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { public List getAllFeatures() throws MobileDeviceManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; - Connection conn = null; - List features = new ArrayList(); + Connection conn; + List features = new ArrayList<>(); try { conn = WindowsDAOFactory.getConnection(); String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WINDOWS_FEATURE"; stmt = conn.prepareStatement(sql); rs = stmt.executeQuery(); - MobileFeature mobileFeature = null; + MobileFeature mobileFeature; while (rs.next()) { mobileFeature = new MobileFeature(); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_windows.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_windows.sql index 638f3bf67c..041cffa7f2 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_windows.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_windows.sql @@ -40,6 +40,9 @@ VALUES 
('INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App'), 
 ('REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App'), 
('DEVICE_LOCK', 'Device Lock', 'Device Lock'), +('DEVICE_RING', 'Ring', 'Ring the device'), +('DISENROLL', 'DisEnroll', 'DisEnroll the device'), +('LOCKRESET', 'LockReset', 'Lock Reset device'), 
('CELLULAR', 'Cellular', 'Cellular'), 
('APN', 'APN', 'APN'), 
('RESTRICTION', 'Restrictions', 'Restrictions operation'), @@ -61,5 +64,5 @@ VALUES ('VPN', 'VPN', 'VPN operation'), ('PER_APP_VPN', 'Per App VPN', 'Per app VPN operation'), ('APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation'), -('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Enterprise wipe operation'), +('WIPE_DATA', 'Enterprise Wipe', 'Enterprise wipe operation'), ('APP_LOCK', 'App lock', 'App lock operation'); diff --git a/pom.xml b/pom.xml index 03f61fdd7a..dd2b325c1c 100644 --- a/pom.xml +++ b/pom.xml @@ -522,7 +522,7 @@ - 4.4.1 + 4.4.2 [4.4.0, 4.5.0) 1.5.4 From 297c7d1e9633c036ea61b8a5d8e7c19bd1dd93cf Mon Sep 17 00:00:00 2001 From: Dileesha Rajapakse Date: Mon, 26 Oct 2015 17:55:50 +0530 Subject: [PATCH 03/22] Added android sql scripts --- .../dbscripts/plugins/mssql_android.sql | 53 ++++++++++++ .../dbscripts/plugins/mysql_android.sql | 41 +++++++-- .../resources/dbscripts/plugins/mysql_ios.sql | 35 +++++++- .../dbscripts/plugins/mysql_windows.sql | 86 +++++++++++-------- .../dbscripts/plugins/oracle_android.sql | 63 ++++++++++++++ 5 files changed, 234 insertions(+), 44 deletions(-) create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mssql_android.sql create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/oracle_android.sql diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mssql_android.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mssql_android.sql new file mode 100644 index 0000000000..3309b033a3 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mssql_android.sql @@ -0,0 +1,53 @@ +-- ----------------------------------------------------- +-- Table `AD_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE AD_DEVICE ( + [ANDROID_DEVICE_ID] VARCHAR(45) NOT NULL, + [GCM_TOKEN] VARCHAR(45) NULL DEFAULT NULL, + [DEVICE_INFO] VARCHAR(8000) 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, + [SERIAL] VARCHAR(45) NULL DEFAULT NULL, + [MAC_ADDRESS] VARCHAR(45) NULL DEFAULT NULL, + [DEVICE_NAME] VARCHAR(100) NULL DEFAULT NULL, + PRIMARY KEY ([ANDROID_DEVICE_ID])); + +-- ----------------------------------------------------- +-- Table `AD_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE AD_FEATURE ( + [ID] INT NOT NULL IDENTITY, + [CODE] VARCHAR(45) NOT NULL, + [NAME] VARCHAR(100) NULL, + [DESCRIPTION] VARCHAR(200) NULL, + PRIMARY KEY ([ID])); + +-- ----------------------------------------------------- +-- TODO remove this later +-- ----------------------------------------------------- +INSERT INTO AD_FEATURE (CODE, NAME, DESCRIPTION) +VALUES +('DEVICE_LOCK', 'Device Lock', 'Lock the device'), +('DEVICE_LOCATION', 'Location', 'Request coordinates of device location'), +('WIFI', 'Wifi', 'Setting up wifi configuration'), +('CAMERA', 'Camera', 'Enable or disable camera'), +('EMAIL', 'Email', 'Configure email settings'), +('DEVICE_MUTE', 'Mute', 'Enable mute in the device'), +('DEVICE_INFO', 'Device Info', 'Request device information'), +('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Remove enterprise applications'), +('CLEAR_PASSWORD', 'Clear Password', 'Clear current password'), +('WIPE_DATA', 'Wipe Data', 'Factory reset the device'), +('APPLICATION_LIST', 'Application List', 'Request list of current installed applications'), +('CHANGE_LOCK_CODE', 'Change Lock-code', 'Change current lock code'), +('INSTALL_APPLICATION', 'Install App', 'Install Enterprise or Market application'), +('UNINSTALL_APPLICATION', 'Uninstall App', 'Uninstall application'), +('BLACKLIST_APPLICATIONS', 'Blacklist app', 'Blacklist applications'), +('ENCRYPT_STORAGE', 'Encrypt storage', 'Encrypt storage'), +('DEVICE_RING', 'Ring', 'Ring the device'), +('PASSCODE_POLICY', 'Password Policy', 'Set passcode policy'), +('NOTIFICATION', 'Message', 'Send message'); \ 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 2c5ed863ce..7161791dd3 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,10 +1,10 @@ -- ----------------------------------------------------- --- Table `MBL_DEVICE` +-- Table `AD_DEVICE` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( - `ANDROID_DEVICE_ID` VARCHAR(45) NOT NULL , - `DEVICE_INFO` VARCHAR(500) NULL DEFAULT NULL, +CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( + `ANDROID_DEVICE_ID` VARCHAR(45) NOT NULL, `GCM_TOKEN` VARCHAR(45) NULL DEFAULT NULL, + `DEVICE_INFO` VARCHAR(8000) NULL DEFAULT NULL, `IMEI` VARCHAR(45) NULL DEFAULT NULL, `IMSI` VARCHAR(45) NULL DEFAULT NULL, `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL, @@ -16,11 +16,10 @@ CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, PRIMARY KEY (`ANDROID_DEVICE_ID`)) -ENGINE = InnoDB; - + ENGINE = InnoDB; -- ----------------------------------------------------- --- Table `MBL_FEATURE` +-- Table `AD_FEATURE` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `AD_FEATURE` ( `ID` INT NOT NULL AUTO_INCREMENT, @@ -28,5 +27,31 @@ CREATE TABLE IF NOT EXISTS `AD_FEATURE` ( `NAME` VARCHAR(100) NULL, `DESCRIPTION` VARCHAR(200) NULL, PRIMARY KEY (`ID`)) -ENGINE = InnoDB; + ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- TODO remove this later +-- ----------------------------------------------------- +INSERT INTO AD_FEATURE (CODE, NAME, DESCRIPTION) +VALUES +('DEVICE_LOCK', 'Device Lock', 'Lock the device'), +('DEVICE_LOCATION', 'Location', 'Request coordinates of device location'), +('WIFI', 'Wifi', 'Setting up wifi configuration'), +('CAMERA', 'Camera', 'Enable or disable camera'), +('EMAIL', 'Email', 'Configure email settings'), +('DEVICE_MUTE', 'Mute', 'Enable mute in the device'), +('DEVICE_INFO', 'Device Info', 'Request device information'), +('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Remove enterprise applications'), +('CLEAR_PASSWORD', 'Clear Password', 'Clear current password'), +('WIPE_DATA', 'Wipe Data', 'Factory reset the device'), +('APPLICATION_LIST', 'Application List', 'Request list of current installed applications'), +('CHANGE_LOCK_CODE', 'Change Lock-code', 'Change current lock code'), +('INSTALL_APPLICATION', 'Install App', 'Install Enterprise or Market application'), +('UNINSTALL_APPLICATION', 'Uninstall App', 'Uninstall application'), +('BLACKLIST_APPLICATIONS', 'Blacklist app', 'Blacklist applications'), +('ENCRYPT_STORAGE', 'Encrypt storage', 'Encrypt storage'), +('DEVICE_RING', 'Ring', 'Ring the device'), +('PASSCODE_POLICY', 'Password Policy', 'Set passcode policy'), +('NOTIFICATION', 'Message', 'Send message'); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_ios.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_ios.sql index 1b90f68c69..a9fc3da003 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_ios.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_ios.sql @@ -35,4 +35,37 @@ CREATE TABLE IF NOT EXISTS `IOS_FEATURE` ( ENGINE = InnoDB; -long +-- ----------------------------------------------------- +-- TODO remove this later +-- ----------------------------------------------------- + +INSERT INTO IOS_FEATURE (CODE, NAME, DESCRIPTION) +VALUES +('INSTALL_ENTERPRISE_APPLICATION', 'Install Enterprise App', 'Install Enterprise App'), +
('INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App'), 
 +('REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App'), +
('DEVICE_LOCK', 'Device Lock', 'Device Lock'), +
('CELLULAR', 'Cellular', 'Cellular'), +
('APN', 'APN', 'APN'), +
('RESTRICTION', 'Restrictions', 'Restrictions operation'), +
('WIFI', 'Wifi', 'Wifi'), +
('DEVICE_INFO', 'Device Info', 'Device info operation'), 
 +('AIR_PLAY', 'Air Play', 'AirPlay operation'), 
 +('LOCATION', 'Location', 'Fetch location'), 
 +('ALARM', 'Alarm', 'Alarm device'), +('APPLICATION_LIST', 'Application list', 'Application list'), +('PROFILE_LIST', 'Profile List', 'Profile list'), +('REMOVE_PROFILE', 'Remove Profile', 'Remove profile'), +('CLEAR_PASSCODE', 'Clear Passcode', 'Clear passcode'), +('CALDAV', 'CalDev', 'Setup CalDav'), +('CALENDAR_SUBSCRIPTION', 'Calendar Subscriptions', 'Calendar subscription'), +('PASSCODE_POLICY', 'Passcode Policy', 'Passcode policy'), +('EMAIL', 'Email', 'Email operation'), +('LDAP', 'LDAP', 'LDAP operation'), +('WEB_CLIP', 'Web Clip', 'Web clip operation'), +('VPN', 'VPN', 'VPN operation'), +('PER_APP_VPN', 'Per App VPN', 'Per app VPN operation'), +('APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation'), +('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Enterprise wipe operation'), +('APP_LOCK', 'App lock', 'App lock operation'), +('GET_RESTRICTIONS', 'Get restrictions', 'Get restrictions operation'); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_windows.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_windows.sql index dfabdc0090..0605ec433a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_windows.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_windows.sql @@ -1,9 +1,24 @@ -- ----------------------------------------------------- --- Table `MBL_DEVICE` +-- Table `WINDOWS_FEATURE` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `MBL_DEVICE` ( +CREATE TABLE IF NOT EXISTS `WINDOWS_FEATURE` ( + `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, + `CODE` VARCHAR(45) NOT NULL, + `NAME` VARCHAR(100) NULL, + `DESCRIPTION` VARCHAR(200) NULL, + PRIMARY KEY (`FEATURE_ID`)) + ENGINE = InnoDB; + + + +-- ----------------------------------------------------- +-- Table `WINDOWS_DEVICE` +-- ----------------------------------------------------- + + CREATE TABLE IF NOT EXISTS `WINDOWS_DEVICE` ( `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, - `PUSH_TOKEN` VARCHAR(45) NULL DEFAULT NULL, + `CHANNEL_URI` VARCHAR(100) NULL DEFAULT NULL, + `DEVICE_INFO` VARCHAR(8000) NULL DEFAULT NULL, `IMEI` VARCHAR(45) NULL DEFAULT NULL, `IMSI` VARCHAR(45) NULL DEFAULT NULL, `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL, @@ -11,42 +26,43 @@ CREATE TABLE IF NOT EXISTS `MBL_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(50) NULL DEFAULT NULL, - `UNLOCK_TOKEN` VARCHAR(2000) NULL DEFAULT NULL, `SERIAL` VARCHAR(45) NULL DEFAULT NULL, + `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, + `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, PRIMARY KEY (`MOBILE_DEVICE_ID`)) -ENGINE = InnoDB; + 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`)) -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 +-- TODO remove this later -- ----------------------------------------------------- -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'); +INSERT INTO WINDOWS_FEATURE (CODE, NAME, DESCRIPTION) +VALUES +('INSTALL_ENTERPRISE_APPLICATION', 'Install Enterprise App', 'Install Enterprise App'), +
('INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App'), 
 +('REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App'), +
('DEVICE_LOCK', 'Device Lock', 'Device Lock'), +
('CELLULAR', 'Cellular', 'Cellular'), +
('APN', 'APN', 'APN'), +
('RESTRICTION', 'Restrictions', 'Restrictions operation'), +
('WIFI', 'Wifi', 'Wifi'), +
('DEVICE_INFO', 'Device Info', 'Device info operation'), 
 +('AIR_PLAY', 'Air Play', 'AirPlay operation'), 
 +('LOCATION', 'Location', 'Fetch location'), 
 +('ALARM', 'Alarm', 'Alarm device'), +('APPLICATION_LIST', 'Application list', 'Application list'), +('PROFILE_LIST', 'Profile List', 'Profile list'), +('REMOVE_PROFILE', 'Remove Profile', 'Remove profile'), +('CLEAR_PASSCODE', 'Clear Passcode', 'Clear passcode'), +('CALDAV', 'CalDev', 'Setup CalDav'), +('CALENDAR_SUBSCRIPTION', 'Calendar Subscriptions', 'Calendar subscription'), +('PASSCODE_POLICY', 'Passcode Policy', 'Passcode policy'), +('EMAIL', 'Email', 'Email operation'), +('LDAP', 'LDAP', 'LDAP operation'), +('WEB_CLIP', 'Web Clip', 'Web clip operation'), +('VPN', 'VPN', 'VPN operation'), +('PER_APP_VPN', 'Per App VPN', 'Per app VPN operation'), +('APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation'), +('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Enterprise wipe operation'), +('APP_LOCK', 'App lock', 'App lock operation'); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/oracle_android.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/oracle_android.sql new file mode 100644 index 0000000000..57c71b1af5 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/oracle_android.sql @@ -0,0 +1,63 @@ +-- ----------------------------------------------------- +-- Table `AD_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE AD_DEVICE ( + ANDROID_DEVICE_ID VARCHAR2(45) NOT NULL, + GCM_TOKEN VARCHAR2(45) DEFAULT NULL NULL, + DEVICE_INFO VARCHAR2(8000) DEFAULT NULL NULL, + IMEI VARCHAR2(45) DEFAULT NULL NULL, + IMSI VARCHAR2(45) DEFAULT NULL NULL, + OS_VERSION VARCHAR2(45) DEFAULT NULL NULL, + DEVICE_MODEL VARCHAR2(45) DEFAULT NULL NULL, + VENDOR VARCHAR2(45) DEFAULT NULL NULL, + LATITUDE VARCHAR2(45) DEFAULT NULL NULL, + LONGITUDE VARCHAR2(45) DEFAULT NULL NULL, + SERIAL VARCHAR2(45) DEFAULT NULL NULL, + MAC_ADDRESS VARCHAR2(45) DEFAULT NULL NULL, + DEVICE_NAME VARCHAR2(100) DEFAULT NULL NULL, + PRIMARY KEY (ANDROID_DEVICE_ID)); + +-- ----------------------------------------------------- +-- Table `AD_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE AD_FEATURE ( + ID NUMBER(10) NOT NULL, + CODE VARCHAR2(45) NOT NULL, + NAME VARCHAR2(100) NULL, + DESCRIPTION VARCHAR2(200) NULL, + PRIMARY KEY (ID)); + +-- Generate ID using sequence and trigger +CREATE SEQUENCE AD_FEATURE_seq START WITH 1 INCREMENT BY 1; + +CREATE OR REPLACE TRIGGER AD_FEATURE_seq_tr + BEFORE INSERT ON AD_FEATURE FOR EACH ROW + WHEN (NEW.ID IS NULL) +BEGIN + SELECT AD_FEATURE_seq.NEXTVAL INTO :NEW.ID FROM DUAL; +END; +/ + +-- ----------------------------------------------------- +-- TODO remove this later +-- ----------------------------------------------------- +INSERT INTO AD_FEATURE (CODE, NAME, DESCRIPTION) + SELECT 'DEVICE_LOCK', 'Device Lock', 'Lock the device' FROM dual UNION ALL + SELECT 'DEVICE_LOCATION', 'Location', 'Request coordinates of device location' FROM dual UNION ALL + SELECT 'WIFI', 'Wifi', 'Setting up wifi configuration' FROM dual UNION ALL + SELECT 'CAMERA', 'Camera', 'Enable or disable camera' FROM dual UNION ALL + SELECT 'EMAIL', 'Email', 'Configure email settings' FROM dual UNION ALL + SELECT 'DEVICE_MUTE', 'Mute', 'Enable mute in the device' FROM dual UNION ALL + SELECT 'DEVICE_INFO', 'Device Info', 'Request device information' FROM dual UNION ALL + SELECT 'ENTERPRISE_WIPE', 'Enterprise Wipe', 'Remove enterprise applications' FROM dual UNION ALL + SELECT 'CLEAR_PASSWORD', 'Clear Password', 'Clear current password' FROM dual UNION ALL + SELECT 'WIPE_DATA', 'Wipe Data', 'Factory reset the device' FROM dual UNION ALL + SELECT 'APPLICATION_LIST', 'Application List', 'Request list of current installed applications' FROM dual UNION ALL + SELECT 'CHANGE_LOCK_CODE', 'Change Lock-code', 'Change current lock code' FROM dual UNION ALL + SELECT 'INSTALL_APPLICATION', 'Install App', 'Install Enterprise or Market application' FROM dual UNION ALL + SELECT 'UNINSTALL_APPLICATION', 'Uninstall App', 'Uninstall application' FROM dual UNION ALL + SELECT 'BLACKLIST_APPLICATIONS', 'Blacklist app', 'Blacklist applications' FROM dual UNION ALL + SELECT 'ENCRYPT_STORAGE', 'Encrypt storage', 'Encrypt storage' FROM dual UNION ALL + SELECT 'DEVICE_RING', 'Ring', 'Ring the device' FROM dual UNION ALL + SELECT 'PASSCODE_POLICY', 'Password Policy', 'Set passcode policy' FROM dual UNION ALL + SELECT 'NOTIFICATION', 'Message', 'Send message' FROM dual; From c2bd221f6484090a9aff1832753d7c75bae77510 Mon Sep 17 00:00:00 2001 From: Dileesha Rajapakse Date: Wed, 28 Oct 2015 11:00:37 +0530 Subject: [PATCH 04/22] Added missing sql DB Scripts --- .../resources/dbscripts/plugins/mssql_ios.sql | 69 ++++++++++++++++ .../dbscripts/plugins/mssql_windows.sql | 61 ++++++++++++++ .../resources/dbscripts/plugins/mysql_ios.sql | 60 +++++++------- .../dbscripts/plugins/mysql_windows.sql | 57 +++++++------ .../dbscripts/plugins/oracle_ios.sql | 80 +++++++++++++++++++ .../dbscripts/plugins/oracle_windows.sql | 72 +++++++++++++++++ 6 files changed, 339 insertions(+), 60 deletions(-) create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mssql_ios.sql create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mssql_windows.sql create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/oracle_ios.sql create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/oracle_windows.sql diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mssql_ios.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mssql_ios.sql new file mode 100644 index 0000000000..871c996eba --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mssql_ios.sql @@ -0,0 +1,69 @@ +-- ----------------------------------------------------- +-- Table `IOS_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE IOS_FEATURE ( + [FEATURE_ID] INT NOT NULL IDENTITY, + [CODE] VARCHAR(45) NOT NULL, + [NAME] VARCHAR(100) NULL, + [DESCRIPTION] VARCHAR(200) NULL, + PRIMARY KEY ([FEATURE_ID]) ) + ; + + +-- ----------------------------------------------------- +-- Table `IOS_DEVICE` +-- ----------------------------------------------------- + CREATE TABLE IOS_DEVICE ( + [MOBILE_DEVICE_ID] VARCHAR(45) NOT NULL, + [APNS_PUSH_TOKEN] VARCHAR(100) NULL DEFAULT NULL, + [MAGIC_TOKEN] VARCHAR(100) NULL DEFAULT NULL, + [MDM_TOKEN] VARCHAR(100) NULL DEFAULT NULL, + [UNLOCK_TOKEN] VARCHAR(2000) NULL DEFAULT NULL, + [CHALLENGE_TOKEN] VARCHAR(45) NULL DEFAULT NULL, + [DEVICE_INFO] VARCHAR(8000) NULL DEFAULT NULL, + [SERIAL] VARCHAR(45) NULL DEFAULT NULL, + [PRODUCT] VARCHAR(45) NULL DEFAULT NULL, + [IMEI] VARCHAR(45) NULL DEFAULT NULL, + [VERSION] VARCHAR(45) NULL DEFAULT NULL, + [MAC_ADDRESS] VARCHAR(45) NULL DEFAULT NULL, + [DEVICE_NAME] VARCHAR(100) NULL DEFAULT NULL, + [ICCID] VARCHAR(45) NULL DEFAULT NULL, + [LATITUDE] VARCHAR(45) NULL DEFAULT NULL, + [LONGITUDE] VARCHAR(45) NULL DEFAULT NULL, + PRIMARY KEY ([MOBILE_DEVICE_ID]) ) + ; + + +-- ----------------------------------------------------- +-- TODO remove this later +-- ----------------------------------------------------- + +INSERT INTO IOS_FEATURE (CODE, NAME, DESCRIPTION) VALUES + ('INSTALL_ENTERPRISE_APPLICATION', 'Install Enterprise App', 'Install Enterprise App'), + ('INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App'), + ('REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App'), + ('DEVICE_LOCK', 'Device Lock', 'Device Lock'), + ('CELLULAR', 'Cellular', 'Cellular'), + ('APN', 'APN', 'APN'), + ('RESTRICTION', 'Restrictions', 'Restrictions operation'), + ('WIFI', 'Wifi', 'Wifi'), + ('DEVICE_INFO', 'Device Info', 'Device info operation'), + ('AIR_PLAY', 'Air Play', 'AirPlay operation'), + ('LOCATION', 'Location', 'Fetch location'), + ('ALARM', 'Alarm', 'Alarm device'), + ('APPLICATION_LIST', 'Application list', 'Application list'), + ('PROFILE_LIST', 'Profile List', 'Profile list'), + ('REMOVE_PROFILE', 'Remove Profile', 'Remove profile'), + ('CLEAR_PASSCODE', 'Clear Passcode', 'Clear passcode'), + ('CALDAV', 'CalDev', 'Setup CalDav'), + ('CALENDAR_SUBSCRIPTION', 'Calendar Subscriptions', 'Calendar subscription'), + ('PASSCODE_POLICY', 'Passcode Policy', 'Passcode policy'), + ('EMAIL', 'Email', 'Email operation'), + ('LDAP', 'LDAP', 'LDAP operation'), + ('WEB_CLIP', 'Web Clip', 'Web clip operation'), + ('VPN', 'VPN', 'VPN operation'), + ('PER_APP_VPN', 'Per App VPN', 'Per app VPN operation'), + ('APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation'), + ('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Enterprise wipe operation'), + ('APP_LOCK', 'App lock', 'App lock operation'), + ('GET_RESTRICTIONS', 'Get restrictions', 'Get restrictions operation'); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mssql_windows.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mssql_windows.sql new file mode 100644 index 0000000000..6f42b553b1 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mssql_windows.sql @@ -0,0 +1,61 @@ +-- ----------------------------------------------------- +-- Table `WINDOWS_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE WINDOWS_FEATURE ( + [FEATURE_ID] INT NOT NULL IDENTITY, + [CODE] VARCHAR(45) NOT NULL, + [NAME] VARCHAR(100) NULL, + [DESCRIPTION] VARCHAR(200) NULL, + PRIMARY KEY ([FEATURE_ID])) + ; + + -- ----------------------------------------------------- +-- Table `WINDOWS_DEVICE` +-- ----------------------------------------------------- + CREATE TABLE WINDOWS_DEVICE ( + [MOBILE_DEVICE_ID] VARCHAR(45) NOT NULL, + [CHANNEL_URI] VARCHAR(100) NULL DEFAULT NULL, + [DEVICE_INFO] VARCHAR(8000) 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, + [SERIAL] VARCHAR(45) NULL DEFAULT NULL, + [MAC_ADDRESS] VARCHAR(45) NULL DEFAULT NULL, + [DEVICE_NAME] VARCHAR(100) NULL DEFAULT NULL, + PRIMARY KEY ([MOBILE_DEVICE_ID])); + +-- ----------------------------------------------------- +-- TODO remove this later +-- ----------------------------------------------------- +INSERT INTO WINDOWS_FEATURE (CODE, NAME, DESCRIPTION) VALUES +('INSTALL_ENTERPRISE_APPLICATION', 'Install Enterprise App', 'Install Enterprise App'), +
('INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App'), 
 +('REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App'), +
('DEVICE_LOCK', 'Device Lock', 'Device Lock'), +
('CELLULAR', 'Cellular', 'Cellular'), +
('APN', 'APN', 'APN'), +
('RESTRICTION', 'Restrictions', 'Restrictions operation'), +
('WIFI', 'Wifi', 'Wifi'), +
('DEVICE_INFO', 'Device Info', 'Device info operation'), 
 +('AIR_PLAY', 'Air Play', 'AirPlay operation'), 
 +('LOCATION', 'Location', 'Fetch location'), 
 +('ALARM', 'Alarm', 'Alarm device'), +('APPLICATION_LIST', 'Application list', 'Application list'), +('PROFILE_LIST', 'Profile List', 'Profile list'), +('REMOVE_PROFILE', 'Remove Profile', 'Remove profile'), +('CLEAR_PASSCODE', 'Clear Passcode', 'Clear passcode'), +('CALDAV', 'CalDev', 'Setup CalDav'), +('CALENDAR_SUBSCRIPTION', 'Calendar Subscriptions', 'Calendar subscription'), +('PASSCODE_POLICY', 'Passcode Policy', 'Passcode policy'), +('EMAIL', 'Email', 'Email operation'), +('LDAP', 'LDAP', 'LDAP operation'), +('WEB_CLIP', 'Web Clip', 'Web clip operation'), +('VPN', 'VPN', 'VPN operation'), +('PER_APP_VPN', 'Per App VPN', 'Per app VPN operation'), +('APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation'), +('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Enterprise wipe operation'), +('APP_LOCK', 'App lock', 'App lock operation'); \ 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_ios.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_ios.sql index a9fc3da003..58abd26276 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_ios.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_ios.sql @@ -13,7 +13,6 @@ CREATE TABLE IF NOT EXISTS `IOS_FEATURE` ( -- ----------------------------------------------------- -- Table `IOS_DEVICE` -- ----------------------------------------------------- - CREATE TABLE IF NOT EXISTS `IOS_DEVICE` ( `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, `APNS_PUSH_TOKEN` VARCHAR(100) NULL DEFAULT NULL, @@ -39,33 +38,32 @@ CREATE TABLE IF NOT EXISTS `IOS_FEATURE` ( -- TODO remove this later -- ----------------------------------------------------- -INSERT INTO IOS_FEATURE (CODE, NAME, DESCRIPTION) -VALUES -('INSTALL_ENTERPRISE_APPLICATION', 'Install Enterprise App', 'Install Enterprise App'), -
('INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App'), 
 -('REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App'), -
('DEVICE_LOCK', 'Device Lock', 'Device Lock'), -
('CELLULAR', 'Cellular', 'Cellular'), -
('APN', 'APN', 'APN'), -
('RESTRICTION', 'Restrictions', 'Restrictions operation'), -
('WIFI', 'Wifi', 'Wifi'), -
('DEVICE_INFO', 'Device Info', 'Device info operation'), 
 -('AIR_PLAY', 'Air Play', 'AirPlay operation'), 
 -('LOCATION', 'Location', 'Fetch location'), 
 -('ALARM', 'Alarm', 'Alarm device'), -('APPLICATION_LIST', 'Application list', 'Application list'), -('PROFILE_LIST', 'Profile List', 'Profile list'), -('REMOVE_PROFILE', 'Remove Profile', 'Remove profile'), -('CLEAR_PASSCODE', 'Clear Passcode', 'Clear passcode'), -('CALDAV', 'CalDev', 'Setup CalDav'), -('CALENDAR_SUBSCRIPTION', 'Calendar Subscriptions', 'Calendar subscription'), -('PASSCODE_POLICY', 'Passcode Policy', 'Passcode policy'), -('EMAIL', 'Email', 'Email operation'), -('LDAP', 'LDAP', 'LDAP operation'), -('WEB_CLIP', 'Web Clip', 'Web clip operation'), -('VPN', 'VPN', 'VPN operation'), -('PER_APP_VPN', 'Per App VPN', 'Per app VPN operation'), -('APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation'), -('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Enterprise wipe operation'), -('APP_LOCK', 'App lock', 'App lock operation'), -('GET_RESTRICTIONS', 'Get restrictions', 'Get restrictions operation'); +INSERT INTO IOS_FEATURE (CODE, NAME, DESCRIPTION) VALUES + ('INSTALL_ENTERPRISE_APPLICATION', 'Install Enterprise App', 'Install Enterprise App'), + ('INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App'), + ('REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App'), + ('DEVICE_LOCK', 'Device Lock', 'Device Lock'), + ('CELLULAR', 'Cellular', 'Cellular'), + ('APN', 'APN', 'APN'), + ('RESTRICTION', 'Restrictions', 'Restrictions operation'), + ('WIFI', 'Wifi', 'Wifi'), + ('DEVICE_INFO', 'Device Info', 'Device info operation'), + ('AIR_PLAY', 'Air Play', 'AirPlay operation'), + ('LOCATION', 'Location', 'Fetch location'), + ('ALARM', 'Alarm', 'Alarm device'), + ('APPLICATION_LIST', 'Application list', 'Application list'), + ('PROFILE_LIST', 'Profile List', 'Profile list'), + ('REMOVE_PROFILE', 'Remove Profile', 'Remove profile'), + ('CLEAR_PASSCODE', 'Clear Passcode', 'Clear passcode'), + ('CALDAV', 'CalDev', 'Setup CalDav'), + ('CALENDAR_SUBSCRIPTION', 'Calendar Subscriptions', 'Calendar subscription'), + ('PASSCODE_POLICY', 'Passcode Policy', 'Passcode policy'), + ('EMAIL', 'Email', 'Email operation'), + ('LDAP', 'LDAP', 'LDAP operation'), + ('WEB_CLIP', 'Web Clip', 'Web clip operation'), + ('VPN', 'VPN', 'VPN operation'), + ('PER_APP_VPN', 'Per App VPN', 'Per app VPN operation'), + ('APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation'), + ('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Enterprise wipe operation'), + ('APP_LOCK', 'App lock', 'App lock operation'), + ('GET_RESTRICTIONS', 'Get restrictions', 'Get restrictions operation'); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_windows.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_windows.sql index 0605ec433a..061b7f5251 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_windows.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_windows.sql @@ -37,32 +37,31 @@ CREATE TABLE IF NOT EXISTS `WINDOWS_FEATURE` ( -- TODO remove this later -- ----------------------------------------------------- -INSERT INTO WINDOWS_FEATURE (CODE, NAME, DESCRIPTION) -VALUES -('INSTALL_ENTERPRISE_APPLICATION', 'Install Enterprise App', 'Install Enterprise App'), -
('INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App'), 
 -('REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App'), -
('DEVICE_LOCK', 'Device Lock', 'Device Lock'), -
('CELLULAR', 'Cellular', 'Cellular'), -
('APN', 'APN', 'APN'), -
('RESTRICTION', 'Restrictions', 'Restrictions operation'), -
('WIFI', 'Wifi', 'Wifi'), -
('DEVICE_INFO', 'Device Info', 'Device info operation'), 
 -('AIR_PLAY', 'Air Play', 'AirPlay operation'), 
 -('LOCATION', 'Location', 'Fetch location'), 
 -('ALARM', 'Alarm', 'Alarm device'), -('APPLICATION_LIST', 'Application list', 'Application list'), -('PROFILE_LIST', 'Profile List', 'Profile list'), -('REMOVE_PROFILE', 'Remove Profile', 'Remove profile'), -('CLEAR_PASSCODE', 'Clear Passcode', 'Clear passcode'), -('CALDAV', 'CalDev', 'Setup CalDav'), -('CALENDAR_SUBSCRIPTION', 'Calendar Subscriptions', 'Calendar subscription'), -('PASSCODE_POLICY', 'Passcode Policy', 'Passcode policy'), -('EMAIL', 'Email', 'Email operation'), -('LDAP', 'LDAP', 'LDAP operation'), -('WEB_CLIP', 'Web Clip', 'Web clip operation'), -('VPN', 'VPN', 'VPN operation'), -('PER_APP_VPN', 'Per App VPN', 'Per app VPN operation'), -('APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation'), -('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Enterprise wipe operation'), -('APP_LOCK', 'App lock', 'App lock operation'); +INSERT INTO WINDOWS_FEATURE (CODE, NAME, DESCRIPTION) VALUES + ('INSTALL_ENTERPRISE_APPLICATION', 'Install Enterprise App', 'Install Enterprise App'), + ('INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App'), + ('REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App'), + ('DEVICE_LOCK', 'Device Lock', 'Device Lock'), + ('CELLULAR', 'Cellular', 'Cellular'), + ('APN', 'APN', 'APN'), + ('RESTRICTION', 'Restrictions', 'Restrictions operation'), + ('WIFI', 'Wifi', 'Wifi'), + ('DEVICE_INFO', 'Device Info', 'Device info operation'), + ('AIR_PLAY', 'Air Play', 'AirPlay operation'), + ('LOCATION', 'Location', 'Fetch location'), + ('ALARM', 'Alarm', 'Alarm device'), + ('APPLICATION_LIST', 'Application list', 'Application list'), + ('PROFILE_LIST', 'Profile List', 'Profile list'), + ('REMOVE_PROFILE', 'Remove Profile', 'Remove profile'), + ('CLEAR_PASSCODE', 'Clear Passcode', 'Clear passcode'), + ('CALDAV', 'CalDev', 'Setup CalDav'), + ('CALENDAR_SUBSCRIPTION', 'Calendar Subscriptions', 'Calendar subscription'), + ('PASSCODE_POLICY', 'Passcode Policy', 'Passcode policy'), + ('EMAIL', 'Email', 'Email operation'), + ('LDAP', 'LDAP', 'LDAP operation'), + ('WEB_CLIP', 'Web Clip', 'Web clip operation'), + ('VPN', 'VPN', 'VPN operation'), + ('PER_APP_VPN', 'Per App VPN', 'Per app VPN operation'), + ('APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation'), + ('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Enterprise wipe operation'), + ('APP_LOCK', 'App lock', 'App lock operation'); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/oracle_ios.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/oracle_ios.sql new file mode 100644 index 0000000000..1354bf577a --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/oracle_ios.sql @@ -0,0 +1,80 @@ +-- ----------------------------------------------------- +-- Table `IOS_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE IOS_FEATURE ( + FEATURE_ID NUMBER(10) NOT NULL, + CODE VARCHAR2(45) NOT NULL, + NAME VARCHAR2(100) NULL, + DESCRIPTION VARCHAR2(200) NULL, + PRIMARY KEY (FEATURE_ID) ) +; + +-- Generate ID using sequence and trigger +CREATE SEQUENCE IOS_FEATURE_seq START WITH 1 INCREMENT BY 1; + +CREATE OR REPLACE TRIGGER IOS_FEATURE_seq_tr +BEFORE INSERT ON IOS_FEATURE FOR EACH ROW +WHEN (NEW.FEATURE_ID IS NULL) + BEGIN + SELECT IOS_FEATURE_seq.NEXTVAL INTO :NEW.FEATURE_ID FROM DUAL; + END; +/ + + +-- ----------------------------------------------------- +-- Table `IOS_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE IOS_DEVICE ( + MOBILE_DEVICE_ID VARCHAR2(45) NOT NULL, + APNS_PUSH_TOKEN VARCHAR2(100) DEFAULT NULL NULL, + MAGIC_TOKEN VARCHAR2(100) DEFAULT NULL NULL, + MDM_TOKEN VARCHAR2(100) DEFAULT NULL NULL, + UNLOCK_TOKEN VARCHAR2(2000) DEFAULT NULL NULL, + CHALLENGE_TOKEN VARCHAR2(45) DEFAULT NULL NULL, + DEVICE_INFO VARCHAR2(8000) DEFAULT NULL NULL, + SERIAL VARCHAR2(45) DEFAULT NULL NULL, + PRODUCT VARCHAR2(45) DEFAULT NULL NULL, + IMEI VARCHAR2(45) DEFAULT NULL NULL, + VERSION VARCHAR2(45) DEFAULT NULL NULL, + MAC_ADDRESS VARCHAR2(45) DEFAULT NULL NULL, + DEVICE_NAME VARCHAR2(100) DEFAULT NULL NULL, + ICCID VARCHAR2(45) DEFAULT NULL NULL, + LATITUDE VARCHAR2(45) DEFAULT NULL NULL, + LONGITUDE VARCHAR2(45) DEFAULT NULL NULL, + PRIMARY KEY (MOBILE_DEVICE_ID) ) +; + + +-- ----------------------------------------------------- +-- TODO remove this later +-- ----------------------------------------------------- + +INSERT INTO IOS_FEATURE (CODE, NAME, DESCRIPTION) + SELECT 'INSTALL_ENTERPRISE_APPLICATION', 'Install Enterprise App', 'Install Enterprise App' FROM dual UNION ALL + SELECT 'INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App' FROM dual UNION ALL + SELECT 'REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App' FROM dual UNION ALL + SELECT 'DEVICE_LOCK', 'Device Lock', 'Device Lock' FROM dual UNION ALL + SELECT 'CELLULAR', 'Cellular', 'Cellular' FROM dual UNION ALL + SELECT 'APN', 'APN', 'APN' FROM dual UNION ALL + SELECT 'RESTRICTION', 'Restrictions', 'Restrictions operation' FROM dual UNION ALL + SELECT 'WIFI', 'Wifi', 'Wifi' FROM dual UNION ALL + SELECT 'DEVICE_INFO', 'Device Info', 'Device info operation' FROM dual UNION ALL + SELECT 'AIR_PLAY', 'Air Play', 'AirPlay operation' FROM dual UNION ALL + SELECT 'LOCATION', 'Location', 'Fetch location' FROM dual UNION ALL + SELECT 'ALARM', 'Alarm', 'Alarm device' FROM dual UNION ALL + SELECT 'APPLICATION_LIST', 'Application list', 'Application list' FROM dual UNION ALL + SELECT 'PROFILE_LIST', 'Profile List', 'Profile list' FROM dual UNION ALL + SELECT 'REMOVE_PROFILE', 'Remove Profile', 'Remove profile' FROM dual UNION ALL + SELECT 'CLEAR_PASSCODE', 'Clear Passcode', 'Clear passcode' FROM dual UNION ALL + SELECT 'CALDAV', 'CalDev', 'Setup CalDav' FROM dual UNION ALL + SELECT 'CALENDAR_SUBSCRIPTION', 'Calendar Subscriptions', 'Calendar subscription' FROM dual UNION ALL + SELECT 'PASSCODE_POLICY', 'Passcode Policy', 'Passcode policy' FROM dual UNION ALL + SELECT 'EMAIL', 'Email', 'Email operation' FROM dual UNION ALL + SELECT 'LDAP', 'LDAP', 'LDAP operation' FROM dual UNION ALL + SELECT 'WEB_CLIP', 'Web Clip', 'Web clip operation' FROM dual UNION ALL + SELECT 'VPN', 'VPN', 'VPN operation' FROM dual UNION ALL + SELECT 'PER_APP_VPN', 'Per App VPN', 'Per app VPN operation' FROM dual UNION ALL + SELECT 'APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation' FROM dual UNION ALL + SELECT 'ENTERPRISE_WIPE', 'Enterprise Wipe', 'Enterprise wipe operation' FROM dual UNION ALL + SELECT 'APP_LOCK', 'App lock', 'App lock operation' FROM dual UNION ALL + SELECT 'GET_RESTRICTIONS', 'Get restrictions', 'Get restrictions operation' FROM dual; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/oracle_windows.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/oracle_windows.sql new file mode 100644 index 0000000000..c14e58cee6 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/oracle_windows.sql @@ -0,0 +1,72 @@ +-- ----------------------------------------------------- +-- Table `WINDOWS_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE WINDOWS_FEATURE ( + FEATURE_ID NUMBER(10) NOT NULL, + CODE VARCHAR2(45) NOT NULL, + NAME VARCHAR2(100) NULL, + DESCRIPTION VARCHAR2(200) NULL, + PRIMARY KEY (FEATURE_ID)) + ; + +-- Generate ID using sequence and trigger +CREATE SEQUENCE WINDOWS_FEATURE_seq START WITH 1 INCREMENT BY 1; + +CREATE OR REPLACE TRIGGER WINDOWS_FEATURE_seq_tr + BEFORE INSERT ON WINDOWS_FEATURE FOR EACH ROW + WHEN (NEW.FEATURE_ID IS NULL) +BEGIN + SELECT WINDOWS_FEATURE_seq.NEXTVAL INTO :NEW.FEATURE_ID FROM DUAL; +END; +/ + +-- ----------------------------------------------------- +-- Table `WINDOWS_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE WINDOWS_DEVICE ( + MOBILE_DEVICE_ID VARCHAR2(45) NOT NULL, + CHANNEL_URI VARCHAR2(100) DEFAULT NULL NULL, + DEVICE_INFO VARCHAR2(8000) DEFAULT NULL NULL, + IMEI VARCHAR2(45) DEFAULT NULL NULL, + IMSI VARCHAR2(45) DEFAULT NULL NULL, + OS_VERSION VARCHAR2(45) DEFAULT NULL NULL, + DEVICE_MODEL VARCHAR2(45) DEFAULT NULL NULL, + VENDOR VARCHAR2(45) DEFAULT NULL NULL, + LATITUDE VARCHAR2(45) DEFAULT NULL NULL, + LONGITUDE VARCHAR2(45) DEFAULT NULL NULL, + SERIAL VARCHAR2(45) DEFAULT NULL NULL, + MAC_ADDRESS VARCHAR2(45) DEFAULT NULL NULL, + DEVICE_NAME VARCHAR2(100) DEFAULT NULL NULL, + PRIMARY KEY (MOBILE_DEVICE_ID)); + +-- ----------------------------------------------------- +-- TODO remove this later +-- ----------------------------------------------------- +INSERT INTO WINDOWS_FEATURE (CODE, NAME, DESCRIPTION) + SELECT 'INSTALL_ENTERPRISE_APPLICATION', 'Install Enterprise App', 'Install Enterprise App' FROM dual UNION ALL +
('INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App'), 
 +('REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App'), +
('DEVICE_LOCK', 'Device Lock', 'Device Lock'), +
('CELLULAR', 'Cellular', 'Cellular'), +
('APN', 'APN', 'APN'), +
('RESTRICTION', 'Restrictions', 'Restrictions operation'), +
('WIFI', 'Wifi', 'Wifi'), +
('DEVICE_INFO', 'Device Info', 'Device info operation'), 
 +('AIR_PLAY', 'Air Play', 'AirPlay operation'), 
 +('LOCATION', 'Location', 'Fetch location'), 
 +('ALARM', 'Alarm', 'Alarm device'), +('APPLICATION_LIST', 'Application list', 'Application list'), +('PROFILE_LIST', 'Profile List', 'Profile list'), +('REMOVE_PROFILE', 'Remove Profile', 'Remove profile'), +('CLEAR_PASSCODE', 'Clear Passcode', 'Clear passcode'), +('CALDAV', 'CalDev', 'Setup CalDav'), +('CALENDAR_SUBSCRIPTION', 'Calendar Subscriptions', 'Calendar subscription'), +('PASSCODE_POLICY', 'Passcode Policy', 'Passcode policy'), +('EMAIL', 'Email', 'Email operation'), +('LDAP', 'LDAP', 'LDAP operation'), +('WEB_CLIP', 'Web Clip', 'Web clip operation'), +('VPN', 'VPN', 'VPN operation'), +('PER_APP_VPN', 'Per App VPN', 'Per app VPN operation'), +('APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation'), +('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Enterprise wipe operation'), +('APP_LOCK', 'App lock', 'App lock operation'); \ No newline at end of file From b5548f5744feedc741ea0923f7c8fe36d3f5269c Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 28 Oct 2015 17:55:26 +0530 Subject: [PATCH 05/22] Adding postgreSQL and Oracle schemas for plugin specific datastores and refactoring existing schemas to be consistent across that of all available plugin types --- .../dao/impl/WindowsDeviceDAOImpl.java | 29 ++++---- .../windows/util/WindowsPluginConstants.java | 2 +- .../src/test/resources/sql/h2.sql | 6 +- .../dbscripts/plugins/android/h2.sql | 30 ++++++++ .../{mysql_android.sql => android/mysql.sql} | 4 +- .../dbscripts/plugins/android/oracle.sql | 49 +++++++++++++ .../dbscripts/plugins/android/postgres.sql | 30 ++++++++ .../dbscripts/plugins/h2_android.sql | 56 --------------- .../resources/dbscripts/plugins/h2_ios.sql | 69 ------------------- .../dbscripts/plugins/h2_windows.sql | 65 ----------------- .../resources/dbscripts/plugins/ios/h2.sql | 33 +++++++++ .../plugins/{mysql_ios.sql => ios/mysql.sql} | 33 ++++----- .../dbscripts/plugins/ios/oracle.sql | 51 ++++++++++++++ .../dbscripts/plugins/ios/postgres.sql | 33 +++++++++ .../dbscripts/plugins/mysql_windows.sql | 52 -------------- .../dbscripts/plugins/windows/h2.sql | 30 ++++++++ .../dbscripts/plugins/windows/mysql.sql | 48 +++++++++++++ .../dbscripts/plugins/windows/oracle.sql | 64 +++++++++++++++++ .../dbscripts/plugins/windows/postgres.sql | 45 ++++++++++++ 19 files changed, 447 insertions(+), 282 deletions(-) create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/h2.sql rename features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/{mysql_android.sql => android/mysql.sql} (96%) create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/oracle.sql create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/postgres.sql delete mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_android.sql delete mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_ios.sql delete mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_windows.sql create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql rename features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/{mysql_ios.sql => ios/mysql.sql} (84%) create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgres.sql delete mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_windows.sql create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/h2.sql create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mysql.sql create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/oracle.sql create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/postgres.sql diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java index 237f881687..d9902cb7b3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java @@ -15,7 +15,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl; import org.apache.commons.logging.Log; @@ -52,17 +51,17 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { try { conn = WindowsDAOFactory.getConnection(); String selectDBQuery = - "SELECT MOBILE_DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " + + "SELECT DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " + "OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS," + " OS_VERSION, DEVICE_NAME " + - "FROM WINDOWS_DEVICE WHERE MOBILE_DEVICE_ID = ?"; + "FROM WIN_DEVICE WHERE DEVICE_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, mblDeviceId); rs = stmt.executeQuery(); while (rs.next()) { mobileDevice = new MobileDevice(); - mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.MOBILE_DEVICE_ID)); + mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.DEVICE_ID)); mobileDevice.setImei(rs.getString(WindowsPluginConstants.IMEI)); mobileDevice.setImsi(rs.getString(WindowsPluginConstants.IMSI)); mobileDevice.setModel(rs.getString(WindowsPluginConstants.DEVICE_MODEL)); @@ -72,7 +71,7 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { mobileDevice.setSerial(rs.getString(WindowsPluginConstants.SERIAL)); mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE)); - Map propertyMap = new HashMap(); + Map propertyMap = new HashMap<>(); propertyMap.put(WindowsPluginConstants.CHANNEL_URI, rs.getString(WindowsPluginConstants.CHANNEL_URI)); propertyMap.put(WindowsPluginConstants.DEVICE_INFO, rs.getString(WindowsPluginConstants.DEVICE_INFO)); propertyMap.put(WindowsPluginConstants.MAC_ADDRESS, rs.getString(WindowsPluginConstants.MAC_ADDRESS)); @@ -99,7 +98,7 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { try { conn = WindowsDAOFactory.getConnection(); String createDBQuery = - "INSERT INTO WINDOWS_DEVICE(MOBILE_DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, " + + "INSERT INTO WIN_DEVICE(DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, " + "IMSI, OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, " + "MAC_ADDRESS, DEVICE_NAME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; @@ -139,14 +138,14 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { @Override public boolean updateMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException { boolean status = false; - Connection conn = null; + Connection conn; PreparedStatement stmt = null; try { conn = WindowsDAOFactory.getConnection(); String updateDBQuery = - "UPDATE WINDOWS_DEVICE SET CHANNEL_URI = ?, DEVICE_INFO = ?, IMEI = ?, IMSI = ?, " + + "UPDATE WIN_DEVICE SET CHANNEL_URI = ?, DEVICE_INFO = ?, IMEI = ?, IMSI = ?, " + "OS_VERSION = ?, DEVICE_MODEL = ?, VENDOR = ?, LATITUDE = ?, LONGITUDE = ?, " + - "SERIAL = ?, MAC_ADDRESS = ?, DEVICE_NAME = ? WHERE MOBILE_DEVICE_ID = ?"; + "SERIAL = ?, MAC_ADDRESS = ?, DEVICE_NAME = ? WHERE DEVICE_ID = ?"; stmt = conn.prepareStatement(updateDBQuery); @@ -188,7 +187,7 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { PreparedStatement stmt = null; try { conn = WindowsDAOFactory.getConnection(); - String deleteDBQuery = "DELETE FROM WINDOWS_DEVICE WHERE MOBILE_DEVICE_ID = ?"; + String deleteDBQuery = "DELETE FROM WIN_DEVICE WHERE DEVICE_ID = ?"; stmt = conn.prepareStatement(deleteDBQuery); stmt.setString(1, mblDeviceId); int rows = stmt.executeUpdate(); @@ -214,20 +213,20 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { PreparedStatement stmt = null; ResultSet rs = null; MobileDevice mobileDevice; - List mobileDevices = new ArrayList(); + List mobileDevices = new ArrayList<>(); try { conn = WindowsDAOFactory.getConnection(); String selectDBQuery = - "SELECT MOBILE_DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " + + "SELECT DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " + "OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS," + " OS_VERSION, DEVICE_NAME " + - "FROM WINDOWS_DEVICE"; + "FROM WIN_DEVICE"; stmt = conn.prepareStatement(selectDBQuery); rs = stmt.executeQuery(); while (rs.next()) { mobileDevice = new MobileDevice(); - mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.MOBILE_DEVICE_ID)); + mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.DEVICE_ID)); mobileDevice.setVendor(rs.getString(WindowsPluginConstants.IMEI)); mobileDevice.setLatitude(rs.getString(WindowsPluginConstants.IMSI)); mobileDevice.setLongitude(rs.getString(WindowsPluginConstants.OS_VERSION)); @@ -235,7 +234,7 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { mobileDevice.setImsi(rs.getString(WindowsPluginConstants.VENDOR)); mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE)); - Map propertyMap = new HashMap(); + Map propertyMap = new HashMap<>(); propertyMap.put(WindowsPluginConstants.CHANNEL_URI, rs.getString(WindowsPluginConstants.CHANNEL_URI)); propertyMap.put(WindowsPluginConstants.DEVICE_INFO, rs.getString(WindowsPluginConstants.DEVICE_INFO)); propertyMap.put(WindowsPluginConstants.DEVICE_NAME, rs.getString(WindowsPluginConstants.DEVICE_NAME)); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java index 50f8f15c3b..853e5d435d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java @@ -24,7 +24,7 @@ package org.wso2.carbon.device.mgt.mobile.impl.windows.util; public class WindowsPluginConstants { //properties related to database table WINDOWS_DEVICE - public static final String MOBILE_DEVICE_ID = "MOBILE_DEVICE_ID"; + public static final String DEVICE_ID = "DEVICE_ID"; public static final String CHANNEL_URI = "CHANNEL_URI"; public static final String DEVICE_INFO = "DEVICE_INFO"; public static final String IMEI = "IMEI"; 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 e10ec1da8d..58210317e2 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 @@ -3,7 +3,7 @@ -- Table `AD_DEVICE` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( - `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL , + `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 , @@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( `TOKEN` VARCHAR(500) NULL DEFAULT NULL, `UNLOCK_TOKEN` VARCHAR(500) NULL DEFAULT NULL, `SERIAL` VARCHAR(45) NULL DEFAULT NULL, - PRIMARY KEY (`MOBILE_DEVICE_ID`) ); + PRIMARY KEY (`DEVICE_ID`) ); -- ----------------------------------------------------- @@ -51,7 +51,7 @@ CREATE TABLE IF NOT EXISTS `AD_DEVICE_OPERATION_MAPPING` ( PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) , CONSTRAINT `fk_AD_DEVICE_OPERATION_AD_DEVICE` FOREIGN KEY (`DEVICE_ID` ) - REFERENCES `AD_DEVICE` (`MOBILE_DEVICE_ID` ) + REFERENCES `AD_DEVICE` (`DEVICE_ID` ) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_AD_DEVICE_OPERATION_AD_OPERATION1` diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/h2.sql new file mode 100644 index 0000000000..1f280205c4 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/h2.sql @@ -0,0 +1,30 @@ + +-- ----------------------------------------------------- +-- Table `AD_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( + `ANDROID_DEVICE_ID` VARCHAR(45) NOT NULL, + `GCM_TOKEN` VARCHAR(45) NULL DEFAULT NULL, + `DEVICE_INFO` VARCHAR(8000) 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, + `SERIAL` VARCHAR(45) NULL DEFAULT NULL, + `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, + `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, + PRIMARY KEY (`ANDROID_DEVICE_ID`)); + +-- ----------------------------------------------------- +-- Table `AD_FEATURE` +-- ----------------------------------------------------- +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`)); + 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/android/mysql.sql similarity index 96% rename from features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_android.sql rename to features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/mysql.sql index 2c5ed863ce..ce25caf6ed 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/android/mysql.sql @@ -1,5 +1,5 @@ -- ----------------------------------------------------- --- Table `MBL_DEVICE` +-- Table `AD_DEVICE` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( `ANDROID_DEVICE_ID` VARCHAR(45) NOT NULL , @@ -20,7 +20,7 @@ ENGINE = InnoDB; -- ----------------------------------------------------- --- Table `MBL_FEATURE` +-- Table `AD_FEATURE` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `AD_FEATURE` ( `ID` INT NOT NULL AUTO_INCREMENT, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/oracle.sql new file mode 100644 index 0000000000..b8a522b905 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/oracle.sql @@ -0,0 +1,49 @@ +-- ----------------------------------------------------- +-- Table `AD_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE AD_DEVICE ( + DEVICE_ID VARCHAR(45) NOT NULL , + DEVICE_INFO VARCHAR(500) DEFAULT NULL, + GCM_TOKEN VARCHAR(45) DEFAULT NULL, + IMEI VARCHAR(45) DEFAULT NULL, + IMSI VARCHAR(45) DEFAULT NULL, + OS_VERSION VARCHAR(45) DEFAULT NULL, + DEVICE_MODEL VARCHAR(45) DEFAULT NULL, + VENDOR VARCHAR(45) DEFAULT NULL, + LATITUDE VARCHAR(45) DEFAULT NULL, + LONGITUDE VARCHAR(45) DEFAULT NULL, + SERIAL VARCHAR(45) DEFAULT NULL, + MAC_ADDRESS VARCHAR(45) DEFAULT NULL, + DEVICE_NAME VARCHAR(100) DEFAULT NULL, + PRIMARY KEY (DEVICE_ID) +); +/ + +-- ----------------------------------------------------- +-- Table `AD_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE AD_FEATURE ( + ID INT NOT NULL, + CODE VARCHAR(45) NOT NULL, + NAME VARCHAR(100) NOT NULL, + DESCRIPTION VARCHAR(200) DEFAULT NULL, + PRIMARY KEY (ID) +); +/ + +-- ----------------------------------------------------- +-- Sequence `AD_FEATURE_ID_INC_SEQ` +-- ----------------------------------------------------- +CREATE SEQUENCE AD_FEATURE_ID_INC_SEQ START WITH 1 INCREMENT BY 1 NOCACHE; +/ + +-- ----------------------------------------------------- +-- Trigger `AD_FEATURE_ID_INC_TRIG` +-- ----------------------------------------------------- +CREATE OR REPLACE TRIGGER AD_FEATURE_ID_INC_TRIG +BEFORE INSERT ON AD_FEATURE +FOR EACH ROW +BEGIN + SELECT AD_FEATURE_ID_INC_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL; +END; +/ diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/postgres.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/postgres.sql new file mode 100644 index 0000000000..af5c9a5cf1 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/postgres.sql @@ -0,0 +1,30 @@ +-- ----------------------------------------------------- +-- Table AD_DEVICE +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS AD_DEVICE ( + ID VARCHAR(45) NOT NULL , + DEVICE_INFO VARCHAR(500) NULL DEFAULT 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, + SERIAL VARCHAR(45) NULL DEFAULT NULL, + MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL, + DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL, + PRIMARY KEY (ID) + ); + +-- ----------------------------------------------------- +-- Table AD_FEATURE +-- ----------------------------------------------------- +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) +); 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 deleted file mode 100644 index 3cef91277e..0000000000 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_android.sql +++ /dev/null @@ -1,56 +0,0 @@ - --- ----------------------------------------------------- --- Table `AD_DEVICE` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( - `ANDROID_DEVICE_ID` VARCHAR(45) NOT NULL, - `GCM_TOKEN` VARCHAR(45) NULL DEFAULT NULL, - `DEVICE_INFO` VARCHAR(8000) 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, - `SERIAL` VARCHAR(45) NULL DEFAULT NULL, - `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, - `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, - PRIMARY KEY (`ANDROID_DEVICE_ID`)); - --- ----------------------------------------------------- --- Table `AD_FEATURE` --- ----------------------------------------------------- -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`)); - - --- ----------------------------------------------------- --- TODO remove this later --- ----------------------------------------------------- - -INSERT INTO AD_FEATURE (CODE, NAME, DESCRIPTION) -VALUES -('DEVICE_LOCK', 'Device Lock', 'Lock the device'), -('DEVICE_LOCATION', 'Location', 'Request coordinates of device location'), -('WIFI', 'Wifi', 'Setting up wifi configuration'), -('CAMERA', 'Camera', 'Enable or disable camera'), -('EMAIL', 'Email', 'Configure email settings'), -('DEVICE_MUTE', 'Mute', 'Enable mute in the device'), -('DEVICE_INFO', 'Device Info', 'Request device information'), -('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Remove enterprise applications'), -('CLEAR_PASSWORD', 'Clear Password', 'Clear current password'), -('WIPE_DATA', 'Wipe Data', 'Factory reset the device'), -('APPLICATION_LIST', 'Application List', 'Request list of current installed applications'), -('CHANGE_LOCK_CODE', 'Change Lock-code', 'Change current lock code'), -('INSTALL_APPLICATION', 'Install App', 'Install Enterprise or Market application'), -('UNINSTALL_APPLICATION', 'Uninstall App', 'Uninstall application'), -('BLACKLIST_APPLICATIONS', 'Blacklist app', 'Blacklist applications'), -('ENCRYPT_STORAGE', 'Encrypt storage', 'Encrypt storage'), -('DEVICE_RING', 'Ring', 'Ring the device'), -('PASSCODE_POLICY', 'Password Policy', 'Set passcode policy'), -('NOTIFICATION', 'Message', 'Send message'); 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 deleted file mode 100644 index 52f30b57ee..0000000000 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_ios.sql +++ /dev/null @@ -1,69 +0,0 @@ --- ----------------------------------------------------- --- Table `IOS_FEATURE` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `IOS_FEATURE` ( - `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, - `CODE` VARCHAR(45) NOT NULL, - `NAME` VARCHAR(100) NULL, - `DESCRIPTION` VARCHAR(200) NULL, - PRIMARY KEY (`FEATURE_ID`) ); - - --- ----------------------------------------------------- --- Table `IOS_DEVICE` --- ----------------------------------------------------- - - CREATE TABLE IF NOT EXISTS `IOS_DEVICE` ( - `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, - `APNS_PUSH_TOKEN` VARCHAR(100) DEFAULT NULL, - `MAGIC_TOKEN` VARCHAR(100) DEFAULT NULL, - `MDM_TOKEN` VARCHAR(100) DEFAULT NULL, - `UNLOCK_TOKEN` VARCHAR(2000) DEFAULT NULL, - `CHALLENGE_TOKEN` VARCHAR(45) DEFAULT NULL, - `DEVICE_INFO` VARCHAR(8000) DEFAULT NULL, - `SERIAL` VARCHAR(45) DEFAULT NULL, - `PRODUCT` VARCHAR(45) DEFAULT NULL, - `IMEI` VARCHAR(45) DEFAULT NULL, - `VERSION` VARCHAR(45) DEFAULT NULL, - `MAC_ADDRESS` VARCHAR(45) DEFAULT NULL, - `DEVICE_NAME` VARCHAR(100) DEFAULT NULL, - `ICCID` VARCHAR(45) DEFAULT NULL, - `LATITUDE` VARCHAR(45) DEFAULT NULL, - `LONGITUDE` VARCHAR(45) DEFAULT NULL, - PRIMARY KEY (`MOBILE_DEVICE_ID`) ); - - --- ----------------------------------------------------- --- TODO remove this later --- ----------------------------------------------------- - -INSERT INTO IOS_FEATURE (CODE, NAME, DESCRIPTION) -VALUES -('INSTALL_ENTERPRISE_APPLICATION', 'Install Enterprise App', 'Install Enterprise App'), -
('INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App'), 
 -('REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App'), -
('DEVICE_LOCK', 'Device Lock', 'Device Lock'), -
('CELLULAR', 'Cellular', 'Cellular'), -
('APN', 'APN', 'APN'), -
('RESTRICTION', 'Restrictions', 'Restrictions operation'), -
('WIFI', 'Wifi', 'Wifi'), -
('DEVICE_INFO', 'Device Info', 'Device info operation'), 
 -('AIR_PLAY', 'Air Play', 'AirPlay operation'), 
 -('LOCATION', 'Location', 'Fetch location'), 
 -('ALARM', 'Alarm', 'Alarm device'), -('APPLICATION_LIST', 'Application list', 'Application list'), -('PROFILE_LIST', 'Profile List', 'Profile list'), -('REMOVE_PROFILE', 'Remove Profile', 'Remove profile'), -('CLEAR_PASSCODE', 'Clear Passcode', 'Clear passcode'), -('CALDAV', 'CalDev', 'Setup CalDav'), -('CALENDAR_SUBSCRIPTION', 'Calendar Subscriptions', 'Calendar subscription'), -('PASSCODE_POLICY', 'Passcode Policy', 'Passcode policy'), -('EMAIL', 'Email', 'Email operation'), -('LDAP', 'LDAP', 'LDAP operation'), -('WEB_CLIP', 'Web Clip', 'Web clip operation'), -('VPN', 'VPN', 'VPN operation'), -('PER_APP_VPN', 'Per App VPN', 'Per app VPN operation'), -('APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation'), -('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Enterprise wipe operation'), -('APP_LOCK', 'App lock', 'App lock operation'), -('GET_RESTRICTIONS', 'Get restrictions', 'Get restrictions operation'); \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_windows.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_windows.sql deleted file mode 100644 index 638f3bf67c..0000000000 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_windows.sql +++ /dev/null @@ -1,65 +0,0 @@ --- ----------------------------------------------------- --- Table `WINDOWS_FEATURE` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `WINDOWS_FEATURE` ( - `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, - `CODE` VARCHAR(45) NOT NULL, - `NAME` VARCHAR(100) NULL, - `DESCRIPTION` VARCHAR(200) NULL, - PRIMARY KEY (`FEATURE_ID`)); - - --- ----------------------------------------------------- --- Table `WINDOWS_DEVICE` --- ----------------------------------------------------- - - CREATE TABLE IF NOT EXISTS `WINDOWS_DEVICE` ( - `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, - `CHANNEL_URI` VARCHAR(100) NULL DEFAULT NULL, - `DEVICE_INFO` VARCHAR(8000) 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, - `SERIAL` VARCHAR(45) NULL DEFAULT NULL, - `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, - `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, - PRIMARY KEY (`MOBILE_DEVICE_ID`) ); - - --- ----------------------------------------------------- --- TODO remove this later --- ----------------------------------------------------- - -INSERT INTO WINDOWS_FEATURE (CODE, NAME, DESCRIPTION) -VALUES -('INSTALL_ENTERPRISE_APPLICATION', 'Install Enterprise App', 'Install Enterprise App'), -
('INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App'), 
 -('REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App'), -
('DEVICE_LOCK', 'Device Lock', 'Device Lock'), -
('CELLULAR', 'Cellular', 'Cellular'), -
('APN', 'APN', 'APN'), -
('RESTRICTION', 'Restrictions', 'Restrictions operation'), -
('WIFI', 'Wifi', 'Wifi'), -
('DEVICE_INFO', 'Device Info', 'Device info operation'), 
 -('AIR_PLAY', 'Air Play', 'AirPlay operation'), 
 -('LOCATION', 'Location', 'Fetch location'), 
 -('ALARM', 'Alarm', 'Alarm device'), -('APPLICATION_LIST', 'Application list', 'Application list'), -('PROFILE_LIST', 'Profile List', 'Profile list'), -('REMOVE_PROFILE', 'Remove Profile', 'Remove profile'), -('CLEAR_PASSCODE', 'Clear Passcode', 'Clear passcode'), -('CALDAV', 'CalDev', 'Setup CalDav'), -('CALENDAR_SUBSCRIPTION', 'Calendar Subscriptions', 'Calendar subscription'), -('PASSCODE_POLICY', 'Passcode Policy', 'Passcode policy'), -('EMAIL', 'Email', 'Email operation'), -('LDAP', 'LDAP', 'LDAP operation'), -('WEB_CLIP', 'Web Clip', 'Web clip operation'), -('VPN', 'VPN', 'VPN operation'), -('PER_APP_VPN', 'Per App VPN', 'Per app VPN operation'), -('APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation'), -('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Enterprise wipe operation'), -('APP_LOCK', 'App lock', 'App lock operation'); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql new file mode 100644 index 0000000000..c9c70ce2da --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql @@ -0,0 +1,33 @@ +-- ----------------------------------------------------- +-- Table `IOS_DEVICE` +-- ----------------------------------------------------- + CREATE TABLE IF NOT EXISTS `IOS_DEVICE` ( + `DEVICE_ID` VARCHAR(45) NOT NULL, + `APNS_PUSH_TOKEN` VARCHAR(100) DEFAULT NULL, + `MAGIC_TOKEN` VARCHAR(100) DEFAULT NULL, + `MDM_TOKEN` VARCHAR(100) DEFAULT NULL, + `UNLOCK_TOKEN` VARCHAR(2000) DEFAULT NULL, + `CHALLENGE_TOKEN` VARCHAR(45) DEFAULT NULL, + `DEVICE_INFO` VARCHAR(8000) DEFAULT NULL, + `SERIAL` VARCHAR(45) DEFAULT NULL, + `PRODUCT` VARCHAR(45) DEFAULT NULL, + `IMEI` VARCHAR(45) DEFAULT NULL, + `VERSION` VARCHAR(45) DEFAULT NULL, + `MAC_ADDRESS` VARCHAR(45) DEFAULT NULL, + `DEVICE_NAME` VARCHAR(100) DEFAULT NULL, + `ICCID` VARCHAR(45) DEFAULT NULL, + `LATITUDE` VARCHAR(45) DEFAULT NULL, + `LONGITUDE` VARCHAR(45) DEFAULT NULL, + PRIMARY KEY (`DEVICE_ID`) +); + +-- ----------------------------------------------------- +-- Table `IOS_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `IOS_FEATURE` ( + `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, + `CODE` VARCHAR(45) NOT NULL, + `NAME` VARCHAR(100) NULL, + `DESCRIPTION` VARCHAR(200) NULL, + PRIMARY KEY (`FEATURE_ID`) +); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_ios.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mysql.sql similarity index 84% rename from features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_ios.sql rename to features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mysql.sql index 1b90f68c69..c71a332548 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_ios.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mysql.sql @@ -1,21 +1,8 @@ --- ----------------------------------------------------- --- Table `IOS_FEATURE` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `IOS_FEATURE` ( - `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, - `CODE` VARCHAR(45) NOT NULL, - `NAME` VARCHAR(100) NULL, - `DESCRIPTION` VARCHAR(200) NULL, - PRIMARY KEY (`FEATURE_ID`) ) - ENGINE = InnoDB; - - -- ----------------------------------------------------- -- Table `IOS_DEVICE` -- ----------------------------------------------------- - - CREATE TABLE IF NOT EXISTS `IOS_DEVICE` ( - `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, +CREATE TABLE IF NOT EXISTS `IOS_DEVICE` ( + `DEVICE_ID` VARCHAR(45) NOT NULL, `APNS_PUSH_TOKEN` VARCHAR(100) NULL DEFAULT NULL, `MAGIC_TOKEN` VARCHAR(100) NULL DEFAULT NULL, `MDM_TOKEN` VARCHAR(100) NULL DEFAULT NULL, @@ -31,8 +18,16 @@ 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`) ) - ENGINE = InnoDB; - + PRIMARY KEY (`DEVICE_ID`) +) ENGINE = InnoDB; -long +-- ----------------------------------------------------- +-- Table `IOS_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `IOS_FEATURE` ( + `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, + `CODE` VARCHAR(45) NOT NULL, + `NAME` VARCHAR(100) NULL, + `DESCRIPTION` VARCHAR(200) NULL, + PRIMARY KEY (`FEATURE_ID`) +) ENGINE = InnoDB; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql new file mode 100644 index 0000000000..11e5212e1c --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql @@ -0,0 +1,51 @@ +-- ----------------------------------------------------- +-- Table `IOS_DEVICE` +-- ----------------------------------------------------- + CREATE TABLE IOS_DEVICE ( + DEVICE_ID VARCHAR(45) NOT NULL, + APNS_PUSH_TOKEN VARCHAR(100) DEFAULT NULL, + MAGIC_TOKEN VARCHAR(100) DEFAULT NULL, + MDM_TOKEN VARCHAR(100) DEFAULT NULL, + UNLOCK_TOKEN VARCHAR(2000) DEFAULT NULL, + CHALLENGE_TOKEN VARCHAR(45) DEFAULT NULL, + DEVICE_INFO VARCHAR(8000) DEFAULT NULL, + SERIAL VARCHAR(45) DEFAULT NULL, + PRODUCT VARCHAR(45) DEFAULT NULL, + IMEI VARCHAR(45) DEFAULT NULL, + VERSION VARCHAR(45) DEFAULT NULL, + MAC_ADDRESS VARCHAR(45) DEFAULT NULL, + DEVICE_NAME VARCHAR(100) DEFAULT NULL, + ICCID VARCHAR(45) DEFAULT NULL, + LATITUDE VARCHAR(45) DEFAULT NULL, + LONGITUDE VARCHAR(45) DEFAULT NULL, + PRIMARY KEY (DEVICE_ID) +); +/ + +-- ----------------------------------------------------- +-- Table `IOS_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE IOS_FEATURE ( + ID INT NOT NULL, + CODE VARCHAR(45) NOT NULL, + NAME VARCHAR(100) NOT NULL, + DESCRIPTION VARCHAR(200) NULL, + PRIMARY KEY (ID) +); +/ + +-- Sequence `IOS_FEATURE_ID_INC_SEQ` +-- ----------------------------------------------------- +CREATE SEQUENCE IOS_FEATURE_ID_INC_SEQ START WITH 1 INCREMENT BY 1 NOCACHE; +/ + +-- ----------------------------------------------------- +-- Trigger `IOS_FEATURE_ID_INC_TRIG` +-- ----------------------------------------------------- +CREATE OR REPLACE TRIGGER IOS_FEATURE_ID_INC_TRIG +BEFORE INSERT ON IOS_FEATURE +FOR EACH ROW +BEGIN + SELECT IOS_FEATURE_ID_INC_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL; +END; +/ diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgres.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgres.sql new file mode 100644 index 0000000000..79b342ca3a --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgres.sql @@ -0,0 +1,33 @@ +-- ----------------------------------------------------- +-- Table IOS_FEATURE +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS IOS_FEATURE ( + ID SERIAL NOT NULL, + CODE VARCHAR(45) NOT NULL, + NAME VARCHAR(100) NULL, + DESCRIPTION VARCHAR(200) NULL, + PRIMARY KEY (ID) +); + +-- ----------------------------------------------------- +-- Table IOS_DEVICE +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS IOS_DEVICE ( + DEVICE_ID VARCHAR(45) NOT NULL, + APNS_PUSH_TOKEN VARCHAR(100) NULL DEFAULT NULL, + MAGIC_TOKEN VARCHAR(100) NULL DEFAULT NULL, + MDM_TOKEN VARCHAR(100) NULL DEFAULT NULL, + UNLOCK_TOKEN VARCHAR(2000) NULL DEFAULT NULL, + CHALLENGE_TOKEN VARCHAR(45) NULL DEFAULT NULL, + DEVICE_INFO VARCHAR(8000) NULL DEFAULT NULL, + SERIAL VARCHAR(45) NULL DEFAULT NULL, + PRODUCT VARCHAR(45) NULL DEFAULT NULL, + IMEI VARCHAR(45) NULL DEFAULT NULL, + VERSION VARCHAR(45) NULL DEFAULT NULL, + MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL, + DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL, + ICCID VARCHAR(45) NULL DEFAULT NULL, + LATITUDE VARCHAR(45) NULL DEFAULT NULL, + LONGITUDE VARCHAR(45) NULL DEFAULT NULL, + PRIMARY KEY (DEVICE_ID) + ); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_windows.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_windows.sql deleted file mode 100644 index dfabdc0090..0000000000 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/mysql_windows.sql +++ /dev/null @@ -1,52 +0,0 @@ --- ----------------------------------------------------- --- 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, - `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`)) -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`)) -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'); - diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/h2.sql new file mode 100644 index 0000000000..3954f3c5ea --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/h2.sql @@ -0,0 +1,30 @@ +-- ----------------------------------------------------- +-- Table `WIN_DEVICE` +-- ----------------------------------------------------- + CREATE TABLE IF NOT EXISTS `WIN_DEVICE` ( + `DEVICE_ID` VARCHAR(45) NOT NULL, + `CHANNEL_URI` VARCHAR(100) NULL DEFAULT NULL, + `DEVICE_INFO` VARCHAR(8000) 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, + `SERIAL` VARCHAR(45) NULL DEFAULT NULL, + `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, + `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, + PRIMARY KEY (`DEVICE_ID`) +); + +-- ----------------------------------------------------- +-- Table `WIN_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WIN_FEATURE` ( + `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, + `CODE` VARCHAR(45) NOT NULL, + `NAME` VARCHAR(100) NULL, + `DESCRIPTION` VARCHAR(200) NULL, + PRIMARY KEY (`FEATURE_ID`) +); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mysql.sql new file mode 100644 index 0000000000..ecdacf5b98 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mysql.sql @@ -0,0 +1,48 @@ +-- ----------------------------------------------------- +-- Table `WIN_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WIN_DEVICE` ( + `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, + `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 (`DEVICE_ID`)) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `WIN_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WIN_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`)) +ENGINE = InnoDB; + +-- ----------------------------------------------------- +-- Table `WIN_FEATURE_PROPERTY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WIN_FEATURE_PROPERTY` ( + `PROPERTY` VARCHAR(45) NOT NULL , + `FEATURE_ID` INT NOT NULL , + PRIMARY KEY (`PROPERTY`), + CONSTRAINT `fk_WIN_FEATURE_PROPERTY_WIN_FEATURE1` + FOREIGN KEY (`FEATURE_ID`) + REFERENCES `WIN_FEATURE` (`FEATURE_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/oracle.sql new file mode 100644 index 0000000000..505330b66c --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/oracle.sql @@ -0,0 +1,64 @@ +-- ----------------------------------------------------- +-- Table `WIN_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE WIN_DEVICE ( + DEVICE_ID VARCHAR(45) NOT NULL, + PUSH_TOKEN VARCHAR(45) DEFAULT NULL, + IMEI VARCHAR(45) DEFAULT NULL, + IMSI VARCHAR(45) DEFAULT NULL, + OS_VERSION VARCHAR(45) DEFAULT NULL, + DEVICE_MODEL VARCHAR(45) DEFAULT NULL, + VENDOR VARCHAR(45) DEFAULT NULL, + LATITUDE VARCHAR(45) DEFAULT NULL, + LONGITUDE VARCHAR(45) DEFAULT NULL, + CHALLENGE VARCHAR(45) DEFAULT NULL, + TOKEN VARCHAR(50) DEFAULT NULL, + UNLOCK_TOKEN VARCHAR(2000) DEFAULT NULL, + SERIAL VARCHAR(45) DEFAULT NULL, + PRIMARY KEY (DEVICE_ID) +); +/ + +-- ----------------------------------------------------- +-- Table `WIN_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE WIN_FEATURE ( + ID INT NOT NULL, + DEVICE_TYPE VARCHAR(45) NOT NULL, + CODE VARCHAR(45) NOT NULL, + NAME VARCHAR(100) NOT NULL, + DESCRIPTION VARCHAR(200) NULL, + PRIMARY KEY (ID) +); +/ + +-- ----------------------------------------------------- +-- Table `WIN_FEATURE_PROPERTY` +-- ----------------------------------------------------- +CREATE TABLE WIN_FEATURE_PROPERTY ( + PROPERTY VARCHAR(45) NOT NULL, + FEATURE_ID INT NOT NULL, + PRIMARY KEY (PROPERTY), + CONSTRAINT fk_WIN_FEATURE_PROPERTY_WIN_FEATURE1 + FOREIGN KEY (FEATURE_ID) + REFERENCES WIN_FEATURE (FEATURE_ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION); +/ + +-- ----------------------------------------------------- +-- Sequence `WIN_FEATURE_ID_INC_SEQ` +-- ----------------------------------------------------- +CREATE SEQUENCE WIN_FEATURE_ID_INC_SEQ START WITH 1 INCREMENT BY 1 NOCACHE; +/ + +-- ----------------------------------------------------- +-- Trigger `WIN_FEATURE_ID_INC_TRIG` +-- ----------------------------------------------------- +CREATE OR REPLACE TRIGGER WIN_FEATURE_ID_INC_TRIG +BEFORE INSERT ON WIN_FEATURE +FOR EACH ROW +BEGIN + SELECT WIN_FEATURE_ID_INC_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL; +END; +/ diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/postgres.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/postgres.sql new file mode 100644 index 0000000000..45754d06fc --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/postgres.sql @@ -0,0 +1,45 @@ +-- ----------------------------------------------------- +-- Table WIN_DEVICE +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS WIN_DEVICE ( + 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, + 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 (DEVICE_ID) + ); + +-- ----------------------------------------------------- +-- Table WIN_FEATURE +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS WIN_FEATURE ( + ID SERIAL NOT NULL, + DEVICE_TYPE VARCHAR(45) NOT NULL, + CODE VARCHAR(45) NULL, + NAME VARCHAR(100) NULL, + DESCRIPTION VARCHAR(200) NULL, + PRIMARY KEY (ID) + ); + +-- ----------------------------------------------------- +-- Table `WIN_FEATURE_PROPERTY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS WIN_FEATURE_PROPERTY ( + PROPERTY VARCHAR(45) NOT NULL , + FEATURE_ID INT NOT NULL , + PRIMARY KEY (PROPERTY), + CONSTRAINT fk_WIN_FEATURE_PROPERTY_WIN_FEATURE1 + FOREIGN KEY (FEATURE_ID) + REFERENCES WIN_FEATURE (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); From 363dca0b6175c912850497a9a75f242772987ecd Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 28 Oct 2015 17:55:38 +0530 Subject: [PATCH 06/22] code clean up --- .../impl/MobileDeviceOperationMappingDAOImpl.java | 14 +++++++------- .../mobile/dao/impl/MobileOperationDAOImpl.java | 9 ++++----- .../dao/impl/MobileOperationPropertyDAOImpl.java | 8 ++++---- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java index 9058df9ae3..931ab33a2b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java @@ -77,7 +77,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio String msg = "Error occurred while adding device id - '" + mblDeviceOperationMapping.getDeviceId() + " and operation id - " + mblDeviceOperationMapping.getOperationId() + - " to mapping table AD_DEVICE_OPERATION"; + " to mapping table AD_DEVICE_OPERATION_MAPPING"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -114,7 +114,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio } catch (SQLException e) { String msg = "Error occurred while updating device id - '" + mblDeviceOperation.getDeviceId() + " and operation id - " + - mblDeviceOperation.getOperationId() + " in table MBL_DEVICE_OPERATION"; + mblDeviceOperation.getOperationId() + " in table AD_DEVICE_OPERATION_MAPPING"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -151,7 +151,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio String msg = "Error occurred while updating the Status of operation to in-progress of device id - '" + mblDeviceId + " and operation id - " + - operationId + " in table MBL_DEVICE_OPERATION"; + operationId + " in table AD_DEVICE_OPERATION_MAPPING"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -189,7 +189,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio String msg = "Error occurred while updating the Status of operation to completed of device id - '" + mblDeviceId + " and operation id - " + - operationId + " in table MBL_DEVICE_OPERATION"; + operationId + " in table AD_DEVICE_OPERATION_MAPPING"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -280,7 +280,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio PreparedStatement stmt = null; MobileDeviceOperationMapping mblDeviceOperation; List mblDeviceOperations = - new ArrayList(); + new ArrayList<>(); try { conn = this.getConnection(); String selectDBQuery = @@ -303,7 +303,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio } } catch (SQLException e) { String msg = - "Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of " + + "Error occurred while fetching mapping table AD_DEVICE_OPERATION_MAPPING entries of " + "device id - '" + mblDeviceId; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); @@ -321,7 +321,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio PreparedStatement stmt = null; MobileDeviceOperationMapping mblDeviceOperation = null; List mblDeviceOperations = - new ArrayList(); + new ArrayList<>(); try { conn = this.getConnection(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java index 9d5694a3a5..12585f5306 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java @@ -36,7 +36,6 @@ import java.sql.SQLException; */ public class MobileOperationDAOImpl implements MobileOperationDAO { - public static final String COLUMN_OPERATION_ID = "OPERATION_ID"; private DataSource dataSource; private static final Log log = LogFactory.getLog(MobileOperationDAOImpl.class); @@ -54,7 +53,7 @@ public class MobileOperationDAOImpl implements MobileOperationDAO { conn = this.getConnection(); String createDBQuery = "INSERT INTO AD_OPERATION(FEATURE_CODE, CREATED_DATE) VALUES ( ?, ?)"; - stmt = conn.prepareStatement(createDBQuery, new String[] { COLUMN_OPERATION_ID }); + stmt = conn.prepareStatement(createDBQuery, new String[] { "OPERATION_ID" }); stmt.setString(1, mblOperation.getFeatureCode()); stmt.setLong(2, mblOperation.getCreatedDate()); int rows = stmt.executeUpdate(); @@ -70,7 +69,7 @@ public class MobileOperationDAOImpl implements MobileOperationDAO { } } catch (SQLException e) { String msg = "Error occurred while adding the operation - '" + - mblOperation.getFeatureCode() + "' to MBL_OPERATION table"; + mblOperation.getFeatureCode() + "' to AD_OPERATION table"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -104,7 +103,7 @@ public class MobileOperationDAOImpl implements MobileOperationDAO { } } catch (SQLException e) { String msg = - "Error occurred while updating the MBL_OPERATION table entry with operation id - '" + + "Error occurred while updating the AD_OPERATION table entry with operation id - '" + mblOperation.getOperationId() + "'"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); @@ -135,7 +134,7 @@ public class MobileOperationDAOImpl implements MobileOperationDAO { } } } catch (SQLException e) { - String msg = "Error occurred while deleting MBL_OPERATION entry with operation Id - "; + String msg = "Error occurred while deleting AD_OPERATION entry with operation Id - "; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java index 0542e6347b..d111dc6535 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java @@ -70,7 +70,7 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA } } catch (SQLException e) { String msg = - "Error occurred while adding mobile operation property to MBL_OPERATION_PROPERTY " + + "Error occurred while adding mobile operation property to AD_OPERATION_PROPERTY " + "table"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); @@ -107,7 +107,7 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA } catch (SQLException e) { String msg = "Error occurred while updating the mobile operation property in" + - " MBL_OPERATION_PROPERTY table."; + " AD_OPERATION_PROPERTY table."; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -139,7 +139,7 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA } } catch (SQLException e) { String msg = - "Error occurred while deleting MBL_OPERATION_PROPERTY entry with operation Id - "; + "Error occurred while deleting AD_OPERATION_PROPERTY entry with operation Id - "; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -193,7 +193,7 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA Connection conn = null; PreparedStatement stmt = null; MobileOperationProperty mobileOperationProperty; - List properties = new ArrayList(); + List properties = new ArrayList<>(); try { conn = this.getConnection(); String selectDBQuery = From 530c6049baf455443fcd1f4da60a0c097e3d0ea0 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 28 Oct 2015 19:09:09 +0530 Subject: [PATCH 07/22] Cleaning up mobile device management implementation --- ...tractMobileDeviceManagementDAOFactory.java | 102 ++++ .../dao/MobileDeviceManagementDAOFactory.java | 82 +--- ...leDeviceManagementDAOFactoryInterface.java | 37 -- .../dao/MobileDeviceOperationMappingDAO.java | 118 ----- .../mgt/mobile/dao/MobileOperationDAO.java | 62 --- .../dao/MobileOperationPropertyDAO.java | 87 ---- .../MobileDeviceOperationMappingDAOImpl.java | 369 --------------- .../mobile/dao/impl/MobileFeatureDAOImpl.java | 42 +- .../dao/impl/MobileOperationDAOImpl.java | 191 -------- .../impl/MobileOperationPropertyDAOImpl.java | 239 ---------- .../AndroidDeviceManagementService.java | 10 - .../impl/android/AndroidDeviceManager.java | 4 +- .../impl/android/AndroidFeatureManager.java | 6 +- .../impl/android/dao/AndroidDAOFactory.java | 22 +- .../dao/impl/AndroidDeviceDAOImpl.java | 20 +- .../dao/impl/AndroidFeatureDAOImpl.java | 28 +- .../android/util/AndroidPluginConstants.java | 2 +- .../impl/windows/WindowsDeviceManager.java | 4 +- .../impl/windows/WindowsFeatureManager.java | 7 +- .../impl/windows/dao/WindowsDAOFactory.java | 28 +- .../dao/impl/WindowsDeviceDAOImpl.java | 1 + ...obileDeviceManagementServiceComponent.java | 6 +- ...ileDeviceOperationMappingDAOTestSuite.java | 441 ------------------ .../impl/dao/MobileFeatureDAOTestSuite.java | 8 +- .../impl/dao/MobileOperationDAOTestSuite.java | 186 -------- .../MobileOperationPropertyDAOTestSuite.java | 237 ---------- .../src/test/resources/sql/h2.sql | 40 +- .../src/test/resources/testng.xml | 3 - .../dbscripts/plugins/android/h2.sql | 4 +- .../dbscripts/plugins/android/mssql.sql | 4 +- .../dbscripts/plugins/android/postgres.sql | 4 +- .../dbscripts/plugins/windows/oracle.sql | 2 +- 32 files changed, 180 insertions(+), 2216 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/AbstractMobileDeviceManagementDAOFactory.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactoryInterface.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationDAO.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationPropertyDAO.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceOperationMappingDAOTestSuite.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationPropertyDAOTestSuite.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/AbstractMobileDeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/AbstractMobileDeviceManagementDAOFactory.java new file mode 100644 index 0000000000..32bcb8de73 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/AbstractMobileDeviceManagementDAOFactory.java @@ -0,0 +1,102 @@ +/* + * 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.dao; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; +import org.wso2.carbon.device.mgt.mobile.config.datasource.JNDILookupDefinition; +import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; +import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; + +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +/** + * Factory class used to create MobileDeviceManagement related DAO objects. + */ +public abstract class AbstractMobileDeviceManagementDAOFactory implements MobileDeviceManagementDAOFactory { + + private static final Log log = LogFactory.getLog(AbstractMobileDeviceManagementDAOFactory.class); + private static Map dataSourceMap = new HashMap<>(); + private static boolean isInitialized; + + public static void init(Map mobileDataSourceConfigMap) + throws MobileDeviceMgtPluginException { + DataSource dataSource; + for (String pluginType : mobileDataSourceConfigMap.keySet()) { + if (dataSourceMap.get(pluginType) == null) { + dataSource = AbstractMobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfigMap.get + (pluginType)); + dataSourceMap.put(pluginType, dataSource); + } + } + isInitialized = true; + } + + public static void init(String key, MobileDataSourceConfig mobileDataSourceConfig) throws + MobileDeviceMgtPluginException { + DataSource dataSource = AbstractMobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfig); + dataSourceMap.put(key, dataSource); + } + + /** + * Resolve data source from the data source definition. + * + * @param config Mobile data source configuration + * @return data source resolved from the data source definition + */ + public static DataSource resolveDataSource(MobileDataSourceConfig config) { + DataSource dataSource = null; + if (config == null) { + throw new RuntimeException("Device Management Repository data source configuration " + + "is null and thus, is not initialized"); + } + JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); + if (jndiConfig != null) { + if (log.isDebugEnabled()) { + log.debug("Initializing Device Management Repository data source using the JNDI " + + "Lookup Definition"); + } + List jndiPropertyList = + jndiConfig.getJndiProperties(); + if (jndiPropertyList != null) { + Hashtable jndiProperties = new Hashtable(); + for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { + jndiProperties.put(prop.getName(), prop.getValue()); + } + dataSource = + MobileDeviceManagementDAOUtil + .lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + } else { + dataSource = MobileDeviceManagementDAOUtil + .lookupDataSource(jndiConfig.getJndiName(), null); + } + } + return dataSource; + } + + public static Map getDataSourceMap() { + return dataSourceMap; + } + +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java index 94d8b2a069..37a5c311ca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java @@ -18,84 +18,10 @@ package org.wso2.carbon.device.mgt.mobile.dao; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; -import org.wso2.carbon.device.mgt.mobile.config.datasource.JNDILookupDefinition; -import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; +public interface MobileDeviceManagementDAOFactory { -import javax.sql.DataSource; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; + MobileDeviceDAO getMobileDeviceDAO(); -/** - * Factory class used to create MobileDeviceManagement related DAO objects. - */ -public abstract class MobileDeviceManagementDAOFactory implements MobileDeviceManagementDAOFactoryInterface { - - private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class); - private static Map dataSourceMap = new HashMap(); - private static boolean isInitialized; - - public static void init(Map mobileDataSourceConfigMap) - throws MobileDeviceMgtPluginException { - DataSource dataSource; - for (String pluginType : mobileDataSourceConfigMap.keySet()) { - if (dataSourceMap.get(pluginType) == null) { - dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfigMap.get - (pluginType)); - dataSourceMap.put(pluginType, dataSource); - } - } - isInitialized = true; - } - - public static void init(String key, MobileDataSourceConfig mobileDataSourceConfig) throws - MobileDeviceMgtPluginException { - DataSource dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfig); - dataSourceMap.put(key, dataSource); - } - - /** - * Resolve data source from the data source definition. - * - * @param config Mobile data source configuration - * @return data source resolved from the data source definition - */ - public static DataSource resolveDataSource(MobileDataSourceConfig config) { - DataSource dataSource = null; - if (config == null) { - throw new RuntimeException("Device Management Repository data source configuration " + - "is null and thus, is not initialized"); - } - JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); - if (jndiConfig != null) { - if (log.isDebugEnabled()) { - log.debug("Initializing Device Management Repository data source using the JNDI " + - "Lookup Definition"); - } - List jndiPropertyList = - jndiConfig.getJndiProperties(); - if (jndiPropertyList != null) { - Hashtable jndiProperties = new Hashtable(); - for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { - jndiProperties.put(prop.getName(), prop.getValue()); - } - dataSource = - MobileDeviceManagementDAOUtil - .lookupDataSource(jndiConfig.getJndiName(), jndiProperties); - } else { - dataSource = MobileDeviceManagementDAOUtil - .lookupDataSource(jndiConfig.getJndiName(), null); - } - } - return dataSource; - } + MobileFeatureDAO getMobileFeatureDAO(); - public static Map getDataSourceMap() { - return dataSourceMap; - } -} \ No newline at end of file +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactoryInterface.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactoryInterface.java deleted file mode 100644 index 3dd2336ef1..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactoryInterface.java +++ /dev/null @@ -1,37 +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.dao; - -import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; - -public interface MobileDeviceManagementDAOFactoryInterface { - - public MobileDeviceDAO getMobileDeviceDAO(); - - public MobileOperationDAO getMobileOperationDAO(); - - public MobileOperationPropertyDAO getMobileOperationPropertyDAO(); - - public MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO(); - - public MobileFeatureDAO getMobileFeatureDao(); - - 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/dao/MobileDeviceOperationMappingDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java deleted file mode 100644 index bc61be0039..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java +++ /dev/null @@ -1,118 +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.dao; - -import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping; - -import java.util.List; - -/** - * This class represents the mapping between mobile device and operations. - */ -public interface MobileDeviceOperationMappingDAO { - - /** - * Adds a new mobile device operation mapping to the table. - * - * @param mblDeviceOperationMapping MobileDeviceOperationMapping object that holds data related - * to the MobileDeviceOperationMapping to be inserted. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean addMobileDeviceOperationMapping(MobileDeviceOperationMapping mblDeviceOperationMapping) - throws MobileDeviceManagementDAOException; - - /** - * Updates a MobileDeviceOperationMapping in MobileDeviceOperationMapping table. - * - * @param mblDeviceOperation MobileDeviceOperationMapping object that holds data has to be updated. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean updateMobileDeviceOperationMapping(MobileDeviceOperationMapping mblDeviceOperation) - throws MobileDeviceManagementDAOException; - - /** - * Updates a MobileDeviceOperationMapping to In-Progress state in MobileDeviceOperationMapping - * table. - * - * @param mblDeviceId MobileDevice id of the mappings to be updated. - * @param operationId Operation id of the mapping to be updated. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean updateMobileDeviceOperationMappingToInProgress(String mblDeviceId, int operationId) - throws MobileDeviceManagementDAOException; - - /** - * Updates a MobileDeviceOperationMapping to completed state in MobileDeviceOperationMapping - * table. - * - * @param mblDeviceId MobileDevice id of the mappings to be updated. - * @param operationId Operation id of the mapping to be updated. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean updateMobileDeviceOperationMappingToCompleted(String mblDeviceId, int operationId) - throws MobileDeviceManagementDAOException; - - /** - * Delete a given MobileDeviceOperationMapping from MobileDeviceOperationMapping table. - * - * @param mblDeviceId MobileDevice id of the mappings to be deleted. - * @param operationId Operation id of the mapping to be deleted. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean deleteMobileDeviceOperationMapping(String mblDeviceId, int operationId) - throws MobileDeviceManagementDAOException; - - /** - * Retrieves a given MobileDeviceOperationMapping object from the MobileDeviceOperationMapping - * table. - * - * @param mblDeviceId Device id of the mapping to be retrieved. - * @param operationId Operation id of the mapping to be retrieved. - * @return MobileDeviceOperation object that holds data of the device operation mapping - * represented by deviceId and operationId. - * @throws MobileDeviceManagementDAOException - */ - MobileDeviceOperationMapping getMobileDeviceOperationMapping(String mblDeviceId, int operationId) - throws MobileDeviceManagementDAOException; - - /** - * Retrieves all the of MobileDeviceOperationMappings relevant to a given mobile device. - * - * @param mblDeviceId MobileDevice id of the mappings to be retrieved. - * @return MobileDeviceOperationMapping object list. - * @throws MobileDeviceManagementDAOException - */ - List getAllMobileDeviceOperationMappingsOfDevice(String mblDeviceId) - throws MobileDeviceManagementDAOException; - - /** - * Retrieves all the pending MobileDeviceOperationMappings of a mobile device. - * - * @param mblDeviceId MobileDevice id of the mappings to be retrieved. - * @return MobileDeviceOperationMapping object list. - * @throws MobileDeviceManagementDAOException - */ - List getAllPendingOperationMappingsOfMobileDevice(String mblDeviceId) - throws MobileDeviceManagementDAOException; -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationDAO.java deleted file mode 100644 index 90e5a3ea7b..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationDAO.java +++ /dev/null @@ -1,62 +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.dao; - -import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; - -/** - * This class represents the key operations associated with persisting mobile operation related - * information. - */ -public interface MobileOperationDAO { - - /** - * Adds a new Mobile operation to the MobileOperation table. - * @param mblOperation MobileOperation object that holds data related to the operation to be - * inserted. - * @return The id of the inserted record, if the insertion was unsuccessful -1 is returned. - * @throws MobileDeviceManagementDAOException - */ - int addMobileOperation(MobileOperation mblOperation) throws MobileDeviceManagementDAOException; - - /** - * Updates a Mobile operation in the MobileOperation table. - * @param mblOperation MobileOperation object that holds data has to be updated. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean updateMobileOperation(MobileOperation mblOperation) throws MobileDeviceManagementDAOException; - - /** - * Deletes a given MobileOperation from MobileOperation table. - * @param mblOperationId Operation code of the MobileOperation to be deleted. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean deleteMobileOperation(int mblOperationId) throws MobileDeviceManagementDAOException; - - /** - * Retrieve a MobileOperation from MobileOperation table. - * @param mblOperationId Operation id of the MobileOperation to be retrieved. - * @return MobileOperation object that holds data of MobileOperation represented by operationId. - * @throws MobileDeviceManagementDAOException - */ - MobileOperation getMobileOperation(int mblOperationId) throws MobileDeviceManagementDAOException; - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationPropertyDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationPropertyDAO.java deleted file mode 100644 index 87216b02d2..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationPropertyDAO.java +++ /dev/null @@ -1,87 +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.dao; - -import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty; - -import java.util.List; - -/** - * - * This class represents the key operations associated with persisting mobile operation property - * related information. - * - */ -public interface MobileOperationPropertyDAO { - - /** - * Add a new MobileOperationProperty to MobileOperationProperty table. - * - * @param mblOperationProperty MobileOperationProperty object that holds data related to the - * operation property to be inserted. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean addMobileOperationProperty(MobileOperationProperty mblOperationProperty) - throws MobileDeviceManagementDAOException; - - /** - * Update a MobileOperationProperty in the MobileOperationProperty table. - * - * @param mblOperationProperty MobileOperationProperty object that holds data has to be updated. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean updateMobileOperationProperty(MobileOperationProperty mblOperationProperty) - throws MobileDeviceManagementDAOException; - - /** - * Deletes MobileOperationProperties of a given operation id from the MobileOperationProperty - * table. - * - * @param mblOperationId Operation id of the MobileOperationProperty to be deleted. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean deleteMobileOperationProperties(int mblOperationId) - throws MobileDeviceManagementDAOException; - - /** - * Retrieve a given MobileOperationProperty from MobileOperationProperty table. - * - * @param mblOperationId Operation id of the mapping to be retrieved. - * @param property Property of the mapping to be retrieved. - * @return MobileOperationProperty object that holds data of the MobileOperationProperty - * represented by mblOperationId and property. - * @throws MobileDeviceManagementDAOException - */ - MobileOperationProperty getMobileOperationProperty(int mblOperationId, String property) - throws MobileDeviceManagementDAOException; - - /** - * Retrieve all the MobileOperationProperties related to the a operation id from - * MobileOperationProperty table. - * - * @param mblOperationId Operation id of the MobileOperationProperty to be retrieved. - * @return List of MobileOperationProperty objects. - * @throws MobileDeviceManagementDAOException - */ - List getAllMobileOperationPropertiesOfOperation(int mblOperationId) - throws MobileDeviceManagementDAOException; -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java deleted file mode 100644 index 931ab33a2b..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java +++ /dev/null @@ -1,369 +0,0 @@ -/* - * Copyright (c) 2014, 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.dao.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceOperationMappingDAO; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping; - -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.Date; -import java.util.List; - -/** - * Implementation of MobileDeviceOperationMappingDAO. - */ -public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperationMappingDAO { - - private DataSource dataSource; - private static final Log log = LogFactory.getLog(MobileDeviceOperationMappingDAOImpl.class); - - public MobileDeviceOperationMappingDAOImpl(DataSource dataSource) { - this.dataSource = dataSource; - } - - @Override - public boolean addMobileDeviceOperationMapping(MobileDeviceOperationMapping mblDeviceOperationMapping) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String createDBQuery = - "INSERT INTO AD_DEVICE_OPERATION_MAPPING (DEVICE_ID, OPERATION_ID, SENT_DATE, " + - "RECEIVED_DATE, STATUS) VALUES (?, ?, ?, ?, ?)"; - - stmt = conn.prepareStatement(createDBQuery); - stmt.setString(1, mblDeviceOperationMapping.getDeviceId()); - stmt.setLong(2, mblDeviceOperationMapping.getOperationId()); - stmt.setLong(3, mblDeviceOperationMapping.getSentDate()); - stmt.setLong(4, mblDeviceOperationMapping.getReceivedDate()); - stmt.setString(5, mblDeviceOperationMapping.getStatus().name()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Added a MobileDevice-Mapping DeviceId : " + mblDeviceOperationMapping - .getDeviceId() + ", " + - "OperationId : " + mblDeviceOperationMapping.getOperationId() + " to the MDM database."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while adding device id - '" + - mblDeviceOperationMapping.getDeviceId() + " and operation id - " + - mblDeviceOperationMapping.getOperationId() + - " to mapping table AD_DEVICE_OPERATION_MAPPING"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public boolean updateMobileDeviceOperationMapping(MobileDeviceOperationMapping mblDeviceOperation) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String updateDBQuery = - "UPDATE AD_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ?, " + - "STATUS = ? WHERE DEVICE_ID = ? AND OPERATION_ID=?"; - stmt = conn.prepareStatement(updateDBQuery); - stmt.setLong(1, mblDeviceOperation.getSentDate()); - stmt.setLong(2, mblDeviceOperation.getReceivedDate()); - stmt.setString(3, mblDeviceOperation.getStatus().name()); - stmt.setString(4, mblDeviceOperation.getDeviceId()); - stmt.setInt(5, mblDeviceOperation.getOperationId()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Updated MobileDevice-Mapping DeviceId : " + mblDeviceOperation.getDeviceId() + " , " + - "OperationId : " + mblDeviceOperation.getOperationId()); - } - } - } catch (SQLException e) { - String msg = "Error occurred while updating device id - '" + - mblDeviceOperation.getDeviceId() + " and operation id - " + - mblDeviceOperation.getOperationId() + " in table AD_DEVICE_OPERATION_MAPPING"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public boolean updateMobileDeviceOperationMappingToInProgress(String mblDeviceId, int operationId) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String updateDBQuery = - "UPDATE AD_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, STATUS = ? " + - "WHERE DEVICE_ID = ? AND OPERATION_ID=?"; - stmt = conn.prepareStatement(updateDBQuery); - stmt.setLong(1, new Date().getTime()); - stmt.setString(2, MobileDeviceOperationMapping.Status.INPROGRESS.name()); - stmt.setString(3, mblDeviceId); - stmt.setInt(4, operationId); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Updated status of MobileDevice-Mapping DeviceId : " + mblDeviceId + " , " + - "OperationId : " + operationId + " to In-Progress state"); - } - } - } catch (SQLException e) { - String msg = - "Error occurred while updating the Status of operation to in-progress of device id - '" + - mblDeviceId + " and operation id - " + - operationId + " in table AD_DEVICE_OPERATION_MAPPING"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public boolean updateMobileDeviceOperationMappingToCompleted(String mblDeviceId, - int operationId) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String updateDBQuery = - "UPDATE AD_DEVICE_OPERATION_MAPPING SET RECEIVED_DATE = ?, STATUS = ? " + - "WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; - stmt = conn.prepareStatement(updateDBQuery); - stmt.setLong(1, new Date().getTime()); - stmt.setString(2, MobileDeviceOperationMapping.Status.COMPLETED.name()); - stmt.setString(3, mblDeviceId); - stmt.setInt(4, operationId); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Updated status of MobileDevice-Mapping DeviceId : " + mblDeviceId + " , " + - "OperationId : " + operationId + " to Completed state"); - } - } - } catch (SQLException e) { - String msg = - "Error occurred while updating the Status of operation to completed of device id - '" + - mblDeviceId + " and operation id - " + - operationId + " in table AD_DEVICE_OPERATION_MAPPING"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public boolean deleteMobileDeviceOperationMapping(String mblDeviceId, int operationId) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String deleteDBQuery = - "DELETE FROM AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND " + - "OPERATION_ID = ?"; - stmt = conn.prepareStatement(deleteDBQuery); - stmt.setString(1, mblDeviceId); - stmt.setInt(2, operationId); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Deleted MobileDevice-Mapping DeviceId : " + mblDeviceId + " , " + - "OperationId : " + operationId + "from MDM database."); - } - } - } catch (SQLException e) { - String msg = - "Error occurred while deleting the table entry AD_DEVICE_OPERATION with " + - " device id - '" + mblDeviceId + " and operation id - " + operationId; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public MobileDeviceOperationMapping getMobileDeviceOperationMapping(String mblDeviceId, - int operationId) - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - MobileDeviceOperationMapping mblDeviceOperation = null; - try { - conn = this.getConnection(); - String selectDBQuery = - "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " + - "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setString(1, mblDeviceId); - stmt.setInt(2, operationId); - ResultSet resultSet = stmt.executeQuery(); - if (resultSet.next()) { - mblDeviceOperation = new MobileDeviceOperationMapping(); - mblDeviceOperation.setDeviceId(resultSet.getString(1)); - mblDeviceOperation.setOperationId(resultSet.getInt(2)); - mblDeviceOperation.setSentDate(resultSet.getInt(3)); - mblDeviceOperation.setReceivedDate(resultSet.getInt(4)); - mblDeviceOperation.setStatus(resultSet.getString(5)); - if (log.isDebugEnabled()) { - log.debug("Fetched MobileDevice-Mapping of DeviceId : " + mblDeviceId + " , " + - "OperationId : " + operationId ); - } - } - } catch (SQLException e) { - String msg = - "Error occurred while fetching table MBL_DEVICE_OPERATION entry with device id - '" + - mblDeviceId + " and operation id - " + operationId; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return mblDeviceOperation; - } - - @Override - public List getAllMobileDeviceOperationMappingsOfDevice( - String mblDeviceId) - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - MobileDeviceOperationMapping mblDeviceOperation; - List mblDeviceOperations = - new ArrayList<>(); - try { - conn = this.getConnection(); - String selectDBQuery = - "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " + - "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setString(1, mblDeviceId); - ResultSet resultSet = stmt.executeQuery(); - while (resultSet.next()) { - mblDeviceOperation = new MobileDeviceOperationMapping(); - mblDeviceOperation.setDeviceId(resultSet.getString(1)); - mblDeviceOperation.setOperationId(resultSet.getInt(2)); - mblDeviceOperation.setSentDate(resultSet.getInt(3)); - mblDeviceOperation.setReceivedDate(resultSet.getInt(4)); - mblDeviceOperation.setStatus(resultSet.getString(5)); - mblDeviceOperations.add(mblDeviceOperation); - } - if (log.isDebugEnabled()) { - log.debug("Fetched all MobileDevice-Mappings of DeviceId : " + mblDeviceId); - } - } catch (SQLException e) { - String msg = - "Error occurred while fetching mapping table AD_DEVICE_OPERATION_MAPPING entries of " + - "device id - '" + mblDeviceId; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return mblDeviceOperations; - } - - @Override - public List getAllPendingOperationMappingsOfMobileDevice( - String mblDeviceId) - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - MobileDeviceOperationMapping mblDeviceOperation = null; - List mblDeviceOperations = - new ArrayList<>(); - try { - - conn = this.getConnection(); - String selectDBQuery = - "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM" + - " AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND STATUS = ?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setString(1, mblDeviceId); - stmt.setString(2, MobileDeviceOperationMapping.Status.NEW.name()); - ResultSet resultSet = stmt.executeQuery(); - while (resultSet.next()) { - mblDeviceOperation = new MobileDeviceOperationMapping(); - mblDeviceOperation.setDeviceId(resultSet.getString(1)); - mblDeviceOperation.setOperationId(resultSet.getInt(2)); - mblDeviceOperation.setSentDate(resultSet.getInt(3)); - mblDeviceOperation.setReceivedDate(resultSet.getInt(4)); - mblDeviceOperation.setStatus(resultSet.getString(5)); - mblDeviceOperations.add(mblDeviceOperation); - } - if (log.isDebugEnabled()) { - log.debug("Fetched all pending MobileDevice-Mappings of DeviceId : " + mblDeviceId); - } - } catch (SQLException e) { - String msg = - "Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of" + - " device id - '" + mblDeviceId; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return mblDeviceOperations; - } - - 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/dao/impl/MobileFeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java index 666e33e2d6..a9636ccb4a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java @@ -64,12 +64,10 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { int rows = stmt.executeUpdate(); if (rows > 0) { if (log.isDebugEnabled()) { - log.debug("Added a new MobileFeature " + mobileFeature.getCode() + " to the" + - " MDM database."); + log.debug("Added a new MobileFeature " + mobileFeature.getCode() + " to the MDM database."); } status = true; } - } catch (SQLException e) { String msg = "Error occurred while adding feature code - '" + mobileFeature.getCode() + "' to feature table"; @@ -91,7 +89,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { conn = this.getConnection(); String updateDBQuery = "UPDATE AD_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ?, DEVICE_TYPE = ?" + - " WHERE FEATURE_ID = ?"; + " WHERE ID = ?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setString(1, mobileFeature.getCode()); stmt.setString(2, mobileFeature.getName()); @@ -132,8 +130,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { if (rows > 0) { status = true; if (log.isDebugEnabled()) { - log.debug("Deleted MobileFeature code " + mblFeatureCode + " from the" + - " MDM database."); + log.debug("Deleted MobileFeature code " + mblFeatureCode + " from the MDM database."); } } } catch (SQLException e) { @@ -155,15 +152,14 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String deleteDBQuery = - "DELETE FROM AD_FEATURE WHERE FEATURE_ID = ?"; + "DELETE FROM AD_FEATURE WHERE ID = ?"; stmt = conn.prepareStatement(deleteDBQuery); stmt.setInt(1, mblFeatureId); int rows = stmt.executeUpdate(); if (rows > 0) { status = true; if (log.isDebugEnabled()) { - log.debug("Deleted MobileFeature id " + mblFeatureId + " from the" + - " MDM database."); + log.debug("Deleted MobileFeature id " + mblFeatureId + " from the MDM database."); } } } catch (SQLException e) { @@ -185,7 +181,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE " + + "SELECT ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE " + "WHERE CODE = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, mblFeatureCode); @@ -198,13 +194,11 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { mobileFeature.setDescription(resultSet.getString(4)); mobileFeature.setDeviceType(resultSet.getString(5)); if (log.isDebugEnabled()) { - log.debug("Fetched MobileFeature " + mblFeatureCode + " from the" + - " MDM database."); + log.debug("Fetched MobileFeature " + mblFeatureCode + " from the MDM database."); } } } catch (SQLException e) { - String msg = "Error occurred while fetching feature code - '" + - mblFeatureCode + "'"; + String msg = "Error occurred while fetching feature code - '" + mblFeatureCode + "'"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -222,8 +216,8 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE" + - " WHERE FEATURE_ID = ?"; + "SELECT ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE" + + " WHERE ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setInt(1, mblFeatureId); ResultSet resultSet = stmt.executeQuery(); @@ -235,13 +229,11 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { mobileFeature.setDescription(resultSet.getString(4)); mobileFeature.setDeviceType(resultSet.getString(5)); if (log.isDebugEnabled()) { - log.debug("Fetched MobileFeatureId" + mblFeatureId + " from the" + - " MDM database."); + log.debug("Fetched MobileFeatureId" + mblFeatureId + " from the MDM database."); } } } catch (SQLException e) { - String msg = "Error occurred while fetching feature id - '" + - mblFeatureId + "'"; + String msg = "Error occurred while fetching feature id - '" + mblFeatureId + "'"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -259,7 +251,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE"; + "SELECT ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE"; stmt = conn.prepareStatement(selectDBQuery); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { @@ -285,16 +277,15 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { } @Override - public List getFeatureByDeviceType(String deviceType) throws - MobileDeviceManagementDAOException { + public List getFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; MobileFeature mobileFeature; - List mobileFeatures = new ArrayList(); + List mobileFeatures = new ArrayList<>(); try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE" + + "SELECT ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE" + " WHERE DEVICE_TYPE = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, deviceType); @@ -332,4 +323,5 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { 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/dao/impl/MobileOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java deleted file mode 100644 index 12585f5306..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationDAOImpl.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (c) 2014, 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.dao.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileOperationDAO; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; - -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -/** - * Implementation of MobileOperationDAO. - */ -public class MobileOperationDAOImpl implements MobileOperationDAO { - - private DataSource dataSource; - private static final Log log = LogFactory.getLog(MobileOperationDAOImpl.class); - - public MobileOperationDAOImpl(DataSource dataSource) { - this.dataSource = dataSource; - } - - @Override - public int addMobileOperation(MobileOperation mblOperation) - throws MobileDeviceManagementDAOException { - int status = -1; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String createDBQuery = - "INSERT INTO AD_OPERATION(FEATURE_CODE, CREATED_DATE) VALUES ( ?, ?)"; - stmt = conn.prepareStatement(createDBQuery, new String[] { "OPERATION_ID" }); - stmt.setString(1, mblOperation.getFeatureCode()); - stmt.setLong(2, mblOperation.getCreatedDate()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - ResultSet rs = stmt.getGeneratedKeys(); - if (rs != null && rs.next()) { - status = rs.getInt(1); - } - if (log.isDebugEnabled()) { - log.debug("Added a new MobileOperation " + mblOperation.getFeatureCode() + - " to MDM database."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while adding the operation - '" + - mblOperation.getFeatureCode() + "' to AD_OPERATION table"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public boolean updateMobileOperation(MobileOperation mblOperation) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String updateDBQuery = - "UPDATE AD_OPERATION SET FEATURE_CODE = ?, CREATED_DATE = ? WHERE " + - "OPERATION_ID = ?"; - stmt = conn.prepareStatement(updateDBQuery); - stmt.setString(1, mblOperation.getFeatureCode()); - stmt.setLong(2, mblOperation.getCreatedDate()); - stmt.setInt(3, mblOperation.getOperationId()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Updated MobileOperation " + mblOperation.getFeatureCode() + - " to MDM database."); - } - } - } catch (SQLException e) { - String msg = - "Error occurred while updating the AD_OPERATION table entry with operation id - '" + - mblOperation.getOperationId() + "'"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public boolean deleteMobileOperation(int mblOperationId) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String deleteDBQuery = - "DELETE FROM AD_OPERATION WHERE OPERATION_ID = ?"; - stmt = conn.prepareStatement(deleteDBQuery); - stmt.setInt(1, mblOperationId); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Deleted a new MobileOperation " + mblOperationId + - " from MDM database."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while deleting AD_OPERATION entry with operation Id - "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public MobileOperation getMobileOperation(int mblOperationId) - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - MobileOperation operation = null; - try { - conn = this.getConnection(); - String selectDBQuery = - "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM AD_OPERATION WHERE " + - "OPERATION_ID = ?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setInt(1, mblOperationId); - ResultSet resultSet = stmt.executeQuery(); - if (resultSet.next()) { - operation = new MobileOperation(); - operation.setOperationId(resultSet.getInt(1)); - operation.setFeatureCode(resultSet.getString(2)); - operation.setCreatedDate(resultSet.getLong(3)); - if (log.isDebugEnabled()) { - log.debug("Fetched MobileOperation " + operation.getFeatureCode() + - " from MDM database."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while fetching operationId - '" + - mblOperationId + "' from MBL_OPERATION"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return operation; - } - - 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); - } - } -} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java deleted file mode 100644 index d111dc6535..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileOperationPropertyDAOImpl.java +++ /dev/null @@ -1,239 +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.dao.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileOperationPropertyDAO; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty; - -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; - -/** - * Implementation of MobileOperationPropertyDAO. - */ -public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDAO { - - private DataSource dataSource; - private static final Log log = LogFactory.getLog(MobileOperationPropertyDAOImpl.class); - - public MobileOperationPropertyDAOImpl(DataSource dataSource) { - this.dataSource = dataSource; - } - - @Override - public boolean addMobileOperationProperty(MobileOperationProperty mblOperationProperty) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String createDBQuery = - "INSERT INTO AD_OPERATION_PROPERTY(OPERATION_ID, PROPERTY, VALUE) " + - "VALUES ( ?, ?, ?)"; - stmt = conn.prepareStatement(createDBQuery); - stmt.setInt(1, mblOperationProperty.getOperationId()); - stmt.setString(2, mblOperationProperty.getProperty()); - stmt.setString(3, mblOperationProperty.getValue()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Added a new MobileOperationProperty " + mblOperationProperty.getProperty() + - " to MDM database."); - } - } - } catch (SQLException e) { - String msg = - "Error occurred while adding mobile operation property to AD_OPERATION_PROPERTY " + - "table"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public boolean updateMobileOperationProperty( - MobileOperationProperty mblOperationProperty) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String createDBQuery = - "UPDATE AD_OPERATION_PROPERTY SET VALUE = ? WHERE OPERATION_ID = ? AND " + - "PROPERTY = ?"; - stmt = conn.prepareStatement(createDBQuery); - stmt.setString(1, mblOperationProperty.getValue()); - stmt.setInt(2, mblOperationProperty.getOperationId()); - stmt.setString(3, mblOperationProperty.getProperty()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Updated MobileOperationProperty " + mblOperationProperty.getProperty() + - " to MDM database."); - } - } - } catch (SQLException e) { - String msg = - "Error occurred while updating the mobile operation property in" + - " AD_OPERATION_PROPERTY table."; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public boolean deleteMobileOperationProperties(int mblOperationId) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String deleteDBQuery = - "DELETE FROM AD_OPERATION_PROPERTY WHERE OPERATION_ID = ?"; - stmt = conn.prepareStatement(deleteDBQuery); - stmt.setInt(1, mblOperationId); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Deleted MobileOperationProperties of operation-id " + - mblOperationId + - " from MDM database."); - } - } - } catch (SQLException e) { - String msg = - "Error occurred while deleting AD_OPERATION_PROPERTY entry with operation Id - "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public MobileOperationProperty getMobileOperationProperty(int mblOperationId, - String property) - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - MobileOperationProperty mobileOperationProperty = null; - try { - conn = this.getConnection(); - String selectDBQuery = - "SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE " + - "OPERATION_ID = ? AND PROPERTY = ?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setInt(1, mblOperationId); - stmt.setString(2, property); - ResultSet resultSet = stmt.executeQuery(); - if (resultSet.next()) { - mobileOperationProperty = new MobileOperationProperty(); - mobileOperationProperty.setOperationId(resultSet.getInt(1)); - mobileOperationProperty.setProperty(resultSet.getString(2)); - mobileOperationProperty.setValue(resultSet.getString(3)); - if (log.isDebugEnabled()) { - log.debug("Fetched MobileOperationProperty of Operation-id : " + - mblOperationId + - " Property : " + property + " from MDM database."); - } - } - } catch (SQLException e) { - String msg = - "Error occurred while fetching the mobile operation property of Operation_id : " + - mblOperationId + " and Property : " + property; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return mobileOperationProperty; - } - - @Override - public List getAllMobileOperationPropertiesOfOperation( - int mblOperationId) throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - MobileOperationProperty mobileOperationProperty; - List properties = new ArrayList<>(); - try { - conn = this.getConnection(); - String selectDBQuery = - "SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE " + - "OPERATION_ID = ?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setInt(1, mblOperationId); - ResultSet resultSet = stmt.executeQuery(); - while (resultSet.next()) { - mobileOperationProperty = new MobileOperationProperty(); - mobileOperationProperty.setOperationId(resultSet.getInt(1)); - mobileOperationProperty.setProperty(resultSet.getString(2)); - mobileOperationProperty.setValue(resultSet.getString(3)); - properties.add(mobileOperationProperty); - } - if (log.isDebugEnabled()) { - log.debug("Fetched all MobileOperationProperties of Operation-id : " + - mblOperationId + - " from MDM database."); - } - } catch (SQLException e) { - String msg = - "Error occurred while fetching the mobile operation properties of Operation_id " + - mblOperationId; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return properties; - } - - 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/AndroidDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java index ffac64decf..9f1e22167f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java @@ -18,23 +18,13 @@ package org.wso2.carbon.device.mgt.mobile.impl.android; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; -import org.wso2.carbon.device.mgt.common.license.mgt.License; -import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; -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.AndroidDAOFactory; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; -import java.util.ArrayList; import java.util.List; /** 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 73b3d9835e..d396f45ee2 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 @@ -28,8 +28,8 @@ import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager; import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; import org.wso2.carbon.device.mgt.mobile.common.MobilePluginConstants; +import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory; 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.AndroidDAOFactory; import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginUtils; @@ -49,7 +49,7 @@ import java.util.List; public class AndroidDeviceManager implements DeviceManager { - private MobileDeviceManagementDAOFactory daoFactory; + private AbstractMobileDeviceManagementDAOFactory daoFactory; private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class); private FeatureManager featureManager = new AndroidFeatureManager(); private LicenseManager licenseManager; 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 999dfb655b..6ce207890c 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,6 +23,7 @@ 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.dao.AbstractMobileDeviceManagementDAOFactory; 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; @@ -37,11 +38,10 @@ public class AndroidFeatureManager implements FeatureManager { private MobileFeatureDAO featureDAO; private static final Log log = LogFactory.getLog(AndroidFeatureManager.class); - private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; public AndroidFeatureManager() { - mobileDeviceManagementDAOFactory = new AndroidDAOFactory(); - this.featureDAO = mobileDeviceManagementDAOFactory.getMobileFeatureDao(); + MobileDeviceManagementDAOFactory daoFactory = new AndroidDAOFactory(); + this.featureDAO = daoFactory.getMobileFeatureDAO(); } @Override 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 dd116e5190..12573ac2b7 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 @@ -29,12 +29,11 @@ import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; -public class AndroidDAOFactory extends MobileDeviceManagementDAOFactory - implements MobileDeviceManagementDAOFactoryInterface { +public class AndroidDAOFactory extends AbstractMobileDeviceManagementDAOFactory { private static final Log log = LogFactory.getLog(AndroidDAOFactory.class); protected static DataSource dataSource; - private static ThreadLocal currentConnection = new ThreadLocal(); + private static ThreadLocal currentConnection = new ThreadLocal<>(); public AndroidDAOFactory() { this.dataSource = getDataSourceMap().get(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); @@ -46,21 +45,7 @@ public class AndroidDAOFactory extends MobileDeviceManagementDAOFactory } @Override - public MobileOperationDAO getMobileOperationDAO() { - return null; - } - - @Override - public MobileOperationPropertyDAO getMobileOperationPropertyDAO() { - return null; - } - - @Override - public MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() { - return null; - } - - @Override public MobileFeatureDAO getMobileFeatureDao() { + public MobileFeatureDAO getMobileFeatureDAO() { return new AndroidFeatureDAOImpl(); } @@ -136,4 +121,5 @@ public class AndroidDAOFactory extends MobileDeviceManagementDAOFactory closeConnection(); } } + } \ No newline at end of file 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 index 886039511d..a43fcab9dc 100644 --- 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 @@ -52,17 +52,16 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{ try { conn = AndroidDAOFactory.getConnection(); String selectDBQuery = - "SELECT ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " + + "SELECT DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " + "VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION" + - " FROM AD_DEVICE WHERE ANDROID_DEVICE_ID = ?"; + " FROM AD_DEVICE WHERE DEVICE_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, mblDeviceId); rs = stmt.executeQuery(); if (rs.next()) { mobileDevice = new MobileDevice(); - mobileDevice.setMobileDeviceId(rs.getString(AndroidPluginConstants. - ANDROID_DEVICE_ID)); + mobileDevice.setMobileDeviceId(rs.getString(AndroidPluginConstants.DEVICE_ID)); mobileDevice.setModel(rs.getString(AndroidPluginConstants.DEVICE_MODEL)); mobileDevice.setSerial(rs.getString(AndroidPluginConstants.SERIAL)); mobileDevice.setVendor(rs.getString(AndroidPluginConstants.VENDOR)); @@ -103,7 +102,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{ try { conn = AndroidDAOFactory.getConnection(); String createDBQuery = - "INSERT INTO AD_DEVICE(ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, SERIAL, " + + "INSERT INTO AD_DEVICE(DEVICE_ID, GCM_TOKEN, DEVICE_INFO, SERIAL, " + "VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, " + "OS_VERSION, DEVICE_MODEL) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; @@ -150,7 +149,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{ String updateDBQuery = "UPDATE AD_DEVICE SET GCM_TOKEN = ?, DEVICE_INFO = ?, SERIAL = ?, VENDOR = ?, " + "MAC_ADDRESS = ?, DEVICE_NAME = ?, LATITUDE = ?, LONGITUDE = ?, IMEI = ?, " + - "IMSI = ?, OS_VERSION = ?, DEVICE_MODEL = ? WHERE ANDROID_DEVICE_ID = ?"; + "IMSI = ?, OS_VERSION = ?, DEVICE_MODEL = ? WHERE DEVICE_ID = ?"; stmt = conn.prepareStatement(updateDBQuery); Map properties = mobileDevice.getDeviceProperties(); @@ -195,7 +194,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{ try { conn = AndroidDAOFactory.getConnection(); String deleteDBQuery = - "DELETE FROM AD_DEVICE WHERE ANDROID_DEVICE_ID = ?"; + "DELETE FROM AD_DEVICE WHERE DEVICE_ID = ?"; stmt = conn.prepareStatement(deleteDBQuery); stmt.setString(1, mblDeviceId); int rows = stmt.executeUpdate(); @@ -225,7 +224,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{ try { conn = AndroidDAOFactory.getConnection(); String selectDBQuery = - "SELECT ANDROID_DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " + + "SELECT DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " + "VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION " + "FROM AD_DEVICE"; stmt = conn.prepareStatement(selectDBQuery); @@ -233,8 +232,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{ while (rs.next()) { mobileDevice = new MobileDevice(); - mobileDevice.setMobileDeviceId(rs.getString(AndroidPluginConstants. - ANDROID_DEVICE_ID)); + mobileDevice.setMobileDeviceId(rs.getString(AndroidPluginConstants.DEVICE_ID)); mobileDevice.setModel(rs.getString(AndroidPluginConstants.DEVICE_MODEL)); mobileDevice.setSerial(rs.getString(AndroidPluginConstants.SERIAL)); mobileDevice.setVendor(rs.getString(AndroidPluginConstants.VENDOR)); @@ -244,7 +242,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{ mobileDevice.setImsi(rs.getString(AndroidPluginConstants.IMSI)); mobileDevice.setOsVersion(rs.getString(AndroidPluginConstants.OS_VERSION)); - Map propertyMap = new HashMap(); + Map propertyMap = new HashMap<>(); propertyMap.put(AndroidPluginConstants.GCM_TOKEN, rs.getString(AndroidPluginConstants.GCM_TOKEN)); propertyMap.put(AndroidPluginConstants.DEVICE_INFO, rs.getString(AndroidPluginConstants.DEVICE_INFO)); propertyMap.put(AndroidPluginConstants.DEVICE_NAME, rs.getString(AndroidPluginConstants.DEVICE_NAME)); 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 index d597d3a5df..88a21ab78a 100644 --- 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 @@ -22,7 +22,6 @@ 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.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; @@ -30,7 +29,6 @@ import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory; 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; @@ -75,7 +73,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { @Override public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { boolean status = false; - Connection conn = null; + Connection conn; PreparedStatement stmt = null; try { conn = AndroidDAOFactory.getConnection(); @@ -112,7 +110,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { PreparedStatement stmt = null; boolean status = false; - Connection conn = null; + Connection conn; try { conn = AndroidDAOFactory.getConnection(); String sql = "DELETE FROM AD_FEATURE WHERE ID = ?"; @@ -131,11 +129,10 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { } @Override - public boolean deleteFeatureByCode(String mblFeatureCode) throws - MobileDeviceManagementDAOException { + public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { PreparedStatement stmt = null; boolean status = false; - Connection conn = null; + Connection conn; try { conn = AndroidDAOFactory.getConnection(); String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?"; @@ -154,11 +151,10 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { } @Override - public MobileFeature getFeatureById(int mblFeatureId) throws - MobileDeviceManagementDAOException { + public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; - Connection conn = null; + Connection conn; try { conn = AndroidDAOFactory.getConnection(); String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE ID = ?"; @@ -189,11 +185,10 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { } @Override - public MobileFeature getFeatureByCode(String mblFeatureCode) throws - MobileDeviceManagementDAOException { + public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; - Connection conn = null; + Connection conn; try { conn = AndroidDAOFactory.getConnection(); @@ -232,11 +227,10 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { @Override public List getAllFeatures() throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; ResultSet rs = null; Connection conn = null; - List features = new ArrayList(); + List features = new ArrayList<>(); try { conn = AndroidDAOFactory.getConnection(); @@ -250,8 +244,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { mobileFeature.setId(rs.getInt(AndroidPluginConstants.ANDROID_FEATURE_ID)); mobileFeature.setCode(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_CODE)); mobileFeature.setName(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_NAME)); - mobileFeature.setDescription(rs.getString(AndroidPluginConstants. - ANDROID_FEATURE_DESCRIPTION)); + mobileFeature.setDescription(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_DESCRIPTION)); mobileFeature.setDeviceType( DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); features.add(mobileFeature); @@ -265,4 +258,5 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { AndroidDAOFactory.closeConnection(); } } + } 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 index 56837f2591..798f5fef16 100644 --- 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 @@ -24,7 +24,7 @@ package org.wso2.carbon.device.mgt.mobile.impl.android.util; public class AndroidPluginConstants { //Properties related to AD_DEVICE table - public static final String ANDROID_DEVICE_ID = "ANDROID_DEVICE_ID"; + public static final String DEVICE_ID = "DEVICE_ID"; public static final String GCM_TOKEN = "GCM_TOKEN"; public static final String DEVICE_INFO = "DEVICE_INFO"; public static final String SERIAL = "SERIAL"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java index 54a1dbea13..18e9d6360f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java @@ -28,8 +28,8 @@ import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager; import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; import org.wso2.carbon.device.mgt.mobile.common.MobilePluginConstants; +import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory; 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.windows.dao.WindowsDAOFactory; import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsPluginUtils; @@ -49,7 +49,7 @@ import java.util.List; public class WindowsDeviceManager implements DeviceManager { - private MobileDeviceManagementDAOFactory daoFactory; + private AbstractMobileDeviceManagementDAOFactory daoFactory; private LicenseManager licenseManager; private FeatureManager featureManager = new WindowsFeatureManager(); private static final Log log = LogFactory.getLog(WindowsDeviceManagementService.class); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java index 99067b7eb1..da7d718cc5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java @@ -23,6 +23,7 @@ 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.dao.AbstractMobileDeviceManagementDAOFactory; 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; @@ -37,16 +38,14 @@ public class WindowsFeatureManager implements FeatureManager { private MobileFeatureDAO featureDAO; private static final Log log = LogFactory.getLog(WindowsFeatureManager.class); - private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; public WindowsFeatureManager() { - mobileDeviceManagementDAOFactory = new WindowsDAOFactory(); - this.featureDAO = mobileDeviceManagementDAOFactory.getMobileFeatureDao(); + MobileDeviceManagementDAOFactory daoFactory = new WindowsDAOFactory(); + this.featureDAO = daoFactory.getMobileFeatureDAO(); } @Override public boolean addFeature(Feature feature) throws DeviceManagementException { - try { WindowsDAOFactory.beginTransaction(); MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java index 3c1ba0424b..ad2af0445f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java @@ -28,12 +28,11 @@ import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; -public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory - implements MobileDeviceManagementDAOFactoryInterface { +public class WindowsDAOFactory extends AbstractMobileDeviceManagementDAOFactory { private static final Log log = LogFactory.getLog(WindowsDAOFactory.class); protected static DataSource dataSource; - private static ThreadLocal currentConnection = new ThreadLocal(); + private static ThreadLocal currentConnection = new ThreadLocal<>(); public WindowsDAOFactory() { this.dataSource = getDataSourceMap().get(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); @@ -45,27 +44,7 @@ public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory } @Override - public MobileOperationDAO getMobileOperationDAO() { - return null; - } - - @Override - public MobileOperationPropertyDAO getMobileOperationPropertyDAO() { - return null; - } - - @Override - public MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() { - return null; - } - - @Override - public MobileFeatureDAO getMobileFeatureDao() { - return null; - } - - @Override - public MobileFeaturePropertyDAO getFeaturePropertyDAO() { + public MobileFeatureDAO getMobileFeatureDAO() { return null; } @@ -145,4 +124,5 @@ public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory log.warn("Error occurred while roll-backing the transaction", e); } } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java index d9902cb7b3..478942b03f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java @@ -251,4 +251,5 @@ public class WindowsDeviceDAOImpl implements MobileDeviceDAO { 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/internal/MobileDeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java index e8325e084a..8f71321f43 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java @@ -28,7 +28,7 @@ import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagementService; import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidPolicyMonitoringService; @@ -79,7 +79,7 @@ public class MobileDeviceManagementServiceComponent { Map dsConfigMap = config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap(); - MobileDeviceManagementDAOFactory.init(dsConfigMap); + AbstractMobileDeviceManagementDAOFactory.init(dsConfigMap); String setupOption = System.getProperty("setup"); if (setupOption != null) { @@ -91,7 +91,7 @@ public class MobileDeviceManagementServiceComponent { try { for (String pluginType : dsConfigMap.keySet()) { MobileDeviceManagementDAOUtil - .setupMobileDeviceManagementSchema(MobileDeviceManagementDAOFactory.getDataSourceMap + .setupMobileDeviceManagementSchema(AbstractMobileDeviceManagementDAOFactory.getDataSourceMap ().get(pluginType), pluginType); } } catch (MobileDeviceMgtPluginException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceOperationMappingDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceOperationMappingDAOTestSuite.java deleted file mode 100644 index 2c419bc5cd..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceOperationMappingDAOTestSuite.java +++ /dev/null @@ -1,441 +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.dao; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tomcat.jdbc.pool.DataSource; -import org.apache.tomcat.jdbc.pool.PoolProperties; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Parameters; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileDeviceOperationMappingDAOImpl; -import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileOperationDAOImpl; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping; -import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; -import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes; -import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration; -import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -/** - * - * Class for holding unit-tests related to MobileDeviceOperationMappingDAO class. - * - */ -public class MobileDeviceOperationMappingDAOTestSuite { - - private static final Log log = - LogFactory.getLog(MobileDeviceOperationMappingDAOTestSuite.class); - public static final String TEST_MOBILE_DEVICE_ID = "ABCD"; - public static final String TEST_MOBILE_IMEI = "2412421412"; - public static final String TEST_MOBILE_IMSI = "325235235"; - public static final String TEST_MOBILE_MODEL = "S5"; - public static final String TEST_MOBILE_VENDOR = "samsung"; - public static final String TEST_MOBILE_REG_ID = "2414"; - public static final String TEST_MOBILE_OS_VERSION = "5.0.0"; - public static final String TEST_MOBILE_LATITUDE = "6.93N"; - public static final String TEST_MOBILE_LONGITUDE = "80.60E"; - public static final String TEST_MOBILE_TOKEN = "2412K2HKHK24K12H4"; - public static final String TEST_MOBILE_SERIAL = "24124IIH4I2K4"; - public static final String TEST_MOBILE_CHALLENGE = "ASFASFSAFASFATWTWQTTQWTWQTQWTQWTWQT"; - public static final String TEST_MOBILE_UNLOCK_TOKEN = "FAFWQUWFUQWYWQYRWQURYUURUWQUWRUWRUWE"; - public static final String TEST_MBL_OPR_FEATURE_CODE1 = "LOCK"; - public static final String TEST_MBL_OPR_FEATURE_CODE2 = "WIPE"; - public static final long TEST_MBL_OPR_CREATED_DATE = new java.util.Date().getTime(); - - private TestDBConfiguration testDBConfiguration; - private MobileOperationDAOImpl mblOperationDAO; - private MobileDeviceOperationMappingDAOImpl mblDeviceOperationMappingDAO; - private int mblOperationId1; - private int mblOperationId2; - - @BeforeClass - @Parameters("dbType") - public void setUpDB(String dbTypeStr) throws Exception { - - DBTypes dbType = DBTypes.valueOf(dbTypeStr); - testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType); - - switch (dbType) { - case H2: - MobileDatabaseUtils.createH2DB(testDBConfiguration); - DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource(); - PoolProperties properties = new PoolProperties(); - properties.setUrl(testDBConfiguration.getConnectionURL()); - properties.setDriverClassName(testDBConfiguration.getDriverClassName()); - properties.setUsername(testDBConfiguration.getUsername()); - properties.setPassword(testDBConfiguration.getPassword()); - testDataSource.setPoolProperties(properties); - mblOperationDAO = new MobileOperationDAOImpl(testDataSource); - mblDeviceOperationMappingDAO = - new MobileDeviceOperationMappingDAOImpl(testDataSource); - default: - } - } - - //@Test - public void addMobileDeviceOperationMappingTest() - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement preparedStatement = null; - - List mblOperations = - new ArrayList(); - MobileDeviceOperationMapping mblDvOperationMapping = - new MobileDeviceOperationMapping(); - //Add a new Device to the database - MobileDevice mobileDevice = new MobileDevice(); - mobileDevice.setMobileDeviceId(TEST_MOBILE_DEVICE_ID); - mobileDevice.setImei(TEST_MOBILE_IMEI); - mobileDevice.setImsi(TEST_MOBILE_IMSI); - mobileDevice.setModel(TEST_MOBILE_MODEL); - mobileDevice.setVendor(TEST_MOBILE_VENDOR); - mobileDevice.setOsVersion(TEST_MOBILE_OS_VERSION); - mobileDevice.setLatitude(TEST_MOBILE_LATITUDE); - mobileDevice.setLongitude(TEST_MOBILE_LONGITUDE); - mobileDevice.setSerial(TEST_MOBILE_SERIAL); - - //Add an Operation to the db - MobileOperation mblOperation = new MobileOperation(); - mblOperation.setFeatureCode(TEST_MBL_OPR_FEATURE_CODE1); - mblOperation.setCreatedDate(TEST_MBL_OPR_CREATED_DATE); - mblOperationId1 = mblOperationDAO.addMobileOperation(mblOperation); - - //Add a new Operation 2 to the db - mblOperation.setFeatureCode(TEST_MBL_OPR_FEATURE_CODE2); - mblOperation.setCreatedDate(TEST_MBL_OPR_CREATED_DATE); - mblOperationId2 = mblOperationDAO.addMobileOperation(mblOperation); - - //Add a device-operation mapping 1 to the table - mblDvOperationMapping.setDeviceId(TEST_MOBILE_DEVICE_ID); - mblDvOperationMapping.setOperationId(mblOperationId1); - mblDvOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW); - boolean status1 = - mblDeviceOperationMappingDAO.addMobileDeviceOperationMapping(mblDvOperationMapping); - - //Add a device-operation mapping 2 to the table - mblDvOperationMapping.setDeviceId(TEST_MOBILE_DEVICE_ID); - mblDvOperationMapping.setOperationId(mblOperationId2); - mblDvOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW); - boolean status2 = - mblDeviceOperationMappingDAO.addMobileDeviceOperationMapping(mblDvOperationMapping); - - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String selectDBQuery = - "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " + - "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?"; - preparedStatement = conn.prepareStatement(selectDBQuery); - preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID); - ResultSet resultSet = preparedStatement.executeQuery(); - while (resultSet.next()) { - mblDvOperationMapping = new MobileDeviceOperationMapping(); - mblDvOperationMapping.setDeviceId(resultSet.getString(1)); - mblDvOperationMapping.setOperationId(resultSet.getInt(2)); - mblDvOperationMapping.setSentDate(resultSet.getLong(3)); - mblDvOperationMapping.setReceivedDate(resultSet.getLong(4)); - mblDvOperationMapping.setStatus(resultSet.getString(5)); - mblOperations.add(mblDvOperationMapping); - } - - } catch (SQLException e) { - String msg = "Error in retrieving Mobile Operation Mappings data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(status1, "MobileOperationMapping1 has added "); - Assert.assertTrue(status2, "MobileOperationMapping2 has added "); - Assert.assertTrue(mblOperations.size() == 2, "MobileOperationMappings have retrieved "); - - for (MobileDeviceOperationMapping mapping : mblOperations) { - Assert.assertEquals(TEST_MOBILE_DEVICE_ID, mapping.getDeviceId(), - "MobileOperationMapping device id has persisted "); - Assert.assertEquals(MobileDeviceOperationMapping.Status.NEW, mapping.getStatus(), - "MobileOperationMapping status has persisted "); - Assert.assertTrue(mapping.getOperationId() > 0, - "MobileOperationMapping operation-id has persisted "); - Assert.assertTrue(mapping.getSentDate() == 0, - "MobileOperationMapping sent-date has fetched "); - Assert.assertTrue(mapping.getReceivedDate() == 0, - "MobileOperationMapping received-date has fetched "); - } - } - - //@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest" }) - public void getMobileDeviceOperationMappingTest() throws MobileDeviceManagementDAOException { - MobileDeviceOperationMapping mblOperationMapping = - mblDeviceOperationMappingDAO.getMobileDeviceOperationMapping( - TEST_MOBILE_DEVICE_ID, mblOperationId1); - Assert.assertNotNull(mblOperationMapping, "MobileOperationMapping 1 has fetched "); - Assert.assertEquals(TEST_MOBILE_DEVICE_ID, mblOperationMapping.getDeviceId(), - "MobileOperationMapping device id has fetched "); - Assert.assertEquals(mblOperationId1, mblOperationMapping.getOperationId(), - "MobileOperationMapping device id has fetched "); - Assert.assertEquals(MobileDeviceOperationMapping.Status.NEW, - mblOperationMapping.getStatus(), - "MobileOperationMapping status has fetched "); - Assert.assertTrue(mblOperationMapping.getSentDate() == 0, - "MobileOperationMapping sent-date has fetched "); - Assert.assertTrue(mblOperationMapping.getReceivedDate() == 0, - "MobileOperationMapping received-date has fetched "); - } - - //@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest" }) - public void getAllMobileDeviceOperationMappingsOfDeviceTest() - throws MobileDeviceManagementDAOException { - List mblOperationMappings = - mblDeviceOperationMappingDAO.getAllMobileDeviceOperationMappingsOfDevice( - TEST_MOBILE_DEVICE_ID); - Assert.assertNotNull(mblOperationMappings, "MobileOperationMappings have fetched "); - Assert.assertTrue(mblOperationMappings.size() == 2, - "All MobileOperationMappings have fetched "); - for (MobileDeviceOperationMapping mblOperationMapping : mblOperationMappings) { - Assert.assertEquals(TEST_MOBILE_DEVICE_ID, mblOperationMapping.getDeviceId(), - "MobileOperationMapping device id has fetched "); - Assert.assertTrue(mblOperationMapping.getOperationId() > 0, - "MobileOperationMapping operation-id has fetched "); - Assert.assertEquals(MobileDeviceOperationMapping.Status.NEW, - mblOperationMapping.getStatus(), - "MobileOperationMapping status has fetched "); - Assert.assertTrue(mblOperationMapping.getSentDate() == 0, - "MobileOperationMapping sent-date has fetched "); - Assert.assertTrue(mblOperationMapping.getReceivedDate() == 0, - "MobileOperationMapping received-date has fetched "); - } - } - - /**@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest", - "getAllMobileDeviceOperationMappingsOfDeviceTest" })*/ - public void updateMobileDeviceOperationMappingToInProgressTest() - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement preparedStatement = null; - MobileDeviceOperationMapping mblOperationMapping = null; - //Update device-operation to In-Progress state - boolean status = - mblDeviceOperationMappingDAO.updateMobileDeviceOperationMappingToInProgress( - TEST_MOBILE_DEVICE_ID, mblOperationId1); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String selectDBQuery = - "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, STATUS FROM " + - "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; - preparedStatement = conn.prepareStatement(selectDBQuery); - preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID); - preparedStatement.setInt(2, mblOperationId1); - ResultSet resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - mblOperationMapping = new MobileDeviceOperationMapping(); - mblOperationMapping.setDeviceId(resultSet.getString(1)); - mblOperationMapping.setOperationId(resultSet.getInt(2)); - mblOperationMapping.setSentDate(resultSet.getLong(3)); - mblOperationMapping.setStatus(resultSet.getString(4)); - } - - } catch (SQLException e) { - String msg = "Error in retrieving Mobile Operation Mappings data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(status, "MobileOperationMapping 1 has updated "); - Assert.assertNotNull(mblOperationMapping, "MobileOperationMappings have fetched "); - Assert.assertEquals(MobileDeviceOperationMapping.Status.INPROGRESS, - mblOperationMapping.getStatus(), - "MobileOperationMapping status has updated "); - Assert.assertTrue(mblOperationMapping.getSentDate() > 0, - "MobileOperationMapping sent-date has updated "); - } - - /** - @Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest", - "getAllMobileDeviceOperationMappingsOfDeviceTest" })*/ - public void updateMobileDeviceOperationMappingToCompletedTest() - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement preparedStatement = null; - MobileDeviceOperationMapping mblOperationMapping = null; - //Update device-operation to Completed state - boolean status = - mblDeviceOperationMappingDAO.updateMobileDeviceOperationMappingToCompleted( - TEST_MOBILE_DEVICE_ID, mblOperationId1); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String selectDBQuery = - "SELECT DEVICE_ID, OPERATION_ID, RECEIVED_DATE, STATUS FROM " + - "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; - preparedStatement = conn.prepareStatement(selectDBQuery); - preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID); - preparedStatement.setInt(2, mblOperationId1); - ResultSet resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - mblOperationMapping = new MobileDeviceOperationMapping(); - mblOperationMapping.setDeviceId(resultSet.getString(1)); - mblOperationMapping.setOperationId(resultSet.getInt(2)); - mblOperationMapping.setReceivedDate(resultSet.getLong(3)); - mblOperationMapping.setStatus(resultSet.getString(4)); - } - - } catch (SQLException e) { - String msg = "Error in retrieving Mobile Operation Mappings data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(status, "MobileOperationMapping 1 has updated "); - Assert.assertNotNull(mblOperationMapping, "MobileOperationMappings have fetched "); - Assert.assertEquals(MobileDeviceOperationMapping.Status.COMPLETED, - mblOperationMapping.getStatus(), - "MobileOperationMapping status has updated "); - Assert.assertTrue(mblOperationMapping.getReceivedDate() > 0, - "MobileOperationMapping received-date has updated "); - } - - /** - @Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest", - "getAllMobileDeviceOperationMappingsOfDeviceTest", - "updateMobileDeviceOperationMappingToInProgressTest", - "updateMobileDeviceOperationMappingToCompletedTest" })*/ - public void updateMobileDeviceOperationMappingTest() - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement preparedStatement = null; - MobileDeviceOperationMapping mblOperationMapping = new MobileDeviceOperationMapping(); - long currentTime = new java.util.Date().getTime(); - //Update device-operation mapping 1 - mblOperationMapping.setDeviceId(TEST_MOBILE_DEVICE_ID); - mblOperationMapping.setOperationId(mblOperationId1); - mblOperationMapping.setStatus(MobileDeviceOperationMapping.Status.INPROGRESS); - mblOperationMapping.setSentDate(currentTime); - mblOperationMapping.setReceivedDate(currentTime); - boolean status = - mblDeviceOperationMappingDAO.updateMobileDeviceOperationMapping( - mblOperationMapping); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String selectDBQuery = - "SELECT DEVICE_ID, OPERATION_ID, RECEIVED_DATE, SENT_DATE, STATUS FROM " + - "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; - preparedStatement = conn.prepareStatement(selectDBQuery); - preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID); - preparedStatement.setInt(2, mblOperationId1); - ResultSet resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - mblOperationMapping = new MobileDeviceOperationMapping(); - mblOperationMapping.setDeviceId(resultSet.getString(1)); - mblOperationMapping.setOperationId(resultSet.getInt(2)); - mblOperationMapping.setReceivedDate(resultSet.getLong(3)); - mblOperationMapping.setSentDate(resultSet.getLong(4)); - mblOperationMapping.setStatus(resultSet.getString(5)); - } - - } catch (SQLException e) { - String msg = "Error in retrieving Mobile Operation Mappings data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(status, "MobileOperationMapping 1 has updated "); - Assert.assertNotNull(mblOperationMapping, "MobileOperationMappings have fetched "); - Assert.assertEquals(MobileDeviceOperationMapping.Status.INPROGRESS, - mblOperationMapping.getStatus(), - "MobileOperationMapping status has updated "); - Assert.assertTrue(mblOperationMapping.getReceivedDate() == currentTime, - "MobileOperationMapping received-date has updated "); - Assert.assertTrue(mblOperationMapping.getSentDate() == currentTime, - "MobileOperationMapping sent-date has updated "); - } - - /** - @Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest", - "getAllMobileDeviceOperationMappingsOfDeviceTest", - "updateMobileDeviceOperationMappingToInProgressTest" })*/ - public void getAllPendingOperationMappingsOfMobileDeviceTest() - throws MobileDeviceManagementDAOException { - List mblOperationMappings = - mblDeviceOperationMappingDAO.getAllPendingOperationMappingsOfMobileDevice( - TEST_MOBILE_DEVICE_ID); - Assert.assertNotNull(mblOperationMappings, "Pending MobileOperationMappings have fetched "); - Assert.assertTrue(mblOperationMappings.size() == 1, - "All MobileOperationMappings have fetched "); - for (MobileDeviceOperationMapping mblOperationMapping : mblOperationMappings) { - Assert.assertEquals(TEST_MOBILE_DEVICE_ID, mblOperationMapping.getDeviceId(), - "MobileOperationMapping device id has fetched "); - Assert.assertTrue(mblOperationMapping.getOperationId() == mblOperationId2, - "MobileOperationMapping operation-id has fetched "); - Assert.assertEquals(MobileDeviceOperationMapping.Status.NEW, - mblOperationMapping.getStatus(), - "MobileOperationMapping status has fetched "); - Assert.assertTrue(mblOperationMapping.getSentDate() == 0, - "MobileOperationMapping sent-date has fetched "); - Assert.assertTrue(mblOperationMapping.getReceivedDate() == 0, - "MobileOperationMapping received-date has fetched "); - } - } - - /** - @Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest", - "getAllMobileDeviceOperationMappingsOfDeviceTest", - "updateMobileDeviceOperationMappingToInProgressTest", - "updateMobileDeviceOperationMappingToCompletedTest", - "updateMobileDeviceOperationMappingTest" })*/ - public void deleteMobileDeviceOperationMappingTest() - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement preparedStatement = null; - boolean status = - mblDeviceOperationMappingDAO.deleteMobileDeviceOperationMapping( - TEST_MOBILE_DEVICE_ID, mblOperationId1); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String selectDBQuery = - "SELECT DEVICE_ID, OPERATION_ID, RECEIVED_DATE, SENT_DATE, STATUS FROM " + - "AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; - preparedStatement = conn.prepareStatement(selectDBQuery); - preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID); - preparedStatement.setInt(2, mblOperationId1); - ResultSet resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - status = false; - } - } catch (SQLException e) { - String msg = "Error in retrieving MobileFeatureProperty data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(status, "MobileDeviceOperationMapping 1 has deleted "); - } -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java index 56d1bd613e..02f66bf044 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java @@ -92,7 +92,7 @@ public class MobileFeatureDAOTestSuite { try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String query = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE WHERE CODE = ?"; + "SELECT ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE WHERE CODE = ?"; preparedStatement = conn.prepareStatement(query); preparedStatement.setString(1, MBL_FEATURE_CODE); ResultSet resultSet = preparedStatement.executeQuery(); @@ -175,7 +175,7 @@ public class MobileFeatureDAOTestSuite { try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); String query = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?"; + "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?"; stmt = conn.prepareStatement(query); stmt.setString(1, MBL_FEATURE_UPDATED_CODE); ResultSet resultSet = stmt.executeQuery(); @@ -208,7 +208,7 @@ public class MobileFeatureDAOTestSuite { boolean status = mblFeatureDAO.deleteFeatureById(mblFeatureId); try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String query = "SELECT FEATURE_ID, CODE FROM AD_FEATURE WHERE FEATURE_ID = ?"; + String query = "SELECT ID, CODE FROM AD_FEATURE WHERE ID = ?"; stmt = conn.prepareStatement(query); stmt.setInt(1, mblFeatureId); ResultSet resultSet = stmt.executeQuery(); @@ -241,7 +241,7 @@ public class MobileFeatureDAOTestSuite { boolean status = mblFeatureDAO.deleteFeatureByCode(MBL_FEATURE_CODE); try { conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String query = "SELECT FEATURE_ID, CODE FROM AD_FEATURE WHERE CODE = ?"; + String query = "SELECT ID, CODE FROM AD_FEATURE WHERE CODE = ?"; preparedStatement = conn.prepareStatement(query); preparedStatement.setString(1, MBL_FEATURE_CODE); ResultSet resultSet = preparedStatement.executeQuery(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java deleted file mode 100644 index 3b05d09b39..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java +++ /dev/null @@ -1,186 +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.dao; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tomcat.jdbc.pool.DataSource; -import org.apache.tomcat.jdbc.pool.PoolProperties; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileOperationDAOImpl; -import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; -import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes; -import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration; -import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils; - -import java.sql.*; - -/** - * Class for holding unit-tests related to MobileOperationDAO class. - */ -public class MobileOperationDAOTestSuite { - - private static final Log log = LogFactory.getLog(MobileOperationDAOTestSuite.class); - public static final String TEST_MBL_OPR_FEATURE_CODE = "LOCK"; - public static final String TEST_MBL_OPR_UPDATED_FEATURE_CODE = "MUTE"; - public static final long TEST_MBL_OPR_CREATED_DATE = new java.util.Date().getTime(); - private TestDBConfiguration testDBConfiguration; - private MobileOperationDAOImpl mblOperationDAO; - private int mblOperationId; - - @BeforeClass - @Parameters("dbType") - public void setUpDB(String dbTypeStr) throws Exception { - - DBTypes dbType = DBTypes.valueOf(dbTypeStr); - testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType); - - switch (dbType) { - case H2: - MobileDatabaseUtils.createH2DB(testDBConfiguration); - DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource(); - PoolProperties properties = new PoolProperties(); - properties.setUrl(testDBConfiguration.getConnectionURL()); - properties.setDriverClassName(testDBConfiguration.getDriverClassName()); - properties.setUsername(testDBConfiguration.getUsername()); - properties.setPassword(testDBConfiguration.getPassword()); - testDataSource.setPoolProperties(properties); - mblOperationDAO = new MobileOperationDAOImpl(testDataSource); - default: - } - } - - @Test - public void addMobileOperationTest() - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement preparedStatement = null; - MobileOperation mblOperation = new MobileOperation(); - MobileOperation testMblOperation = new MobileOperation(); - mblOperation.setFeatureCode(TEST_MBL_OPR_FEATURE_CODE); - mblOperation.setCreatedDate(TEST_MBL_OPR_CREATED_DATE); - mblOperationId = mblOperationDAO.addMobileOperation(mblOperation); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String selectDBQuery = - "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM AD_OPERATION WHERE OPERATION_ID = ?"; - preparedStatement = conn.prepareStatement(selectDBQuery); - preparedStatement.setInt(1, mblOperationId); - ResultSet resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - testMblOperation.setOperationId(resultSet.getInt(1)); - testMblOperation.setFeatureCode(resultSet.getString(2)); - testMblOperation.setCreatedDate(resultSet.getLong(3)); - } - } catch (SQLException e) { - String msg = "Error in retrieving Mobile Operation data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(mblOperationId > 0, "MobileOperation has added "); - Assert.assertEquals(TEST_MBL_OPR_FEATURE_CODE, testMblOperation.getFeatureCode(), - "MobileOperation feature code has persisted "); - Assert.assertEquals(TEST_MBL_OPR_CREATED_DATE, testMblOperation.getCreatedDate(), - "MobileOperation created-date has persisted "); - } - - @Test(dependsOnMethods = { "addMobileOperationTest" }) - public void getMobileOperationTest() - throws MobileDeviceManagementDAOException { - - MobileOperation mobileOperation = mblOperationDAO.getMobileOperation(mblOperationId); - Assert.assertEquals(TEST_MBL_OPR_CREATED_DATE, mobileOperation.getCreatedDate(), - "MobileOperation created-date has retrieved "); - Assert.assertEquals(TEST_MBL_OPR_FEATURE_CODE, mobileOperation.getFeatureCode(), - "MobileOperation feature-code has retrieved "); - } - - @Test(dependsOnMethods = { "addMobileOperationTest", "getMobileOperationTest" }) - public void updateMobileOperationTest() - throws MobileDeviceManagementDAOException { - - Connection conn = null; - PreparedStatement preparedStatement = null; - long updatedDate = new java.util.Date().getTime(); - MobileOperation mblOperation = new MobileOperation(); - MobileOperation testMblOperation = new MobileOperation(); - mblOperation.setFeatureCode(TEST_MBL_OPR_UPDATED_FEATURE_CODE); - mblOperation.setCreatedDate(updatedDate); - mblOperation.setOperationId(mblOperationId); - boolean status = mblOperationDAO.updateMobileOperation(mblOperation); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String selectDBQuery = - "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM AD_OPERATION WHERE OPERATION_ID = ?"; - preparedStatement = conn.prepareStatement(selectDBQuery); - preparedStatement.setInt(1, mblOperationId); - ResultSet resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - testMblOperation.setOperationId(resultSet.getInt(1)); - testMblOperation.setFeatureCode(resultSet.getString(2)); - testMblOperation.setCreatedDate(resultSet.getLong(3)); - } - } catch (SQLException e) { - String msg = "Error in retrieving Mobile Operation data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(status, "MobileOperation has updated "); - Assert.assertEquals(TEST_MBL_OPR_UPDATED_FEATURE_CODE, testMblOperation.getFeatureCode(), - "MobileOperation feature code has updated "); - Assert.assertEquals(updatedDate, testMblOperation.getCreatedDate(), - "MobileOperation created-date has updated "); - } - - @Test(dependsOnMethods = { "addMobileOperationTest", "getMobileOperationTest", - "updateMobileOperationTest" }) - public void deleteMobileDeviceTest() - throws MobileDeviceManagementDAOException { - - Connection conn = null; - PreparedStatement preparedStatement = null; - boolean deleted = mblOperationDAO.deleteMobileOperation(mblOperationId); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String selectDBQuery = - "SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM AD_OPERATION WHERE OPERATION_ID = ?"; - preparedStatement = conn.prepareStatement(selectDBQuery); - preparedStatement.setInt(1, mblOperationId); - ResultSet resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - deleted = false; - } - } catch (SQLException e) { - String msg = "Error in retrieving Mobile Operation data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(deleted, "MobileOperation has deleted "); - } -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationPropertyDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationPropertyDAOTestSuite.java deleted file mode 100644 index 1342d61045..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationPropertyDAOTestSuite.java +++ /dev/null @@ -1,237 +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.dao; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tomcat.jdbc.pool.DataSource; -import org.apache.tomcat.jdbc.pool.PoolProperties; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileOperationDAOImpl; -import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileOperationPropertyDAOImpl; -import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; -import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty; -import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes; -import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration; -import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils; - -import java.sql.*; -import java.util.ArrayList; -import java.util.List; - -/** - * - * Class for holding unit-tests related to MobileOperationPropertyDAO class. - * - */ -public class MobileOperationPropertyDAOTestSuite { - - private static final Log log = LogFactory.getLog(MobileOperationPropertyDAOTestSuite.class); - public static final String TEST_MBL_OPR_FEATURE_CODE = "LOCK"; - public static final long TEST_MBL_OPR_CREATED_DATE = new java.util.Date().getTime(); - public static final String TEST_MBL_OPR_PROPERTY_SSID = "SSID"; - public static final String TEST_MBL_OPR_PROPERTY_SSID_VALUE = "wso2"; - public static final String TEST_MBL_OPR_PROPERTY_PWD = "PASSWORD"; - public static final String TEST_MBL_OPR_PROPERTY_PWD_VALUE = "wso2"; - public static final String TEST_MBL_OPR_PROPERTY_PWD_UPDATED_VALUE = "wso2mdm"; - private int mblOperationId; - private TestDBConfiguration testDBConfiguration; - private MobileOperationPropertyDAOImpl mobileOperationPropertyDAO; - private MobileOperationDAOImpl mblOperationDAO; - - @BeforeClass - @Parameters("dbType") - public void setUpDB(String dbTypeStr) throws Exception { - - DBTypes dbType = DBTypes.valueOf(dbTypeStr); - testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType); - - switch (dbType) { - case H2: - MobileDatabaseUtils.createH2DB(testDBConfiguration); - DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource(); - PoolProperties properties = new PoolProperties(); - properties.setUrl(testDBConfiguration.getConnectionURL()); - properties.setDriverClassName(testDBConfiguration.getDriverClassName()); - properties.setUsername(testDBConfiguration.getUsername()); - properties.setPassword(testDBConfiguration.getPassword()); - testDataSource.setPoolProperties(properties); - mobileOperationPropertyDAO = new MobileOperationPropertyDAOImpl(testDataSource); - mblOperationDAO = new MobileOperationDAOImpl(testDataSource); - default: - } - } - - @Test - public void addMobileOperationPropertyTest() - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement preparedStatement = null; - MobileOperation mblOperation = new MobileOperation(); - MobileOperationProperty operationProperty = new MobileOperationProperty(); - List properties = new ArrayList(); - //Add a new Operation to the database - MobileOperation testMblOperation = new MobileOperation(); - mblOperation.setFeatureCode(TEST_MBL_OPR_FEATURE_CODE); - mblOperation.setCreatedDate(TEST_MBL_OPR_CREATED_DATE); - mblOperationId = mblOperationDAO.addMobileOperation(mblOperation); - //Add property1 - operationProperty.setOperationId(mblOperationId); - operationProperty.setProperty(TEST_MBL_OPR_PROPERTY_SSID); - operationProperty.setValue(TEST_MBL_OPR_PROPERTY_SSID_VALUE); - boolean status1 = mobileOperationPropertyDAO.addMobileOperationProperty(operationProperty); - - //add property2 - operationProperty = new MobileOperationProperty(); - operationProperty.setOperationId(mblOperationId); - operationProperty.setProperty(TEST_MBL_OPR_PROPERTY_PWD); - operationProperty.setValue(TEST_MBL_OPR_PROPERTY_PWD_VALUE); - boolean status2 = mobileOperationPropertyDAO.addMobileOperationProperty(operationProperty); - - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String selectDBQuery = - "SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE OPERATION_ID = ?"; - preparedStatement = conn.prepareStatement(selectDBQuery); - preparedStatement.setInt(1, mblOperationId); - ResultSet resultSet = preparedStatement.executeQuery(); - while (resultSet.next()) { - operationProperty = new MobileOperationProperty(); - operationProperty.setOperationId(resultSet.getInt(1)); - operationProperty.setProperty(resultSet.getString(2)); - operationProperty.setValue(resultSet.getString(3)); - properties.add(operationProperty); - } - - } catch (SQLException e) { - String msg = "Error in retrieving Mobile Operation Property data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(status1, "MobileOperationProperty1 has added "); - Assert.assertTrue(status2, "MobileOperationProperty2 has added "); - Assert.assertTrue(properties.size() == 2, "MobileOperationProperties have retrieved "); - - for (MobileOperationProperty mobileOperationProperty : properties) { - Assert.assertNotNull(mobileOperationProperty.getProperty(), - "MobileOperationProperty property has persisted "); - Assert.assertNotNull(mobileOperationProperty.getValue(), - "MobileOperationProperty value has persisted "); - } - } - - @Test(dependsOnMethods = { "addMobileOperationPropertyTest" }) - public void getMobileOperationPropertyTest() - throws MobileDeviceManagementDAOException { - MobileOperationProperty mobileOperationProperty = mobileOperationPropertyDAO - .getMobileOperationProperty(mblOperationId, TEST_MBL_OPR_PROPERTY_PWD); - Assert.assertEquals(mblOperationId, mobileOperationProperty.getOperationId(), - "MobileOperationProperty operation-id has retrieved "); - Assert.assertEquals(TEST_MBL_OPR_PROPERTY_PWD, mobileOperationProperty.getProperty(), - "MobileOperationProperty property has retrieved "); - Assert.assertEquals(TEST_MBL_OPR_PROPERTY_PWD_VALUE, mobileOperationProperty.getValue(), - "MobileOperationProperty property-value has retrieved "); - } - - @Test(dependsOnMethods = { "addMobileOperationPropertyTest" }) - public void getAllMobileOperationPropertiesOfOperationTest() - throws MobileDeviceManagementDAOException { - List mobileOperationProperties = mobileOperationPropertyDAO - .getAllMobileOperationPropertiesOfOperation(mblOperationId); - Assert.assertTrue(mobileOperationProperties.size() == 2, - "MobileOperationProperties of operation has retrieved"); - } - - @Test(dependsOnMethods = { "addMobileOperationPropertyTest", "getMobileOperationPropertyTest", - "getAllMobileOperationPropertiesOfOperationTest" }) - public void updateMobileOperationPropertyTest() - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement preparedStatement = null; - MobileOperationProperty mblOperationProperty = new MobileOperationProperty(); - MobileOperationProperty testMblOperationProperty = new MobileOperationProperty(); - mblOperationProperty.setOperationId(mblOperationId); - mblOperationProperty.setProperty(TEST_MBL_OPR_PROPERTY_PWD); - mblOperationProperty.setValue(TEST_MBL_OPR_PROPERTY_PWD_UPDATED_VALUE); - - boolean status = - mobileOperationPropertyDAO.updateMobileOperationProperty(mblOperationProperty); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String selectDBQuery = - "SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE" + - " OPERATION_ID = ? AND PROPERTY = ?"; - preparedStatement = conn.prepareStatement(selectDBQuery); - preparedStatement.setInt(1, mblOperationId); - preparedStatement.setString(2, TEST_MBL_OPR_PROPERTY_PWD); - ResultSet resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - testMblOperationProperty.setOperationId(resultSet.getInt(1)); - testMblOperationProperty.setProperty(resultSet.getString(2)); - testMblOperationProperty.setValue(resultSet.getString(3)); - } - } catch (SQLException e) { - String msg = "Error in retrieving MobileOperationProperty data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(status, "MobileOperationProperty has updated "); - Assert.assertEquals(TEST_MBL_OPR_PROPERTY_PWD_UPDATED_VALUE, - testMblOperationProperty.getValue(), - "MobileOperationProperty value has updated "); - } - - @Test(dependsOnMethods = { "addMobileOperationPropertyTest", "getMobileOperationPropertyTest", - "getAllMobileOperationPropertiesOfOperationTest", - "updateMobileOperationPropertyTest" }) - public void deleteMobileOperationPropertiesOfOperationTest() - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement preparedStatement = null; - boolean status = - mobileOperationPropertyDAO.deleteMobileOperationProperties(mblOperationId); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String selectDBQuery = - "SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE" + - " OPERATION_ID = ?"; - preparedStatement = conn.prepareStatement(selectDBQuery); - preparedStatement.setInt(1, mblOperationId); - ResultSet resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - status = false; - } - } catch (SQLException e) { - String msg = "Error in retrieving MobileOperationProperty data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(status, "MobileOperationProperty has deleted "); - } -} 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 58210317e2..78b5b7b8b3 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 @@ -23,12 +23,12 @@ CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( -- Table `AD_FEATURE` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `AD_FEATURE` ( - `FEATURE_ID` INT NOT NULL AUTO_INCREMENT , + `ID` INT NOT NULL AUTO_INCREMENT , `CODE` VARCHAR(45) NOT NULL, `NAME` VARCHAR(100) NULL , `DESCRIPTION` VARCHAR(200) NULL , `DEVICE_TYPE` VARCHAR(50) NULL , - PRIMARY KEY (`FEATURE_ID`) ); + PRIMARY KEY (`ID`) ); -- ----------------------------------------------------- -- Table `AD_OPERATION` @@ -39,40 +39,6 @@ CREATE TABLE IF NOT EXISTS `AD_OPERATION` ( `CREATED_DATE` BIGINT NULL , PRIMARY KEY (`OPERATION_ID`)); --- ----------------------------------------------------- --- Table `AD_DEVICE_OPERATION_MAPPING` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `AD_DEVICE_OPERATION_MAPPING` ( - `DEVICE_ID` VARCHAR(45) NOT NULL , - `OPERATION_ID` INT NOT NULL , - `SENT_DATE` BIGINT NULL , - `RECEIVED_DATE` BIGINT NULL , - `STATUS` VARCHAR(10) NOT NULL , - PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) , - CONSTRAINT `fk_AD_DEVICE_OPERATION_AD_DEVICE` - FOREIGN KEY (`DEVICE_ID` ) - REFERENCES `AD_DEVICE` (`DEVICE_ID` ) - ON DELETE NO ACTION - ON UPDATE NO ACTION, - CONSTRAINT `fk_AD_DEVICE_OPERATION_AD_OPERATION1` - FOREIGN KEY (`OPERATION_ID` ) - REFERENCES `AD_OPERATION` (`OPERATION_ID` ) - ON DELETE NO ACTION - ON UPDATE NO ACTION); - --- ----------------------------------------------------- --- Table `AD_OPERATION_PROPERTY` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `AD_OPERATION_PROPERTY` ( - `OPERATION_ID` INT NOT NULL , - `PROPERTY` VARCHAR(45) NOT NULL , - `VALUE` TEXT NULL , - PRIMARY KEY (`OPERATION_ID`, `PROPERTY`) , - CONSTRAINT `fk_AD_OPERATION_PROPERTY_AD_OPERATION1` - FOREIGN KEY (`OPERATION_ID` ) - REFERENCES `AD_OPERATION` (`OPERATION_ID` ) - ON DELETE NO ACTION - ON UPDATE NO ACTION); -- ----------------------------------------------------- -- Table `AD_FEATURE_PROPERTY` @@ -83,6 +49,6 @@ CREATE TABLE IF NOT EXISTS `AD_FEATURE_PROPERTY` ( PRIMARY KEY (`PROPERTY`) , CONSTRAINT `fk_AD_FEATURE_PROPERTY_AD_FEATURE1` FOREIGN KEY (`FEATURE_ID` ) - REFERENCES `AD_FEATURE` (`FEATURE_ID` ) + REFERENCES `AD_FEATURE` (`ID` ) ON DELETE NO ACTION ON UPDATE NO ACTION); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml index 667486519b..68f54744ad 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml @@ -29,10 +29,7 @@ - - - diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/h2.sql index 1f280205c4..09b3cc91c3 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/h2.sql @@ -3,7 +3,7 @@ -- Table `AD_DEVICE` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( - `ANDROID_DEVICE_ID` VARCHAR(45) NOT NULL, + `DEVICE_ID` VARCHAR(45) NOT NULL, `GCM_TOKEN` VARCHAR(45) NULL DEFAULT NULL, `DEVICE_INFO` VARCHAR(8000) NULL DEFAULT NULL, `IMEI` VARCHAR(45) NULL DEFAULT NULL, @@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS `AD_DEVICE` ( `SERIAL` VARCHAR(45) NULL DEFAULT NULL, `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, - PRIMARY KEY (`ANDROID_DEVICE_ID`)); + PRIMARY KEY (`DEVICE_ID`)); -- ----------------------------------------------------- -- Table `AD_FEATURE` diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/mssql.sql index 23cda9006a..f95ec0f913 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/mssql.sql @@ -2,7 +2,7 @@ -- Table `AD_DEVICE` -- ----------------------------------------------------- CREATE TABLE AD_DEVICE ( - ANDROID_DEVICE_ID VARCHAR(45) NOT NULL, + DEVICE_ID VARCHAR(45) NOT NULL, GCM_TOKEN VARCHAR(45) NULL DEFAULT NULL, DEVICE_INFO VARCHAR(8000) NULL DEFAULT NULL, IMEI VARCHAR(45) NULL DEFAULT NULL, @@ -15,7 +15,7 @@ CREATE TABLE AD_DEVICE ( SERIAL VARCHAR(45) NULL DEFAULT NULL, MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL, DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL, - PRIMARY KEY (ANDROID_DEVICE_ID)); + PRIMARY KEY (DEVICE_ID)); -- ----------------------------------------------------- -- Table `AD_FEATURE` diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/postgres.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/postgres.sql index af5c9a5cf1..8c3f0591bf 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/postgres.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/postgres.sql @@ -2,7 +2,7 @@ -- Table AD_DEVICE -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS AD_DEVICE ( - ID VARCHAR(45) NOT NULL , + DEVICE_ID VARCHAR(45) NOT NULL , DEVICE_INFO VARCHAR(500) NULL DEFAULT NULL, GCM_TOKEN VARCHAR(45) NULL DEFAULT NULL, IMEI VARCHAR(45) NULL DEFAULT NULL, @@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS AD_DEVICE ( SERIAL VARCHAR(45) NULL DEFAULT NULL, MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL, DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL, - PRIMARY KEY (ID) + PRIMARY KEY (DEVICE_ID) ); -- ----------------------------------------------------- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/oracle.sql index 505330b66c..952b4d817b 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/oracle.sql @@ -41,7 +41,7 @@ CREATE TABLE WIN_FEATURE_PROPERTY ( PRIMARY KEY (PROPERTY), CONSTRAINT fk_WIN_FEATURE_PROPERTY_WIN_FEATURE1 FOREIGN KEY (FEATURE_ID) - REFERENCES WIN_FEATURE (FEATURE_ID) + REFERENCES WIN_FEATURE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION); / From 78f0ba2cdf844fafc5c2e6a0f1d643295e680e3e Mon Sep 17 00:00:00 2001 From: harshanl Date: Wed, 28 Oct 2015 20:07:03 +0530 Subject: [PATCH 08/22] Added feature addition to the plugin initialization. --- ...leDeviceManagementDAOFactoryInterface.java | 2 +- .../mgt/mobile/dao/MobileFeatureDAO.java | 11 +- .../mobile/dao/impl/MobileFeatureDAOImpl.java | 5 + .../impl/android/AndroidDeviceManager.java | 7 +- .../impl/android/AndroidFeatureManager.java | 142 +++++++++++++++++- .../impl/android/dao/AndroidDAOFactory.java | 3 +- .../dao/impl/AndroidFeatureDAOImpl.java | 53 +++++-- .../impl/windows/WindowsFeatureManager.java | 14 +- .../impl/windows/dao/WindowsDAOFactory.java | 2 +- .../util/MobileDeviceManagementUtil.java | 15 ++ .../src/main/resources/conf/mobile-config.xml | 60 ++------ 11 files changed, 238 insertions(+), 76 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactoryInterface.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactoryInterface.java index 3dd2336ef1..946aa6d732 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactoryInterface.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactoryInterface.java @@ -30,7 +30,7 @@ public interface MobileDeviceManagementDAOFactoryInterface { public MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO(); - public MobileFeatureDAO getMobileFeatureDao(); + public MobileFeatureDAO getMobileFeatureDAO(); 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/dao/MobileFeatureDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java index 627a670bd9..55c77424b7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java @@ -32,11 +32,20 @@ public interface MobileFeatureDAO { * Adds a new MobileFeature to Mobile-Feature table. * * @param mobileFeature MobileFeature object that holds data related to the feature to be inserted. - * @return The id of inserted MobileFeature. + * @return boolean status of the operation. * @throws MobileDeviceManagementDAOException */ boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException; + /** + * Adda a list of MobileFeatures to Mobile-Feature table. + * + * @param mobileFeatures List of MobileFeature objects. + * @return boolean status of the operation. + * @throws MobileDeviceManagementDAOException + */ + boolean addFeatures(List mobileFeatures) throws MobileDeviceManagementDAOException; + /** * Updates a MobileFeature in Mobile-Feature table. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java index 666e33e2d6..ed5540af78 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java @@ -81,6 +81,11 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { return status; } + @Override + public boolean addFeatures(List mobileFeatures) throws MobileDeviceManagementDAOException { + return false; + } + @Override public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { 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 73b3d9835e..4bccafb469 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 @@ -62,10 +62,13 @@ public class AndroidDeviceManager implements DeviceManager { try { licenseManager .addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, defaultLicense); + featureManager.addSupportedFeaturesToDB(); } catch (LicenseManagementException e) { log.error("Error occurred while adding default license for Android devices", e); - } - } + } catch (DeviceManagementException e) { + log.error("Error occurred while adding supported device features for Android platform", e); + } + } @Override public FeatureManager getFeatureManager() { 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 999dfb655b..ed23a360dd 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 @@ -41,12 +41,11 @@ public class AndroidFeatureManager implements FeatureManager { public AndroidFeatureManager() { mobileDeviceManagementDAOFactory = new AndroidDAOFactory(); - this.featureDAO = mobileDeviceManagementDAOFactory.getMobileFeatureDao(); + this.featureDAO = mobileDeviceManagementDAOFactory.getMobileFeatureDAO(); } @Override public boolean addFeature(Feature feature) throws DeviceManagementException { - try { AndroidDAOFactory.beginTransaction(); MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature); @@ -63,11 +62,32 @@ public class AndroidFeatureManager implements FeatureManager { } } + @Override + public boolean addFeatures(List features) throws DeviceManagementException { + List mobileFeatures = new ArrayList(); + for (Feature feature:features) { + mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature)); + } + try { + AndroidDAOFactory.beginTransaction(); + featureDAO.addFeatures(mobileFeatures); + AndroidDAOFactory.commitTransaction(); + return true; + } catch (MobileDeviceManagementDAOException e) { + try { + AndroidDAOFactory.rollbackTransaction(); + } catch (MobileDeviceManagementDAOException e1) { + log.warn("Error occurred while roll-backing the transaction", e); + } + throw new DeviceManagementException("Error occurred while adding the features", e); + } + } + @Override public Feature getFeature(String name) throws DeviceManagementException { try { MobileFeature mobileFeature = featureDAO.getFeatureByCode(name); - Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature); + Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature); return feature; } catch (MobileDeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while retrieving the feature", e); @@ -76,7 +96,6 @@ public class AndroidFeatureManager implements FeatureManager { @Override public List getFeatures() throws DeviceManagementException { - List featureList = new ArrayList(); try { List mobileFeatures = featureDAO.getAllFeatures(); @@ -86,13 +105,13 @@ public class AndroidFeatureManager implements FeatureManager { return featureList; } catch (MobileDeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " + - "Android platform", e); + "Android platform", e); } } @Override public boolean removeFeature(String code) throws DeviceManagementException { - boolean status = false; + boolean status; try { AndroidDAOFactory.beginTransaction(); featureDAO.deleteFeatureByCode(code); @@ -109,4 +128,115 @@ public class AndroidFeatureManager implements FeatureManager { return status; } + @Override + public boolean addSupportedFeaturesToDB() throws DeviceManagementException { + synchronized (this) { + List supportedFeatures = getSupportedFeatures(); + List existingFeatures = this.getFeatures(); + List missingFeatures = MobileDeviceManagementUtil. + getMissingFeatures(supportedFeatures, existingFeatures); + return this.addFeatures(missingFeatures); + } + } + + //Get the supported feature list. + private static List getSupportedFeatures() { + List supportedFeatures = new ArrayList(); + Feature feature = new Feature(); + feature.setCode("DEVICE_LOCK"); + feature.setName("Device Lock"); + feature.setDescription("Lock the device"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("DEVICE_LOCATION"); + feature.setName("Location"); + feature.setDescription("Request coordinates of device location"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("WIFI"); + feature.setName("wifi"); + feature.setDescription("Setting up wifi configuration"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("CAMERA"); + feature.setName("camera"); + feature.setDescription("Enable or disable camera"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("EMAIL"); + feature.setName("Email"); + feature.setDescription("Configure email settings"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("DEVICE_MUTE"); + feature.setName("mute"); + feature.setDescription("Enable mute in the device"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("DEVICE_INFO"); + feature.setName("Device info"); + feature.setDescription("Request device information"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("ENTERPRISE_WIPE"); + feature.setName("Enterprise Wipe"); + feature.setDescription("Remove enterprise applications"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("CLEAR_PASSWORD"); + feature.setName("Clear Password"); + feature.setDescription("Clear current password"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("WIPE_DATA"); + feature.setName("Wipe Data"); + feature.setDescription("Factory reset the device"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("APPLICATION_LIST"); + feature.setName("Application List"); + feature.setDescription("Request list of current installed applications"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("CHANGE_LOCK_CODE"); + feature.setName("Change Lock-code"); + feature.setDescription("Change current lock code"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("INSTALL_APPLICATION"); + feature.setName("Install App"); + feature.setDescription("Install Enterprise or Market application"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("UNINSTALL_APPLICATION"); + feature.setName("Uninstall App"); + feature.setDescription("Uninstall application"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("BLACKLIST_APPLICATIONS"); + feature.setName("Blacklist app"); + feature.setDescription("Blacklist applications"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("ENCRYPT_STORAGE"); + feature.setName("Encrypt storage"); + feature.setDescription("Encrypt storage"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("DEVICE_RING"); + feature.setName("Ring"); + feature.setDescription("Ring the device"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("PASSCODE_POLICY"); + feature.setName("Password Policy"); + feature.setDescription("Set passcode policy"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("NOTIFICATION"); + feature.setName("Message"); + feature.setDescription("Send message"); + supportedFeatures.add(feature); + return supportedFeatures; + } } \ No newline at end of file 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 dd116e5190..9e2317c840 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 @@ -60,7 +60,8 @@ public class AndroidDAOFactory extends MobileDeviceManagementDAOFactory return null; } - @Override public MobileFeatureDAO getMobileFeatureDao() { + @Override + public MobileFeatureDAO getMobileFeatureDAO() { return new AndroidFeatureDAOImpl(); } 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 index d597d3a5df..4ebb8b55ef 100644 --- 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 @@ -48,10 +48,9 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { @Override public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; boolean status = false; - Connection conn = null; + Connection conn; try { conn = AndroidDAOFactory.getConnection(); String sql = "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; @@ -61,11 +60,37 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { 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); + mobileFeature.getName() + "' into the metadata repository", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public boolean addFeatures(List mobileFeatures) throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + MobileFeature mobileFeature; + boolean status = false; + Connection conn; + try { + conn = AndroidDAOFactory.getConnection(); + stmt = conn.prepareStatement("INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"); + for (int i = 0; i < mobileFeatures.size(); i++) { + mobileFeature = mobileFeatures.get(i); + stmt.setString(1, mobileFeature.getCode()); + stmt.setString(2, mobileFeature.getName()); + stmt.setString(3, mobileFeature.getDescription()); + stmt.addBatch(); + } + stmt.executeBatch(); + status = true; + } catch (SQLException e) { + throw new AndroidFeatureManagementDAOException( + "Error occurred while adding android features into the metadata repository", e); } finally { MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -75,7 +100,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { @Override public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { boolean status = false; - Connection conn = null; + Connection conn; PreparedStatement stmt = null; try { conn = AndroidDAOFactory.getConnection(); @@ -112,7 +137,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { PreparedStatement stmt = null; boolean status = false; - Connection conn = null; + Connection conn; try { conn = AndroidDAOFactory.getConnection(); String sql = "DELETE FROM AD_FEATURE WHERE ID = ?"; @@ -135,7 +160,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { MobileDeviceManagementDAOException { PreparedStatement stmt = null; boolean status = false; - Connection conn = null; + Connection conn; try { conn = AndroidDAOFactory.getConnection(); String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?"; @@ -146,7 +171,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { } catch (SQLException e) { throw new AndroidFeatureManagementDAOException( "Error occurred while deleting android feature '" + - mblFeatureCode + "' from Android database.", e); + mblFeatureCode + "' from Android database.", e); } finally { MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); } @@ -158,7 +183,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { MobileDeviceManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; - Connection conn = null; + Connection conn; try { conn = AndroidDAOFactory.getConnection(); String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE ID = ?"; @@ -193,7 +218,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { MobileDeviceManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; - Connection conn = null; + Connection conn; try { conn = AndroidDAOFactory.getConnection(); @@ -217,7 +242,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { } catch (SQLException e) { throw new AndroidFeatureManagementDAOException( "Error occurred while retrieving android feature '" + - mblFeatureCode + "' from the Android database.", e); + mblFeatureCode + "' from the Android database.", e); } finally { MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); AndroidDAOFactory.closeConnection(); @@ -235,7 +260,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { PreparedStatement stmt = null; ResultSet rs = null; - Connection conn = null; + Connection conn; List features = new ArrayList(); try { @@ -259,10 +284,10 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO { return features; } catch (SQLException e) { throw new AndroidFeatureManagementDAOException("Error occurred while retrieving all " + - "android features from the android database.", e); + "android features from the android database.", e); } finally { MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); AndroidDAOFactory.closeConnection(); } } -} +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java index 99067b7eb1..3bee4d2d07 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java @@ -41,7 +41,7 @@ public class WindowsFeatureManager implements FeatureManager { public WindowsFeatureManager() { mobileDeviceManagementDAOFactory = new WindowsDAOFactory(); - this.featureDAO = mobileDeviceManagementDAOFactory.getMobileFeatureDao(); + this.featureDAO = mobileDeviceManagementDAOFactory.getMobileFeatureDAO(); } @Override @@ -59,6 +59,11 @@ public class WindowsFeatureManager implements FeatureManager { } } + @Override + public boolean addFeatures(List list) throws DeviceManagementException { + return false; + } + @Override public Feature getFeature(String name) throws DeviceManagementException { try { @@ -88,7 +93,7 @@ public class WindowsFeatureManager implements FeatureManager { @Override public boolean removeFeature(String code) throws DeviceManagementException { - boolean status = false; + boolean status; try { WindowsDAOFactory.beginTransaction(); featureDAO.deleteFeatureByCode(code); @@ -101,4 +106,9 @@ public class WindowsFeatureManager implements FeatureManager { return status; } + @Override + public boolean addSupportedFeaturesToDB() throws DeviceManagementException { + return false; + } + } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java index 3c1ba0424b..fa39d2ae08 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java @@ -60,7 +60,7 @@ public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory } @Override - public MobileFeatureDAO getMobileFeatureDao() { + public MobileFeatureDAO getMobileFeatureDAO() { return null; } 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 768c55d4c3..dcb4688b33 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 @@ -298,4 +298,19 @@ public class MobileDeviceManagementUtil { e.getMessage(), e); } } + + public static List getMissingFeatures(List supportedFeatures, List existingFeatures) { + HashMap featureHashMap = new HashMap(); + for (Feature feature: existingFeatures) { + featureHashMap.put(feature.getCode(),feature); + } + List missingFeatures = new ArrayList(); + for (Feature supportedFeature : supportedFeatures) { + if (featureHashMap.get(supportedFeature.getCode()) != null) { + continue; + } + missingFeatures.add(supportedFeature); + } + return missingFeatures; + } } 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 c4c5c8f0e7..06076bbcb5 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 @@ -19,53 +19,17 @@ - - - - jdbc/MobileAndroidDM_DS - - - - - jdbc/MobileWindowsDM_DS - - - + + + + jdbc/MobileAndroidDM_DS + + + + + jdbc/MobileWindowsDM_DS + + + - - - - 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 - - - From 58ae783a496355d76b533c11b23a203cdd59b9a7 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 28 Oct 2015 20:39:10 +0530 Subject: [PATCH 09/22] Fixing issues uncovered while running -Dsetup option with non-existent plugin based database scripts --- .../util/MobileDeviceManagementSchemaInitializer.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementSchemaInitializer.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementSchemaInitializer.java index 6af99b1e97..f0071a85f5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementSchemaInitializer.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementSchemaInitializer.java @@ -45,21 +45,18 @@ public final class MobileDeviceManagementSchemaInitializer extends DatabaseCreat return pluginType; } - public void setPluginType(String pluginType) { - this.pluginType = pluginType; - } - public MobileDeviceManagementSchemaInitializer(DataSource dataSource, String pType) { super(dataSource); this.pluginType = pType; } protected String getDbScriptLocation(String databaseType) { - String scriptName = databaseType + "_" + getPluginType() + ".sql"; + String scriptName = databaseType + ".sql"; + String scriptLocation = setupSQLScriptBaseLocation + this.getPluginType() + File.separator + scriptName; if (log.isDebugEnabled()) { - log.debug("Loading database script from :" + scriptName); + log.debug("Loading database script from :" + scriptLocation); } - return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName; + return scriptLocation; } } From 3005a8906efa5104c221d99dd12eed2dae426f16 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 28 Oct 2015 20:43:12 +0530 Subject: [PATCH 10/22] Renaming postgres.sql to postgresql.sql --- .../dbscripts/plugins/android/{postgres.sql => postgresql.sql} | 0 .../dbscripts/plugins/ios/{postgres.sql => postgresql.sql} | 0 .../dbscripts/plugins/windows/{postgres.sql => postgresql.sql} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/{postgres.sql => postgresql.sql} (100%) rename features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/{postgres.sql => postgresql.sql} (100%) rename features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/{postgres.sql => postgresql.sql} (100%) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/postgres.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/postgresql.sql similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/postgres.sql rename to features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/android/postgresql.sql diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgres.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgresql.sql similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgres.sql rename to features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgresql.sql diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/postgres.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/postgresql.sql similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/postgres.sql rename to features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/postgresql.sql From 1aee8edace98aff7120cd0ad20fa3d4a9fa0f523 Mon Sep 17 00:00:00 2001 From: harshanl Date: Wed, 28 Oct 2015 22:39:31 +0530 Subject: [PATCH 11/22] updated android featuremgr --- .../mgt/mobile/impl/android/AndroidFeatureManager.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 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/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 31e980f9d5..ada8eb7d32 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 @@ -65,7 +65,7 @@ public class AndroidFeatureManager implements FeatureManager { @Override public boolean addFeatures(List features) throws DeviceManagementException { List mobileFeatures = new ArrayList(); - for (Feature feature:features) { + for (Feature feature : features) { mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature)); } try { @@ -134,8 +134,11 @@ public class AndroidFeatureManager implements FeatureManager { List supportedFeatures = getSupportedFeatures(); List existingFeatures = this.getFeatures(); List missingFeatures = MobileDeviceManagementUtil. - getMissingFeatures(supportedFeatures, existingFeatures); - return this.addFeatures(missingFeatures); + getMissingFeatures(supportedFeatures, existingFeatures); + if (missingFeatures.size() > 0) { + return this.addFeatures(missingFeatures); + } + return true; } } From 9adfb05b37ed705fe5316d49d369bc79196c55d1 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Thu, 29 Oct 2015 14:12:52 +0530 Subject: [PATCH 12/22] refactored WindowsFeatureManager --- .../impl/windows/WindowsDeviceManager.java | 5 + .../impl/windows/WindowsFeatureManager.java | 97 ++++++++++++++++--- .../impl/windows/dao/WindowsDAOFactory.java | 3 +- .../dao/impl/WindowsFeatureDAOImpl.java | 46 +++++++-- .../dbscripts/plugins/windows/mssql.sql | 4 +- .../dbscripts/plugins/windows/mysql.sql | 13 --- .../dbscripts/plugins/windows/oracle.sql | 14 --- .../dbscripts/plugins/windows/postgresql.sql | 13 --- 8 files changed, 126 insertions(+), 69 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java index 18e9d6360f..106b1def71 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java @@ -57,11 +57,16 @@ public class WindowsDeviceManager implements DeviceManager { public WindowsDeviceManager() { this.daoFactory = new WindowsDAOFactory(); this.licenseManager = new RegistryBasedLicenseManager(); + License defaultLicense = WindowsPluginUtils.getDefaultLicense(); + try { licenseManager.addLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, defaultLicense); + featureManager.addSupportedFeaturesToDB(); } catch (LicenseManagementException e) { log.error("Error occurred while adding default license for Windows devices", e); + } catch (DeviceManagementException e) { + log.error("Error occurred while adding supported device features for Windows platform", e); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java index 889d40f26f..21396b766c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java @@ -18,12 +18,9 @@ */ package org.wso2.carbon.device.mgt.mobile.impl.windows; -import org.apache.commons.logging.Log; -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.dao.AbstractMobileDeviceManagementDAOFactory; 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; @@ -37,7 +34,6 @@ import java.util.List; public class WindowsFeatureManager implements FeatureManager { private MobileFeatureDAO featureDAO; - private static final Log log = LogFactory.getLog(WindowsFeatureManager.class); public WindowsFeatureManager() { MobileDeviceManagementDAOFactory daoFactory = new WindowsDAOFactory(); @@ -47,27 +43,39 @@ public class WindowsFeatureManager implements FeatureManager { @Override public boolean addFeature(Feature feature) throws DeviceManagementException { try { - WindowsDAOFactory.beginTransaction(); + WindowsDAOFactory.beginTransaction(); MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature); featureDAO.addFeature(mobileFeature); - WindowsDAOFactory.commitTransaction(); + WindowsDAOFactory.commitTransaction(); return true; } catch (MobileDeviceManagementDAOException e) { - WindowsDAOFactory.rollbackTransaction(); + WindowsDAOFactory.rollbackTransaction(); throw new DeviceManagementException("Error occurred while adding the feature", e); } } @Override - public boolean addFeatures(List list) throws DeviceManagementException { - return false; + public boolean addFeatures(List features) throws DeviceManagementException { + List mobileFeatures = new ArrayList(); + for (Feature feature : features) { + mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature)); + } + try { + WindowsDAOFactory.beginTransaction(); + featureDAO.addFeatures(mobileFeatures); + WindowsDAOFactory.commitTransaction(); + return true; + } catch (MobileDeviceManagementDAOException e) { + WindowsDAOFactory.rollbackTransaction(); + throw new DeviceManagementException("Error occurred while adding the features", e); + } } @Override public Feature getFeature(String name) throws DeviceManagementException { try { MobileFeature mobileFeature = featureDAO.getFeatureByCode(name); - Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature); + Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature); return feature; } catch (MobileDeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while retrieving the feature", e); @@ -86,7 +94,7 @@ public class WindowsFeatureManager implements FeatureManager { return featureList; } catch (MobileDeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " + - "Android platform", e); + "Windows platform", e); } } @@ -94,12 +102,12 @@ public class WindowsFeatureManager implements FeatureManager { public boolean removeFeature(String code) throws DeviceManagementException { boolean status; try { - WindowsDAOFactory.beginTransaction(); + WindowsDAOFactory.beginTransaction(); featureDAO.deleteFeatureByCode(code); - WindowsDAOFactory.commitTransaction(); + WindowsDAOFactory.commitTransaction(); status = true; } catch (MobileDeviceManagementDAOException e) { - WindowsDAOFactory.rollbackTransaction(); + WindowsDAOFactory.rollbackTransaction(); throw new DeviceManagementException("Error occurred while removing the feature", e); } return status; @@ -107,7 +115,64 @@ public class WindowsFeatureManager implements FeatureManager { @Override public boolean addSupportedFeaturesToDB() throws DeviceManagementException { - return false; + synchronized (this) { + List supportedFeatures = getSupportedFeatures(); + List existingFeatures = this.getFeatures(); + List missingFeatures = MobileDeviceManagementUtil. + getMissingFeatures(supportedFeatures, existingFeatures); + if (missingFeatures.size() > 0) { + return this.addFeatures(missingFeatures); + } + return true; + } } -} \ No newline at end of file + public static List getSupportedFeatures() { + List supportedFeatures = new ArrayList(); + Feature feature = new Feature(); + feature.setCode("DEVICE_LOCK"); + feature.setName("Device Lock"); + feature.setDescription("Lock the device"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("CAMERA"); + feature.setName("camera"); + feature.setDescription("Enable or disable camera"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("DEVICE_INFO"); + feature.setName("Device info"); + feature.setDescription("Request device information"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("WIPE_DATA"); + feature.setName("Wipe Data"); + feature.setDescription("Factory reset the device"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("ENCRYPT_STORAGE"); + feature.setName("Encrypt storage"); + feature.setDescription("Encrypt storage"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("DEVICE_RING"); + feature.setName("Ring"); + feature.setDescription("Ring the device"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("PASSCODE_POLICY"); + feature.setName("Password Policy"); + feature.setDescription("Set passcode policy"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("DISENROLL"); + feature.setName("DisEnroll"); + feature.setDescription("DisEnroll the device"); + supportedFeatures.add(feature); + feature = new Feature(); + feature.setCode("LOCK_RESET"); + feature.setName("LockReset"); + feature.setDescription("Lock Reset device"); + return supportedFeatures; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java index f9e930d8bc..0cf128d4c6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java @@ -26,6 +26,7 @@ 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.MobileFeatureDAO; import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsDeviceDAOImpl; +import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsFeatureDAOImpl; import javax.sql.DataSource; import java.sql.Connection; @@ -48,7 +49,7 @@ public class WindowsDAOFactory extends AbstractMobileDeviceManagementDAOFactory @Override public MobileFeatureDAO getMobileFeatureDAO() { - return null; + return new WindowsFeatureDAOImpl(); } public static void beginTransaction() throws MobileDeviceManagementDAOException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java index a8c1109425..6827670716 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java @@ -46,6 +46,7 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { public WindowsFeatureDAOImpl() { } + @Override public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { PreparedStatement stmt = null; @@ -53,7 +54,7 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { Connection conn; try { conn = WindowsDAOFactory.getConnection(); - String sql = "INSERT INTO WINDOWS_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; + String sql = "INSERT INTO WIN_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; stmt = conn.prepareStatement(sql); stmt.setString(1, mobileFeature.getCode()); stmt.setString(2, mobileFeature.getName()); @@ -71,6 +72,31 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { return status; } + @Override + public boolean addFeatures(List mobileFeatures) throws MobileDeviceManagementDAOException { + PreparedStatement stmt = null; + boolean status = false; + Connection conn; + try { + conn = WindowsDAOFactory.getConnection(); + stmt = conn.prepareStatement("INSERT INTO WIN_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"); + for (MobileFeature mobileFeature : mobileFeatures) { + stmt.setString(1, mobileFeature.getCode()); + stmt.setString(2, mobileFeature.getName()); + stmt.setString(3, mobileFeature.getDescription()); + stmt.addBatch(); + } + stmt.executeBatch(); + status = true; + } catch (SQLException e) { + throw new WindowsFeatureManagementDAOException( + "Error occurred while adding windows features into the metadata repository", e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + @Override public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { boolean status = false; @@ -79,7 +105,7 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { try { conn = WindowsDAOFactory.getConnection(); String updateDBQuery = - "UPDATE WINDOWS_FEATURE SET NAME = ?, DESCRIPTION = ?" + + "UPDATE WIN_FEATURE SET NAME = ?, DESCRIPTION = ?" + "WHERE CODE = ?"; stmt = conn.prepareStatement(updateDBQuery); @@ -110,10 +136,10 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { PreparedStatement stmt = null; boolean status = false; - Connection conn = null; + Connection conn; try { conn = WindowsDAOFactory.getConnection(); - String sql = "DELETE FROM WINDOWS_FEATURE WHERE FEATURE_ID = ?"; + String sql = "DELETE FROM WIN_FEATURE WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, mblFeatureId); stmt.execute(); @@ -132,10 +158,10 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { PreparedStatement stmt = null; boolean status = false; - Connection conn = null; + Connection conn; try { conn = WindowsDAOFactory.getConnection(); - String sql = "DELETE FROM WINDOWS_FEATURE WHERE CODE = ?"; + String sql = "DELETE FROM WIN_FEATURE WHERE CODE = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, mblFeatureCode); stmt.execute(); @@ -154,10 +180,10 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; - Connection conn = null; + Connection conn; try { conn = WindowsDAOFactory.getConnection(); - String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WINDOWS_FEATURE WHERE ID = ?"; + String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE WHERE ID = ?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, mblFeatureId); rs = stmt.executeQuery(); @@ -191,7 +217,7 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { try { conn = WindowsDAOFactory.getConnection(); - String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WINDOWS_FEATURE WHERE CODE = ?"; + String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE WHERE CODE = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, mblFeatureCode); rs = stmt.executeQuery(); @@ -231,7 +257,7 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { try { conn = WindowsDAOFactory.getConnection(); - String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WINDOWS_FEATURE"; + String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE"; stmt = conn.prepareStatement(sql); rs = stmt.executeQuery(); MobileFeature mobileFeature; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mssql.sql index c905c89a42..4bcd1e3db4 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mssql.sql @@ -1,7 +1,7 @@ -- ----------------------------------------------------- -- Table `WINDOWS_FEATURE` -- ----------------------------------------------------- -CREATE TABLE WINDOWS_FEATURE ( +CREATE TABLE WIN_FEATURE ( ID INT NOT NULL IDENTITY, CODE VARCHAR(45) NOT NULL, NAME VARCHAR(100) NULL, @@ -12,7 +12,7 @@ CREATE TABLE WINDOWS_FEATURE ( -- ----------------------------------------------------- -- Table `WINDOWS_DEVICE` -- ----------------------------------------------------- - CREATE TABLE WINDOWS_DEVICE ( + CREATE TABLE WIN_DEVICE ( DEVICE_ID VARCHAR(45) NOT NULL, CHANNEL_URI VARCHAR(100) NULL DEFAULT NULL, DEVICE_INFO VARCHAR(8000) NULL DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mysql.sql index ecdacf5b98..347f1ad2e0 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/mysql.sql @@ -31,18 +31,5 @@ CREATE TABLE IF NOT EXISTS `WIN_FEATURE` ( PRIMARY KEY (`FEATURE_ID`)) ENGINE = InnoDB; --- ----------------------------------------------------- --- Table `WIN_FEATURE_PROPERTY` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `WIN_FEATURE_PROPERTY` ( - `PROPERTY` VARCHAR(45) NOT NULL , - `FEATURE_ID` INT NOT NULL , - PRIMARY KEY (`PROPERTY`), - CONSTRAINT `fk_WIN_FEATURE_PROPERTY_WIN_FEATURE1` - FOREIGN KEY (`FEATURE_ID`) - REFERENCES `WIN_FEATURE` (`FEATURE_ID`) - ON DELETE NO ACTION - ON UPDATE NO ACTION) -ENGINE = InnoDB; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/oracle.sql index 952b4d817b..8a96b79473 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/oracle.sql @@ -32,20 +32,6 @@ CREATE TABLE WIN_FEATURE ( ); / --- ----------------------------------------------------- --- Table `WIN_FEATURE_PROPERTY` --- ----------------------------------------------------- -CREATE TABLE WIN_FEATURE_PROPERTY ( - PROPERTY VARCHAR(45) NOT NULL, - FEATURE_ID INT NOT NULL, - PRIMARY KEY (PROPERTY), - CONSTRAINT fk_WIN_FEATURE_PROPERTY_WIN_FEATURE1 - FOREIGN KEY (FEATURE_ID) - REFERENCES WIN_FEATURE (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION); -/ - -- ----------------------------------------------------- -- Sequence `WIN_FEATURE_ID_INC_SEQ` -- ----------------------------------------------------- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/postgresql.sql index 45754d06fc..865f306820 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/windows/postgresql.sql @@ -30,16 +30,3 @@ CREATE TABLE IF NOT EXISTS WIN_FEATURE ( PRIMARY KEY (ID) ); --- ----------------------------------------------------- --- Table `WIN_FEATURE_PROPERTY` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS WIN_FEATURE_PROPERTY ( - PROPERTY VARCHAR(45) NOT NULL , - FEATURE_ID INT NOT NULL , - PRIMARY KEY (PROPERTY), - CONSTRAINT fk_WIN_FEATURE_PROPERTY_WIN_FEATURE1 - FOREIGN KEY (FEATURE_ID) - REFERENCES WIN_FEATURE (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION -); From 8a97c3d612fb409e1a7f1b5bc17f4dfada856d21 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Thu, 29 Oct 2015 14:13:37 +0530 Subject: [PATCH 13/22] Fixed code issues --- .../impl/windows/WindowsFeatureManager.java | 28 +++++++++++-------- .../impl/windows/dao/WindowsDAOFactory.java | 1 - 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java index 21396b766c..5194d53e46 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java @@ -1,21 +1,21 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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. - * + * 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.windows; import org.wso2.carbon.device.mgt.common.DeviceManagementException; @@ -127,6 +127,10 @@ public class WindowsFeatureManager implements FeatureManager { } } + /** + * Get supported Windows features. + * @return Supported features. + */ public static List getSupportedFeatures() { List supportedFeatures = new ArrayList(); Feature feature = new Feature(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java index 0cf128d4c6..40f8cc46e9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java @@ -128,5 +128,4 @@ public class WindowsDAOFactory extends AbstractMobileDeviceManagementDAOFactory log.warn("Error occurred while roll-backing the transaction", e); } } - } From feb5901b273dbf415b7ccf2b49b2efeaba2040cf Mon Sep 17 00:00:00 2001 From: hasuniea Date: Thu, 29 Oct 2015 14:19:41 +0530 Subject: [PATCH 14/22] deleted seperate h2_windows.sql --- .../dbscripts/plugins/h2_windows.sql | 68 ------------------- 1 file changed, 68 deletions(-) delete mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_windows.sql diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_windows.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_windows.sql deleted file mode 100644 index 041cffa7f2..0000000000 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/h2_windows.sql +++ /dev/null @@ -1,68 +0,0 @@ --- ----------------------------------------------------- --- Table `WINDOWS_FEATURE` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `WINDOWS_FEATURE` ( - `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, - `CODE` VARCHAR(45) NOT NULL, - `NAME` VARCHAR(100) NULL, - `DESCRIPTION` VARCHAR(200) NULL, - PRIMARY KEY (`FEATURE_ID`)); - - --- ----------------------------------------------------- --- Table `WINDOWS_DEVICE` --- ----------------------------------------------------- - - CREATE TABLE IF NOT EXISTS `WINDOWS_DEVICE` ( - `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, - `CHANNEL_URI` VARCHAR(100) NULL DEFAULT NULL, - `DEVICE_INFO` VARCHAR(8000) 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, - `SERIAL` VARCHAR(45) NULL DEFAULT NULL, - `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL, - `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, - PRIMARY KEY (`MOBILE_DEVICE_ID`) ); - - --- ----------------------------------------------------- --- TODO remove this later --- ----------------------------------------------------- - -INSERT INTO WINDOWS_FEATURE (CODE, NAME, DESCRIPTION) -VALUES -('INSTALL_ENTERPRISE_APPLICATION', 'Install Enterprise App', 'Install Enterprise App'), -
('INSTALL_STORE_APPLICATION', 'Install Public App', 'Install Public App'), 
 -('REMOVE_APPLICATION', 'Uninstall App', 'Uninstall App'), -
('DEVICE_LOCK', 'Device Lock', 'Device Lock'), -('DEVICE_RING', 'Ring', 'Ring the device'), -('DISENROLL', 'DisEnroll', 'DisEnroll the device'), -('LOCKRESET', 'LockReset', 'Lock Reset device'), -
('CELLULAR', 'Cellular', 'Cellular'), -
('APN', 'APN', 'APN'), -
('RESTRICTION', 'Restrictions', 'Restrictions operation'), -
('WIFI', 'Wifi', 'Wifi'), -
('DEVICE_INFO', 'Device Info', 'Device info operation'), 
 -('AIR_PLAY', 'Air Play', 'AirPlay operation'), 
 -('LOCATION', 'Location', 'Fetch location'), 
 -('ALARM', 'Alarm', 'Alarm device'), -('APPLICATION_LIST', 'Application list', 'Application list'), -('PROFILE_LIST', 'Profile List', 'Profile list'), -('REMOVE_PROFILE', 'Remove Profile', 'Remove profile'), -('CLEAR_PASSCODE', 'Clear Passcode', 'Clear passcode'), -('CALDAV', 'CalDev', 'Setup CalDav'), -('CALENDAR_SUBSCRIPTION', 'Calendar Subscriptions', 'Calendar subscription'), -('PASSCODE_POLICY', 'Passcode Policy', 'Passcode policy'), -('EMAIL', 'Email', 'Email operation'), -('LDAP', 'LDAP', 'LDAP operation'), -('WEB_CLIP', 'Web Clip', 'Web clip operation'), -('VPN', 'VPN', 'VPN operation'), -('PER_APP_VPN', 'Per App VPN', 'Per app VPN operation'), -('APP_TO_PER_APP_VPN_MAPPING', 'VPN App mapping', 'App to per app VPN mapping operation'), -('WIPE_DATA', 'Enterprise Wipe', 'Enterprise wipe operation'), -('APP_LOCK', 'App lock', 'App lock operation'); From a437bda6afcae24387d0ac5029db76d3e824d2d4 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Thu, 29 Oct 2015 14:21:34 +0530 Subject: [PATCH 15/22] fixed code issues --- .../mgt/mobile/impl/windows/util/WindowsPluginConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java index 4fa2871acc..e13b4642d6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java @@ -38,7 +38,7 @@ public class WindowsPluginConstants { public static final String MAC_ADDRESS = "MAC_ADDRESS"; public static final String DEVICE_NAME = "DEVICE_NAME"; - //Properties related to AD_FEATURE table + //Properties related to WIN_FEATURE table public static final String WINDOWS_FEATURE_ID = "FEATURE_ID"; public static final String WINDOWS_FEATURE_CODE = "CODE"; public static final String WINDOWS_FEATURE_NAME = "NAME"; From 16b6c527ef079747b3b153a924bce838d1d3e870 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Thu, 29 Oct 2015 14:47:59 +0530 Subject: [PATCH 16/22] refactored windowsFeatureManager --- .../device/mgt/mobile/impl/windows/WindowsFeatureManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java index 5194d53e46..80d1bd5b94 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java @@ -177,6 +177,7 @@ public class WindowsFeatureManager implements FeatureManager { feature.setCode("LOCK_RESET"); feature.setName("LockReset"); feature.setDescription("Lock Reset device"); + supportedFeatures.add(feature); return supportedFeatures; } } From 42d8b084b52f2655db875f8d844577068c0c6c49 Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Fri, 30 Oct 2015 18:35:08 +0530 Subject: [PATCH 17/22] changing DEVICE_ID table name --- .../src/main/resources/dbscripts/plugins/ios/h2.sql | 4 ++-- .../src/main/resources/dbscripts/plugins/ios/mssql.sql | 4 ++-- .../src/main/resources/dbscripts/plugins/ios/mysql.sql | 4 ++-- .../src/main/resources/dbscripts/plugins/ios/oracle.sql | 4 ++-- .../src/main/resources/dbscripts/plugins/ios/postgresql.sql | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql index c9c70ce2da..a115e54575 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/h2.sql @@ -2,7 +2,7 @@ -- Table `IOS_DEVICE` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `IOS_DEVICE` ( - `DEVICE_ID` VARCHAR(45) NOT NULL, + `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, `APNS_PUSH_TOKEN` VARCHAR(100) DEFAULT NULL, `MAGIC_TOKEN` VARCHAR(100) DEFAULT NULL, `MDM_TOKEN` VARCHAR(100) DEFAULT NULL, @@ -18,7 +18,7 @@ `ICCID` VARCHAR(45) DEFAULT NULL, `LATITUDE` VARCHAR(45) DEFAULT NULL, `LONGITUDE` VARCHAR(45) DEFAULT NULL, - PRIMARY KEY (`DEVICE_ID`) + PRIMARY KEY (`MOBILE_DEVICE_ID`) ); -- ----------------------------------------------------- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mssql.sql index 78cbc22c21..5205ff6f2b 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mssql.sql @@ -13,7 +13,7 @@ CREATE TABLE IOS_FEATURE ( -- Table `IOS_DEVICE` -- ----------------------------------------------------- CREATE TABLE IOS_DEVICE ( - DEVICE_ID VARCHAR(45) NOT NULL, + MOBILE_DEVICE_ID VARCHAR(45) NOT NULL, APNS_PUSH_TOKEN VARCHAR(100) NULL DEFAULT NULL, MAGIC_TOKEN VARCHAR(100) NULL DEFAULT NULL, MDM_TOKEN VARCHAR(100) NULL DEFAULT NULL, @@ -29,5 +29,5 @@ CREATE TABLE IOS_FEATURE ( ICCID VARCHAR(45) NULL DEFAULT NULL, LATITUDE VARCHAR(45) NULL DEFAULT NULL, LONGITUDE VARCHAR(45) NULL DEFAULT NULL, - PRIMARY KEY (DEVICE_ID) + PRIMARY KEY (MOBILE_DEVICE_ID) ); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mysql.sql index c71a332548..3f617b7c74 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/mysql.sql @@ -2,7 +2,7 @@ -- Table `IOS_DEVICE` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `IOS_DEVICE` ( - `DEVICE_ID` VARCHAR(45) NOT NULL, + `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL, `APNS_PUSH_TOKEN` VARCHAR(100) NULL DEFAULT NULL, `MAGIC_TOKEN` VARCHAR(100) NULL DEFAULT NULL, `MDM_TOKEN` VARCHAR(100) NULL DEFAULT NULL, @@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS `IOS_DEVICE` ( `ICCID` VARCHAR(45) NULL DEFAULT NULL, `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, - PRIMARY KEY (`DEVICE_ID`) + PRIMARY KEY (`MOBILE_DEVICE_ID`) ) ENGINE = InnoDB; -- ----------------------------------------------------- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql index 11e5212e1c..3e129477f5 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/oracle.sql @@ -2,7 +2,7 @@ -- Table `IOS_DEVICE` -- ----------------------------------------------------- CREATE TABLE IOS_DEVICE ( - DEVICE_ID VARCHAR(45) NOT NULL, + MOBILE_DEVICE_ID VARCHAR(45) NOT NULL, APNS_PUSH_TOKEN VARCHAR(100) DEFAULT NULL, MAGIC_TOKEN VARCHAR(100) DEFAULT NULL, MDM_TOKEN VARCHAR(100) DEFAULT NULL, @@ -18,7 +18,7 @@ ICCID VARCHAR(45) DEFAULT NULL, LATITUDE VARCHAR(45) DEFAULT NULL, LONGITUDE VARCHAR(45) DEFAULT NULL, - PRIMARY KEY (DEVICE_ID) + PRIMARY KEY (MOBILE_DEVICE_ID) ); / diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgresql.sql index 79b342ca3a..1ada59fdc7 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/dbscripts/plugins/ios/postgresql.sql @@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS IOS_FEATURE ( -- Table IOS_DEVICE -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS IOS_DEVICE ( - DEVICE_ID VARCHAR(45) NOT NULL, + MOBILE_DEVICE_ID VARCHAR(45) NOT NULL, APNS_PUSH_TOKEN VARCHAR(100) NULL DEFAULT NULL, MAGIC_TOKEN VARCHAR(100) NULL DEFAULT NULL, MDM_TOKEN VARCHAR(100) NULL DEFAULT NULL, @@ -29,5 +29,5 @@ CREATE TABLE IF NOT EXISTS IOS_DEVICE ( ICCID VARCHAR(45) NULL DEFAULT NULL, LATITUDE VARCHAR(45) NULL DEFAULT NULL, LONGITUDE VARCHAR(45) NULL DEFAULT NULL, - PRIMARY KEY (DEVICE_ID) + PRIMARY KEY (MOBILE_DEVICE_ID) ); From 85fdb3c930344960041461bad91d97980d20c487 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 30 Oct 2015 19:48:45 +0530 Subject: [PATCH 18/22] refactored code issues --- .../impl/MobileFeaturePropertyDAOImpl.java | 500 +++++++++--------- .../impl/windows/WindowsFeatureManager.java | 13 + .../dao/impl/WindowsFeatureDAOImpl.java | 10 - .../impl/dao/MobileFeatureDAOTestSuite.java | 260 --------- .../MobileFeaturePropertyDAOTestSuite.java | 241 --------- .../src/test/resources/testng.xml | 9 - 6 files changed, 263 insertions(+), 770 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java index e3edfc3249..a71db74ab3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java @@ -1,250 +1,250 @@ -/* - * Copyright (c) 2014, 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.dao.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileFeaturePropertyDAO; -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.MobileFeatureProperty; - -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; - -/** - * Implementation of MobileFeaturePropertyDAO. - */ -public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { - - private DataSource dataSource; - private static final Log log = LogFactory.getLog(MobileFeaturePropertyDAOImpl.class); - - public MobileFeaturePropertyDAOImpl(DataSource dataSource) { - this.dataSource = dataSource; - } - - @Override - public boolean addMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String createDBQuery = - "INSERT INTO AD_FEATURE_PROPERTY(PROPERTY, FEATURE_ID) VALUES (?, ?)"; - - stmt = conn.prepareStatement(createDBQuery); - stmt.setString(1, mblFeatureProperty.getProperty()); - stmt.setInt(2, mblFeatureProperty.getFeatureID()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Added MobileFeatureProperty " + mblFeatureProperty.getProperty() + - " to the MDM database."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while adding property id - '" + - mblFeatureProperty.getFeatureID() + "'"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public boolean updateMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String updateDBQuery = - "UPDATE AD_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?"; - stmt = conn.prepareStatement(updateDBQuery); - stmt.setInt(1, mblFeatureProperty.getFeatureID()); - stmt.setString(2, mblFeatureProperty.getProperty()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Updated MobileFeatureProperty " + mblFeatureProperty.getProperty()); - } - } - } catch (SQLException e) { - String msg = "Error occurred while updating the feature property with property - '" + - mblFeatureProperty.getProperty() + "'"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public boolean deleteMobileFeatureProperty(String property) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String deleteDBQuery = - "DELETE FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?"; - stmt = conn.prepareStatement(deleteDBQuery); - stmt.setString(1, property); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Deleted MobileFeatureProperty " + property + " from MDM database."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while deleting feature property with property - " + - property; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public boolean deleteMobileFeaturePropertiesOfFeature(Integer mblFeatureId) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String deleteDBQuery = - "DELETE FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; - stmt = conn.prepareStatement(deleteDBQuery); - stmt.setInt(1, mblFeatureId); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Deleted all MobileFeatureProperties of FeatureId " + mblFeatureId + - " from MDM database."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while deleting feature properties of feature - " + - mblFeatureId; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public MobileFeatureProperty getMobileFeatureProperty(String property) - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - MobileFeatureProperty mobileFeatureProperty = null; - try { - conn = this.getConnection(); - String selectDBQuery = - "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setString(1, property); - ResultSet resultSet = stmt.executeQuery(); - if (resultSet.next()) { - mobileFeatureProperty = new MobileFeatureProperty(); - mobileFeatureProperty.setProperty(resultSet.getString(1)); - mobileFeatureProperty.setFeatureID(resultSet.getInt(2)); - if (log.isDebugEnabled()) { - log.debug("Fetched MobileFeatureProperty " + mobileFeatureProperty.getProperty() + - " from MDM database."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while fetching property - '" + - property + "'"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return mobileFeatureProperty; - } - - @Override - public List getFeaturePropertiesOfFeature(Integer mblFeatureId) - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - MobileFeatureProperty mobileFeatureProperty; - List FeatureProperties = new ArrayList(); - try { - conn = this.getConnection(); - String selectDBQuery = - "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setInt(1, mblFeatureId); - ResultSet resultSet = stmt.executeQuery(); - while (resultSet.next()) { - mobileFeatureProperty = new MobileFeatureProperty(); - mobileFeatureProperty.setProperty(resultSet.getString(1)); - mobileFeatureProperty.setFeatureID(resultSet.getInt(2)); - FeatureProperties.add(mobileFeatureProperty); - } - if (log.isDebugEnabled()) { - log.debug("Fetched all MobileFeatureProperties of featureId " + mblFeatureId + - " from MDM database."); - } - return FeatureProperties; - } catch (SQLException e) { - String msg = "Error occurred while fetching all feature property.'"; - 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); - } - } -} +///* +// * Copyright (c) 2014, 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.dao.impl; +// +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +//import org.wso2.carbon.device.mgt.mobile.dao.MobileFeaturePropertyDAO; +//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.MobileFeatureProperty; +// +//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; +// +///** +// * Implementation of MobileFeaturePropertyDAO. +// */ +//public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { +// +// private DataSource dataSource; +// private static final Log log = LogFactory.getLog(MobileFeaturePropertyDAOImpl.class); +// +// public MobileFeaturePropertyDAOImpl(DataSource dataSource) { +// this.dataSource = dataSource; +// } +// +// @Override +// public boolean addMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty) +// throws MobileDeviceManagementDAOException { +// boolean status = false; +// Connection conn = null; +// PreparedStatement stmt = null; +// try { +// conn = this.getConnection(); +// String createDBQuery = +// "INSERT INTO AD_FEATURE_PROPERTY(PROPERTY, FEATURE_ID) VALUES (?, ?)"; +// +// stmt = conn.prepareStatement(createDBQuery); +// stmt.setString(1, mblFeatureProperty.getProperty()); +// stmt.setInt(2, mblFeatureProperty.getFeatureID()); +// int rows = stmt.executeUpdate(); +// if (rows > 0) { +// status = true; +// if (log.isDebugEnabled()) { +// log.debug("Added MobileFeatureProperty " + mblFeatureProperty.getProperty() + +// " to the MDM database."); +// } +// } +// } catch (SQLException e) { +// String msg = "Error occurred while adding property id - '" + +// mblFeatureProperty.getFeatureID() + "'"; +// log.error(msg, e); +// throw new MobileDeviceManagementDAOException(msg, e); +// } finally { +// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); +// } +// return status; +// } +// +// @Override +// public boolean updateMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty) +// throws MobileDeviceManagementDAOException { +// boolean status = false; +// Connection conn = null; +// PreparedStatement stmt = null; +// try { +// conn = this.getConnection(); +// String updateDBQuery = +// "UPDATE AD_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?"; +// stmt = conn.prepareStatement(updateDBQuery); +// stmt.setInt(1, mblFeatureProperty.getFeatureID()); +// stmt.setString(2, mblFeatureProperty.getProperty()); +// int rows = stmt.executeUpdate(); +// if (rows > 0) { +// status = true; +// if (log.isDebugEnabled()) { +// log.debug("Updated MobileFeatureProperty " + mblFeatureProperty.getProperty()); +// } +// } +// } catch (SQLException e) { +// String msg = "Error occurred while updating the feature property with property - '" + +// mblFeatureProperty.getProperty() + "'"; +// log.error(msg, e); +// throw new MobileDeviceManagementDAOException(msg, e); +// } finally { +// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); +// } +// return status; +// } +// +// @Override +// public boolean deleteMobileFeatureProperty(String property) +// throws MobileDeviceManagementDAOException { +// boolean status = false; +// Connection conn = null; +// PreparedStatement stmt = null; +// try { +// conn = this.getConnection(); +// String deleteDBQuery = +// "DELETE FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?"; +// stmt = conn.prepareStatement(deleteDBQuery); +// stmt.setString(1, property); +// int rows = stmt.executeUpdate(); +// if (rows > 0) { +// status = true; +// if (log.isDebugEnabled()) { +// log.debug("Deleted MobileFeatureProperty " + property + " from MDM database."); +// } +// } +// } catch (SQLException e) { +// String msg = "Error occurred while deleting feature property with property - " + +// property; +// log.error(msg, e); +// throw new MobileDeviceManagementDAOException(msg, e); +// } finally { +// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); +// } +// return status; +// } +// +// @Override +// public boolean deleteMobileFeaturePropertiesOfFeature(Integer mblFeatureId) +// throws MobileDeviceManagementDAOException { +// boolean status = false; +// Connection conn = null; +// PreparedStatement stmt = null; +// try { +// conn = this.getConnection(); +// String deleteDBQuery = +// "DELETE FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; +// stmt = conn.prepareStatement(deleteDBQuery); +// stmt.setInt(1, mblFeatureId); +// int rows = stmt.executeUpdate(); +// if (rows > 0) { +// status = true; +// if (log.isDebugEnabled()) { +// log.debug("Deleted all MobileFeatureProperties of FeatureId " + mblFeatureId + +// " from MDM database."); +// } +// } +// } catch (SQLException e) { +// String msg = "Error occurred while deleting feature properties of feature - " + +// mblFeatureId; +// log.error(msg, e); +// throw new MobileDeviceManagementDAOException(msg, e); +// } finally { +// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); +// } +// return status; +// } +// +// @Override +// public MobileFeatureProperty getMobileFeatureProperty(String property) +// throws MobileDeviceManagementDAOException { +// Connection conn = null; +// PreparedStatement stmt = null; +// MobileFeatureProperty mobileFeatureProperty = null; +// try { +// conn = this.getConnection(); +// String selectDBQuery = +// "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?"; +// stmt = conn.prepareStatement(selectDBQuery); +// stmt.setString(1, property); +// ResultSet resultSet = stmt.executeQuery(); +// if (resultSet.next()) { +// mobileFeatureProperty = new MobileFeatureProperty(); +// mobileFeatureProperty.setProperty(resultSet.getString(1)); +// mobileFeatureProperty.setFeatureID(resultSet.getInt(2)); +// if (log.isDebugEnabled()) { +// log.debug("Fetched MobileFeatureProperty " + mobileFeatureProperty.getProperty() + +// " from MDM database."); +// } +// } +// } catch (SQLException e) { +// String msg = "Error occurred while fetching property - '" + +// property + "'"; +// log.error(msg, e); +// throw new MobileDeviceManagementDAOException(msg, e); +// } finally { +// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); +// } +// return mobileFeatureProperty; +// } +// +// @Override +// public List getFeaturePropertiesOfFeature(Integer mblFeatureId) +// throws MobileDeviceManagementDAOException { +// Connection conn = null; +// PreparedStatement stmt = null; +// MobileFeatureProperty mobileFeatureProperty; +// List FeatureProperties = new ArrayList(); +// try { +// conn = this.getConnection(); +// String selectDBQuery = +// "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; +// stmt = conn.prepareStatement(selectDBQuery); +// stmt.setInt(1, mblFeatureId); +// ResultSet resultSet = stmt.executeQuery(); +// while (resultSet.next()) { +// mobileFeatureProperty = new MobileFeatureProperty(); +// mobileFeatureProperty.setProperty(resultSet.getString(1)); +// mobileFeatureProperty.setFeatureID(resultSet.getInt(2)); +// FeatureProperties.add(mobileFeatureProperty); +// } +// if (log.isDebugEnabled()) { +// log.debug("Fetched all MobileFeatureProperties of featureId " + mblFeatureId + +// " from MDM database."); +// } +// return FeatureProperties; +// } catch (SQLException e) { +// String msg = "Error occurred while fetching all feature property.'"; +// 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/windows/WindowsFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java index 80d1bd5b94..0dca8b5d67 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java @@ -51,6 +51,8 @@ public class WindowsFeatureManager implements FeatureManager { } catch (MobileDeviceManagementDAOException e) { WindowsDAOFactory.rollbackTransaction(); throw new DeviceManagementException("Error occurred while adding the feature", e); + } finally { + WindowsDAOFactory.closeConnection(); } } @@ -68,17 +70,22 @@ public class WindowsFeatureManager implements FeatureManager { } catch (MobileDeviceManagementDAOException e) { WindowsDAOFactory.rollbackTransaction(); throw new DeviceManagementException("Error occurred while adding the features", e); + } finally { + WindowsDAOFactory.closeConnection(); } } @Override public Feature getFeature(String name) throws DeviceManagementException { try { + WindowsDAOFactory.openConnection(); MobileFeature mobileFeature = featureDAO.getFeatureByCode(name); Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature); return feature; } catch (MobileDeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while retrieving the feature", e); + } finally { + WindowsDAOFactory.closeConnection(); } } @@ -87,6 +94,7 @@ public class WindowsFeatureManager implements FeatureManager { List featureList = new ArrayList(); try { + WindowsDAOFactory.openConnection(); List mobileFeatures = featureDAO.getAllFeatures(); for (MobileFeature mobileFeature : mobileFeatures) { featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature)); @@ -95,6 +103,8 @@ public class WindowsFeatureManager implements FeatureManager { } catch (MobileDeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " + "Windows platform", e); + } finally { + WindowsDAOFactory.closeConnection(); } } @@ -109,6 +119,8 @@ public class WindowsFeatureManager implements FeatureManager { } catch (MobileDeviceManagementDAOException e) { WindowsDAOFactory.rollbackTransaction(); throw new DeviceManagementException("Error occurred while removing the feature", e); + } finally { + WindowsDAOFactory.closeConnection(); } return status; } @@ -129,6 +141,7 @@ public class WindowsFeatureManager implements FeatureManager { /** * Get supported Windows features. + * * @return Supported features. */ public static List getSupportedFeatures() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java index 6827670716..8b5d11a933 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java @@ -107,12 +107,10 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { String updateDBQuery = "UPDATE WIN_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; @@ -187,7 +185,6 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { stmt = conn.prepareStatement(sql); stmt.setInt(1, mblFeatureId); rs = stmt.executeQuery(); - MobileFeature mobileFeature = null; if (rs.next()) { mobileFeature = new MobileFeature(); @@ -205,7 +202,6 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { mblFeatureId + "' from the Windows database.", e); } finally { MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - WindowsDAOFactory.closeConnection(); } } @@ -214,14 +210,12 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { PreparedStatement stmt = null; ResultSet rs = null; Connection conn; - try { conn = WindowsDAOFactory.getConnection(); String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE WHERE CODE = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, mblFeatureCode); rs = stmt.executeQuery(); - MobileFeature mobileFeature = null; if (rs.next()) { mobileFeature = new MobileFeature(); @@ -239,7 +233,6 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { mblFeatureCode + "' from the Windows database.", e); } finally { MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - WindowsDAOFactory.closeConnection(); } } @@ -254,14 +247,12 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { ResultSet rs = null; Connection conn; List features = new ArrayList<>(); - try { conn = WindowsDAOFactory.getConnection(); String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE"; stmt = conn.prepareStatement(sql); rs = stmt.executeQuery(); MobileFeature mobileFeature; - while (rs.next()) { mobileFeature = new MobileFeature(); mobileFeature.setId(rs.getInt(WindowsPluginConstants.WINDOWS_FEATURE_ID)); @@ -278,7 +269,6 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { "windows features from the Windows database.", e); } finally { MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - WindowsDAOFactory.closeConnection(); } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java deleted file mode 100644 index 02f66bf044..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java +++ /dev/null @@ -1,260 +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.dao; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tomcat.jdbc.pool.DataSource; -import org.apache.tomcat.jdbc.pool.PoolProperties; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileFeatureDAOImpl; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; -import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes; -import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration; -import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils; - -import java.sql.*; -import java.util.List; - -/** - * - * Class for holding unit-tests related to MobileFeatureDAO class. - * - */ -public class MobileFeatureDAOTestSuite { - - private static final Log log = LogFactory.getLog(MobileFeatureDAOTestSuite.class); - public static final String MBL_FEATURE_NAME = "Camera"; - private static final String MBL_FEATURE_CODE = "500A"; - public static final String MBL_FEATURE_DESCRIPTION = "Camera enable or disable"; - public static final String MBL_FEATURE_DEVICE_TYPE = "Android"; - public static final String MBL_FEATURE_UPDATED_CODE = "501B"; - private TestDBConfiguration testDBConfiguration; - private MobileFeatureDAOImpl mblFeatureDAO; - private int mblFeatureId; - - @BeforeClass - @Parameters("dbType") - public void setUpDB(String dbTypeStr) throws Exception { - - DBTypes dbType = DBTypes.valueOf(dbTypeStr); - testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType); - - switch (dbType) { - case H2: - MobileDatabaseUtils.createH2DB(testDBConfiguration); - DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource(); - PoolProperties properties = new PoolProperties(); - properties.setUrl(testDBConfiguration.getConnectionURL()); - properties.setDriverClassName(testDBConfiguration.getDriverClassName()); - properties.setUsername(testDBConfiguration.getUsername()); - properties.setPassword(testDBConfiguration.getPassword()); - testDataSource.setPoolProperties(properties); - mblFeatureDAO = new MobileFeatureDAOImpl(testDataSource); - default: - } - } - - @Test - public void addMobileFeatureTest() - throws MobileDeviceManagementDAOException { - - Connection conn = null; - PreparedStatement preparedStatement = null; - MobileFeature mobileFeature = new MobileFeature(); - MobileFeature testMblFeature = new MobileFeature(); - mobileFeature.setCode(MBL_FEATURE_CODE); - mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION); - mobileFeature.setName(MBL_FEATURE_NAME); - mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE); - mblFeatureDAO.addFeature(mobileFeature); - - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String query = - "SELECT ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM AD_FEATURE WHERE CODE = ?"; - preparedStatement = conn.prepareStatement(query); - preparedStatement.setString(1, MBL_FEATURE_CODE); - ResultSet resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - testMblFeature.setId(resultSet.getInt(1)); - testMblFeature.setCode(resultSet.getString(2)); - testMblFeature.setName(resultSet.getString(3)); - testMblFeature.setDescription(resultSet.getString(4)); - testMblFeature.setDeviceType(resultSet.getString(5)); - } - } catch (SQLException e) { - String msg = "Error in retrieving Mobile Feature data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - mblFeatureId = testMblFeature.getId(); - Assert.assertTrue(mblFeatureId > 0, "MobileFeature has added "); - Assert.assertEquals(MBL_FEATURE_CODE, testMblFeature.getCode(), - "MobileFeature code has persisted "); - Assert.assertEquals(MBL_FEATURE_NAME, testMblFeature.getName(), - "MobileFeature name has persisted "); - Assert.assertEquals(MBL_FEATURE_DESCRIPTION, testMblFeature.getDescription(), - "MobileFeature description has persisted "); - Assert.assertEquals(MBL_FEATURE_DEVICE_TYPE, testMblFeature.getDeviceType(), - "MobileFeature device-type has persisted "); - } - - @Test(dependsOnMethods = { "addMobileFeatureTest" }) - public void getMobileFeatureByCodeTest() - throws MobileDeviceManagementDAOException { - - MobileFeature mobileFeature = mblFeatureDAO.getFeatureByCode(MBL_FEATURE_CODE); - Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(), - "MobileFeature code has retrieved "); - Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(), - "MobileFeature name has retrieved "); - Assert.assertEquals(MBL_FEATURE_DESCRIPTION, mobileFeature.getDescription(), - "MobileFeature description has retrieved "); - } - - @Test(dependsOnMethods = { "addMobileFeatureTest" }) - public void getMobileFeatureByIdTest() - throws MobileDeviceManagementDAOException { - - MobileFeature mobileFeature = mblFeatureDAO.getFeatureById(mblFeatureId); - Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(), - "MobileFeature code has retrieved "); - Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(), - "MobileFeature name has retrieved "); - Assert.assertEquals(MBL_FEATURE_DESCRIPTION, mobileFeature.getDescription(), - "MobileFeature description has retrieved "); - } - - @Test(dependsOnMethods = { "addMobileFeatureTest" }) - public void getAllMobileFeaturesTest() - throws MobileDeviceManagementDAOException { - - List mobileFeatures = mblFeatureDAO.getAllFeatures(); - Assert.assertNotNull(mobileFeatures, "MobileFeature list is not null"); - Assert.assertTrue(mobileFeatures.size() > 0, "MobileFeature list has 1 MobileFeature"); - } - - @Test(dependsOnMethods = { "addMobileFeatureTest", "getMobileFeatureByCodeTest", - "getMobileFeatureByIdTest", "getAllMobileFeaturesTest" }) - public void updateMobileFeatureTest() - throws MobileDeviceManagementDAOException { - - Connection conn = null; - PreparedStatement stmt = null; - - MobileFeature mobileFeature = new MobileFeature(); - MobileFeature testMblFeature = new MobileFeature(); - mobileFeature.setCode(MBL_FEATURE_UPDATED_CODE); - mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION); - mobileFeature.setName(MBL_FEATURE_NAME); - mobileFeature.setId(mblFeatureId); - boolean updated = mblFeatureDAO.updateFeature(mobileFeature); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String query = - "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?"; - stmt = conn.prepareStatement(query); - stmt.setString(1, MBL_FEATURE_UPDATED_CODE); - ResultSet resultSet = stmt.executeQuery(); - if (resultSet.next()) { - testMblFeature.setId(resultSet.getInt(1)); - testMblFeature.setCode(resultSet.getString(2)); - testMblFeature.setName(resultSet.getString(3)); - testMblFeature.setDescription(resultSet.getString(4)); - } - } catch (SQLException e) { - String msg = "Error in updating Mobile Feature data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, stmt, null); - } - Assert.assertTrue(updated, "MobileFeature has updated"); - Assert.assertEquals(MBL_FEATURE_UPDATED_CODE, testMblFeature.getCode(), - "MobileFeature data has updated "); - } - - @Test(dependsOnMethods = { "addMobileFeatureTest", "getMobileFeatureByCodeTest", - "getMobileFeatureByIdTest", "getAllMobileFeaturesTest", - "updateMobileFeatureTest" }) - public void deleteMobileFeatureByIdTest() - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - - boolean status = mblFeatureDAO.deleteFeatureById(mblFeatureId); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String query = "SELECT ID, CODE FROM AD_FEATURE WHERE ID = ?"; - stmt = conn.prepareStatement(query); - stmt.setInt(1, mblFeatureId); - ResultSet resultSet = stmt.executeQuery(); - if (resultSet.next()) { - status = false; - } - } catch (SQLException e) { - String msg = "Error in deleting Mobile Feature data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, stmt, null); - } - Assert.assertTrue(status, "MobileFeature has deleted "); - } - - @Test(dependsOnMethods = { "addMobileFeatureTest", "getMobileFeatureByCodeTest", - "getMobileFeatureByIdTest", "getAllMobileFeaturesTest", - "updateMobileFeatureTest", "deleteMobileFeatureByIdTest" }) - public void deleteMobileFeatureByCodeTest() - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement preparedStatement = null; - MobileFeature mobileFeature = new MobileFeature(); - mobileFeature.setCode(MBL_FEATURE_CODE); - mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION); - mobileFeature.setName(MBL_FEATURE_NAME); - mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE); - mblFeatureDAO.addFeature(mobileFeature); - boolean status = mblFeatureDAO.deleteFeatureByCode(MBL_FEATURE_CODE); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String query = "SELECT ID, CODE FROM AD_FEATURE WHERE CODE = ?"; - preparedStatement = conn.prepareStatement(query); - preparedStatement.setString(1, MBL_FEATURE_CODE); - ResultSet resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - status = false; - } - } catch (SQLException e) { - String msg = "Error in deleting Mobile Feature data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(status, "MobileFeature has deleted "); - } -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java deleted file mode 100644 index 5c0c296a3b..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java +++ /dev/null @@ -1,241 +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.dao; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tomcat.jdbc.pool.DataSource; -import org.apache.tomcat.jdbc.pool.PoolProperties; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileFeatureDAOImpl; -import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileFeaturePropertyDAOImpl; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeatureProperty; -import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes; -import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration; -import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils; - -import java.sql.*; -import java.util.ArrayList; -import java.util.List; - -/** - * - * Class for holding unit-tests related to MobileFeaturePropertyDAO class. - * - */ -public class MobileFeaturePropertyDAOTestSuite { - - private static final Log log = LogFactory.getLog(MobileFeaturePropertyDAOTestSuite.class); - public static final String MBL_FEATURE_NAME = "WIFI"; - private static final String MBL_FEATURE_CODE = "500A"; - public static final String MBL_FEATURE_DESCRIPTION = "Wifi config"; - public static final String MBL_FEATURE_DEVICE_TYPE = "Android"; - public static final String MBL_FEATURE_PROP_1 = "SSID"; - public static final String MBL_FEATURE_PROP_2 = "PASSWORD"; - private TestDBConfiguration testDBConfiguration; - private MobileFeatureDAOImpl mblFeatureDAO; - private MobileFeaturePropertyDAOImpl mobileFeaturePropertyDAO; - private int mblFeatureId; - - @BeforeClass - @Parameters("dbType") - public void setUpDB(String dbTypeStr) throws Exception { - - DBTypes dbType = DBTypes.valueOf(dbTypeStr); - testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType); - - switch (dbType) { - case H2: - MobileDatabaseUtils.createH2DB(testDBConfiguration); - DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource(); - PoolProperties properties = new PoolProperties(); - properties.setUrl(testDBConfiguration.getConnectionURL()); - properties.setDriverClassName(testDBConfiguration.getDriverClassName()); - properties.setUsername(testDBConfiguration.getUsername()); - properties.setPassword(testDBConfiguration.getPassword()); - testDataSource.setPoolProperties(properties); - mblFeatureDAO = new MobileFeatureDAOImpl(testDataSource); - mobileFeaturePropertyDAO = new MobileFeaturePropertyDAOImpl(testDataSource); - default: - } - } - - @Test - public void addMobileFeaturePropertyTest() - throws MobileDeviceManagementDAOException { - - Connection conn = null; - PreparedStatement preparedStatement = null; - List propertyList = new ArrayList(); - //Add a new MobileFeature to the database - MobileFeature mobileFeature = new MobileFeature(); - mobileFeature.setCode(MBL_FEATURE_CODE); - mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION); - mobileFeature.setName(MBL_FEATURE_NAME); - mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE); - mblFeatureDAO.addFeature(mobileFeature); - - MobileFeature persistMblFeature = mblFeatureDAO.getFeatureByCode(MBL_FEATURE_CODE); - mblFeatureId = persistMblFeature.getId(); - //Add 1st property to the feature - MobileFeatureProperty mobileFeatureProperty = new MobileFeatureProperty(); - mobileFeatureProperty.setFeatureID(mblFeatureId); - mobileFeatureProperty.setProperty(MBL_FEATURE_PROP_1); - boolean status1 = mobileFeaturePropertyDAO.addMobileFeatureProperty(mobileFeatureProperty); - - //Add 2nd property to the feature - mobileFeatureProperty.setProperty(MBL_FEATURE_PROP_2); - boolean status2 = mobileFeaturePropertyDAO.addMobileFeatureProperty(mobileFeatureProperty); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String query = - "SELECT FEATURE_ID, PROPERTY FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; - preparedStatement = conn.prepareStatement(query); - preparedStatement.setInt(1, mblFeatureId); - ResultSet resultSet = preparedStatement.executeQuery(); - - while (resultSet.next()) { - mobileFeatureProperty = new MobileFeatureProperty(); - mobileFeatureProperty.setFeatureID(resultSet.getInt(1)); - mobileFeatureProperty.setProperty(resultSet.getString(2)); - propertyList.add(mobileFeatureProperty); - } - } catch (SQLException e) { - String msg = "Error in retrieving Mobile Feature data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(status1, "MobileFeatureProperty1 has added "); - Assert.assertTrue(status2, "MobileFeatureProperty2 has added "); - Assert.assertTrue(propertyList.size() == 2, "MobileFeatureProperties have retrieved "); - - for (MobileFeatureProperty mblFeatureProperty : propertyList) { - Assert.assertNotNull(mblFeatureProperty.getProperty(), - "MobileFeatureProperty property has persisted "); - Assert.assertNotNull(mblFeatureProperty.getFeatureID(), - "MobileFeatureProperty feature-id has persisted "); - } - - } - - @Test(dependsOnMethods = { "addMobileFeaturePropertyTest" }) - public void getMobileFeaturePropertyTest() - throws MobileDeviceManagementDAOException { - MobileFeatureProperty mobileFeatureProperty = - mobileFeaturePropertyDAO.getMobileFeatureProperty(MBL_FEATURE_PROP_1); - Assert.assertNotNull(mobileFeatureProperty, "MobileFeatureProperty has retrieved "); - Assert.assertEquals(MBL_FEATURE_PROP_1, mobileFeatureProperty.getProperty(), - "MobileFeatureProperty property has retrieved "); - Assert.assertTrue(mblFeatureId == mobileFeatureProperty.getFeatureID(), - "MobileFeatureProperty featureId has retrieved "); - } - - @Test(dependsOnMethods = { "addMobileFeaturePropertyTest" }) - public void getFeaturePropertyOfFeatureTest() - throws MobileDeviceManagementDAOException { - List mobileFeatureProperties = - mobileFeaturePropertyDAO.getFeaturePropertiesOfFeature(mblFeatureId); - Assert.assertNotNull(mobileFeatureProperties, "MobileFeatureProperty list has retrieved "); - Assert.assertTrue(mobileFeatureProperties.size() == 2, - "MobileFeatureProperties have fetched "); - for (MobileFeatureProperty mblFeatureProperty : mobileFeatureProperties) { - Assert.assertNotNull(mblFeatureProperty.getProperty(), - "MobileFeatureProperty property has fetched "); - Assert.assertNotNull(mblFeatureProperty.getFeatureID(), - "MobileFeatureProperty feature-id has fetched "); - } - } - - @Test(dependsOnMethods = { "addMobileFeaturePropertyTest", "getMobileFeaturePropertyTest", - "getFeaturePropertyOfFeatureTest" }, expectedExceptions = MobileDeviceManagementDAOException.class) - public void updateMobileFeaturePropertyTest() throws MobileDeviceManagementDAOException { - //Update 1st property to a non-exist feature - MobileFeatureProperty mobileFeatureProperty = new MobileFeatureProperty(); - mobileFeatureProperty.setFeatureID(2); - mobileFeatureProperty.setProperty(MBL_FEATURE_PROP_1); - mobileFeaturePropertyDAO.updateMobileFeatureProperty(mobileFeatureProperty); - } - - @Test(dependsOnMethods = { "addMobileFeaturePropertyTest", "getMobileFeaturePropertyTest", - "getFeaturePropertyOfFeatureTest" }) - public void deleteMobileFeaturePropertyTest() - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement preparedStatement = null; - boolean status = - mobileFeaturePropertyDAO.deleteMobileFeatureProperty(MBL_FEATURE_PROP_2); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String query = - "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?"; - preparedStatement = conn.prepareStatement(query); - preparedStatement.setString(1, MBL_FEATURE_PROP_2); - ResultSet resultSet = preparedStatement.executeQuery(); - - if (resultSet.next()) { - status = false; - } - } catch (SQLException e) { - String msg = "Error in retrieving MobileFeatureProperty data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(status, "MobileFeatureProperty has deleted "); - } - - @Test(dependsOnMethods = { "addMobileFeaturePropertyTest", "getMobileFeaturePropertyTest", - "getFeaturePropertyOfFeatureTest", "updateMobileFeaturePropertyTest", - "deleteMobileFeaturePropertyTest" }) - public void deleteMobileFeaturePropertiesOfFeatureTest() - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement preparedStatement = null; - boolean status = - mobileFeaturePropertyDAO.deleteMobileFeaturePropertiesOfFeature(mblFeatureId); - try { - conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL()); - String query = - "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; - preparedStatement = conn.prepareStatement(query); - preparedStatement.setInt(1, mblFeatureId); - ResultSet resultSet = preparedStatement.executeQuery(); - - if (resultSet.next()) { - status = false; - } - } catch (SQLException e) { - String msg = "Error in retrieving MobileFeatureProperty data "; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null); - } - Assert.assertTrue(status, "MobileFeatureProperties has deleted "); - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml index 68f54744ad..f73ab880b0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml @@ -24,13 +24,4 @@ - - - - - - - - - \ No newline at end of file From c257a7a5ab6fa288b38b5de47e4825a966bdb52e Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 30 Oct 2015 19:53:16 +0530 Subject: [PATCH 19/22] refactored code issues --- .../mobile/dao/MobileFeaturePropertyDAO.java | 94 ------------------- 1 file changed, 94 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java deleted file mode 100644 index 51a6cef289..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java +++ /dev/null @@ -1,94 +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.dao; - -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeatureProperty; - -import java.util.List; - -/** - * This class represents the key operations associated with persisting mobile feature property - * related information. - */ -public interface MobileFeaturePropertyDAO { - - /** - * Add a new MobileFeatureProperty to MobileFeatureProperty table. - * - * @param mblFeatureProperty MobileFeatureProperty object that holds data related to the feature - * property to be inserted. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean addMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty) - throws MobileDeviceManagementDAOException; - - /** - * Updates a MobileFeatureProperty in the MobileFeatureProperty table. - * - * @param mblFeatureProperty MobileFeatureProperty object that holds data has to be updated. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean updateMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty) - throws MobileDeviceManagementDAOException; - - /** - * Deletes a given MobileFeatureProperty from MobileFeatureProperty table. - * - * @param property Property of the MobileFeatureProperty to be deleted. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean deleteMobileFeatureProperty(String property) throws MobileDeviceManagementDAOException; - - /** - * Deletes MobileFeatureProperties of a given feature from MobileFeatureProperty table. - * - * @param mblFeatureId Feature-id of the MobileFeature corresponding properties should be deleted. - * @return The status of the operation. - * @throws MobileDeviceManagementDAOException - */ - boolean deleteMobileFeaturePropertiesOfFeature(Integer mblFeatureId) - throws MobileDeviceManagementDAOException; - - /** - * Retrieves a given MobileFeatureProperty from MobileFeatureProperty table. - * - * @param property Property of the feature property to be retrieved. - * @return MobileFeatureProperty object that holds data of the feature property represented by - * property. - * @throws MobileDeviceManagementDAOException - */ - MobileFeatureProperty getMobileFeatureProperty(String property) - throws MobileDeviceManagementDAOException; - - /** - * Retrieves a list of MobileFeatureProperties corresponds to a given feature id from - * MobileFeatureProperty table. - * - * @param mblFeatureId feature id of the MobileFeatureProperties to be retrieved. - * @return List of MobileFeatureProperty objects that holds data of the MobileFeatureProperties - * represented by featureId. - * @throws MobileDeviceManagementDAOException - */ - List getFeaturePropertiesOfFeature(Integer mblFeatureId) - throws MobileDeviceManagementDAOException; - -} From 728cf398535a6fc2d4245809c93104a40e60ad50 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 30 Oct 2015 20:00:59 +0530 Subject: [PATCH 20/22] refactored code issues --- .../mgt/mobile/impl/android/dao/AndroidDAOFactory.java | 6 +----- 1 file changed, 1 insertion(+), 5 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/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 1eaa717af0..3a9e527581 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 @@ -47,11 +47,7 @@ public class AndroidDAOFactory extends AbstractMobileDeviceManagementDAOFactory public MobileFeatureDAO getMobileFeatureDAO() { return new AndroidFeatureDAOImpl(); } - - public MobileFeaturePropertyDAO getFeaturePropertyDAO() { - return null; - } - + public static void beginTransaction() throws MobileDeviceManagementDAOException { try { Connection conn = dataSource.getConnection(); From 20fd4c1efff6a104dc687ce511b69d5012c7e0cf Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 30 Oct 2015 20:04:24 +0530 Subject: [PATCH 21/22] refactored code issues --- .../impl/MobileFeaturePropertyDAOImpl.java | 250 ------------------ .../impl/android/dao/AndroidDAOFactory.java | 2 +- 2 files changed, 1 insertion(+), 251 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java deleted file mode 100644 index a71db74ab3..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java +++ /dev/null @@ -1,250 +0,0 @@ -///* -// * Copyright (c) 2014, 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.dao.impl; -// -//import org.apache.commons.logging.Log; -//import org.apache.commons.logging.LogFactory; -//import org.wso2.carbon.device.mgt.mobile.dao.MobileFeaturePropertyDAO; -//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.MobileFeatureProperty; -// -//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; -// -///** -// * Implementation of MobileFeaturePropertyDAO. -// */ -//public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { -// -// private DataSource dataSource; -// private static final Log log = LogFactory.getLog(MobileFeaturePropertyDAOImpl.class); -// -// public MobileFeaturePropertyDAOImpl(DataSource dataSource) { -// this.dataSource = dataSource; -// } -// -// @Override -// public boolean addMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty) -// throws MobileDeviceManagementDAOException { -// boolean status = false; -// Connection conn = null; -// PreparedStatement stmt = null; -// try { -// conn = this.getConnection(); -// String createDBQuery = -// "INSERT INTO AD_FEATURE_PROPERTY(PROPERTY, FEATURE_ID) VALUES (?, ?)"; -// -// stmt = conn.prepareStatement(createDBQuery); -// stmt.setString(1, mblFeatureProperty.getProperty()); -// stmt.setInt(2, mblFeatureProperty.getFeatureID()); -// int rows = stmt.executeUpdate(); -// if (rows > 0) { -// status = true; -// if (log.isDebugEnabled()) { -// log.debug("Added MobileFeatureProperty " + mblFeatureProperty.getProperty() + -// " to the MDM database."); -// } -// } -// } catch (SQLException e) { -// String msg = "Error occurred while adding property id - '" + -// mblFeatureProperty.getFeatureID() + "'"; -// log.error(msg, e); -// throw new MobileDeviceManagementDAOException(msg, e); -// } finally { -// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); -// } -// return status; -// } -// -// @Override -// public boolean updateMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty) -// throws MobileDeviceManagementDAOException { -// boolean status = false; -// Connection conn = null; -// PreparedStatement stmt = null; -// try { -// conn = this.getConnection(); -// String updateDBQuery = -// "UPDATE AD_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?"; -// stmt = conn.prepareStatement(updateDBQuery); -// stmt.setInt(1, mblFeatureProperty.getFeatureID()); -// stmt.setString(2, mblFeatureProperty.getProperty()); -// int rows = stmt.executeUpdate(); -// if (rows > 0) { -// status = true; -// if (log.isDebugEnabled()) { -// log.debug("Updated MobileFeatureProperty " + mblFeatureProperty.getProperty()); -// } -// } -// } catch (SQLException e) { -// String msg = "Error occurred while updating the feature property with property - '" + -// mblFeatureProperty.getProperty() + "'"; -// log.error(msg, e); -// throw new MobileDeviceManagementDAOException(msg, e); -// } finally { -// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); -// } -// return status; -// } -// -// @Override -// public boolean deleteMobileFeatureProperty(String property) -// throws MobileDeviceManagementDAOException { -// boolean status = false; -// Connection conn = null; -// PreparedStatement stmt = null; -// try { -// conn = this.getConnection(); -// String deleteDBQuery = -// "DELETE FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?"; -// stmt = conn.prepareStatement(deleteDBQuery); -// stmt.setString(1, property); -// int rows = stmt.executeUpdate(); -// if (rows > 0) { -// status = true; -// if (log.isDebugEnabled()) { -// log.debug("Deleted MobileFeatureProperty " + property + " from MDM database."); -// } -// } -// } catch (SQLException e) { -// String msg = "Error occurred while deleting feature property with property - " + -// property; -// log.error(msg, e); -// throw new MobileDeviceManagementDAOException(msg, e); -// } finally { -// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); -// } -// return status; -// } -// -// @Override -// public boolean deleteMobileFeaturePropertiesOfFeature(Integer mblFeatureId) -// throws MobileDeviceManagementDAOException { -// boolean status = false; -// Connection conn = null; -// PreparedStatement stmt = null; -// try { -// conn = this.getConnection(); -// String deleteDBQuery = -// "DELETE FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; -// stmt = conn.prepareStatement(deleteDBQuery); -// stmt.setInt(1, mblFeatureId); -// int rows = stmt.executeUpdate(); -// if (rows > 0) { -// status = true; -// if (log.isDebugEnabled()) { -// log.debug("Deleted all MobileFeatureProperties of FeatureId " + mblFeatureId + -// " from MDM database."); -// } -// } -// } catch (SQLException e) { -// String msg = "Error occurred while deleting feature properties of feature - " + -// mblFeatureId; -// log.error(msg, e); -// throw new MobileDeviceManagementDAOException(msg, e); -// } finally { -// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); -// } -// return status; -// } -// -// @Override -// public MobileFeatureProperty getMobileFeatureProperty(String property) -// throws MobileDeviceManagementDAOException { -// Connection conn = null; -// PreparedStatement stmt = null; -// MobileFeatureProperty mobileFeatureProperty = null; -// try { -// conn = this.getConnection(); -// String selectDBQuery = -// "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE PROPERTY = ?"; -// stmt = conn.prepareStatement(selectDBQuery); -// stmt.setString(1, property); -// ResultSet resultSet = stmt.executeQuery(); -// if (resultSet.next()) { -// mobileFeatureProperty = new MobileFeatureProperty(); -// mobileFeatureProperty.setProperty(resultSet.getString(1)); -// mobileFeatureProperty.setFeatureID(resultSet.getInt(2)); -// if (log.isDebugEnabled()) { -// log.debug("Fetched MobileFeatureProperty " + mobileFeatureProperty.getProperty() + -// " from MDM database."); -// } -// } -// } catch (SQLException e) { -// String msg = "Error occurred while fetching property - '" + -// property + "'"; -// log.error(msg, e); -// throw new MobileDeviceManagementDAOException(msg, e); -// } finally { -// MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); -// } -// return mobileFeatureProperty; -// } -// -// @Override -// public List getFeaturePropertiesOfFeature(Integer mblFeatureId) -// throws MobileDeviceManagementDAOException { -// Connection conn = null; -// PreparedStatement stmt = null; -// MobileFeatureProperty mobileFeatureProperty; -// List FeatureProperties = new ArrayList(); -// try { -// conn = this.getConnection(); -// String selectDBQuery = -// "SELECT PROPERTY, FEATURE_ID FROM AD_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; -// stmt = conn.prepareStatement(selectDBQuery); -// stmt.setInt(1, mblFeatureId); -// ResultSet resultSet = stmt.executeQuery(); -// while (resultSet.next()) { -// mobileFeatureProperty = new MobileFeatureProperty(); -// mobileFeatureProperty.setProperty(resultSet.getString(1)); -// mobileFeatureProperty.setFeatureID(resultSet.getInt(2)); -// FeatureProperties.add(mobileFeatureProperty); -// } -// if (log.isDebugEnabled()) { -// log.debug("Fetched all MobileFeatureProperties of featureId " + mblFeatureId + -// " from MDM database."); -// } -// return FeatureProperties; -// } catch (SQLException e) { -// String msg = "Error occurred while fetching all feature property.'"; -// 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/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 3a9e527581..c96bbf437e 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 @@ -47,7 +47,7 @@ public class AndroidDAOFactory extends AbstractMobileDeviceManagementDAOFactory public MobileFeatureDAO getMobileFeatureDAO() { return new AndroidFeatureDAOImpl(); } - + public static void beginTransaction() throws MobileDeviceManagementDAOException { try { Connection conn = dataSource.getConnection(); From 7701015ea095009e6f04517edd8e128644e45e14 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 30 Oct 2015 20:12:26 +0530 Subject: [PATCH 22/22] refactored code conflicts --- .../mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java index 8b5d11a933..da1bdfa474 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java @@ -120,10 +120,8 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO { } } } catch (SQLException e) { - String msg = "Error occurred while updating the Windows Feature '" + - mobileFeature.getCode() + "' to the Android db."; - log.error(msg, e); - throw new WindowsFeatureManagementDAOException(msg, e); + throw new WindowsFeatureManagementDAOException("Error occurred while updating the Windows Feature '" + + mobileFeature.getCode() + "' to the Windows db.", e); } finally { MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); }