Search in sources :

Example 11 with INode

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

the class MarketplaceCatalogTest method setupCatalog.

protected void setupCatalog() throws MalformedURLException {
    final SearchResult discoveryResult = new SearchResult();
    discoveryResult.setNodes(discoveryNodes);
    CatalogDescriptor catalogDescriptor = new CatalogDescriptor();
    catalogDescriptor.setUrl(new URL("http://marketplace.eclipse.org"));
    MarketplaceDiscoveryStrategy discoveryStrategy = new MarketplaceDiscoveryStrategy(catalogDescriptor) {

        final MarketplaceCategory category = new MarketplaceCategory();

        {
            category.setId("<root>");
        }

        @Override
        public void performDiscovery(IProgressMonitor monitor) throws CoreException {
            if (!categories.contains(category)) {
                categories.add(category);
            }
            handleSearchResult(category, discoveryResult, new NullProgressMonitor());
        }

        @Override
        protected synchronized Map<String, IInstallableUnit> computeInstalledIUs(IProgressMonitor monitor) {
            Map<String, IInstallableUnit> installedIus = new HashMap<String, IInstallableUnit>();
            for (INode node : installedNodes) {
                IIus ius = node.getIus();
                if (ius != null) {
                    for (IIu iu : ius.getIuElements()) {
                        String featureId = iu.getId() + ".feature.group";
                        InstallableUnit installableUnit = new InstallableUnit();
                        installableUnit.setId(featureId);
                        installedIus.put(featureId, installableUnit);
                    }
                }
            }
            return installedIus;
        }

        @Override
        protected MarketplaceCategory findMarketplaceCategory(IProgressMonitor monitor) throws CoreException {
            return category;
        }
    };
    catalog = new MarketplaceCatalog() {

        @Override
        protected IStatus checkForUpdates(List<MarketplaceNodeCatalogItem> updateCheckNeeded, final Map<String, IInstallableUnit> installedIUs, final IProgressMonitor monitor) {
            for (MarketplaceNodeCatalogItem item : updateCheckNeeded) {
                checkedForUpdate.add(item.getData());
                List<MarketplaceNodeInstallableUnitItem> installableUnitItems = item.getInstallableUnitItems();
                boolean hasUpdate = updateAvailable.contains(item.getData());
                for (MarketplaceNodeInstallableUnitItem iuItem : installableUnitItems) {
                    iuItem.setUpdateAvailable(hasUpdate);
                }
            }
            return Status.OK_STATUS;
        }
    };
    catalog.getDiscoveryStrategies().add(discoveryStrategy);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) IStatus(org.eclipse.core.runtime.IStatus) HashMap(java.util.HashMap) MarketplaceDiscoveryStrategy(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult) MarketplaceCategory(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) InstallableUnit(org.eclipse.equinox.internal.p2.metadata.InstallableUnit) URL(java.net.URL) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IIu(org.eclipse.epp.mpc.core.model.IIu) MarketplaceNodeInstallableUnitItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeInstallableUnitItem) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) ArrayList(java.util.ArrayList) List(java.util.List) MarketplaceCatalog(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog) IIus(org.eclipse.epp.mpc.core.model.IIus) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 12 with INode

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

the class UserFavoritesService method setFavorites.

public void setFavorites(Collection<? extends INode> nodes, IProgressMonitor monitor) throws NoServiceException, ConflictException, NotAuthorizedException, IllegalStateException, IOException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.UserFavoritesService_SettingUserFavorites, 1000);
    String favoritesData = createFavoritesBlobData(nodes);
    try {
        if (favoritesData == null || "".equals(favoritesData)) {
            // $NON-NLS-1$
            getFavoritesBlob().delete();
        } else {
            getFavoritesBlob().setContentsUTF(favoritesData);
        }
        // FIXME waiting for USS bug 488335 to have proper progress and cancelation
        progress.worked(900);
    } catch (OperationCanceledException ex) {
        throw processProtocolException(ex);
    } catch (ProtocolException ex) {
        throw processProtocolException(ex);
    }
    synchronized (this) {
        SubMonitor notifyNewProgress = SubMonitor.convert(progress.newChild(50), nodes.size());
        Set<String> newFavorites = new HashSet<String>();
        for (INode node : nodes) {
            String id = node.getId();
            if (newFavorites.add(id)) {
                boolean newFavorite = favorites.add(id);
                if (newFavorite) {
                    didChangeFavorite(id, true);
                }
            }
            notifyNewProgress.worked(1);
        }
        SubMonitor notifyRemovedProgress = SubMonitor.convert(progress.newChild(50), favorites.size());
        for (Iterator<String> i = favorites.iterator(); i.hasNext(); ) {
            String id = i.next();
            if (!newFavorites.contains(id)) {
                i.remove();
                didChangeFavorite(id, false);
            }
            notifyRemovedProgress.worked(1);
        }
    }
}
Also used : ProtocolException(org.eclipse.userstorage.util.ProtocolException) INode(org.eclipse.epp.mpc.core.model.INode) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 13 with INode

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

the class UserFavoritesService method doAlterFavorites.

private void doAlterFavorites(Collection<? extends INode> nodes, boolean favorite, IProgressMonitor monitor) throws ConflictException, IOException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.UserFavoritesService_SettingUserFavorites, 1000);
    List<INode> favorites = getFavorites(progress.newChild(300));
    for (INode node : nodes) {
        INode currentFavorite = QueryHelper.findById(favorites, node);
        if (currentFavorite != null && !favorite) {
            favorites.remove(currentFavorite);
        } else if (currentFavorite == null && favorite) {
            favorites.add(node);
        }
    }
    setFavorites(favorites, progress.newChild(700));
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) SubMonitor(org.eclipse.core.runtime.SubMonitor)

Example 14 with INode

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

the class MarketplaceDiscoveryStrategy method refreshUserFavorites.

public void refreshUserFavorites(IProgressMonitor monitor) throws CoreException {
    final SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_FavoritesRefreshing, 1001);
    try {
        MarketplaceCategory catalogCategory = findMarketplaceCategory(progress.newChild(1));
        List<CatalogItem> items = catalogCategory.getItems();
        if (hasUserFavoritesService()) {
            Map<String, INode> nodes = new HashMap<String, INode>();
            for (CatalogItem item : items) {
                Object data = item.getData();
                if (data instanceof INode) {
                    INode node = (INode) data;
                    nodes.put(node.getId(), node);
                }
            }
            if (nodes.isEmpty()) {
                return;
            }
            try {
                applyShellProvider();
                marketplaceService.userFavorites(new ArrayList<INode>(nodes.values()), progress.newChild(500));
                for (CatalogItem catalogItem : items) {
                    if (catalogItem instanceof MarketplaceNodeCatalogItem) {
                        MarketplaceNodeCatalogItem nodeItem = (MarketplaceNodeCatalogItem) catalogItem;
                        INode node = nodes.get(nodeItem.getId());
                        nodeItem.setUserFavorite(node == null ? null : node.getUserFavorite());
                    }
                }
            } catch (NotAuthorizedException e) {
                catalogCategory = addPopularItems(progress.newChild(500));
                addUserStorageLoginItem(catalogCategory, e.getLocalizedMessage());
            } catch (UnsupportedOperationException ex) {
                catalogCategory = addPopularItems(progress.newChild(500));
                addFavoritesNotSupportedItem(catalogCategory);
            } catch (Exception ex) {
                // FIXME we should use the wizard page's status line to show errors, but that's unreachable from here...
                MarketplaceClientCore.error(Messages.MarketplaceDiscoveryStrategy_FavoritesRetrieveError, ex);
                addRetryErrorItem(catalogCategory, ex);
            }
        } else {
            for (CatalogItem catalogItem : items) {
                if (catalogItem instanceof MarketplaceNodeCatalogItem) {
                    MarketplaceNodeCatalogItem nodeItem = (MarketplaceNodeCatalogItem) catalogItem;
                    nodeItem.setUserFavorite(null);
                }
            }
        }
    } finally {
        monitor.done();
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) HashMap(java.util.HashMap) SubMonitor(org.eclipse.core.runtime.SubMonitor) 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)

Example 15 with INode

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

the class MarketplaceDiscoveryStrategy method performNodeQuery.

public void performNodeQuery(IProgressMonitor monitor, Set<? extends INode> nodes) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_searchingMarketplace, 1001);
    try {
        MarketplaceCategory catalogCategory = findMarketplaceCategory(progress.newChild(1));
        catalogCategory.setContents(Contents.QUERY);
        SearchResult result = new SearchResult();
        result.setNodes(new ArrayList<Node>());
        if (!monitor.isCanceled()) {
            if (!nodes.isEmpty()) {
                List<INode> resolvedNodes = marketplaceService.getNodes(nodes, progress.newChild(500));
                for (INode node : resolvedNodes) {
                    result.getNodes().add((Node) node);
                }
            } else {
                progress.setWorkRemaining(500);
            }
            result.setMatchCount(result.getNodes().size());
            handleSearchResult(catalogCategory, result, progress.newChild(500));
        }
    } finally {
        monitor.done();
    }
}
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) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult)

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