Changes to the policiesCount, rolesCount, usersCount methods

revert-70aa11f8
Rasika Perera 8 years ago
parent 0fab418187
commit 1d7546916c

@ -79,14 +79,14 @@ policyModule = function () {
policyObjectToView["status"] = "Active/Updated";
isUpdated = true;
} else if (policyObjectFromRestEndpoint["active"] == true &&
policyObjectFromRestEndpoint["updated"] == false) {
policyObjectFromRestEndpoint["updated"] == false) {
policyObjectToView["status"] = "Active";
} else if (policyObjectFromRestEndpoint["active"] == false &&
policyObjectFromRestEndpoint["updated"] == true) {
policyObjectFromRestEndpoint["updated"] == true) {
policyObjectToView["status"] = "Inactive/Updated";
isUpdated = true;
} else if (policyObjectFromRestEndpoint["active"] == false &&
policyObjectFromRestEndpoint["updated"] == false) {
policyObjectFromRestEndpoint["updated"] == false) {
policyObjectToView["status"] = "Inactive";
}
// push view-objects to list
@ -131,13 +131,39 @@ policyModule = function () {
}
try {
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/policies?offset=0&limit=100";
"/policies?offset=0&limit=100";
return serviceInvokers.XMLHttp.get(url, privateMethods.handleGetAllPoliciesResponse);
} catch (e) {
throw e;
}
};
/*
Get policies count from backend services.
*/
publicMethods.getPoliciesCount = function () {
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
if (!carbonUser) {
log.error("User object was not found in the session");
throw constants["ERRORS"]["USER_NOT_FOUND"];
}
try {
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/policies?offset=0&limit=1";
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
return parse(responsePayload["responseText"])["count"];
},
function (responsePayload) {
log.error(responsePayload["responseText"]);
return -1;
}
);
} catch (e) {
throw e;
}
};
/*
@Updated - used by getAllPolicies
*/

@ -59,17 +59,17 @@ var userModule = function () {
privateMethods.callBackend = function (url, method) {
if (constants["HTTP_GET"] == method) {
return serviceInvokers.XMLHttp.get(url,
function (backendResponse) {
var response = {};
response.content = backendResponse.responseText;
if (backendResponse.status == 200) {
response.status = "success";
} else if (backendResponse.status == 400 || backendResponse.status == 401 ||
backendResponse.status == 404 || backendResponse.status == 500) {
response.status = "error";
}
return response;
}
function (backendResponse) {
var response = {};
response.content = backendResponse.responseText;
if (backendResponse.status == 200) {
response.status = "success";
} else if (backendResponse.status == 400 || backendResponse.status == 401 ||
backendResponse.status == 404 || backendResponse.status == 500) {
response.status = "error";
}
return response;
}
);
} else {
log.error("Runtime error : This method only support HTTP GET requests.");
@ -141,6 +141,35 @@ var userModule = function () {
}
};
/*
Get users count from backend services.
*/
publicMethods.getUsersCount = function () {
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
var utility = require("/app/modules/utility.js")["utility"];
if (!carbonUser) {
log.error("User object was not found in the session");
throw constants["ERRORS"]["USER_NOT_FOUND"];
}
try {
utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users?offset=0&limit=1";
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
return parse(responsePayload["responseText"])["count"];
},
function (responsePayload) {
log.error(responsePayload["responseText"]);
return -1;
}
);
} catch (e) {
throw e;
} finally {
utility.endTenantFlow();
}
};
/**
* Return a User object from the backend by calling the JAX-RS
* @param username
@ -151,7 +180,7 @@ var userModule = function () {
try {
utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" +
encodeURIComponent(username);
encodeURIComponent(username);
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
response["content"] = parse(response.content);
response["userDomain"] = carbonUser.domain;
@ -173,7 +202,7 @@ var userModule = function () {
try {
utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" +
encodeURIComponent(username) + "/roles";
encodeURIComponent(username) + "/roles";
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") {
response.content = parse(response.content).roles;
@ -223,7 +252,7 @@ var userModule = function () {
try {
utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/roles?offset=0&limit=100";
"/roles?offset=0&limit=100";
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") {
response.content = parse(response.content).roles;
@ -236,6 +265,36 @@ var userModule = function () {
}
};
/**
* Get User Roles count from user store (Internal roles not included).
*/
publicMethods.getRolesCount = function () {
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
var utility = require("/app/modules/utility.js")["utility"];
if (!carbonUser) {
log.error("User object was not found in the session");
throw constants["ERRORS"]["USER_NOT_FOUND"];
}
try {
utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/roles?offset=0&limit=1";
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
return parse(responsePayload["responseText"])["count"];
},
function (responsePayload) {
log.error(responsePayload["responseText"]);
return -1;
}
);
} catch (e) {
throw e;
} finally {
utility.endTenantFlow();
}
};
/*
@Updated
*/
@ -253,7 +312,7 @@ var userModule = function () {
try {
utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/roles?user-store=" + userStore + "&limit=100";
"/roles?user-store=" + userStore + "&limit=100";
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") {
response.content = parse(response.content).roles;
@ -270,7 +329,7 @@ var userModule = function () {
* Get Platforms.
* @deprecated moved this device module under getDeviceTypes.
*/
//TODO Move this piece of logic out of user.js to somewhere else appropriate.
//TODO Move this piece of logic out of user.js to somewhere else appropriate.
publicMethods.getPlatforms = function () {
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
var utility = require("/app/modules/utility.js")["utility"];
@ -306,7 +365,7 @@ var userModule = function () {
try {
utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/roles/" + encodeURIComponent(roleName);
"/roles/" + encodeURIComponent(roleName);
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") {
response.content = parse(response.content);

@ -39,9 +39,9 @@ function onRequest() {
//TODO: Enable Group Management Service API on CDMF
//page.group_count = groupModule.getGroupCount();
page.group_count = -1;
page.user_count = userModule.getUsers()["content"].length;
page.policy_count = policyModule.getAllPolicies()["content"].length;
page.role_count = userModule.getRoles()["content"].length;
page.user_count = userModule.getUsersCount();
page.policy_count = policyModule.getPoliciesCount();
page.role_count = userModule.getRolesCount();
return page;
}
Loading…
Cancel
Save