Search in sources :

Example 11 with ApiAddress

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;
}
Also used : ApiAddress(org.ambraproject.wombat.service.remote.ApiAddress) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Example 12 with ApiAddress

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");
}
Also used : ApiAddress(org.ambraproject.wombat.service.remote.ApiAddress) Map(java.util.Map)

Example 13 with ApiAddress

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);
}
Also used : RelatedArticleType(org.ambraproject.wombat.model.RelatedArticleType) Type(java.lang.reflect.Type) ArticleType(org.ambraproject.wombat.model.ArticleType) ApiAddress(org.ambraproject.wombat.service.remote.ApiAddress) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 14 with ApiAddress

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"));
}
Also used : ArticleComment(org.ambraproject.wombat.model.ArticleComment) HttpResponse(org.apache.http.HttpResponse) ApiAddress(org.ambraproject.wombat.service.remote.ApiAddress) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with ApiAddress

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();
}
Also used : ArticleCommentFlag(org.ambraproject.wombat.model.ArticleCommentFlag) ApiAddress(org.ambraproject.wombat.service.remote.ApiAddress) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ApiAddress (org.ambraproject.wombat.service.remote.ApiAddress)15 Map (java.util.Map)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ArticlePointer (org.ambraproject.wombat.identity.ArticlePointer)3 Test (org.junit.Test)3 Gson (com.google.gson.Gson)2 ArticleComment (org.ambraproject.wombat.model.ArticleComment)2 ArticleCommentFlag (org.ambraproject.wombat.model.ArticleCommentFlag)2 RelatedArticle (org.ambraproject.wombat.model.RelatedArticle)2 HttpResponse (org.apache.http.HttpResponse)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Type (java.lang.reflect.Type)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 NotFoundException (org.ambraproject.wombat.controller.NotFoundException)1