use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class MarketplaceCatalogTest method setupCatalog.
protected void setupCatalog() throws MalformedURLException {
final SearchResult discoveryResult = new SearchResult();
discoveryResult.setNodes(discoveryNodes);
CatalogDescriptor catalogDescriptor = new CatalogDescriptor();
catalogDescriptor.setUrl(new URL("http://marketplace.eclipse.org"));
MarketplaceDiscoveryStrategy discoveryStrategy = new MarketplaceDiscoveryStrategy(catalogDescriptor) {
final MarketplaceCategory category = new MarketplaceCategory();
{
category.setId("<root>");
}
@Override
public void performDiscovery(IProgressMonitor monitor) throws CoreException {
if (!categories.contains(category)) {
categories.add(category);
}
handleSearchResult(category, discoveryResult, new NullProgressMonitor());
}
@Override
protected synchronized Map<String, IInstallableUnit> computeInstalledIUs(IProgressMonitor monitor) {
Map<String, IInstallableUnit> installedIus = new HashMap<String, IInstallableUnit>();
for (INode node : installedNodes) {
IIus ius = node.getIus();
if (ius != null) {
for (IIu iu : ius.getIuElements()) {
String featureId = iu.getId() + ".feature.group";
InstallableUnit installableUnit = new InstallableUnit();
installableUnit.setId(featureId);
installedIus.put(featureId, installableUnit);
}
}
}
return installedIus;
}
@Override
protected MarketplaceCategory findMarketplaceCategory(IProgressMonitor monitor) throws CoreException {
return category;
}
};
catalog = new MarketplaceCatalog() {
@Override
protected IStatus checkForUpdates(List<MarketplaceNodeCatalogItem> updateCheckNeeded, final Map<String, IInstallableUnit> installedIUs, final IProgressMonitor monitor) {
for (MarketplaceNodeCatalogItem item : updateCheckNeeded) {
checkedForUpdate.add(item.getData());
List<MarketplaceNodeInstallableUnitItem> installableUnitItems = item.getInstallableUnitItems();
boolean hasUpdate = updateAvailable.contains(item.getData());
for (MarketplaceNodeInstallableUnitItem iuItem : installableUnitItems) {
iuItem.setUpdateAvailable(hasUpdate);
}
}
return Status.OK_STATUS;
}
};
catalog.getDiscoveryStrategies().add(discoveryStrategy);
}
use of org.eclipse.epp.mpc.core.model.INode 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.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class UserFavoritesService method doAlterFavorites.
private void doAlterFavorites(Collection<? extends INode> nodes, boolean favorite, IProgressMonitor monitor) throws ConflictException, IOException {
SubMonitor progress = SubMonitor.convert(monitor, Messages.UserFavoritesService_SettingUserFavorites, 1000);
List<INode> favorites = getFavorites(progress.newChild(300));
for (INode node : nodes) {
INode currentFavorite = QueryHelper.findById(favorites, node);
if (currentFavorite != null && !favorite) {
favorites.remove(currentFavorite);
} else if (currentFavorite == null && favorite) {
favorites.add(node);
}
}
setFavorites(favorites, progress.newChild(700));
}
use of org.eclipse.epp.mpc.core.model.INode 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.mpc.core.model.INode in project epp.mpc by eclipse.
the class MarketplaceDiscoveryStrategy method performNodeQuery.
public void performNodeQuery(IProgressMonitor monitor, Set<? extends INode> nodes) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_searchingMarketplace, 1001);
try {
MarketplaceCategory catalogCategory = findMarketplaceCategory(progress.newChild(1));
catalogCategory.setContents(Contents.QUERY);
SearchResult result = new SearchResult();
result.setNodes(new ArrayList<Node>());
if (!monitor.isCanceled()) {
if (!nodes.isEmpty()) {
List<INode> resolvedNodes = marketplaceService.getNodes(nodes, progress.newChild(500));
for (INode node : resolvedNodes) {
result.getNodes().add((Node) node);
}
} else {
progress.setWorkRemaining(500);
}
result.setMatchCount(result.getNodes().size());
handleSearchResult(catalogCategory, result, progress.newChild(500));
}
} finally {
monitor.done();
}
}
Aggregations