use of com.google.gwt.http.client.Response in project pentaho-platform by pentaho.
the class MantleXul method fetchPluginOverlays.
private void fetchPluginOverlays() {
AbstractCommand cmd = new AbstractCommand() {
protected void performOperation(boolean feedback) {
performOperation();
}
protected void performOperation() {
// $NON-NLS-1$
final String url = GWT.getHostPageBaseURL() + "api/plugin-manager/overlays";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
builder.setHeader("accept", "application/json");
try {
builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
Window.alert(exception.getMessage());
}
public void onResponseReceived(Request request, Response response) {
JsArray<JsXulOverlay> jsoverlays = JsXulOverlay.parseJson(JsonUtils.escapeJsonForEval(response.getText()));
ArrayList<XulOverlay> overlays = new ArrayList<XulOverlay>();
for (int i = 0; i < jsoverlays.length(); i++) {
JsXulOverlay o = jsoverlays.get(i);
MantleXulOverlay overlay;
overlay = new MantleXulOverlay(o.getId(), o.getOverlayUri(), o.getSource(), o.getResourceBundleUri(), Integer.parseInt(o.getPriority()));
overlays.add(overlay);
}
MantleXul.this.addOverlays(overlays);
// $NON-NLS-1$
final String url = GWT.getHostPageBaseURL() + "plugin/data-access/api/permissions/hasDataAccess";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
builder.setHeader("accept", "application/json");
try {
builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
Window.alert(exception.getMessage());
}
public void onResponseReceived(Request request, Response response) {
if (response.getText().equals("true")) {
controller.loadOverlay("dataaccess");
}
}
});
} catch (RequestException e) {
// showError(e);
}
}
});
} catch (RequestException e) {
// showError(e);
}
}
};
cmd.execute();
}
use of com.google.gwt.http.client.Response in project activityinfo by bedatadriven.
the class AttachmentWidget method checkBlobExistance.
public void checkBlobExistance() {
try {
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uploader.getBaseUrl() + "/exists");
requestBuilder.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() == Response.SC_OK) {
addNewRow(uploader.getAttachment());
setState(true);
fireValueChanged();
} else {
LOGGER.severe("Failed to fetch attachment serving url. Status code is not ok. ");
setState(false);
}
}
@Override
public void onError(Request request, Throwable exception) {
LOGGER.log(Level.SEVERE, "Failed to fetch attachment serving url. ", exception);
setState(false);
}
});
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to send request for fetching serving url. ", e);
setState(false);
}
}
use of com.google.gwt.http.client.Response in project data-access by pentaho.
the class GwtDatasourceEditorEntryPoint method showEditDatabaseDialog.
public void showEditDatabaseDialog(final DialogListener dialogListener, final String databaseName) {
String cacheBuster = String.valueOf(new java.util.Date().getTime());
String url = ConnectionController.getServiceURL("get", new String[][] { { "name", databaseName }, { "ts", cacheBuster } });
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
builder.setHeader("Accept", "application/json");
try {
builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
Window.alert(exception.toString());
}
@SuppressWarnings("deprecation")
public void onResponseReceived(Request request, Response response) {
IDatabaseConnection conn = null;
if (response.getStatusCode() == Response.SC_OK) {
AutoBean<IDatabaseConnection> bean = AutoBeanCodex.decode(connectionAutoBeanFactory, IDatabaseConnection.class, response.getText());
conn = bean.as();
}
ConnectionController connectionController = wizard.getConnectionController();
connectionController.init();
DatasourceModel datasourceModel = connectionController.getDatasourceModel();
if (datasourceModel == null) {
datasourceModel = new DatasourceModel();
}
datasourceModel.setSelectedRelationalConnection(conn);
// This is important for edit mode of datasource model
datasourceModel.setEditing(true);
connectionController.setDatasourceModel(datasourceModel);
connectionController.showEditConnectionDialog(dialogListener, conn);
}
});
} catch (Exception e) {
Window.alert("Cannot edit datasource");
}
}
use of com.google.gwt.http.client.Response in project data-access by pentaho.
the class MetadataImportDialogController method createSubmitCompleteHandler.
private SubmitCompleteHandler createSubmitCompleteHandler() {
return new SubmitCompleteHandler() {
@Override
public void onSubmitComplete(SubmitCompleteEvent event) {
// delete all surrounded tags
final String jsonResponseText = new HTML(event.getResults()).getText();
final JSONObject jsonResponse;
JSONValue jsonVal = JSONParser.parseStrict(jsonResponseText);
if (jsonVal != null) {
jsonResponse = jsonVal.isObject();
} else {
jsonResponse = null;
}
if (jsonResponse == null) {
onImportError("wrong data from xmi file checker");
return;
}
String tempFileName = jsonResponse.get("xmiFileName").isString().stringValue();
RequestBuilder checkFileRequest = new RequestBuilder(RequestBuilder.GET, METADATA_CHECK_URL + "?tempFileName=" + URL.encode(tempFileName));
checkFileRequest.setCallback(new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() == HttpStatus.SC_OK) {
if (Boolean.TRUE.toString().equalsIgnoreCase(response.getText())) {
promptImportMetadata(resBundle.getString("importDialog.IMPORT_METADATA"), resBundle.getString("importDialog.CONFIRMATION_LOAD_DSW"), resBundle.getString("importDialog.DIALOG_DSW_RADIO", "Data Source Wizard (Includes Analysis model)"), resBundle.getString("importDialog.DIALOG_METADATA_RADIO", "Metadata model"), new AsyncCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
new XmiImporterRequest((Boolean) result ? METADATA_IMPORT_DSW_URL : METADATA_IMPORT_XMI_URL, jsonResponse).doImport(false);
}
@Override
public void onFailure(Throwable caught) {
onImportError(caught.getMessage());
}
});
} else if (Boolean.FALSE.toString().equals(response.getText())) {
new XmiImporterRequest(METADATA_IMPORT_XMI_URL, jsonResponse).doImport(false);
} else {
onImportError("wrong data from xmi file checker");
}
} else {
onImportError("[server data error] , wrong code: " + response.getStatusCode());
}
}
@Override
public void onError(Request request, Throwable exception) {
onImportError("[request error] " + exception.getMessage());
}
});
try {
checkFileRequest.send();
} catch (RequestException e) {
onImportError(e.getMessage());
}
}
};
}
use of com.google.gwt.http.client.Response in project data-access by pentaho.
the class ConnectionController 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 = 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) {
datasourceModel.getGuiStateModel().addConnection(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_0001_UNABLE_TO_ADD_CONNECTION"));
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
}
Aggregations