Search in sources :

Example 71 with RequestCallback

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

the class SelectUserOrRoleDialog method fetchAllRoles.

public void fetchAllRoles(final ArrayList<String> existing, final Document fileInfo) {
    try {
        // $NON-NLS-1$
        final String url = GWT.getHostPageBaseURL() + "api/userrolelist/permission-roles";
        RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
        // This header is required to force Internet Explorer to not cache values from the GET response.
        requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        requestBuilder.setHeader("accept", "application/json");
        requestBuilder.sendRequest(null, new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
                JsArrayString roles = parseRolesJson(JsonUtils.escapeJsonForEval(response.getText()));
                // filter out existing
                rolesListBox.clear();
                PermissionsPanel permPanel = new PermissionsPanel(null);
                for (int i = 0; i < roles.length(); i++) {
                    String role = roles.get(i);
                    if (!existing.contains(role)) {
                        rolesListBox.addItem(role);
                    } else {
                        if (!permPanel.getNames(fileInfo, 1).contains(role) && permPanel.getNames(fileInfo, 0).contains(role)) {
                            // we have equal user/role pair(s) and user already in existing list
                            rolesListBox.addItem(role);
                        }
                    }
                }
            }
        });
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    }
}
Also used : Response(com.google.gwt.http.client.Response) 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) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) RequestException(com.google.gwt.http.client.RequestException) PermissionsPanel(org.pentaho.mantle.client.solutionbrowser.fileproperties.PermissionsPanel)

Example 72 with RequestCallback

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

the class PerspectiveManager method init.

private void init() {
    // $NON-NLS-1$
    final String url = GWT.getHostPageBaseURL() + "api/scheduler/canSchedule/?ts=" + System.currentTimeMillis();
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    // $NON-NLS-1$//$NON-NLS-2$
    builder.setHeader("Content-Type", "application/json");
    builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    canSchedule = true;
    try {
        builder.sendRequest(null, new RequestCallback() {

            @Override
            public void onError(Request request, Throwable throwable) {
                setupPerspectiveManager();
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                    canSchedule = "true".equals(response.getText());
                }
                setupPerspectiveManager();
            }
        });
    } catch (Exception 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) JsArrayString(com.google.gwt.core.client.JsArrayString) RequestException(com.google.gwt.http.client.RequestException)

Example 73 with RequestCallback

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

the class RepositoryFileTreeManager method fetchRepositoryFileTree.

public void fetchRepositoryFileTree(final AsyncCallback<RepositoryFileTree> callback, Integer depth, String filter, Boolean showHidden) {
    // notify listeners that we are about to talk to the server (in case there's anything they want to do
    // such as busy cursor or tree loading indicators)
    beforeFetchRepositoryFileTree();
    RequestBuilder builder = null;
    // $NON-NLS-1$
    String url = GWT.getHostPageBaseURL() + "api/repo/files/:/tree?";
    if (depth == null) {
        depth = -1;
    }
    if (filter == null) {
        // $NON-NLS-1$
        filter = "*";
    }
    if (showHidden == null) {
        showHidden = Boolean.FALSE;
    }
    url = url + "depth=" + depth + "&filter=" + filter + "&showHidden=" + showHidden + "&ts=" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    System.currentTimeMillis();
    builder = new RequestBuilder(RequestBuilder.GET, url);
    builder.setHeader("Accept", "application/json");
    builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    RequestCallback innerCallback = new RequestCallback() {

        public void onError(Request request, Throwable exception) {
            Window.alert(exception.toString());
        }

        public void onResponseReceived(Request request, Response response) {
            if (response.getStatusCode() == Response.SC_OK) {
                String json = response.getText();
                System.out.println(json);
                final JsonToRepositoryFileTreeConverter converter = new JsonToRepositoryFileTreeConverter(response.getText());
                fileTree = converter.getTree();
                String deletedFilesUrl = GWT.getHostPageBaseURL() + "api/repo/files/deleted?ts=" + System.currentTimeMillis();
                RequestBuilder deletedFilesRequestBuilder = new RequestBuilder(RequestBuilder.GET, deletedFilesUrl);
                deletedFilesRequestBuilder.setHeader("Accept", "application/json");
                deletedFilesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                try {
                    deletedFilesRequestBuilder.sendRequest(null, new RequestCallback() {

                        public void onError(Request request, Throwable exception) {
                            fireRepositoryFileTreeFetched();
                            Window.alert(exception.toString());
                        }

                        public void onResponseReceived(Request delRequest, Response delResponse) {
                            if (delResponse.getStatusCode() == Response.SC_OK) {
                                try {
                                    trashItems = JsonToRepositoryFileTreeConverter.getTrashFiles(delResponse.getText());
                                } catch (Throwable t) {
                                // apparently this happens when you have no trash
                                }
                                fireRepositoryFileTreeFetched();
                            } else {
                                fireRepositoryFileTreeFetched();
                            }
                        }
                    });
                } catch (Exception e) {
                    fireRepositoryFileTreeFetched();
                }
                if (callback != null) {
                    callback.onSuccess(fileTree);
                }
            } else {
                fileTree = new RepositoryFileTree();
                RepositoryFile errorFile = new RepositoryFile();
                errorFile.setFolder(true);
                errorFile.setName("!ERROR!");
                fileTree.setFile(errorFile);
            }
        }
    };
    try {
        builder.sendRequest(null, innerCallback);
    } catch (RequestException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
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) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) RequestException(com.google.gwt.http.client.RequestException) RequestException(com.google.gwt.http.client.RequestException) RepositoryFileTree(org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree) JsonToRepositoryFileTreeConverter(org.pentaho.gwt.widgets.client.filechooser.JsonToRepositoryFileTreeConverter)

Example 74 with RequestCallback

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

the class SolutionBrowserPanel method openFile.

public void openFile(final String fileNameWithPath, final FileCommand.COMMAND mode) {
    final String moduleBaseURL = GWT.getModuleBaseURL();
    final String moduleName = GWT.getModuleName();
    final String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
    // Expecting some encoding here
    final String path = fileNameWithPath;
    // $NON-NLS-1$
    final String url = contextURL + "api/repo/files/" + pathToId(path) + "/properties";
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    executableTypesRequestBuilder.setHeader("accept", "application/json");
    executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    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) {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("repositoryFileDto", (JSONObject) JSONParser.parseLenient(response.getText()));
                    RepositoryFile repositoryFile = new RepositoryFile(jsonObject);
                    openFile(repositoryFile, mode);
                }
            }
        });
    } 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) JSONObject(com.google.gwt.json.client.JSONObject) Request(com.google.gwt.http.client.Request) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) JsArrayString(com.google.gwt.core.client.JsArrayString) RequestException(com.google.gwt.http.client.RequestException)

Example 75 with RequestCallback

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

the class SolutionBrowserPanel method getFile.

public void getFile(final String solutionPath, final SolutionFileHandler handler) {
    final String moduleBaseURL = GWT.getModuleBaseURL();
    final String moduleName = GWT.getModuleName();
    final String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
    // Expecting some encoding here
    final String path = solutionPath;
    // $NON-NLS-1$
    final String url = contextURL + "api/repo/files/" + pathToId(path) + "/properties";
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    executableTypesRequestBuilder.setHeader("accept", "application/json");
    executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    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) {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("repositoryFileDto", (JSONObject) JSONParser.parseLenient(response.getText()));
                    RepositoryFile repositoryFile = new RepositoryFile(jsonObject);
                    handler.handle(repositoryFile);
                }
            }
        });
    } 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) JSONObject(com.google.gwt.json.client.JSONObject) Request(com.google.gwt.http.client.Request) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) JsArrayString(com.google.gwt.core.client.JsArrayString) RequestException(com.google.gwt.http.client.RequestException)

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