Search in sources :

Example 46 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
    Map<String, String> supportedLanguages = Messages.getResourceBundle().getSupportedLanguages();
    if (supportedLanguages != null && supportedLanguages.keySet() != null && !supportedLanguages.isEmpty()) {
        MenuBar langMenu = (MenuBar) languageMenu.getManagedObject();
        langMenu.insertSeparator(0);
        for (String lang : supportedLanguages.keySet()) {
            MenuItem langMenuItem = new MenuItem(supportedLanguages.get(lang), new SwitchLocaleCommand(lang));
            // $NON-NLS-1$
            langMenuItem.getElement().setId(supportedLanguages.get(lang) + "_menu_item");
            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("accept", "application/json");
                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("accept", "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) 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) MenuItem(com.google.gwt.user.client.ui.MenuItem) PentahoMenuItem(org.pentaho.gwt.widgets.client.menuitem.PentahoMenuItem) 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) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 47 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 48 with RequestException

use of com.google.gwt.http.client.RequestException 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());
            }
        }
    };
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) Request(com.google.gwt.http.client.Request) HTML(com.google.gwt.user.client.ui.HTML) SubmitCompleteEvent(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler) RequestException(com.google.gwt.http.client.RequestException) JSONValue(com.google.gwt.json.client.JSONValue) Response(com.google.gwt.http.client.Response) JSONObject(com.google.gwt.json.client.JSONObject) RequestCallback(com.google.gwt.http.client.RequestCallback)

Example 49 with RequestException

use of com.google.gwt.http.client.RequestException 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);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) DialogListener(org.pentaho.ui.xul.util.DialogController.DialogListener) ConnectionDialogListener(org.pentaho.platform.dataaccess.datasource.wizard.ConnectionDialogListener) DatabaseDialogListener(org.pentaho.ui.database.event.DatabaseDialogListener) Request(com.google.gwt.http.client.Request) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) RequestException(com.google.gwt.http.client.RequestException) RequestException(com.google.gwt.http.client.RequestException) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 50 with RequestException

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

the class ConnectionController method deleteConnection.

@Bindable
public void deleteConnection() {
    removeConfirmationDialog.hide();
    RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, 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);
    }
}
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) ArrayList(java.util.ArrayList) IDatabaseConnectionList(org.pentaho.ui.database.event.IDatabaseConnectionList) List(java.util.List) RequestException(com.google.gwt.http.client.RequestException) RequestException(com.google.gwt.http.client.RequestException) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Aggregations

RequestException (com.google.gwt.http.client.RequestException)162 RequestCallback (com.google.gwt.http.client.RequestCallback)155 Response (com.google.gwt.http.client.Response)154 Request (com.google.gwt.http.client.Request)153 RequestBuilder (com.google.gwt.http.client.RequestBuilder)106 JSONException (com.google.gwt.json.client.JSONException)55 HttpException (com.willshex.gson.web.service.client.HttpException)55 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)17 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 FollowUsersResponse (com.willshex.blogwt.shared.api.user.call.FollowUsersResponse)12