Search in sources :

Example 1 with UsersInner

use of org.wso2.ei.dashboard.core.rest.model.UsersInner in project product-mi-tooling by wso2.

the class UsersDelegate method getUsers.

private Users getUsers(String groupId) throws ManagementApiException {
    Users users = new Users();
    NodeList nodeList = databaseManager.fetchNodes(groupId);
    // assumption - In a group, users of all nodes in the group should be identical
    String nodeId = nodeList.get(0).getNodeId();
    String mgtApiUrl = ManagementApiUtils.getMgtApiUrl(groupId, nodeId);
    String accessToken = databaseManager.getAccessToken(groupId, nodeId);
    String url = mgtApiUrl.concat("users/");
    CloseableHttpResponse httpResponse = Utils.doGet(groupId, nodeId, accessToken, url);
    JsonArray userList = HttpUtils.getJsonResponse(httpResponse).get("list").getAsJsonArray();
    for (JsonElement user : userList) {
        UsersInner usersInner = getUserDetails(groupId, nodeId, accessToken, url, user);
        users.add(usersInner);
    }
    return users;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) NodeList(org.wso2.ei.dashboard.core.rest.model.NodeList) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Users(org.wso2.ei.dashboard.core.rest.model.Users) UsersInner(org.wso2.ei.dashboard.core.rest.model.UsersInner)

Example 2 with UsersInner

use of org.wso2.ei.dashboard.core.rest.model.UsersInner in project product-mi-tooling by wso2.

the class UsersDelegate method getUserDetails.

private UsersInner getUserDetails(String groupId, String nodeId, String accessToken, String url, JsonElement user) throws ManagementApiException {
    String userId = user.getAsJsonObject().get("userId").getAsString();
    UsersInner usersInner = new UsersInner();
    usersInner.setUserId(userId);
    String getUsersDetailsUrl;
    if (userId.contains(DOMAIN_SEPARATOR)) {
        String[] parts = userId.split(DOMAIN_SEPARATOR);
        // parts[0] = domain, parts[1] = new userId
        getUsersDetailsUrl = url.concat(parts[1]).concat("?domain=").concat(parts[0]);
    } else {
        getUsersDetailsUrl = url.concat(userId);
    }
    CloseableHttpResponse userDetailResponse = Utils.doGet(groupId, nodeId, accessToken, getUsersDetailsUrl);
    String userDetail = HttpUtils.getStringResponse(userDetailResponse);
    usersInner.setDetails(userDetail);
    return usersInner;
}
Also used : CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) UsersInner(org.wso2.ei.dashboard.core.rest.model.UsersInner)

Aggregations

CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 UsersInner (org.wso2.ei.dashboard.core.rest.model.UsersInner)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 NodeList (org.wso2.ei.dashboard.core.rest.model.NodeList)1 Users (org.wso2.ei.dashboard.core.rest.model.Users)1