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

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

本文整理了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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. /**
  2. * Update a Merge Request Note
  3. *
  4. * @param mergeRequest The merge request
  5. * @param noteId The id of the note
  6. * @param body The content of the note
  7. * @return the Gitlab Note
  8. * @throws IOException on gitlab api call error
  9. */
  10. public GitlabNote updateNote(GitlabMergeRequest mergeRequest, Integer noteId, String body) throws IOException {
  11. Query query = new Query()
  12. .appendIf("body", body);
  13. String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() +
  14. GitlabMergeRequest.URL + "/" + mergeRequest.getIid() + GitlabNote.URL + "/" + noteId + query.toString();
  15. return retrieve().method(PUT).to(tailUrl, GitlabNote.class);
  16. }

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

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

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

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

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

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

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

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

相关文章