use of org.ambraproject.wombat.identity.RequestedDoiVersion in project wombat by PLOS.
the class BrowseController method transformIssueImageMetadata.
private void transformIssueImageMetadata(Model model, Site site, String imageArticleDoi) throws IOException {
RequestedDoiVersion requestedDoiVersion = RequestedDoiVersion.of(imageArticleDoi);
ArticleMetadata imageArticleMetadata;
try {
imageArticleMetadata = articleMetadataFactory.get(site, requestedDoiVersion);
} catch (NotFoundException e) {
throw new RuntimeException("Issue's image article not found: " + requestedDoiVersion, e);
}
ArticlePointer issueImageArticleId = imageArticleMetadata.getArticlePointer();
String issueDesc = (String) imageArticleMetadata.getIngestionMetadata().get("description");
model.addAttribute("issueTitle", articleTransformService.transformImageDescription(site, issueImageArticleId, XmlUtil.extractElement(issueDesc, "title")));
model.addAttribute("issueDescription", articleTransformService.transformImageDescription(site, issueImageArticleId, XmlUtil.removeElement(issueDesc, "title")));
}
use of org.ambraproject.wombat.identity.RequestedDoiVersion in project wombat by PLOS.
the class ArticleControllerTest method testRenderArticleShouldSucceed.
/**
* Test successful rendering of an article.
*
* @throws URISyntaxException if an invalid URI
* @throws Exception if failed to render article
*/
@Test
public void testRenderArticleShouldSucceed() throws URISyntaxException, Exception {
when(articleMetadata.validateVisibility(anyString())).thenReturn(articleMetadata);
when(articleMetadata.populate(any(), any())).thenReturn(articleMetadata);
when(articleMetadata.fillAmendments(any())).thenReturn(articleMetadata);
doReturn(articleMetadata).when(articleMetadataFactory).newInstance(any(), any(), any(), any(), any(), any());
RequestedDoiVersion expectedRequestedDoi = RequestedDoiVersion.of(EXPECTED_DOI);
ArticlePointer expectedArticlePointer = new ArticlePointer(expectedRequestedDoi, EXPECTED_DOI, EXPECTED_INGESTION_NUMBER, expectedRequestedDoi.getRevisionNumber());
when(articleResolutionService.toIngestion(expectedRequestedDoi)).thenReturn(expectedArticlePointer);
Map<String, Object> itemResponse = ImmutableMap.of("items", ImmutableMap.of());
doAnswer(invocation -> {
return itemResponse;
}).when(articleService).getItemTable(expectedArticlePointer);
ImmutableMap<String, String> journal = ImmutableMap.of("journalKey", DESKTOP_PLOS_ONE);
ImmutableMap<String, Object> ingestionMetadata = ImmutableMap.of("journal", journal);
ApiAddress address = ApiAddress.builder("articles").embedDoi(EXPECTED_DOI).addToken("relationships").build();
when(articleApi.requestObject(address, ArticleMetadata.Factory.RELATED_ARTICLE_GSON_TYPE)).thenReturn(ImmutableList.<RelatedArticle>of());
when(articleApi.requestObject(any(), eq(Map.class))).thenReturn(ingestionMetadata);
when(articleMetadata.getArticlePointer()).thenReturn(expectedArticlePointer);
String expectedHtml = "<html><title>This is a title</title><body>This is the body</body></html>";
Reference reference = Reference.build().setTitle("Reference title").setPublisherName("Publisher Name").setAuthors(ImmutableList.of()).setCollabAuthors(ImmutableList.of()).build();
ImmutableList<Reference> expectedReferences = ImmutableList.of(reference);
ArticleController.HtmlWithReferences expectedHtmlWithReferences = new ArticleController.HtmlWithReferences(expectedHtml, expectedReferences);
when(corpusContentApi.readManuscript(any(), any(), any(), any())).thenReturn(expectedHtmlWithReferences);
String expectedViewName = NOSPACE_JOINER.join(DESKTOP_PLOS_ONE, "/ftl/article/article");
String requestUri = NOSPACE_JOINER.join("/article?id=", EXPECTED_DOI);
mockMvc.perform(get(new URI(requestUri))).andExpect(status().isOk()).andExpect(model().attribute("articleText", expectedHtml)).andExpect(model().attribute("references", expectedReferences)).andExpect(view().name(expectedViewName));
verify(articleResolutionService).toIngestion(expectedRequestedDoi);
verify(articleService).getItemTable(expectedArticlePointer);
verify(articleApi, times(1)).requestObject(any(), eq(Map.class));
verify(articleMetadata).getArticlePointer();
verify(corpusContentApi).readManuscript(any(), any(), any(), any());
}
use of org.ambraproject.wombat.identity.RequestedDoiVersion in project wombat by PLOS.
the class ArticleResolutionServiceTest method testToParentIngestionForIngestionNumber.
@Test
public void testToParentIngestionForIngestionNumber() throws IOException {
Map<String, Object> doiOverview = makeSampleDoiOverview();
when(articleApi.requestObject(any(), eq(Map.class))).thenReturn(doiOverview);
RequestedDoiVersion assetId = RequestedDoiVersion.ofIngestion("info:doi/10.1371/journal.pcbi.1002012.g002", 1);
AssetPointer assetPointer = articleResolutionService.toParentIngestion(assetId);
assertEquals("10.1371/journal.pcbi.1002012.g002", assetPointer.getAssetDoi());
assertEquals("10.1371/journal.pcbi.1002012", assetPointer.getParentArticle().getDoi());
assertEquals(1, assetPointer.getParentArticle().getIngestionNumber());
assertEquals(OptionalInt.empty(), assetPointer.getParentArticle().getRevisionNumber());
}
use of org.ambraproject.wombat.identity.RequestedDoiVersion in project wombat by PLOS.
the class ArticleResolutionServiceTest method testToParentIngestion.
@Test
public void testToParentIngestion() throws IOException {
Map<String, Object> doiOverview = makeSampleDoiOverview();
when(articleApi.requestObject(any(), eq(Map.class))).thenReturn(doiOverview);
RequestedDoiVersion assetId = RequestedDoiVersion.of("info:doi/10.1371/journal.pcbi.1002012.g002");
AssetPointer assetPointer = articleResolutionService.toParentIngestion(assetId);
assertEquals("10.1371/journal.pcbi.1002012.g002", assetPointer.getAssetDoi());
assertEquals("10.1371/journal.pcbi.1002012", assetPointer.getParentArticle().getDoi());
assertEquals(1, assetPointer.getParentArticle().getIngestionNumber());
assertEquals(1, assetPointer.getParentArticle().getRevisionNumber().getAsInt());
}
use of org.ambraproject.wombat.identity.RequestedDoiVersion in project wombat by PLOS.
the class ArticleResolutionServiceTest method testToParentIngestionForRevisionNumber.
@Test
public void testToParentIngestionForRevisionNumber() throws IOException {
Map<String, Object> doiOverview = makeSampleDoiOverview();
when(articleApi.requestObject(any(), eq(Map.class))).thenReturn(doiOverview);
RequestedDoiVersion assetId = RequestedDoiVersion.ofRevision("info:doi/10.1371/journal.pcbi.1002012.g002", 1);
AssetPointer assetPointer = articleResolutionService.toParentIngestion(assetId);
assertEquals("10.1371/journal.pcbi.1002012.g002", assetPointer.getAssetDoi());
assertEquals("10.1371/journal.pcbi.1002012", assetPointer.getParentArticle().getDoi());
assertEquals(1, assetPointer.getParentArticle().getIngestionNumber());
assertEquals(1, assetPointer.getParentArticle().getRevisionNumber().getAsInt());
}
Aggregations