use of org.ambraproject.wombat.service.remote.ApiAddress in project wombat by PLOS.
the class CommentServiceImpl method getArticleComments.
@Override
public List<Map<String, Object>> getArticleComments(RequestedDoiVersion articleId, Site site) throws IOException {
final ApiAddress commentsUrl = ApiAddress.builder("articles").embedDoi(articleId.getDoi()).addToken("comments").build();
List<Map<String, Object>> comments = articleApi.requestObject(commentsUrl, List.class);
comments.forEach(comment -> modifyCommentTree(comment, CommentFormatting::addFormattingFields));
if (site.getType() == null || !site.getType().equals("preprints")) {
addCreatorData(comments);
}
return comments;
}
use of org.ambraproject.wombat.service.remote.ApiAddress in project wombat by PLOS.
the class ArticleServiceImpl method getItemTable.
@Override
public Map<String, ?> getItemTable(ArticlePointer articleId) throws IOException {
ApiAddress itemAddress = articleId.asApiAddress().addToken("items").build();
Map<String, ?> itemResponse = articleApi.requestObject(itemAddress, Map.class);
return (Map<String, ?>) itemResponse.get("items");
}
use of org.ambraproject.wombat.service.remote.ApiAddress in project wombat by PLOS.
the class ArticleMetadata method getAuthors.
private Map<String, Object> getAuthors(ArticlePointer ap) throws IOException {
Type tt = new TypeToken<Map<String, Object>>() {
}.getType();
ApiAddress authorAddress = ap.asApiAddress().addToken("authors").build();
return factory.articleApi.<Map<String, Object>>requestObject(authorAddress, tt);
}
use of org.ambraproject.wombat.service.remote.ApiAddress in project wombat by PLOS.
the class CommentController 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 CommentController 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();
}
Aggregations