Search in sources :

Example 56 with RequestCallback

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

the class CheckForSoftwareUpdatesCommand method performOperation.

protected void performOperation(boolean feedback) {
    // $NON-NLS-1$
    final String url = GWT.getHostPageBaseURL() + "api/version/softwareUpdates";
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    requestBuilder.setHeader("accept", "text/plain");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("softwareUpdates"), Messages.getString("noUpdatesAvailable"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
                true);
                dialogBox.center();
            }

            public void onResponseReceived(Request request, Response response) {
                Document doc = XMLParser.parse(response.getText());
                // $NON-NLS-1$
                NodeList updates = doc.getElementsByTagName("update");
                if (updates.getLength() > 0) {
                    FlexTable updateTable = new FlexTable();
                    // $NON-NLS-1$
                    updateTable.setStyleName("backgroundContentTable");
                    // $NON-NLS-1$
                    updateTable.setWidget(0, 0, new Label(Messages.getString("version")));
                    // $NON-NLS-1$
                    updateTable.setWidget(0, 1, new Label(Messages.getString("type")));
                    // $NON-NLS-1$
                    updateTable.setWidget(0, 2, new Label(Messages.getString("os")));
                    // $NON-NLS-1$
                    updateTable.setWidget(0, 3, new Label(Messages.getString("link")));
                    // $NON-NLS-1$
                    updateTable.getCellFormatter().setStyleName(0, 0, "backgroundContentHeaderTableCell");
                    // $NON-NLS-1$
                    updateTable.getCellFormatter().setStyleName(0, 1, "backgroundContentHeaderTableCell");
                    // $NON-NLS-1$
                    updateTable.getCellFormatter().setStyleName(0, 2, "backgroundContentHeaderTableCell");
                    // $NON-NLS-1$
                    updateTable.getCellFormatter().setStyleName(0, 3, "backgroundContentHeaderTableCellRight");
                    for (int i = 0; i < updates.getLength(); i++) {
                        Element updateElement = (Element) updates.item(i);
                        // $NON-NLS-1$
                        String version = updateElement.getAttribute("version");
                        // $NON-NLS-1$
                        String type = updateElement.getAttribute("type");
                        // $NON-NLS-1$
                        String os = updateElement.getAttribute("os");
                        // String title = updateElement.getAttribute("title");
                        // $NON-NLS-1$
                        String downloadURL = updateElement.getElementsByTagName("downloadurl").item(0).toString();
                        // $NON-NLS-1$ //$NON-NLS-2$
                        downloadURL = downloadURL.substring(downloadURL.indexOf("http"), downloadURL.indexOf("]"));
                        updateTable.setWidget(i + 1, 0, new Label(version));
                        updateTable.setWidget(i + 1, 1, new Label(type));
                        updateTable.setWidget(i + 1, 2, new Label(os));
                        updateTable.setWidget(i + 1, 3, new HTML("<A HREF=\"" + downloadURL + "\" target=\"_blank\" title=\"" + downloadURL + "\">" + Messages.getString("download") + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                        "</A>"));
                        // $NON-NLS-1$
                        updateTable.getCellFormatter().setStyleName(i + 1, 0, "backgroundContentTableCell");
                        // $NON-NLS-1$
                        updateTable.getCellFormatter().setStyleName(i + 1, 1, "backgroundContentTableCell");
                        // $NON-NLS-1$
                        updateTable.getCellFormatter().setStyleName(i + 1, 2, "backgroundContentTableCell");
                        // $NON-NLS-1$
                        updateTable.getCellFormatter().setStyleName(i + 1, 3, "backgroundContentTableCellRight");
                        if (i == updates.getLength() - 1) {
                            // last
                            // $NON-NLS-1$
                            updateTable.getCellFormatter().setStyleName(i + 1, 0, "backgroundContentTableCellBottom");
                            // $NON-NLS-1$
                            updateTable.getCellFormatter().setStyleName(i + 1, 1, "backgroundContentTableCellBottom");
                            // $NON-NLS-1$
                            updateTable.getCellFormatter().setStyleName(i + 1, 2, "backgroundContentTableCellBottom");
                            // $NON-NLS-1$
                            updateTable.getCellFormatter().setStyleName(i + 1, 3, "backgroundContentTableCellBottomRight");
                        }
                    }
                    PromptDialogBox versionPromptDialog = new PromptDialogBox(Messages.getString("softwareUpdateAvailable"), Messages.getString("ok"), null, false, true, // $NON-NLS-1$ //$NON-NLS-2$
                    updateTable);
                    versionPromptDialog.center();
                } else {
                    MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("softwareUpdates"), Messages.getString("noUpdatesAvailable"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
                    true);
                    dialogBox.center();
                }
            }
        });
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    // showError(e);
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) PromptDialogBox(org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox) NodeList(com.google.gwt.xml.client.NodeList) Element(com.google.gwt.xml.client.Element) Request(com.google.gwt.http.client.Request) FlexTable(com.google.gwt.user.client.ui.FlexTable) Label(com.google.gwt.user.client.ui.Label) HTML(com.google.gwt.user.client.ui.HTML) Document(com.google.gwt.xml.client.Document) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback)

Example 57 with RequestCallback

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

the class ExecuteGlobalActionsCommand method performOperation.

protected void performOperation() {
    // $NON-NLS-1$
    final String url = GWT.getHostPageBaseURL() + "api/system/refresh/globalActions";
    RequestBuilder requestBuilder = new CsrfRequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("accept", "text/plain");
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("info"), Messages.getString("globalActionsExecutedSuccessfully"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
                true);
                dialogBox.center();
            }
        });
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    // 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) RequestCallback(com.google.gwt.http.client.RequestCallback) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Example 58 with RequestCallback

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

the class NewFolderCommand method performOperation.

protected void performOperation(boolean feedback) {
    final SolutionFolderActionEvent event = new SolutionFolderActionEvent();
    event.setAction(this.getClass().getName());
    final TextBox folderNameTextBox = new TextBox();
    folderNameTextBox.setTabIndex(1);
    folderNameTextBox.setVisibleLength(40);
    VerticalPanel vp = new VerticalPanel();
    // $NON-NLS-1$
    vp.add(new Label(Messages.getString("newFolderName")));
    vp.add(folderNameTextBox);
    final PromptDialogBox newFolderDialog = new PromptDialogBox(Messages.getString("newFolder"), Messages.getString("ok"), Messages.getString("cancel"), false, true, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    vp);
    newFolderDialog.setFocusWidget(folderNameTextBox);
    folderNameTextBox.setFocus(true);
    final IDialogCallback callback = new IDialogCallback() {

        public void cancelPressed() {
            newFolderDialog.hide();
        }

        public void okPressed() {
            if (!NameUtils.isValidFolderName(folderNameTextBox.getText())) {
                event.setMessage(Messages.getString("containsIllegalCharacters", folderNameTextBox.getText()));
                EventBusUtil.EVENT_BUS.fireEvent(event);
                return;
            }
            solutionPath = parentFolder.getPath() + "/" + folderNameTextBox.getText();
            // $NON-NLS-1$
            String createDirUrl = contextURL + "api/repo/dirs/" + SolutionBrowserPanel.pathToId(solutionPath);
            RequestBuilder createDirRequestBuilder = new RequestBuilder(RequestBuilder.PUT, createDirUrl);
            try {
                createDirRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                createDirRequestBuilder.sendRequest("", new RequestCallback() {

                    @Override
                    public void onError(Request createFolderRequest, Throwable exception) {
                        MessageDialogBox dialogBox = new MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
                        Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$
                        Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()), false, false, true);
                        dialogBox.center();
                        event.setMessage(Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()));
                        EventBusUtil.EVENT_BUS.fireEvent(event);
                    }

                    @Override
                    public void onResponseReceived(Request createFolderRequest, Response createFolderResponse) {
                        if (createFolderResponse.getStatusCode() == 200) {
                            NewFolderCommand.this.callback.onHandle(solutionPath);
                            new RefreshRepositoryCommand().execute(false);
                            event.setMessage("Success");
                            FileChooserDialog.setIsDirty(Boolean.TRUE);
                            setBrowseRepoDirty(Boolean.TRUE);
                            EventBusUtil.EVENT_BUS.fireEvent(event);
                        } else {
                            event.setMessage(StringUtils.isEmpty(createFolderResponse.getText()) || Messages.getString(createFolderResponse.getText()) == null ? // $NON-NLS-1$
                            Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()) : Messages.getString(createFolderResponse.getText(), folderNameTextBox.getText()));
                            EventBusUtil.EVENT_BUS.fireEvent(event);
                        }
                    }
                });
            } catch (RequestException e) {
                Window.alert(e.getLocalizedMessage());
                event.setMessage(e.getLocalizedMessage());
                EventBusUtil.EVENT_BUS.fireEvent(event);
            }
        }
    };
    newFolderDialog.setCallback(callback);
    newFolderDialog.center();
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) PromptDialogBox(org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox) SolutionFolderActionEvent(org.pentaho.mantle.client.events.SolutionFolderActionEvent) Label(com.google.gwt.user.client.ui.Label) Request(com.google.gwt.http.client.Request) TextBox(com.google.gwt.user.client.ui.TextBox) IDialogCallback(org.pentaho.gwt.widgets.client.dialogs.IDialogCallback) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) RequestCallback(com.google.gwt.http.client.RequestCallback)

Example 59 with RequestCallback

use of com.google.gwt.http.client.RequestCallback 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 60 with RequestCallback

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

the class SchedulesPanel method controlJobs.

private void controlJobs(final Set<JsJob> jobs, String function, final Method method, final boolean refreshData) {
    for (final JsJob job : jobs) {
        RequestBuilder builder = createRequestBuilder(method, "api/scheduler/" + function);
        builder.setHeader(HTTP.CONTENT_TYPE, JSON_CONTENT_TYPE);
        JSONObject startJobRequest = new JSONObject();
        startJobRequest.put("jobId", new JSONString(job.getJobId()));
        try {
            builder.sendRequest(startJobRequest.toString(), new RequestCallback() {

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

                public void onResponseReceived(Request request, Response response) {
                    final String jobState = response.getText();
                    job.setState(jobState);
                    table.redraw();
                    updateJobScheduleButtonStyle(jobState);
                    if (refreshData) {
                        refresh();
                    }
                }
            });
        } 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) JSONObject(com.google.gwt.json.client.JSONObject) EmptyRequestCallback(org.pentaho.mantle.client.EmptyRequestCallback) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) JSONString(com.google.gwt.json.client.JSONString) RequestException(com.google.gwt.http.client.RequestException) JSONString(com.google.gwt.json.client.JSONString)

Aggregations

RequestCallback (com.google.gwt.http.client.RequestCallback)175 Response (com.google.gwt.http.client.Response)170 Request (com.google.gwt.http.client.Request)169 RequestException (com.google.gwt.http.client.RequestException)162 RequestBuilder (com.google.gwt.http.client.RequestBuilder)113 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)16 CsrfRequestBuilder (org.pentaho.mantle.client.csrf.CsrfRequestBuilder)14 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