mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'release-2.0.x' of https://github.com/wso2/carbon-device-mgt into release-2.0.x
This commit is contained in:
commit
ba23e5cfd9
@ -1,10 +1,9 @@
|
||||
{
|
||||
"appContext": "/devicemgt/",
|
||||
"httpsURL" : "https://%server.ip%:8243",
|
||||
"httpURL" : "http://%server.ip%:8280",
|
||||
"wssURL" : "https://localhost:9445",
|
||||
"wsURL" : "%http.ip%",
|
||||
"portalURL": "https://%server.ip%:9445",
|
||||
"httpsURL" : "https://%iot.gateway.host%:%iot.gateway.https.port%",
|
||||
"httpURL" : "http://%iot.gateway.host%:%iot.gateway.http.port",
|
||||
"wssURL" : "https://%iot.analytics.host%:%iot.analytics.https.host%",
|
||||
"portalURL": "https://%iot.analytics.host%:%iot.analytics.https.port%",
|
||||
"dashboardServerURL" : "%https.ip%",
|
||||
"androidEnrollmentDir": "/android-web-agent/enrollment",
|
||||
"windowsEnrollmentDir": "/windows-web-agent/enrollment",
|
||||
@ -19,12 +18,12 @@
|
||||
"clientName": "emm",
|
||||
"owner": "admin@carbon.super",
|
||||
"dynamicClientAppRegistrationServiceURL": "%https.ip%/dynamic-client-web/register",
|
||||
"apiManagerClientAppRegistrationServiceURL": "%https.ip%/api-application-registration/register/tenants",
|
||||
"apiManagerClientAppRegistrationServiceURL": "https://%iot.gateway.host%:%iot.gateway.https.port%/api-application-registration/register/tenants",
|
||||
"grantType": "password refresh_token urn:ietf:params:oauth:grant-type:saml2-bearer urn:ietf:params:oauth:grant-type:jwt-bearer",
|
||||
"tokenScope": "admin",
|
||||
"callbackUrl": "%https.ip%/api/device-mgt/v1.0"
|
||||
},
|
||||
"tokenServiceURL": "%https.ip%/oauth2/token"
|
||||
"tokenServiceURL": "https://%iot.gateway.host%:%iot.gateway.https.port%/token"
|
||||
},
|
||||
"adminUser":"admin@carbon.super",
|
||||
"adminUserTenantId":"-1234",
|
||||
|
||||
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed 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 batchProviders;
|
||||
|
||||
batchProviders = function () {
|
||||
var operations = {};
|
||||
var CONTENT_TYPE_JSON = "application/json";
|
||||
var JS_MAX_VALUE = "9007199254740992";
|
||||
var JS_MIN_VALUE = "-9007199254740992";
|
||||
|
||||
var tableName = "ORG_WSO2_GEO_FUSEDSPATIALEVENT";
|
||||
|
||||
var typeMap = {
|
||||
"bool": "string",
|
||||
"boolean": "string",
|
||||
"string": "string",
|
||||
"int": "number",
|
||||
"integer": "number",
|
||||
"long": "number",
|
||||
"double": "number",
|
||||
"float": "number",
|
||||
"time": "time"
|
||||
};
|
||||
|
||||
var log = new Log();
|
||||
var carbon = require('carbon');
|
||||
var JSUtils = Packages.org.wso2.carbon.analytics.jsservice.Utils;
|
||||
var AnalyticsCachedJSServiceConnector = Packages.org.wso2.carbon.analytics.jsservice.AnalyticsCachedJSServiceConnector;
|
||||
var AnalyticsCache = Packages.org.wso2.carbon.analytics.jsservice.AnalyticsCachedJSServiceConnector.AnalyticsCache;
|
||||
var cacheTimeoutSeconds = 5;
|
||||
|
||||
var cacheSizeBytes = 1024 * 1024 * 1024; // 1GB
|
||||
response.contentType = CONTENT_TYPE_JSON;
|
||||
|
||||
|
||||
var cache = application.get("AnalyticsWebServiceCache");
|
||||
if (cache == null) {
|
||||
cache = new AnalyticsCache(cacheTimeoutSeconds, cacheSizeBytes);
|
||||
application.put("AnalyticsWebServiceCache", cache);
|
||||
}
|
||||
var connector = new AnalyticsCachedJSServiceConnector(cache);
|
||||
|
||||
|
||||
/**
|
||||
* returns an array of column names & types
|
||||
* @param providerConfig
|
||||
*/
|
||||
operations.getSchema = function (loggedInUser) {
|
||||
var schema = [];
|
||||
var result = connector.getTableSchema(loggedInUser, tableName).getMessage();
|
||||
result = JSON.parse(result);
|
||||
|
||||
var columns = result.columns;
|
||||
Object.getOwnPropertyNames(columns).forEach(function (name, idx, array) {
|
||||
var type = "ordinal";
|
||||
if (columns[name]['type']) {
|
||||
type = columns[name]['type'];
|
||||
}
|
||||
schema.push({
|
||||
fieldName: name,
|
||||
fieldType: typeMap[type.toLowerCase()]
|
||||
});
|
||||
});
|
||||
// log.info(schema);
|
||||
return schema;
|
||||
};
|
||||
|
||||
/**
|
||||
* returns the actual data
|
||||
* @param providerConfig
|
||||
* @param limit
|
||||
*/
|
||||
operations.getData = function (loggedInUser, deviceId, deviceType) {
|
||||
var luceneQuery = "";
|
||||
var limit = 100;
|
||||
var result;
|
||||
//if there's a filter present, we should perform a Lucene search instead of reading the table
|
||||
if (luceneQuery) {
|
||||
luceneQuery = 'id:"' + deviceId + '" AND type:"' + deviceType + '"';
|
||||
var filter = {
|
||||
"query": luceneQuery,
|
||||
"start": 0,
|
||||
"count": limit
|
||||
};
|
||||
result = connector.search(loggedInUser, tableName, stringify(filter)).getMessage();
|
||||
} else {
|
||||
var from = JS_MIN_VALUE;
|
||||
var to = JS_MAX_VALUE;
|
||||
result = connector.getRecordsByRange(loggedInUser, tableName, from, to, 0, limit, null).getMessage();
|
||||
|
||||
}
|
||||
result = JSON.parse(result);
|
||||
var data = [];
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
var values = result[i].values;
|
||||
data.push(values);
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
|
||||
|
||||
return operations;
|
||||
}();
|
||||
@ -24,6 +24,7 @@ deviceModule = function () {
|
||||
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 batchProvider = require("/app/modules/batch-provider-api.js")["batchProviders"];
|
||||
|
||||
var publicMethods = {};
|
||||
var privateMethods = {};
|
||||
@ -67,6 +68,21 @@ deviceModule = function () {
|
||||
log.error("User object was not found in the session");
|
||||
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
||||
}
|
||||
var userName = carbonUser.username + "@" + carbonUser.domain;
|
||||
var locationDataSet = batchProvider.getData(userName, deviceId, deviceType);
|
||||
|
||||
var locationData = [];
|
||||
var locationTimeData = [];
|
||||
for (var i = 0 ; i < locationDataSet.length; i++) {
|
||||
var gpsReading = {};
|
||||
var gpsReadingTimes = {};
|
||||
gpsReading.lat = locationDataSet[i].latitude;
|
||||
gpsReading.lng = locationDataSet[i].longitude;
|
||||
gpsReadingTimes.time = locationDataSet[i].timeStamp;
|
||||
locationData.push(gpsReading);
|
||||
locationTimeData.push(gpsReadingTimes);
|
||||
}
|
||||
|
||||
var utility = require('/app/modules/utility.js')["utility"];
|
||||
try {
|
||||
utility.startTenantFlow(carbonUser);
|
||||
@ -144,6 +160,10 @@ deviceModule = function () {
|
||||
if (device["deviceInfo"]) {
|
||||
filteredDeviceData["latestDeviceInfo"] = device["deviceInfo"];
|
||||
}
|
||||
var locationHistory = {};
|
||||
locationHistory.locations = locationData;
|
||||
locationHistory.times = locationTimeData;
|
||||
filteredDeviceData["locationHistory"] = locationHistory;
|
||||
response["content"] = filteredDeviceData;
|
||||
response["status"] = "success";
|
||||
return response;
|
||||
|
||||
@ -22,6 +22,7 @@ var conf = function () {
|
||||
conf = require("/app/conf/config.json");
|
||||
var pinch = require("/app/modules/conf-reader/pinch.min.js")["pinch"];
|
||||
var server = require("carbon")["server"];
|
||||
var process = require("process");
|
||||
pinch(conf, /^/,
|
||||
function (path, key, value) {
|
||||
if ((typeof value === "string") && value.indexOf("%https.ip%") > -1) {
|
||||
@ -36,8 +37,23 @@ var conf = function () {
|
||||
} else if ((typeof value === "string") && value.indexOf("%server.ip%") > -1) {
|
||||
var getProperty = require("process").getProperty;
|
||||
return value.replace("%server.ip%", getProperty("carbon.local.ip"));
|
||||
} else {
|
||||
var paramPattern = new RegExp("%(.*?)%", "g");
|
||||
var out = value;
|
||||
while ((matches = paramPattern.exec(value)) !== null) {
|
||||
// This is necessary to avoid infinite loops with zero-width matches
|
||||
if (matches.index === paramPattern.lastIndex) {
|
||||
paramPattern.lastIndex++;
|
||||
}
|
||||
if (matches.length == 2) {
|
||||
var property = process.getProperty(matches[1]);
|
||||
if (property) {
|
||||
out = out.replace(new RegExp("%" + matches[1] + "%", "g"), property);
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
);
|
||||
application.put("CONF", conf);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user