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);
}
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);
}
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));
});
}
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);
}
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);
}
Aggregations