forked from community/device-mgt-plugins
Merge pull request #4 from dulichan/master
UI improvements and backend implementationsrevert-dabc3590
commit
4c1d4a01a5
@ -0,0 +1,39 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you 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 verb = request.getMethod();
|
||||||
|
var uri = request.getRequestURI();
|
||||||
|
var callPath=uri.replace("/cdm/api/","");
|
||||||
|
var log = new Log();
|
||||||
|
var deviceModule = require("/modules/device.js");
|
||||||
|
if (uri != null) {
|
||||||
|
var uriMatcher = new URIMatcher(callPath);
|
||||||
|
log.info(callPath);
|
||||||
|
if (uriMatcher.match("devices/mobile/{type}/{deviceid}/")) {
|
||||||
|
var deviceId = uriMatcher.elements().deviceid;
|
||||||
|
var type = uriMatcher.elements().type;
|
||||||
|
var result = deviceModule.viewDevice(type, deviceId);
|
||||||
|
print(result);
|
||||||
|
}
|
||||||
|
if (uriMatcher.match("devices/mobile/")) {
|
||||||
|
var result = deviceModule.listDevices();
|
||||||
|
print(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%>
|
@ -1,6 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you 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.
|
||||||
|
*/
|
||||||
function identifierFormatter(value, row, index) {
|
function identifierFormatter(value, row, index) {
|
||||||
return [
|
return [
|
||||||
'<a class="like" href="/cdm/devices/'+value+'" title="Like">',
|
'<a class="like" href="/cdm/devices/' + row["deviceType"] + '/' + value + '" title="Like">',
|
||||||
value,
|
value,
|
||||||
'</a>'
|
'</a>'
|
||||||
].join('');}
|
].join('');
|
||||||
|
}
|
@ -1 +1,32 @@
|
|||||||
//Init js to execute
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you 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.
|
||||||
|
*/
|
||||||
|
//Init js to execute
|
||||||
|
var logger = new Log();
|
||||||
|
logger.debug("running debug");
|
||||||
|
var app_TENANT_CONFIGS = 'tenant.configs';
|
||||||
|
var app_carbon = require('carbon');
|
||||||
|
var app_configs = {
|
||||||
|
"HTTPS_URL": "https://localhost:9443"
|
||||||
|
};
|
||||||
|
|
||||||
|
var app_server = new app_carbon.server.Server({
|
||||||
|
tenanted: app_configs.tenanted,
|
||||||
|
url: app_configs.HTTPS_URL + '/admin'
|
||||||
|
});
|
||||||
|
application.put("SERVER", app_server);
|
||||||
|
application.put(app_TENANT_CONFIGS, {});
|
||||||
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you 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 utility = require("/modules/utility.js");
|
||||||
|
var DeviceIdentifier = Packages.org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
var log = new Log();
|
||||||
|
|
||||||
|
var deviceManagementService = utility.getDeviceManagementService();
|
||||||
|
|
||||||
|
var listDevices = function () {
|
||||||
|
var devices = deviceManagementService.getAllDevices("android");
|
||||||
|
var deviceList = [];
|
||||||
|
|
||||||
|
for (i = 0; i < devices.size(); i++) {
|
||||||
|
var device = devices.get(i);
|
||||||
|
deviceList.push({
|
||||||
|
"identifier": device.getDeviceIdentifier(),
|
||||||
|
"name": device.getName(),
|
||||||
|
"ownership": device.getOwnership(),
|
||||||
|
"owner": device.getOwner(),
|
||||||
|
"deviceType": device.getType(),
|
||||||
|
"vendor": device.getProperties().get("vendor"),
|
||||||
|
"model": device.getProperties().get("model"),
|
||||||
|
"osVersion": device.getProperties().get("osVersion")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return deviceList;
|
||||||
|
}
|
||||||
|
var getDevice = function(type, deviceId){
|
||||||
|
var deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setType(type);
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
var device = deviceManagementService.getDevice(deviceIdentifier);
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
var viewDevice = function(type, deviceId){
|
||||||
|
var device = this.getDevice(type, deviceId);
|
||||||
|
|
||||||
|
var entries = device.getProperties().entrySet();
|
||||||
|
var iterator = entries.iterator();
|
||||||
|
var properties = {};
|
||||||
|
while(iterator.hasNext()){
|
||||||
|
var entry = iterator.next();
|
||||||
|
var key = entry.getKey();
|
||||||
|
var value = entry.getValue();
|
||||||
|
properties[key]= value;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
"identifier": device.getDeviceIdentifier(),
|
||||||
|
"name": device.getName(),
|
||||||
|
"ownership": device.getOwnership(),
|
||||||
|
"owner": device.getOwner(),
|
||||||
|
"deviceType": device.getType(),
|
||||||
|
"vendor": device.getProperties().get("vendor"),
|
||||||
|
"model": device.getProperties().get("model"),
|
||||||
|
"osVersion": device.getProperties().get("osVersion"),
|
||||||
|
"properties": properties
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//temporary
|
||||||
|
|
||||||
|
var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext,
|
||||||
|
Class = java.lang.Class;
|
||||||
|
|
||||||
|
osgiService = function (clazz) {
|
||||||
|
return PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(Class.forName(clazz));
|
||||||
|
};
|
||||||
|
var getDeviceManagementService= function(){
|
||||||
|
//server.authenticate("admin", "admin");
|
||||||
|
var realmService = osgiService('org.wso2.carbon.device.mgt.core.service.DeviceManagementService');
|
||||||
|
//var realmService = null;
|
||||||
|
return realmService;
|
||||||
|
}
|
Loading…
Reference in new issue