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 b820c40d79..01626c3642 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 @@ -86,5 +86,14 @@ public interface MobileFeatureDAO { * @return Feature object list. * @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 getMobileFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException; + List getAllMobileFeatures() 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 5faf3b9641..850d034761 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 30dc4db147..df6780f8e6 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.setInt(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 getMobileFeatureByDeviceType(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 766c6aca68..c08076a08a 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 38b6944d61..9bfed2780d 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/dto/MobileFeatureProperty.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeatureProperty.java index 5068006cad..d6ef7d10e7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeatureProperty.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeatureProperty.java @@ -22,13 +22,13 @@ package org.wso2.carbon.device.mgt.mobile.dto; public class MobileFeatureProperty { private String property; - private String featureID; + private Integer featureID; - public String getFeatureID() { + public Integer getFeatureID() { return featureID; } - public void setFeatureID(String featureID) { + public void setFeatureID(Integer featureID) { this.featureID = featureID; } 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 af3622e9cb..96706117e7 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,39 @@ 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.getMobileFeatureByDeviceType(deviceType); + for (MobileFeature mobileFeature : mobileFeatures) { + Feature feature = new Feature(); + feature.setId(mobileFeature.getId()); + feature.setDeviceType(mobileFeature.getDeviceType()); + feature.setName(mobileFeature.getName()); + feature.setDescription(mobileFeature.getDescription()); + 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 diff --git a/product/modules/distribution/src/repository/database/WSO2MobileDM_DB.h2.db b/product/modules/distribution/src/repository/database/WSO2MobileDM_DB.h2.db index 78086440fd..361e1db39d 100644 Binary files a/product/modules/distribution/src/repository/database/WSO2MobileDM_DB.h2.db and b/product/modules/distribution/src/repository/database/WSO2MobileDM_DB.h2.db differ diff --git a/product/modules/distribution/src/repository/dbscripts/cdm/plugins/h2.sql b/product/modules/distribution/src/repository/dbscripts/cdm/plugins/h2.sql index aab99bd146..86e0de45ff 100644 --- a/product/modules/distribution/src/repository/dbscripts/cdm/plugins/h2.sql +++ b/product/modules/distribution/src/repository/dbscripts/cdm/plugins/h2.sql @@ -20,6 +20,7 @@ CREATE TABLE IF NOT EXISTS `MBL_DEVICE` ( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( `FEATURE_ID` INT NOT NULL AUTO_INCREMENT , + `DEVICE_TYPE` VARCHAR(45) NOT NULL , `CODE` VARCHAR(45) NOT NULL , `NAME` VARCHAR(100) NULL , `DESCRIPTION` VARCHAR(200) NULL , @@ -74,10 +75,15 @@ CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` ( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` ( `PROPERTY` VARCHAR(45) NOT NULL , - `FEATURE_ID` VARCHAR(45) NOT NULL , + `FEATURE_ID` INT NOT NULL , PRIMARY KEY (`PROPERTY`) , CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1` FOREIGN KEY (`FEATURE_ID` ) REFERENCES `MBL_FEATURE` (`FEATURE_ID` ) ON DELETE NO ACTION ON UPDATE NO ACTION); + +-- ----------------------------------------------------- +-- Inserts +-- ----------------------------------------------------- +Insert into MBL_FEATURE (DEVICE_TYPE_ID,CODE, NAME, DESCRIPTION) VALUES ('android', "503A", "DEVICE_LOCK", "Device lock"); \ No newline at end of file diff --git a/product/modules/distribution/src/repository/dbscripts/cdm/plugins/mysql.sql b/product/modules/distribution/src/repository/dbscripts/cdm/plugins/mysql.sql index 3e6ee30a5f..2928514d4a 100644 --- a/product/modules/distribution/src/repository/dbscripts/cdm/plugins/mysql.sql +++ b/product/modules/distribution/src/repository/dbscripts/cdm/plugins/mysql.sql @@ -20,6 +20,7 @@ ENGINE = InnoDB; -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( `FEATURE_ID` INT NOT NULL AUTO_INCREMENT, + `DEVICE_TYPE_ID` INT NOT NULL, `CODE` VARCHAR(45) NULL, `NAME` VARCHAR(100) NULL, `DESCRIPTION` VARCHAR(200) NULL, @@ -97,4 +98,8 @@ CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` ( ENGINE = InnoDB; +-- ----------------------------------------------------- +-- Inserts +-- ----------------------------------------------------- +Insert into MBL_FEATURE (DEVICE_TYPE_ID,CODE, NAME, DESCRIPTION) VALUES ('android', "503A", "DEVICE_LOCK", "Device lock"); diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/api/mobile/device-api.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/api/mobile/device-api.jag index 783176d285..298a62d763 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/api/mobile/device-api.jag +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/api/mobile/device-api.jag @@ -22,6 +22,7 @@ var uri = request.getRequestURI(); var callPath=uri.replace("/cdm/api/",""); var log = new Log(); var deviceModule = require("/modules/device.js"); + if (uri != null) { var uriMatcher = new URIMatcher(callPath); log.info(callPath); diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/api/mobile/operation-api.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/api/mobile/operation-api.jag new file mode 100644 index 0000000000..b11875d1eb --- /dev/null +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/api/mobile/operation-api.jag @@ -0,0 +1,40 @@ +<% +/* + * 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. + */ + +var verb = request.getMethod(); +var uri = request.getRequestURI(); +var callPath=uri.replace("/cdm/api/",""); +var log = new Log(); +var deviceModule = require("/modules/device.js"); + +if (uri != null) { + var uriMatcher = new URIMatcher(callPath); + //log.info(callPath); + log.info(uriMatcher.match("operation/{type}/{deviceid}/{operation}")); + if (uriMatcher.match("operation/{type}/{deviceid}/{operation}")) { + + var deviceId = uriMatcher.elements().deviceid; + var type = uriMatcher.elements().type; + var operation = uriMatcher.elements().operation; + var result = deviceModule.performOperation(deviceId, operation,[],type); + + + } +} +%> \ No newline at end of file diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/client/javascript/main.js b/product/modules/distribution/src/repository/jaggeryapps/cdm/client/javascript/main.js index 0fa9dd49d8..af57503dac 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/client/javascript/main.js +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/client/javascript/main.js @@ -21,4 +21,22 @@ function identifierFormatter(value, row, index) { value, '' ].join(''); -} \ No newline at end of file +} + +var currentDeviceOperation; +var currentDevice; +var currentDeviceType; +function performOperation(){ + currentDevice = $("#deviceMain").data("deviceid"); + currentDeviceType = $("#deviceMain").data("devicetype"); + $.post("/cdm/api/operation/"+currentDeviceType+"/"+currentDevice+"/"+currentDeviceOperation,function(){ + $('#confirmModel').modal('hide'); + }); +} + +$(document).ready(function(){ + $(".device-operation").click(function(){ + currentDeviceOperation = $(this).data("operation"); + $('#confirmModel').modal('show'); + }); +}); \ No newline at end of file diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/includes/footer.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/includes/footer.jag index 49db93e039..a62b5cfb80 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/includes/footer.jag +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/includes/footer.jag @@ -1,3 +1,21 @@ <% // footer includes -%> \ No newline at end of file +%> + + \ No newline at end of file diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/jaggery.conf b/product/modules/distribution/src/repository/jaggeryapps/cdm/jaggery.conf index efc8b12576..92697a30fa 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/jaggery.conf +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/jaggery.conf @@ -10,6 +10,10 @@ "url": "/dashboard", "path": "/pages/dashboard.jag" }, + { + "url" : "/api/operation/*", + "path": "/api/mobile/operation-api.jag" + }, { "url": "/api/devices/mobile/*", "path": "/api/mobile/device-api.jag" diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/device.js b/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/device.js index 13d77bc291..59fd1ba0c5 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/device.js +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/device.js @@ -19,16 +19,16 @@ var utility = require("/modules/utility.js"); var DeviceIdentifier = Packages.org.wso2.carbon.device.mgt.common.DeviceIdentifier; var DeviceManagerUtil = Packages.org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; +var Operation = Packages.org.wso2.carbon.device.mgt.common.Operation; +var Type = Packages.org.wso2.carbon.device.mgt.common.Operation.Type; +var Properties = Packages.java.util.Properties; +var ArrayList = Packages.java.util.ArrayList; var log = new Log(); var deviceManagementService = utility.getDeviceManagementService(); var listDevices = function () { - var devices = deviceManagementService.getAllDevices("android"); - var deviceList = []; - - for (i = 0; i < devices.size(); i++) { var device = devices.get(i); @@ -54,10 +54,38 @@ var getDevice = function(type, deviceId){ return device; } -var viewDevice = function(type, deviceId){ +var getOperations = function(type){ + var features = deviceManagementService.getOperationManager("android").getFeaturesForDeviceType(type); + var featuresConverted = []; + for (i = 0; i < features.size(); i++) { + var feature = features.get(i); + featuresConverted.push({ + "featureName": feature.getName(), + "featureDescription": feature.getDescription() + }); + } + return featuresConverted; +} +var performOperation = function(deviceId, featureName, properties, type){ + var operation = new Operation(); + operation.setCode(featureName); + operation.setType(Type.COMMAND); + var props = new Properties(); + for (i = 0; i < properties.length; i++) { + var object = properties[i]; + props.setProperty(object.key,object.value); + } + operation.setProperties(props); + var deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId) + deviceIdentifier.setType(type); + var deviceList = new ArrayList(); + deviceList.add(deviceIdentifier); + deviceManagementService.getOperationManager("android").addOperation(operation, deviceList); +} +var viewDevice = function(type, deviceId){ var device = this.getDevice(type, deviceId); - var propertiesList = DeviceManagerUtil.convertPropertiesToMap(device.getProperties()); var entries = propertiesList.entrySet(); var iterator = entries.iterator(); diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/dashboard.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/dashboard.jag index 46c5cd3dad..8bf721890f 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/dashboard.jag +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/dashboard.jag @@ -73,6 +73,7 @@ var title="WSO2 CDM"; <% + include("/includes/footer.jag"); include("/includes/layout-footer.jag"); %> diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/device.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/device.jag index 91977bdade..17a14734d5 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/device.jag +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/device.jag @@ -35,22 +35,26 @@ var title="WSO2 CDM"; var deviceId = uriMatcher.elements().deviceid; var type = uriMatcher.elements().type; var device = deviceModule.viewDevice(type, deviceId); + var operations = deviceModule.getOperations("android"); %> -
+

<%=device.name%>

- - + <% + } +%>
@@ -97,6 +101,7 @@ var title="WSO2 CDM";
<% + include("/includes/footer.jag"); include("/includes/layout-footer.jag"); %>