Search in sources :

Example 1 with IIdentifiable

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

the class DefaultMarketplaceService method computeRelativeSearchUrl.

/**
 * Creates the query URL for the Marketplace REST API.
 * <p>
 * If the query string is non-empty, the format for the returned relative URL is
 * <code>search/apachesolr_search/[query]?filters=[filters]</code> where [query] is the URL encoded query string and
 * [filters] are the category and market IDs (category first for browser urls, market first for API urls). If both
 * market and category are null, the filters are omitted completely.
 * <p>
 * If the query is empty and either market or category are not null, the format for the relative URL is
 * <code>taxonomy/term/[filters]</code> where [filters] is the comma-separated list of category and market, in that
 * order.
 * <p>
 * If the query is empty and both category and market are null, the result is null
 *
 * @param market
 *            the market to search or null
 * @param category
 *            the category to search or null
 * @param queryText
 *            the search query
 * @param api
 *            true to create REST API url, false for browser url
 * @return the relative search url, e.g.
 *         <code>api/p/search/apachesolr_search/WikiText?filters=tid:38%20tid:31</code> or
 *         <code>taxonomy/term/38,31/api/p</code>
 */
public String computeRelativeSearchUrl(IMarket market, ICategory category, String queryText, boolean api) {
    String relativeUrl;
    if (queryText != null && queryText.trim().length() > 0) {
        relativeUrl = (api ? API_SEARCH_URI_FULL : API_SEARCH_URI) + urlEncode(queryText.trim());
        // $NON-NLS-1$
        String queryString = "";
        if (market != null || category != null) {
            // $NON-NLS-1$
            queryString += "filters=";
            IIdentifiable first = api ? market : category;
            IIdentifiable second = api ? category : market;
            if (first != null) {
                // $NON-NLS-1$
                queryString += "tid:" + urlEncode(first.getId());
                if (second != null) {
                    // $NON-NLS-1$
                    queryString += "%20";
                }
            }
            if (second != null) {
                // $NON-NLS-1$
                queryString += "tid:" + urlEncode(second.getId());
            }
        }
        if (queryString.length() > 0) {
            relativeUrl += '?' + queryString;
        }
    } else if (market != null || category != null) {
        // http://marketplace.eclipse.org/taxonomy/term/38,31
        relativeUrl = API_TAXONOMY_URI;
        if (category != null) {
            relativeUrl += urlEncode(category.getId());
            if (market != null) {
                relativeUrl += ',';
            }
        }
        if (market != null) {
            relativeUrl += urlEncode(market.getId());
        }
        if (api) {
            relativeUrl += '/' + API_URI_SUFFIX;
        }
    } else {
        relativeUrl = null;
    }
    return relativeUrl;
}
Also used : IIdentifiable(org.eclipse.epp.mpc.core.model.IIdentifiable)

Example 2 with IIdentifiable

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

the class MarketplaceViewer method setFilters.

private void setFilters(QueryData queryData) {
    // $NON-NLS-1$
    setFindText(queryData.queryText == null ? "" : queryData.queryText);
    for (CatalogFilter filter : getConfiguration().getFilters()) {
        if (filter instanceof AbstractTagFilter) {
            AbstractTagFilter tagFilter = (AbstractTagFilter) filter;
            if (tagFilter.getTagClassification() == ICategory.class) {
                List<Tag> choices = tagFilter.getChoices();
                Tag tag = choices.isEmpty() ? null : choices.get(0);
                if (tag != null) {
                    IIdentifiable data = null;
                    if (tag.getTagClassifier() == IMarket.class) {
                        data = queryData.queryMarket;
                    } else if (tag.getTagClassifier() == ICategory.class) {
                        data = queryData.queryCategory;
                    } else {
                        continue;
                    }
                    tag = null;
                    if (data != null) {
                        for (Tag choice : choices) {
                            final Object choiceData = choice.getData();
                            if (choiceData == data || matches(data, choiceData)) {
                                tag = choice;
                                break;
                            }
                        }
                    }
                    tagFilter.setSelected(tag == null ? Collections.<Tag>emptySet() : Collections.singleton(tag));
                    // we expect a query to happen next, so don't fire a property change resulting in an additional query
                    tagFilter.updateUi();
                }
            }
        }
    }
    initQueryFromFilters();
}
Also used : CatalogFilter(org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter) ICategory(org.eclipse.epp.mpc.core.model.ICategory) IIdentifiable(org.eclipse.epp.mpc.core.model.IIdentifiable) Tag(org.eclipse.equinox.internal.p2.discovery.model.Tag)

Aggregations

IIdentifiable (org.eclipse.epp.mpc.core.model.IIdentifiable)2 ICategory (org.eclipse.epp.mpc.core.model.ICategory)1 Tag (org.eclipse.equinox.internal.p2.discovery.model.Tag)1 CatalogFilter (org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter)1