Search in sources :

Example 1 with PermissionsPanel

use of org.pentaho.mantle.client.solutionbrowser.fileproperties.PermissionsPanel 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 2 with PermissionsPanel

use of org.pentaho.mantle.client.solutionbrowser.fileproperties.PermissionsPanel in project pentaho-platform by pentaho.

the class SelectUserOrRoleDialog method fetchAllUsers.

public void fetchAllUsers(final ArrayList<String> existing, final Document fileInfo) {
    try {
        // $NON-NLS-1$
        final String url = GWT.getHostPageBaseURL() + "api/userrolelist/permission-users";
        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("couldNotGetUsers"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
                true);
                dialogBox.center();
            }

            public void onResponseReceived(Request request, Response response) {
                JsArrayString users = parseUsersJson(JsonUtils.escapeJsonForEval(response.getText()));
                // filter out existing
                usersListBox.clear();
                PermissionsPanel permPanel = new PermissionsPanel(null);
                for (int i = 0; i < users.length(); i++) {
                    String user = users.get(i);
                    if (!existing.contains(user)) {
                        usersListBox.addItem(user);
                    } else {
                        if (!permPanel.getNames(fileInfo, 0).contains(user) && permPanel.getNames(fileInfo, 1).contains(user)) {
                            // we have equal user/role pair(s) and role already in existing list
                            usersListBox.addItem(user);
                        }
                    }
                }
            }
        });
    } 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

JsArrayString (com.google.gwt.core.client.JsArrayString)2 Request (com.google.gwt.http.client.Request)2 RequestBuilder (com.google.gwt.http.client.RequestBuilder)2 RequestCallback (com.google.gwt.http.client.RequestCallback)2 RequestException (com.google.gwt.http.client.RequestException)2 Response (com.google.gwt.http.client.Response)2 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)2 PermissionsPanel (org.pentaho.mantle.client.solutionbrowser.fileproperties.PermissionsPanel)2