use of com.google.gwt.http.client.Response in project data-access by pentaho.
the class ConnectionController method overwriteCheck.
@Bindable
public void overwriteCheck() {
if (!saveConnectionConfirmationDialog.isHidden()) {
closeSaveConnectionConfirmationDialog();
}
if (!renameConnectionConfirmationDialog.isHidden()) {
closeRenameConnectionConfirmationDialog();
}
if (datasourceModel.isEditing() && previousConnectionName.equals(currentConnection.getName())) {
// if editing and no name change, proceed.
updateConnection();
} else {
// either new connection, or editing involved a name change.
RequestBuilder checkConnectionBuilder = new RequestBuilder(RequestBuilder.GET, getServiceURL("getid", new String[][] { { "name", currentConnection.getName() } }));
checkConnectionBuilder.setHeader("Content-Type", "application/json");
try {
checkConnectionBuilder.sendRequest(null, new RequestCallback() {
public void onResponseReceived(Request request, Response response) {
switch(response.getStatusCode()) {
case Response.SC_OK:
existingConnectionId = response.getText();
showOverwriteConnectionConfirmationDialog();
break;
case Response.SC_NOT_FOUND:
saveConnection();
break;
default:
// TODO: error message
saveConnection();
}
}
public void onError(Request request, Throwable exception) {
displayErrorMessage(exception);
}
});
} catch (Exception e) {
displayErrorMessage(e);
}
}
}
use of com.google.gwt.http.client.Response in project data-access by pentaho.
the class ConnectionController method deleteConnection.
@Bindable
public void deleteConnection() {
removeConfirmationDialog.hide();
RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, getServiceURL("deletebyname", new String[][] { { "name", datasourceModel.getSelectedRelationalConnection().getName() } }));
try {
deleteConnectionBuilder.sendRequest(null, 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) {
openSuccesDialog(MessageHandler.getString("SUCCESS"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.CONNECTION_DELETED"));
datasourceModel.getGuiStateModel().deleteConnection(datasourceModel.getSelectedRelationalConnection().getName());
List<IDatabaseConnection> connections = datasourceModel.getGuiStateModel().getConnections();
if (connections != null && connections.size() > 0) {
datasourceModel.setSelectedRelationalConnection(connections.get(connections.size() - 1));
} else {
datasourceModel.setSelectedRelationalConnection(null);
}
} else {
openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.ERROR_0002_UNABLE_TO_DELETE_CONNECTION"));
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
}
use of com.google.gwt.http.client.Response in project data-access by pentaho.
the class JdbcDatasourceService method remove.
/* (non-Javadoc)
* @see org.pentaho.platform.dataaccess.datasource.ui.service.IUIDatasourceAdminService#remove(org.pentaho.platform
* .dataaccess.datasource.IDatasourceInfo)
*/
@Override
public void remove(IDatasourceInfo dsInfo, Object callback) {
final XulServiceCallback<Boolean> responseCallback = (XulServiceCallback<Boolean>) callback;
RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, getBaseURL() + NameUtils.URLEncode("deletebyname?name={0}", dsInfo.getId()));
try {
deleteConnectionBuilder.sendRequest(null, new RequestCallback() {
public void onResponseReceived(Request request, Response response) {
responseCallback.success(response.getStatusCode() == Response.SC_OK);
}
public void onError(Request request, Throwable error) {
responseCallback.error(error.getLocalizedMessage(), error);
}
});
} catch (RequestException e) {
responseCallback.error(e.getLocalizedMessage(), e);
}
}
use of com.google.gwt.http.client.Response in project data-access by pentaho.
the class WizardConnectionController method handleDialogAccept.
@Bindable
public void handleDialogAccept() {
// first, test the connection
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) {
saveConnectionConfirmationDialog.show();
}
@Override
public void onResponseReceived(Request request, Response response) {
try {
if (response.getStatusCode() == Response.SC_OK) {
// test is ok, now check if we are renaming
renameCheck();
} else {
// confirm if we should continu saving this invalid connection.
saveConnectionConfirmationDialog.show();
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
}
use of com.google.gwt.http.client.Response in project data-access by pentaho.
the class WizardConnectionController method addConnection.
@Bindable
public void addConnection() {
RequestBuilder addConnectionBuilder = new RequestBuilder(RequestBuilder.POST, ConnectionController.getServiceURL("add"));
addConnectionBuilder.setHeader("Content-Type", "application/json");
try {
// AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(currentConnection);
AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
addConnectionBuilder.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) {
IDatabaseConnection conn = AutobeanUtilities.connectionBeanToImpl(currentConnection);
datasourceModel.getGuiStateModel().addConnection(conn);
datasourceModel.setSelectedRelationalConnection(conn);
} else {
openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.ERROR_0001_UNABLE_TO_ADD_CONNECTION"));
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
}
Aggregations