use of com.cubrid.cubridmanager.core.cubrid.user.model.UserGroup in project cubrid-manager by CUBRID.
the class GetUserListTask method buildUserInfo.
/**
*
* Build the database user information
*
* @param dbUserInfoList DbUserInfoList
* @throws SQLException The exception
*/
private void buildUserInfo(DbUserInfoList dbUserInfoList) {
Map<String, String> oidMap = new HashMap<String, String>();
Map<String, List<String>> groupMap = new HashMap<String, List<String>>();
String sql = "SELECT db_user, name, groups FROM db_user";
// [TOOLS-2425]Support shard broker
sql = databaseInfo.wrapShardQuery(sql);
try {
stmt = connection.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
String oidStr = rs.getString(1);
String name = rs.getString(2);
CUBRIDResultSetProxy cubridRS = (CUBRIDResultSetProxy) rs;
Object[] objs = (Object[]) cubridRS.getCollection(3);
List<String> groups = new ArrayList<String>();
for (Object obj : objs) {
if (obj != null && obj.getClass() == CUBRIDOIDProxy.getCUBRIDOIDClass(cubridRS.getJdbcVersion())) {
groups.add((new CUBRIDOIDProxy(obj)).getOidString());
}
}
if (name != null) {
name = name.toLowerCase(Locale.getDefault());
}
oidMap.put(oidStr, name);
groupMap.put(name, groups);
DbUserInfo dbUserInfo = new DbUserInfo();
dbUserInfo.setDbName(databaseInfo.getDbName());
dbUserInfo.setName(name);
dbUserInfo.addAuthorization(new HashMap<String, String>());
dbUserInfoList.addUser(dbUserInfo);
}
} catch (SQLException ex) {
errorMsg = ex.getMessage();
} finally {
QueryUtil.freeQuery(stmt, rs);
}
// get the group user
if (dbUserInfoList.getUserList() != null) {
for (DbUserInfo userInfo : dbUserInfoList.getUserList()) {
UserGroup userGroup = userInfo.getGroups();
if (userGroup == null) {
userGroup = new UserGroup();
userInfo.addGroups(userGroup);
}
List<String> groupOIDList = groupMap.get(userInfo.getName());
for (String groupOID : groupOIDList) {
String groupUser = oidMap.get(groupOID);
if (groupUser != null) {
userInfo.getGroups().addGroup(groupUser);
}
}
}
}
//get the member user
// for (DbUserInfo userInfo : dbUserInfoList.getUserList()) {
// List<String> groupNameList = userInfo.getGroupList();
// for (String groupName : groupNameList) {
// User groupUser = catalog.getUserByName(groupName);
// if (groupUser != null) {
// ((CUBRIDUser) groupUser).addMember(user.getName());
// }
// }
// }
}
Aggregations