forked from community/device-mgt-core
parent
8f0840e3df
commit
e7c5ef78d0
@ -1,62 +0,0 @@
|
|||||||
<%
|
|
||||||
/*
|
|
||||||
* 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 uri = request.getRequestURI();
|
|
||||||
var uriMatcher = new URIMatcher(String(uri));
|
|
||||||
|
|
||||||
var log = new Log("/api/operation-api.jag");
|
|
||||||
|
|
||||||
var utility = require('/app/modules/utility.js').utility;
|
|
||||||
var constants = require('/app/modules/constants.js');
|
|
||||||
var operationModule = require("/app/modules/operation.js").operationModule;
|
|
||||||
|
|
||||||
response.contentType = 'application/json';
|
|
||||||
|
|
||||||
var user = session.get(constants.USER_SESSION_KEY);
|
|
||||||
|
|
||||||
var result;
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
response.sendRedirect("/devicemgt/login?#login-required");
|
|
||||||
exit();
|
|
||||||
} else {
|
|
||||||
if (uriMatcher.match("/{context}/api/operations/{deviceType}/stats")) {
|
|
||||||
var deviceType = uriMatcher.elements().deviceType;
|
|
||||||
var deviceId = request.getParameter("deviceId");
|
|
||||||
var monitorOperations = operationModule.getMonitorOperations(deviceType);
|
|
||||||
var stats = [];
|
|
||||||
result = {};
|
|
||||||
for (var op in monitorOperations) {
|
|
||||||
result = operationModule.handleGETOperation(deviceType, monitorOperations[op].operation, monitorOperations[op].name, deviceId);
|
|
||||||
stats.push(result.data);
|
|
||||||
}
|
|
||||||
result.data = stats;
|
|
||||||
} else if (uriMatcher.match("/{context}/api/operations/{deviceType}/{operation}")) {
|
|
||||||
var deviceType = uriMatcher.elements().deviceType;
|
|
||||||
var operation = uriMatcher.elements().operation;
|
|
||||||
var deviceId = request.getParameter("deviceId");
|
|
||||||
var params = request.getAllParameters();
|
|
||||||
result = operationModule.handlePOSTOperation(deviceType, operation, deviceId, params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// returning the result.
|
|
||||||
if (result) {
|
|
||||||
print(result);
|
|
||||||
}
|
|
||||||
%>
|
|
@ -1,55 +0,0 @@
|
|||||||
<%
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2016, 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 uri = request.getRequestURI();
|
|
||||||
var uriMatcher = new URIMatcher(String(uri));
|
|
||||||
|
|
||||||
var log = new Log("api/policy-api.jag");
|
|
||||||
|
|
||||||
var constants = require("/app/modules/constants.js");
|
|
||||||
var policyModule = require("/app/modules/policy.js").policyModule;
|
|
||||||
|
|
||||||
var deviceType, deviceId;
|
|
||||||
|
|
||||||
var user = session.get(constants.USER_SESSION_KEY);
|
|
||||||
|
|
||||||
var responseProcessor = require('utils').response;
|
|
||||||
response.contentType = 'application/json';
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
response = responseProcessor.buildErrorResponse(response, 401, "Unauthorized");
|
|
||||||
} else {
|
|
||||||
if (uriMatcher.match("/{context}/api/policies/add")) {
|
|
||||||
var content = request.getContent();
|
|
||||||
var policyName = content.policyName;
|
|
||||||
var policyDefinition = content.profile.policyDefinition;
|
|
||||||
var policyDescription = content.profile.policyDescription;
|
|
||||||
deviceType = content.profile.deviceType.name;
|
|
||||||
deviceId = content.deviceId;
|
|
||||||
try {
|
|
||||||
response.content = policyModule.addPolicy(policyName, deviceType, policyDefinition,
|
|
||||||
policyDescription, deviceId);
|
|
||||||
} catch (e) {
|
|
||||||
log.error("Exception occurred while trying to add new policy under name:" + policyName, e);
|
|
||||||
// http status code 500 refers to - Internal Server Error.
|
|
||||||
responseProcessor.buildErrorResponse(response, 500, "Internal server error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
%>
|
|
Loading…
Reference in new issue