Search in sources :

Example 1 with GsonMultipleObjectsDeserializer

use of com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonMultipleObjectsDeserializer in project intellij-community by JetBrains.

the class GitlabRepository method fetchProjects.

/**
   * Always forcibly attempts do fetch new projects from server.
   */
@NotNull
public List<GitlabProject> fetchProjects() throws Exception {
    final ResponseHandler<List<GitlabProject>> handler = new GsonMultipleObjectsDeserializer<>(GSON, LIST_OF_PROJECTS_TYPE);
    final String projectUrl = getRestApiUrl("projects");
    final List<GitlabProject> result = new ArrayList<>();
    int pageNum = 1;
    while (true) {
        final URI paginatedProjectsUrl = new URIBuilder(projectUrl).addParameter("page", String.valueOf(pageNum)).addParameter("per_page", "30").build();
        final List<GitlabProject> page = getHttpClient().execute(new HttpGet(paginatedProjectsUrl), handler);
        // Gitlab's REST API doesn't allow to know beforehand how many projects are available
        if (page.isEmpty()) {
            break;
        }
        result.addAll(page);
        pageNum++;
    }
    myProjects = result;
    return Collections.unmodifiableList(myProjects);
}
Also used : GitlabProject(com.intellij.tasks.gitlab.model.GitlabProject) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) GsonMultipleObjectsDeserializer(com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonMultipleObjectsDeserializer) ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GsonMultipleObjectsDeserializer

use of com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonMultipleObjectsDeserializer in project intellij-community by JetBrains.

the class GitlabRepository method fetchIssues.

@NotNull
public List<GitlabIssue> fetchIssues(int pageNumber, int pageSize, boolean openedOnly) throws Exception {
    ensureProjectsDiscovered();
    final URIBuilder uriBuilder = new URIBuilder(getIssuesUrl()).addParameter("page", String.valueOf(pageNumber)).addParameter("per_page", String.valueOf(pageSize)).addParameter("order_by", "updated_at");
    if (openedOnly) {
        // Filtering by state was added in v7.3
        uriBuilder.addParameter("state", "opened");
    }
    final ResponseHandler<List<GitlabIssue>> handler = new GsonMultipleObjectsDeserializer<>(GSON, LIST_OF_ISSUES_TYPE);
    return getHttpClient().execute(new HttpGet(uriBuilder.build()), handler);
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) GsonMultipleObjectsDeserializer(com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonMultipleObjectsDeserializer) ArrayList(java.util.ArrayList) List(java.util.List) URIBuilder(org.apache.http.client.utils.URIBuilder) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GsonMultipleObjectsDeserializer (com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonMultipleObjectsDeserializer)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 HttpGet (org.apache.http.client.methods.HttpGet)2 URIBuilder (org.apache.http.client.utils.URIBuilder)2 NotNull (org.jetbrains.annotations.NotNull)2 GitlabProject (com.intellij.tasks.gitlab.model.GitlabProject)1 URI (java.net.URI)1