Search in sources :

Example 1 with EnterPasswordDialog

use of org.pentaho.di.ui.core.dialog.EnterPasswordDialog in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryDialog method create.

private void create() {
    System.out.println("Loading repository info...");
    KettleDatabaseRepositoryMeta repositoryMeta = new KettleDatabaseRepositoryMeta();
    getInfo(repositoryMeta);
    if (repositoryMeta.getConnection() != null) {
        if (repositoryMeta.getConnection().getAccessType() == DatabaseMeta.TYPE_ACCESS_ODBC) {
            // Show a warning: using ODBC is not always the best choice ;-)
            System.out.println("Show ODBC warning...");
            MessageBox qmb = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
            qmb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.ODBCIsNotSafe.Message", Const.CR, Const.CR));
            qmb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.ODBCIsNotSafe.Title"));
            int answer = qmb.open();
            if (answer != SWT.YES) {
                // Don't continue
                return;
            }
        }
        try {
            System.out.println("Allocating repository...");
            KettleDatabaseRepository rep = (KettleDatabaseRepository) PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
            rep.init(repositoryMeta);
            if (!rep.getDatabaseMeta().getDatabaseInterface().supportsRepository()) {
                // Show a warning box "This database type is not supported for the use as a database repository."
                System.out.println("Show database type is not supported warning...");
                MessageBox qmb = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
                qmb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.DBTypeNotSupport.Message", Const.CR, Const.CR));
                qmb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.DBTypeNotSupport.Title"));
                int answer = qmb.open();
                if (answer != SWT.YES) {
                    // Don't continue
                    return;
                }
            }
            System.out.println("Connecting to database for repository creation...");
            rep.connectionDelegate.connect(true, true);
            boolean upgrade = false;
            String cu = BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Create");
            try {
                String userTableName = rep.getDatabaseMeta().quoteField(KettleDatabaseRepository.TABLE_R_USER);
                upgrade = rep.getDatabase().checkTableExists(userTableName);
                if (upgrade) {
                    cu = BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Upgrade");
                }
            } catch (KettleDatabaseException dbe) {
                // Roll back the connection: this is required for certain databases like PGSQL
                // Otherwise we can't execute any other DDL statement.
                // 
                rep.rollback();
            // Don't show an error anymore, just go ahead and propose to create the repository!
            }
            MessageBox qmb = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
            qmb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Message1") + cu + BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Message2"));
            qmb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Title"));
            int answer = qmb.open();
            if (answer == SWT.YES) {
                boolean goAhead = !upgrade;
                if (!goAhead) {
                    EnterPasswordDialog etd = new EnterPasswordDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.EnterPassword.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.EnterPassword.Message"), "");
                    etd.setModal();
                    String pwd = etd.open();
                    if (pwd != null) {
                        try {
                            // authenticate as admin before upgrade
                            // disconnect before connecting, we connected above already
                            // 
                            rep.disconnect();
                            rep.connect("admin", pwd, true);
                            goAhead = true;
                        } catch (KettleException e) {
                            new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToVerifyUser.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToVerifyUser.Message"), e);
                        }
                    }
                }
                if (goAhead) {
                    System.out.println(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.TryingToUpgradeRepository.Message1") + cu + BaseMessages.getString(PKG, "RepositoryDialog.Dialog.TryingToUpgradeRepository.Message2"));
                    UpgradeRepositoryProgressDialog urpd = new UpgradeRepositoryProgressDialog(shell, rep, upgrade);
                    if (urpd.open()) {
                        if (urpd.isDryRun()) {
                            StringBuilder sql = new StringBuilder();
                            sql.append("-- Repository creation/upgrade DDL: ").append(Const.CR);
                            sql.append("--").append(Const.CR);
                            sql.append("-- Nothing was created nor modified in the target repository database.").append(Const.CR);
                            sql.append("-- Hit the OK button to execute the generated SQL or Close to reject the changes.").append(Const.CR);
                            sql.append("-- Please note that it is possible to change/edit the generated SQL before execution.").append(Const.CR);
                            sql.append("--").append(Const.CR);
                            for (String statement : urpd.getGeneratedStatements()) {
                                if (statement.endsWith(";")) {
                                    sql.append(statement).append(Const.CR);
                                } else {
                                    sql.append(statement).append(";").append(Const.CR).append(Const.CR);
                                }
                            }
                            SQLEditor editor = new SQLEditor(rep.getDatabaseMeta(), shell, SWT.NONE, rep.getDatabaseMeta(), DBCache.getInstance(), sql.toString());
                            editor.open();
                        } else {
                            MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
                            mb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UpgradeFinished.Message1") + cu + BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UpgradeFinished.Message2"));
                            mb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UpgradeFinished.Title"));
                            mb.open();
                        }
                    }
                }
            }
            rep.disconnect();
        } catch (KettleException ke) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToConnectToUpgrade.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToConnectToUpgrade.Message") + Const.CR, ke);
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
        mb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.FirstCreateAValidConnection.Message"));
        mb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.FirstCreateAValidConnection.Title"));
        mb.open();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) UpgradeRepositoryProgressDialog(org.pentaho.di.ui.repository.dialog.UpgradeRepositoryProgressDialog) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleDatabaseRepositoryMeta(org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) KettleDatabaseRepository(org.pentaho.di.repository.kdr.KettleDatabaseRepository) EnterPasswordDialog(org.pentaho.di.ui.core.dialog.EnterPasswordDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) KettleDatabaseRepository(org.pentaho.di.repository.kdr.KettleDatabaseRepository) Repository(org.pentaho.di.repository.Repository)

Example 2 with EnterPasswordDialog

use of org.pentaho.di.ui.core.dialog.EnterPasswordDialog in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryDialog method drop.

private void drop() {
    KettleDatabaseRepositoryMeta repositoryMeta = new KettleDatabaseRepositoryMeta();
    getInfo(repositoryMeta);
    try {
        KettleDatabaseRepository rep = (KettleDatabaseRepository) PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
        rep.init(repositoryMeta);
        MessageBox qmb = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
        qmb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.ConfirmRemovalOfRepository.Message"));
        qmb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.ConfirmRemovalOfRepository.Title"));
        int answer = qmb.open();
        if (answer == SWT.YES) {
            EnterPasswordDialog etd = new EnterPasswordDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.AskAdminPassword.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.AskAdminPassword.Message"), "");
            String pwd = etd.open();
            if (pwd != null) {
                try {
                    // Connect as admin user
                    rep.connect("admin", pwd);
                    try {
                        rep.dropRepositorySchema();
                        MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
                        mb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.RemovedRepositoryTables.Message"));
                        mb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.RemovedRepositoryTables.Title"));
                        mb.open();
                    } catch (KettleDatabaseException dbe) {
                        MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                        mb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToRemoveRepository.Message") + Const.CR + dbe.getMessage());
                        mb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToRemoveRepository.Title"));
                        mb.open();
                    }
                } catch (KettleException e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToVerifyAdminUser.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToVerifyAdminUser.Message"), e);
                } finally {
                    rep.disconnect();
                }
            }
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.NoRepositoryFoundOnConnection.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.NoRepositoryFoundOnConnection.Message"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseRepository(org.pentaho.di.repository.kdr.KettleDatabaseRepository) Repository(org.pentaho.di.repository.Repository) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleDatabaseRepositoryMeta(org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) KettleDatabaseRepository(org.pentaho.di.repository.kdr.KettleDatabaseRepository) EnterPasswordDialog(org.pentaho.di.ui.core.dialog.EnterPasswordDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

MessageBox (org.eclipse.swt.widgets.MessageBox)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 KettleException (org.pentaho.di.core.exception.KettleException)2 RepositoryPluginType (org.pentaho.di.core.plugins.RepositoryPluginType)2 Repository (org.pentaho.di.repository.Repository)2 KettleDatabaseRepository (org.pentaho.di.repository.kdr.KettleDatabaseRepository)2 KettleDatabaseRepositoryMeta (org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta)2 EnterPasswordDialog (org.pentaho.di.ui.core.dialog.EnterPasswordDialog)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 SQLEditor (org.pentaho.di.ui.core.database.dialog.SQLEditor)1 UpgradeRepositoryProgressDialog (org.pentaho.di.ui.repository.dialog.UpgradeRepositoryProgressDialog)1