Search in sources :

Example 1 with SearchFilterItem

use of org.ambraproject.wombat.model.SearchFilterItem 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)

Aggregations

ArrayList (java.util.ArrayList)1 SearchFilterItem (org.ambraproject.wombat.model.SearchFilterItem)1 UnmatchedSiteException (org.ambraproject.wombat.service.UnmatchedSiteException)1