Search in sources :

Example 16 with ICategory

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

the class UnmarshallerTest method marketplaceRoot.

@Test
public void marketplaceRoot() throws IOException, UnmarshalException {
    // from http://www.eclipseplugincentral.net/xml
    Object model = processResource("resources/marketplace-root.xml");
    assertNotNull(model);
    assertTrue(model instanceof Marketplace);
    Marketplace marketplace = (Marketplace) model;
    assertEquals(4, marketplace.getMarket().size());
    IMarket market = marketplace.getMarket().get(0);
    assertEquals("31", market.getId());
    assertEquals("Tools", market.getName());
    assertEquals("http://www.eclipseplugincentral.net/category/markets/tools", market.getUrl());
    assertEquals(36, market.getCategory().size());
    ICategory category = market.getCategory().get(10);
    assertEquals("24", category.getId());
    assertEquals("IDE", category.getName());
    assertEquals("http://www.eclipseplugincentral.net/taxonomy/term/24%2C31", category.getUrl());
}
Also used : Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace) ICategory(org.eclipse.epp.mpc.core.model.ICategory) IMarket(org.eclipse.epp.mpc.core.model.IMarket) Test(org.junit.Test)

Example 17 with ICategory

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

the class DefaultMarketplaceService method getCategory.

public Category getCategory(ICategory category, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, 200);
    if (category.getId() != null && category.getUrl() == null) {
        List<Market> markets = listMarkets(progress.newChild(50));
        ICategory resolvedCategory = null;
        outer: for (Market market : markets) {
            List<Category> categories = market.getCategory();
            for (Category aCategory : categories) {
                if (aCategory.equalsId(category)) {
                    resolvedCategory = aCategory;
                    break outer;
                }
            }
        }
        if (progress.isCanceled()) {
            throw new OperationCanceledException();
        } else if (resolvedCategory == null) {
            throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_categoryNotFound, category.getId()));
        } else {
            return getCategory(resolvedCategory, progress.newChild(150));
        }
    }
    Marketplace marketplace = processRequest(category.getUrl(), API_URI_SUFFIX, progress.newChild(200));
    if (marketplace.getCategory().isEmpty()) {
        throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_categoryNotFound, category.getUrl()));
    } else if (marketplace.getCategory().size() > 1) {
        throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_unexpectedResponse, category.getUrl()));
    }
    Category resolvedCategory = marketplace.getCategory().get(0);
    return resolvedCategory;
}
Also used : Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace) Category(org.eclipse.epp.internal.mpc.core.model.Category) ICategory(org.eclipse.epp.mpc.core.model.ICategory) CoreException(org.eclipse.core.runtime.CoreException) ICategory(org.eclipse.epp.mpc.core.model.ICategory) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) List(java.util.List) IFavoriteList(org.eclipse.epp.mpc.core.model.IFavoriteList) ArrayList(java.util.ArrayList) Market(org.eclipse.epp.internal.mpc.core.model.Market) IMarket(org.eclipse.epp.mpc.core.model.IMarket)

Example 18 with ICategory

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

the class NewsUrlHandler method handleSearch.

@Override
protected boolean handleSearch(CatalogDescriptor descriptor, String url, String searchString, Map<String, String> params) {
    MarketplaceWizard marketplaceWizard = viewer.getWizard();
    // $NON-NLS-1$
    String filterParam = params.get("filter");
    // $NON-NLS-1$
    String[] filters = filterParam.split(" ");
    ICategory searchCategory = null;
    IMarket searchMarket = null;
    for (String filter : filters) {
        if (filter.startsWith("tid:")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String id = filter.substring("tid:".length());
            List<CatalogCategory> catalogCategories = marketplaceWizard.getCatalog().getCategories();
            for (CatalogCategory catalogCategory : catalogCategories) {
                if (catalogCategory instanceof MarketplaceCategory) {
                    MarketplaceCategory marketplaceCategory = (MarketplaceCategory) catalogCategory;
                    List<? extends IMarket> markets = marketplaceCategory.getMarkets();
                    for (IMarket market : markets) {
                        if (id.equals(market.getId())) {
                            searchMarket = market;
                        } else {
                            final List<? extends ICategory> categories = market.getCategory();
                            for (ICategory category : categories) {
                                if (id.equals(category.getId())) {
                                    searchCategory = category;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    marketplaceWizard.getCatalogPage().search(descriptor, searchMarket, searchCategory, searchString);
    return true;
}
Also used : ICategory(org.eclipse.epp.mpc.core.model.ICategory) CatalogCategory(org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory) MarketplaceCategory(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory) IMarket(org.eclipse.epp.mpc.core.model.IMarket)

Example 19 with ICategory

use of org.eclipse.epp.mpc.core.model.ICategory 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)

Example 20 with ICategory

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

the class MarketplaceDiscoveryStrategy method performQuery.

public void performQuery(IMarket market, ICategory category, String queryText, IProgressMonitor monitor) throws CoreException {
    final int totalWork = 1001;
    SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_searchingMarketplace, totalWork);
    try {
        ISearchResult result;
        MarketplaceCategory catalogCategory = findMarketplaceCategory(progress.newChild(1));
        catalogCategory.setContents(Contents.QUERY);
        SubMonitor nodeQueryProgress = progress.newChild(500);
        try {
            // check if the query matches a node url and just retrieve that node
            result = performNodeQuery(queryText, nodeQueryProgress);
        } catch (CoreException ex) {
            // node not found, continue with regular query
            result = null;
            // no work was done
            nodeQueryProgress.setWorkRemaining(0);
        }
        if (result == null) {
            // regular query
            // resolve market and category if necessary
            IMarket resolvedMarket;
            ICategory resolvedCategory;
            try {
                resolvedMarket = resolve(market, catalogCategory.getMarkets());
                resolvedCategory = resolveCategory(category, catalogCategory.getMarkets());
            } catch (IllegalArgumentException ex) {
                throw new CoreException(MarketplaceClientCore.computeStatus(ex, Messages.MarketplaceDiscoveryStrategy_invalidFilter));
            } catch (NoSuchElementException ex) {
                throw new CoreException(MarketplaceClientCore.computeStatus(ex, Messages.MarketplaceDiscoveryStrategy_unknownFilter));
            }
            progress.setWorkRemaining(totalWork - 1);
            result = marketplaceService.search(resolvedMarket, resolvedCategory, queryText, progress.newChild(500));
        }
        handleSearchResult(catalogCategory, result, progress.newChild(500));
        if (result.getNodes().isEmpty()) {
            catalogCategory.setMatchCount(0);
            addCatalogItem(catalogCategory);
        }
    } finally {
        progress.done();
    }
}
Also used : ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) CoreException(org.eclipse.core.runtime.CoreException) ICategory(org.eclipse.epp.mpc.core.model.ICategory) SubMonitor(org.eclipse.core.runtime.SubMonitor) IMarket(org.eclipse.epp.mpc.core.model.IMarket) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

ICategory (org.eclipse.epp.mpc.core.model.ICategory)22 IMarket (org.eclipse.epp.mpc.core.model.IMarket)11 Test (org.junit.Test)10 Marketplace (org.eclipse.epp.internal.mpc.core.model.Marketplace)8 INode (org.eclipse.epp.mpc.core.model.INode)8 ICategories (org.eclipse.epp.mpc.core.model.ICategories)5 ArrayList (java.util.ArrayList)3 NoSuchElementException (java.util.NoSuchElementException)3 CoreException (org.eclipse.core.runtime.CoreException)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 SubMonitor (org.eclipse.core.runtime.SubMonitor)3 Tag (org.eclipse.equinox.internal.p2.discovery.model.Tag)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 DefaultMarketplaceService (org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService)2 ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1