Search in sources :

Example 6 with DefaultMarketplaceService

use of org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService in project epp.mpc by eclipse.

the class DefaultMarketplaceServiceTest method computeRelativeSearchUrl.

/**
 * bug 302825 - Make sure that search URLs have the following form:<br/>
 * <code>http://marketplace.eclipse.org/api/p/search/apachesolr_search/WikiText?filters=tid:38%20tid:31</code>
 * <p>
 * bug 397004 - If both market and category are provided, make sure market is listed first
 */
@Test
public void computeRelativeSearchUrl() {
    DefaultMarketplaceService service = new DefaultMarketplaceService();
    String marketId = "31";
    String categoryId = "38";
    String query = "some query";
    Market market = new Market();
    market.setId(marketId);
    Category category = new Category();
    category.setId(categoryId);
    String apiSearchPrefix = DefaultMarketplaceService.API_SEARCH_URI_FULL;
    String searchUrl = service.computeRelativeSearchUrl(null, null, query, true);
    assertEquals(apiSearchPrefix + "some+query", searchUrl);
    searchUrl = service.computeRelativeSearchUrl(market, null, query, true);
    assertEquals(apiSearchPrefix + "some+query?filters=tid:" + marketId, searchUrl);
    searchUrl = service.computeRelativeSearchUrl(null, category, query, true);
    assertEquals(apiSearchPrefix + "some+query?filters=tid:" + categoryId, searchUrl);
    // bug 397004 - make sure market comes first for api
    searchUrl = service.computeRelativeSearchUrl(market, category, query, true);
    assertEquals(apiSearchPrefix + "some+query?filters=tid:" + marketId + "%20tid:" + categoryId, searchUrl);
    // bug 397004 - make sure category comes first for browser
    searchUrl = service.computeRelativeSearchUrl(market, category, query, false);
    assertEquals(DefaultMarketplaceService.API_SEARCH_URI + "some+query?filters=tid:" + categoryId + "%20tid:" + marketId, searchUrl);
    searchUrl = service.computeRelativeSearchUrl(market, null, null, true);
    assertEquals(DefaultMarketplaceService.API_TAXONOMY_URI + marketId + "/" + RemoteMarketplaceService.API_URI_SUFFIX, searchUrl);
    searchUrl = service.computeRelativeSearchUrl(null, category, null, false);
    assertEquals(DefaultMarketplaceService.API_TAXONOMY_URI + categoryId, searchUrl);
    // taxonomy uri is category-first for both API and browser
    searchUrl = service.computeRelativeSearchUrl(market, category, null, true);
    assertEquals(DefaultMarketplaceService.API_TAXONOMY_URI + categoryId + "," + marketId + "/" + RemoteMarketplaceService.API_URI_SUFFIX, searchUrl);
    searchUrl = service.computeRelativeSearchUrl(market, category, null, false);
    assertEquals(DefaultMarketplaceService.API_TAXONOMY_URI + categoryId + "," + marketId, searchUrl);
}
Also used : Category(org.eclipse.epp.internal.mpc.core.model.Category) ICategory(org.eclipse.epp.mpc.core.model.ICategory) DefaultMarketplaceService(org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService) Market(org.eclipse.epp.internal.mpc.core.model.Market) IMarket(org.eclipse.epp.mpc.core.model.IMarket) Test(org.junit.Test)

Example 7 with DefaultMarketplaceService

use of org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService in project epp.mpc by eclipse.

the class BrowseCatalogItem method getMarketplaceUrl.

private static String getMarketplaceUrl(CatalogDescriptor catalogDescriptor, MarketplaceViewer viewer) throws URISyntaxException {
    URL url = catalogDescriptor.getUrl();
    try {
        ContentType contentType = viewer.getQueryContentType();
        if (contentType == ContentType.SEARCH) {
            String queryText = viewer.getQueryText();
            ICategory queryCategory = viewer.getQueryCategory();
            IMarket queryMarket = viewer.getQueryMarket();
            String path = new DefaultMarketplaceService(url).computeRelativeSearchUrl(queryMarket, queryCategory, queryText, false);
            if (path != null) {
                url = new URL(url, path);
            }
        }
    } catch (IllegalArgumentException e) {
        // should never happen
        MarketplaceClientUi.error(e);
    } catch (MalformedURLException e) {
        // should never happen
        MarketplaceClientUi.error(e);
    }
    URI uri = url.toURI();
    return uri.toString();
}
Also used : MalformedURLException(java.net.MalformedURLException) ContentType(org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceViewer.ContentType) ICategory(org.eclipse.epp.mpc.core.model.ICategory) DefaultMarketplaceService(org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService) IMarket(org.eclipse.epp.mpc.core.model.IMarket) URI(java.net.URI) URL(java.net.URL)

Aggregations

DefaultMarketplaceService (org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService)7 URL (java.net.URL)5 ICategory (org.eclipse.epp.mpc.core.model.ICategory)3 IMarket (org.eclipse.epp.mpc.core.model.IMarket)3 IMarketplaceService (org.eclipse.epp.mpc.core.service.IMarketplaceService)3 Before (org.junit.Before)3 MalformedURLException (java.net.MalformedURLException)2 Test (org.junit.Test)2 URI (java.net.URI)1 Map (java.util.Map)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Category (org.eclipse.epp.internal.mpc.core.model.Category)1 Market (org.eclipse.epp.internal.mpc.core.model.Market)1 Node (org.eclipse.epp.internal.mpc.core.model.Node)1 CachingMarketplaceService (org.eclipse.epp.internal.mpc.core.service.CachingMarketplaceService)1 MarketplaceCatalog (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog)1 MarketplaceDiscoveryStrategy (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy)1 InstallProfile (org.eclipse.epp.internal.mpc.ui.wizards.InstallProfile)1 ContentType (org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceViewer.ContentType)1