Changes to the policiesCount, rolesCount, usersCount methods

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

@ -138,6 +138,32 @@ policyModule = function () {
} }
}; };
/*
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 @Updated - used by getAllPolicies
*/ */

@ -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 * Return a User object from the backend by calling the JAX-RS
* @param username * @param username
@ -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 @Updated
*/ */

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