use of com.google.gwt.http.client.RequestBuilder in project data-access by pentaho.
the class WizardConnectionController method deleteConnection.
@Bindable
public void deleteConnection() {
removeConfirmationDialog.hide();
RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, ConnectionController.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.RequestBuilder 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 com.google.gwt.http.client.RequestBuilder in project data-access by pentaho.
the class AnalysisImportDialogController method reloadConnections.
private void reloadConnections() {
String cacheBuster = "?ts=" + new java.util.Date().getTime();
RequestBuilder listConnectionBuilder = new RequestBuilder(RequestBuilder.GET, getBaseURL() + "list" + cacheBuster);
listConnectionBuilder.setHeader("Content-Type", "application/json");
listConnectionBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
try {
listConnectionBuilder.sendRequest(null, new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
exception.printStackTrace();
MessageHandler.getInstance().showErrorDialog(exception.getMessage());
}
@Override
public void onResponseReceived(Request request, Response response) {
AutoBean<IDatabaseConnectionList> bean = AutoBeanCodex.decode(connectionAutoBeanFactory, IDatabaseConnectionList.class, response.getText());
List<IDatabaseConnection> databaseConnections = bean.as().getDatabaseConnections();
List<IDatabaseConnection> standardDatabaseConnections = new ArrayList();
// take anything except connections where STANDARD_CONNECTION == false
for (IDatabaseConnection databaseConnection : databaseConnections) {
if ((databaseConnection.getAttributes() == null) || (databaseConnection.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == null) || (databaseConnection.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == Boolean.TRUE.toString())) {
standardDatabaseConnections.add(databaseConnection);
}
}
importDialogModel.setConnectionList(standardDatabaseConnections);
}
});
} catch (RequestException e) {
MessageHandler.getInstance().showErrorDialog(MessageHandler.getString("ERROR"), "DatasourceEditor.ERROR_0004_CONNECTION_SERVICE_NULL");
}
}
use of com.google.gwt.http.client.RequestBuilder in project data-access by pentaho.
the class AnalysisImportDialogController method editDatasource.
public void editDatasource(final IDatasourceInfo datasourceInfo) {
this.datasourceInfo = datasourceInfo;
boolean isEditMode = datasourceInfo != null;
// MONDRIAN-1731 uploadAnalysisButton.setDisabled(isEditMode);
acceptButton.setLabel(isEditMode ? resBundle.getString("importDialog.SAVE") : resBundle.getString("importDialog.IMPORT"));
if (!isEditMode) {
return;
}
String url = GWT.getModuleBaseURL();
int indexOfContent = url.indexOf("content");
if (indexOfContent > -1) {
url = url.substring(0, indexOfContent);
url = url + "plugin/data-access/api/datasource/" + NameUtils.URLEncode(datasourceInfo.getId()) + "/getAnalysisDatasourceInfo";
}
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
try {
requestBuilder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable e) {
logger.log(Level.ALL, e.getMessage());
}
public void onResponseReceived(Request request, final Response response) {
boolean paramHandled, hasParameters = false;
String responseValue = response.getText();
StringBuilder name = new StringBuilder();
StringBuilder value = new StringBuilder();
int state = 0;
char ch;
int i, len = responseValue.length();
for (i = 0; i < len; i++) {
ch = responseValue.charAt(i);
switch(state) {
case // new name/value pair
0:
paramHandled = handleParam(name, value);
if (!hasParameters) {
hasParameters = paramHandled;
}
switch(ch) {
case ';':
break;
default:
state = 1;
name.append(ch);
}
break;
case // looking for equals
1:
switch(ch) {
case '=':
state = 2;
break;
default:
name.append(ch);
}
break;
case // about to parse the value
2:
switch(ch) {
case '"':
state = 3;
break;
case ';':
state = 0;
break;
default:
value.append(ch);
state = 4;
}
break;
case // parse value till closing quote.
3:
switch(ch) {
case '"':
state = 0;
break;
default:
value.append(ch);
}
break;
case 4:
switch(ch) {
case ';':
state = 0;
break;
default:
value.append(ch);
}
break;
default:
}
}
paramHandled = handleParam(name, value);
if (!hasParameters) {
hasParameters = paramHandled;
}
schemaNameLabel.setValue(datasourceInfo.getId() + ".mondrian.xml");
importDialogModel.setUploadedFile(datasourceInfo.getId());
int preference;
XulRadio radio;
if (hasParameters) {
preference = PARAMETER_MODE;
radio = manualRadio;
} else {
preference = DATASOURCE_MODE;
radio = availableRadio;
}
setPreference(preference);
radio.setSelected(true);
}
});
} catch (Exception e) {
logger.log(Level.ALL, e.getMessage());
}
}
use of com.google.gwt.http.client.RequestBuilder in project data-access by pentaho.
the class DatasourceServiceManagerGwtImpl method remove.
/* (non-Javadoc)
* @see org.pentaho.platform.dataaccess.datasource.wizard.service.IXulAsyncDatasourceServiceManager#remove(org
* .pentaho.platform.dataaccess.datasource.IDatasourceInfo)
*/
@Override
public void remove(IDatasourceInfo dsInfo, final Object xulCallback) {
final String removeURL;
String datasourceId = NameUtils.URLEncode(dsInfo.getId());
if (dsInfo.getType() == MetadataUIDatasourceService.TYPE) {
removeURL = getWebAppRoot() + "plugin/data-access/api/datasource/metadata/" + datasourceId + "/remove";
} else if (dsInfo.getType() == MondrianUIDatasourceService.TYPE) {
removeURL = getWebAppRoot() + "plugin/data-access/api/datasource/analysis/" + datasourceId + "/remove";
} else if (dsInfo.getType() == DSWUIDatasourceService.TYPE) {
removeURL = getWebAppRoot() + "plugin/data-access/api/datasource/dsw/" + datasourceId + "/remove";
} else {
removeURL = null;
}
AuthenticatedGwtServiceUtil.invokeCommand(new IAuthenticatedGwtCommand<Boolean>() {
public void execute(final AsyncCallback<Boolean> callback) {
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, removeURL);
try {
requestBuilder.sendRequest(null, new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
callback.onFailure(exception);
}
@Override
public void onResponseReceived(Request request, Response response) {
callback.onSuccess(response.getStatusCode() == Response.SC_OK);
}
});
} catch (RequestException e) {
XulServiceCallback<Boolean> responseCallback = (XulServiceCallback<Boolean>) xulCallback;
responseCallback.error(e.getLocalizedMessage(), e);
}
}
}, new AsyncCallback<Boolean>() {
public void onFailure(Throwable e) {
XulServiceCallback<Boolean> responseCallback = (XulServiceCallback<Boolean>) xulCallback;
responseCallback.error(e.getLocalizedMessage(), e);
}
public void onSuccess(Boolean arg) {
XulServiceCallback<Boolean> responseCallback = (XulServiceCallback<Boolean>) xulCallback;
responseCallback.success(arg);
}
});
}
Aggregations