|
|
|
@ -69,35 +69,22 @@ deviceModule = function () {
|
|
|
|
|
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
|
|
|
|
}
|
|
|
|
|
var userName = carbonUser.username + "@" + carbonUser.domain;
|
|
|
|
|
|
|
|
|
|
var locationDataSet = [];
|
|
|
|
|
switch (deviceType) {
|
|
|
|
|
case 'android':
|
|
|
|
|
locationDataSet = batchProvider.getData(userName, deviceId, deviceType);
|
|
|
|
|
break;
|
|
|
|
|
case 'android_sense':
|
|
|
|
|
locationDataSet = batchProvider.getData(userName, deviceId, deviceType);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
var locationData = [];
|
|
|
|
|
var locationTimeData = [];
|
|
|
|
|
if (locationDataSet != null) {
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < locationDataSet.length; i++) {
|
|
|
|
|
var gpsReading = {};
|
|
|
|
|
var gpsReadingTimes = {};
|
|
|
|
|
gpsReading.lat = locationDataSet[i].latitude;
|
|
|
|
|
gpsReading.lng = locationDataSet[i].longitude;
|
|
|
|
|
if (deviceType == "android") {
|
|
|
|
|
gpsReadingTimes.time = locationDataSet[i].timeStamp;
|
|
|
|
|
} else {
|
|
|
|
|
gpsReadingTimes.time = locationDataSet[i].meta_timestamp;
|
|
|
|
|
}
|
|
|
|
|
locationData.push(gpsReading);
|
|
|
|
|
locationTimeData.push(gpsReadingTimes);
|
|
|
|
|
var locationHistory = [];
|
|
|
|
|
try {
|
|
|
|
|
var fromDate = new Date();
|
|
|
|
|
fromDate.setHours(fromDate.getHours() - 2);
|
|
|
|
|
var toDate = new Date();
|
|
|
|
|
var serviceUrl = devicemgtProps["httpsURL"] + '/api/device-mgt/v1.0/geo-services/stats/' + deviceType + '/' + deviceId;
|
|
|
|
|
serviceInvokers.XMLHttp.get(serviceUrl,
|
|
|
|
|
function (backendResponse) {
|
|
|
|
|
if (backendResponse.status === 200 && backendResponse.responseText) {
|
|
|
|
|
locationHistory = JSON.parse(backendResponse.responseText);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log.error(e.message, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var locationInfo = {};
|
|
|
|
|
try {
|
|
|
|
|
var url = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId + "/location";
|
|
|
|
@ -110,14 +97,12 @@ deviceModule = function () {
|
|
|
|
|
locationInfo.latitude = device.latitude;
|
|
|
|
|
locationInfo.longitude = device.longitude;
|
|
|
|
|
locationInfo.updatedOn = device.updatedTime;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log.error(e.message, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var utility = require('/app/modules/utility.js')["utility"];
|
|
|
|
|
try {
|
|
|
|
|
utility.startTenantFlow(carbonUser);
|
|
|
|
@ -192,16 +177,35 @@ deviceModule = function () {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (device["deviceInfo"]) {
|
|
|
|
|
filteredDeviceData["latestDeviceInfo"] = device["deviceInfo"];
|
|
|
|
|
} else {
|
|
|
|
|
filteredDeviceData["latestDeviceInfo"] = {};
|
|
|
|
|
filteredDeviceData["latestDeviceInfo"]["location"] = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//location related verification and modifications
|
|
|
|
|
// adding the location histry for the movement path.
|
|
|
|
|
var locationHistory = {};
|
|
|
|
|
locationHistory.locations = locationData;
|
|
|
|
|
locationHistory.times = locationTimeData;
|
|
|
|
|
filteredDeviceData["locationHistory"] = locationHistory;
|
|
|
|
|
|
|
|
|
|
//checking for the latest location information based on historical data.
|
|
|
|
|
if (locationHistory) {
|
|
|
|
|
var infoDate;
|
|
|
|
|
var locationDate;
|
|
|
|
|
var historicalLatestLoc = locationHistory[locationHistory.length - 1];
|
|
|
|
|
if (historicalLatestLoc && filteredDeviceData.latestDeviceInfo && filteredDeviceData.latestDeviceInfo.location) {
|
|
|
|
|
infoDate = new Date(filteredDeviceData.latestDeviceInfo.location.updatedTime);
|
|
|
|
|
locationDate = new Date(historicalLatestLoc.values.timeStamp);
|
|
|
|
|
}
|
|
|
|
|
if (infoDate < locationDate || filteredDeviceData.latestDeviceInfo.length === 0) {
|
|
|
|
|
filteredDeviceData.latestDeviceInfo.location = {};
|
|
|
|
|
filteredDeviceData.latestDeviceInfo.location.longitude = historicalLatestLoc.values.longitude;
|
|
|
|
|
filteredDeviceData.latestDeviceInfo.location.latitude = historicalLatestLoc.values.latitude;
|
|
|
|
|
filteredDeviceData.latestDeviceInfo.location.updatedTime = historicalLatestLoc.values.timeStamp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//checking for the latest location information.
|
|
|
|
|
if (filteredDeviceData.latestDeviceInfo.location && locationInfo) {
|
|
|
|
|
var infoDate = new Date(filteredDeviceData.latestDeviceInfo.location.updatedTime);
|
|
|
|
@ -209,11 +213,10 @@ deviceModule = function () {
|
|
|
|
|
if (infoDate < locationDate) {
|
|
|
|
|
filteredDeviceData.latestDeviceInfo.location.longitude = locationInfo.longitude;
|
|
|
|
|
filteredDeviceData.latestDeviceInfo.location.latitude = locationInfo.latitude;
|
|
|
|
|
}
|
|
|
|
|
filteredDeviceData.latestDeviceInfo.location.updatedTime = locationInfo.updatedOn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response["content"] = filteredDeviceData;
|
|
|
|
|
response["status"] = "success";
|
|
|
|
|
return response;
|
|
|
|
@ -277,28 +280,6 @@ deviceModule = function () {
|
|
|
|
|
return response;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
@Updated
|
|
|
|
|
*/
|
|
|
|
|
// publicMethods.getLicense = function (deviceType) {
|
|
|
|
|
// var url;
|
|
|
|
|
// var license;
|
|
|
|
|
// if (deviceType == "windows") {
|
|
|
|
|
// url = mdmProps["httpURL"] + "/mdm-windows-agent/services/device/license";
|
|
|
|
|
// } else if (deviceType == "ios") {
|
|
|
|
|
// url = mdmProps["httpsURL"] + "/ios-enrollment/license/";
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (url != null && url != undefined) {
|
|
|
|
|
// serviceInvokers.XMLHttp.get(url, function (responsePayload) {
|
|
|
|
|
// license = responsePayload.text;
|
|
|
|
|
// }, function (responsePayload) {
|
|
|
|
|
// return null;
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// return license;
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
publicMethods.getDevices = function (userName) {
|
|
|
|
|
var url = devicemgtProps["httpsURL"] +
|
|
|
|
|
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices";
|
|
|
|
|