use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class DefaultMarketplaceService method getNodesByUrl.
private void getNodesByUrl(Collection<? extends INode> nodes, Map<INode, INode> resolvedNodeMapping, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, nodes.size());
int remaining = nodes.size();
for (INode node : nodes) {
if (node.getId() == null && node.getUrl() != null) {
Node resolvedNode = getNode(node, progress.newChild(1));
resolvedNodeMapping.put(node, resolvedNode);
}
progress.setWorkRemaining(--remaining);
}
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class DefaultMarketplaceService method getNodesById.
private void getNodesById(Collection<? extends INode> nodes, Map<INode, INode> resolvedNodeMapping, IProgressMonitor monitor) throws CoreException {
StringBuilder nodeIdQuery = new StringBuilder();
Map<String, INode> nodeIds = new HashMap<String, INode>(nodes.size());
for (INode node : nodes) {
if (node.getId() == null) {
continue;
}
nodeIds.put(node.getId(), node);
String encodedId = urlEncode(node.getId());
if (nodeIdQuery.length() > 0) {
// $NON-NLS-1$
nodeIdQuery.append(",");
}
nodeIdQuery.append(encodedId);
}
Marketplace marketplace = processRequest(API_NODE_URI + '/' + nodeIdQuery + '/' + API_URI_SUFFIX, monitor);
List<Node> resolvedNodes = marketplace.getNode();
for (Node node : resolvedNodes) {
INode inputNode = nodeIds.get(node.getId());
if (inputNode != null) {
resolvedNodeMapping.put(inputNode, node);
} else {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_unexpectedResponse, nodeIdQuery));
}
}
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class DefaultMarketplaceService method getNodes.
public List<INode> getNodes(Collection<? extends INode> nodes, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, Messages.DefaultMarketplaceService_getNodesProgress, nodes.size());
if (nodes.isEmpty()) {
return new ArrayList<INode>();
}
List<INode> nodesById = null;
List<INode> nodesByUrl = null;
for (INode node : nodes) {
if (node.getId() == null) {
if (node.getUrl() == null) {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_invalidNode, node));
}
if (nodesByUrl == null) {
nodesByUrl = new ArrayList<INode>();
}
nodesByUrl.add(node);
} else {
if (nodesById == null) {
nodesById = new ArrayList<INode>(nodes.size());
}
nodesById.add(node);
}
}
Map<INode, INode> resolvedNodeMapping = new HashMap<INode, INode>(nodes.size());
if (nodesById != null) {
getNodesById(nodesById, resolvedNodeMapping, progress.newChild(nodesById.size()));
}
if (nodesByUrl != null) {
getNodesByUrl(nodesByUrl, resolvedNodeMapping, progress.newChild(nodesByUrl.size()));
}
List<INode> resultNodes = new ArrayList<INode>(nodes.size());
MultiStatus missingNodes = null;
for (INode inputNode : nodes) {
INode resolvedNode = resolvedNodeMapping.get(inputNode);
if (resolvedNode != null) {
resultNodes.add(resolvedNode);
} else {
String query;
if (inputNode.getId() != null) {
query = inputNode.getId();
} else {
query = inputNode.getUrl();
}
IStatus missingNodeDetailStatus = createStatus(IStatus.INFO, Messages.DefaultMarketplaceService_nodeNotFound, query);
if (missingNodes == null) {
missingNodes = new MultiStatus(MarketplaceClientCore.BUNDLE_ID, 0, "Some entries could not be found on the Marketplace", // $NON-NLS-1$
null);
}
missingNodes.add(missingNodeDetailStatus);
}
}
if (missingNodes != null) {
MarketplaceClientCore.getLog().log(missingNodes);
}
return resultNodes;
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class DefaultMarketplaceService method userFavorites.
public ISearchResult userFavorites(IProgressMonitor monitor) throws CoreException, NotAuthorizedException {
SubMonitor progress = SubMonitor.convert(monitor, Messages.DefaultMarketplaceService_FavoritesRetrieve, 10000);
IUserFavoritesService userFavoritesService = getUserFavoritesService();
if (userFavoritesService == null) {
throw new UnsupportedOperationException();
}
final List<INode> favorites;
try {
favorites = userFavoritesService.getFavorites(progress.newChild(1000));
} catch (NotAuthorizedException e) {
throw e;
} catch (Exception e) {
throw new CoreException(MarketplaceClientCore.computeStatus(e, Messages.DefaultMarketplaceService_FavoritesErrorRetrieving));
}
progress.setWorkRemaining(9000);
return resolveFavoriteNodes(favorites, progress.newChild(9000), true);
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class MarketplaceViewer method doQuery.
private IStatus doQuery(final QueryData queryData, final Set<? extends INode> nodes) {
try {
final ContentType queryType = contentType;
queryContentType = queryType;
final IStatus[] result = new IStatus[1];
context.run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
switch(queryType) {
case POPULAR:
result[0] = getCatalog().popular(monitor);
break;
case RECENT:
result[0] = getCatalog().recent(monitor);
break;
case RELATED:
result[0] = getCatalog().related(monitor);
break;
case INSTALLED:
result[0] = getCatalog().installed(monitor);
break;
case FAVORITES:
result[0] = getCatalog().userFavorites(false, monitor);
break;
case SELECTION:
Set<String> nodeIds = new HashSet<String>();
for (CatalogItem item : getSelectionModel().getItemToSelectedOperation().keySet()) {
nodeIds.add(((INode) item.getData()).getId());
}
result[0] = getCatalog().performQuery(monitor, nodeIds);
break;
case SEARCH:
case FEATURED_MARKET:
default:
if (nodes != null && !nodes.isEmpty()) {
result[0] = getCatalog().performNodeQuery(monitor, nodes);
} else if (queryData.queryText != null && queryData.queryText.length() > 0) {
String tag = getTagQuery(queryData.queryText);
if (tag != null) {
result[0] = getCatalog().tagged(tag, monitor);
} else {
result[0] = getCatalog().performQuery(queryData.queryMarket, queryData.queryCategory, queryData.queryText, monitor);
}
} else {
result[0] = getCatalog().featured(monitor, queryData.queryMarket, queryData.queryCategory);
}
break;
}
if (!monitor.isCanceled() && result[0] != null && result[0].getSeverity() != IStatus.CANCEL) {
getCatalog().checkForUpdates(monitor);
}
MarketplaceViewer.this.getControl().getDisplay().syncExec(new Runnable() {
public void run() {
updateViewer(queryData.queryText);
}
});
}
});
if (result[0] != null && !result[0].isOK() && result[0].getSeverity() != IStatus.CANCEL) {
MarketplaceClientUi.handle(result[0], (result[0].getSeverity() > IStatus.WARNING ? StatusManager.SHOW | StatusManager.BLOCK : 0) | StatusManager.LOG);
return result[0];
} else {
verifyUpdateSiteAvailability();
return Status.OK_STATUS;
}
} catch (InvocationTargetException e) {
IStatus status = computeStatus(e, Messages.MarketplaceViewer_unexpectedException);
MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
return status;
} catch (InterruptedException e) {
// cancelled by user so nothing to do here.
return Status.CANCEL_STATUS;
}
}
Aggregations