Search in sources :

Example 46 with RequestBuilder

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

the class PermissionsPanel method prepareRequests.

/**
 * @return
 */
public List<RequestBuilder> prepareRequests() {
    ArrayList<RequestBuilder> requestBuilders = new ArrayList<RequestBuilder>();
    String moduleBaseURL = GWT.getModuleBaseURL();
    String moduleName = GWT.getModuleName();
    String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
    // $NON-NLS-1$//$NON-NLS-2$
    String url = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(fileSummary.getPath()) + "/acl";
    RequestBuilder builder = new RequestBuilder(RequestBuilder.PUT, url);
    builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    builder.setHeader("Content-Type", "application/xml");
    // default
    if (isInheritsAcls(fileInfo)) {
        removeAllAces(fileInfo);
    } else {
        // Check if any of the permission sets should be replaced with ALL.
        // Any non-inherited Ace with a permission set containing PERM_GRANT_PERM should be replaced
        // with a single PERM_ALL.
        NodeList aces = fileInfo.getElementsByTagName(ACES_ELEMENT_NAME);
        for (int i = 0; i < aces.getLength(); i++) {
            Element ace = (Element) aces.item(i);
            NodeList perms = ace.getElementsByTagName(PERMISSIONS_ELEMENT_NAME);
            for (int j = 0; j < perms.getLength(); j++) {
                Element perm = (Element) perms.item(j);
                if (perm.getFirstChild() != null) {
                    if (Integer.parseInt(perm.getFirstChild().getNodeValue()) == PERM_GRANT_PERM) {
                        replacePermissionsWithAll(ace, fileInfo);
                        break;
                    }
                }
            }
        }
    }
    // set request data in builder itself
    builder.setRequestData(fileInfo.toString());
    // add builder to list to return to parent for execution
    requestBuilders.add(builder);
    return requestBuilders;
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) NodeList(com.google.gwt.xml.client.NodeList) Element(com.google.gwt.xml.client.Element) ArrayList(java.util.ArrayList)

Example 47 with RequestBuilder

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

the class PermissionsPanel method setAdmin.

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

            public void onError(Request request, Throwable caught) {
                isAdmin = false;
            }

            public void onResponseReceived(Request request, Response response) {
                // $NON-NLS-1$
                isAdmin = "true".equalsIgnoreCase(response.getText());
            }
        });
    } catch (RequestException e) {
        isAdmin = 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)

Example 48 with RequestBuilder

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

the class AbstractFilePickList method reloadFavorites.

public void reloadFavorites(final T pickListItem, final String command) {
    final String url = GWT.getHostPageBaseURL() + "api/user-settings/favorites";
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    try {
        builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        builder.setHeader("accept", "application/json");
        builder.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_NO_CONTENT && FILE_PICK_ADD.equals(command)) {
                    filePickList = new ArrayList<T>();
                    add(filePickList.size(), pickListItem);
                } else if (response.getStatusCode() == Response.SC_OK) {
                    try {
                        JSONArray jsonArr = (JSONArray) JSONParser.parse(response.getText());
                        filePickList = new ArrayList<T>();
                        T filePickItem;
                        for (int i = 0; i < jsonArr.size(); i++) {
                            filePickItem = createFilePickItem(jsonArr.get(i).isObject());
                            filePickList.add(filePickItem);
                        }
                        if (FILE_PICK_ADD.equals(command)) {
                            add(filePickList.size(), pickListItem);
                        } else if (FILE_PICK_REMOVE.equals(command)) {
                            filePickList.remove(pickListItem);
                            fireItemsChangedEvent();
                        }
                    } catch (Exception e) {
                        if (FILE_PICK_ADD.equals(command)) {
                            add(filePickList.size(), pickListItem);
                        } else if (FILE_PICK_REMOVE.equals(command)) {
                            filePickList.remove(pickListItem);
                            fireItemsChangedEvent();
                        }
                    }
                }
            }
        });
    } catch (RequestException e) {
    // showError(e);
    }
}
Also used : CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) RequestBuilder(com.google.gwt.http.client.RequestBuilder) Request(com.google.gwt.http.client.Request) ArrayList(java.util.ArrayList) JSONArray(com.google.gwt.json.client.JSONArray) RequestException(com.google.gwt.http.client.RequestException) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) GWT(com.google.gwt.core.client.GWT)

Example 49 with RequestBuilder

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

the class AbstractFilePickList method save.

/**
 * Convert the FilePickList to JSON and save it to a user setting
 *
 * @param settingName
 */
public void save(String settingName) {
    String url = GWT.getHostPageBaseURL() + "api/user-settings/" + settingName;
    RequestBuilder builder = new CsrfRequestBuilder(RequestBuilder.POST, url);
    try {
        builder.setHeader("accept", "application/json");
        builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        builder.sendRequest(toJson().toString(), new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
                fireOnSavedEvent();
            }
        });
    } catch (RequestException e) {
    // showError(e);
    }
}
Also used : Response(com.google.gwt.http.client.Response) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) RequestBuilder(com.google.gwt.http.client.RequestBuilder) 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 50 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder 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)

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