Search in sources :

Example 1 with MantleSettingsLoadedEvent

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());
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) RequestBuilder(com.google.gwt.http.client.RequestBuilder) Request(com.google.gwt.http.client.Request) MantleSettingsLoadedEvent(org.pentaho.mantle.client.events.MantleSettingsLoadedEvent) RequestException(com.google.gwt.http.client.RequestException)

Aggregations

Request (com.google.gwt.http.client.Request)1 RequestBuilder (com.google.gwt.http.client.RequestBuilder)1 RequestCallback (com.google.gwt.http.client.RequestCallback)1 RequestException (com.google.gwt.http.client.RequestException)1 Response (com.google.gwt.http.client.Response)1 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)1 MantleSettingsLoadedEvent (org.pentaho.mantle.client.events.MantleSettingsLoadedEvent)1