Search in sources :

Example 6 with NotAuthorizedException

use of org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException 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 7 with NotAuthorizedException

use of org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method userFavorites.

public void userFavorites(boolean promptLogin, IProgressMonitor monitor) throws CoreException {
    final SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_FavoritesRetrieve, 1001);
    try {
        MarketplaceCategory catalogCategory = findMarketplaceCategory(progress.newChild(1));
        catalogCategory.setContents(Contents.USER_FAVORITES);
        IUserFavoritesService userFavoritesService = marketplaceService.getUserFavoritesService();
        if (userFavoritesService != null) {
            try {
                applyShellProvider();
                ISearchResult result;
                if (promptLogin) {
                    IMarketplaceStorageService storageService = userFavoritesService.getStorageService();
                    result = storageService.runWithLogin(new Callable<ISearchResult>() {

                        public ISearchResult call() throws Exception {
                            return marketplaceService.userFavorites(progress.newChild(500));
                        }
                    });
                } else {
                    result = marketplaceService.userFavorites(progress.newChild(500));
                }
                if (result.getNodes().isEmpty()) {
                    catalogCategory = addPopularItems(progress.newChild(500));
                    addNoFavoritesItem(catalogCategory);
                } else {
                    handleSearchResult(catalogCategory, result, progress.newChild(500));
                }
            } 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 {
            catalogCategory = addPopularItems(progress.newChild(1000));
            addFavoritesNotSupportedItem(catalogCategory);
        }
    } finally {
        monitor.done();
    }
}
Also used : ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SubMonitor(org.eclipse.core.runtime.SubMonitor) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService) Callable(java.util.concurrent.Callable) 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)

Aggregations

NotAuthorizedException (org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException)7 INode (org.eclipse.epp.mpc.core.model.INode)6 IOException (java.io.IOException)5 MalformedURLException (java.net.MalformedURLException)5 URISyntaxException (java.net.URISyntaxException)5 CoreException (org.eclipse.core.runtime.CoreException)5 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)5 NoSuchElementException (java.util.NoSuchElementException)3 FileNotFoundException (java.io.FileNotFoundException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 Callable (java.util.concurrent.Callable)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 ConflictException (org.eclipse.userstorage.util.ConflictException)2 HashMap (java.util.HashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1