Search in sources :

Example 56 with RequestBuilder

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

the class PasteFilesCommand method performOperation.

/*
   * (non-Javadoc)
   *
   * @see org.pentaho.mantle.client.commands.AbstractCommand#performOperation(boolean)
   */
@Override
protected void performOperation(boolean feedback) {
    final SolutionBrowserClipboard clipBoard = SolutionBrowserClipboard.getInstance();
    @SuppressWarnings("unchecked") final List<SolutionBrowserFile> clipboardFileItems = clipBoard.getClipboardItems();
    if (clipboardFileItems != null && clipboardFileItems.size() > 0 && getSolutionPath() != null) {
        String getChildrenUrl = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(getSolutionPath()) + "/tree?depth=1" + "&showHidden=" + // $NON-NLS-1$ //$NON-NLS-2$
        SolutionBrowserPanel.getInstance().getSolutionTree().isShowHiddenFiles();
        RequestBuilder childrenRequestBuilder = new RequestBuilder(RequestBuilder.GET, getChildrenUrl);
        try {
            childrenRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
            childrenRequestBuilder.sendRequest(null, new RequestCallback() {

                @Override
                public void onError(Request getChildrenRequest, Throwable exception) {
                    Window.alert(exception.getLocalizedMessage());
                    event.setMessage(exception.getLocalizedMessage());
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                }

                @Override
                public void onResponseReceived(Request getChildrenRequest, Response getChildrenResponse) {
                    event.setMessage("Click");
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                    boolean cutSameDir = false;
                    if (getChildrenResponse.getStatusCode() >= 200 && getChildrenResponse.getStatusCode() < 300) {
                        boolean promptForOptions = false;
                        Document children = XMLParser.parse(getChildrenResponse.getText());
                        NodeList childrenNameNodes = children.getElementsByTagName(NAME_NODE_TAG);
                        List<String> childNames = new ArrayList<String>();
                        for (int i = 0; i < childrenNameNodes.getLength(); i++) {
                            Node childNameNode = childrenNameNodes.item(i);
                            childNames.add(childNameNode.getFirstChild().getNodeValue());
                        }
                        for (SolutionBrowserFile file : clipboardFileItems) {
                            if (file.getPath() != null) {
                                String pasteFileParentPath = file.getPath();
                                // $NON-NLS-1$
                                String fileNameWithExt = pasteFileParentPath.substring(pasteFileParentPath.lastIndexOf("/") + 1, pasteFileParentPath.length());
                                // $NON-NLS-1$
                                pasteFileParentPath = pasteFileParentPath.substring(0, pasteFileParentPath.lastIndexOf("/"));
                                if (childNames.contains(fileNameWithExt) && !getSolutionPath().equals(pasteFileParentPath)) {
                                    promptForOptions = true;
                                    break;
                                } else if (childNames.contains(fileNameWithExt) && getSolutionPath().equals(pasteFileParentPath) && SolutionBrowserClipboard.getInstance().getClipboardAction() == SolutionBrowserClipboard.ClipboardAction.CUT) {
                                    cutSameDir = true;
                                    break;
                                }
                            }
                        }
                        if (promptForOptions) {
                            final OverwritePromptDialog overwriteDialog = new OverwritePromptDialog();
                            final IDialogCallback callback = new IDialogCallback() {

                                public void cancelPressed() {
                                    event.setMessage("Cancel");
                                    EventBusUtil.EVENT_BUS.fireEvent(event);
                                    overwriteDialog.hide();
                                }

                                public void okPressed() {
                                    performSave(clipBoard, overwriteDialog.getOverwriteMode());
                                }
                            };
                            overwriteDialog.setCallback(callback);
                            overwriteDialog.center();
                        } else {
                            if (!cutSameDir) {
                                performSave(clipBoard, 2);
                            } else {
                                event.setMessage("Cancel");
                                EventBusUtil.EVENT_BUS.fireEvent(event);
                            }
                        }
                    } else {
                        Window.alert(getChildrenResponse.getText());
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.getLocalizedMessage());
        }
    }
}
Also used : SolutionBrowserFile(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile) RequestBuilder(com.google.gwt.http.client.RequestBuilder) NodeList(com.google.gwt.xml.client.NodeList) Node(com.google.gwt.xml.client.Node) Request(com.google.gwt.http.client.Request) Document(com.google.gwt.xml.client.Document) IDialogCallback(org.pentaho.gwt.widgets.client.dialogs.IDialogCallback) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) OverwritePromptDialog(org.pentaho.mantle.client.dialogs.OverwritePromptDialog) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(com.google.gwt.xml.client.NodeList) SolutionBrowserClipboard(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserClipboard)

Example 57 with RequestBuilder

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

the class RestoreFileCommand method performRestoreToHomeFolder.

private void performRestoreToHomeFolder(final String filesList, final int restoreResponseStatusCode, final String userHomeFolderPath, final SolutionFileActionEvent event) {
    final String encodedUserHomeFolderPath = SolutionBrowserPanel.pathToId(userHomeFolderPath);
    String fileListDescription = "files";
    // if there is one file
    if (filesList.split(",").length == 1) {
        fileListDescription = "file";
    }
    HTML messageTextBox = new HTML();
    String cannotRestoreToOrigFolder = Messages.getString("cannotRestoreToOriginFolder", fileListDescription);
    String restoreToHomeFolder = Messages.getString("restoreToHomeFolder", userHomeFolderPath);
    messageTextBox.setHTML(cannotRestoreToOrigFolder + "<br> <br>" + restoreToHomeFolder + "<br>");
    final PromptDialogBox restoreFileWarningDialogBox = new PromptDialogBox(Messages.getString("couldNotWriteToFolder"), "Restore File", "Cancel", true, true);
    restoreFileWarningDialogBox.setContent(messageTextBox);
    final IDialogCallback callback = new IDialogCallback() {

        public void cancelPressed() {
            restoreFileWarningDialogBox.hide();
        }

        public void okPressed() {
            // files in homeFolder with same names
            if (restoreResponseStatusCode == Response.SC_CONFLICT) {
                final OverwritePromptDialog overwriteDialog = new OverwritePromptDialog();
                final IDialogCallback callback = new IDialogCallback() {

                    public void cancelPressed() {
                        event.setMessage("Cancel");
                        overwriteDialog.hide();
                    }

                    public void okPressed() {
                        // $NON-NLS-1$
                        String restoreFilesUrl = contextURL + "api/repo/files/restore?overwriteMode=" + overwriteDialog.getOverwriteMode();
                        RequestBuilder builder = new RequestBuilder(RequestBuilder.PUT, restoreFilesUrl);
                        try {
                            builder.sendRequest(filesList, new RequestCallback() {

                                @Override
                                public void onResponseReceived(Request request, Response response) {
                                    if (response.getStatusCode() == Response.SC_OK) {
                                        new RefreshRepositoryCommand().execute(false);
                                        event.setMessage("Success");
                                        EventBusUtil.EVENT_BUS.fireEvent(event);
                                    } else {
                                        showErrorDialogBox(event);
                                    }
                                }

                                @Override
                                public void onError(Request request, Throwable exception) {
                                    showErrorDialogBox(event);
                                }
                            });
                        } catch (RequestException e) {
                            showErrorDialogBox(event);
                        }
                    }
                };
                overwriteDialog.setCallback(callback);
                overwriteDialog.center();
            } else if (restoreResponseStatusCode == Response.SC_NOT_ACCEPTABLE) {
                String moveFilesURL = contextURL + "api/repo/files/" + encodedUserHomeFolderPath + "/move";
                RequestBuilder builder = new RequestBuilder(RequestBuilder.PUT, moveFilesURL);
                try {
                    builder.sendRequest(filesList, new RequestCallback() {

                        @Override
                        public void onResponseReceived(Request request, Response response) {
                            new RefreshRepositoryCommand().execute(false);
                            event.setMessage("Success");
                            EventBusUtil.EVENT_BUS.fireEvent(event);
                        }

                        @Override
                        public void onError(Request request, Throwable exception) {
                            showErrorDialogBox(event);
                        }
                    });
                } catch (RequestException e) {
                    showErrorDialogBox(event);
                }
            }
        }
    };
    restoreFileWarningDialogBox.setCallback(callback);
    restoreFileWarningDialogBox.center();
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) PromptDialogBox(org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox) Request(com.google.gwt.http.client.Request) HTML(com.google.gwt.user.client.ui.HTML) IDialogCallback(org.pentaho.gwt.widgets.client.dialogs.IDialogCallback) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) OverwritePromptDialog(org.pentaho.mantle.client.dialogs.OverwritePromptDialog)

Example 58 with RequestBuilder

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

the class RestoreFileCommand method execute.

/*
   * (non-Javadoc)
   * 
   * @see com.google.gwt.user.client.Command#execute()
   */
@Override
public void execute() {
    final SolutionFileActionEvent event = new SolutionFileActionEvent();
    event.setAction(this.getClass().getName());
    String temp = "";
    if (repositoryFiles != null) {
        for (RepositoryFile repoFile : repositoryFiles) {
            // $NON-NLS-1$
            temp += repoFile.getId() + ",";
        }
    }
    // Add file names from js
    temp = temp + fileList;
    // remove trailing ","
    temp = temp.substring(0, temp.length() - 1);
    final String filesList = temp;
    // $NON-NLS-1$
    String deleteFilesURL = contextURL + "api/repo/files/restore";
    RequestBuilder deleteFilesRequestBuilder = new RequestBuilder(RequestBuilder.PUT, deleteFilesURL);
    // $NON-NLS-1$//$NON-NLS-2$
    deleteFilesRequestBuilder.setHeader("Content-Type", "text/plain");
    deleteFilesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        deleteFilesRequestBuilder.sendRequest(filesList, new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
                MessageDialogBox dialogBox = new MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
                Messages.getString("cannotRestore"), // $NON-NLS-1$ //$NON-NLS-2$
                Messages.getString("couldNotRestoreItem", type), false, false, true);
                dialogBox.center();
                event.setMessage("cannotRestore");
                EventBusUtil.EVENT_BUS.fireEvent(event);
            }

            @Override
            public void onResponseReceived(final Request request, final Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    new RefreshRepositoryCommand().execute(false);
                    event.setMessage("Success");
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                } else if (response.getStatusCode() == Response.SC_CONFLICT || response.getStatusCode() == Response.SC_NOT_ACCEPTABLE) {
                    final int restoreResponseStatusCode = response.getStatusCode();
                    final String userHomeDirUrl = GWT.getHostPageBaseURL() + "api/session/userWorkspaceDir";
                    final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, userHomeDirUrl);
                    try {
                        // Get user home folder string
                        builder.sendRequest("", new RequestCallback() {

                            @Override
                            public void onResponseReceived(final Request request, final Response response) {
                                if (response.getStatusCode() == 200) {
                                    // API returns /user/home_folder/workspace
                                    String userHomeFolderPath = response.getText().replaceAll("/workspace", "");
                                    performRestoreToHomeFolder(filesList, restoreResponseStatusCode, userHomeFolderPath, event);
                                }
                            }

                            @Override
                            public void onError(Request request, Throwable exception) {
                                showErrorDialogBox(event);
                            }
                        });
                    } catch (RequestException e) {
                        showErrorDialogBox(event);
                    }
                } else {
                    MessageDialogBox dialogBox = new MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("cannotRestore"), // $NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("couldNotRestoreItem", type), false, false, true, Messages.getString("close"));
                    dialogBox.center();
                    event.setMessage("Success");
                    FileChooserDialog.setIsDirty(Boolean.TRUE);
                    setBrowseRepoDirty(Boolean.TRUE);
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                }
            }
        });
    } catch (RequestException e) {
        showErrorDialogBox(event);
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) Request(com.google.gwt.http.client.Request) SolutionFileActionEvent(org.pentaho.mantle.client.events.SolutionFileActionEvent) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)

Example 59 with RequestBuilder

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

the class RefreshSystemSettingsCommand method performOperation.

protected void performOperation() {
    // $NON-NLS-1$
    final String url = GWT.getHostPageBaseURL() + "api/system/refresh/systemSettings";
    RequestBuilder requestBuilder = new CsrfRequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("accept", "text/plain");
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            // showError(exception);
            }

            public void onResponseReceived(Request request, Response response) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("info"), Messages.getString("refreshSystemSettingsSuccess"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
                true);
                dialogBox.center();
            }
        });
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    // 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) 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 60 with RequestBuilder

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

the class RunInBackgroundCommand method checkSchedulePermissionAndDialog.

protected void checkSchedulePermissionAndDialog() {
    // $NON-NLS-1$
    final String url = getFullyQualifiedURL() + "api/scheduler/isScheduleAllowed?id=" + repositoryFile.getRepositoryFile().getId();
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("accept", "text/plain");
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    final MessageDialogBox errorDialog = new MessageDialogBox(Messages.getString("error"), Messages.getString("noSchedulePermission"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
    true);
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable caught) {
                errorDialog.center();
            }

            public void onResponseReceived(Request request, Response response) {
                if ("true".equalsIgnoreCase(response.getText())) {
                    showDialog(true);
                } else {
                    errorDialog.center();
                }
            }
        });
    } catch (RequestException re) {
        errorDialog.center();
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) JSONString(com.google.gwt.json.client.JSONString) RequestException(com.google.gwt.http.client.RequestException)

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