use of org.ambraproject.wombat.service.remote.ApiAddress in project wombat by PLOS.
the class ArticleResolutionService method toParentIngestion.
public AssetPointer toParentIngestion(RequestedDoiVersion assetId) throws IOException {
Map<String, ?> doiOverview;
try {
ApiAddress apiAddress = ApiAddress.builder("dois").embedDoi(assetId.getDoi()).build();
doiOverview = articleApi.requestObject(apiAddress, Map.class);
} catch (EntityNotFoundException e) {
throw new NotFoundException(e);
}
String type = (String) doiOverview.get("type");
if (!ARTICLE_ASSET_TYPES.contains(type)) {
throw new NotFoundException("Not an article asset: " + assetId);
}
Map<String, ?> parentArticle = (Map<String, ?>) doiOverview.get("article");
ArticlePointer parentArticlePtr = resolve(assetId, parentArticle);
String canonicalAssetDoi = (String) doiOverview.get("doi");
return new AssetPointer(canonicalAssetDoi, parentArticlePtr);
}
use of org.ambraproject.wombat.service.remote.ApiAddress in project wombat by PLOS.
the class AlertService method removeSubjectAlert.
/**
* Remove the subject alert for the loggedin user for the journal.
* After removing the subject, if other subjects exist in the alert object for the journal,
* then it uses PUT individuals/{userId}/alerts/{alertId} to modify the alert object,
* otherwise it uses DELETE individuals/{userId}/alerts/{alertId} to remove the
* alert object.
*
* @param authId The authentication ID of the logged in user.
* @param journalKey The journal key.
* @param subjectName The subject to remove alert for.
* @throws IOException
*/
public void removeSubjectAlert(String authId, String journalKey, String subjectName) throws IOException {
String userId = userApi.getUserIdFromAuthId(authId);
List<Alert> alerts = fetchAlerts(userId);
Alert alert = findMatchingAlert(alerts, journalKey).orElseThrow(() -> new AlertException("no subject alert found"));
RemoveResult result = removeSubjectFromAlert(alert, subjectName);
if (result == RemoveResult.NOT_FOUND) {
throw new AlertException("matching subject alert not found");
}
String alertId = alert.getId().toString();
ApiAddress address = buildAlertAddress(userId).addToken(alertId).build();
if (result == RemoveResult.EMPTY_AFTER_REMOVE) {
userApi.deleteObject(address);
} else {
userApi.putObject(address, alert);
}
}
use of org.ambraproject.wombat.service.remote.ApiAddress in project wombat by PLOS.
the class ArticleController method receiveNewComment.
/**
* @param parentArticleDoi null if a reply to another comment
* @param parentCommentUri null if a direct reply to an article
*/
@RequestMapping(name = "postComment", method = RequestMethod.POST, value = "/article/comments/new")
@ResponseBody
public Object receiveNewComment(HttpServletRequest request, @SiteParam Site site, @RequestParam("commentTitle") String commentTitle, @RequestParam("comment") String commentBody, @RequestParam("isCompetingInterest") boolean hasCompetingInterest, @RequestParam(value = "authorEmailAddress", required = false) String authorEmailAddress, @RequestParam(value = "authorName", required = false) String authorName, @RequestParam(value = "authorPhone", required = false) String authorPhone, @RequestParam(value = "authorAffiliation", required = false) String authorAffiliation, @RequestParam(value = "ciStatement", required = false) String ciStatement, @RequestParam(value = "target", required = false) String parentArticleDoi, @RequestParam(value = "inReplyTo", required = false) String parentCommentUri) throws IOException {
if (honeypotService.checkHoneypot(request, authorPhone, authorAffiliation)) {
return ImmutableMap.of("status", "success");
}
checkCommentsAreEnabled();
Map<String, Object> validationErrors = commentValidationService.validateComment(site, commentTitle, commentBody, hasCompetingInterest, ciStatement);
if (!validationErrors.isEmpty()) {
return ImmutableMap.of("validationErrors", validationErrors);
}
if (parentArticleDoi == null) {
Map<String, Object> comment = getComment(parentCommentUri);
parentArticleDoi = getParentArticleDoiFromComment(comment);
}
ApiAddress address = ApiAddress.builder("articles").embedDoi(parentArticleDoi).addToken("comments").build();
String authId = request.getRemoteUser();
final String creatorUserId = authId == null ? null : userApi.getUserIdFromAuthId(authId);
ArticleComment comment = new ArticleComment(parentArticleDoi, creatorUserId, parentCommentUri, commentTitle, commentBody, ciStatement, authorEmailAddress, authorName);
HttpResponse response = articleApi.postObject(address, comment);
String responseJson = EntityUtils.toString(response.getEntity());
Map<String, Object> commentJson = gson.fromJson(responseJson, HashMap.class);
return ImmutableMap.of("createdCommentUri", commentJson.get("commentUri"));
}
use of org.ambraproject.wombat.service.remote.ApiAddress 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.service.remote.ApiAddress in project wombat by PLOS.
the class ArticleMetadataTest method testFetchRelatedArticlesWithSpecificUse.
@Test
public void testFetchRelatedArticlesWithSpecificUse() throws Exception {
String doi = "10.9999/journal.xxxx.0";
List<RelatedArticle> map = new Gson().fromJson(read("articleMeta/ppat.1005446.related2.json"), ArticleMetadata.Factory.RELATED_ARTICLE_GSON_TYPE);
ApiAddress address = ApiAddress.builder("articles").embedDoi(doi).addToken("relationships").build();
when(articleApi.requestObject(address, ArticleMetadata.Factory.RELATED_ARTICLE_GSON_TYPE)).thenReturn(map);
List<RelatedArticle> raList = articleMetadataFactory.fetchRelatedArticles(doi);
assertEquals(1, raList.size());
RelatedArticle ra = raList.get(0);
assertEquals("foo", ra.getType().getSpecificUse());
}
Aggregations