use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class WizardConnectionController method testConnection.
@Bindable
public void testConnection() {
RequestBuilder testConnectionBuilder = new RequestBuilder(RequestBuilder.PUT, ConnectionController.getServiceURL("test"));
testConnectionBuilder.setHeader("Content-Type", "application/json");
try {
// AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(currentConnection);
AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
testConnectionBuilder.sendRequest(AutoBeanCodex.encode(bean).getPayload(), new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
displayErrorMessage(exception);
}
@Override
public void onResponseReceived(Request request, Response response) {
Boolean testPassed = new Boolean(response.getText());
try {
if (testPassed) {
openSuccesDialog(MessageHandler.getString("SUCCESS"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.CONNECTION_TEST_SUCCESS"));
} else {
openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.ERROR_0003_CONNECTION_TEST_FAILED"));
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class WizardRelationalDatasourceController method init.
@Bindable
public void init(final DatasourceModel datasourceModel) {
this.datasourceModel = datasourceModel;
bf = new GwtBindingFactory(document);
// $NON-NLS-1$
sampleDataTree = (XulTree) document.getElementById("relationalSampleDataTable");
// $NON-NLS-1$
aggregationEditorDialog = (XulDialog) document.getElementById("relationalAggregationEditorDialog");
// $NON-NLS-1$
sampleDataDialog = (XulDialog) document.getElementById("relationalSampleDataDialog");
// $NON-NLS-1$
errorDialog = (XulDialog) document.getElementById("errorDialog");
// $NON-NLS-1$
errorLabel = (XulLabel) document.getElementById("errorLabel");
// $NON-NLS-1$
applyQueryConfirmationDialog = (XulDialog) document.getElementById("applyQueryConfirmationDialog");
// $NON-NLS-1$
errorLabel = (XulLabel) document.getElementById("errorLabel");
// $NON-NLS-1$
successDialog = (XulDialog) document.getElementById("successDialog");
// $NON-NLS-1$
successLabel = (XulLabel) document.getElementById("successLabel");
// $NON-NLS-1$
datasourceName = (XulTextbox) document.getElementById("datasourceName");
// $NON-NLS-1$
connections = (XulListbox) document.getElementById("connectionList");
// $NON-NLS-1$
query = (XulTextbox) document.getElementById("query");
// $NON-NLS-1$
connectionDialog = (XulDialog) document.getElementById("connectionDialog");
// $NON-NLS-1$
previewResultsDialog = (XulDialog) document.getElementById("previewResultsDialog");
// $NON-NLS-1$
previewResultsTable = (XulTree) document.getElementById("previewResultsTable");
// $NON-NLS-1$
previewResultsTreeCols = (XulTreeCols) document.getElementById("previewResultsTreeCols");
// $NON-NLS-1$
previewLimit = (XulTextbox) document.getElementById("previewLimit");
// $NON-NLS-1$
editConnectionButton = (XulButton) document.getElementById("editConnection");
// $NON-NLS-1$
removeConnectionButton = (XulButton) document.getElementById("removeConnection");
// $NON-NLS-1$
editQueryButton = (XulButton) document.getElementById("editQuery");
// $NON-NLS-1$
previewButton = (XulButton) document.getElementById("preview");
bf.setBindingType(Binding.Type.ONE_WAY);
bf.createBinding(datasourceModel.getGuiStateModel(), "relationalPreviewValidated", previewButton, // $NON-NLS-1$ //$NON-NLS-2$
"!disabled");
List<Binding> bindingsThatNeedInitialized = new ArrayList<Binding>();
BindingConvertor<IDatabaseConnection, Boolean> buttonConvertor = new BindingConvertor<IDatabaseConnection, Boolean>() {
@Override
public Boolean sourceToTarget(IDatabaseConnection value) {
return !(value == null);
}
@Override
public IDatabaseConnection targetToSource(Boolean value) {
return null;
}
};
bf.setBindingType(Binding.Type.ONE_WAY);
final Binding domainBinding = bf.createBinding(datasourceModel.getGuiStateModel(), "connections", this, // $NON-NLS-1$ //$NON-NLS-2$
"relationalConnections");
// $NON-NLS-1$
bf.createBinding(this, connectionNamesListProp, connections, "elements");
bf.createBinding(datasourceModel, "selectedRelationalConnection", editConnectionButton, "!disabled", // $NON-NLS-1$ //$NON-NLS-2$
buttonConvertor);
bf.createBinding(datasourceModel, "selectedRelationalConnection", removeConnectionButton, "!disabled", // $NON-NLS-1$ //$NON-NLS-2$
buttonConvertor);
bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
bf.createBinding(datasourceModel, "selectedRelationalConnection", connections, "selectedIndex", new // $NON-NLS-1$ //$NON-NLS-2$
BindingConvertor<IDatabaseConnection, Integer>() {
@Override
public Integer sourceToTarget(IDatabaseConnection connection) {
if (connection != null) {
return datasourceModel.getGuiStateModel().getConnectionIndex(connection);
}
return -1;
}
@Override
public IDatabaseConnection targetToSource(Integer value) {
if (value >= 0) {
return datasourceModel.getGuiStateModel().getConnections().get(value);
}
return null;
}
});
bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
bf.createBinding(datasourceModel.getGuiStateModel(), "previewLimit", previewLimit, // $NON-NLS-1$ //$NON-NLS-2$
"value");
// $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(datasourceModel, "query", query, "value");
try {
// Fires the population of the model listbox. This cascades down to the categories and columns. In essence, this
// call initializes the entire UI.
domainBinding.fireSourceChanged();
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
for (Binding b : bindingsThatNeedInitialized) {
try {
b.fireSourceChanged();
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class JdbcDatasourceResourceTest method testGetConnection.
@Test
public void testGetConnection() throws Exception {
IDatabaseConnection mockIDatabaseConnection = mock(IDatabaseConnection.class);
doReturn(mockIDatabaseConnection).when(jdbcDatasourceResource.service).getConnectionByName("Name");
Response mockResponse = mock(Response.class);
doReturn(mockResponse).when(jdbcDatasourceResource).buildOkResponse(mockIDatabaseConnection);
Response response = jdbcDatasourceResource.getConnection("Name");
verify(jdbcDatasourceResource, times(1)).getConnection("Name");
assertEquals(response, mockResponse);
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class JdbcDatasourceResourceTest method testUpdate.
@Test
public void testUpdate() throws Exception {
DatabaseConnection mockDatabaseConnection = mock(DatabaseConnection.class);
doReturn("").when(mockDatabaseConnection).getPassword();
doReturn("id").when(mockDatabaseConnection).getName();
IDatabaseConnection mockSavedConn = mock(IDatabaseConnection.class);
doReturn(mockSavedConn).when(jdbcDatasourceResource.service).getConnectionByName("id");
doReturn("password").when(mockSavedConn).getPassword();
doReturn(true).when(jdbcDatasourceResource.service).updateConnection(mockDatabaseConnection);
doNothing().when(jdbcDatasourceResource).validateAccess();
Response mockResponse = mock(Response.class);
doReturn(mockResponse).when(jdbcDatasourceResource).buildOkResponse();
Response response = jdbcDatasourceResource.addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
verify(jdbcDatasourceResource, times(1)).addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
assertEquals(response, mockResponse);
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class TablesSelectionStep method refresh.
@Override
public void refresh() {
IDatabaseConnection connection = ((MultiTableDatasource) parentDatasource).getConnection();
joinSelectionServiceGwtImpl.retrieveSchemas(connection, new XulServiceCallback<List>() {
public void error(String message, Throwable error) {
error.printStackTrace();
mtdatasource.displayErrors(new JoinError(message, error.getMessage()));
}
public void success(List schemaValues) {
schemas.removePropertyChangeListener(schemaSelection);
joinGuiModel.setSchemas(schemaValues);
schemas.addPropertyChangeListener(schemaSelection);
fetchTables();
}
});
}
Aggregations