use of org.eclipse.epp.mpc.core.model.ICategory in project epp.mpc by eclipse.
the class MarketplaceDiscoveryStrategy method resolveCategory.
private static ICategory resolveCategory(ICategory category, List<? extends IMarket> markets) throws IllegalArgumentException, NoSuchElementException {
if (category != null && category.getId() == null) {
// need to resolve
if (category.getUrl() == null && category.getName() == null) {
throw new IllegalArgumentException(NLS.bind(Messages.MarketplaceDiscoveryStrategy_unidentifiableItem, category));
}
for (IMarket market : markets) {
List<? extends ICategory> categories = market.getCategory();
ICategory resolved = resolve(category, categories);
if (resolved != null) {
return resolved;
}
}
if (category.getUrl() != null) {
throw new NoSuchElementException(NLS.bind(Messages.MarketplaceDiscoveryStrategy_noUrlMatch, category.getUrl()));
} else {
throw new NoSuchElementException(NLS.bind(Messages.MarketplaceDiscoveryStrategy_noNameMatch, category.getName()));
}
}
return category;
}
use of org.eclipse.epp.mpc.core.model.ICategory 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);
}
}
}
}
Aggregations