parent
c4a0ac4bf3
commit
135b6e8881
@ -1,118 +1,211 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, 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,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||||
* KIND, either express or implied. See the License for the
|
* either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function onRequest(context) {
|
function onRequest(context) {
|
||||||
var log = new Log("detail.js");
|
var log = new Log("cdmf.unit.device.view/view.js");
|
||||||
var deviceType = context.uriParams.deviceType;
|
var deviceType = context["uriParams"]["deviceType"];
|
||||||
var deviceId = request.getParameter("id");
|
var deviceId = request.getParameter("id");
|
||||||
|
var deviceViewData = {};
|
||||||
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
|
if (deviceType && deviceId) {
|
||||||
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
||||||
var device = deviceModule.viewDevice(deviceType, deviceId)["content"];
|
var response = deviceModule.viewDevice(deviceType, deviceId);
|
||||||
|
if (response["status"] == "success") {
|
||||||
|
deviceViewData["deviceFound"] = true;
|
||||||
|
deviceViewData["isAuthorized"] = true;
|
||||||
|
|
||||||
|
var filteredDeviceData = response["content"];
|
||||||
|
|
||||||
if (device) {
|
// creating deviceView information model from filtered device data
|
||||||
var viewModel = {};
|
var viewModel = {};
|
||||||
var deviceInfo = (device.properties) ? device.properties.DEVICE_INFO : null;
|
if (filteredDeviceData["type"]) {
|
||||||
if (deviceInfo != undefined && String(deviceInfo.toString()).length > 0) {
|
viewModel["deviceType"] = filteredDeviceData["type"];
|
||||||
deviceInfo = parse(stringify(deviceInfo));
|
viewModel.isNotWindows = true;
|
||||||
if (device.type == "ios") {
|
if (viewModel["deviceType"] == "windows") {
|
||||||
deviceInfo = parse(deviceInfo);
|
viewModel.isNotWindows = false;
|
||||||
viewModel.imei = device.properties.IMEI;
|
}
|
||||||
viewModel.phoneNumber = deviceInfo.PhoneNumber;
|
}
|
||||||
viewModel.udid = deviceInfo.UDID;
|
if (filteredDeviceData["deviceIdentifier"]) {
|
||||||
viewModel.BatteryLevel = Math.round(deviceInfo.BatteryLevel * 100);
|
viewModel["deviceIdentifier"] = filteredDeviceData["deviceIdentifier"];
|
||||||
viewModel.DeviceCapacity = Math.round(deviceInfo.DeviceCapacity * 100) / 100;
|
}
|
||||||
viewModel.AvailableDeviceCapacity = Math.round(deviceInfo.AvailableDeviceCapacity * 100) / 100;
|
if (filteredDeviceData["name"]) {
|
||||||
viewModel.DeviceCapacityUsed = Math.round((viewModel.DeviceCapacity
|
viewModel["name"] = filteredDeviceData["name"];
|
||||||
- viewModel.AvailableDeviceCapacity) * 100) / 100;
|
}
|
||||||
viewModel.DeviceCapacityPercentage = Math.round(viewModel.AvailableDeviceCapacity
|
if (filteredDeviceData["enrolmentInfo"]) {
|
||||||
/ viewModel.DeviceCapacity * 10000) / 100;
|
if (filteredDeviceData["enrolmentInfo"]["status"]) {
|
||||||
viewModel.location = {
|
viewModel["status"] = filteredDeviceData["enrolmentInfo"]["status"];
|
||||||
latitude: device.properties.LATITUDE,
|
viewModel.isActive = false ;
|
||||||
longitude: device.properties.LONGITUDE
|
viewModel.isNotRemoved = true;
|
||||||
};
|
if (filteredDeviceData["enrolmentInfo"]["status"]== "ACTIVE") {
|
||||||
} else if (device.type == "android") {
|
viewModel.isActive = true ;
|
||||||
viewModel.imei = device.properties.IMEI;
|
}
|
||||||
viewModel.model = device.properties.DEVICE_MODEL;
|
if (filteredDeviceData["enrolmentInfo"]["status"]== "REMOVED") {
|
||||||
viewModel.vendor = device.properties.VENDOR;
|
viewModel.isNotRemoved = false ;
|
||||||
viewModel.internal_memory = {};
|
}
|
||||||
viewModel.external_memory = {};
|
}
|
||||||
viewModel.location = {
|
if (filteredDeviceData["enrolmentInfo"]["owner"]) {
|
||||||
latitude: device.properties.LATITUDE,
|
viewModel["owner"] = filteredDeviceData["enrolmentInfo"]["owner"];
|
||||||
longitude: device.properties.LONGITUDE
|
}
|
||||||
};
|
if (filteredDeviceData["enrolmentInfo"]["ownership"]) {
|
||||||
var info = {};
|
viewModel["ownership"] = filteredDeviceData["enrolmentInfo"]["ownership"];
|
||||||
var infoList = parse(deviceInfo);
|
}
|
||||||
if (infoList != null && infoList != undefined) {
|
}
|
||||||
for (var j = 0; j < infoList.length; j++) {
|
if (filteredDeviceData["initialDeviceInfo"]) {
|
||||||
info[infoList[j].name] = infoList[j].value;
|
viewModel["deviceInfoAvailable"] = true;
|
||||||
|
if (filteredDeviceData["initialDeviceInfo"]["IMEI"]) {
|
||||||
|
viewModel["imei"] = filteredDeviceData["initialDeviceInfo"]["IMEI"];
|
||||||
|
}
|
||||||
|
if (!filteredDeviceData["latestDeviceInfo"]) {
|
||||||
|
if (filteredDeviceData["initialDeviceInfo"]["OS_BUILD_DATE"]) {
|
||||||
|
if (filteredDeviceData["initialDeviceInfo"]["OS_BUILD_DATE"] != "0") {
|
||||||
|
viewModel["osBuildDate"] = new Date(filteredDeviceData["initialDeviceInfo"]["OS_BUILD_DATE"] * 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (filteredDeviceData["initialDeviceInfo"]["LATITUDE"] && filteredDeviceData["initialDeviceInfo"]["LONGITUDE"]) {
|
||||||
|
viewModel["location"] = {};
|
||||||
|
viewModel["location"]["latitude"] = filteredDeviceData["initialDeviceInfo"]["LATITUDE"];
|
||||||
|
viewModel["location"]["longitude"] = filteredDeviceData["initialDeviceInfo"]["LONGITUDE"];
|
||||||
|
}
|
||||||
|
if (filteredDeviceData["initialDeviceInfo"]["VENDOR"] && filteredDeviceData["initialDeviceInfo"]["DEVICE_MODEL"]) {
|
||||||
|
viewModel["vendor"] = filteredDeviceData["initialDeviceInfo"]["VENDOR"];
|
||||||
|
viewModel["model"] = filteredDeviceData["initialDeviceInfo"]["DEVICE_MODEL"];
|
||||||
|
}
|
||||||
|
if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]) {
|
||||||
|
if (deviceType == "android") {
|
||||||
|
viewModel["BatteryLevel"] = {};
|
||||||
|
viewModel["BatteryLevel"]["value"] = filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["BATTERY_LEVEL"];
|
||||||
|
|
||||||
|
viewModel["internalMemory"] = {};
|
||||||
|
viewModel["internalMemory"]["total"] = Math.
|
||||||
|
round(filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] * 100) / 100;
|
||||||
|
if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] != 0) {
|
||||||
|
viewModel["internalMemory"]["usage"] = Math.
|
||||||
|
round((filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] -
|
||||||
|
filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_AVAILABLE_MEMORY"])
|
||||||
|
/ filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] * 10000) / 100;
|
||||||
|
} else {
|
||||||
|
viewModel["internalMemory"]["usage"] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModel["externalMemory"] = {};
|
||||||
|
viewModel["externalMemory"]["total"] = Math.
|
||||||
|
round(filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] * 100) / 100;
|
||||||
|
if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] != 0) {
|
||||||
|
viewModel["externalMemory"]["usage"] = Math.
|
||||||
|
round((filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] -
|
||||||
|
filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_AVAILABLE_MEMORY"])
|
||||||
|
/ filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] * 10000) / 100;
|
||||||
|
} else {
|
||||||
|
viewModel["externalMemory"]["usage"] = 0;
|
||||||
|
}
|
||||||
|
} else if (deviceType == "ios") {
|
||||||
|
viewModel["BatteryLevel"] = {};
|
||||||
|
viewModel["BatteryLevel"]["value"] = filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["BatteryLevel"];
|
||||||
|
|
||||||
|
viewModel["internalMemory"] = {};
|
||||||
|
viewModel["internalMemory"]["total"] = Math.
|
||||||
|
round(filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] * 100) / 100;
|
||||||
|
if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] != 0) {
|
||||||
|
viewModel["internalMemory"]["usage"] = Math.
|
||||||
|
round((filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] -
|
||||||
|
filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["AvailableDeviceCapacity"])
|
||||||
|
/ filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] * 10000) / 100;
|
||||||
|
} else {
|
||||||
|
viewModel["internalMemory"]["usage"] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deviceInfo = info;
|
|
||||||
viewModel.BatteryLevel = deviceInfo.BATTERY_LEVEL;
|
|
||||||
viewModel.internal_memory.FreeCapacity = Math.round(deviceInfo.INTERNAL_AVAILABLE_MEMORY * 100)/100;
|
|
||||||
viewModel.internal_memory.DeviceCapacityPercentage = Math.round(deviceInfo.INTERNAL_AVAILABLE_MEMORY
|
|
||||||
/ deviceInfo.INTERNAL_TOTAL_MEMORY * 10000) / 100;
|
|
||||||
viewModel.external_memory.FreeCapacity = Math.round(deviceInfo.EXTERNAL_AVAILABLE_MEMORY * 100) / 100;
|
|
||||||
viewModel.external_memory.DeviceCapacityPercentage = Math.round(deviceInfo.EXTERNAL_AVAILABLE_MEMORY
|
|
||||||
/ deviceInfo.EXTERNAL_TOTAL_MEMORY * 10000) / 100;
|
|
||||||
} else if (device.type == "windows") {
|
|
||||||
viewModel.imei = device.properties.IMEI;
|
|
||||||
viewModel.model = device.properties.DEVICE_MODEL;
|
|
||||||
viewModel.vendor = device.properties.VENDOR;
|
|
||||||
viewModel.internal_memory = {};
|
|
||||||
viewModel.external_memory = {};
|
|
||||||
viewModel.location = {
|
|
||||||
latitude: device.properties.LATITUDE,
|
|
||||||
longitude: device.properties.LONGITUDE
|
|
||||||
};
|
|
||||||
/*var info = {};
|
|
||||||
if (deviceInfo != null && deviceInfo != undefined){
|
|
||||||
var infoList = parse(deviceInfo);
|
|
||||||
if (infoList != null && infoList != undefined) {
|
|
||||||
for (var j = 0; j < infoList.length; j++) {
|
|
||||||
info[infoList[j].name] = infoList[j].value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
deviceInfo = info;
|
|
||||||
viewModel.BatteryLevel = deviceInfo.BATTERY_LEVEL;
|
|
||||||
viewModel.internal_memory.FreeCapacity = Math.round((deviceInfo.INTERNAL_TOTAL_MEMORY -
|
|
||||||
deviceInfo.INTERNAL_AVAILABLE_MEMORY) * 100) / 100;
|
|
||||||
viewModel.internal_memory.DeviceCapacityPercentage = Math.round(deviceInfo.INTERNAL_AVAILABLE_MEMORY
|
|
||||||
/ deviceInfo.INTERNAL_TOTAL_MEMORY * 10000) / 100;
|
|
||||||
viewModel.external_memory.FreeCapacity = Math.round((deviceInfo.EXTERNAL_TOTAL_MEMORY -
|
|
||||||
deviceInfo.EXTERNAL_AVAILABLE_MEMORY) * 100) / 100;
|
|
||||||
viewModel.external_memory.DeviceCapacityPercentage = Math.round(deviceInfo.EXTERNAL_AVAILABLE_MEMORY
|
|
||||||
/ deviceInfo.EXTERNAL_TOTAL_MEMORY * 10000) / 100;
|
|
||||||
}*/
|
|
||||||
}else if (device.type == "TemperatureController") {
|
|
||||||
viewModel.system = device.properties.IMEI;
|
|
||||||
viewModel.machine = device.properties.DEVICE_MODEL;
|
|
||||||
viewModel.vendor = device.properties.VENDOR;
|
|
||||||
viewModel.internal_memory = {};
|
|
||||||
viewModel.external_memory = {};
|
|
||||||
}
|
}
|
||||||
device.viewModel = viewModel;
|
|
||||||
}
|
}
|
||||||
}
|
if (filteredDeviceData["latestDeviceInfo"]) {
|
||||||
|
viewModel["deviceInfoAvailable"] = true;
|
||||||
|
if (filteredDeviceData["latestDeviceInfo"]["osBuildDate"]) {
|
||||||
|
if (filteredDeviceData["latestDeviceInfo"]["osBuildDate"] != "0") {
|
||||||
|
viewModel["osBuildDate"] = new Date(filteredDeviceData["latestDeviceInfo"]["osBuildDate"] * 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (filteredDeviceData["latestDeviceInfo"]["location"]["latitude"] &&
|
||||||
|
filteredDeviceData["latestDeviceInfo"]["location"]["longitude"]) {
|
||||||
|
viewModel["location"] = {};
|
||||||
|
viewModel["location"]["latitude"] = filteredDeviceData["latestDeviceInfo"]["location"]["latitude"];
|
||||||
|
viewModel["location"]["longitude"] = filteredDeviceData["latestDeviceInfo"]["location"]["longitude"];
|
||||||
|
}
|
||||||
|
if (filteredDeviceData["latestDeviceInfo"]["vendor"] && filteredDeviceData["latestDeviceInfo"]["deviceModel"]) {
|
||||||
|
viewModel["vendor"] = filteredDeviceData["latestDeviceInfo"]["vendor"];
|
||||||
|
viewModel["model"] = filteredDeviceData["latestDeviceInfo"]["deviceModel"];
|
||||||
|
}
|
||||||
|
if (filteredDeviceData["latestDeviceInfo"]["updatedTime"]) {
|
||||||
|
viewModel["lastUpdatedTime"] = filteredDeviceData["latestDeviceInfo"]["updatedTime"].
|
||||||
|
substr(0, filteredDeviceData["latestDeviceInfo"]["updatedTime"].indexOf("+"));
|
||||||
|
}
|
||||||
|
viewModel["BatteryLevel"] = {};
|
||||||
|
viewModel["BatteryLevel"]["value"] = filteredDeviceData["latestDeviceInfo"]["batteryLevel"];
|
||||||
|
|
||||||
|
viewModel["cpuUsage"] = {};
|
||||||
|
viewModel["cpuUsage"]["value"] = filteredDeviceData["latestDeviceInfo"]["cpuUsage"];
|
||||||
|
|
||||||
var utility = require("/app/modules/utility.js").utility;
|
viewModel["ramUsage"] = {};
|
||||||
var configs = utility.getDeviceTypeConfig(deviceType);
|
if (filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] != 0) {
|
||||||
return {"device": device, "label" : configs["deviceType"]["label"]};
|
viewModel["ramUsage"]["value"] = Math.
|
||||||
|
round((filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] -
|
||||||
|
filteredDeviceData["latestDeviceInfo"]["availableRAMMemory"])
|
||||||
|
/ filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] * 10000) / 100;
|
||||||
|
} else {
|
||||||
|
viewModel["ramUsage"]["value"] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModel["internalMemory"] = {};
|
||||||
|
viewModel["internalMemory"]["total"] = Math.
|
||||||
|
round(filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] * 100) / 100;
|
||||||
|
if (filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] != 0) {
|
||||||
|
viewModel["internalMemory"]["usage"] = Math.
|
||||||
|
round((filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] -
|
||||||
|
filteredDeviceData["latestDeviceInfo"]["internalAvailableMemory"])
|
||||||
|
/ filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] * 10000) / 100;
|
||||||
|
} else {
|
||||||
|
viewModel["internalMemory"]["usage"] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModel["externalMemory"] = {};
|
||||||
|
viewModel["externalMemory"]["total"] = Math.
|
||||||
|
round(filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] * 100) / 100;
|
||||||
|
if (filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] != 0) {
|
||||||
|
viewModel["externalMemory"]["usage"] = Math.
|
||||||
|
round((filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] -
|
||||||
|
filteredDeviceData["latestDeviceInfo"]["externalAvailableMemory"])
|
||||||
|
/ filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] * 10000) / 100;
|
||||||
|
} else {
|
||||||
|
viewModel["externalMemory"]["usage"] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!filteredDeviceData["initialDeviceInfo"] && !filteredDeviceData["latestDeviceInfo"]) {
|
||||||
|
viewModel["deviceInfoAvailable"] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
deviceViewData["deviceView"] = viewModel;
|
||||||
|
} else if (response["status"] == "unauthorized") {
|
||||||
|
deviceViewData["deviceFound"] = true;
|
||||||
|
deviceViewData["isAuthorized"] = false;
|
||||||
|
} else if (response["status"] == "notFound") {
|
||||||
|
deviceViewData["deviceFound"] = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
deviceViewData["deviceFound"] = false;
|
||||||
}
|
}
|
||||||
|
log.error(deviceViewData);
|
||||||
|
return deviceViewData;
|
||||||
}
|
}
|
Loading…
Reference in new issue