use of org.eclipse.userstorage.util.ProtocolException 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);
}
}
}
use of org.eclipse.userstorage.util.ProtocolException in project epp.mpc by eclipse.
the class UserFavoritesService method alterFavorites.
private void alterFavorites(Collection<? extends INode> nodes, boolean favorite, IProgressMonitor monitor) throws NotAuthorizedException, ConflictException, IOException {
SubMonitor progress = SubMonitor.convert(monitor, Messages.UserFavoritesService_SettingUserFavorites, 1000);
ConflictException conflictException = null;
for (int i = 0; i < RETRY_COUNT; i++) {
try {
progress.setWorkRemaining(1000);
doAlterFavorites(nodes, favorite, progress.newChild(800));
progress.done();
return;
} catch (ConflictException e) {
conflictException = e;
} catch (OperationCanceledException ex) {
throw processProtocolException(ex);
} catch (ProtocolException ex) {
throw processProtocolException(ex);
}
}
if (conflictException != null) {
throw conflictException;
}
}
use of org.eclipse.userstorage.util.ProtocolException in project epp.mpc by eclipse.
the class UserFavoritesService method getFavoriteIds.
public Set<String> getFavoriteIds(IProgressMonitor monitor) throws NoServiceException, NotAuthorizedException, IllegalStateException, IOException {
SubMonitor progress = SubMonitor.convert(monitor, Messages.DefaultMarketplaceService_FavoritesRetrieve, 1000);
try {
String favoritesData = getFavoritesBlob().getContentsUTF();
// FIXME waiting for USS bug 488335 to have proper progress and cancelation
progress.worked(950);
Set<String> result = parseFavoritesBlobData(favoritesData);
synchronized (this) {
favorites.clear();
favorites.addAll(result);
}
return result;
} catch (NotFoundException ex) {
// the user does not yet have favorites
return new LinkedHashSet<String>();
} catch (OperationCanceledException ex) {
throw processProtocolException(ex);
} catch (ProtocolException ex) {
throw processProtocolException(ex);
}
}
Aggregations