Search in sources :

Example 1 with ContentKey

use of org.ambraproject.wombat.service.remote.ContentKey in project wombat by PLOS.

the class PowerPointController method getImageFile.

private ByteSource getImageFile(AssetPointer assetId) throws IOException {
    Map<String, ?> files = articleService.getItemFiles(assetId);
    Map<String, ?> file = (Map<String, ?>) files.get(IMAGE_SIZE);
    ContentKey key = ContentKey.createForUuid((String) file.get("crepoKey"), UUID.fromString((String) file.get("crepoUuid")));
    return new ByteSource() {

        @Override
        public InputStream openStream() throws IOException {
            return corpusContentApi.request(key, ImmutableList.of()).getEntity().getContent();
        }
    };
}
Also used : ContentKey(org.ambraproject.wombat.service.remote.ContentKey) ByteSource(com.google.common.io.ByteSource) Map(java.util.Map)

Example 2 with ContentKey

use of org.ambraproject.wombat.service.remote.ContentKey in project wombat by PLOS.

the class ArticleAssetController method createKey.

private static ContentKey createKey(Map<String, ?> fileRepoKey) {
    String key = (String) fileRepoKey.get("crepoKey");
    UUID uuid = UUID.fromString((String) fileRepoKey.get("crepoUuid"));
    ContentKey contentKey = ContentKey.createForUuid(key, uuid);
    if (fileRepoKey.get("bucketName") != null) {
        contentKey.setBucketName(fileRepoKey.get("bucketName").toString());
    }
    return contentKey;
}
Also used : ContentKey(org.ambraproject.wombat.service.remote.ContentKey) UUID(java.util.UUID)

Example 3 with ContentKey

use of org.ambraproject.wombat.service.remote.ContentKey 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 4 with ContentKey

use of org.ambraproject.wombat.service.remote.ContentKey in project wombat by PLOS.

the class SiteContentController method renderSiteContent.

@RequestMapping(name = "siteContent", value = "/s/{pageName}")
public String renderSiteContent(Model model, @SiteParam Site site, @PathVariable String pageName) throws IOException {
    Theme theme = site.getTheme();
    Map<String, Object> pageConfig = theme.getConfigMap("siteContent");
    String repoKeyPrefix = (String) pageConfig.get("contentRepoKeyPrefix");
    if (repoKeyPrefix == null) {
        throw new RuntimeConfigurationException("Content repo prefix not configured for theme " + theme.toString());
    }
    String repoKey = repoKeyPrefix + "." + pageName;
    CacheKey cacheKey = CacheKey.create("siteContent_meta", repoKey);
    // versioning is not supported for site content
    ContentKey version = ContentKey.createForLatestVersion(repoKey);
    try {
        // Check for validity of the content repo key prior to rendering page. Return a 404 if no object found.
        editorialContentApi.requestMetadata(cacheKey, version);
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    }
    model.addAttribute("siteContentRepoKey", repoKey);
    return site + "/ftl/siteContent/container";
}
Also used : ContentKey(org.ambraproject.wombat.service.remote.ContentKey) RuntimeConfigurationException(org.ambraproject.wombat.config.RuntimeConfigurationException) Theme(org.ambraproject.wombat.config.theme.Theme) EntityNotFoundException(org.ambraproject.wombat.service.EntityNotFoundException) EntityNotFoundException(org.ambraproject.wombat.service.EntityNotFoundException) CacheKey(org.ambraproject.wombat.util.CacheKey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ContentKey

use of org.ambraproject.wombat.service.remote.ContentKey in project wombat by PLOS.

the class ArticleServiceImpl method getManuscriptKey.

@Override
public ContentKey getManuscriptKey(ArticlePointer articleId) throws IOException {
    Map<String, ?> itemTable = getItemTable(articleId);
    Map<String, ?> articleItem = (Map<String, ?>) itemTable.values().stream().filter(itemObj -> ((Map<String, ?>) itemObj).get("itemType").equals("article")).collect(MoreCollectors.onlyElement());
    Map<String, ?> articleFiles = (Map<String, ?>) articleItem.get("files");
    Map<String, ?> manuscriptPointer = (Map<String, ?>) articleFiles.get("manuscript");
    String crepoKey = (String) manuscriptPointer.get("crepoKey");
    UUID crepoUuid = UUID.fromString((String) manuscriptPointer.get("crepoUuid"));
    ContentKey key = ContentKey.createForUuid(crepoKey, crepoUuid);
    String bucketName = (String) manuscriptPointer.get("bucketName");
    key.setBucketName(bucketName);
    return key;
}
Also used : ContentKey(org.ambraproject.wombat.service.remote.ContentKey) UUID(java.util.UUID) Map(java.util.Map)

Aggregations

ContentKey (org.ambraproject.wombat.service.remote.ContentKey)5 Map (java.util.Map)3 UUID (java.util.UUID)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ByteSource (com.google.common.io.ByteSource)1 RuntimeConfigurationException (org.ambraproject.wombat.config.RuntimeConfigurationException)1 Link (org.ambraproject.wombat.config.site.url.Link)1 Theme (org.ambraproject.wombat.config.theme.Theme)1 AssetPointer (org.ambraproject.wombat.identity.AssetPointer)1 EntityNotFoundException (org.ambraproject.wombat.service.EntityNotFoundException)1 CacheKey (org.ambraproject.wombat.util.CacheKey)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1