Search in sources :

Example 51 with RequestBuilder

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

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

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

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

Example 55 with RequestBuilder

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

the class NewDropdownCommand method performOperation.

protected void performOperation(boolean feedback) {
    final PopupPanel popup = new PopupPanel(true, false) {

        public void show() {
            // show glass pane
            super.show();
            if (pageBackground == null) {
                pageBackground = new FocusPanel() {

                    public void onBrowserEvent(Event event) {
                        int type = event.getTypeInt();
                        switch(type) {
                            case Event.ONKEYDOWN:
                                {
                                    if ((char) event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
                                        event.stopPropagation();
                                        hide();
                                    }
                                    return;
                                }
                        }
                        super.onBrowserEvent(event);
                    }
                };
                pageBackground.addClickHandler(new ClickHandler() {

                    public void onClick(ClickEvent event) {
                        hide();
                        pageBackground.setVisible(false);
                        pageBackground.getElement().getStyle().setDisplay(Display.NONE);
                    }
                });
                RootPanel.get().add(pageBackground, 0, 0);
            }
            // $NON-NLS-1$ //$NON-NLS-2$
            pageBackground.setSize("100%", Window.getClientHeight() + Window.getScrollTop() + "px");
            pageBackground.setVisible(true);
            pageBackground.getElement().getStyle().setDisplay(Display.BLOCK);
            // hide <embeds>
            // TODO: migrate to GlassPane Listener
            FrameUtils.toggleEmbedVisibility(false);
            // Notify listeners that we're showing a dialog (hide PDFs, flash).
            GlassPane.getInstance().show();
        }

        public void hide(boolean autoClosed) {
            super.hide(autoClosed);
            pageBackground.setVisible(false);
            GlassPane.getInstance().hide();
        }

        protected void onPreviewNativeEvent(final NativePreviewEvent event) {
            // Switch on the event type
            int type = event.getTypeInt();
            switch(type) {
                case Event.ONKEYDOWN:
                    {
                        Event nativeEvent = Event.as(event.getNativeEvent());
                        if ((char) nativeEvent.getKeyCode() == KeyCodes.KEY_ESCAPE) {
                            event.cancel();
                            hide();
                        }
                        return;
                    }
            }
        }
    };
    if (popup.isShowing()) {
        popup.hide();
        return;
    }
    // $NON-NLS-1$
    String url = GWT.getHostPageBaseURL() + "api/plugin-manager/settings/new-toolbar-button";
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
    // $NON-NLS-1$//$NON-NLS-2$
    rb.setHeader("Content-Type", "text/plain");
    // $NON-NLS-1$//$NON-NLS-2$
    rb.setHeader("accept", "application/json");
    rb.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        rb.sendRequest(null, 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$
                exception.getMessage(), false, false, true);
                dialogBox.center();
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                    JsArray<JsCreateNewConfig> jsarray = parseJson(JsonUtils.escapeJsonForEval(response.getText()));
                    final ArrayList<JsCreateNewConfig> sorted = new ArrayList<JsCreateNewConfig>();
                    for (int i = 0; i < jsarray.length(); i++) {
                        sorted.add(jsarray.get(i));
                    }
                    Collections.sort(sorted, new JsCreateNewConfigComparator());
                    popup.setStyleName("newToolbarDropdown");
                    VerticalPanel buttonPanel = new VerticalPanel();
                    popup.add(buttonPanel);
                    for (int i = 0; i < sorted.size(); i++) {
                        final int finali = i;
                        String enabledUrl = sorted.get(i).getEnabledUrl();
                        if (buttonEnabled(enabledUrl)) {
                            Button button = new Button(Messages.getString(sorted.get(i).getLabel()));
                            button.setStyleName("pentaho-button");
                            button.getElement().addClassName("newToolbarDropdownButton");
                            button.addClickHandler(new ClickHandler() {

                                public void onClick(ClickEvent event) {
                                    if (sorted.get(finali).getActionUrl().startsWith("javascript:")) {
                                        doEvalJS(sorted.get(finali).getActionUrl().substring("javascript:".length()));
                                    } else {
                                        SolutionBrowserPanel.getInstance().getContentTabPanel().showNewURLTab(Messages.getString(sorted.get(finali).getTabName()), Messages.getString(sorted.get(finali).getTabName()), sorted.get(finali).getActionUrl(), false);
                                    }
                                    popup.hide();
                                }
                            });
                            String name = sorted.get(i).getName();
                            if ("data-access".equals(name)) {
                                buttonPanel.add(new HTML("<hr style='color: #a7a7a7' />"));
                            }
                            buttonPanel.add(button);
                        }
                    }
                    popup.setPopupPosition(anchorWidget.getAbsoluteLeft(), anchorWidget.getAbsoluteTop() + anchorWidget.getOffsetHeight());
                    popup.show();
                } else {
                    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("error"), false, false, true);
                    dialogBox.center();
                }
            }

            private boolean buttonEnabled(String enabledUrl) {
                if (enabledUrl == null || enabledUrl.isEmpty()) {
                    return true;
                } else {
                    Boolean enabled = false;
                    try {
                        enabled = Boolean.valueOf(sendRequest(enabledUrl));
                    } catch (Exception e) {
                    }
                    return enabled;
                }
            }
        });
    } 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$
        e.getMessage(), false, false, true);
        dialogBox.center();
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) PopupPanel(com.google.gwt.user.client.ui.PopupPanel) ArrayList(java.util.ArrayList) HTML(com.google.gwt.user.client.ui.HTML) FocusPanel(com.google.gwt.user.client.ui.FocusPanel) RequestException(com.google.gwt.http.client.RequestException) Button(com.google.gwt.user.client.ui.Button) JsCreateNewConfigComparator(org.pentaho.mantle.client.objects.JsCreateNewConfigComparator) JsArray(com.google.gwt.core.client.JsArray) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RequestCallback(com.google.gwt.http.client.RequestCallback) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Event(com.google.gwt.user.client.Event) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) JsCreateNewConfig(org.pentaho.mantle.client.objects.JsCreateNewConfig)

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