Search in sources :

Example 16 with ISearchResult

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

the class DefaultMarketplaceServiceTest method search.

@Test
@org.junit.experimental.categories.Category(RemoteTests.class)
public void search() throws CoreException {
    ISearchResult result = search("Tools", "Editor", "snipmatch");
    assertNotNull(result);
    assertNotNull(result.getNodes());
    assertEquals(Integer.valueOf(1), result.getMatchCount());
    assertEquals(1, result.getNodes().size());
    INode node = result.getNodes().get(0);
    assertTrue(node.getName().startsWith("Snipmatch"));
    assertEquals("1743547", node.getId());
}
Also used : ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) INode(org.eclipse.epp.mpc.core.model.INode) Test(org.junit.Test)

Example 17 with ISearchResult

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

the class DefaultMarketplaceServiceTest method featured.

@Test
@org.junit.experimental.categories.Category(RemoteTests.class)
public void featured() throws CoreException {
    ISearchResult result = marketplaceService.featured(new NullProgressMonitor());
    assertSearchResultSanity(result);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) Test(org.junit.Test)

Example 18 with ISearchResult

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

Example 19 with ISearchResult

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

the class MarketplaceDiscoveryStrategy method performNodeQuery.

private ISearchResult performNodeQuery(String nodeUrl, IProgressMonitor progress) throws CoreException {
    final INode[] queryNode = new INode[1];
    MarketplaceUrlHandler urlHandler = new MarketplaceUrlHandler() {

        @Override
        protected boolean handleNode(CatalogDescriptor descriptor, String url, INode node) {
            queryNode[0] = node;
            return true;
        }
    };
    if (urlHandler.handleUri(nodeUrl) && queryNode[0] != null) {
        INode node = marketplaceService.getNode(queryNode[0], progress);
        SearchResult result = new SearchResult();
        result.setMatchCount(1);
        result.setNodes(Collections.singletonList((Node) node));
        return result;
    }
    return null;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult) MarketplaceUrlHandler(org.eclipse.epp.mpc.ui.MarketplaceUrlHandler) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 20 with ISearchResult

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

the class DiscoverNatureSupportJob method run.

@Override
protected IStatus run(IProgressMonitor monitor) {
    BundleContext bundleContext = MarketplaceClientUiPlugin.getBundleContext();
    ServiceReference<IMarketplaceServiceLocator> locatorReference = bundleContext.getServiceReference(IMarketplaceServiceLocator.class);
    IMarketplaceServiceLocator locator = bundleContext.getService(locatorReference);
    IMarketplaceService marketplaceService = locator.getDefaultMarketplaceService();
    // $NON-NLS-1$]
    String fileExtensionTag = "nature_" + natureId;
    try {
        ISearchResult searchResult = marketplaceService.tagged(fileExtensionTag, monitor);
        nodes = searchResult.getNodes();
    } catch (CoreException ex) {
        IStatus status = new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.LookupByNatureJob_discoveryFailed, natureId), ex);
        MarketplaceClientUi.getLog().log(status);
        // Do not return this status as it would show an error
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService) IMarketplaceServiceLocator(org.eclipse.epp.mpc.core.service.IMarketplaceServiceLocator) BundleContext(org.osgi.framework.BundleContext)

Aggregations

ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)21 SubMonitor (org.eclipse.core.runtime.SubMonitor)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)6 Test (org.junit.Test)6 CoreException (org.eclipse.core.runtime.CoreException)5 INode (org.eclipse.epp.mpc.core.model.INode)5 NoSuchElementException (java.util.NoSuchElementException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Node (org.eclipse.epp.internal.mpc.core.model.Node)2 SearchResult (org.eclipse.epp.internal.mpc.core.model.SearchResult)2 ICategory (org.eclipse.epp.mpc.core.model.ICategory)2 IMarket (org.eclipse.epp.mpc.core.model.IMarket)2 IMarketplaceService (org.eclipse.epp.mpc.core.service.IMarketplaceService)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1