Search in sources :

Example 56 with INode

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

the class MarketplaceDiscoveryStrategy method installErrorReport.

public void installErrorReport(IProgressMonitor monitor, IStatus result, Set<CatalogItem> items, IInstallableUnit[] operationIUs, String resolutionDetails) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_sendingErrorNotification, 100);
    try {
        Set<Node> nodes = new HashSet<Node>();
        for (CatalogItem item : items) {
            Object data = item.getData();
            if (data instanceof INode) {
                nodes.add((Node) data);
            }
        }
        Set<String> iuIdsAndVersions = new HashSet<String>();
        for (IInstallableUnit iu : operationIUs) {
            String id = iu.getId();
            String version = iu.getVersion() == null ? null : iu.getVersion().toString();
            // $NON-NLS-1$
            iuIdsAndVersions.add(id + "," + version);
        }
        marketplaceService.reportInstallError(result, nodes, iuIdsAndVersions, resolutionDetails, progress);
    } finally {
        progress.done();
    }
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) 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) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet)

Example 57 with INode

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

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

the class MarketplaceDiscoveryStrategy method handleSearchResult.

protected void handleSearchResult(MarketplaceCategory catalogCategory, ISearchResult result, final IProgressMonitor monitor) {
    List<CatalogItem> items = getItems();
    if (items != null && !result.getNodes().isEmpty()) {
        int nodeWork = 1000;
        int favoritesWork = catalogCategory.getContents() == Contents.USER_FAVORITES ? 0 : 1000;
        SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_loadingResources, result.getNodes().size() * nodeWork + favoritesWork);
        try {
            boolean userFavoritesSupported = false;
            if (catalogCategory.getContents() == Contents.USER_FAVORITES) {
                userFavoritesSupported = true;
            } else if (hasUserFavoritesService()) {
                try {
                    applyShellProvider();
                    marketplaceService.userFavorites(result.getNodes(), progress.newChild(favoritesWork));
                    userFavoritesSupported = true;
                } catch (NotAuthorizedException e1) {
                // user is not logged in. we just ignore this.
                } catch (UnsupportedOperationException e1) {
                // ignore
                } catch (Exception e1) {
                    // something went wrong. log and proceed.
                    MarketplaceClientCore.error(Messages.MarketplaceDiscoveryStrategy_FavoritesRetrieveError, e1);
                }
            }
            for (final INode node : result.getNodes()) {
                String id = node.getId();
                try {
                    final MarketplaceNodeCatalogItem catalogItem = new MarketplaceNodeCatalogItem();
                    catalogItem.setMarketplaceUrl(catalogDescriptor.getUrl());
                    catalogItem.setId(id);
                    catalogItem.setName(getCatalogItemName(node));
                    catalogItem.setCategoryId(catalogCategory.getId());
                    ICategories categories = node.getCategories();
                    if (categories != null) {
                        for (ICategory category : categories.getCategory()) {
                            catalogItem.addTag(new Tag(ICategory.class, category.getId(), category.getName()));
                        }
                    }
                    catalogItem.setData(node);
                    catalogItem.setSource(source);
                    catalogItem.setLicense(node.getLicense());
                    catalogItem.setUserFavorite(userFavoritesSupported ? node.getUserFavorite() : null);
                    IIus ius = node.getIus();
                    if (ius != null) {
                        List<MarketplaceNodeInstallableUnitItem> installableUnitItems = new ArrayList<MarketplaceNodeInstallableUnitItem>();
                        for (IIu iu : ius.getIuElements()) {
                            MarketplaceNodeInstallableUnitItem iuItem = new MarketplaceNodeInstallableUnitItem();
                            iuItem.init(iu);
                            installableUnitItems.add(iuItem);
                        }
                        catalogItem.setInstallableUnitItems(installableUnitItems);
                    }
                    if (node.getShortdescription() == null && node.getBody() != null) {
                        // bug 306653 <!--break--> marks the end of the short description.
                        String descriptionText = node.getBody();
                        Matcher matcher = BREAK_PATTERN.matcher(node.getBody());
                        if (matcher.find()) {
                            int start = matcher.start();
                            if (start > 0) {
                                String shortDescriptionText = descriptionText.substring(0, start).trim();
                                if (shortDescriptionText.length() > 0) {
                                    descriptionText = shortDescriptionText;
                                }
                            }
                        }
                        catalogItem.setDescription(descriptionText);
                    } else {
                        catalogItem.setDescription(node.getShortdescription());
                    }
                    catalogItem.setProvider(node.getCompanyname());
                    String updateurl = node.getUpdateurl();
                    if (updateurl != null) {
                        try {
                            // trim is important!
                            updateurl = updateurl.trim();
                            URLUtil.toURL(updateurl);
                            catalogItem.setSiteUrl(updateurl);
                        } catch (MalformedURLException e) {
                        // don't use malformed URLs
                        }
                    }
                    if (catalogItem.getInstallableUnits() == null || catalogItem.getInstallableUnits().isEmpty() || catalogItem.getSiteUrl() == null) {
                        catalogItem.setAvailable(false);
                    }
                    if (node.getImage() != null) {
                        if (!source.getResourceProvider().containsResource(node.getImage())) {
                            cacheResource(source.getResourceProvider(), catalogItem, node.getImage());
                        }
                        createIcon(catalogItem, node);
                    }
                    if (node.getBody() != null || node.getScreenshot() != null) {
                        final Overview overview = new Overview();
                        overview.setItem(catalogItem);
                        overview.setSummary(node.getBody());
                        overview.setUrl(node.getUrl());
                        catalogItem.setOverview(overview);
                        if (node.getScreenshot() != null) {
                            if (!source.getResourceProvider().containsResource(node.getScreenshot())) {
                                cacheResource(source.getResourceProvider(), catalogItem, node.getScreenshot());
                            }
                            overview.setScreenshot(node.getScreenshot());
                        }
                    }
                    items.add(catalogItem);
                    marketplaceInfo.map(catalogItem.getMarketplaceUrl(), node);
                    marketplaceInfo.computeInstalled(computeInstalledFeatures(progress.newChild(nodeWork)), catalogItem);
                } catch (RuntimeException ex) {
                    MarketplaceClientUi.error(NLS.bind(Messages.MarketplaceDiscoveryStrategy_ParseError, // $NON-NLS-1$
                    node == null ? "null" : id), ex);
                }
            }
        } finally {
            progress.done();
        }
        if (result.getMatchCount() != null) {
            catalogCategory.setMatchCount(result.getMatchCount());
            if (result.getMatchCount() > result.getNodes().size()) {
                // add an item here to indicate that the search matched more items than were returned by the server
                addCatalogItem(catalogCategory);
            }
        }
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) MalformedURLException(java.net.MalformedURLException) Matcher(java.util.regex.Matcher) ICategory(org.eclipse.epp.mpc.core.model.ICategory) SubMonitor(org.eclipse.core.runtime.SubMonitor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Overview(org.eclipse.equinox.internal.p2.discovery.model.Overview) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) NoSuchElementException(java.util.NoSuchElementException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) IIu(org.eclipse.epp.mpc.core.model.IIu) ICategories(org.eclipse.epp.mpc.core.model.ICategories) Tag(org.eclipse.equinox.internal.p2.discovery.model.Tag) IIus(org.eclipse.epp.mpc.core.model.IIus)

Example 59 with INode

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

the class MarketplaceInfo method computeInstalledNodes.

/**
 * Calculate the known catalog nodes that might be installed. Since no remote query should happen, this only checks
 * if any one of the IUs for a node are installed.
 *
 * @param repositoryUrl
 *            the catalog url for which installed nodes should be computed
 * @param installedIus
 *            all of the currently installed IUs
 * @return a set of node ids, or an empty set if there are no known installed nodes
 * @deprecated use {@link #computeInstalledNodes(URL, Map)} instead
 */
@Deprecated
public synchronized Set<INode> computeInstalledNodes(URL repositoryUrl, Set<String> installedIus) {
    Set<INode> nodes = new HashSet<INode>();
    String keyPrefix = computeUrlKey(repositoryUrl) + '#';
    for (Map.Entry<String, List<String>> entry : nodeKeyToIU.entrySet()) {
        if (entry.getKey().startsWith(keyPrefix)) {
            List<String> ius = nodeKeyToIU.get(entry.getKey());
            if (computeInstalled(installedIus, ius, false)) {
                String nodeId = entry.getKey().substring(keyPrefix.length());
                Node node = new Node();
                node.setId(nodeId);
                nodes.add(node);
            }
        }
    }
    return nodes;
}
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) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 60 with INode

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

the class MarketplaceInfo method computeInstalledNodes.

/**
 * Calculate the known catalog nodes that might be installed. Since no remote query should happen, this only checks
 * if any one of the IUs for a node are installed.
 *
 * @param repositoryUrl
 *            the catalog url for which installed nodes should be computed
 * @param installedIus
 *            all of the currently installed IUs
 * @return a set of node ids, or an empty set if there are no known installed nodes
 */
public synchronized Set<INode> computeInstalledNodes(URL repositoryUrl, Map<String, IInstallableUnit> installedIus) {
    Set<INode> nodes = new HashSet<INode>();
    String keyPrefix = computeUrlKey(repositoryUrl) + '#';
    for (Map.Entry<String, List<String>> entry : nodeKeyToIU.entrySet()) {
        if (entry.getKey().startsWith(keyPrefix)) {
            List<String> ius = nodeKeyToIU.get(entry.getKey());
            if (computeInstalled(installedIus.keySet(), ius, false)) {
                String nodeId = entry.getKey().substring(keyPrefix.length());
                INode node = QueryHelper.nodeById(nodeId);
                nodes.add(node);
            }
        }
    }
    for (IInstallableUnit iu : installedIus.values()) {
        String nodeUrl = iu.getProperty(MPC_NODE_IU_PROPERTY);
        if (nodeUrl != null && nodeUrl.startsWith(repositoryUrl.toString())) {
            INode node = QueryHelper.nodeByUrl(nodeUrl);
            nodes.add(node);
        }
    }
    return nodes;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) ArrayList(java.util.ArrayList) List(java.util.List) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

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