org.gitlab.api.http.Query.appendIf()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中org.gitlab.api.http.Query.appendIf方法的一些代码示例,展示了Query.appendIf的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.appendIf方法的具体详情如下:
包路径:org.gitlab.api.http.Query
类名称:Query
方法名:appendIf

Query.appendIf介绍

[英]Conditionally append a parameter to the query if the value of the parameter is not null
[中]如果参数的值不为null,则有条件地将参数附加到查询中

代码示例

代码示例来源:origin: Argelbargel/gitlab-branch-source-plugin

public List<GitlabRepositoryTree> getTree(int id, String ref, String path) throws GitLabAPIException {
  try {
    Query query = new Query()
        .appendIf("path", path)
        .appendIf("ref_name", ref);
    String tailUrl = GitlabProject.URL + "/" + id + "/repository" + GitlabRepositoryTree.URL + query.toString();
    GitlabRepositoryTree[] tree = delegate.retrieve().to(tailUrl, GitlabRepositoryTree[].class);
    return Arrays.asList(tree);
  } catch (Exception e) {
    throw new GitLabAPIException(e);
  }
}

代码示例来源:origin: timols/java-gitlab-api

/**
 * Get an archive of the repository
 *
 * @param project The Project
 * @param path    The path inside the repository. Used to get content of subdirectories (optional)
 * @param ref     The name of a repository branch or tag or if not given the default branch (optional)
 * @throws IOException on gitlab api call error
 */
public List<GitlabRepositoryTree> getRepositoryTree(GitlabProject project, String path, String ref, boolean recursive) throws IOException {
  Query query = new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery()
      .appendIf("path", path)
      .appendIf("ref", ref)
      .appendIf("recursive", recursive);
  String tailUrl = GitlabProject.URL + "/" + project.getId() + "/repository" + GitlabRepositoryTree.URL + query.toString();
  return retrieve().getAll(tailUrl, GitlabRepositoryTree[].class);
}

代码示例来源:origin: timols/java-gitlab-api

/**
 * Get an archive of the repository
 *
 * @param project The Project
 * @param path    The path inside the repository. Used to get content of subdirectories (optional)
 * @param ref     The name of a repository branch or tag or if not given the default branch (optional)
 * @throws IOException on gitlab api call error
 */
public List<GitlabRepositoryTree> getRepositoryTree(GitlabProject project, String path, String ref, boolean recursive) throws IOException {
  Query query = new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery()
      .appendIf("path", path)
      .appendIf("ref", ref)
      .appendIf("recursive", recursive);
  String tailUrl = GitlabProject.URL + "/" + project.getId() + "/repository" + GitlabRepositoryTree.URL + query.toString();
  return retrieve().getAll(tailUrl, GitlabRepositoryTree[].class);
}

代码示例来源:origin: timols/java-gitlab-api

/**
 * @param namespace The namespace of the fork
 * @param projectId ProjectId of the project forked
 * @return The new Gitlab Project
 * @throws IOException on gitlab api call error
 */
public GitlabProject createFork(String namespace, Integer projectId) throws IOException {
  Query query = new Query()
      .appendIf("namespace", namespace);
  String tailUrl = GitlabProject.URL + "/" + projectId + "/fork" + query.toString();
  return dispatch().to(tailUrl, GitlabProject.class);
}

代码示例来源:origin: timols/java-gitlab-api

/**
 * @param namespace The namespace of the fork
 * @param projectId ProjectId of the project forked
 * @return The new Gitlab Project
 * @throws IOException on gitlab api call error
 */
public GitlabProject createFork(String namespace, Integer projectId) throws IOException {
  Query query = new Query()
      .appendIf("namespace", namespace);
  String tailUrl = GitlabProject.URL + "/" + projectId + "/fork" + query.toString();
  return dispatch().to(tailUrl, GitlabProject.class);
}

代码示例来源:origin: org.gitlab/java-gitlab-api

/**
 * @param namespace The namespace of the fork
 * @param projectId ProjectId of the project forked
 * @return The new Gitlab Project
 * @throws IOException on gitlab api call error
 */
public GitlabProject createFork(String namespace, Integer projectId) throws IOException {
  Query query = new Query()
      .appendIf("namespace", namespace);
  String tailUrl = GitlabProject.URL + "/" + projectId + "/fork" + query.toString();
  return dispatch().to(tailUrl, GitlabProject.class);
}

代码示例来源:origin: bozaro/git-as-svn

@NotNull
private GitlabProject createGitlabProject(@NotNull GitlabAPI rootAPI, @NotNull GitlabGroup group, @NotNull String name, @NotNull GitlabVisibility visibility, @NotNull Set<String> tags) throws IOException {
 // java-gitlab-api doesn't handle tag_list, so we have to do this manually
 final Query query = new Query()
   .append("name", name)
   .appendIf("namespace_id", group.getId())
   .appendIf("visibility", visibility.toString())
   .appendIf("tag_list", String.join(",", tags));
 final String tailUrl = GitlabProject.URL + query.toString();
 return rootAPI.dispatch().to(tailUrl, GitlabProject.class);
}

代码示例来源:origin: timols/java-gitlab-api

@Test
public void conditionalAppend_null_notNull() throws UnsupportedEncodingException {
  Query query = new Query()
      .appendIf("p1", (String) null)
      .appendIf("p2", "v2");
  assertEquals("?p2=v2", query.toString());
}

代码示例来源:origin: timols/java-gitlab-api

@Test
public void conditionalAppend_notNull() throws UnsupportedEncodingException {
  Query query = new Query()
      .appendIf("p1", "v1")
      .appendIf("p2", "v2");
  assertEquals("?p1=v1&p2=v2", query.toString());
}

代码示例来源:origin: timols/java-gitlab-api

/**
 * Creates a Group
 *
 * @param request  An object that represents the parameters for the request.
 * @param sudoUser The user for whom we're creating the group
 * @return The GitLab Group
 * @throws IOException on gitlab api call error
 */
public GitlabGroup createGroup(CreateGroupRequest request, GitlabUser sudoUser) throws IOException {
  Query query = request.toQuery();
  query.appendIf(PARAM_SUDO, sudoUser != null ? sudoUser.getId() : null);
  String tailUrl = GitlabGroup.URL + query.toString();
  return dispatch().to(tailUrl, GitlabGroup.class);
}

代码示例来源:origin: org.gitlab/java-gitlab-api

/**
 * Creates a Group
 *
 * @param request  An object that represents the parameters for the request.
 * @param sudoUser The user for whom we're creating the group
 * @return The GitLab Group
 * @throws IOException on gitlab api call error
 */
public GitlabGroup createGroup(CreateGroupRequest request, GitlabUser sudoUser) throws IOException {
  Query query = request.toQuery();
  query.appendIf(PARAM_SUDO, sudoUser != null ? sudoUser.getId() : null);
  String tailUrl = GitlabGroup.URL + query.toString();
  return dispatch().to(tailUrl, GitlabGroup.class);
}

代码示例来源:origin: timols/java-gitlab-api

/**
 * Creates a Group
 *
 * @param request  An object that represents the parameters for the request.
 * @param sudoUser The user for whom we're creating the group
 * @return The GitLab Group
 * @throws IOException on gitlab api call error
 */
public GitlabGroup createGroup(CreateGroupRequest request, GitlabUser sudoUser) throws IOException {
  Query query = request.toQuery();
  query.appendIf(PARAM_SUDO, sudoUser != null ? sudoUser.getId() : null);
  String tailUrl = GitlabGroup.URL + query.toString();
  return dispatch().to(tailUrl, GitlabGroup.class);
}

代码示例来源:origin: timols/java-gitlab-api

public List<GitlabGroup> getGroupsViaSudo(String username, Pagination pagination) throws IOException {
  String tailUrl = GitlabGroup.URL;
  Query query = new Query()
      .appendIf(PARAM_SUDO, username);
  if (pagination != null) {
    query.mergeWith(pagination.asQuery());
  }
  return retrieve().getAll(tailUrl + query.toString(), GitlabGroup[].class);
}

代码示例来源:origin: timols/java-gitlab-api

public List<GitlabGroup> getGroupsViaSudo(String username, Pagination pagination) throws IOException {
  String tailUrl = GitlabGroup.URL;
  Query query = new Query()
      .appendIf(PARAM_SUDO, username);
  if (pagination != null) {
    query.mergeWith(pagination.asQuery());
  }
  return retrieve().getAll(tailUrl + query.toString(), GitlabGroup[].class);
}

代码示例来源:origin: org.gitlab/java-gitlab-api

public List<GitlabGroup> getGroupsViaSudo(String username, Pagination pagination) throws IOException {
  String tailUrl = GitlabGroup.URL;
  Query query = new Query()
      .appendIf(PARAM_SUDO, username);
  if (pagination != null) {
    query.mergeWith(pagination.asQuery());
  }
  return retrieve().getAll(tailUrl + query.toString(), GitlabGroup[].class);
}

代码示例来源:origin: timols/java-gitlab-api

/**
 * Update a Merge Request Note
 *
 * @param mergeRequest The merge request
 * @param noteId       The id of the note
 * @param body         The content of the note
 * @return the Gitlab Note
 * @throws IOException on gitlab api call error
 */
public GitlabNote updateNote(GitlabMergeRequest mergeRequest, Integer noteId, String body) throws IOException {
  Query query = new Query()
      .appendIf("body", body);
  String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() +
      GitlabMergeRequest.URL + "/" + mergeRequest.getIid() + GitlabNote.URL + "/" + noteId + query.toString();
  return retrieve().method(PUT).to(tailUrl, GitlabNote.class);
}

代码示例来源:origin: timols/java-gitlab-api

@Test
public void conditionalAppend_null() throws UnsupportedEncodingException {
  Query query = new Query()
      .appendIf("p1", (String) null);
  assertEquals("", query.toString());
}

代码示例来源:origin: timols/java-gitlab-api

/**
 * Get a list of projects accessible by the authenticated user.
 *
 * @return A list of gitlab projects
 * @throws IOException on gitlab api call error
 */
public List<GitlabProject> getProjectsViaSudo(GitlabUser user) throws IOException {
  Query query = new Query()
      .appendIf(PARAM_SUDO, user.getId());
  query.mergeWith(new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery());
  String tailUrl = GitlabProject.URL + query.toString();
  return retrieve().getAll(tailUrl, GitlabProject[].class);
}

代码示例来源:origin: timols/java-gitlab-api

/**
 * Get a list of projects accessible by the authenticated user.
 *
 * @return A list of gitlab projects
 * @throws IOException on gitlab api call error
 */
public List<GitlabProject> getProjectsViaSudo(GitlabUser user) throws IOException {
  Query query = new Query()
      .appendIf(PARAM_SUDO, user.getId());
  query.mergeWith(new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery());
  String tailUrl = GitlabProject.URL + query.toString();
  return retrieve().getAll(tailUrl, GitlabProject[].class);
}

代码示例来源:origin: org.gitlab/java-gitlab-api

/**
 * Get a list of projects accessible by the authenticated user.
 *
 * @return A list of gitlab projects
 * @throws IOException on gitlab api call error
 */
public List<GitlabProject> getProjectsViaSudo(GitlabUser user) throws IOException {
  Query query = new Query()
      .appendIf(PARAM_SUDO, user.getId());
  query.mergeWith(new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery());
  String tailUrl = GitlabProject.URL + query.toString();
  return retrieve().getAll(tailUrl, GitlabProject[].class);
}

相关文章

微信公众号

最新文章

更多