Example usage for com.google.gwt.http.client RequestBuilder GET

List of usage examples for com.google.gwt.http.client RequestBuilder GET

Introduction

In this page you can find the example usage for com.google.gwt.http.client RequestBuilder GET.

Prototype

Method GET

To view the source code for com.google.gwt.http.client RequestBuilder GET.

Click Source Link

Document

Specifies that the HTTP GET method should be used.

Usage

From source file:org.pentaho.mantle.client.MantleApplication.java

License:Open Source License

public void onMantleSettingsLoaded(MantleSettingsLoadedEvent event) {
    final HashMap<String, String> settings = event.getSettings();

    final boolean showOnlyPerspective = Boolean
            .parseBoolean(StringUtils.isEmpty(Window.Location.getParameter("showOnlyPerspective"))
                    ? settings.get("showOnlyPerspective")
                    : Window.Location.getParameter("showOnlyPerspective"));
    final String startupPerspective = StringUtils.isEmpty(Window.Location.getParameter("startupPerspective"))
            ? settings.get("startupPerspective")
            : Window.Location.getParameter("startupPerspective");

    mantleRevisionOverride = settings.get("user-console-revision");

    RootPanel.get("pucMenuBar").add(MantleXul.getInstance().getMenubar());
    RootPanel.get("pucPerspectives").add(PerspectiveManager.getInstance());
    RootPanel.get("pucToolBar").add(MantleXul.getInstance().getToolbar());
    RootPanel.get("pucUserDropDown").add(new UserDropDown());

    if (showOnlyPerspective && !StringUtils.isEmpty(startupPerspective)) {
        RootPanel.get("pucHeader").setVisible(false);
        RootPanel.get("pucContent").getElement().getStyle().setTop(0, Unit.PX);
    }/*from   w  w w.  java2 s . c  o m*/

    // update supported file types
    PluginOptionsHelper.buildEnabledOptionsList(settings);

    // show stuff we've created/configured
    contentDeck.add(new Label());
    contentDeck.showWidget(0);
    contentDeck.add(SolutionBrowserPanel.getInstance());
    if (showOnlyPerspective && !StringUtils.isEmpty(startupPerspective)) {
        SolutionBrowserPanel.getInstance().setVisible(false);
    }

    contentDeck.getElement().setId("applicationShell");
    contentDeck.setStyleName("applicationShell");

    // menubar=no,location=no,resizable=yes,scrollbars=no,status=no,width=1200,height=800
    try {
        RootPanel.get("pucContent").add(contentDeck);
    } catch (Throwable t) {
        // onLoad of something is causing problems
    }

    RootPanel.get().add(WaitPopup.getInstance());

    // Add in the overlay panel
    overlayPanel.setVisible(false);
    overlayPanel.setHeight("100%");
    overlayPanel.setWidth("100%");
    overlayPanel.getElement().getStyle().setProperty("zIndex", "1000");
    overlayPanel.getElement().getStyle().setProperty("position", "absolute");
    RootPanel.get().add(overlayPanel, 0, 0);

    String submitOnEnterSetting = settings.get("submit-on-enter-key");
    submitOnEnter = submitOnEnterSetting == null ? submitOnEnter : Boolean.parseBoolean(submitOnEnterSetting);

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

            @Override
            public void onError(Request arg0, Throwable arg1) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                        arg1.getLocalizedMessage(), false, false, true);
                dialogBox.center();
            }

            @Override
            public void onResponseReceived(Request arg0, Response response) {
                Boolean isAdministrator = Boolean.parseBoolean(response.getText());
                SolutionBrowserPanel.getInstance().setAdministrator(isAdministrator);

                try {
                    String restUrl2 = GWT.getHostPageBaseURL() + "api/scheduler/canSchedule"; //$NON-NLS-1$
                    RequestBuilder requestBuilder2 = new RequestBuilder(RequestBuilder.GET, restUrl2);
                    requestBuilder2.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                    requestBuilder2.sendRequest(null, new RequestCallback() {
                        @Override
                        public void onError(Request arg0, Throwable arg1) {
                            MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                                    arg1.getLocalizedMessage(), false, false, true);
                            dialogBox.center();
                        }

                        public void onResponseReceived(Request arg0, Response response) {
                            Boolean isScheduler = Boolean.parseBoolean(response.getText());
                            SolutionBrowserPanel.getInstance().setScheduler(isScheduler);

                            String numStartupURLsSetting = settings.get("num-startup-urls");
                            if (numStartupURLsSetting != null) {
                                int numStartupURLs = Integer.parseInt(numStartupURLsSetting); //$NON-NLS-1$
                                for (int i = 0; i < numStartupURLs; i++) {
                                    String url = settings.get("startup-url-" + (i + 1)); //$NON-NLS-1$
                                    String name = settings.get("startup-name-" + (i + 1)); //$NON-NLS-1$
                                    if (StringUtils.isEmpty(url) == false) { //$NON-NLS-1$
                                        url = URL.decodeQueryString(url);
                                        name = URL.decodeQueryString(name);
                                        SolutionBrowserPanel.getInstance().getContentTabPanel()
                                                .showNewURLTab(name != null ? name : url, url, url, false);
                                    }
                                }
                            }
                            if (SolutionBrowserPanel.getInstance().getContentTabPanel().getWidgetCount() > 0) {
                                SolutionBrowserPanel.getInstance().getContentTabPanel().selectTab(0);
                            }

                            // startup-url on the URL for the app, wins over settings
                            String startupURL = Window.Location.getParameter("startup-url"); //$NON-NLS-1$
                            if (startupURL != null && !"".equals(startupURL)) { //$NON-NLS-1$
                                // Spaces were double encoded so that they wouldn't be replaced with '+' when creating a deep
                                // link so when following a deep link we need to replace '%20' with a space even after decoding
                                String title = Window.Location.getParameter("name").replaceAll("%20", " "); //$NON-NLS-1$
                                SolutionBrowserPanel.getInstance().getContentTabPanel().showNewURLTab(title,
                                        title, startupURL, false);
                            }
                        }
                    });
                } catch (RequestException e) {
                    MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                            e.getLocalizedMessage(), false, false, true);
                    dialogBox.center();
                }
            }
        });
    } catch (RequestException e) {
        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), e.getLocalizedMessage(), //$NON-NLS-1$
                false, false, true);
        dialogBox.center();
    }

    if (!StringUtils.isEmpty(startupPerspective)) {
        if (PerspectiveManager.getInstance().isLoaded()) {
            PerspectiveManager.getInstance().setPerspective(startupPerspective);
        } else {
            EventBusUtil.EVENT_BUS.addHandler(PerspectivesLoadedEvent.TYPE,
                    new PerspectivesLoadedEventHandler() {
                        public void onPerspectivesLoaded(PerspectivesLoadedEvent event) {
                            PerspectiveManager.getInstance().setPerspective(startupPerspective);
                        }
                    });
        }
    }

}

From source file:org.pentaho.mantle.client.solutionbrowser.filepicklist.AbstractFilePickList.java

License:Open Source License

public void reloadFavorites(final T pickListItem, final String command) {
    final String url = GWT.getHostPageBaseURL() + "api/user-settings/favorites"; //$NON-NLS-1$

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    try {/*from ww w  .j a va  2s .c  o m*/
        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_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);
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.filepicklist.AbstractFilePickList.java

License:Open Source License

public void reloadRecents(final T pickListItem, final String command) {
    final String url = GWT.getHostPageBaseURL() + "api/user-settings/recent"; //$NON-NLS-1$

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    try {//from  ww  w . j av a 2  s .c  om
        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_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_REMOVE.equals(command)) {
                            filePickList.remove(pickListItem);
                            fireItemsChangedEvent();
                        }
                    } catch (Exception e) {
                        if (FILE_PICK_REMOVE.equals(command)) {
                            filePickList.remove(pickListItem);
                            fireItemsChangedEvent();
                        }
                    }
                }
            }
        });
    } catch (RequestException e) {
        // showError(e);
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.fileproperties.FilePropertiesDialog.java

License:Open Source License

/**
 * @param fileSummary/*w  ww. ja  v  a  2 s.  c  o  m*/
 */
protected void getAcls(RepositoryFile fileSummary) {
    String url = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(fileSummary.getPath()) + "/acl"; //$NON-NLS-1$ //$NON-NLS-2$
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    // This header is required to force Internet Explorer to not cache values from the GET response.
    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 dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                        exception.getLocalizedMessage(), false, false, true);
                dialogBox.center();
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    generalTab.setAclResponse(response);
                    if (permissionsTab != null) {
                        permissionsTab.setAclResponse(response);
                    }
                } else {
                    MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                            Messages.getString("serverErrorColon") + " " + response.getStatusCode(), false, //$NON-NLS-1$//$NON-NLS-2$
                            false, true);
                    dialogBox.center();
                }
            }
        });
    } catch (RequestException e) {
        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), e.getLocalizedMessage(), //$NON-NLS-1$
                false, false, true);
        dialogBox.center();
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.fileproperties.FilePropertiesDialog.java

License:Open Source License

/**
 * @param fileSummary/*from ww  w.j a va  2  s.c  o  m*/
 */
protected void getMetadata(RepositoryFile fileSummary) {
    String metadataUrl = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(fileSummary.getPath()) //$NON-NLS-1$
            + "/metadata?cb=" + System.currentTimeMillis(); //$NON-NLS-1$
    RequestBuilder metadataBuilder = new RequestBuilder(RequestBuilder.GET, metadataUrl);
    // This header is required to force Internet Explorer to not cache values from the GET response.
    metadataBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    metadataBuilder.setHeader("accept", "application/json");
    try {
        metadataBuilder.sendRequest(null, new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    if (response.getText() != null && !"".equals(response.getText())
                            && !response.getText().equals("null")) {
                        generalTab.setMetadataResponse(response);
                    }
                } else {
                    MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                            Messages.getString("serverErrorColon") + " " + response.getStatusCode(), false, //$NON-NLS-1$//$NON-NLS-2$
                            false, true);
                    dialogBox.center();
                }
            }
        });
    } catch (RequestException e) {
        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), e.getLocalizedMessage(), //$NON-NLS-1$
                false, false, true);
        dialogBox.center();
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.fileproperties.PermissionsPanel.java

License:Open Source License

/**
 * @param fileSummary//www  .ja va  2  s  .c  o m
 */
public PermissionsPanel(RepositoryFile theFileSummary) {
    this.fileSummary = theFileSummary;

    removeButton.setStylePrimaryName("pentaho-button");
    addButton.setStylePrimaryName("pentaho-button");
    usersAndRolesList.getElement().setId("sharePanelUsersAndRolesList");
    addButton.getElement().setId("sharePanelAddButton");
    removeButton.getElement().setId("sharePanelRemoveButton");

    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            // find list to remove
            if (usersAndRolesList.getItemCount() == 0) {
                return;
            }
            dirty = true;

            for (final String userOrRoleString : SelectUserOrRoleDialog
                    .getSelectedItemsValue(usersAndRolesList)) {
                String recipientType = getRecipientTypeByValue(userOrRoleString);
                //"(user)".length() = "(role)".length() = 6
                String userOrRoleNameString = userOrRoleString.substring(0, userOrRoleString.length() - 6);
                removeRecipient(userOrRoleNameString, recipientType, fileInfo);
                usersAndRolesList.removeItem(usersAndRolesList.getSelectedIndex());
                existingUsersAndRoles.remove(userOrRoleNameString);
            }
            if (usersAndRolesList.getItemCount() > 0) {
                usersAndRolesList.setSelectedIndex(0);
            }
            buildPermissionsTable(fileInfo);
        }
    });

    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            dirty = true;
            final SelectUserOrRoleDialog pickUserRoleDialog = new SelectUserOrRoleDialog(fileInfo,
                    existingUsersAndRoles, new IUserRoleSelectedCallback() {

                        public void roleSelected(String role) {
                            //this was done to distinguish users and roles in case they are identical
                            usersAndRolesList.addItem(role, role + "(role)"); //$NON-NLS-1$
                            existingUsersAndRoles.add(role);
                            usersAndRolesList.setSelectedIndex(usersAndRolesList.getItemCount() - 1);
                            addRecipient(role, ROLE_TYPE, fileInfo);
                            buildPermissionsTable(fileInfo);
                        }

                        public void userSelected(String user) {
                            usersAndRolesList.addItem(user, user + "(user)"); //$NON-NLS-1$
                            existingUsersAndRoles.add(user);
                            usersAndRolesList.setSelectedIndex(usersAndRolesList.getItemCount() - 1);
                            addRecipient(user, USER_TYPE, fileInfo);
                            buildPermissionsTable(fileInfo);
                        }
                    });
            pickUserRoleDialog.center();
        }

    });

    FlowPanel buttonPanel = new FlowPanel();
    buttonPanel.add(addButton);
    buttonPanel.add(removeButton);
    usersAndRolesList.setVisibleItemCount(7);
    usersAndRolesList.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            // update permissions list and permission label (put username in it)
            // rebuild permissionsTable settings based on selected mask
            buildPermissionsTable(fileInfo);
        }

    });
    usersAndRolesList.setWidth("100%"); //$NON-NLS-1$
    buttonPanel.setWidth("100%"); //$NON-NLS-1$

    readPermissionCheckBox.getElement().setId("sharePermissionRead"); //$NON-NLS-1$
    deletePermissionCheckBox.getElement().setId("sharePermissionDelete"); //$NON-NLS-1$
    writePermissionCheckBox.getElement().setId("sharePermissionWrite"); //$NON-NLS-1$
    managePermissionCheckBox.getElement().setId("sharePermissionManagePerm"); //$NON-NLS-1$

    readPermissionCheckBox.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent clickEvent) {
            updatePermissionMask(fileInfo, readPermissionCheckBox.getValue(), PERM_READ);
            refreshPermission();
        }
    });
    deletePermissionCheckBox.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent clickEvent) {
            setDeleteCheckBox(deletePermissionCheckBox.getValue());
            refreshPermission();
        }
    });
    writePermissionCheckBox.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent clickEvent) {
            setWriteCheckBox(writePermissionCheckBox.getValue());
            refreshPermission();
        }
    });
    managePermissionCheckBox.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent clickEvent) {
            setManageCheckBox(managePermissionCheckBox.getValue());
            refreshPermission();
        }
    });

    readPermissionCheckBox.setEnabled(false);

    inheritsCheckBox.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent clickEvent) {
            dirty = true;
            String moduleBaseURL = GWT.getModuleBaseURL();
            String moduleName = GWT.getModuleName();
            final String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));

            if (inheritsCheckBox.getValue()) {
                VerticalPanel vp = new VerticalPanel();
                vp.add(new Label(Messages.getString("permissionsWillBeLostQuestion"))); //$NON-NLS-1$
                // Get the state of add and remove button
                final boolean currRemoveButtonState = removeButton.isEnabled();
                final boolean currAddButtonState = addButton.isEnabled();
                final PromptDialogBox permissionsOverwriteConfirm = new PromptDialogBox(
                        Messages.getString("permissionsWillBeLostConfirmMessage"), Messages.getString("ok"), //$NON-NLS-1$//$NON-NLS-2$
                        Messages.getString("cancel"), false, true, vp); //$NON-NLS-1$

                final IDialogCallback callback = new IDialogCallback() {

                    public void cancelPressed() {
                        permissionsOverwriteConfirm.hide();
                        inheritsCheckBox.setValue(false);
                        dirty = false;
                        // BACKLOG-15986 Set the button state to value before the confirmation dialog
                        setInheritsAcls(inheritsCheckBox.getValue(), fileInfo);
                        addButton.setEnabled(currAddButtonState);
                        removeButton.setEnabled(currRemoveButtonState);
                    }

                    public void okPressed() {
                        String path = fileSummary.getPath().substring(0,
                                fileSummary.getPath().lastIndexOf("/"));
                        String url = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(path) //$NON-NLS-1$
                                + "/acl"; //$NON-NLS-1$
                        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
                        // This header is required to force Internet Explorer to not cache values from the GET response.
                        builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                        try {
                            builder.sendRequest(null, new RequestCallback() {
                                public void onResponseReceived(Request request, Response response) {
                                    if (response.getStatusCode() == Response.SC_OK) {
                                        initializePermissionPanel(XMLParser.parse(response.getText()));
                                        inheritsCheckBox.setValue(true);
                                        refreshPermission();
                                    } else {
                                        inheritsCheckBox.setValue(false);
                                        refreshPermission();
                                        MessageDialogBox dialogBox = new MessageDialogBox(
                                                Messages.getString("error"), //$NON-NLS-1$
                                                Messages.getString("couldNotGetPermissions", //$NON-NLS-1$
                                                        response.getStatusText()), false, false, true);
                                        dialogBox.center();
                                    }
                                }

                                @Override
                                public void onError(Request request, Throwable exception) {
                                    inheritsCheckBox.setValue(false);
                                    refreshPermission();
                                    MessageDialogBox dialogBox = new MessageDialogBox(
                                            Messages.getString("error"), //$NON-NLS-1$
                                            Messages.getString("couldNotGetPermissions", //$NON-NLS-1$
                                                    exception.getLocalizedMessage()), false, false, true);
                                    dialogBox.center();
                                }
                            });
                        } catch (RequestException e) {
                            inheritsCheckBox.setValue(false);
                            refreshPermission();
                            MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                                    Messages.getString("couldNotGetPermissions", e.getLocalizedMessage()), //$NON-NLS-1$
                                    false, false, true);
                            dialogBox.center();
                        }
                    }
                };
                permissionsOverwriteConfirm.setCallback(callback);
                permissionsOverwriteConfirm.center();

            }
            refreshPermission();
        }
    });

    int row = 0;
    setWidget(row++, 0, inheritsCheckBox);
    setWidget(row++, 0, new Label(Messages.getString("usersAndRoles"))); //$NON-NLS-1$
    setWidget(row++, 0, usersAndRolesList);

    // right justify button panel
    CellFormatter buttonPanelCellFormatter = new CellFormatter();
    buttonPanelCellFormatter.setHorizontalAlignment(row, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    setCellFormatter(buttonPanelCellFormatter);
    setWidget(row++, 0, buttonPanel);

    setWidget(row++, 0, permissionsLabel);
    setWidget(row++, 0, permissionsTable);

    setCellPadding(4);

    setWidth("100%"); //$NON-NLS-1$

    permissionsTable.setWidget(0, 0, managePermissionCheckBox);
    permissionsTable.setWidget(1, 0, deletePermissionCheckBox);
    permissionsTable.setWidget(2, 0, writePermissionCheckBox);
    permissionsTable.setWidget(3, 0, readPermissionCheckBox);
    permissionsTable.setStyleName("permissionsTable"); //$NON-NLS-1$
    permissionsTable.setWidth("100%"); //$NON-NLS-1$
    permissionsTable.setHeight("100%"); //$NON-NLS-1$

    init();
}

From source file:org.pentaho.mantle.client.solutionbrowser.fileproperties.SelectUserOrRoleDialog.java

License:Open Source License

public void fetchAllRoles(final ArrayList<String> existing, final Document fileInfo) {

    try {/*w  w w.  j  a v a 2 s. co  m*/
        final String url = GWT.getHostPageBaseURL() + "api/userrolelist/permission-roles"; //$NON-NLS-1$
        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"), //$NON-NLS-1$
                        Messages.getString("couldNotGetRoles"), false, false, true); //$NON-NLS-1$
                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());
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.fileproperties.SelectUserOrRoleDialog.java

License:Open Source License

public void fetchAllUsers(final ArrayList<String> existing, final Document fileInfo) {
    try {/*ww w .j a  v a2 s . c  o  m*/
        final String url = GWT.getHostPageBaseURL() + "api/userrolelist/permission-users"; //$NON-NLS-1$
        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"), //$NON-NLS-1$
                        Messages.getString("couldNotGetUsers"), false, false, true); //$NON-NLS-1$
                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());
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.RepositoryFileTreeManager.java

License:Open Source License

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();// w  w w  .j a  v  a 2s  . c o m
    RequestBuilder builder = null;
    String url = GWT.getHostPageBaseURL() + "api/repo/files/:/tree?"; //$NON-NLS-1$
    if (depth == null) {
        depth = -1;
    }
    if (filter == null) {
        filter = "*"; //$NON-NLS-1$
    }
    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();
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel.java

License:Open Source License

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));
    final String path = solutionPath; // Expecting some encoding here
    final String url = contextURL + "api/repo/files/" + pathToId(path) + "/properties"; //$NON-NLS-1$

    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 {/*w ww . j a  v  a 2s. co  m*/
        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);
    }
}