Search in sources :

Example 1 with GetUserListTask

use of com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask in project cubrid-manager by CUBRID.

the class CQBDbUsersFolderLoader method load.

/**
	 *
	 * Load children object for parent
	 *
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        CubridDatabase database = ((ISchemaNode) parent).getDatabase();
        if (database.getRunningType() == DbRunningType.STANDALONE) {
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        DbUserInfoList dbUserInfoList = new DbUserInfoList();
        GetUserListTask task = new GetUserListTask(database.getDatabaseInfo());
        parent.removeAllChild();
        try {
            dbUserInfoList = task.getResultModel();
        } catch (Exception e) {
            LOGGER.error("load user failed", e);
        }
        DbUserInfo latestDLoginedbUserInfo = databaseInfo.getAuthLoginedDbUserInfo();
        List<DbUserInfo> dbUserList = dbUserInfoList == null ? null : dbUserInfoList.getUserList();
        formatUserList(dbUserList);
        for (int i = 0; dbUserList != null && dbUserList.size() > i; i++) {
            DbUserInfo dbUserInfo = dbUserList.get(i);
            if (dbUserInfo.getName().equals(latestDLoginedbUserInfo.getName())) {
                dbUserInfo.setDbaAuthority(latestDLoginedbUserInfo.isDbaAuthority());
            // databaseInfo.setAuthLoginedDbUserInfo(dbUserInfo);
            }
            String id = parent.getId() + NODE_SEPARATOR + dbUserInfo.getName();
            ICubridNode dbUserInfoNode = new DefaultSchemaNode(id, dbUserInfo.getName(), "icons/navigator/user_item.png");
            dbUserInfoNode.setType(NodeType.USER);
            dbUserInfoNode.setModelObj(dbUserInfo);
            dbUserInfoNode.setContainer(false);
            dbUserInfoNode.setEditorId(CQBUserEditor.ID);
            parent.addChild(dbUserInfoNode);
        }
        databaseInfo.setDbUserInfoList(dbUserInfoList);
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 2 with GetUserListTask

use of com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask in project cubrid-manager by CUBRID.

the class DBAuthComparator method loadData.

/**
	 * Load the data
	 */
private void loadData() {
    final GetUserListTask getUserTask = new GetUserListTask(database.getDatabaseInfo());
    final GetAllUserAuthorizationsTask getUserAuthTask = new GetAllUserAuthorizationsTask(database.getDatabaseInfo());
    TaskJobExecutor taskExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            final List<UserDetailInfo> userDetailList = new ArrayList<UserDetailInfo>();
            DbUserInfoList userListInfo = getUserTask.getResultModel();
            Map<String, UserDetailInfo> allUserAuthMap = getUserAuthTask.getAllAuthMap();
            if (userListInfo != null) {
                for (DbUserInfo userInfo : userListInfo.getUserList()) {
                    UserDetailInfo userDetailInfo = allUserAuthMap.get(userInfo.getName());
                    if (userDetailInfo == null) {
                        userDetailInfo = new UserDetailInfo();
                        userDetailInfo.setUserName(userInfo.getName());
                    }
                    userDetailList.add(userDetailInfo);
                }
            }
            setTableData(userDetailList);
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    taskExec.addTask(getUserTask);
    taskExec.addTask(getUserAuthTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.jobLoadUserData + " - " + "@" + dbName + "@" + serverName;
    taskExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) GetAllUserAuthorizationsTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetAllUserAuthorizationsTask) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) List(java.util.List) ArrayList(java.util.ArrayList) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) Map(java.util.Map) UserDetailInfo(com.cubrid.cubridmanager.core.cubrid.user.model.UserDetailInfo)

Example 3 with GetUserListTask

use of com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask in project cubrid-manager by CUBRID.

the class EditUserAction method doRun.

/**
	 * Perform do run
	 *
	 * @param node
	 */
public void doRun(ISchemaNode node) {
    // FIXME move this logic to core module
    CubridDatabase database = node.getDatabase();
    EditUserDialog dlg = new EditUserDialog(shell);
    Connection con = null;
    try {
        con = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), false);
        final GetAllClassListTask classInfoTask = new GetAllClassListTask(database.getDatabaseInfo(), con);
        final GetAllPartitionClassTask partitionTask = new GetAllPartitionClassTask(database.getDatabaseInfo(), con);
        GetUserListTask task = new GetUserListTask(database.getDatabaseInfo(), con);
        DbUserInfoList userListInfo = null;
        try {
            userListInfo = task.getResultModel();
        } catch (Exception e) {
            LOGGER.error("load user failed", e);
            return;
        }
        boolean isSuccess = dlg.execTask(-1, new ITask[] { classInfoTask, partitionTask }, getShell());
        if (!isSuccess) {
            return;
        }
        dlg.setUserListInfo(userListInfo);
        dlg.setDatabase(database);
        dlg.setUserName(node.getName());
        dlg.setPartitionClassMap(partitionTask.getPartitionClassMap());
        dlg.setNewFlag(false);
        GetUserAuthorizationsTask privilegeTask = new GetUserAuthorizationsTask(database.getDatabaseInfo(), con);
        try {
            for (DbUserInfo userInfo : userListInfo.getUserList()) {
                userInfo.setUserAuthorizations(privilegeTask.getUserAuthorizations(userInfo.getName()));
            }
        } catch (Exception e) {
            LOGGER.error("get user failed", e);
            return;
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        QueryUtil.freeQuery(con);
    }
    if (dlg.open() == IDialogConstants.OK_ID) {
        if (database.getServer() != null) {
            persisteManager.updateDBPassword(database.getServer().getServerName(), database.getServer().getHostAddress(), database.getServer().getMonPort(), database.getDatabaseInfo().getDbName(), database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName(), dlg.getInputtedPassword(), database.isAutoSavePassword());
        }
        CubridNavigatorView navigationView = CubridNavigatorView.findNavigationView();
        if (navigationView != null) {
            TreeViewer treeViewer = navigationView.getViewer();
            if (treeViewer != null) {
                DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
                if (userInfo != null && userInfo.getName().equalsIgnoreCase(node.getName())) {
                    CommonUITool.openInformationBox(Messages.titleLogout, Messages.msgLogoutInfomation);
                    database.setLogined(false);
                    database.setAutoSavePassword(false);
                    CubridNodeChangedEvent event = new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGOUT);
                    CubridNodeManager.getInstance().fireCubridNodeChanged(event);
                    database.removeAllChild();
                    treeViewer.refresh(database, true);
                } else {
                    CommonUITool.refreshNavigatorTree(treeViewer, node.getParent());
                    setEnabled(false);
                }
            }
        }
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        persisteManager.savaAllServers();
        persisteManager.saveAllGroupNodes();
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) Connection(java.sql.Connection) GetAllPartitionClassTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) EditUserDialog(com.cubrid.common.ui.cubrid.user.dialog.EditUserDialog) GetUserAuthorizationsTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserAuthorizationsTask) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 4 with GetUserListTask

use of com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask in project cubrid-manager by CUBRID.

the class AddUserAction method doRun.

/**
	 * Perform do run
	 *
	 * @param node
	 */
public void doRun(ISchemaNode node) {
    // FIXME move this logic to core module
    CubridDatabase database = node.getDatabase();
    //		if (database.getDatabaseInfo().isHAMode()) {
    //			CommonUITool.openErrorBox(Messages.errNoSupportInHA);
    //			return;
    //		}
    String childId = database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridNodeLoader.USERS_FOLDER_ID;
    ICubridNode folderNode = database.getChild(childId);
    if (folderNode == null) {
        return;
    }
    EditUserDialog dlg = new EditUserDialog(getShell());
    Connection con = null;
    try {
        con = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), false);
        final GetAllClassListTask classInfoTask = new GetAllClassListTask(database.getDatabaseInfo(), con);
        final GetAllPartitionClassTask partitionTask = new GetAllPartitionClassTask(database.getDatabaseInfo(), con);
        GetUserListTask task = new GetUserListTask(database.getDatabaseInfo(), con);
        DbUserInfoList userListInfo = null;
        try {
            userListInfo = task.getResultModel();
        } catch (Exception e) {
            LOGGER.error("load user failed", e);
            return;
        }
        boolean isSuccess = dlg.execTask(-1, new ITask[] { classInfoTask, partitionTask }, getShell());
        if (!isSuccess) {
            return;
        }
        dlg.setUserListInfo(userListInfo);
        dlg.setDatabase(database);
        dlg.setUserName(node.getName());
        dlg.setPartitionClassMap(partitionTask.getPartitionClassMap());
        dlg.setNewFlag(true);
        GetUserAuthorizationsTask privilegeTask = new GetUserAuthorizationsTask(database.getDatabaseInfo(), con);
        try {
            for (DbUserInfo userInfo : userListInfo.getUserList()) {
                if (userInfo.getName().equals(node.getName())) {
                    userInfo.setUserAuthorizations(privilegeTask.getUserAuthorizations(userInfo.getName()));
                }
            }
        } catch (Exception e) {
            LOGGER.error("get user failed", e);
            return;
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        QueryUtil.freeQuery(con);
    }
    if (dlg.open() == IDialogConstants.OK_ID) {
        //Don't count the child
        if (!folderNode.getLoader().isLoaded()) {
            return;
        }
        CubridNavigatorView navigatorView = CubridNavigatorView.findNavigationView();
        if (navigatorView != null) {
            TreeViewer treeViewer = navigatorView.getViewer();
            if (treeViewer != null) {
                CubridNodeChangedEvent event = new CubridNodeChangedEvent(folderNode, CubridNodeChangedEventType.NODE_REFRESH);
                CubridNodeManager.getInstance().fireCubridNodeChanged(event);
                CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, folderNode);
            } else {
                CommonUITool.refreshNavigatorTree(treeViewer, node.getParent());
                setEnabled(false);
            }
        }
        ActionManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) Connection(java.sql.Connection) GetAllPartitionClassTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) EditUserDialog(com.cubrid.common.ui.cubrid.user.dialog.EditUserDialog) GetUserAuthorizationsTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserAuthorizationsTask) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 5 with GetUserListTask

use of com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask in project cubrid-manager by CUBRID.

the class CQBUserEditor method execTask.

/**
	 * Execute tasks
	 *
	 * @param tasks the task array
	 * @return boolean
	 */
public boolean execTask(final ITask[] tasks) {
    TaskExecutor taskExecutor = new TaskExecutor() {

        public boolean exec(IProgressMonitor monitor) {
            for (ITask t : tasks) {
                if (t instanceof GetAllClassListTask) {
                    allClassInfoList = ((GetAllClassListTask) t).getAllClassInfoList();
                } else {
                    t.execute();
                }
                if (t instanceof GetUserListTask) {
                    try {
                        userListInfo = ((GetUserListTask) t).getResultModel();
                    } catch (Exception e) {
                        LOGGER.error(e.getMessage());
                    }
                }
                if (t instanceof GetAllPartitionClassTask) {
                    partitionClassMap = ((GetAllPartitionClassTask) t).getPartitionClassMap();
                }
                final String msg = t.getErrorMsg();
                if (monitor.isCanceled()) {
                    return false;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            return true;
        }
    };
    for (ITask task : tasks) {
        taskExecutor.addTask(task);
    }
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    return taskExecutor.isSuccess();
}
Also used : GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) GetAllPartitionClassTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

GetUserListTask (com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask)6 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)5 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)4 GetAllPartitionClassTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask)4 DbUserInfoList (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList)4 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)3 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)3 GetUserAuthorizationsTask (com.cubrid.cubridmanager.core.cubrid.user.task.GetUserAuthorizationsTask)3 Connection (java.sql.Connection)3 ITask (com.cubrid.common.core.task.ITask)2 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)2 EditUserDialog (com.cubrid.common.ui.cubrid.user.dialog.EditUserDialog)2 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 PartInitException (org.eclipse.ui.PartInitException)2 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)1 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)1 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)1