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;
}
Aggregations