Search in sources :

Example 1 with UnmatchedSiteException

use of org.ambraproject.wombat.service.UnmatchedSiteException in project wombat by PLOS.

the class CommonParams method buildActiveFilterItems.

/**
 * Creates an instance of {SearchFilterItem} for active filters using url parameters
 *
 * @param activeFilterItems set of active filter items
 * @param parameterMap      request's query parameter
 * @param filterName        name of the filter
 * @param filterValues      values of the filter
 */
private void buildActiveFilterItems(Set<SearchFilterItem> activeFilterItems, Map<String, String[]> parameterMap, String filterName, String[] filterValues) {
    for (String filterValue : filterValues) {
        List<String> filterValueList = new ArrayList<>(Arrays.asList(filterValues));
        // include the rest of filter values for that specific filter
        if (filterValueList.size() > 1) {
            filterValueList.remove(filterValue);
        }
        String displayName;
        try {
            if (filterName.equals("filterJournals")) {
                displayName = siteSet.getJournalNameFromKey(filterValue);
            } else {
                displayName = filterValue;
            }
            SearchFilterItem filterItem = SearchFilterItem.builder().setDisplayName(displayName).setNumberOfHits(0).setFilterParamName(filterName).setFilterValue(filterValue).build();
            activeFilterItems.add(filterItem);
        } catch (UnmatchedSiteException umse) {
            log.info("Search on an invalid journal filter: %s".format(filterValue));
        }
    }
}
Also used : UnmatchedSiteException(org.ambraproject.wombat.service.UnmatchedSiteException) SearchFilterItem(org.ambraproject.wombat.model.SearchFilterItem) ArrayList(java.util.ArrayList)

Example 2 with UnmatchedSiteException

use of org.ambraproject.wombat.service.UnmatchedSiteException in project wombat by PLOS.

the class Theme method resolveForeignJournalKey.

/**
 * Resolve a journal key for another site into that site. Uses theme-specific config hooks to define links between
 * sites (for example, mobile themes link to mobile sites) before defaulting to searching the site set for a site with
 * that journal key.
 *
 * @param siteSet    the system's set of all sites
 * @param journalKey a journal key belonging to another site
 * @return a site for the journal key, using preferences defined for this theme if any
 */
public Site resolveForeignJournalKey(SiteSet siteSet, String journalKey) throws UnmatchedSiteException {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(journalKey));
    Map<?, ?> otherJournals = (Map<?, ?>) getConfigMap("journal").get("otherJournals");
    if (otherJournals != null) {
        String otherSiteKey = (String) otherJournals.get(journalKey);
        if (otherSiteKey != null) {
            return siteSet.getSite(otherSiteKey);
        }
    // else, fall through and try the other way
    }
    // No site name was explicitly given for the journal key, so just search siteSet for it.
    for (Site candidateSite : siteSet.getSites()) {
        if (candidateSite.getJournalKey().equals(journalKey)) {
            return candidateSite;
        }
    }
    throw new UnmatchedSiteException("Journal key not matched to site: " + journalKey);
}
Also used : Site(org.ambraproject.wombat.config.site.Site) UnmatchedSiteException(org.ambraproject.wombat.service.UnmatchedSiteException) Map(java.util.Map)

Aggregations

UnmatchedSiteException (org.ambraproject.wombat.service.UnmatchedSiteException)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Site (org.ambraproject.wombat.config.site.Site)1 SearchFilterItem (org.ambraproject.wombat.model.SearchFilterItem)1