Search in sources :

Example 1 with BlueFavoriteContainer

use of io.jenkins.blueocean.rest.model.BlueFavoriteContainer in project blueocean-plugin by jenkinsci.

the class FavoritesStatePreloader method getFetchData.

@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
    User jenkinsUser = User.current();
    if (jenkinsUser != null) {
        BlueOrganization organization = IterableUtils.getFirst(OrganizationFactory.getInstance().list(), null);
        if (organization != null) {
            String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
            // don't need this list when at pipeline pages
            if (pipelineFullName != null) {
                return null;
            }
            UserImpl blueUser = new UserImpl(organization, jenkinsUser, organization.getUsers());
            BlueFavoriteContainer favoritesContainer = blueUser.getFavorites();
            if (favoritesContainer != null) {
                JSONArray favorites = new JSONArray();
                // Limit the number of favorites to return to a sane amount
                Iterator<BlueFavorite> favoritesIterator = favoritesContainer.iterator(0, DEFAULT_LIMIT);
                while (favoritesIterator.hasNext()) {
                    Reachable favorite = favoritesIterator.next();
                    try {
                        favorites.add(JSONObject.fromObject(Export.toJson(favorite)));
                    } catch (IOException e) {
                        LOGGER.log(Level.FINE, String.format("Unable to preload favorites for User '%s'. Serialization error.", jenkinsUser.getFullName()), e);
                        return null;
                    }
                }
                return new FetchData(favoritesContainer.getLink().getHref() + "?start=0&limit=" + DEFAULT_LIMIT, favorites.toString());
            }
        }
    }
    // Don't preload any data on the page.
    return null;
}
Also used : BlueFavoriteContainer(io.jenkins.blueocean.rest.model.BlueFavoriteContainer) BlueFavorite(io.jenkins.blueocean.rest.model.BlueFavorite) User(hudson.model.User) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) UserImpl(io.jenkins.blueocean.service.embedded.rest.UserImpl) JSONArray(net.sf.json.JSONArray) Reachable(io.jenkins.blueocean.rest.Reachable) IOException(java.io.IOException)

Aggregations

User (hudson.model.User)1 Reachable (io.jenkins.blueocean.rest.Reachable)1 BlueFavorite (io.jenkins.blueocean.rest.model.BlueFavorite)1 BlueFavoriteContainer (io.jenkins.blueocean.rest.model.BlueFavoriteContainer)1 BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)1 UserImpl (io.jenkins.blueocean.service.embedded.rest.UserImpl)1 IOException (java.io.IOException)1 JSONArray (net.sf.json.JSONArray)1