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();
}
}
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
}
}
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()));
}
}
}
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);
}
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);
}
}
Aggregations