Пример #1
0
  public void getRepo(String repoUri) {
    // Send request to server and catch any errors.
    this.lastRepoURI = repoUri;
    // this.lastPrefix = null;
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, repoUri);
    try {
      Request request =
          builder.sendRequest(
              null,
              new RequestCallback() {
                public void onError(Request request, Throwable exception) {
                  // displayError("Couldn't retrieve JSON "+exception.getMessage());
                }

                public void onResponseReceived(Request request, Response response) {
                  GWT.log(response.getStatusCode() + " " + response.getText());
                  if (200 == response.getStatusCode()) {
                    Repository repo = Repository.asRepository(response.getText());
                    updateRepo(repo);
                  } else {
                    Window.alert(
                        "Update failure: " + response.getStatusText() + " " + response.getText());
                  }
                }
              });
    } catch (RequestException e) {
      Window.alert("Update exception: " + e.toString());
    }
  }
Пример #2
0
  public void deleteFolder(final FileNode object) {
    String filename = getCanonicalName(object);

    String url = this.repo.getUri() + "/folder?filename=" + URL.encodeQueryString(filename);
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.DELETE, url);
    try {
      Request request =
          builder.sendRequest(
              null,
              new RequestCallback() {
                public void onError(Request request, Throwable exception) {
                  // displayError("Couldn't retrieve JSON "+exception.getMessage());
                }

                public void onResponseReceived(Request request, Response response) {
                  GWT.log(response.getStatusCode() + " " + response.getText());
                  if (200 != response.getStatusCode()) {
                    Window.alert(
                        "Delete failure: " + response.getStatusText() + " " + response.getText());
                  }
                }
              });
    } catch (RequestException e) {
      Window.alert("Delete exception: " + e.toString());
    }
  }
Пример #3
0
  /** @param node */
  public void makePublic(final FileNode node, boolean isPublic) {
    String url = node.getRepository() + "/permissions";
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url);
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    StringBuilder args = new StringBuilder();
    args.append("isPublic=");
    args.append(URL.encodeQueryString(Boolean.toString(isPublic)));
    args.append("&filename=");
    args.append(URL.encodeQueryString(getCanonicalName(node)));
    try {
      Request request =
          builder.sendRequest(
              args.toString(),
              new RequestCallback() {
                public void onError(Request request, Throwable exception) {
                  // displayError("Couldn't retrieve JSON "+exception.getMessage());
                }

                public void onResponseReceived(Request request, Response response) {
                  GWT.log("Got reply");
                  if (200 == response.getStatusCode()) {
                    GWT.log("Reply is" + response.getText());
                    GWT.log("Headers is " + response.getHeadersAsString());
                    GWT.log("Status Text " + response.getStatusText());
                    fetchFiles(repositoryUri, node.getPath());
                  } else {
                    Window.alert(
                        "Update failure: " + response.getStatusText() + " " + response.getText());
                  }
                }
              });
    } catch (RequestException e) {
      Window.alert("Update exception: " + e.toString());
    }
  }
Пример #4
0
  /** @param view */
  public void fetchFiles(String repoURI, final String prefix) {
    String url = repoURI + "/list";
    if (prefix != null) {
      url += "?prefix=" + URL.encodeQueryString(prefix);
    }
    this.lastRepoURI = repoURI;
    this.lastPrefix = prefix;
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
      builder.sendRequest(
          null,
          new RequestCallback() {

            public void onError(Request request, Throwable exception) {
              GWT.log("Couldn't retrieve JSON " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
              if (200 == response.getStatusCode()) {
                GWT.log(response.getText());
                RepoListResponse result = RepoListResponse.parseJSON(response.getText());
                List<FileNode> crumbs = result.getCrumbs();
                List<FileNode> namesWithPlaceholders = result.getFiles();
                if (crumbs != null && placeholderMap != null) {
                  String lastPath = "";
                  if (crumbs.size() > 1) {
                    FileNode lastCrumb = crumbs.get(crumbs.size() - 1);
                    lastPath = getCanonicalName(lastCrumb) + "/";
                  }
                  GWT.log("lastPath=" + lastPath);
                  if (placeholderMap.containsKey(lastPath)) {
                    java.util.Collection<FileNode> placeholders =
                        placeholderMap.get(lastPath).values();
                    namesWithPlaceholders =
                        new ArrayList<FileNode>(placeholders.size() + result.getFiles().size());
                    GWT.log("adding placeholder");
                    namesWithPlaceholders.addAll(placeholders);
                    namesWithPlaceholders.addAll(result.getFiles());
                  }
                }
                updateRepoContent(result.getCrumbs(), namesWithPlaceholders);
              } else {
                GWT.log("Couldn't retrieve JSON (" + response.getStatusText() + ")");
              }
            }
          });
    } catch (RequestException e) {
      GWT.log("Couldn't retrieve JSON " + e.getMessage());
    }
  }
Пример #5
0
  /**
   * @param node
   * @param originPanel
   */
  public void getSignature(final String file) {

    String url = this.repo.getUri() + "/sign?name=" + URL.encodeQueryString(file);
    final String uri = this.repositoryUri;

    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
      Request request =
          builder.sendRequest(
              null,
              new RequestCallback() {
                public void onError(Request request, Throwable exception) {
                  // displayError("Couldn't retrieve JSON "+exception.getMessage());
                }

                public void onResponseReceived(Request request, Response response) {
                  GWT.log(response.getStatusCode() + " " + response.getText());
                  if (200 == response.getStatusCode()) {
                    if (uri.equals(RepoContentActivity.this.repositoryUri)) {
                      UploadSignature signature =
                          UploadSignature.asUploadSignature(response.getText());
                      provideSignature(signature);
                    }
                  } else {
                    Window.alert(
                        "Signature fetch failure: "
                            + response.getStatusText()
                            + " "
                            + response.getText());
                  }
                }
              });
    } catch (RequestException e) {
      Window.alert("Signature fetch exception: " + e.toString());
    }
  }
Пример #6
0
  /**
   * @param node
   * @param fileDetailsPanel
   */
  public void getOrigin(final FileNode node, final FileDetailsPanel fileDetailsPanel) {

    String url =
        node.getRepository() + "/origin" + "?name=" + URL.encodeQueryString(node.getName());
    if (!isNullOrBlank(node.getPath())) {
      url += "&path=" + URL.encodeQueryString(node.getPath());
    }

    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
      Request request =
          builder.sendRequest(
              null,
              new RequestCallback() {
                public void onError(Request request, Throwable exception) {
                  // displayError("Couldn't retrieve JSON "+exception.getMessage());
                }

                public void onResponseReceived(Request request, Response response) {
                  GWT.log(response.getStatusCode() + " " + response.getText());
                  if (200 == response.getStatusCode()) {
                    Origin origin = Origin.asOrigin(response.getText());
                    provideOrigin(node, origin, fileDetailsPanel);
                  } else {
                    Window.alert(
                        "Origin fetch failure: "
                            + response.getStatusText()
                            + " "
                            + response.getText());
                  }
                }
              });
    } catch (RequestException e) {
      Window.alert("Origin fetch exception: " + e.toString());
    }
  }
Пример #7
0
  private void updateRepoDetails(
      String url,
      String name,
      String description,
      String target,
      String kind,
      String root,
      boolean isPublic,
      String authId,
      String password) {

    if (url == null || url.trim().length() == 0) {
      url = cacheManager.ServiceAddress + "repository";
    }
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url);
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    StringBuilder args = new StringBuilder();
    args.append("name=");
    args.append(URL.encodeQueryString(name));
    if (description != null && description.length() != 0) {
      args.append("&description=");
      args.append(URL.encodeQueryString(description));
    }
    args.append("&target=");
    args.append(URL.encodeQueryString(target));
    args.append("&kind=");
    args.append(URL.encodeQueryString(kind));
    args.append("&root=");
    args.append(URL.encodeQueryString(root));
    args.append("&isPublic=");
    args.append(URL.encode(isPublic ? "true" : "false"));
    if (password != null && password.length() > 0) {
      args.append("&repositoryId=");
      args.append(URL.encodeQueryString(authId));
      args.append("&secret=");
      args.append(URL.encodeQueryString(password));
    }
    GWT.log(args.toString());
    GWT.log(authId);
    GWT.log(password);
    try {
      Request request =
          builder.sendRequest(
              args.toString(),
              new RequestCallback() {
                public void onError(Request request, Throwable exception) {
                  // displayError("Couldn't retrieve JSON "+exception.getMessage());
                }

                public void onResponseReceived(Request request, Response response) {
                  GWT.log("Got reply");
                  if (200 == response.getStatusCode()) {
                    goToPrevious();
                  } else if (201 == response.getStatusCode()) {
                    goToPrevious();
                  } else {
                    Window.alert(
                        "Repository update error "
                            + response.getStatusText()
                            + " "
                            + response.getText());
                  }
                }
              });
    } catch (RequestException e) {
      // displayError("Couldn't retrieve JSON "+e.getMessage());
    }
  }