revert-70aa11f8
harshanl 8 years ago
commit 5a6120d6fa

@ -20,26 +20,14 @@ var deviceModule;
deviceModule = function () {
var log = new Log("/app/modules/business-controllers/device.js");
var utility = require('/app/modules/utility.js').utility;
var utility = require('/app/modules/utility.js')["utility"];
var constants = require('/app/modules/constants.js');
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
// var ArrayList = Packages.java.util.ArrayList;
// var Properties = Packages.java.util.Properties;
// var DeviceIdentifier = Packages.org.wso2.carbon.device.mgt.common.DeviceIdentifier;
// var DeviceManagerUtil = Packages.org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
// 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 CommandOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
var deviceManagementService = utility.getDeviceManagementService();
var publicMethods = {};
var privateMethods = {};
// var deviceCloudService = devicemgtProps["httpsURL"] + "/common/device_manager";
/**
* Only GET method is implemented for now since there are no other type of methods used this method.
* @param url - URL to call the backend without the host
@ -67,170 +55,9 @@ deviceModule = function () {
};
privateMethods.validateAndReturn = function (value) {
return (value == undefined || value == null) ? constants.UNSPECIFIED : value;
return (value == undefined || value == null) ? constants["UNSPECIFIED"] : value;
};
/*
@Deprecated
*/
// publicMethods.listDevices = function () {
// var carbonUser = session.get(constants.USER_SESSION_KEY);
// var utility = require('/app/modules/utility.js').utility;
// if (!carbonUser) {
// log.error("User object was not found in the session");
// throw constants.ERRORS.USER_NOT_FOUND;
// }
// try {
// utility.startTenantFlow(carbonUser);
// var deviceManagementService = utility.getDeviceManagementService();
// var devices = deviceManagementService.getAllDevices();
// var deviceList = [];
// var i, device, propertiesList, deviceObject;
// for (i = 0; i < devices.size(); i++) {
// device = devices.get(i);
// propertiesList = DeviceManagerUtil.convertDevicePropertiesToMap(device.getProperties());
//
// deviceObject = {};
// deviceObject[constants.DEVICE_IDENTIFIER] =
// privateMethods.validateAndReturn(device.getDeviceIdentifier());
// deviceObject[constants.DEVICE_NAME] =
// privateMethods.validateAndReturn(device.getName());
// deviceObject[constants.DEVICE_OWNERSHIP] =
// privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwnership());
// deviceObject[constants.DEVICE_OWNER] =
// privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwner());
// deviceObject[constants.DEVICE_TYPE] =
// privateMethods.validateAndReturn(device.getType());
// deviceObject[constants.DEVICE_PROPERTIES] = {};
// if (device.getType() == constants.PLATFORM_IOS) {
// deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
// privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_PRODUCT));
// deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] = constants.VENDOR_APPLE;
// } else {
// deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
// privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_MODEL));
// deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] =
// privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_VENDOR));
// }
// deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_OS_VERSION] =
// privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_OS_VERSION));
//
// deviceList.push(deviceObject);
// }
// return deviceList;
// } catch (e) {
// throw e;
// } finally {
// utility.endTenantFlow();
// }
// };
/*
@Deprecated
*/
/*
Get the supported features by the device type
*/
// publicMethods.getFeatures = function (deviceType) {
// var carbonUser = session.get(constants.USER_SESSION_KEY);
// var utility = require('/app/modules/utility.js').utility;
// if (!carbonUser) {
// log.error("User object was not found in the session");
// throw constants.ERRORS.USER_NOT_FOUND;
// }
// try {
// utility.startTenantFlow(carbonUser);
// var deviceManagementService = utility.getDeviceManagementService();
// var features = deviceManagementService.getFeatureManager(deviceType).getFeatures();
// var featuresConverted = {};
// if (features) {
// var i, feature, featureObject;
// for (i = 0; i < features.size(); i++) {
// feature = features.get(i);
// featureObject = {};
// featureObject[constants.FEATURE_NAME] = feature.getName();
// featureObject[constants.FEATURE_DESCRIPTION] = feature.getDescription();
// featuresConverted[feature.getName()] = featureObject;
// }
// }
// return featuresConverted;
// } catch (e) {
// throw e;
// } finally {
// utility.endTenantFlow();
// }
// };
/*
@Deprecated
*/
// publicMethods.performOperation = function (devices, operation) {
// var carbonUser = session.get(constants.USER_SESSION_KEY);
// var utility = require('/app/modules/utility.js').utility;
// if (!carbonUser) {
// log.error("User object was not found in the session");
// throw constants.ERRORS.USER_NOT_FOUND;
// }
// try {
// utility.startTenantFlow(carbonUser);
// var deviceManagementService = utility.getDeviceManagementService();
// var operationInstance;
// if (operation.type == "COMMAND") {
// operationInstance = new CommandOperation();
// } else if (operation.type == "CONFIG") {
// operationInstance = new ConfigOperation();
// } else {
// operationInstance = new SimpleOperation();
// }
// operationInstance.setCode(operation.featureName);
// var props = new Properties();
// var i, object;
// for (i = 0; i < operation.properties.length; i++) {
// object = properties[i];
// props.setProperty(object.key, object.value);
// }
// operationInstance.setProperties(props);
// var deviceList = new ArrayList();
// var j, device, deviceIdentifier;
// for (j = 0; j < devices.length; i++) {
// device = devices[j];
// deviceIdentifier = new DeviceIdentifier();
// deviceIdentifier.setId(device.id);
// deviceIdentifier.setType(device.type);
// deviceList.add(deviceIdentifier);
// }
// deviceManagementService.addOperation(operationInstance, deviceList);
// } catch (e) {
// throw e;
// } finally {
// utility.endTenantFlow();
// }
// };
/*
@Deprecated
*/
// privateMethods.getDevice = function (type, deviceId) {
// var carbonUser = session.get(constants.USER_SESSION_KEY);
// var utility = require('/app/modules/utility.js').utility;
// if (!carbonUser) {
// log.error("User object was not found in the session");
// throw constants.ERRORS.USER_NOT_FOUND;
// }
// try {
// utility.startTenantFlow(carbonUser);
// var deviceManagementService = utility.getDeviceManagementService();
// var deviceIdentifier = new DeviceIdentifier();
// deviceIdentifier.setType(type);
// deviceIdentifier.setId(deviceId);
// return deviceManagementService.getDevice(deviceIdentifier);
// } catch (e) {
// throw e;
// } finally {
// utility.endTenantFlow();
// }
// };
/*
@Updated
*/
@ -243,7 +70,6 @@ deviceModule = function () {
var utility = require('/app/modules/utility.js')["utility"];
try {
utility.startTenantFlow(carbonUser);
//var url = mdmProps["httpsURL"] + "/mdm-admin/devices/view?type=" + deviceType + "&id=" + deviceId;
var url = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId;
return serviceInvokers.XMLHttp.get(
url,
@ -276,6 +102,9 @@ deviceModule = function () {
} else if (backendResponse.status == 401) {
response["status"] = "unauthorized";
return response;
} else if (backendResponse.status == 404) {
response["status"] = "notFound";
return response;
} else {
response["status"] = "error";
return response;
@ -298,10 +127,10 @@ deviceModule = function () {
var url;
if (uiPermissions.LIST_DEVICES) {
url = devicemgtProps["httpsURL"] +
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices?offset=0&limit=1";
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices?offset=0&limit=1";
} else if (uiPermissions.LIST_OWN_DEVICES) {
url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/devices?offset=0&limit=1&user=" + carbonUser.username;
"/devices?offset=0&limit=1&user=" + carbonUser.username;
} else {
log.error("Access denied for user: " + carbonUser.username);
return -1;
@ -330,8 +159,6 @@ deviceModule = function () {
return response;
};
//Old methods
//TODO: make sure these methods are updated
/*
@Updated
*/

@ -435,3 +435,68 @@ CREATE TABLE DM_DEVICE_DETAIL (
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
GO
-- DASHBOARD RELATED VIEWS --
CREATE VIEW POLICY_COMPLIANCE_INFO AS
SELECT TOP 100 PERCENT
DEVICE_INFO.DEVICE_ID,
DEVICE_INFO.DEVICE_IDENTIFICATION,
DEVICE_INFO.PLATFORM,
DEVICE_INFO.OWNERSHIP,
DEVICE_INFO.CONNECTIVITY_STATUS,
ISNULL(DEVICE_WITH_POLICY_INFO.POLICY_ID, -1) AS POLICY_ID,
ISNULL(DEVICE_WITH_POLICY_INFO.IS_COMPLIANT, -1) AS
IS_COMPLIANT,
DEVICE_INFO.TENANT_ID
FROM
(SELECT
DM_DEVICE.ID AS DEVICE_ID,
DM_DEVICE.DEVICE_IDENTIFICATION,
DM_DEVICE_TYPE.NAME AS PLATFORM,
DM_ENROLMENT.OWNERSHIP,
DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS,
DM_DEVICE.TENANT_ID
FROM DM_DEVICE, DM_DEVICE_TYPE, DM_ENROLMENT
WHERE DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID) DEVICE_INFO
LEFT JOIN
(SELECT
DEVICE_ID,
POLICY_ID,
STATUS AS IS_COMPLIANT
FROM
DM_POLICY_COMPLIANCE_STATUS) DEVICE_WITH_POLICY_INFO
ON DEVICE_INFO.DEVICE_ID = DEVICE_WITH_POLICY_INFO.DEVICE_ID
ORDER BY DEVICE_INFO.DEVICE_ID;
GO
CREATE VIEW FEATURE_NON_COMPLIANCE_INFO AS
SELECT TOP 100 PERCENT
DM_DEVICE.ID AS DEVICE_ID,
DM_DEVICE.DEVICE_IDENTIFICATION,
DM_DEVICE_DETAIL.DEVICE_MODEL,
DM_DEVICE_DETAIL.VENDOR,
DM_DEVICE_DETAIL.OS_VERSION,
DM_ENROLMENT.OWNERSHIP,
DM_ENROLMENT.OWNER,
DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS,
DM_POLICY_COMPLIANCE_STATUS.POLICY_ID,
DM_DEVICE_TYPE.NAME
AS PLATFORM,
DM_POLICY_COMPLIANCE_FEATURES.FEATURE_CODE,
DM_POLICY_COMPLIANCE_FEATURES.STATUS AS IS_COMPLAINT,
DM_DEVICE.TENANT_ID
FROM
DM_POLICY_COMPLIANCE_FEATURES, DM_POLICY_COMPLIANCE_STATUS, DM_ENROLMENT, DM_DEVICE, DM_DEVICE_TYPE, DM_DEVICE_DETAIL
WHERE
DM_POLICY_COMPLIANCE_FEATURES.COMPLIANCE_STATUS_ID = DM_POLICY_COMPLIANCE_STATUS.ID AND
DM_POLICY_COMPLIANCE_STATUS.ENROLMENT_ID =
DM_ENROLMENT.ID AND
DM_POLICY_COMPLIANCE_STATUS.DEVICE_ID = DM_DEVICE.ID AND
DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND
DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID
ORDER BY TENANT_ID, DEVICE_ID;
GO
-- END OF DASHBOARD RELATED VIEWS --

Loading…
Cancel
Save