Search in sources :

Example 1 with Link

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);
    }
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Link(org.ambraproject.wombat.config.site.url.Link)

Example 2 with 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);
}
Also used : Site(org.ambraproject.wombat.config.site.Site) Link(org.ambraproject.wombat.config.site.url.Link)

Example 3 with Link

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);
    }
}
Also used : Site(org.ambraproject.wombat.config.site.Site) Link(org.ambraproject.wombat.config.site.url.Link)

Example 4 with Link

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);
    }
}
Also used : ContentKey(org.ambraproject.wombat.service.remote.ContentKey) AssetPointer(org.ambraproject.wombat.identity.AssetPointer) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Link(org.ambraproject.wombat.config.site.url.Link)

Example 5 with Link

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;
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Link(org.ambraproject.wombat.config.site.url.Link)

Aggregations

Link (org.ambraproject.wombat.config.site.url.Link)7 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 Site (org.ambraproject.wombat.config.site.Site)3 HashMap (java.util.HashMap)2 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 AssetPointer (org.ambraproject.wombat.identity.AssetPointer)1 ContentKey (org.ambraproject.wombat.service.remote.ContentKey)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1