Search in sources :

Example 1 with CreateUserTask

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

the class EditUserDialog method buttonPressed.

/**
	 * When press button,call it
	 * 
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
        if (!valid()) {
            return;
        }
        boolean isChangePassword = false;
        if (newFlag) {
            isChangePassword = true;
        } else if (changePwdBtn.getSelection()) {
            isChangePassword = true;
        }
        String password = null;
        if (isChangePassword) {
            password = pwdText.getText();
            if (password == null) {
                password = "";
            }
        }
        this.inputtedPassword = password;
        boolean isNoDbaAuthUser = database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(userName) && !database.getDatabaseInfo().getAuthLoginedDbUserInfo().isDbaAuthority();
        String taskName = Messages.bind(Messages.addOrUpdateUserTaskName, userNameText.getText());
        TaskExecutor taskExecutor = new CommonTaskExec(taskName);
        ITask task = null;
        boolean isDropAndCreateUser = false;
        if (isNoDbaAuthUser) {
            if (isChangePassword) {
                task = new ChangeDbUserPwdTask(database.getDatabaseInfo());
                ChangeDbUserPwdTask changeDbUserPwdTask = (ChangeDbUserPwdTask) task;
                changeDbUserPwdTask.setDbUserName(userName);
                changeDbUserPwdTask.setNewPwd(password);
                taskExecutor.addTask(changeDbUserPwdTask);
            } else {
                super.buttonPressed(IDialogConstants.CANCEL_ID);
                return;
            }
        } else {
            if (newFlag) {
                List<String> groupList = new ArrayList<String>();
                for (int i = 0; i < userGroupTable.getItemCount(); i++) {
                    groupList.add(userGroupTable.getItem(i).getText(0));
                }
                List<String> memberList = new ArrayList<String>();
                for (Map<String, String> map : memberListData) {
                    memberList.add(map.get("0").toLowerCase(Locale.getDefault()));
                }
                task = new CreateUserTask(database.getDatabaseInfo(), userNameText.getText(), pwdText.getText(), groupList, memberList);
                taskExecutor.addTask(task);
            } else {
                if (!groupChange()) {
                    task = new DropUserTask(database.getDatabaseInfo(), userName);
                    taskExecutor.addTask(task);
                    List<String> groupList = new ArrayList<String>();
                    for (int i = 0; i < userGroupTable.getItemCount(); i++) {
                        groupList.add(userGroupTable.getItem(i).getText(0));
                    }
                    List<String> memberList = new ArrayList<String>();
                    for (Map<String, String> map : memberListData) {
                        memberList.add(map.get("0").toLowerCase(Locale.getDefault()));
                    }
                    task = new CreateUserTask(database.getDatabaseInfo(), userNameText.getText(), pwdText.getText(), groupList, memberList);
                    taskExecutor.addTask(task);
                    isDropAndCreateUser = true;
                } else if (isChangePassword) {
                    task = new ChangeDbUserPwdTask(database.getDatabaseInfo());
                    ChangeDbUserPwdTask changeDbUserPwdTask = (ChangeDbUserPwdTask) task;
                    changeDbUserPwdTask.setDbUserName(userName);
                    changeDbUserPwdTask.setNewPwd(password);
                    taskExecutor.addTask(task);
                }
            }
        }
        task = new UpdateAddUserJdbcTask(database.getDatabaseInfo(), userNameText.getText(), classGrantMap, authListData, authListDataOld, isDBAGroup(), isDropAndCreateUser);
        taskExecutor.addTask(task);
        new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
        if (taskExecutor.isSuccess() && isChangePassword && database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(userName)) {
            database.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(password);
        }
        if (taskExecutor.isSuccess()) {
            String message = null;
            if (newFlag) {
                message = Messages.msgAddUserSuccess;
            } else {
                message = Messages.msgModifyUserSuccess;
            }
            CommonUITool.openInformationBox(Messages.msgInformation, message);
        } else {
            return;
        }
    }
    super.buttonPressed(buttonId);
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ITask(com.cubrid.common.core.task.ITask) ArrayList(java.util.ArrayList) CreateUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.CreateUserTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ChangeDbUserPwdTask(com.cubrid.cubridmanager.core.cubrid.user.task.ChangeDbUserPwdTask) DropUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.DropUserTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) UpdateAddUserJdbcTask(com.cubrid.cubridmanager.core.cubrid.user.task.UpdateAddUserJdbcTask)

Aggregations

ITask (com.cubrid.common.core.task.ITask)1 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 ChangeDbUserPwdTask (com.cubrid.cubridmanager.core.cubrid.user.task.ChangeDbUserPwdTask)1 CreateUserTask (com.cubrid.cubridmanager.core.cubrid.user.task.CreateUserTask)1 DropUserTask (com.cubrid.cubridmanager.core.cubrid.user.task.DropUserTask)1 UpdateAddUserJdbcTask (com.cubrid.cubridmanager.core.cubrid.user.task.UpdateAddUserJdbcTask)1 ArrayList (java.util.ArrayList)1