Search in sources :

Example 11 with ISearchResult

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

the class DiscoverFileSupportJob method run.

private IStatus run(IMarketplaceService marketplaceService, IProgressMonitor monitor) {
    final List<String> fileExtensions = getFileExtensions(fileName);
    final List<String> fileExtensionTags = new ArrayList<String>();
    for (String string : fileExtensions) {
        fileExtensionTags.add(getFileExtensionTag(string));
    }
    final List<? extends INode> nodes;
    try {
        ISearchResult searchResult = marketplaceService.tagged(fileExtensionTags, monitor);
        nodes = orderNodesByTagSubExtensionCount(searchResult.getNodes(), fileExtensionTags);
    } catch (CoreException ex) {
        IStatus status = new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.DiscoverFileSupportJob_discoveryFailed, getFileExtensionLabel(fileName)), ex);
        // Do not return this status as it would show an error, e.g. when the user is currently offline
        MarketplaceClientUi.getLog().log(status);
        return Status.CANCEL_STATUS;
    }
    if (nodes.isEmpty()) {
        return Status.OK_STATUS;
    }
    UIJob openDialog = new ShowFileSupportProposalsJob(fileName, nodes, editorRegistry, defaultDescriptor, display);
    openDialog.setPriority(Job.INTERACTIVE);
    openDialog.setSystem(true);
    openDialog.schedule();
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) UIJob(org.eclipse.ui.progress.UIJob)

Example 12 with ISearchResult

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

the class DefaultMarketplaceService method resolveFavoriteNodes.

private ISearchResult resolveFavoriteNodes(final List<INode> nodes, IProgressMonitor monitor, boolean filterIncompatible) throws CoreException {
    IMarketplaceService resolveService = this;
    IMarketplaceService registeredService = ServiceHelper.getMarketplaceServiceLocator().getMarketplaceService(this.getBaseUrl().toString());
    if (registeredService instanceof CachingMarketplaceService) {
        CachingMarketplaceService cachingService = (CachingMarketplaceService) registeredService;
        if (cachingService.getDelegate() == this) {
            resolveService = cachingService;
        }
    }
    final List<INode> resolvedNodes = resolveService.getNodes(nodes, monitor);
    for (ListIterator<INode> i = resolvedNodes.listIterator(); i.hasNext(); ) {
        INode resolved = i.next();
        ((Node) resolved).setUserFavorite(true);
        if (filterIncompatible && !isInstallable(resolved)) {
            i.remove();
        }
    }
    if (!filterIncompatible) {
        // sort the node list so uninstallable nodes come last
        Collections.sort(resolvedNodes, new Comparator<INode>() {

            public int compare(INode n1, INode n2) {
                if (n1 == n2) {
                    return 0;
                }
                boolean n1Installable = isInstallable(n1);
                boolean n2Installable = isInstallable(n2);
                if (n1Installable == n2Installable) {
                    return 0;
                }
                if (n1Installable) {
                    // && !n2Installable
                    return -1;
                }
                // !n1Installable && n2Installable
                return 1;
            }
        });
    }
    return new ISearchResult() {

        public List<? extends INode> getNodes() {
            return resolvedNodes;
        }

        public Integer getMatchCount() {
            return resolvedNodes.size();
        }
    };
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService)

Example 13 with ISearchResult

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

the class CachingMarketplaceService method related.

public ISearchResult related(final List<? extends INode> basedOn, IProgressMonitor monitor) throws CoreException {
    String searchKey = null;
    if (basedOn != null && !basedOn.isEmpty()) {
        StringBuilder searchKeyBldr = new StringBuilder();
        for (INode node : basedOn) {
            searchKeyBldr.append(node.getId()).append('+');
        }
        searchKey = searchKeyBldr.substring(0, searchKeyBldr.length() - 1);
    }
    // $NON-NLS-1$
    String key = computeSearchKey("related", null, null, searchKey);
    return performSearch(monitor, key, new SearchOperation() {

        public ISearchResult doSearch(IProgressMonitor monitor) throws CoreException {
            return delegate.related(basedOn, monitor);
        }
    });
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) CoreException(org.eclipse.core.runtime.CoreException)

Example 14 with ISearchResult

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

the class DefaultMarketplaceServiceTest method favorites.

@Test
@org.junit.experimental.categories.Category(RemoteTests.class)
// top favorites are not exposed in MPC anymore - this fails with a 503 due to the varnish cache failing
@Ignore
public void favorites() throws CoreException {
    ISearchResult result = marketplaceService.topFavorites(new NullProgressMonitor());
    assertSearchResultSanity(result);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with ISearchResult

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

the class DefaultMarketplaceServiceTest method search_bug448453.

@Test
@org.junit.experimental.categories.Category(RemoteTests.class)
public void search_bug448453() throws CoreException {
    ISearchResult result = search(null, null, "play!");
    assertNotNull(result);
    assertNotNull(result.getNodes());
}
Also used : ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) Test(org.junit.Test)

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