Search in sources :

Example 1 with Category

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);
    }
}
Also used : Category(org.eclipse.epp.internal.mpc.core.model.Category)

Example 2 with Category

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);
}
Also used : Category(org.eclipse.epp.internal.mpc.core.model.Category) ICategory(org.eclipse.epp.mpc.core.model.ICategory) DefaultMarketplaceService(org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService) Market(org.eclipse.epp.internal.mpc.core.model.Market) IMarket(org.eclipse.epp.mpc.core.model.IMarket) Test(org.junit.Test)

Example 3 with Category

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;
}
Also used : Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace) Category(org.eclipse.epp.internal.mpc.core.model.Category) ICategory(org.eclipse.epp.mpc.core.model.ICategory) CoreException(org.eclipse.core.runtime.CoreException) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) Search(org.eclipse.epp.internal.mpc.core.model.Search) FileNotFoundException(java.io.FileNotFoundException) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult)

Example 4 with Category

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;
}
Also used : Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace) Category(org.eclipse.epp.internal.mpc.core.model.Category) ICategory(org.eclipse.epp.mpc.core.model.ICategory) CoreException(org.eclipse.core.runtime.CoreException) ICategory(org.eclipse.epp.mpc.core.model.ICategory) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) List(java.util.List) IFavoriteList(org.eclipse.epp.mpc.core.model.IFavoriteList) ArrayList(java.util.ArrayList) Market(org.eclipse.epp.internal.mpc.core.model.Market) IMarket(org.eclipse.epp.mpc.core.model.IMarket)

Aggregations

Category (org.eclipse.epp.internal.mpc.core.model.Category)4 ICategory (org.eclipse.epp.mpc.core.model.ICategory)3 CoreException (org.eclipse.core.runtime.CoreException)2 Market (org.eclipse.epp.internal.mpc.core.model.Market)2 Marketplace (org.eclipse.epp.internal.mpc.core.model.Marketplace)2 IMarket (org.eclipse.epp.mpc.core.model.IMarket)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 Node (org.eclipse.epp.internal.mpc.core.model.Node)1 Search (org.eclipse.epp.internal.mpc.core.model.Search)1 SearchResult (org.eclipse.epp.internal.mpc.core.model.SearchResult)1 DefaultMarketplaceService (org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService)1 IFavoriteList (org.eclipse.epp.mpc.core.model.IFavoriteList)1 INode (org.eclipse.epp.mpc.core.model.INode)1 ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)1 Test (org.junit.Test)1