Search in sources :

Example 1 with BlueFavorite

use of io.jenkins.blueocean.rest.model.BlueFavorite 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) {
        UserImpl blueUser = new UserImpl(jenkinsUser);
        BlueFavoriteContainer favoritesContainer = blueUser.getFavorites();
        if (favoritesContainer != null) {
            JSONArray favorites = new JSONArray();
            Iterator<BlueFavorite> favoritesIterator = favoritesContainer.iterator();
            while (favoritesIterator.hasNext()) {
                Reachable favorite = favoritesIterator.next();
                try {
                    favorites.add(JSONObject.fromObject(ModelObjectSerializer.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(), 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) UserImpl(io.jenkins.blueocean.service.embedded.rest.UserImpl) JSONArray(net.sf.json.JSONArray) Reachable(io.jenkins.blueocean.rest.Reachable) IOException(java.io.IOException)

Example 2 with BlueFavorite

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

the class FavoriteContainerImpl method iterator.

@Override
public Iterator<BlueFavorite> iterator() {
    List<BlueFavorite> favorites = new ArrayList<>();
    Jenkins j = Jenkins.getInstance();
    for (final Item favorite : Favorites.getFavorites(user.user)) {
        if (favorite instanceof AbstractFolder) {
            continue;
        }
        BlueFavorite blueFavorite = FavoriteUtil.getFavorite(favorite);
        if (blueFavorite != null) {
            favorites.add(blueFavorite);
        }
    }
    return favorites.iterator();
}
Also used : Jenkins(jenkins.model.Jenkins) Item(hudson.model.Item) BlueFavorite(io.jenkins.blueocean.rest.model.BlueFavorite) AbstractFolder(com.cloudbees.hudson.plugins.folder.AbstractFolder) ArrayList(java.util.ArrayList)

Aggregations

BlueFavorite (io.jenkins.blueocean.rest.model.BlueFavorite)2 AbstractFolder (com.cloudbees.hudson.plugins.folder.AbstractFolder)1 Item (hudson.model.Item)1 User (hudson.model.User)1 Reachable (io.jenkins.blueocean.rest.Reachable)1 BlueFavoriteContainer (io.jenkins.blueocean.rest.model.BlueFavoriteContainer)1 UserImpl (io.jenkins.blueocean.service.embedded.rest.UserImpl)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Jenkins (jenkins.model.Jenkins)1 JSONArray (net.sf.json.JSONArray)1