Search in sources :

Example 6 with DatabaseDialog

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

the class JobEntryDialog_ConnectionLine_Test method showDbDialog_LoopsUntilUniqueValueIsInput.

@Test
public void showDbDialog_LoopsUntilUniqueValueIsInput() throws Exception {
    DatabaseMeta db1 = createDefaultDatabase();
    DatabaseMeta db2 = createDefaultDatabase();
    db2.setName(INPUT_NAME);
    JobMeta jobMeta = new JobMeta();
    jobMeta.addDatabase(db1);
    jobMeta.addDatabase(db2);
    final String expectedResult = INPUT_NAME + "2";
    DatabaseDialog databaseDialog = mock(DatabaseDialog.class);
    when(databaseDialog.open()).thenReturn(INPUT_NAME).thenReturn(INPUT_NAME + " ").thenReturn(INPUT_NAME.toUpperCase()).thenReturn(expectedResult);
    JobEntryDialog dialog = mock(JobEntryDialog.class);
    dialog.databaseDialog = databaseDialog;
    dialog.jobMeta = jobMeta;
    when(dialog.showDbDialogUnlessCancelledOrValid(anyDbMeta(), anyDbMeta())).thenCallRealMethod();
    // try to rename db1 ("qwerty")
    String result = dialog.showDbDialogUnlessCancelledOrValid((DatabaseMeta) db1.clone(), db1);
    assertEquals(expectedResult, result);
    // database dialog should be shown four times
    verify(databaseDialog, times(4)).open();
    // and the error message should be shown three times
    verify(dialog, times(3)).showDbExistsDialog(anyDbMeta());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseDialog(org.pentaho.di.ui.core.database.dialog.DatabaseDialog) Test(org.junit.Test)

Example 7 with DatabaseDialog

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

the class BaseStepDialog_ConnectionLine_Test method test_showDbDialogUnlessCancelledOrValid_ShownOnce.

private void test_showDbDialogUnlessCancelledOrValid_ShownOnce(String inputName, String expectedResult) throws Exception {
    DatabaseDialog databaseDialog = mock(DatabaseDialog.class);
    when(databaseDialog.open()).thenReturn(inputName);
    TransMeta transMeta = new TransMeta();
    DatabaseMeta db = createDefaultDatabase();
    transMeta.addDatabase(db);
    BaseStepDialog dialog = mock(BaseStepDialog.class);
    dialog.databaseDialog = databaseDialog;
    dialog.transMeta = transMeta;
    when(dialog.showDbDialogUnlessCancelledOrValid(anyDbMeta(), anyDbMeta())).thenCallRealMethod();
    when(dialog.getDatabaseDialog(any(Shell.class))).thenCallRealMethod();
    String result = dialog.showDbDialogUnlessCancelledOrValid((DatabaseMeta) db.clone(), db);
    assertEquals(expectedResult, result);
    // database dialog should be shown only once
    verify(databaseDialog, times(1)).open();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) TransMeta(org.pentaho.di.trans.TransMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseDialog(org.pentaho.di.ui.core.database.dialog.DatabaseDialog)

Example 8 with DatabaseDialog

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

the class StarModelerPerspective method createSharedDatabase.

protected void createSharedDatabase(CCombo targetDatabase) {
    Shell shell = Spoon.getInstance().getShell();
    boolean retry = true;
    while (retry) {
        try {
            DatabaseMeta dbMeta = new DatabaseMeta();
            DatabaseDialog databaseDialog = new DatabaseDialog(shell, dbMeta);
            if (databaseDialog.open() != null) {
                // Add dbMeta to the shared databases...
                // 
                IMetaStore metaStore = Spoon.getInstance().getMetaStore();
                DatabaseMetaStoreUtil.createDatabaseElement(metaStore, dbMeta);
                // Refresh the list...
                // 
                final List<DatabaseMeta> sharedDatabases = DatabaseMetaStoreUtil.getDatabaseElements(metaStore);
                String[] databaseNames = SharedDatabaseUtil.getSortedDatabaseNames(sharedDatabases);
                targetDatabase.setItems(databaseNames);
                targetDatabase.setText(dbMeta.getName());
            }
            retry = false;
        } catch (MetaStoreElementExistException e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "StarModelerPerspective.Exception.UnableToCreateSharedDB.Title"), BaseMessages.getString(PKG, "StarModelerPerspective.Exception.UnableToCreateSharedDB.Message"), e);
        } catch (MetaStoreException e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "StarModelerPerspective.Exception.UnableToCreateSharedDB.Title"), BaseMessages.getString(PKG, "StarModelerPerspective.Exception.UnableToCreateSharedDB.Message"), e);
            retry = false;
        }
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) Shell(org.eclipse.swt.widgets.Shell) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) DatabaseDialog(org.pentaho.di.ui.core.database.dialog.DatabaseDialog)

Example 9 with DatabaseDialog

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

the class RepositoryConnectController method editDatabaseConnection.

public String editDatabaseConnection(String database) {
    CompletableFuture<String> future = new CompletableFuture<>();
    spoonSupplier.get().getShell().getDisplay().asyncExec(() -> {
        DatabaseMeta databaseMeta = getDatabase(database);
        String originalName = databaseMeta.getName();
        DatabaseDialog databaseDialog = new DatabaseDialog(spoonSupplier.get().getShell(), databaseMeta);
        databaseDialog.open();
        if (!isDatabaseWithNameExist(databaseMeta, false)) {
            save();
            future.complete(databaseMeta.getName());
        } else {
            DatabaseDialog.showDatabaseExistsDialog(spoonSupplier.get().getShell(), databaseMeta);
            databaseMeta.setName(originalName);
            databaseMeta.setDisplayName(originalName);
            future.complete(originalName);
        }
    });
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("name", future.get());
        return jsonObject.toJSONString();
    } catch (Exception e) {
        jsonObject.put("name", "None");
        return jsonObject.toJSONString();
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JSONObject(org.json.simple.JSONObject) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleException(org.pentaho.di.core.exception.KettleException) ExecutionException(java.util.concurrent.ExecutionException) DatabaseDialog(org.pentaho.di.ui.core.database.dialog.DatabaseDialog)

Example 10 with DatabaseDialog

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

the class RepositoryConnectController method createConnection.

public String createConnection() {
    CompletableFuture<String> future = new CompletableFuture<>();
    spoonSupplier.get().getShell().getDisplay().asyncExec(() -> {
        DatabaseDialog databaseDialog = new DatabaseDialog(spoonSupplier.get().getShell(), new DatabaseMeta());
        databaseDialog.open();
        DatabaseMeta databaseMeta = databaseDialog.getDatabaseMeta();
        if (databaseMeta != null) {
            if (!isDatabaseWithNameExist(databaseMeta, true)) {
                addDatabase(databaseMeta);
                future.complete(databaseMeta.getName());
            } else {
                DatabaseDialog.showDatabaseExistsDialog(spoonSupplier.get().getShell(), databaseMeta);
            }
        }
        future.complete("None");
    });
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("name", future.get());
        return jsonObject.toJSONString();
    } catch (Exception e) {
        jsonObject.put("name", "None");
        return jsonObject.toJSONString();
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JSONObject(org.json.simple.JSONObject) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleException(org.pentaho.di.core.exception.KettleException) ExecutionException(java.util.concurrent.ExecutionException) DatabaseDialog(org.pentaho.di.ui.core.database.dialog.DatabaseDialog)

Aggregations

DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)11 DatabaseDialog (org.pentaho.di.ui.core.database.dialog.DatabaseDialog)11 Shell (org.eclipse.swt.widgets.Shell)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 JSONObject (org.json.simple.JSONObject)2 Test (org.junit.Test)2 KettleException (org.pentaho.di.core.exception.KettleException)2 JobMeta (org.pentaho.di.job.JobMeta)2 TransMeta (org.pentaho.di.trans.TransMeta)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 Button (org.eclipse.swt.widgets.Button)1 Label (org.eclipse.swt.widgets.Label)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1 ComboVar (org.pentaho.di.ui.core.widget.ComboVar)1 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)1