Search in sources :

Example 26 with RequestBuilder

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

the class UserRolesAdminPanelController method saveUser.

public void saveUser(final String name, final String password) {
    String serviceUrl = GWT.getHostPageBaseURL() + "api/userroledao/createUser";
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.PUT, serviceUrl);
    try {
        executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        executableTypesRequestBuilder.setHeader("Content-Type", "application/json");
        String json = "{\"userName\": \"" + encodeUri(name) + "\", \"password\": \"ENC:" + b64encode(password) + "\"}";
        executableTypesRequestBuilder.sendRequest(json, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                displayErrorInMessageBox(Messages.getString("Error"), exception.getLocalizedMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() != Response.SC_NO_CONTENT) {
                    String errorMsg = Messages.getString("newUserErrorMessage");
                    String errorValidationMessage = response.getHeader(PUC_VALIDATION_ERROR_MESSAGE);
                    if (errorValidationMessage != null) {
                        errorMsg = errorMsg + "\n" + errorValidationMessage;
                    }
                    showXulErrorMessage(Messages.getString("newUser"), errorMsg);
                } else {
                    initializeAvailableUsers(name);
                    initializeRoles(rolesListBox.getValue(rolesListBox.getSelectedIndex()), "api/userroledao/roles", rolesListBox);
                }
            }
        });
    } catch (RequestException e) {
        displayErrorInMessageBox(Messages.getString("Error"), e.getLocalizedMessage());
    }
}
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)

Example 27 with RequestBuilder

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

the class UserRolesAdminPanelController method initializeActionBaseSecurityElements.

private void initializeActionBaseSecurityElements() {
    final String url = GWT.getHostPageBaseURL() + "api/userroledao/logicalRoleMap";
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    executableTypesRequestBuilder.setHeader("accept", "application/json");
    try {
        executableTypesRequestBuilder.sendRequest(null, new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
                String roleMappings = response.getText();
                rolesPermissionsPanel.initializeActionBaseSecurityElements(roleMappings);
                systemRolesPermissionsPanel.initializeActionBaseSecurityElements(roleMappings);
            }
        });
    } catch (RequestException e) {
    // ignored
    }
}
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)

Example 28 with RequestBuilder

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

the class AboutCommand method performOperation.

protected void performOperation(boolean feedback) {
    if (StringUtils.isEmpty(MantleApplication.mantleRevisionOverride) == false) {
        showAboutDialog(MantleApplication.mantleRevisionOverride);
    } else {
        // $NON-NLS-1$
        final String url = GWT.getHostPageBaseURL() + "api/version/show";
        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) {
                // showError(exception);
                }

                public void onResponseReceived(Request request, Response response) {
                    showAboutDialog(response.getText());
                }
            });
        } 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) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Example 29 with RequestBuilder

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

the class DeleteFileCommand method doDelete.

public void doDelete(String filesList, final SolutionFileActionEvent event) {
    // $NON-NLS-1$
    String deleteFilesURL = contextURL + "api/repo/files/delete";
    RequestBuilder deleteFilesRequestBuilder = new RequestBuilder(RequestBuilder.PUT, deleteFilesURL);
    // $NON-NLS-1$//$NON-NLS-2$
    deleteFilesRequestBuilder.setHeader("Content-Type", "text/plain");
    deleteFilesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        deleteFilesRequestBuilder.sendRequest(filesList, new RequestCallback() {

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

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                    event.setMessage("Success");
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                    new RefreshRepositoryCommand().execute(false);
                    FileChooserDialog.setIsDirty(Boolean.TRUE);
                    setBrowseRepoDirty(Boolean.TRUE);
                    for (SolutionBrowserFile file : filesToDelete) {
                        if (file.getPath() != null) {
                            SolutionBrowserPanel.getInstance().removeRecent(file.getPath());
                            SolutionBrowserPanel.getInstance().removeFavorite(file.getPath());
                        }
                    }
                } else {
                    event.setMessage(Messages.getString("couldNotDeleteFile"));
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                }
            }
        });
    } catch (RequestException e) {
        MessageDialogBox dialogBox = new // $NON-NLS-1$ //$NON-NLS-2$
        MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("couldNotDeleteFile"), false, false, true);
        dialogBox.center();
        event.setMessage(Messages.getString("couldNotDeleteFile"));
        EventBusUtil.EVENT_BUS.fireEvent(event);
    }
}
Also used : Response(com.google.gwt.http.client.Response) SolutionBrowserFile(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Example 30 with RequestBuilder

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

the class ContentCleanerPanel method deleteContentNow.

/**
 * @param age
 *          in milliseconds
 */
public void deleteContentNow(long age) {
    showLoadingIndicator();
    String date = DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(new Date());
    String json = "{\"jobName\": \"Content Cleaner\", \"actionClass\": \"org.pentaho.platform.admin.GeneratedContentCleaner\"," + " \"jobParameters\":[ { \"name\": \"age\", \"stringValue\": \"" + age + "\", \"type\": \"string\" }], \"simpleJobTrigger\": { \"endTime\": null, \"repeatCount\": \"0\", " + "\"repeatInterval\": \"0\", \"startTime\": \"" + date + "\", \"uiPassParam\": \"RUN_ONCE\"} }";
    RequestBuilder scheduleFileRequestBuilder = new RequestBuilder(RequestBuilder.POST, GWT.getHostPageBaseURL() + "api/scheduler/job");
    scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    // $NON-NLS-1$//$NON-NLS-2$
    scheduleFileRequestBuilder.setHeader("Content-Type", "application/json");
    try {
        scheduleFileRequestBuilder.sendRequest(json, new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
                String jobId = response.getText();
                final RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "api/scheduler/jobinfo?jobId=" + URL.encodeQueryString(jobId));
                requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                // $NON-NLS-1$//$NON-NLS-2$
                requestBuilder.setHeader("Content-Type", "application/json");
                // $NON-NLS-1$//$NON-NLS-2$
                requestBuilder.setHeader("accept", "application/json");
                // create a timer to check if the job has finished
                Timer t = new Timer() {

                    public void run() {
                        try {
                            requestBuilder.sendRequest(null, new RequestCallback() {

                                @Override
                                public void onResponseReceived(Request request, Response response) {
                                    // once the job is finished, it is removed from scheduler and we should receive a 404 code.
                                    if (response.getStatusCode() != Response.SC_OK) {
                                        hideLoadingIndicator();
                                        cancel();
                                    }
                                }

                                @Override
                                public void onError(Request request, Throwable throwable) {
                                    hideLoadingIndicator();
                                    cancel();
                                }
                            });
                        } catch (RequestException e) {
                            hideLoadingIndicator();
                            cancel();
                        }
                    }
                };
                t.scheduleRepeating(1000);
            }
        });
    } catch (RequestException re) {
        hideLoadingIndicator();
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Timer(com.google.gwt.user.client.Timer) Request(com.google.gwt.http.client.Request) JSONString(com.google.gwt.json.client.JSONString) RequestException(com.google.gwt.http.client.RequestException) Date(java.util.Date)

Aggregations

RequestBuilder (com.google.gwt.http.client.RequestBuilder)132 RequestException (com.google.gwt.http.client.RequestException)116 RequestCallback (com.google.gwt.http.client.RequestCallback)113 Response (com.google.gwt.http.client.Response)111 Request (com.google.gwt.http.client.Request)110 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)27 CsrfRequestBuilder (org.pentaho.mantle.client.csrf.CsrfRequestBuilder)22 JSONString (com.google.gwt.json.client.JSONString)19 ArrayList (java.util.ArrayList)16 Bindable (org.pentaho.ui.xul.stereotype.Bindable)15 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)13 JSONObject (com.google.gwt.json.client.JSONObject)11 JsArrayString (com.google.gwt.core.client.JsArrayString)9 JSONArray (com.google.gwt.json.client.JSONArray)8 List (java.util.List)8 HTML (com.google.gwt.user.client.ui.HTML)7 IDialogCallback (org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)7 EmptyRequestCallback (org.pentaho.mantle.client.EmptyRequestCallback)7 PromptDialogBox (org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox)6 RepositoryFile (org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)6