Deprecating obsolete UI functions - device.js

revert-70aa11f8
dilanua 8 years ago
parent bc4192280c
commit 303f16e747

@ -25,18 +25,18 @@ deviceModule = function () {
var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
var ArrayList = Packages.java.util.ArrayList; // var ArrayList = Packages.java.util.ArrayList;
var Properties = Packages.java.util.Properties; // var Properties = Packages.java.util.Properties;
var DeviceIdentifier = Packages.org.wso2.carbon.device.mgt.common.DeviceIdentifier; // var DeviceIdentifier = Packages.org.wso2.carbon.device.mgt.common.DeviceIdentifier;
var DeviceManagerUtil = Packages.org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; // var DeviceManagerUtil = Packages.org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
var SimpleOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.SimpleOperation; // var SimpleOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.SimpleOperation;
var ConfigOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation; // var ConfigOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation;
var CommandOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; // var CommandOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
var publicMethods = {}; var publicMethods = {};
var privateMethods = {}; var privateMethods = {};
var deviceCloudService = devicemgtProps["httpsURL"] + "/common/device_manager"; // var deviceCloudService = devicemgtProps["httpsURL"] + "/common/device_manager";
privateMethods.validateAndReturn = function (value) { privateMethods.validateAndReturn = function (value) {
return (value == undefined || value == null) ? constants.UNSPECIFIED : value; return (value == undefined || value == null) ? constants.UNSPECIFIED : value;
@ -45,57 +45,57 @@ deviceModule = function () {
/* /*
@Deprecated @Deprecated
*/ */
publicMethods.listDevices = function () { // publicMethods.listDevices = function () {
var carbonUser = session.get(constants.USER_SESSION_KEY); // var carbonUser = session.get(constants.USER_SESSION_KEY);
var utility = require('/app/modules/utility.js').utility; // var utility = require('/app/modules/utility.js').utility;
if (!carbonUser) { // if (!carbonUser) {
log.error("User object was not found in the session"); // log.error("User object was not found in the session");
throw constants.ERRORS.USER_NOT_FOUND; // throw constants.ERRORS.USER_NOT_FOUND;
} // }
try { // try {
utility.startTenantFlow(carbonUser); // utility.startTenantFlow(carbonUser);
var deviceManagementService = utility.getDeviceManagementService(); // var deviceManagementService = utility.getDeviceManagementService();
var devices = deviceManagementService.getAllDevices(); // var devices = deviceManagementService.getAllDevices();
var deviceList = []; // var deviceList = [];
var i, device, propertiesList, deviceObject; // var i, device, propertiesList, deviceObject;
for (i = 0; i < devices.size(); i++) { // for (i = 0; i < devices.size(); i++) {
device = devices.get(i); // device = devices.get(i);
propertiesList = DeviceManagerUtil.convertDevicePropertiesToMap(device.getProperties()); // propertiesList = DeviceManagerUtil.convertDevicePropertiesToMap(device.getProperties());
//
deviceObject = {}; // deviceObject = {};
deviceObject[constants.DEVICE_IDENTIFIER] = // deviceObject[constants.DEVICE_IDENTIFIER] =
privateMethods.validateAndReturn(device.getDeviceIdentifier()); // privateMethods.validateAndReturn(device.getDeviceIdentifier());
deviceObject[constants.DEVICE_NAME] = // deviceObject[constants.DEVICE_NAME] =
privateMethods.validateAndReturn(device.getName()); // privateMethods.validateAndReturn(device.getName());
deviceObject[constants.DEVICE_OWNERSHIP] = // deviceObject[constants.DEVICE_OWNERSHIP] =
privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwnership()); // privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwnership());
deviceObject[constants.DEVICE_OWNER] = // deviceObject[constants.DEVICE_OWNER] =
privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwner()); // privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwner());
deviceObject[constants.DEVICE_TYPE] = // deviceObject[constants.DEVICE_TYPE] =
privateMethods.validateAndReturn(device.getType()); // privateMethods.validateAndReturn(device.getType());
deviceObject[constants.DEVICE_PROPERTIES] = {}; // deviceObject[constants.DEVICE_PROPERTIES] = {};
if (device.getType() == constants.PLATFORM_IOS) { // if (device.getType() == constants.PLATFORM_IOS) {
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] = // deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_PRODUCT)); // privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_PRODUCT));
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] = constants.VENDOR_APPLE; // deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] = constants.VENDOR_APPLE;
} else { // } else {
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] = // deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_MODEL)); // privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_MODEL));
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] = // deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] =
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_VENDOR)); // privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_VENDOR));
} // }
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_OS_VERSION] = // deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_OS_VERSION] =
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_OS_VERSION)); // privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_OS_VERSION));
//
deviceList.push(deviceObject); // deviceList.push(deviceObject);
} // }
return deviceList; // return deviceList;
} catch (e) { // } catch (e) {
throw e; // throw e;
} finally { // } finally {
utility.endTenantFlow(); // utility.endTenantFlow();
} // }
}; // };
/* /*
@Deprecated @Deprecated
@ -103,105 +103,105 @@ deviceModule = function () {
/* /*
Get the supported features by the device type Get the supported features by the device type
*/ */
publicMethods.getFeatures = function (deviceType) { // publicMethods.getFeatures = function (deviceType) {
var carbonUser = session.get(constants.USER_SESSION_KEY); // var carbonUser = session.get(constants.USER_SESSION_KEY);
var utility = require('/app/modules/utility.js').utility; // var utility = require('/app/modules/utility.js').utility;
if (!carbonUser) { // if (!carbonUser) {
log.error("User object was not found in the session"); // log.error("User object was not found in the session");
throw constants.ERRORS.USER_NOT_FOUND; // throw constants.ERRORS.USER_NOT_FOUND;
} // }
try { // try {
utility.startTenantFlow(carbonUser); // utility.startTenantFlow(carbonUser);
var deviceManagementService = utility.getDeviceManagementService(); // var deviceManagementService = utility.getDeviceManagementService();
var features = deviceManagementService.getFeatureManager(deviceType).getFeatures(); // var features = deviceManagementService.getFeatureManager(deviceType).getFeatures();
var featuresConverted = {}; // var featuresConverted = {};
if (features) { // if (features) {
var i, feature, featureObject; // var i, feature, featureObject;
for (i = 0; i < features.size(); i++) { // for (i = 0; i < features.size(); i++) {
feature = features.get(i); // feature = features.get(i);
featureObject = {}; // featureObject = {};
featureObject[constants.FEATURE_NAME] = feature.getName(); // featureObject[constants.FEATURE_NAME] = feature.getName();
featureObject[constants.FEATURE_DESCRIPTION] = feature.getDescription(); // featureObject[constants.FEATURE_DESCRIPTION] = feature.getDescription();
featuresConverted[feature.getName()] = featureObject; // featuresConverted[feature.getName()] = featureObject;
} // }
} // }
return featuresConverted; // return featuresConverted;
} catch (e) { // } catch (e) {
throw e; // throw e;
} finally { // } finally {
utility.endTenantFlow(); // utility.endTenantFlow();
} // }
}; // };
/* /*
@Deprecated @Deprecated
*/ */
publicMethods.performOperation = function (devices, operation) { // publicMethods.performOperation = function (devices, operation) {
var carbonUser = session.get(constants.USER_SESSION_KEY); // var carbonUser = session.get(constants.USER_SESSION_KEY);
var utility = require('/app/modules/utility.js').utility; // var utility = require('/app/modules/utility.js').utility;
if (!carbonUser) { // if (!carbonUser) {
log.error("User object was not found in the session"); // log.error("User object was not found in the session");
throw constants.ERRORS.USER_NOT_FOUND; // throw constants.ERRORS.USER_NOT_FOUND;
} // }
try { // try {
utility.startTenantFlow(carbonUser); // utility.startTenantFlow(carbonUser);
var deviceManagementService = utility.getDeviceManagementService(); // var deviceManagementService = utility.getDeviceManagementService();
var operationInstance; // var operationInstance;
if (operation.type == "COMMAND") { // if (operation.type == "COMMAND") {
operationInstance = new CommandOperation(); // operationInstance = new CommandOperation();
} else if (operation.type == "CONFIG") { // } else if (operation.type == "CONFIG") {
operationInstance = new ConfigOperation(); // operationInstance = new ConfigOperation();
} else { // } else {
operationInstance = new SimpleOperation(); // operationInstance = new SimpleOperation();
} // }
operationInstance.setCode(operation.featureName); // operationInstance.setCode(operation.featureName);
var props = new Properties(); // var props = new Properties();
var i, object; // var i, object;
for (i = 0; i < operation.properties.length; i++) { // for (i = 0; i < operation.properties.length; i++) {
object = properties[i]; // object = properties[i];
props.setProperty(object.key, object.value); // props.setProperty(object.key, object.value);
} // }
operationInstance.setProperties(props); // operationInstance.setProperties(props);
var deviceList = new ArrayList(); // var deviceList = new ArrayList();
var j, device, deviceIdentifier; // var j, device, deviceIdentifier;
for (j = 0; j < devices.length; i++) { // for (j = 0; j < devices.length; i++) {
device = devices[j]; // device = devices[j];
deviceIdentifier = new DeviceIdentifier(); // deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(device.id); // deviceIdentifier.setId(device.id);
deviceIdentifier.setType(device.type); // deviceIdentifier.setType(device.type);
deviceList.add(deviceIdentifier); // deviceList.add(deviceIdentifier);
} // }
deviceManagementService.addOperation(operationInstance, deviceList); // deviceManagementService.addOperation(operationInstance, deviceList);
} catch (e) { // } catch (e) {
throw e; // throw e;
} finally { // } finally {
utility.endTenantFlow(); // utility.endTenantFlow();
} // }
}; // };
/* /*
@Deprecated @Deprecated
*/ */
privateMethods.getDevice = function (type, deviceId) { // privateMethods.getDevice = function (type, deviceId) {
var carbonUser = session.get(constants.USER_SESSION_KEY); // var carbonUser = session.get(constants.USER_SESSION_KEY);
var utility = require('/app/modules/utility.js').utility; // var utility = require('/app/modules/utility.js').utility;
if (!carbonUser) { // if (!carbonUser) {
log.error("User object was not found in the session"); // log.error("User object was not found in the session");
throw constants.ERRORS.USER_NOT_FOUND; // throw constants.ERRORS.USER_NOT_FOUND;
} // }
try { // try {
utility.startTenantFlow(carbonUser); // utility.startTenantFlow(carbonUser);
var deviceManagementService = utility.getDeviceManagementService(); // var deviceManagementService = utility.getDeviceManagementService();
var deviceIdentifier = new DeviceIdentifier(); // var deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setType(type); // deviceIdentifier.setType(type);
deviceIdentifier.setId(deviceId); // deviceIdentifier.setId(deviceId);
return deviceManagementService.getDevice(deviceIdentifier); // return deviceManagementService.getDevice(deviceIdentifier);
} catch (e) { // } catch (e) {
throw e; // throw e;
} finally { // } finally {
utility.endTenantFlow(); // utility.endTenantFlow();
} // }
}; // };
/* /*
@Updated @Updated
@ -218,37 +218,37 @@ deviceModule = function () {
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/view?type=" + deviceType + "&id=" + deviceId; var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/view?type=" + deviceType + "&id=" + deviceId;
return serviceInvokers.XMLHttp.get( return serviceInvokers.XMLHttp.get(
url, function (responsePayload) { url, function (responsePayload) {
var device = responsePayload.responseContent; var device = responsePayload.responseContent;
if (device) { if (device) {
var propertiesList = device["properties"]; var propertiesList = device["properties"];
var properties = {}; var properties = {};
if (propertiesList){ if (propertiesList){
for (var i = 0; i < propertiesList.length; i++) { for (var i = 0; i < propertiesList.length; i++) {
properties[propertiesList[i]["name"]] = propertiesList[i]["value"]; properties[propertiesList[i]["name"]] = propertiesList[i]["value"];
}
}
var deviceObject = {};
deviceObject[constants["DEVICE_IDENTIFIER"]] = device["deviceIdentifier"];
deviceObject[constants["DEVICE_NAME"]] = device["name"];
deviceObject[constants["DEVICE_OWNERSHIP"]] = device["enrolmentInfo"]["ownership"];
deviceObject[constants["DEVICE_OWNER"]] = device["enrolmentInfo"]["owner"];
deviceObject[constants["DEVICE_STATUS"]] = device["enrolmentInfo"]["status"];
deviceObject[constants["DEVICE_TYPE"]] = device["type"];
if (device["type"] == constants["PLATFORM_IOS"]) {
properties[constants["DEVICE_MODEL"]] = properties[constants["DEVICE_PRODUCT"]];
delete properties[constants["DEVICE_PRODUCT"]];
properties[constants["DEVICE_VENDOR"]] = constants["VENDOR_APPLE"];
} }
deviceObject[constants["DEVICE_PROPERTIES"]] = properties;
return deviceObject;
} }
}, var deviceObject = {};
function (responsePayload) { deviceObject[constants["DEVICE_IDENTIFIER"]] = device["deviceIdentifier"];
var response = {}; deviceObject[constants["DEVICE_NAME"]] = device["name"];
response["status"] = "error"; deviceObject[constants["DEVICE_OWNERSHIP"]] = device["enrolmentInfo"]["ownership"];
return response; deviceObject[constants["DEVICE_OWNER"]] = device["enrolmentInfo"]["owner"];
deviceObject[constants["DEVICE_STATUS"]] = device["enrolmentInfo"]["status"];
deviceObject[constants["DEVICE_TYPE"]] = device["type"];
if (device["type"] == constants["PLATFORM_IOS"]) {
properties[constants["DEVICE_MODEL"]] = properties[constants["DEVICE_PRODUCT"]];
delete properties[constants["DEVICE_PRODUCT"]];
properties[constants["DEVICE_VENDOR"]] = constants["VENDOR_APPLE"];
}
deviceObject[constants["DEVICE_PROPERTIES"]] = properties;
return deviceObject;
} }
},
function (responsePayload) {
var response = {};
response["status"] = "error";
return response;
}
); );
} catch (e) { } catch (e) {
throw e; throw e;
@ -268,19 +268,19 @@ deviceModule = function () {
url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/count"; url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/count";
} else if (uiPermissions.LIST_OWN_DEVICES) { } else if (uiPermissions.LIST_OWN_DEVICES) {
url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/user/" + carbonUser.username url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/user/" + carbonUser.username
+ "/count"; + "/count";
} else { } else {
log.error("Access denied for user: " + carbonUser.username); log.error("Access denied for user: " + carbonUser.username);
return -1; return -1;
} }
return serviceInvokers.XMLHttp.get( return serviceInvokers.XMLHttp.get(
url, function (responsePayload) { url, function (responsePayload) {
return responsePayload; return responsePayload;
}, },
function (responsePayload) { function (responsePayload) {
log.error(responsePayload); log.error(responsePayload);
return -1; return -1;
} }
); );
} else { } else {
log.error("User object was not found in the session"); log.error("User object was not found in the session");
@ -291,13 +291,13 @@ deviceModule = function () {
publicMethods.getDeviceTypes = function () { publicMethods.getDeviceTypes = function () {
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/types"; var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/types";
return serviceInvokers.XMLHttp.get( return serviceInvokers.XMLHttp.get(
url, function (responsePayload) { url, function (responsePayload) {
return responsePayload; return responsePayload;
}, },
function (responsePayload) { function (responsePayload) {
log.error(responsePayload); log.error(responsePayload);
return -1; return -1;
} }
); );
}; };
@ -328,16 +328,16 @@ deviceModule = function () {
publicMethods.getDevices = function (userName) { publicMethods.getDevices = function (userName) {
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/user/" + userName; var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/user/" + userName;
return serviceInvokers.XMLHttp.get( return serviceInvokers.XMLHttp.get(
url, function (responsePayload) { url, function (responsePayload) {
for (var i = 0; i < responsePayload.length; i++) { for (var i = 0; i < responsePayload.length; i++) {
responsePayload[i].thumb = utility.getDeviceThumb(responsePayload[i].type); responsePayload[i].thumb = utility.getDeviceThumb(responsePayload[i].type);
}
return responsePayload;
},
function (responsePayload) {
log.error(responsePayload);
return -1;
} }
return responsePayload;
},
function (responsePayload) {
log.error(responsePayload);
return -1;
}
); );
}; };
return publicMethods; return publicMethods;

Loading…
Cancel
Save