use of org.pentaho.mantle.client.events.MantleSettingsLoadedEvent in project pentaho-platform by pentaho.
the class MantleSettingsManager method getMantleSettings.
private void getMantleSettings(final AsyncCallback<HashMap<String, String>> callback) {
final RequestCallback internalCallback = new RequestCallback() {
public void onError(Request request, Throwable exception) {
MessageDialogBox dialog = new MessageDialogBox(Messages.getString("error"), Messages.getString("couldNotGetUserSettings"), true, false, // $NON-NLS-1$ //$NON-NLS-2$
true);
dialog.center();
}
public void onResponseReceived(Request request, Response response) {
JsArray<JsSetting> jsSettings = null;
try {
jsSettings = JsSetting.parseSettingsJson(response.getText());
} catch (Throwable t) {
// happens when there are no settings
}
for (int i = 0; i < jsSettings.length(); i++) {
settings.put(jsSettings.get(i).getName(), jsSettings.get(i).getValue());
}
settings.put("is-administrator", "" + isAdministrator);
if (callback != null) {
callback.onSuccess(settings);
}
EventBusUtil.EVENT_BUS.fireEvent(new MantleSettingsLoadedEvent(settings));
}
};
final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "api/mantle/settings");
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
builder.setHeader("accept", "application/json");
try {
// $NON-NLS-1$
final String url = GWT.getHostPageBaseURL() + "api/repo/files/canAdminister";
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
requestBuilder.setHeader("accept", "text/plain");
requestBuilder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable caught) {
try {
builder.sendRequest(null, internalCallback);
} catch (RequestException e) {
// ignored
}
// CHECKSTYLE IGNORE Indentation FOR NEXT 1 LINES
MantleSettingsManager.getInstance().isAdministrator = false;
}
public void onResponseReceived(Request request, Response response) {
try {
builder.sendRequest(null, internalCallback);
} catch (RequestException e) {
// ignored
}
// CHECKSTYLE IGNORE Indentation FOR NEXT 1 LINES
MantleSettingsManager.getInstance().isAdministrator = isAdministrator;
}
});
} catch (RequestException e) {
Window.alert(e.getMessage());
}
}
Aggregations