forked from community/device-mgt-core
parent
ab5aa3e31c
commit
ca10ad53bb
@ -0,0 +1,59 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* 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 log = new Log("api/data-tables-invoker-api.jag");
|
||||||
|
|
||||||
|
var uri = request.getRequestURI();
|
||||||
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
|
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"];
|
||||||
|
|
||||||
|
if (uriMatcher.match("/{context}/api/data-tables/invoker")) {
|
||||||
|
var url = request.getParameter("url");
|
||||||
|
var targetURL;
|
||||||
|
var payload = request.getContent();
|
||||||
|
|
||||||
|
function appendQueryParam (url, queryParam , value) {
|
||||||
|
if (url.indexOf("?") > 0) {
|
||||||
|
return url + "&" + queryParam + "=" + value;
|
||||||
|
}
|
||||||
|
return url + "?" + queryParam + "=" + value;
|
||||||
|
}
|
||||||
|
targetURL = devicemgtProps["httpsURL"] + request.getParameter("url");
|
||||||
|
|
||||||
|
var allParams = request.getAllParameters();
|
||||||
|
|
||||||
|
for (var key in allParams) {
|
||||||
|
if (allParams.hasOwnProperty(key)) {
|
||||||
|
if(key == "limit" || key == "offset" || key == "filter"){
|
||||||
|
targetURL = appendQueryParam(targetURL, key, allParams[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceInvokers.XMLHttp.get(
|
||||||
|
targetURL,
|
||||||
|
// response callback
|
||||||
|
function (backendResponse) {
|
||||||
|
response["status"] = backendResponse["status"];
|
||||||
|
response["content"] = backendResponse["responseText"];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* 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 serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"];
|
||||||
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
|
||||||
|
if (uriMatcher.match("/{context}/api/operation/paginate")) {
|
||||||
|
var deviceType = request.getParameter("deviceType");
|
||||||
|
var deviceId = request.getParameter("deviceId");
|
||||||
|
var index = request.getParameter("start");
|
||||||
|
var length = request.getParameter("length");
|
||||||
|
var search = request.getParameter("search[value]");
|
||||||
|
|
||||||
|
var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices/" +
|
||||||
|
deviceType + "/" + deviceId + "/operations?offset=" + index + "&limit=" + length;
|
||||||
|
|
||||||
|
serviceInvokers.XMLHttp.get(
|
||||||
|
restAPIEndpoint,
|
||||||
|
function (restAPIResponse) {
|
||||||
|
if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
|
||||||
|
var responsePayload = parse(restAPIResponse["responseText"]);
|
||||||
|
|
||||||
|
var paginatedResult = {};
|
||||||
|
paginatedResult["recordsTotal"] = responsePayload["count"];
|
||||||
|
paginatedResult["recordsFiltered"] = responsePayload["count"];
|
||||||
|
paginatedResult["data"] = responsePayload["operations"];
|
||||||
|
|
||||||
|
response["status"] = 200;
|
||||||
|
response["content"] = paginatedResult;
|
||||||
|
} else {
|
||||||
|
response["status"] = restAPIResponse["status"];
|
||||||
|
if (restAPIResponse["responseText"]) {
|
||||||
|
response["content"] = parse(restAPIResponse["responseText"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
%>
|
@ -0,0 +1,52 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
|
||||||
|
var uri = request.getRequestURI();
|
||||||
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
|
|
||||||
|
var log = new Log("api/policy-api.jag");
|
||||||
|
|
||||||
|
var constants = require("/modules/constants.js");
|
||||||
|
var policyModule = require("/modules/policy.js").policyModule;
|
||||||
|
|
||||||
|
var result;
|
||||||
|
if (uriMatcher.match("/{context}/api/policies/update")) {
|
||||||
|
payload = request.getContent();
|
||||||
|
policyModule.updatePolicyPriorities(payload);
|
||||||
|
} else if (uriMatcher.match("/{context}/api/policies/{id}/delete")) {
|
||||||
|
elements = uriMatcher.elements();
|
||||||
|
policyId = elements.id;
|
||||||
|
try {
|
||||||
|
result = policyModule.deletePolicy(policyId);
|
||||||
|
} catch (e) {
|
||||||
|
log.error("Exception occurred while trying to delete policy for id:" + policyId, e);
|
||||||
|
// http status code 500 refers to - Internal Server Error.
|
||||||
|
result = 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// returning the result.
|
||||||
|
if (result) {
|
||||||
|
response.content = result;
|
||||||
|
}
|
||||||
|
%>
|
Loading…
Reference in new issue