use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class ArticleController method getReferences.
/**
* Get a list of references.
* References to PLOS articles are supplemented with the absolute link to the journal site.
*
* @param site
* @param request
* @param xml
* @return
* @throws IOException
*/
private List<Reference> getReferences(Site site, HttpServletRequest request, byte[] xml) throws IOException {
final Document document = parseXmlService.getDocument(new ByteArrayInputStream(xml));
// do not supply Solr related link service now
List<Reference> references = parseXmlService.parseArticleReferences(document, null);
// invoke the Solr API once to resolve all journal keys
List<String> plosDois = references.stream().map(ref -> ref.getDoi()).filter(doi -> inPlosJournal(doi)).collect(Collectors.toList());
List<String> plosJournalKeys = doiToJournalResolutionService.getJournalKeysFromDois(plosDois, site);
// store the link text from journal key to references.
// since Reference is immutable, need to create a new list of new reference objects.
Iterator<Reference> refs = references.iterator();
Iterator<String> journalKeys = plosJournalKeys.iterator();
List<Reference> processedReferences = new ArrayList<Reference>();
while (refs.hasNext()) {
Reference ref = refs.next();
if (!inPlosJournal(ref.getDoi())) {
processedReferences.add(ref);
continue;
}
String key = journalKeys.next();
if (Strings.isNullOrEmpty(key)) {
processedReferences.add(ref);
continue;
}
Reference.Builder builder = new Reference.Builder(ref);
Reference refWithLink = builder.setFullArticleLink(getFullArticleLink(site, request, ref.getDoi(), key)).build();
processedReferences.add(refWithLink);
}
references = processedReferences;
return references;
}
use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class WombatControllerTestConfig method siteSetDependency.
@Bean
public SiteSet siteSetDependency() {
Site mockSite = mock(Site.class);
ImmutableSet<Site> sitesSet = new ImmutableSet.Builder<Site>().add(mockSite).build();
when(mockSite.getJournalKey()).thenReturn("daJournalKey");
SiteRequestScheme mockRequestScheme = mock(SiteRequestScheme.class);
when(mockRequestScheme.isForSite(any(HttpServletRequest.class))).thenReturn(true);
when(mockSite.getRequestScheme()).thenReturn(mockRequestScheme);
when(mockSite.toString()).thenReturn(MOCK_SITE_URL);
SiteSet mockSet = mock(SiteSet.class);
when(mockSet.getSites()).thenReturn(sitesSet);
return mockSet;
}
use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class SolrSearchApiTest method testAddArticleLinks.
@Test
public void testAddArticleLinks() throws IOException {
SolrSearchApi solrSearchApiForTest = new SearchApiForAddArticleLinksTest();
Map<String, List<Map>> searchResults = new HashMap<>();
List<Map> docs = new ArrayList<>(1);
Map doc = new HashMap();
List<String> crossPubbedJournals = new ArrayList<>(1);
crossPubbedJournals.add("journal1Key");
doc.put("id", "12345");
doc.put("eissn", "123");
docs.add(doc);
searchResults.put("docs", docs);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("someContextPath");
Site site = MockSiteUtil.getByUniqueJournalKey(siteSet, "journal2Key");
Map<?, ?> actual = solrSearchApiForTest.addArticleLinks(searchResults, request, site, siteSet);
List<Map> actualDocs = (List) actual.get("docs");
assertEquals(actualDocs.size(), 1);
Map actualDoc = (Map) actualDocs.get(0);
assertEquals(actualDoc.get("id"), "12345");
assertTrue(actualDoc.get("link").toString().endsWith("someContextPath/site1/article?id=12345"));
}
use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class SolrSearchApiImpl method initializeEIssnToJournalKeyMap.
/**
* Initializes the eIssnToJournalKey map if necessary by calling rhino to get eISSNs for all journals.
*
* @param siteSet set of all sites
* @param currentSite site associated with the current request
* @throws IOException
*/
@VisibleForTesting
protected synchronized void initializeEIssnToJournalKeyMap(SiteSet siteSet, Site currentSite) throws IOException {
if (eIssnToJournalKey == null) {
Map<String, String> mutable = new HashMap<>();
for (Site site : siteSet.getSites()) {
Map<String, String> rhinoResult = (Map<String, String>) articleApi.requestObject(ApiAddress.builder("journals").addToken(site.getJournalKey()).build(), Map.class);
mutable.put(rhinoResult.get("eIssn"), site.getJournalKey());
}
eIssnToJournalKey = ImmutableMap.copyOf(mutable);
}
}
use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class SpringSecurityConfiguration method validateHostname.
private void validateHostname(HttpServletRequest request) {
ClientEndpoint clientEndpoint = ClientEndpoint.get(request);
Set<String> hostNames = siteSet.getSites().stream().map((Site site) -> site.getRequestScheme().getHostName()).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toSet());
if (!hostNames.isEmpty() && !hostNames.contains(clientEndpoint.getHostname())) {
throw new AccessDeniedException(String.format("Attempt to validate against foreign hostname %s. " + "Possible hijack attempt.", clientEndpoint.getHostname()));
}
}
Aggregations