Search in sources :

Example 6 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class ArticleCrudController method writeRevision.

@Transactional(readOnly = false)
@RequestMapping(value = "/articles/{doi}/revisions", method = RequestMethod.POST)
public ResponseEntity<?> writeRevision(@PathVariable("doi") String doi, @RequestParam(value = "revision", required = false) Integer revisionNumber, @RequestParam(value = "ingestion", required = true) Integer ingestionNumber) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(doi));
    ArticleIngestionIdentifier ingestionId = ArticleIngestionIdentifier.create(articleId, ingestionNumber);
    final ArticleRevision revision;
    if (revisionNumber == null) {
        revision = articleRevisionWriteService.createRevision(ingestionId);
    } else {
        ArticleRevisionIdentifier revisionId = ArticleRevisionIdentifier.create(articleId, revisionNumber);
        revision = articleRevisionWriteService.writeRevision(revisionId, ingestionId);
    }
    return ServiceResponse.reportCreated(ArticleRevisionView.getView(revision)).asJsonResponse(entityGson);
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) ArticleIngestionIdentifier(org.ambraproject.rhino.identity.ArticleIngestionIdentifier) ArticleRevisionIdentifier(org.ambraproject.rhino.identity.ArticleRevisionIdentifier) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class ArticleCrudController method getCommentCount.

// TODO: Get rid of this?
@Transactional(readOnly = true)
@RequestMapping(value = "/articles/{doi:.+}/comments", method = RequestMethod.GET, params = "count")
public ResponseEntity<?> getCommentCount(@PathVariable("doi") String doi) throws IOException {
    ArticleIdentifier id = ArticleIdentifier.create(DoiEscaping.unescape(doi));
    Article article = articleCrudService.readArticle(id);
    return commentCrudService.getCommentCount(article).asJsonResponse(entityGson);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Article(org.ambraproject.rhino.model.Article) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class ArticleCrudServiceImpl method getItemOverview.

@Override
public Optional<ResolvedDoiView> getItemOverview(Doi doi) {
    return hibernateTemplate.execute(session -> {
        Query ingestionQuery = session.createQuery("FROM ArticleItem WHERE doi = :doi");
        ingestionQuery.setParameter("doi", doi.getName());
        List<ArticleItem> items = ingestionQuery.list();
        if (items.isEmpty())
            return Optional.empty();
        ResolvedDoiView.DoiWorkType type = items.stream().allMatch(ArticleCrudServiceImpl::isMainArticleItem) ? ResolvedDoiView.DoiWorkType.ARTICLE : ResolvedDoiView.DoiWorkType.ASSET;
        ArticleIdentifier articleId = Iterables.getOnlyElement(items.stream().map(item -> ArticleIdentifier.create(item.getIngestion().getArticle().getDoi())).collect(Collectors.toSet()));
        Query revisionQuery = session.createQuery("" + "FROM ArticleRevision WHERE ingestion IN " + "  (SELECT ingestion FROM ArticleItem WHERE doi = :doi)");
        revisionQuery.setParameter("doi", doi.getName());
        List<ArticleRevision> revisions = revisionQuery.list();
        Collection<ArticleIngestion> ingestions = Collections2.transform(items, ArticleItem::getIngestion);
        ArticleOverview articleOverview = ArticleOverview.build(articleId, ingestions, revisions);
        return Optional.of(ResolvedDoiView.createForArticle(doi, type, articleOverview));
    });
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ResolvedDoiView(org.ambraproject.rhino.view.ResolvedDoiView) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Query(org.hibernate.Query) ArticleOverview(org.ambraproject.rhino.view.article.ArticleOverview)

Example 9 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class CommentCrudController method create.

@RequestMapping(value = "/articles/{articleDoi}/comments", method = RequestMethod.POST)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "CommentInputView", value = "example: {\"creatorUserId\": 10365, " + "\"parentCommentId\": \"10.1371/annotation/0043aae2-f69d-4a05-ab19-4709704eb749\", " + "\"title\": \"no, really watch this\", " + "\"body\": \"http://www.youtube.com/watch?v=iGQdwSAAz9I\", " + "\"highlightedText\": \"whoah...\", " + "\"competingInterestStatement\": \"I'm going for an Emmy\"}")
public ResponseEntity<?> create(HttpServletRequest request, @PathVariable("articleDoi") String articleDoi) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentInputView input = readJsonFromRequest(request, CommentInputView.class);
    // TODO: Pass Optional.empty() if client POSTed to "/comments"?
    Optional<ArticleIdentifier> articleIdObj = Optional.of(articleId);
    return commentCrudService.createComment(articleIdObj, input).asJsonResponse(entityGson);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentInputView(org.ambraproject.rhino.view.comment.CommentInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class CommentCrudController method read.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi:.+}", method = RequestMethod.GET)
public ResponseEntity<?> read(@PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
    return commentCrudService.serveComment(commentId).asJsonResponse(entityGson);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 CommentIdentifier (org.ambraproject.rhino.identity.CommentIdentifier)9 Article (org.ambraproject.rhino.model.Article)7 RestClientException (org.ambraproject.rhino.rest.RestClientException)5 Transactional (org.springframework.transaction.annotation.Transactional)5 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)4 Query (org.hibernate.Query)4 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)3 ResponseEntity (org.springframework.http.ResponseEntity)3 Preconditions (com.google.common.base.Preconditions)2 ImmutableList (com.google.common.collect.ImmutableList)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2