Search in sources :

Example 1 with NotAuthorizedException

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

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

the class ImportFavoritesPage method performImport.

public void performImport() {
    setErrorMessage(null);
    saveInstallSelected();
    List<MarketplaceNodeCatalogItem> importFavorites = getSelection();
    if (importFavorites.isEmpty()) {
        return;
    }
    final IUserFavoritesService userFavoritesService = findUserFavoritesService();
    if (userFavoritesService == null) {
        return;
    }
    final List<INode> importNodes = new ArrayList<INode>();
    for (MarketplaceNodeCatalogItem item : importFavorites) {
        importNodes.add(item.getData());
    }
    try {
        getContainer().run(true, false, new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    userFavoritesService.getStorageService().runWithLogin(new Callable<Void>() {

                        public Void call() throws Exception {
                            try {
                                userFavoritesService.addFavorites(importNodes, monitor);
                            } catch (NotAuthorizedException e) {
                                setErrorMessage(Messages.ImportFavoritesPage_unauthorizedErrorMessage);
                            } catch (ConflictException e) {
                                setErrorMessage(Messages.ImportFavoritesPage_conflictErrorMessage);
                            }
                            return null;
                        }
                    });
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        MarketplaceClientCore.error(cause);
        setErrorMessage(NLS.bind(Messages.ImportFavoritesPage_unknownErrorMessage, cause));
    } catch (InterruptedException e) {
    // ignore
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) ConflictException(org.eclipse.userstorage.util.ConflictException) ArrayList(java.util.ArrayList) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Callable(java.util.concurrent.Callable) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) ConflictException(org.eclipse.userstorage.util.ConflictException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)

Example 3 with NotAuthorizedException

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

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

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

the class DiscoveryItem method toggleFavorite.

private void toggleFavorite() {
    final INode node = this.getCatalogItemNode();
    final IUserFavoritesService userFavoritesService = getUserFavoritesService();
    if (node != null && userFavoritesService != null) {
        final boolean newFavorited = !isFavorited();
        final Throwable[] error = new Throwable[] { null };
        BusyIndicator.showWhile(getDisplay(), new Runnable() {

            public void run() {
                try {
                    ModalContext.run(new IRunnableWithProgress() {

                        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                            try {
                                userFavoritesService.getStorageService().runWithLogin(new Callable<Void>() {

                                    public Void call() throws Exception {
                                        userFavoritesService.setFavorite(node, newFavorited, monitor);
                                        return null;
                                    }
                                });
                            } catch (Exception e) {
                                error[0] = e;
                            }
                        }
                    }, true, new NullProgressMonitor(), getDisplay());
                } catch (InvocationTargetException e) {
                    error[0] = e.getCause();
                } catch (InterruptedException e) {
                    error[0] = e;
                }
            }
        });
        Throwable e = error[0];
        if (e != null) {
            if (e instanceof NotAuthorizedException) {
                // authentication was cancelled
                return;
            } else if (e instanceof ConflictException) {
                // silently ignored - service already tried to resolve this
                return;
            } else {
                IStatus status = MarketplaceClientCore.computeStatus(e, NLS.bind(Messages.DiscoveryItem_FavoriteActionFailed, this.getNameLabelText()));
                MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
                return;
            }
        }
        setFavorited(newFavorited);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) IStatus(org.eclipse.core.runtime.IStatus) ConflictException(org.eclipse.userstorage.util.ConflictException) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) ConflictException(org.eclipse.userstorage.util.ConflictException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

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