use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class MarketplaceDiscoveryStrategy method performQuery.
public void performQuery(IProgressMonitor monitor, Set<String> nodeIds) throws CoreException {
Set<INode> nodes = new HashSet<INode>();
for (String nodeId : nodeIds) {
Node node = new Node();
node.setId(nodeId);
nodes.add(node);
}
performNodeQuery(monitor, nodes);
}
use of org.eclipse.epp.mpc.core.model.INode 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.mpc.core.model.INode in project epp.mpc by eclipse.
the class DefaultMarketplaceService method reportInstallError.
public void reportInstallError(IStatus result, Set<? extends INode> nodes, Set<String> iuIdsAndVersions, String resolutionDetails, IProgressMonitor monitor) throws CoreException {
HttpClient client;
URL location;
HttpPost method;
try {
// $NON-NLS-1$
location = new URL(baseUrl, "install/error/report");
String target = location.toURI().toString();
client = HttpUtil.createHttpClient(target);
method = new HttpPost(target);
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
} catch (MalformedURLException e) {
throw new IllegalStateException(e);
}
try {
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
Map<String, String> requestMetaParameters = getRequestMetaParameters();
for (Map.Entry<String, String> metaParam : requestMetaParameters.entrySet()) {
if (metaParam.getKey() != null) {
parameters.add(new BasicNameValuePair(metaParam.getKey(), metaParam.getValue()));
}
}
// $NON-NLS-1$
parameters.add(new BasicNameValuePair("status", Integer.toString(result.getSeverity())));
// $NON-NLS-1$
parameters.add(new BasicNameValuePair("statusMessage", result.getMessage()));
for (INode node : nodes) {
// $NON-NLS-1$
parameters.add(new BasicNameValuePair("node", node.getId()));
}
if (iuIdsAndVersions != null && !iuIdsAndVersions.isEmpty()) {
for (String iuAndVersion : iuIdsAndVersions) {
// $NON-NLS-1$
parameters.add(new BasicNameValuePair("iu", iuAndVersion));
}
}
// $NON-NLS-1$
parameters.add(new BasicNameValuePair("detailedMessage", resolutionDetails));
if (!parameters.isEmpty()) {
// $NON-NLS-1$
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters, "UTF-8");
method.setEntity(entity);
client.execute(method);
}
} catch (IOException e) {
String message = NLS.bind(Messages.DefaultMarketplaceService_cannotCompleteRequest_reason, location.toString(), e.getMessage());
throw new CoreException(createErrorStatus(message, e));
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class DefaultMarketplaceService method related.
public SearchResult related(List<? extends INode> basedOn, IProgressMonitor monitor) throws CoreException {
// $NON-NLS-1$
String basedOnQuery = "";
if (basedOn != null && !basedOn.isEmpty()) {
StringBuilder sb = new StringBuilder().append('?').append(PARAM_BASED_ON_NODES).append('=');
boolean first = true;
for (INode node : basedOn) {
if (!first) {
sb.append('+');
}
sb.append(node.getId());
first = false;
}
basedOnQuery = sb.toString();
}
Marketplace marketplace = processRequest(API_RELATED_URI + '/' + API_URI_SUFFIX + basedOnQuery, monitor);
return createSearchResult(marketplace.getRelated());
}
use of org.eclipse.epp.mpc.core.model.INode 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;
}
Aggregations