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());
}
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();
}
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;
}
}
}
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();
}
}
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();
}
}
Aggregations