From df09c4bd3c6b75a62ac04afe1238c980cf9c8a4d Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 23 Jan 2015 18:39:28 +0530 Subject: [PATCH] * Added method to the mobile feature DAO to get features by type * Changed method - getFeaturePropertyOfFeature to accept a string * Added Device Type to the Feature DAO implementations * Changed Device Feature properties DAO for Int * Implemented the get feature by type to android operation manager --- .../mgt/mobile/dao/MobileFeatureDAO.java | 9 +++ .../mobile/dao/MobileFeaturePropertyDAO.java | 2 +- .../mobile/dao/impl/MobileFeatureDAOImpl.java | 69 ++++++++++++++----- .../impl/MobileFeaturePropertyDAOImpl.java | 12 ++-- .../device/mgt/mobile/dto/MobileFeature.java | 8 +++ .../AndroidMobileOperationManager.java | 44 ++++++++++-- 6 files changed, 115 insertions(+), 29 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java index 8b516443a..28a6aafe9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java @@ -87,4 +87,13 @@ public interface MobileFeatureDAO { * @throws MobileDeviceManagementDAOException */ List getAllFeatures() throws MobileDeviceManagementDAOException; + + /** + * Retrieve all the features from plugin specific database for a Device Type. + * @param deviceType - Device type. + * @return Feature object list. + * @throws MobileDeviceManagementDAOException + */ + List getFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/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 index a61a598a9..fce7df41b 100644 --- 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 @@ -70,7 +70,7 @@ public interface MobileFeaturePropertyDAO { * @return Feature property object that holds data of the feature property represented by propertyId. * @throws MobileDeviceManagementDAOException */ - List getFeaturePropertyOfFeature(String featureId) + List getFeaturePropertyOfFeature(Integer featureId) throws MobileDeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java index 6f983089d..89fa32915 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java @@ -18,8 +18,8 @@ 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.MobileFeatureDAO; 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; @@ -51,12 +51,13 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String createDBQuery = - "INSERT INTO MBL_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; + "INSERT INTO MBL_FEATURE(CODE, NAME, DESCRIPTION, DEVICE_TYPE) VALUES (?, ?, ?, ?)"; stmt = conn.prepareStatement(createDBQuery); stmt.setString(1, mobileFeature.getCode()); stmt.setString(2, mobileFeature.getName()); stmt.setString(3, mobileFeature.getDescription()); + stmt.setString(4, mobileFeature.getDeviceType()); int rows = stmt.executeUpdate(); if (rows > 0) { status = true; @@ -81,12 +82,13 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String updateDBQuery = - "UPDATE MBL_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ? WHERE FEATURE_ID = ?"; + "UPDATE MBL_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ?, DEVICE_TYPE = ? WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setString(1, mobileFeature.getCode()); stmt.setString(2, mobileFeature.getName()); stmt.setString(3, mobileFeature.getDescription()); - stmt.setInt(4, mobileFeature.getId()); + stmt.setString(4, mobileFeature.getDeviceType()); + stmt.setInt(5, mobileFeature.getId()); int rows = stmt.executeUpdate(); if (rows > 0) { status = true; @@ -163,16 +165,17 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = ?"; + "SELECT FEATURE_ID,DEVICE_TYPE, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, featureCode); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { mobileFeature = new MobileFeature(); mobileFeature.setId(resultSet.getInt(1)); - mobileFeature.setCode(resultSet.getString(2)); - mobileFeature.setName(resultSet.getString(3)); - mobileFeature.setDescription(resultSet.getString(4)); + mobileFeature.setDeviceType(resultSet.getString(2)); + mobileFeature.setCode(resultSet.getString(3)); + mobileFeature.setName(resultSet.getString(4)); + mobileFeature.setDescription(resultSet.getString(5)); break; } } catch (SQLException e) { @@ -195,16 +198,17 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE FEATURE_ID = ?"; + "SELECT FEATURE_ID,DEVICE_TYPE, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); stmt.setString(1, featureID); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { mobileFeature = new MobileFeature(); mobileFeature.setId(resultSet.getInt(1)); - mobileFeature.setCode(resultSet.getString(2)); - mobileFeature.setName(resultSet.getString(3)); - mobileFeature.setDescription(resultSet.getString(4)); + mobileFeature.setDeviceType(resultSet.getString(2)); + mobileFeature.setCode(resultSet.getString(3)); + mobileFeature.setName(resultSet.getString(4)); + mobileFeature.setDescription(resultSet.getString(5)); break; } } catch (SQLException e) { @@ -227,15 +231,16 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { try { conn = this.getConnection(); String selectDBQuery = - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE"; + "SELECT FEATURE_ID,DEVICE_TYPE, CODE, NAME, DESCRIPTION FROM MBL_FEATURE"; stmt = conn.prepareStatement(selectDBQuery); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { mobileFeature = new MobileFeature(); mobileFeature.setId(resultSet.getInt(1)); - mobileFeature.setCode(resultSet.getString(2)); - mobileFeature.setName(resultSet.getString(3)); - mobileFeature.setDescription(resultSet.getString(4)); + mobileFeature.setDeviceType(resultSet.getString(2)); + mobileFeature.setCode(resultSet.getString(3)); + mobileFeature.setName(resultSet.getString(4)); + mobileFeature.setDescription(resultSet.getString(5)); mobileFeatures.add(mobileFeature); } return mobileFeatures; @@ -248,6 +253,38 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { } } + @Override + public List getFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + MobileFeature mobileFeature; + List mobileFeatures = new ArrayList(); + try { + conn = this.getConnection(); + String selectDBQuery = + "SELECT FEATURE_ID, DEVICE_TYPE, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE DEVICE_TYPE = ?"; + stmt = conn.prepareStatement(selectDBQuery); + stmt.setString(1, deviceType); + ResultSet resultSet = stmt.executeQuery(); + while (resultSet.next()) { + mobileFeature = new MobileFeature(); + mobileFeature.setId(resultSet.getInt(1)); + mobileFeature.setDeviceType(resultSet.getString(2)); + mobileFeature.setCode(resultSet.getString(3)); + mobileFeature.setName(resultSet.getString(4)); + mobileFeature.setDescription(resultSet.getString(5)); + mobileFeatures.add(mobileFeature); + } + return mobileFeatures; + } catch (SQLException e) { + String msg = "Error occurred while fetching all features.'"; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + }finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + } + private Connection getConnection() throws MobileDeviceManagementDAOException { try { return dataSource.getConnection(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/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 f99a2c7f0..759bba19b 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 @@ -56,7 +56,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { stmt = conn.prepareStatement(createDBQuery); stmt.setString(1, mobileFeatureProperty.getProperty()); - stmt.setString(2, mobileFeatureProperty.getFeatureID()); + stmt.setInt(2, mobileFeatureProperty.getFeatureID()); int rows = stmt.executeUpdate(); if (rows > 0) { status = true; @@ -83,7 +83,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { String updateDBQuery = "UPDATE MBL_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?"; stmt = conn.prepareStatement(updateDBQuery); - stmt.setString(1, mobileFeatureProperty.getFeatureID()); + stmt.setInt(1, mobileFeatureProperty.getFeatureID()); stmt.setString(2, mobileFeatureProperty.getProperty()); int rows = stmt.executeUpdate(); if (rows > 0) { @@ -143,7 +143,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { while (resultSet.next()) { mobileFeatureProperty = new MobileFeatureProperty(); mobileFeatureProperty.setProperty(resultSet.getString(1)); - mobileFeatureProperty.setFeatureID(resultSet.getString(2)); + mobileFeatureProperty.setFeatureID(resultSet.getInt(2)); break; } } catch (SQLException e) { @@ -158,7 +158,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { } @Override - public List getFeaturePropertyOfFeature(String featureId) + public List getFeaturePropertyOfFeature(Integer featureId) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; @@ -169,12 +169,12 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { String selectDBQuery = "SELECT PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); - stmt.setString(1, featureId); + stmt.setInt(1, featureId); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { mobileFeatureProperty = new MobileFeatureProperty(); mobileFeatureProperty.setProperty(resultSet.getString(1)); - mobileFeatureProperty.setFeatureID(resultSet.getString(2)); + mobileFeatureProperty.setFeatureID(resultSet.getInt(2)); FeatureProperties.add(mobileFeatureProperty); } return FeatureProperties; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeature.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeature.java index 38b6944d6..9bfed2780 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeature.java @@ -24,6 +24,7 @@ import java.io.Serializable; public class MobileFeature implements Serializable { private int id; + private String deviceType; private String code; private String name; private String description; @@ -60,4 +61,11 @@ public class MobileFeature implements Serializable { this.description = description; } + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java index aeb22ba7b..765dabd09 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java @@ -17,15 +17,13 @@ package org.wso2.carbon.device.mgt.mobile.impl.android; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.Operation; -import org.wso2.carbon.device.mgt.common.OperationManagementException; +import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.mobile.AbstractMobileOperationManager; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping; -import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; -import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty; +import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; +import org.wso2.carbon.device.mgt.mobile.dao.MobileFeaturePropertyDAO; +import org.wso2.carbon.device.mgt.mobile.dto.*; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; import java.util.ArrayList; @@ -155,4 +153,38 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage } return operations; } + + @Override + public List getFeaturesForDeviceType(String deviceType) throws FeatureManagementException { + MobileFeatureDAO featureDAO = MobileDeviceManagementDAOFactory.getFeatureDAO(); + MobileFeaturePropertyDAO featurePropertyDAO = MobileDeviceManagementDAOFactory.getFeaturePropertyDAO(); + List features = new ArrayList(); + try { + List mobileFeatures = featureDAO.getFeatureByDeviceType(deviceType); + for (MobileFeature mobileFeature : mobileFeatures) { + Feature feature = new Feature(); + feature.setId(mobileFeature.getId()); + feature.setDeviceType(mobileFeature.getDeviceType()); + feature.setName(mobileFeature.getName()); + List metadataEntries = new ArrayList(); + List properties = + featurePropertyDAO.getFeaturePropertyOfFeature(mobileFeature.getId()); + for (MobileFeatureProperty property : properties) { + Feature.MetadataEntry metaEntry = new Feature.MetadataEntry(); + metaEntry.setId(property.getFeatureID()); + metaEntry.setValue(property.getProperty()); + metadataEntries.add(metaEntry); + } + feature.setMetadataEntries(metadataEntries); + features.add(feature); + } + } catch (MobileDeviceManagementDAOException e) { + String msg = + "Error while fetching the features for the device type " + + deviceType; + log.error(msg, e); + throw new FeatureManagementException(msg, e); + } + return features; + } } \ No newline at end of file