Search in sources :

Example 46 with INode

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

the class DefaultMarketplaceService method getNodesByUrl.

private void getNodesByUrl(Collection<? extends INode> nodes, Map<INode, INode> resolvedNodeMapping, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, nodes.size());
    int remaining = nodes.size();
    for (INode node : nodes) {
        if (node.getId() == null && node.getUrl() != null) {
            Node resolvedNode = getNode(node, progress.newChild(1));
            resolvedNodeMapping.put(node, resolvedNode);
        }
        progress.setWorkRemaining(--remaining);
    }
}
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) SubMonitor(org.eclipse.core.runtime.SubMonitor)

Example 47 with INode

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

the class DefaultMarketplaceService method getNodesById.

private void getNodesById(Collection<? extends INode> nodes, Map<INode, INode> resolvedNodeMapping, IProgressMonitor monitor) throws CoreException {
    StringBuilder nodeIdQuery = new StringBuilder();
    Map<String, INode> nodeIds = new HashMap<String, INode>(nodes.size());
    for (INode node : nodes) {
        if (node.getId() == null) {
            continue;
        }
        nodeIds.put(node.getId(), node);
        String encodedId = urlEncode(node.getId());
        if (nodeIdQuery.length() > 0) {
            // $NON-NLS-1$
            nodeIdQuery.append(",");
        }
        nodeIdQuery.append(encodedId);
    }
    Marketplace marketplace = processRequest(API_NODE_URI + '/' + nodeIdQuery + '/' + API_URI_SUFFIX, monitor);
    List<Node> resolvedNodes = marketplace.getNode();
    for (Node node : resolvedNodes) {
        INode inputNode = nodeIds.get(node.getId());
        if (inputNode != null) {
            resolvedNodeMapping.put(inputNode, node);
        } else {
            throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_unexpectedResponse, nodeIdQuery));
        }
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode)

Example 48 with INode

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

the class DefaultMarketplaceService method getNodes.

public List<INode> getNodes(Collection<? extends INode> nodes, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.DefaultMarketplaceService_getNodesProgress, nodes.size());
    if (nodes.isEmpty()) {
        return new ArrayList<INode>();
    }
    List<INode> nodesById = null;
    List<INode> nodesByUrl = null;
    for (INode node : nodes) {
        if (node.getId() == null) {
            if (node.getUrl() == null) {
                throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_invalidNode, node));
            }
            if (nodesByUrl == null) {
                nodesByUrl = new ArrayList<INode>();
            }
            nodesByUrl.add(node);
        } else {
            if (nodesById == null) {
                nodesById = new ArrayList<INode>(nodes.size());
            }
            nodesById.add(node);
        }
    }
    Map<INode, INode> resolvedNodeMapping = new HashMap<INode, INode>(nodes.size());
    if (nodesById != null) {
        getNodesById(nodesById, resolvedNodeMapping, progress.newChild(nodesById.size()));
    }
    if (nodesByUrl != null) {
        getNodesByUrl(nodesByUrl, resolvedNodeMapping, progress.newChild(nodesByUrl.size()));
    }
    List<INode> resultNodes = new ArrayList<INode>(nodes.size());
    MultiStatus missingNodes = null;
    for (INode inputNode : nodes) {
        INode resolvedNode = resolvedNodeMapping.get(inputNode);
        if (resolvedNode != null) {
            resultNodes.add(resolvedNode);
        } else {
            String query;
            if (inputNode.getId() != null) {
                query = inputNode.getId();
            } else {
                query = inputNode.getUrl();
            }
            IStatus missingNodeDetailStatus = createStatus(IStatus.INFO, Messages.DefaultMarketplaceService_nodeNotFound, query);
            if (missingNodes == null) {
                missingNodes = new MultiStatus(MarketplaceClientCore.BUNDLE_ID, 0, "Some entries could not be found on the Marketplace", // $NON-NLS-1$
                null);
            }
            missingNodes.add(missingNodeDetailStatus);
        }
    }
    if (missingNodes != null) {
        MarketplaceClientCore.getLog().log(missingNodes);
    }
    return resultNodes;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) SubMonitor(org.eclipse.core.runtime.SubMonitor) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus)

Example 49 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(IProgressMonitor monitor) throws CoreException, NotAuthorizedException {
    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(progress.newChild(1000));
    } catch (NotAuthorizedException e) {
        throw e;
    } catch (Exception e) {
        throw new CoreException(MarketplaceClientCore.computeStatus(e, Messages.DefaultMarketplaceService_FavoritesErrorRetrieving));
    }
    progress.setWorkRemaining(9000);
    return resolveFavoriteNodes(favorites, progress.newChild(9000), true);
}
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) 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 50 with INode

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

the class MarketplaceViewer method doQuery.

private IStatus doQuery(final QueryData queryData, final Set<? extends INode> nodes) {
    try {
        final ContentType queryType = contentType;
        queryContentType = queryType;
        final IStatus[] result = new IStatus[1];
        context.run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                switch(queryType) {
                    case POPULAR:
                        result[0] = getCatalog().popular(monitor);
                        break;
                    case RECENT:
                        result[0] = getCatalog().recent(monitor);
                        break;
                    case RELATED:
                        result[0] = getCatalog().related(monitor);
                        break;
                    case INSTALLED:
                        result[0] = getCatalog().installed(monitor);
                        break;
                    case FAVORITES:
                        result[0] = getCatalog().userFavorites(false, monitor);
                        break;
                    case SELECTION:
                        Set<String> nodeIds = new HashSet<String>();
                        for (CatalogItem item : getSelectionModel().getItemToSelectedOperation().keySet()) {
                            nodeIds.add(((INode) item.getData()).getId());
                        }
                        result[0] = getCatalog().performQuery(monitor, nodeIds);
                        break;
                    case SEARCH:
                    case FEATURED_MARKET:
                    default:
                        if (nodes != null && !nodes.isEmpty()) {
                            result[0] = getCatalog().performNodeQuery(monitor, nodes);
                        } else if (queryData.queryText != null && queryData.queryText.length() > 0) {
                            String tag = getTagQuery(queryData.queryText);
                            if (tag != null) {
                                result[0] = getCatalog().tagged(tag, monitor);
                            } else {
                                result[0] = getCatalog().performQuery(queryData.queryMarket, queryData.queryCategory, queryData.queryText, monitor);
                            }
                        } else {
                            result[0] = getCatalog().featured(monitor, queryData.queryMarket, queryData.queryCategory);
                        }
                        break;
                }
                if (!monitor.isCanceled() && result[0] != null && result[0].getSeverity() != IStatus.CANCEL) {
                    getCatalog().checkForUpdates(monitor);
                }
                MarketplaceViewer.this.getControl().getDisplay().syncExec(new Runnable() {

                    public void run() {
                        updateViewer(queryData.queryText);
                    }
                });
            }
        });
        if (result[0] != null && !result[0].isOK() && result[0].getSeverity() != IStatus.CANCEL) {
            MarketplaceClientUi.handle(result[0], (result[0].getSeverity() > IStatus.WARNING ? StatusManager.SHOW | StatusManager.BLOCK : 0) | StatusManager.LOG);
            return result[0];
        } else {
            verifyUpdateSiteAvailability();
            return Status.OK_STATUS;
        }
    } catch (InvocationTargetException e) {
        IStatus status = computeStatus(e, Messages.MarketplaceViewer_unexpectedException);
        MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
        return status;
    } catch (InterruptedException e) {
        // cancelled by user so nothing to do here.
        return Status.CANCEL_STATUS;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) INode(org.eclipse.epp.mpc.core.model.INode) Set(java.util.Set) HashSet(java.util.HashSet) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) UserActionCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.UserActionCatalogItem) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

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