Search in sources :

Example 1 with ProtocolException

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);
        }
    }
}
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 2 with ProtocolException

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;
    }
}
Also used : ProtocolException(org.eclipse.userstorage.util.ProtocolException) ConflictException(org.eclipse.userstorage.util.ConflictException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor)

Example 3 with ProtocolException

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);
    }
}
Also used : ProtocolException(org.eclipse.userstorage.util.ProtocolException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(org.eclipse.userstorage.util.NotFoundException)

Aggregations

OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 SubMonitor (org.eclipse.core.runtime.SubMonitor)3 ProtocolException (org.eclipse.userstorage.util.ProtocolException)3 FileNotFoundException (java.io.FileNotFoundException)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 INode (org.eclipse.epp.mpc.core.model.INode)1 ConflictException (org.eclipse.userstorage.util.ConflictException)1 NotFoundException (org.eclipse.userstorage.util.NotFoundException)1