Search in sources :

Example 1 with JsonToRepositoryFileTreeConverter

use of org.pentaho.gwt.widgets.client.filechooser.JsonToRepositoryFileTreeConverter 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)

Aggregations

Request (com.google.gwt.http.client.Request)1 RequestBuilder (com.google.gwt.http.client.RequestBuilder)1 RequestCallback (com.google.gwt.http.client.RequestCallback)1 RequestException (com.google.gwt.http.client.RequestException)1 Response (com.google.gwt.http.client.Response)1 JsonToRepositoryFileTreeConverter (org.pentaho.gwt.widgets.client.filechooser.JsonToRepositoryFileTreeConverter)1 RepositoryFile (org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)1 RepositoryFileTree (org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree)1