Search in sources :

Example 41 with RequestException

use of com.google.gwt.http.client.RequestException in project pentaho-platform by pentaho.

the class SchedulesPanel method editJob.

private void editJob(final JsJob editJob) {
    final String jobId = editJob.getJobId();
    final String apiEndpoint = "api/scheduler/jobinfo?jobId=" + URL.encodeQueryString(jobId);
    RequestBuilder executableTypesRequestBuilder = createRequestBuilder(RequestBuilder.GET, apiEndpoint);
    executableTypesRequestBuilder.setHeader(HTTP_ACCEPT_HEADER, JSON_CONTENT_TYPE);
    try {
        executableTypesRequestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            // showError(exception);
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    final JsJob jsJob = parseJsonJob(JsonUtils.escapeJsonForEval(response.getText()));
                    // check email is setup
                    final String checkEmailEndpoint = "api/emailconfig/isValid";
                    RequestBuilder emailValidRequest = createRequestBuilder(RequestBuilder.GET, checkEmailEndpoint);
                    emailValidRequest.setHeader("accept", "text/plain");
                    try {
                        emailValidRequest.sendRequest(null, new RequestCallback() {

                            public void onError(Request request, Throwable exception) {
                                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), exception.toString(), false, false, true);
                                dialogBox.center();
                            }

                            public void onResponseReceived(Request request, Response response) {
                                if (response.getStatusCode() == Response.SC_OK) {
                                    final boolean isEmailConfValid = Boolean.parseBoolean(response.getText());
                                    final NewScheduleDialog scheduleDialog = new NewScheduleDialog(jsJob, scheduleDialogCallback, isEmailConfValid);
                                    scheduleDialog.center();
                                }
                            }
                        });
                    } catch (RequestException e) {
                    // showError(e);
                    }
                } else {
                    String message = Messages.getString("serverErrorColon") + " " + response.getStatusCode();
                    MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), message, false, false, true);
                    dialogBox.center();
                }
            }
        });
    } catch (RequestException e) {
    // showError(e);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) EmptyRequestCallback(org.pentaho.mantle.client.EmptyRequestCallback) RequestCallback(com.google.gwt.http.client.RequestCallback) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) Request(com.google.gwt.http.client.Request) JSONString(com.google.gwt.json.client.JSONString) RequestException(com.google.gwt.http.client.RequestException) NewScheduleDialog(org.pentaho.mantle.client.dialogs.scheduling.NewScheduleDialog)

Example 42 with RequestException

use of com.google.gwt.http.client.RequestException in project pentaho-platform by pentaho.

the class MantleController method init.

/**
 * Called when the Xul Dom is ready, grab all Xul references here.
 */
@Bindable
public void init() {
    // $NON-NLS-1$
    openBtn = (XulToolbarbutton) document.getElementById("openButton");
    // $NON-NLS-1$
    newBtn = (XulToolbarbutton) document.getElementById("newButton");
    // $NON-NLS-1$
    saveBtn = (XulToolbarbutton) document.getElementById("saveButton");
    // $NON-NLS-1$
    saveAsBtn = (XulToolbarbutton) document.getElementById("saveAsButton");
    printBtn = (XulToolbarbutton) document.getElementById("printButton");
    // $NON-NLS-1$
    contentEditBtn = (XulToolbarbutton) document.getElementById("editContentButton");
    bf = new GwtBindingFactory(document);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(model, "saveEnabled", saveBtn, "visible");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(model, "saveAsEnabled", saveAsBtn, "visible");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(model, "contentEditEnabled", contentEditBtn, "visible");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(model, "contentEditSelected", this, "editContentSelected");
    bf.createBinding(model, "printVisible", printBtn, "visible");
    // $NON-NLS-1$
    saveMenuItem = (XulMenuitem) document.getElementById("saveMenuItem");
    // $NON-NLS-1$
    saveAsMenuItem = (XulMenuitem) document.getElementById("saveAsMenuItem");
    // $NON-NLS-1$
    useDescriptionsMenuItem = (XulMenuitem) document.getElementById("useDescriptionsMenuItem");
    // $NON-NLS-1$
    showHiddenFilesMenuItem = (XulMenuitem) document.getElementById("showHiddenFilesMenuItem");
    // $NON-NLS-1$
    languageMenu = (XulMenubar) document.getElementById("languagemenu");
    // $NON-NLS-1$
    themesMenu = (XulMenubar) document.getElementById("themesmenu");
    // $NON-NLS-1$
    toolsMenu = (XulMenubar) document.getElementById("toolsmenu");
    // $NON-NLS-1$
    recentMenu = (XulMenubar) document.getElementById("recentmenu");
    // $NON-NLS-1$
    favoriteMenu = (XulMenubar) document.getElementById("favoritesmenu");
    if (PerspectiveManager.getInstance().isLoaded()) {
        PerspectiveManager.getInstance().enablePerspective(PerspectiveManager.OPENED_PERSPECTIVE, false);
    } else {
        EventBusUtil.EVENT_BUS.addHandler(PerspectivesLoadedEvent.TYPE, new PerspectivesLoadedEventHandler() {

            public void onPerspectivesLoaded(PerspectivesLoadedEvent event) {
                PerspectiveManager.getInstance().enablePerspective(PerspectiveManager.OPENED_PERSPECTIVE, false);
            }
        });
    }
    // install language sub-menus
    ResourceBundle resourceBundle = Messages.getResourceBundle();
    Map<String, String> supportedLanguages = resourceBundle.getSupportedLanguages();
    if (supportedLanguages != null && !supportedLanguages.isEmpty()) {
        String currentLanguage = resourceBundle.getLanguage();
        MenuBar langMenu = (MenuBar) languageMenu.getManagedObject();
        langMenu.insertSeparator(0);
        for (String lang : supportedLanguages.keySet()) {
            CheckBoxMenuItem langMenuItem = new CheckBoxMenuItem(supportedLanguages.get(lang), new SwitchLocaleCommand(lang));
            langMenuItem.getElement().setId(supportedLanguages.get(lang) + "_menu_item");
            langMenuItem.setChecked(lang.equalsIgnoreCase(currentLanguage));
            langMenu.insertItem(langMenuItem, 0);
        }
    }
    buildFavoritesAndRecent(false);
    UserSettingsManager.getInstance().getUserSettings(new AsyncCallback<JsArray<JsSetting>>() {

        public void onSuccess(JsArray<JsSetting> settings) {
            processSettings(settings);
        }

        public void onFailure(Throwable caught) {
        }
    }, false);
    EventBusUtil.EVENT_BUS.addHandler(UserSettingsLoadedEvent.TYPE, new UserSettingsLoadedEventHandler() {

        public void onUserSettingsLoaded(UserSettingsLoadedEvent event) {
            processSettings(event.getSettings());
        }
    });
    // install themes
    RequestBuilder getActiveThemeRequestBuilder = // $NON-NLS-1$
    new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "api/theme/active");
    try {
        getActiveThemeRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        getActiveThemeRequestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            // showError(exception);
            }

            public void onResponseReceived(Request request, Response response) {
                final String activeTheme = response.getText();
                RequestBuilder getThemesRequestBuilder = // $NON-NLS-1$
                new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "api/theme/list");
                getThemesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                // $NON-NLS-1$ //$NON-NLS-2$
                getThemesRequestBuilder.setHeader(HTTP_REQUEST_ACCEPT_HEADER, JSON_REQUEST_HEADER);
                try {
                    getThemesRequestBuilder.sendRequest(null, new RequestCallback() {

                        public void onError(Request arg0, Throwable arg1) {
                        }

                        public void onResponseReceived(Request request, Response response) {
                            try {
                                // $NON-NLS-1$
                                final String url = GWT.getHostPageBaseURL() + "api/repo/files/canAdminister";
                                RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
                                requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                                // $NON-NLS-1$ //$NON-NLS-2$
                                requestBuilder.setHeader(HTTP_REQUEST_ACCEPT_HEADER, "text/plain");
                                requestBuilder.sendRequest(null, new RequestCallback() {

                                    public void onError(Request request, Throwable caught) {
                                    }

                                    public void onResponseReceived(Request request, Response response) {
                                        // $NON-NLS-1$
                                        toolsMenu.setVisible("true".equalsIgnoreCase(response.getText()));
                                        // $NON-NLS-1$
                                        showHiddenFilesMenuItem.setVisible("true".equalsIgnoreCase(response.getText()));
                                    }
                                });
                            } catch (RequestException e) {
                                Window.alert(e.getMessage());
                            }
                            JsArray<JsTheme> themes = JsTheme.getThemes(JsonUtils.escapeJsonForEval(response.getText()));
                            for (int i = 0; i < themes.length(); i++) {
                                JsTheme theme = themes.get(i);
                                PentahoMenuItem themeMenuItem = new PentahoMenuItem(theme.getName(), new SwitchThemeCommand(theme.getId()));
                                // $NON-NLS-1$
                                themeMenuItem.getElement().setId(theme.getId() + "_menu_item");
                                themeMenuItem.setChecked(theme.getId().equals(activeTheme));
                                ((MenuBar) themesMenu.getManagedObject()).addItem(themeMenuItem);
                            }
                            // $NON-NLS-1$ //$NON-NLS-2$
                            bf.createBinding(model, "saveEnabled", saveMenuItem, "!disabled");
                            // $NON-NLS-1$ //$NON-NLS-2$
                            bf.createBinding(model, "saveAsEnabled", saveAsMenuItem, "!disabled");
                            if (PerspectiveManager.getInstance().isLoaded()) {
                                executeAdminContent();
                            } else {
                                EventBusUtil.EVENT_BUS.addHandler(PerspectivesLoadedEvent.TYPE, new PerspectivesLoadedEventHandler() {

                                    public void onPerspectivesLoaded(PerspectivesLoadedEvent event) {
                                        executeAdminContent();
                                    }
                                });
                            }
                            setupNativeHooks(MantleController.this);
                        }
                    });
                } catch (RequestException e) {
                // showError(e);
                }
            }
        });
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    // showError(e);
    }
}
Also used : PentahoMenuItem(org.pentaho.gwt.widgets.client.menuitem.PentahoMenuItem) CheckBoxMenuItem(org.pentaho.gwt.widgets.client.menuitem.CheckBoxMenuItem) RequestBuilder(com.google.gwt.http.client.RequestBuilder) UserSettingsLoadedEvent(org.pentaho.mantle.client.events.UserSettingsLoadedEvent) MenuBar(com.google.gwt.user.client.ui.MenuBar) RequestException(com.google.gwt.http.client.RequestException) SwitchLocaleCommand(org.pentaho.mantle.client.commands.SwitchLocaleCommand) UserSettingsLoadedEventHandler(org.pentaho.mantle.client.events.UserSettingsLoadedEventHandler) JsSetting(org.pentaho.mantle.client.usersettings.JsSetting) JsArray(com.google.gwt.core.client.JsArray) PerspectivesLoadedEventHandler(org.pentaho.mantle.client.events.PerspectivesLoadedEventHandler) Request(com.google.gwt.http.client.Request) Response(com.google.gwt.http.client.Response) SwitchThemeCommand(org.pentaho.mantle.client.commands.SwitchThemeCommand) PerspectivesLoadedEvent(org.pentaho.mantle.client.events.PerspectivesLoadedEvent) RequestCallback(com.google.gwt.http.client.RequestCallback) GwtBindingFactory(org.pentaho.ui.xul.gwt.binding.GwtBindingFactory) ResourceBundle(org.pentaho.gwt.widgets.client.utils.i18n.ResourceBundle) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 43 with RequestException

use of com.google.gwt.http.client.RequestException 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();
}
Also used : JsArray(com.google.gwt.core.client.JsArray) RequestBuilder(com.google.gwt.http.client.RequestBuilder) AbstractCommand(org.pentaho.mantle.client.commands.AbstractCommand) Request(com.google.gwt.http.client.Request) ArrayList(java.util.ArrayList) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) XulOverlay(org.pentaho.ui.xul.XulOverlay) MantleXulOverlay(org.pentaho.mantle.client.objects.MantleXulOverlay) RequestCallback(com.google.gwt.http.client.RequestCallback) MantleXulOverlay(org.pentaho.mantle.client.objects.MantleXulOverlay)

Example 44 with RequestException

use of com.google.gwt.http.client.RequestException in project pentaho-platform by pentaho.

the class UserSettingsManager method getUserSettings.

private void getUserSettings(final AsyncCallback<JsArray<JsSetting>> callback) {
    // $NON-NLS-1$
    final String url = GWT.getHostPageBaseURL() + "api/user-settings/list";
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    builder.setHeader("accept", "application/json");
    builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        builder.sendRequest(null, 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
                }
                // CHECKSTYLE IGNORE Indentation FOR NEXT 1 LINES
                getInstance().settings = jsSettings;
                if (callback != null) {
                    callback.onSuccess(settings);
                }
                EventBusUtil.EVENT_BUS.fireEvent(new UserSettingsLoadedEvent(settings));
            }
        });
    } catch (RequestException e) {
    // showError(e);
    }
}
Also used : Response(com.google.gwt.http.client.Response) JsArray(com.google.gwt.core.client.JsArray) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) UserSettingsLoadedEvent(org.pentaho.mantle.client.events.UserSettingsLoadedEvent) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Example 45 with RequestException

use of com.google.gwt.http.client.RequestException in project pentaho-platform by pentaho.

the class MantleController method updatePassword.

public void updatePassword(String user, String newPassword, String oldPassword, final ServiceCallback callback) {
    String userName = user;
    String serviceUrl = GWT.getHostPageBaseURL() + "api/userroledao/user";
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.PUT, serviceUrl);
    try {
        executableTypesRequestBuilder.setHeader(HTTP_REQUEST_ACCEPT_HEADER, JSON_REQUEST_HEADER);
        executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        executableTypesRequestBuilder.setHeader("Content-Type", JSON_REQUEST_HEADER);
        String json = "{\"userName\": \"" + encodeUri(userName) + "\", \"newPassword\": \"ENC:" + b64encode(newPassword) + "\", \"oldPassword\": \"ENC:" + b64encode(oldPassword) + "\"}";
        executableTypesRequestBuilder.sendRequest(json, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                handleCallbackError(callback, false, "");
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() != Response.SC_NO_CONTENT) {
                    handleCallbackError(callback, false, response.getHeader(PUC_VALIDATION_ERROR_MESSAGE));
                } else {
                    callback.serviceResult(true);
                }
            }
        });
    } catch (RequestException e) {
        showXulErrorMessage(Messages.getString(CHANGE_PASS_ERROR_TITLE), Messages.getString(CHANGE_PASS_ERROR_MESSAGE));
        callback.serviceResult(false);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Aggregations

RequestException (com.google.gwt.http.client.RequestException)164 RequestCallback (com.google.gwt.http.client.RequestCallback)154 Response (com.google.gwt.http.client.Response)153 Request (com.google.gwt.http.client.Request)152 RequestBuilder (com.google.gwt.http.client.RequestBuilder)108 JSONException (com.google.gwt.json.client.JSONException)55 HttpException (com.willshex.gson.web.service.client.HttpException)55 CsrfRequestBuilder (org.pentaho.mantle.client.csrf.CsrfRequestBuilder)17 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)16 BlockUsersRequest (com.willshex.blogwt.shared.api.user.call.BlockUsersRequest)12 BlockUsersResponse (com.willshex.blogwt.shared.api.user.call.BlockUsersResponse)12 ChangePasswordRequest (com.willshex.blogwt.shared.api.user.call.ChangePasswordRequest)12 ChangePasswordResponse (com.willshex.blogwt.shared.api.user.call.ChangePasswordResponse)12 ChangeUserAccessRequest (com.willshex.blogwt.shared.api.user.call.ChangeUserAccessRequest)12 ChangeUserAccessResponse (com.willshex.blogwt.shared.api.user.call.ChangeUserAccessResponse)12 ChangeUserDetailsRequest (com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsRequest)12 ChangeUserDetailsResponse (com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsResponse)12 CheckUsernameRequest (com.willshex.blogwt.shared.api.user.call.CheckUsernameRequest)12 CheckUsernameResponse (com.willshex.blogwt.shared.api.user.call.CheckUsernameResponse)12 FollowUsersRequest (com.willshex.blogwt.shared.api.user.call.FollowUsersRequest)12