Search in sources :

Example 16 with Marketplace

use of org.eclipse.epp.internal.mpc.core.model.Marketplace 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 17 with Marketplace

use of org.eclipse.epp.internal.mpc.core.model.Marketplace 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)

Example 18 with Marketplace

use of org.eclipse.epp.internal.mpc.core.model.Marketplace in project epp.mpc by eclipse.

the class NodeListingContentHandler method endElement.

@Override
public boolean endElement(String uri, String localName) throws SAXException {
    if (localName.equals(getRootElementName())) {
        if (parentModel instanceof Marketplace) {
            Marketplace marketplace = (Marketplace) parentModel;
            setMarketplaceResult(marketplace, model);
        }
        getUnmarshaller().setModel(model);
        model = null;
        getUnmarshaller().setCurrentHandler(parentHandler);
        if (parentHandler != null) {
            parentHandler.endElement(uri, localName);
        }
        return true;
    } else if (localName.equals("node")) {
    // $NON-NLS-1$
    // nothing to do
    }
    return false;
}
Also used : Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace)

Aggregations

Marketplace (org.eclipse.epp.internal.mpc.core.model.Marketplace)18 INode (org.eclipse.epp.mpc.core.model.INode)11 ICategory (org.eclipse.epp.mpc.core.model.ICategory)9 Test (org.junit.Test)9 CoreException (org.eclipse.core.runtime.CoreException)4 ICategories (org.eclipse.epp.mpc.core.model.ICategories)4 Node (org.eclipse.epp.internal.mpc.core.model.Node)3 Category (org.eclipse.epp.internal.mpc.core.model.Category)2 Search (org.eclipse.epp.internal.mpc.core.model.Search)2 IMarket (org.eclipse.epp.mpc.core.model.IMarket)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 Favorites (org.eclipse.epp.internal.mpc.core.model.Favorites)1 Featured (org.eclipse.epp.internal.mpc.core.model.Featured)1 Market (org.eclipse.epp.internal.mpc.core.model.Market)1 News (org.eclipse.epp.internal.mpc.core.model.News)1