Search in sources :

Example 1 with IFavoriteList

use of org.eclipse.epp.mpc.core.model.IFavoriteList in project epp.mpc by eclipse.

the class UserFavoritesServiceTest method testGetRandomFavoriteLists.

@Test
public void testGetRandomFavoriteLists() throws Exception {
    List<IFavoriteList> favoriteLists = favoritesService.getRandomFavoriteLists(null);
    assertNotNull(favoriteLists);
    assertFalse(favoriteLists.isEmpty());
    assertFalse(favoriteLists.contains(null));
    for (IFavoriteList favoriteList : favoriteLists) {
        assertNotNull(favoriteList.getId());
        assertNotNull(favoriteList.getUrl());
        assertEquals(favoriteList.getId().trim(), favoriteList.getId());
        assertEquals(favoriteList.getUrl().trim(), favoriteList.getUrl());
    }
    IFavoriteList favoriteList = favoriteLists.get(0);
    testGetFavoriteIds(favoriteList.getId());
}
Also used : IFavoriteList(org.eclipse.epp.mpc.core.model.IFavoriteList) Test(org.junit.Test)

Example 2 with IFavoriteList

use of org.eclipse.epp.mpc.core.model.IFavoriteList in project epp.mpc by eclipse.

the class UserFavoritesService method getRandomFavoriteLists.

public List<IFavoriteList> getRandomFavoriteLists(IProgressMonitor monitor) throws IOException {
    URI serviceUri = getStorageService().getServiceUri();
    final URI randomFavoritesUri = serviceUri.resolve(RANDOM_FAVORITE_LISTS_ENDPOINT);
    return new AbstractJSONListRequest<IFavoriteList>(randomFavoritesUri, JSON_FAVORITE_LISTS_PATTERN) {

        @Override
        protected IFavoriteList parseListElement(String entryBody) {
            String id = findFavoritesListId(entryBody);
            if (id == null) {
                return null;
            }
            String owner = findFavoritesListOwner(entryBody);
            if (owner == null) {
                owner = id;
            }
            String label = findFavoritesListLabel(entryBody);
            if (label != null && (label.equals(id) || label.equals(owner))) {
                label = null;
            }
            String favoritesListUrl = getFavoritesListUrl(entryBody, id);
            if (favoritesListUrl == null) {
                return null;
            }
            String icon = getAttribute(JSON_OWNER_ICON_ATTRIBUTE_PATTERN, null, entryBody);
            String profileUrl = getAttribute(JSON_OWNER_PROFILE_URL_ATTRIBUTE_PATTERN, null, entryBody);
            IFavoriteList favoritesByUserId = QueryHelper.favoritesByUserId(id);
            ((FavoriteList) favoritesByUserId).setOwner(owner);
            ((FavoriteList) favoritesByUserId).setOwnerProfileUrl(profileUrl);
            ((FavoriteList) favoritesByUserId).setName(label);
            ((FavoriteList) favoritesByUserId).setUrl(favoritesListUrl);
            ((FavoriteList) favoritesByUserId).setIcon(icon);
            return favoritesByUserId;
        }
    }.execute(randomFavoritesUri);
}
Also used : IFavoriteList(org.eclipse.epp.mpc.core.model.IFavoriteList) URI(java.net.URI)

Example 3 with IFavoriteList

use of org.eclipse.epp.mpc.core.model.IFavoriteList in project epp.mpc by eclipse.

the class FavoritesDiscoveryStrategy method addFavoriteListEntries.

private void addFavoriteListEntries(MarketplaceCategory catalogCategory, List<IFavoriteList> userFavoriteLists) {
    if (userFavoriteLists == null || userFavoriteLists.isEmpty()) {
        return;
    }
    catalogCategory.setContents(Contents.FAVORITE_LISTS);
    catalogCategory.setName(Messages.FavoritesDiscoveryStrategy_favoritesCategoryTitle);
    MarketplaceCatalogSource source = this.getCatalogSource();
    int maxCount = Math.min(userFavoriteLists.size(), 5);
    for (int i = 0; i < maxCount; i++) {
        IFavoriteList favoriteList = userFavoriteLists.get(i);
        FavoriteListCatalogItem item = new FavoriteListCatalogItem();
        item.setFavoriteList(favoriteList);
        item.setId(favoriteList.getId());
        item.setName(favoriteList.getName());
        item.setProvider(favoriteList.getOwner());
        String iconUrl = favoriteList.getIcon();
        if (iconUrl != null) {
            if (!source.getResourceProvider().containsResource(iconUrl)) {
                cacheResource(source.getResourceProvider(), item, iconUrl);
            }
            createIcon(item, favoriteList);
        }
        addItem(catalogCategory, item);
    }
}
Also used : IFavoriteList(org.eclipse.epp.mpc.core.model.IFavoriteList)

Aggregations

IFavoriteList (org.eclipse.epp.mpc.core.model.IFavoriteList)3 URI (java.net.URI)1 Test (org.junit.Test)1