use of org.eclipse.epp.internal.mpc.core.model.Node in project epp.mpc by eclipse.
the class DefaultMarketplaceService method resolveFavoriteNodes.
private ISearchResult resolveFavoriteNodes(final List<INode> nodes, IProgressMonitor monitor, boolean filterIncompatible) throws CoreException {
IMarketplaceService resolveService = this;
IMarketplaceService registeredService = ServiceHelper.getMarketplaceServiceLocator().getMarketplaceService(this.getBaseUrl().toString());
if (registeredService instanceof CachingMarketplaceService) {
CachingMarketplaceService cachingService = (CachingMarketplaceService) registeredService;
if (cachingService.getDelegate() == this) {
resolveService = cachingService;
}
}
final List<INode> resolvedNodes = resolveService.getNodes(nodes, monitor);
for (ListIterator<INode> i = resolvedNodes.listIterator(); i.hasNext(); ) {
INode resolved = i.next();
((Node) resolved).setUserFavorite(true);
if (filterIncompatible && !isInstallable(resolved)) {
i.remove();
}
}
if (!filterIncompatible) {
// sort the node list so uninstallable nodes come last
Collections.sort(resolvedNodes, new Comparator<INode>() {
public int compare(INode n1, INode n2) {
if (n1 == n2) {
return 0;
}
boolean n1Installable = isInstallable(n1);
boolean n2Installable = isInstallable(n2);
if (n1Installable == n2Installable) {
return 0;
}
if (n1Installable) {
// && !n2Installable
return -1;
}
// !n1Installable && n2Installable
return 1;
}
});
}
return new ISearchResult() {
public List<? extends INode> getNodes() {
return resolvedNodes;
}
public Integer getMatchCount() {
return resolvedNodes.size();
}
};
}
use of org.eclipse.epp.internal.mpc.core.model.Node in project epp.mpc by eclipse.
the class DefaultMarketplaceService method getNode.
public Node getNode(INode node, IProgressMonitor monitor) throws CoreException {
Marketplace marketplace;
String query;
if (node.getId() != null) {
// bug 304928: prefer the id method rather than the URL, since the id provides a stable URL and the
// URL is based on the name, which could change.
query = node.getId();
String encodedId = urlEncode(node.getId());
marketplace = processRequest(API_NODE_URI + '/' + encodedId + '/' + API_URI_SUFFIX, monitor);
} else {
query = node.getUrl();
marketplace = processRequest(node.getUrl(), API_URI_SUFFIX, monitor);
}
if (marketplace.getNode().isEmpty()) {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_nodeNotFound, query));
} else if (marketplace.getNode().size() > 1) {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_unexpectedResponse, query));
}
Node resolvedNode = marketplace.getNode().get(0);
return resolvedNode;
}
use of org.eclipse.epp.internal.mpc.core.model.Node 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.model.Node in project epp.mpc by eclipse.
the class AbstractMarketplaceWizardBotTest method testNode.
private static INode testNode(String id, String url, String name) {
Node node = (Node) QueryHelper.nodeById(id);
node.setUrl(url);
node.setName(name);
return node;
}
use of org.eclipse.epp.internal.mpc.core.model.Node in project epp.mpc by eclipse.
the class MarketplaceDiscoveryStrategyTest method testSearchByNodeUrl.
@Test
public void testSearchByNodeUrl() throws Exception {
final INode[] testNode = new INode[1];
final IMarketplaceService marketplaceService = new DefaultMarketplaceService(catalogUrl) {
@Override
public Node getNode(INode node, IProgressMonitor monitor) throws CoreException {
testNode[0] = node;
return (Node) node;
}
@Override
public SearchResult search(IMarket market, ICategory category, String queryText, IProgressMonitor monitor) throws CoreException {
Assert.fail("Unexpected invocation");
// dead code
return null;
}
};
setupCatalog(marketplaceService);
testNode[0] = null;
catalog.performQuery(null, null, new URL(catalogUrl, "content/test").toExternalForm(), new NullProgressMonitor());
assertNotNull(testNode[0]);
assertNotNull(testNode[0].getUrl());
testNode[0] = null;
catalog.performQuery(null, null, new URL(catalogUrl, "node/12345").toExternalForm(), new NullProgressMonitor());
assertNotNull(testNode[0]);
assertNotNull(testNode[0].getId());
}
Aggregations