Search in sources :

Example 6 with Node

use of org.eclipse.epp.internal.mpc.core.model.Node 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 7 with Node

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

the class DefaultMarketplaceService method getNode.

public Node getNode(INode node, IProgressMonitor monitor) throws CoreException {
    Marketplace marketplace;
    String query;
    if (node.getId() != null) {
        // bug 304928: prefer the id method rather than the URL, since the id provides a stable URL and the
        // URL is based on the name, which could change.
        query = node.getId();
        String encodedId = urlEncode(node.getId());
        marketplace = processRequest(API_NODE_URI + '/' + encodedId + '/' + API_URI_SUFFIX, monitor);
    } else {
        query = node.getUrl();
        marketplace = processRequest(node.getUrl(), API_URI_SUFFIX, monitor);
    }
    if (marketplace.getNode().isEmpty()) {
        throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_nodeNotFound, query));
    } else if (marketplace.getNode().size() > 1) {
        throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_unexpectedResponse, query));
    }
    Node resolvedNode = marketplace.getNode().get(0);
    return resolvedNode;
}
Also used : Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace) CoreException(org.eclipse.core.runtime.CoreException) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode)

Example 8 with Node

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

the class DefaultMarketplaceService method userFavorites.

public void userFavorites(List<? extends INode> nodes, IProgressMonitor monitor) throws NotAuthorizedException, CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.DefaultMarketplaceService_FavoritesUpdate, 10000);
    IUserFavoritesService userFavoritesService = getUserFavoritesService();
    if (userFavoritesService == null) {
        throw new UnsupportedOperationException();
    }
    if (nodes == null || nodes.isEmpty()) {
        return;
    }
    Set<String> favorites = null;
    try {
        favorites = userFavoritesService == null ? null : userFavoritesService.getFavoriteIds(progress);
    } catch (NotAuthorizedException e) {
        throw e;
    } catch (Exception e) {
        throw new CoreException(MarketplaceClientCore.computeStatus(e, Messages.DefaultMarketplaceService_FavoritesErrorRetrieving));
    } finally {
        for (INode node : nodes) {
            ((Node) node).setUserFavorite(favorites == null ? null : favorites.contains(node.getId()));
        }
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) CoreException(org.eclipse.core.runtime.CoreException) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) SubMonitor(org.eclipse.core.runtime.SubMonitor) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 9 with Node

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

the class AbstractMarketplaceWizardBotTest method testNode.

private static INode testNode(String id, String url, String name) {
    Node node = (Node) QueryHelper.nodeById(id);
    node.setUrl(url);
    node.setName(name);
    return node;
}
Also used : Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode)

Example 10 with Node

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

the class MarketplaceDiscoveryStrategyTest method testSearchByNodeUrl.

@Test
public void testSearchByNodeUrl() throws Exception {
    final INode[] testNode = new INode[1];
    final IMarketplaceService marketplaceService = new DefaultMarketplaceService(catalogUrl) {

        @Override
        public Node getNode(INode node, IProgressMonitor monitor) throws CoreException {
            testNode[0] = node;
            return (Node) node;
        }

        @Override
        public SearchResult search(IMarket market, ICategory category, String queryText, IProgressMonitor monitor) throws CoreException {
            Assert.fail("Unexpected invocation");
            // dead code
            return null;
        }
    };
    setupCatalog(marketplaceService);
    testNode[0] = null;
    catalog.performQuery(null, null, new URL(catalogUrl, "content/test").toExternalForm(), new NullProgressMonitor());
    assertNotNull(testNode[0]);
    assertNotNull(testNode[0].getUrl());
    testNode[0] = null;
    catalog.performQuery(null, null, new URL(catalogUrl, "node/12345").toExternalForm(), new NullProgressMonitor());
    assertNotNull(testNode[0]);
    assertNotNull(testNode[0].getId());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DefaultMarketplaceService(org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) ICategory(org.eclipse.epp.mpc.core.model.ICategory) IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService) IMarket(org.eclipse.epp.mpc.core.model.IMarket) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Node (org.eclipse.epp.internal.mpc.core.model.Node)20 INode (org.eclipse.epp.mpc.core.model.INode)19 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)5 HashSet (java.util.HashSet)4 CoreException (org.eclipse.core.runtime.CoreException)4 SearchResult (org.eclipse.epp.internal.mpc.core.model.SearchResult)4 Marketplace (org.eclipse.epp.internal.mpc.core.model.Marketplace)3 FileNotFoundException (java.io.FileNotFoundException)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 Matcher (java.util.regex.Matcher)2 Ius (org.eclipse.epp.internal.mpc.core.model.Ius)2 ICategory (org.eclipse.epp.mpc.core.model.ICategory)2 IMarketplaceService (org.eclipse.epp.mpc.core.service.IMarketplaceService)2 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1