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();
}
};
}
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;
}
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);
}
}
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";
}
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;
}
Aggregations