use of org.ambraproject.wombat.config.site.url.Link in project wombat by PLOS.
the class BrowseController method validateIssueSite.
/**
* Validate that an issue belongs to the current site. If not, throw an exception
* indicating that the user should be redirected to the appropriate site
*/
private void validateIssueSite(Site site, Map<String, ?> issueMetadata) throws IOException {
String issueId = (String) issueMetadata.get("doi");
Map<String, String> parentVolumeMetadata = (Map<String, String>) issueMetadata.get("parentVolume");
String publishedJournalKey = parentVolumeMetadata.get("journalKey");
String siteJournalKey = site.getJournalKey();
if (!publishedJournalKey.equals(siteJournalKey)) {
Link link = buildCrossSiteRedirectToIssue(publishedJournalKey, site, issueId);
throw new InternalRedirectException(link);
}
}
use of org.ambraproject.wombat.config.site.url.Link in project wombat by PLOS.
the class GeneralDoiController method getRedirectFor.
private Link getRedirectFor(Site site, RequestedDoiVersion id) throws IOException {
DoiTypeInfo typeInfo = getTypeOf(id);
RedirectFunction redirectFunction = redirectHandlers.get(typeInfo.typeKey);
if (redirectFunction == null) {
throw new RuntimeException(String.format("Unrecognized type (%s) for: %s", typeInfo.typeKey, id));
}
Site targetSite = site.getTheme().resolveForeignJournalKey(siteSet, typeInfo.journalKey);
Link.Factory factory = Link.toAbsoluteAddress(targetSite);
return redirectFunction.getLink(factory, id);
}
use of org.ambraproject.wombat.config.site.url.Link in project wombat by PLOS.
the class TopLevelLockssManifestService method printPage.
/**
* @param request the HTTP request whose response we are building
* @param writer the buffer into which to print the response
*/
private void printPage(HttpServletRequest request, PrintWriter writer) {
for (String line : PREAMBLE) {
writer.println(line);
}
for (Site site : getSitesByDistinctJournalKey()) {
String journalName = site.getJournalName();
Link.Factory.PatternBuilder pattern = Link.toAbsoluteAddress(site).toPattern(requestMappingContextDictionary, "lockssYears");
Link manifestLink;
try {
manifestLink = pattern.build();
} catch (Link.PatternNotFoundException e) {
// omit link for this site
continue;
}
String manifestUrl = manifestLink.get(request);
writer.println(String.format(" <li><a href=\"%s\">%s</a></li>", manifestUrl, journalName));
}
for (String line : POSTAMBLE) {
writer.println(line);
}
}
use of org.ambraproject.wombat.config.site.url.Link in project wombat by PLOS.
the class ArticleAssetController method serve.
private void serve(HttpServletRequest requestFromClient, HttpServletResponse responseToClient, AssetUrlStyle requestedStyle, Site site, RequestedDoiVersion id, String fileType, boolean isDownload) throws IOException {
AssetPointer asset = articleResolutionService.toParentIngestion(id);
Map<String, ?> itemMetadata = articleService.getItemMetadata(asset);
String itemType = (String) itemMetadata.get("itemType");
AssetUrlStyle itemStyle = AssetUrlStyle.findByItemType(itemType);
if (requestedStyle != itemStyle) {
Link redirectLink = itemStyle.buildRedirectLink(requestMappingContextDictionary, site, id, fileType, isDownload);
String location = redirectLink.get(requestFromClient);
log.warn(String.format("Redirecting %s request for %s to <%s>. Bad link?", requestedStyle, asset.asParameterMap(), location));
redirectTo(responseToClient, location);
return;
}
Map<String, ?> files = (Map<String, ?>) itemMetadata.get("files");
Map<String, ?> fileRepoKey = (Map<String, ?>) files.get(fileType);
if (fileRepoKey == null) {
fileRepoKey = handleUnmatchedFileType(id, itemType, fileType, files);
}
// TODO: Check visibility against site?
ContentKey contentKey = createKey(fileRepoKey);
try (CloseableHttpResponse responseFromApi = corpusContentApi.request(contentKey, ImmutableList.of())) {
forwardAssetResponse(responseFromApi, responseToClient, isDownload);
}
}
use of org.ambraproject.wombat.config.site.url.Link in project wombat by PLOS.
the class ArticleMetadata method validateVisibility.
/**
* Validate that an article ought to be visible to the user. If not, throw an exception indicating that the user
* should see a 404.
* <p/>
* An article may be invisible if it is not in a published state, or if it has not been published in a journal
* corresponding to the site.
*
* @throws NotVisibleException if the article is not visible on the site
*/
public ArticleMetadata validateVisibility(String handlerName) {
Map<String, ?> journal = (Map<String, ?>) ingestionMetadata.get("journal");
String publishedJournalKey = (String) journal.get("journalKey");
String siteJournalKey = site.getJournalKey();
if (!publishedJournalKey.equals(siteJournalKey)) {
Link link = buildCrossSiteRedirect(publishedJournalKey, handlerName);
throw new InternalRedirectException(link);
}
return this;
}
Aggregations