From a277fd53c22806c2b405c82e2889849ce5db57cc Mon Sep 17 00:00:00 2001 From: hasuniea Date: Wed, 21 Oct 2015 19:29:34 +0530 Subject: [PATCH 01/12] 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 000000000..5444fd223 --- /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 000000000..e69e20997 --- /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 50f8f15c3..53515ccf0 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/12] 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 3c1ba0424..170023c69 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 e69e20997..a8c110942 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 638f3bf67..041cffa7f 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 03f61fdd7..dd2b325c1 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 9adfb05b37ed705fe5316d49d369bc79196c55d1 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Thu, 29 Oct 2015 14:12:52 +0530 Subject: [PATCH 03/12] 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 18e9d6360..106b1def7 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 889d40f26..21396b766 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 f9e930d8b..0cf128d4c 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 a8c110942..682767071 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 c905c89a4..4bcd1e3db 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 ecdacf5b9..347f1ad2e 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 952b4d817..8a96b7947 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 45754d06f..865f30682 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 04/12] 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 21396b766..5194d53e4 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 0cf128d4c..40f8cc46e 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 05/12] 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 041cffa7f..000000000 --- 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 06/12] 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 4fa2871ac..e13b4642d 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 07/12] 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 5194d53e4..80d1bd5b9 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 85fdb3c930344960041461bad91d97980d20c487 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 30 Oct 2015 19:48:45 +0530 Subject: [PATCH 08/12] 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 e3edfc324..a71db74ab 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 80d1bd5b9..0dca8b5d6 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 682767071..8b5d11a93 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 02f66bf04..000000000 --- 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 5c0c296a3..000000000 --- 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 68f54744a..f73ab880b 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 09/12] 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 51a6cef28..000000000 --- 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 10/12] 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 1eaa717af..3a9e52758 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 11/12] 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 a71db74ab..000000000 --- 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 3a9e52758..c96bbf437 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 12/12] 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 8b5d11a93..da1bdfa47 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); }