use of org.ambraproject.wombat.util.UrlParamBuilder in project wombat by PLOS.
the class AbstractContentApi method buildUri.
private URI buildUri(ContentKey key, RequestMode mode) throws IOException {
RepoConfig repoConfig = getRepoConfig();
UrlParamBuilder requestParams = UrlParamBuilder.params();
key.setParameters(requestParams);
String repoBucketName = key.getBucketName() != null ? key.getBucketName() : repoConfig.bucketName;
return URI.create(String.format("%s/%s/%s?%s", repoConfig.address, mode.getPathComponent(), repoBucketName, UriUtil.formatMangledParams(requestParams.build())));
}
use of org.ambraproject.wombat.util.UrlParamBuilder in project wombat by PLOS.
the class SolrSearchApiTest method testSetQueryFilters.
@Test
public void testSetQueryFilters() {
UrlParamBuilder actual = UrlParamBuilder.params();
List<String> articleTypes = new ArrayList<>();
List<String> subjects = new ArrayList<>();
// Multiple journals
setQueryFilters(actual, Arrays.asList("foo", "bar", "blaz"), articleTypes, subjects, ArticleSearchQuery.SolrEnumeratedDateRange.ALL_TIME);
SetMultimap<String, String> actualMap = convertToMap(actual.build());
assertJournals(actualMap.get("fq"), "foo", "bar", "blaz");
// date range
actual = UrlParamBuilder.params();
setQueryFilters(actual, ImmutableList.of("foo"), articleTypes, subjects, ArticleSearchQuery.SolrEnumeratedDateRange.LAST_3_MONTHS);
actualMap = convertToMap(actual.build());
assertEquals(2, actualMap.get("fq").size());
for (String s : actualMap.get("fq")) {
if (!s.contains("publication_date:") && !s.contains("journal_key:")) {
fail(s);
}
}
// null date range
actual = UrlParamBuilder.params();
setQueryFilters(UrlParamBuilder.params(), ImmutableList.of("foo"), articleTypes, subjects, null);
actualMap = convertToMap(actual.build());
Set<String> fq = actualMap.get("fq");
for (String s : fq) {
if (s.startsWith("publication_date:")) {
fail(s);
}
}
}
use of org.ambraproject.wombat.util.UrlParamBuilder in project wombat by PLOS.
the class SolrSearchApiTest method testSetQueryFilters_ExplicitDateRange.
@Test
public void testSetQueryFilters_ExplicitDateRange() throws IOException {
UrlParamBuilder actual = UrlParamBuilder.params();
ArticleSearchQuery.SolrExplicitDateRange edr = new ArticleSearchQuery.SolrExplicitDateRange("test", "2011-01-01", "2015-06-01");
setQueryFilters(actual, ImmutableList.of("foo"), new ArrayList<String>(), new ArrayList<String>(), edr);
SetMultimap<String, String> actualMap = convertToMap(actual.build());
assertPubDate(actualMap.get("fq"));
assertJournals(actualMap.get("fq"), "foo");
}
use of org.ambraproject.wombat.util.UrlParamBuilder in project wombat by PLOS.
the class SolrSearchApiTest method testSetQueryFilters_IncludeSubjects.
@Test
public void testSetQueryFilters_IncludeSubjects() throws IOException {
UrlParamBuilder actual = UrlParamBuilder.params();
ArticleSearchQuery.SolrExplicitDateRange edr = new ArticleSearchQuery.SolrExplicitDateRange("test", "2011-01-01", "2015-06-01");
ArrayList<String> articleTypes = new ArrayList<>();
articleTypes.add("Research Article");
setQueryFilters(actual, ImmutableList.of("foo"), articleTypes, Arrays.asList("Skull", "Head", "Teeth"), edr);
SetMultimap<String, String> actualMap = convertToMap(actual.build());
assertPubDate(actualMap.get("fq"));
assertJournals(actualMap.get("fq"), "foo");
assertArticleTypes(actualMap.get("fq"));
assertSubjects(actualMap.get("fq"), "\"Skull\"", "\"Head\"", "\"Teeth\"");
}
use of org.ambraproject.wombat.util.UrlParamBuilder in project wombat by PLOS.
the class SearchController method getSearchRssFeedView.
/**
* Performs a simple search and serves the result as XML to be read by an RSS reader
*
* @param request HttpServletRequest
* @param model model that will be passed to the template
* @param site site the request originates from
* @param params search parameters identical to the {@code search} method
* @return RSS view of articles returned by the search
* @throws IOException
*/
@RequestMapping(name = "searchFeed", value = "/search/feed/{feedType:atom|rss}", params = { "q" }, method = RequestMethod.GET)
public ModelAndView getSearchRssFeedView(HttpServletRequest request, Model model, @SiteParam Site site, @PathVariable String feedType, @RequestParam MultiValueMap<String, String> params) throws IOException {
CommonParams commonParams = modelCommonParams(request, model, site, params);
String queryString = params.getFirst("q");
ArticleSearchQuery query = commonParams.makeArticleSearchQueryBuilder().setQuery(queryString).setSimple(commonParams.isSimpleSearch(queryString)).setFields(ArticleSearchQuery.RSS_FIELDS).build();
SolrSearchApi.Result searchResults = solrSearchApi.search(query);
String feedTitle = new UrlParamBuilder().addAll(params).build().toString();
;
ModelAndView mav = new ModelAndView();
FeedMetadataField.SITE.putInto(mav, site);
FeedMetadataField.FEED_INPUT.putInto(mav, searchResults.getDocs());
FeedMetadataField.TITLE.putInto(mav, feedTitle);
mav.setView(FeedType.getView(articleFeedView, feedType));
return mav;
}
Aggregations