Search in sources :

Example 1 with ConflictException

use of org.eclipse.userstorage.util.ConflictException 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 2 with ConflictException

use of org.eclipse.userstorage.util.ConflictException 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 ConflictException

use of org.eclipse.userstorage.util.ConflictException 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

ConflictException (org.eclipse.userstorage.util.ConflictException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NotAuthorizedException (org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException)2 INode (org.eclipse.epp.mpc.core.model.INode)2 IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 MarketplaceNodeCatalogItem (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)1 ProtocolException (org.eclipse.userstorage.util.ProtocolException)1