Search in sources :

Example 1 with UserApi

use of org.ambraproject.wombat.service.remote.UserApi in project wombat by PLOS.

the class ArticleController method renderArticleCommentTree.

/**
 * Serves a request for an expanded view of a single comment and any replies.
 *
 * @param model      data to pass to the view
 * @param site       current site
 * @param commentDoi specifies the comment
 * @return path to the template
 * @throws IOException
 */
@RequestMapping(name = "articleCommentTree", value = "/article/comment")
public String renderArticleCommentTree(HttpServletRequest request, Model model, @SiteParam Site site, @RequestParam("id") String commentDoi) throws IOException {
    requireNonemptyParameter(commentDoi);
    Map<String, Object> comment;
    try {
        comment = commentService.getComment(commentDoi, site);
    } catch (CommentService.CommentNotFoundException e) {
        throw new NotFoundException(e);
    } catch (UserApi.UserApiException e) {
        log.error(e.getMessage(), e);
        model.addAttribute("userApiError", e);
        // Get a copy of the comment that is not populated with userApi data.
        // This articleApi call is redundant to one that commentService.getComment would have made before throwing.
        // TODO: Prevent extra articleApi call
        comment = getComment(commentDoi);
    }
    RequestedDoiVersion doi = RequestedDoiVersion.of(getParentArticleDoiFromComment(comment));
    articleMetadataFactory.get(site, doi).validateVisibility("articleCommentTree").populate(request, model);
    model.addAttribute("comment", comment);
    addCommentAvailability(model);
    return site + "/ftl/article/comment/comment";
}
Also used : CommentService(org.ambraproject.wombat.service.CommentService) RequestedDoiVersion(org.ambraproject.wombat.identity.RequestedDoiVersion) EntityNotFoundException(org.ambraproject.wombat.service.EntityNotFoundException) UserApi(org.ambraproject.wombat.service.remote.UserApi) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UserApi

use of org.ambraproject.wombat.service.remote.UserApi in project wombat by PLOS.

the class CommentController method renderArticleCommentTree.

/**
 * Serves a request for an expanded view of a single comment and any replies.
 *
 * @param model      data to pass to the view
 * @param site       current site
 * @param commentDoi specifies the comment
 * @return path to the template
 * @throws IOException
 */
@RequestMapping(name = "articleCommentTree", value = "/article/comment")
public String renderArticleCommentTree(HttpServletRequest request, Model model, @SiteParam Site site, @RequestParam("id") String commentDoi) throws IOException {
    requireNonemptyParameter(commentDoi);
    Map<String, Object> comment;
    try {
        comment = commentService.getComment(commentDoi, site);
    } catch (CommentService.CommentNotFoundException e) {
        throw new NotFoundException(e);
    } catch (UserApi.UserApiException e) {
        log.error(e.getMessage(), e);
        model.addAttribute("userApiError", e);
        // Get a copy of the comment that is not populated with userApi data.
        // This articleApi call is redundant to one that commentService.getComment would have made before throwing.
        // TODO: Prevent extra articleApi call
        comment = getComment(commentDoi);
    }
    RequestedDoiVersion doi = RequestedDoiVersion.of(getParentArticleDoiFromComment(comment));
    articleMetadataFactory.get(site, doi).validateVisibility("articleCommentTree").populate(request, model);
    model.addAttribute("comment", comment);
    addCommentAvailability(model);
    return site + "/ftl/article/comment/comment";
}
Also used : CommentService(org.ambraproject.wombat.service.CommentService) RequestedDoiVersion(org.ambraproject.wombat.identity.RequestedDoiVersion) UserApi(org.ambraproject.wombat.service.remote.UserApi) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RequestedDoiVersion (org.ambraproject.wombat.identity.RequestedDoiVersion)2 CommentService (org.ambraproject.wombat.service.CommentService)2 UserApi (org.ambraproject.wombat.service.remote.UserApi)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 EntityNotFoundException (org.ambraproject.wombat.service.EntityNotFoundException)1