use of org.eclipse.epp.mpc.core.model.ICategory in project epp.mpc by eclipse.
the class UnmarshallerTest method marketplaceRoot.
@Test
public void marketplaceRoot() throws IOException, UnmarshalException {
// from http://www.eclipseplugincentral.net/xml
Object model = processResource("resources/marketplace-root.xml");
assertNotNull(model);
assertTrue(model instanceof Marketplace);
Marketplace marketplace = (Marketplace) model;
assertEquals(4, marketplace.getMarket().size());
IMarket market = marketplace.getMarket().get(0);
assertEquals("31", market.getId());
assertEquals("Tools", market.getName());
assertEquals("http://www.eclipseplugincentral.net/category/markets/tools", market.getUrl());
assertEquals(36, market.getCategory().size());
ICategory category = market.getCategory().get(10);
assertEquals("24", category.getId());
assertEquals("IDE", category.getName());
assertEquals("http://www.eclipseplugincentral.net/taxonomy/term/24%2C31", category.getUrl());
}
use of org.eclipse.epp.mpc.core.model.ICategory in project epp.mpc by eclipse.
the class DefaultMarketplaceService method getCategory.
public Category getCategory(ICategory category, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 200);
if (category.getId() != null && category.getUrl() == null) {
List<Market> markets = listMarkets(progress.newChild(50));
ICategory resolvedCategory = null;
outer: for (Market market : markets) {
List<Category> categories = market.getCategory();
for (Category aCategory : categories) {
if (aCategory.equalsId(category)) {
resolvedCategory = aCategory;
break outer;
}
}
}
if (progress.isCanceled()) {
throw new OperationCanceledException();
} else if (resolvedCategory == null) {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_categoryNotFound, category.getId()));
} else {
return getCategory(resolvedCategory, progress.newChild(150));
}
}
Marketplace marketplace = processRequest(category.getUrl(), API_URI_SUFFIX, progress.newChild(200));
if (marketplace.getCategory().isEmpty()) {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_categoryNotFound, category.getUrl()));
} else if (marketplace.getCategory().size() > 1) {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_unexpectedResponse, category.getUrl()));
}
Category resolvedCategory = marketplace.getCategory().get(0);
return resolvedCategory;
}
use of org.eclipse.epp.mpc.core.model.ICategory in project epp.mpc by eclipse.
the class NewsUrlHandler method handleSearch.
@Override
protected boolean handleSearch(CatalogDescriptor descriptor, String url, String searchString, Map<String, String> params) {
MarketplaceWizard marketplaceWizard = viewer.getWizard();
// $NON-NLS-1$
String filterParam = params.get("filter");
// $NON-NLS-1$
String[] filters = filterParam.split(" ");
ICategory searchCategory = null;
IMarket searchMarket = null;
for (String filter : filters) {
if (filter.startsWith("tid:")) {
// $NON-NLS-1$
// $NON-NLS-1$
String id = filter.substring("tid:".length());
List<CatalogCategory> catalogCategories = marketplaceWizard.getCatalog().getCategories();
for (CatalogCategory catalogCategory : catalogCategories) {
if (catalogCategory instanceof MarketplaceCategory) {
MarketplaceCategory marketplaceCategory = (MarketplaceCategory) catalogCategory;
List<? extends IMarket> markets = marketplaceCategory.getMarkets();
for (IMarket market : markets) {
if (id.equals(market.getId())) {
searchMarket = market;
} else {
final List<? extends ICategory> categories = market.getCategory();
for (ICategory category : categories) {
if (id.equals(category.getId())) {
searchCategory = category;
}
}
}
}
}
}
}
}
marketplaceWizard.getCatalogPage().search(descriptor, searchMarket, searchCategory, searchString);
return true;
}
use of org.eclipse.epp.mpc.core.model.ICategory in project epp.mpc by eclipse.
the class BrowseCatalogItem method getMarketplaceUrl.
private static String getMarketplaceUrl(CatalogDescriptor catalogDescriptor, MarketplaceViewer viewer) throws URISyntaxException {
URL url = catalogDescriptor.getUrl();
try {
ContentType contentType = viewer.getQueryContentType();
if (contentType == ContentType.SEARCH) {
String queryText = viewer.getQueryText();
ICategory queryCategory = viewer.getQueryCategory();
IMarket queryMarket = viewer.getQueryMarket();
String path = new DefaultMarketplaceService(url).computeRelativeSearchUrl(queryMarket, queryCategory, queryText, false);
if (path != null) {
url = new URL(url, path);
}
}
} catch (IllegalArgumentException e) {
// should never happen
MarketplaceClientUi.error(e);
} catch (MalformedURLException e) {
// should never happen
MarketplaceClientUi.error(e);
}
URI uri = url.toURI();
return uri.toString();
}
use of org.eclipse.epp.mpc.core.model.ICategory in project epp.mpc by eclipse.
the class MarketplaceDiscoveryStrategy method performQuery.
public void performQuery(IMarket market, ICategory category, String queryText, IProgressMonitor monitor) throws CoreException {
final int totalWork = 1001;
SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_searchingMarketplace, totalWork);
try {
ISearchResult result;
MarketplaceCategory catalogCategory = findMarketplaceCategory(progress.newChild(1));
catalogCategory.setContents(Contents.QUERY);
SubMonitor nodeQueryProgress = progress.newChild(500);
try {
// check if the query matches a node url and just retrieve that node
result = performNodeQuery(queryText, nodeQueryProgress);
} catch (CoreException ex) {
// node not found, continue with regular query
result = null;
// no work was done
nodeQueryProgress.setWorkRemaining(0);
}
if (result == null) {
// regular query
// resolve market and category if necessary
IMarket resolvedMarket;
ICategory resolvedCategory;
try {
resolvedMarket = resolve(market, catalogCategory.getMarkets());
resolvedCategory = resolveCategory(category, catalogCategory.getMarkets());
} catch (IllegalArgumentException ex) {
throw new CoreException(MarketplaceClientCore.computeStatus(ex, Messages.MarketplaceDiscoveryStrategy_invalidFilter));
} catch (NoSuchElementException ex) {
throw new CoreException(MarketplaceClientCore.computeStatus(ex, Messages.MarketplaceDiscoveryStrategy_unknownFilter));
}
progress.setWorkRemaining(totalWork - 1);
result = marketplaceService.search(resolvedMarket, resolvedCategory, queryText, progress.newChild(500));
}
handleSearchResult(catalogCategory, result, progress.newChild(500));
if (result.getNodes().isEmpty()) {
catalogCategory.setMatchCount(0);
addCatalogItem(catalogCategory);
}
} finally {
progress.done();
}
}
Aggregations