use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class ConnectionController method testConnection.
@Bindable
public void testConnection() {
RequestBuilder testConnectionBuilder = new RequestBuilder(RequestBuilder.PUT, getServiceURL("test"));
testConnectionBuilder.setHeader("Content-Type", "application/json");
try {
AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(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 ConnectionController method updateConnection.
@Bindable
public void updateConnection() {
RequestBuilder updateConnectionBuilder = new RequestBuilder(RequestBuilder.POST, ConnectionController.getServiceURL("update"));
updateConnectionBuilder.setHeader("Content-Type", "application/json");
try {
AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
updateConnectionBuilder.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) {
try {
if (response.getStatusCode() == Response.SC_OK) {
datasourceModel.getGuiStateModel().updateConnection(existingConnectionName, currentConnection);
datasourceModel.setSelectedRelationalConnection(currentConnection);
DialogListener dialogListener = connectionSetter.getOuterListener();
if (dialogListener != null) {
dialogListener.onDialogAccept(currentConnection);
}
} else {
openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.ERROR_0004_UNABLE_TO_UPDATE_CONNECTION"));
}
} 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 ConnectionController method reloadConnections.
public void reloadConnections() {
String cacheBuster = String.valueOf(new java.util.Date().getTime());
String[][] params = new String[][] { { "ts", cacheBuster } };
RequestBuilder listConnectionBuilder = new RequestBuilder(RequestBuilder.GET, getServiceURL("list", params));
listConnectionBuilder.setHeader("Content-Type", "application/json");
try {
listConnectionBuilder.sendRequest(null, new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
MessageHandler.getInstance().showErrorDialog(MessageHandler.getString("ERROR"), MessageHandler.getString("DatasourceEditor.ERROR_0002_UNABLE_TO_SHOW_DIALOG", exception.getLocalizedMessage()));
}
@Override
public void onResponseReceived(Request request, Response response) {
AutoBean<IDatabaseConnectionList> bean = AutoBeanCodex.decode(connectionAutoBeanFactory, IDatabaseConnectionList.class, response.getText());
List<IDatabaseConnection> connectionBeanList = bean.as().getDatabaseConnections();
List<IDatabaseConnection> connectionImplList = new ArrayList<IDatabaseConnection>();
for (IDatabaseConnection connectionBean : connectionBeanList) {
try {
// take anything except connections where STANDARD_CONNECTION == false
if ((connectionBean.getAttributes() == null) || (connectionBean.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == null) || (connectionBean.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == Boolean.TRUE.toString())) {
connectionImplList.add(AutobeanUtilities.connectionBeanToImpl(connectionBean));
}
} catch (Exception e) {
// skip invalid connections that couldn't be converted to IDatabaseConnection
}
}
if (datasourceModel != null) {
datasourceModel.getGuiStateModel().setConnections(connectionImplList);
}
}
});
} catch (RequestException e) {
MessageHandler.getInstance().showErrorDialog(MessageHandler.getString("ERROR"), "DatasourceEditor.ERROR_0004_CONNECTION_SERVICE_NULL");
}
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class DatasourceModel method clearModel.
/*
* Clears out the model
*/
public void clearModel() {
// clear the models before switching the datasource type, otherwise
// an error is presented to the user.
setQuery("");
setDatasourceName("");
guiStateModel.clearModel();
// BISERVER-3664: Temporary solution for IE ListBoxs not accepting -1 selectedIndex.
// Explicitly selecting the first connection object makes all browsers behave the same.
IDatabaseConnection firstConnection = guiStateModel.getConnections().size() > 0 ? guiStateModel.getConnections().get(0) : null;
setSelectedRelationalConnection(firstConnection);
modelInfo.clearModel();
guiStateModel.setDataStagingComplete(false);
setDatasourceType(DatasourceType.NONE);
validate();
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class JdbcDatasourceService method getIds.
@Override
public void getIds(final XulServiceCallback<List<IDatasourceInfo>> callback) {
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, getMetadataBaseURL() + "getDatasourcePermissions");
requestBuilder.setHeader("Content-Type", "application/json");
try {
requestBuilder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
callback.error(exception.getMessage(), exception);
}
public void onResponseReceived(Request request, Response response) {
if (response.getText().equals("EDIT")) {
String cacheBuster = "?ts=" + new java.util.Date().getTime();
RequestBuilder listConnectionBuilder = new RequestBuilder(RequestBuilder.GET, getBaseURL() + "list" + cacheBuster);
listConnectionBuilder.setHeader("Content-Type", "application/json");
try {
listConnectionBuilder.sendRequest(null, new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
callback.error(exception.getMessage(), exception);
}
@Override
public void onResponseReceived(Request request, Response response) {
AutoBean<IDatabaseConnectionList> bean = AutoBeanCodex.decode(connectionAutoBeanFactory, IDatabaseConnectionList.class, response.getText());
List<IDatabaseConnection> connections = bean.as().getDatabaseConnections();
List<IDatasourceInfo> datasourceInfos = new ArrayList<IDatasourceInfo>();
for (IDatabaseConnection connection : connections) {
// check attributes to make sure we only return "standard" connections which can be managed
Map<String, String> attributes = connection.getAttributes();
if (attributes.containsKey(ATTRIBUTE_STANDARD_CONNECTION)) {
if (attributes.get(ATTRIBUTE_STANDARD_CONNECTION).equals(Boolean.FALSE.toString())) {
continue;
}
}
datasourceInfos.add(new DatasourceInfo(connection.getName(), connection.getName(), TYPE, editable, removable, importable, exportable));
}
callback.success(datasourceInfos);
}
});
} catch (RequestException e) {
callback.error(e.getMessage(), e);
}
}
}
});
} catch (RequestException e) {
callback.error(e.getMessage(), e);
}
}
Aggregations