Skip to content

Commit

Permalink
Added new method for displaying Users on ChildAccounts->Users grid
Browse files Browse the repository at this point in the history
Signed-off-by: ct-ajovanovic <aleksandra.jovanovic@comtrade.com>
  • Loading branch information
ct-ajovanovic authored and Coduz committed Dec 21, 2018
1 parent 7469958 commit 62ce4ee
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Expand Up @@ -77,9 +77,8 @@ protected void load(Object loadConfig, AsyncCallback<PagingLoadResult<GwtUser>>
if (query.getScopeId() == null) {
callback.onSuccess(new BasePagingLoadResult<GwtUser>(new ArrayList<GwtUser>()));
} else {
GWT_USER_SERVICE.query((PagingLoadConfig) loadConfig,
query,
callback);
GWT_USER_SERVICE.getUsersForAccount((PagingLoadConfig) loadConfig, query,
currentSession.getSelectedAccountId(), callback);
}
}
};
Expand Down
Expand Up @@ -332,4 +332,44 @@ public PagingLoadResult<GwtUser> getUsersForRole(PagingLoadConfig pagingLoadConf
}
return new BasePagingLoadResult<GwtUser>(list, pagingLoadConfig.getOffset(), totalLength);
}

@Override
public PagingLoadResult<GwtUser> getUsersForAccount(PagingLoadConfig loadConfig, GwtUserQuery gwtUserQuery,
String accountId) throws GwtKapuaException {

int totalLength = 0;
List<GwtUser> gwtUsers = new ArrayList<GwtUser>();
try {
UserQuery userQuery = GwtKapuaUserModelConverter.convertUserQuery(loadConfig, gwtUserQuery);
UserListResult users = USER_SERVICE.query(userQuery);
totalLength = (int) USER_SERVICE.count(userQuery);

if (!users.isEmpty()) {
final UserQuery allUsersQuery = USER_FACTORY.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(accountId));
UserListResult allUsers = KapuaSecurityUtils.doPrivileged(new Callable<UserListResult>() {

@Override
public UserListResult call() throws Exception {
return USER_SERVICE.query(allUsersQuery);
}
});

HashMap<String, String> usernameMap = new HashMap<String, String>();
for (User user : allUsers.getItems()) {
usernameMap.put(user.getId().toCompactId(), user.getName());
}
for (User u : users.getItems()) {
GwtUser gwtUser = KapuaGwtUserModelConverter.convertUser(u);
gwtUser.setCreatedByName(usernameMap.get(u.getCreatedBy().toCompactId()));
gwtUser.setModifiedByName(usernameMap.get(u.getModifiedBy().toCompactId()));
gwtUsers.add(gwtUser);
}
}

} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}

return new BasePagingLoadResult<GwtUser>(gwtUsers, loadConfig.getOffset(), totalLength);
}
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Eurotech and/or its affiliates and others
* Copyright (c) 2017, 2018 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -96,4 +96,6 @@ public PagingLoadResult<GwtUser> query(PagingLoadConfig loadConfig, GwtUserQuery
public ListLoadResult<GwtGroupedNVPair> getUserDescription(String shortScopeId, String shortUserId) throws GwtKapuaException;

PagingLoadResult<GwtUser> getUsersForRole(PagingLoadConfig pagingLoadConfig, GwtAccessRoleQuery query) throws GwtKapuaException;

public PagingLoadResult<GwtUser> getUsersForAccount(PagingLoadConfig loadConfig, GwtUserQuery gwtUserQuery, String accountId) throws GwtKapuaException;
}

0 comments on commit 62ce4ee

Please sign in to comment.