Search in sources :

Example 1 with BbServerUser

use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerUser in project blueocean-plugin by jenkinsci.

the class BitbucketServerApi method getOrgs.

@Override
@Nonnull
public BbPage<BbOrg> getOrgs(int pageNumber, int pageSize) {
    try {
        if (pageNumber <= 0) {
            pageNumber = 1;
        }
        if (pageSize <= 0) {
            pageSize = PagedResponse.DEFAULT_LIMIT;
        }
        InputStream inputStream = request.get(String.format("%s?start=%s&limit=%s", baseUrl + "projects/", toStart(pageNumber, pageSize), pageSize)).getContent();
        BbPage<BbOrg> page = om.readValue(inputStream, new TypeReference<BbServerPage<BbServerProject>>() {
        });
        if (pageNumber == 1) {
            // add user org as the first org on first page
            BbServerUser user = getUser(userName);
            List<BbOrg> teams = new ArrayList<>();
            teams.add(user.toPersonalProject());
            teams.addAll(page.getValues());
            return new BbServerPage<>(page.getStart(), page.getLimit(), page.getSize() + 1, teams, page.isLastPage());
        }
        return page;
    } catch (IOException e) {
        throw handleException(e);
    }
}
Also used : BbServerPage(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerPage) InputStream(java.io.InputStream) BbServerUser(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerUser) ArrayList(java.util.ArrayList) BbOrg(io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbOrg) IOException(java.io.IOException) Nonnull(javax.annotation.Nonnull)

Aggregations

BbOrg (io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbOrg)1 BbServerPage (io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerPage)1 BbServerUser (io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerUser)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1