use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class MarketplaceDiscoveryStrategy method installErrorReport.
public void installErrorReport(IProgressMonitor monitor, IStatus result, Set<CatalogItem> items, IInstallableUnit[] operationIUs, String resolutionDetails) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_sendingErrorNotification, 100);
try {
Set<Node> nodes = new HashSet<Node>();
for (CatalogItem item : items) {
Object data = item.getData();
if (data instanceof INode) {
nodes.add((Node) data);
}
}
Set<String> iuIdsAndVersions = new HashSet<String>();
for (IInstallableUnit iu : operationIUs) {
String id = iu.getId();
String version = iu.getVersion() == null ? null : iu.getVersion().toString();
// $NON-NLS-1$
iuIdsAndVersions.add(id + "," + version);
}
marketplaceService.reportInstallError(result, nodes, iuIdsAndVersions, resolutionDetails, progress);
} finally {
progress.done();
}
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class MarketplaceDiscoveryStrategy method performNodeQuery.
private ISearchResult performNodeQuery(String nodeUrl, IProgressMonitor progress) throws CoreException {
final INode[] queryNode = new INode[1];
MarketplaceUrlHandler urlHandler = new MarketplaceUrlHandler() {
@Override
protected boolean handleNode(CatalogDescriptor descriptor, String url, INode node) {
queryNode[0] = node;
return true;
}
};
if (urlHandler.handleUri(nodeUrl) && queryNode[0] != null) {
INode node = marketplaceService.getNode(queryNode[0], progress);
SearchResult result = new SearchResult();
result.setMatchCount(1);
result.setNodes(Collections.singletonList((Node) node));
return result;
}
return null;
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class MarketplaceDiscoveryStrategy method handleSearchResult.
protected void handleSearchResult(MarketplaceCategory catalogCategory, ISearchResult result, final IProgressMonitor monitor) {
List<CatalogItem> items = getItems();
if (items != null && !result.getNodes().isEmpty()) {
int nodeWork = 1000;
int favoritesWork = catalogCategory.getContents() == Contents.USER_FAVORITES ? 0 : 1000;
SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_loadingResources, result.getNodes().size() * nodeWork + favoritesWork);
try {
boolean userFavoritesSupported = false;
if (catalogCategory.getContents() == Contents.USER_FAVORITES) {
userFavoritesSupported = true;
} else if (hasUserFavoritesService()) {
try {
applyShellProvider();
marketplaceService.userFavorites(result.getNodes(), progress.newChild(favoritesWork));
userFavoritesSupported = true;
} catch (NotAuthorizedException e1) {
// user is not logged in. we just ignore this.
} catch (UnsupportedOperationException e1) {
// ignore
} catch (Exception e1) {
// something went wrong. log and proceed.
MarketplaceClientCore.error(Messages.MarketplaceDiscoveryStrategy_FavoritesRetrieveError, e1);
}
}
for (final INode node : result.getNodes()) {
String id = node.getId();
try {
final MarketplaceNodeCatalogItem catalogItem = new MarketplaceNodeCatalogItem();
catalogItem.setMarketplaceUrl(catalogDescriptor.getUrl());
catalogItem.setId(id);
catalogItem.setName(getCatalogItemName(node));
catalogItem.setCategoryId(catalogCategory.getId());
ICategories categories = node.getCategories();
if (categories != null) {
for (ICategory category : categories.getCategory()) {
catalogItem.addTag(new Tag(ICategory.class, category.getId(), category.getName()));
}
}
catalogItem.setData(node);
catalogItem.setSource(source);
catalogItem.setLicense(node.getLicense());
catalogItem.setUserFavorite(userFavoritesSupported ? node.getUserFavorite() : null);
IIus ius = node.getIus();
if (ius != null) {
List<MarketplaceNodeInstallableUnitItem> installableUnitItems = new ArrayList<MarketplaceNodeInstallableUnitItem>();
for (IIu iu : ius.getIuElements()) {
MarketplaceNodeInstallableUnitItem iuItem = new MarketplaceNodeInstallableUnitItem();
iuItem.init(iu);
installableUnitItems.add(iuItem);
}
catalogItem.setInstallableUnitItems(installableUnitItems);
}
if (node.getShortdescription() == null && node.getBody() != null) {
// bug 306653 <!--break--> marks the end of the short description.
String descriptionText = node.getBody();
Matcher matcher = BREAK_PATTERN.matcher(node.getBody());
if (matcher.find()) {
int start = matcher.start();
if (start > 0) {
String shortDescriptionText = descriptionText.substring(0, start).trim();
if (shortDescriptionText.length() > 0) {
descriptionText = shortDescriptionText;
}
}
}
catalogItem.setDescription(descriptionText);
} else {
catalogItem.setDescription(node.getShortdescription());
}
catalogItem.setProvider(node.getCompanyname());
String updateurl = node.getUpdateurl();
if (updateurl != null) {
try {
// trim is important!
updateurl = updateurl.trim();
URLUtil.toURL(updateurl);
catalogItem.setSiteUrl(updateurl);
} catch (MalformedURLException e) {
// don't use malformed URLs
}
}
if (catalogItem.getInstallableUnits() == null || catalogItem.getInstallableUnits().isEmpty() || catalogItem.getSiteUrl() == null) {
catalogItem.setAvailable(false);
}
if (node.getImage() != null) {
if (!source.getResourceProvider().containsResource(node.getImage())) {
cacheResource(source.getResourceProvider(), catalogItem, node.getImage());
}
createIcon(catalogItem, node);
}
if (node.getBody() != null || node.getScreenshot() != null) {
final Overview overview = new Overview();
overview.setItem(catalogItem);
overview.setSummary(node.getBody());
overview.setUrl(node.getUrl());
catalogItem.setOverview(overview);
if (node.getScreenshot() != null) {
if (!source.getResourceProvider().containsResource(node.getScreenshot())) {
cacheResource(source.getResourceProvider(), catalogItem, node.getScreenshot());
}
overview.setScreenshot(node.getScreenshot());
}
}
items.add(catalogItem);
marketplaceInfo.map(catalogItem.getMarketplaceUrl(), node);
marketplaceInfo.computeInstalled(computeInstalledFeatures(progress.newChild(nodeWork)), catalogItem);
} catch (RuntimeException ex) {
MarketplaceClientUi.error(NLS.bind(Messages.MarketplaceDiscoveryStrategy_ParseError, // $NON-NLS-1$
node == null ? "null" : id), ex);
}
}
} finally {
progress.done();
}
if (result.getMatchCount() != null) {
catalogCategory.setMatchCount(result.getMatchCount());
if (result.getMatchCount() > result.getNodes().size()) {
// add an item here to indicate that the search matched more items than were returned by the server
addCatalogItem(catalogCategory);
}
}
}
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class MarketplaceInfo method computeInstalledNodes.
/**
* Calculate the known catalog nodes that might be installed. Since no remote query should happen, this only checks
* if any one of the IUs for a node are installed.
*
* @param repositoryUrl
* the catalog url for which installed nodes should be computed
* @param installedIus
* all of the currently installed IUs
* @return a set of node ids, or an empty set if there are no known installed nodes
* @deprecated use {@link #computeInstalledNodes(URL, Map)} instead
*/
@Deprecated
public synchronized Set<INode> computeInstalledNodes(URL repositoryUrl, Set<String> installedIus) {
Set<INode> nodes = new HashSet<INode>();
String keyPrefix = computeUrlKey(repositoryUrl) + '#';
for (Map.Entry<String, List<String>> entry : nodeKeyToIU.entrySet()) {
if (entry.getKey().startsWith(keyPrefix)) {
List<String> ius = nodeKeyToIU.get(entry.getKey());
if (computeInstalled(installedIus, ius, false)) {
String nodeId = entry.getKey().substring(keyPrefix.length());
Node node = new Node();
node.setId(nodeId);
nodes.add(node);
}
}
}
return nodes;
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class MarketplaceInfo method computeInstalledNodes.
/**
* Calculate the known catalog nodes that might be installed. Since no remote query should happen, this only checks
* if any one of the IUs for a node are installed.
*
* @param repositoryUrl
* the catalog url for which installed nodes should be computed
* @param installedIus
* all of the currently installed IUs
* @return a set of node ids, or an empty set if there are no known installed nodes
*/
public synchronized Set<INode> computeInstalledNodes(URL repositoryUrl, Map<String, IInstallableUnit> installedIus) {
Set<INode> nodes = new HashSet<INode>();
String keyPrefix = computeUrlKey(repositoryUrl) + '#';
for (Map.Entry<String, List<String>> entry : nodeKeyToIU.entrySet()) {
if (entry.getKey().startsWith(keyPrefix)) {
List<String> ius = nodeKeyToIU.get(entry.getKey());
if (computeInstalled(installedIus.keySet(), ius, false)) {
String nodeId = entry.getKey().substring(keyPrefix.length());
INode node = QueryHelper.nodeById(nodeId);
nodes.add(node);
}
}
}
for (IInstallableUnit iu : installedIus.values()) {
String nodeUrl = iu.getProperty(MPC_NODE_IU_PROPERTY);
if (nodeUrl != null && nodeUrl.startsWith(repositoryUrl.toString())) {
INode node = QueryHelper.nodeByUrl(nodeUrl);
nodes.add(node);
}
}
return nodes;
}
Aggregations