Search in sources :

Example 26 with INode

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

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

the class DefaultMarketplaceService method userFavorites.

public ISearchResult userFavorites(URI favoritesUri, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.DefaultMarketplaceService_FavoritesRetrieve, 10000);
    IUserFavoritesService userFavoritesService = getUserFavoritesService();
    if (userFavoritesService == null) {
        throw new UnsupportedOperationException();
    }
    final List<INode> favorites;
    try {
        favorites = userFavoritesService.getFavorites(favoritesUri, progress.newChild(1000));
    } catch (Exception e) {
        throw new CoreException(MarketplaceClientCore.computeStatus(e, Messages.DefaultMarketplaceService_FavoritesErrorRetrieving));
    }
    progress.setWorkRemaining(9000);
    return resolveFavoriteNodes(favorites, progress.newChild(9000), false);
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) CoreException(org.eclipse.core.runtime.CoreException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) 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 28 with INode

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

the class CachingMarketplaceService method getNodes.

public List<INode> getNodes(Collection<? extends INode> nodes, IProgressMonitor monitor) throws CoreException {
    Map<INode, INode> resolvedNodes = new LinkedHashMap<INode, INode>();
    List<INode> unresolvedNodes = new ArrayList<INode>();
    for (INode node : nodes) {
        if (!mapCachedNode(node, resolvedNodes)) {
            unresolvedNodes.add(node);
        }
    }
    if (!unresolvedNodes.isEmpty()) {
        List<INode> newResolvedNodes = delegate.getNodes(unresolvedNodes, monitor);
        for (INode node : newResolvedNodes) {
            cacheNode(node);
        }
        for (INode node : unresolvedNodes) {
            mapCachedNode(node, resolvedNodes);
        }
    }
    List<INode> result = new ArrayList<INode>(nodes.size());
    for (INode node : nodes) {
        INode resolvedNode = resolvedNodes.get(node);
        if (resolvedNode != null) {
            result.add(resolvedNode);
        }
    }
    return result;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

Example 29 with INode

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

the class CachingMarketplaceService method getNode.

public INode getNode(INode node, IProgressMonitor monitor) throws CoreException {
    String nodeKey = computeNodeKey(node);
    INode nodeResult = null;
    if (nodeKey != null) {
        nodeResult = getCached(nodeKey, INode.class);
    }
    if (nodeResult == null) {
        String nodeUrlKey = computeNodeUrlKey(node);
        if (nodeUrlKey != null) {
            nodeResult = getCached(nodeUrlKey, INode.class);
        }
    }
    if (nodeResult == null) {
        nodeResult = delegate.getNode(node, monitor);
        if (nodeResult != null) {
            cacheNode(nodeResult);
        }
    }
    return nodeResult;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode)

Example 30 with INode

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

Aggregations

INode (org.eclipse.epp.mpc.core.model.INode)63 Node (org.eclipse.epp.internal.mpc.core.model.Node)13 ArrayList (java.util.ArrayList)12 CoreException (org.eclipse.core.runtime.CoreException)12 SubMonitor (org.eclipse.core.runtime.SubMonitor)12 Test (org.junit.Test)12 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10 Marketplace (org.eclipse.epp.internal.mpc.core.model.Marketplace)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 ICategory (org.eclipse.epp.mpc.core.model.ICategory)8 URISyntaxException (java.net.URISyntaxException)7 NotAuthorizedException (org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException)7 ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)7 IOException (java.io.IOException)6 MalformedURLException (java.net.MalformedURLException)6 List (java.util.List)6 IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)6 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)6