use of org.ambraproject.wombat.service.remote.ApiAddress in project wombat by PLOS.
the class ArticleController method receiveCommentFlag.
@RequestMapping(name = "postCommentFlag", method = RequestMethod.POST, value = "/article/comments/flag")
@ResponseBody
public Object receiveCommentFlag(HttpServletRequest request, @RequestParam("reasonCode") String reasonCode, @RequestParam("comment") String flagCommentBody, @RequestParam("target") String targetCommentDoi) throws IOException {
checkCommentsAreEnabled();
Map<String, Object> validationErrors = commentValidationService.validateFlag(flagCommentBody);
if (!validationErrors.isEmpty()) {
return ImmutableMap.of("validationErrors", validationErrors);
}
String authId = request.getRemoteUser();
final String creatorUserId = authId == null ? null : userApi.getUserIdFromAuthId(authId);
ArticleCommentFlag flag = new ArticleCommentFlag(creatorUserId, flagCommentBody, reasonCode);
Map<String, Object> comment = getComment(targetCommentDoi);
String parentArticleDoi = getParentArticleDoiFromComment(comment);
ApiAddress address = ApiAddress.builder("articles").embedDoi(parentArticleDoi).addToken("comments").embedDoi(targetCommentDoi).addToken("flags").build();
articleApi.postObject(address, flag);
// the "201 CREATED" status is all the AJAX client needs
return ImmutableMap.of();
}
use of org.ambraproject.wombat.service.remote.ApiAddress in project wombat by PLOS.
the class CommentServiceImpl method getRecentJournalComments.
@Override
public List<Map<String, Object>> getRecentJournalComments(String journalKey, int count) throws IOException {
Preconditions.checkArgument(count >= 0);
ApiAddress requestAddress = ApiAddress.builder("comments").addParameter("journal", journalKey).addParameter("limit", count).build();
List<Map<String, Object>> comments = articleApi.requestObject(requestAddress, List.class);
comments.forEach(comment -> modifyCommentTree(comment, CommentFormatting::addFormattingFields));
addArticleTitle(comments);
addCreatorData(comments);
return comments;
}
use of org.ambraproject.wombat.service.remote.ApiAddress in project wombat by PLOS.
the class CommentServiceImpl method getComment.
@Override
public Map<String, Object> getComment(String commentDoi, Site site) throws IOException {
Map<String, Object> comment;
try {
final ApiAddress commentUrl = ApiAddress.builder("comments").embedDoi(commentDoi).build();
comment = articleApi.requestObject(commentUrl, Map.class);
} catch (EntityNotFoundException enfe) {
throw new CommentNotFoundException(commentDoi, enfe);
}
modifyCommentTree(comment, CommentFormatting::addFormattingFields);
if (site.getType() == null || !site.getType().equals("preprints")) {
addCreatorData(ImmutableList.of(comment));
}
return comment;
}
use of org.ambraproject.wombat.service.remote.ApiAddress in project wombat by PLOS.
the class CommentControllerTest method setup.
@Before
public void setup() throws IOException {
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());
expectedRequestedDoi = RequestedDoiVersion.of(EXPECTED_DOI);
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.of());
when(articleApi.requestObject(any(), eq(Map.class))).thenReturn(ingestionMetadata);
}
use of org.ambraproject.wombat.service.remote.ApiAddress in project wombat by PLOS.
the class ArticleMetadataTest method testFetchRelatedArticles.
@Test
public void testFetchRelatedArticles() throws Exception {
String doi = "10.9999/journal.xxxx.0";
List<RelatedArticle> map = new Gson().fromJson(read("articleMeta/ppat.1005446.related.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("10.1371/journal.ppat.1006021", ra.getDoi());
assertEquals(null, ra.getType().getSpecificUse());
}
Aggregations