use of org.eclipse.epp.internal.mpc.core.model.Category in project epp.mpc by eclipse.
the class CategoryContentHandler method startElement.
@Override
public void startElement(String uri, String localName, Attributes attributes) {
if (localName.equals("category")) {
// $NON-NLS-1$
model = new Category();
// $NON-NLS-1$
model.setId(attributes.getValue(NS_URI, "id"));
// $NON-NLS-1$
model.setName(attributes.getValue(NS_URI, "name"));
// $NON-NLS-1$
model.setUrl(attributes.getValue(NS_URI, "url"));
// $NON-NLS-1$
model.setCount(toInteger(attributes.getValue(NS_URI, "count")));
} else if (localName.equals("node")) {
// $NON-NLS-1$
org.eclipse.epp.internal.mpc.core.service.xml.NodeContentHandler childHandler = new org.eclipse.epp.internal.mpc.core.service.xml.NodeContentHandler();
childHandler.setParentModel(model);
childHandler.setParentHandler(this);
childHandler.setUnmarshaller(getUnmarshaller());
getUnmarshaller().setCurrentHandler(childHandler);
childHandler.startElement(uri, localName, attributes);
}
}
use of org.eclipse.epp.internal.mpc.core.model.Category in project epp.mpc by eclipse.
the class DefaultMarketplaceServiceTest method computeRelativeSearchUrl.
/**
* bug 302825 - Make sure that search URLs have the following form:<br/>
* <code>http://marketplace.eclipse.org/api/p/search/apachesolr_search/WikiText?filters=tid:38%20tid:31</code>
* <p>
* bug 397004 - If both market and category are provided, make sure market is listed first
*/
@Test
public void computeRelativeSearchUrl() {
DefaultMarketplaceService service = new DefaultMarketplaceService();
String marketId = "31";
String categoryId = "38";
String query = "some query";
Market market = new Market();
market.setId(marketId);
Category category = new Category();
category.setId(categoryId);
String apiSearchPrefix = DefaultMarketplaceService.API_SEARCH_URI_FULL;
String searchUrl = service.computeRelativeSearchUrl(null, null, query, true);
assertEquals(apiSearchPrefix + "some+query", searchUrl);
searchUrl = service.computeRelativeSearchUrl(market, null, query, true);
assertEquals(apiSearchPrefix + "some+query?filters=tid:" + marketId, searchUrl);
searchUrl = service.computeRelativeSearchUrl(null, category, query, true);
assertEquals(apiSearchPrefix + "some+query?filters=tid:" + categoryId, searchUrl);
// bug 397004 - make sure market comes first for api
searchUrl = service.computeRelativeSearchUrl(market, category, query, true);
assertEquals(apiSearchPrefix + "some+query?filters=tid:" + marketId + "%20tid:" + categoryId, searchUrl);
// bug 397004 - make sure category comes first for browser
searchUrl = service.computeRelativeSearchUrl(market, category, query, false);
assertEquals(DefaultMarketplaceService.API_SEARCH_URI + "some+query?filters=tid:" + categoryId + "%20tid:" + marketId, searchUrl);
searchUrl = service.computeRelativeSearchUrl(market, null, null, true);
assertEquals(DefaultMarketplaceService.API_TAXONOMY_URI + marketId + "/" + RemoteMarketplaceService.API_URI_SUFFIX, searchUrl);
searchUrl = service.computeRelativeSearchUrl(null, category, null, false);
assertEquals(DefaultMarketplaceService.API_TAXONOMY_URI + categoryId, searchUrl);
// taxonomy uri is category-first for both API and browser
searchUrl = service.computeRelativeSearchUrl(market, category, null, true);
assertEquals(DefaultMarketplaceService.API_TAXONOMY_URI + categoryId + "," + marketId + "/" + RemoteMarketplaceService.API_URI_SUFFIX, searchUrl);
searchUrl = service.computeRelativeSearchUrl(market, category, null, false);
assertEquals(DefaultMarketplaceService.API_TAXONOMY_URI + categoryId + "," + marketId, searchUrl);
}
use of org.eclipse.epp.internal.mpc.core.model.Category in project epp.mpc by eclipse.
the class DefaultMarketplaceService method processSearchRequest.
private SearchResult processSearchRequest(String relativeUrl, String queryText, IProgressMonitor monitor) throws CoreException {
SearchResult result = new SearchResult();
if (relativeUrl == null) {
// empty search
result.setMatchCount(0);
result.setNodes(new ArrayList<Node>());
} else {
Marketplace marketplace;
try {
marketplace = processRequest(relativeUrl, monitor);
} catch (CoreException ex) {
Throwable cause = ex.getCause();
if (cause instanceof FileNotFoundException) {
throw new CoreException(createErrorStatus(NLS.bind(Messages.DefaultMarketplaceService_UnsupportedSearchString, queryText), cause));
}
throw ex;
}
Search search = marketplace.getSearch();
if (search != null) {
result.setMatchCount(search.getCount());
result.setNodes(search.getNode());
} else if (marketplace.getCategory().size() == 1) {
Category category = marketplace.getCategory().get(0);
result.setMatchCount(category.getNode().size());
result.setNodes(category.getNode());
} else {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_unexpectedResponse, relativeUrl));
}
}
return result;
}
use of org.eclipse.epp.internal.mpc.core.model.Category 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;
}
Aggregations