Search in sources :

Example 1 with UserGroup

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());
//				}
//			}
//		}
}
Also used : CUBRIDResultSetProxy(com.cubrid.jdbc.proxy.driver.CUBRIDResultSetProxy) CUBRIDOIDProxy(com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) UserGroup(com.cubrid.cubridmanager.core.cubrid.user.model.UserGroup) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ArrayList(java.util.ArrayList) List(java.util.List) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList)

Aggregations

DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)1 DbUserInfoList (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList)1 UserGroup (com.cubrid.cubridmanager.core.cubrid.user.model.UserGroup)1 CUBRIDOIDProxy (com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy)1 CUBRIDResultSetProxy (com.cubrid.jdbc.proxy.driver.CUBRIDResultSetProxy)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1