Search in sources :

Example 21 with ArticleIdentifier

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

the class CommentCrudController method delete.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi:.+}", method = RequestMethod.DELETE)
@ApiOperation(value = "delete", notes = "Performs a hard delete operation in the database. " + "NOTE: fails loudly if attempting to delete a comment that has any replies. All replies must " + "be deleted first.")
public ResponseEntity<?> delete(HttpServletRequest request, @PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
    // TODO: Validate articleId
    String deletedCommentUri = commentCrudService.deleteComment(commentId);
    return reportDeleted(deletedCommentUri);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with ArticleIdentifier

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

the class CommentCrudController method patch.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi:.+}", method = RequestMethod.PATCH)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "CommentInputView", value = "example #1: {\"title\": \"new title\"}<br>" + "example #2: {\"body\": \"comment body replacement text\"}<br>" + "example #3: {\"isRemoved\": \"true\"}")
public ResponseEntity<?> patch(HttpServletRequest request, @PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
    // TODO: Validate articleId
    CommentInputView input = readJsonFromRequest(request, CommentInputView.class);
    return commentCrudService.patchComment(commentId, input).asJsonResponse(entityGson);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) CommentInputView(org.ambraproject.rhino.view.comment.CommentInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with ArticleIdentifier

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

the class CommentCrudController method removeAllFlags.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi}/flags", method = RequestMethod.DELETE)
public ResponseEntity<?> removeAllFlags(@PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
    // TODO: Validate articleId
    commentCrudService.removeFlagsFromComment(commentId);
    return reportDeleted(commentId.toString());
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with ArticleIdentifier

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

the class CommentCrudController method readFlag.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi}/flags/{flagId}", method = RequestMethod.GET)
public void readFlag(@RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) Date ifModifiedSince, @PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi, @PathVariable("flagId") long flagId) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
    // TODO: Validate articleId and commentId
    commentCrudService.readCommentFlag(flagId).getIfModified(ifModifiedSince).asJsonResponse(entityGson);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with ArticleIdentifier

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

the class CommentCrudController method createFlag.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi}/flags", method = RequestMethod.POST)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "CommentFlagInputView", value = "example: {\"creatorUserId\": 10365, \"body\": \"oops\", \"reasonCode\": \"spam\"}")
public ResponseEntity<?> createFlag(HttpServletRequest request, @PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
    // TODO: Validate articleId
    CommentFlagInputView input = readJsonFromRequest(request, CommentFlagInputView.class);
    Flag commentFlag = commentCrudService.createCommentFlag(commentId, input);
    return ServiceResponse.reportCreated(commentNodeViewFactory.createFlagView(commentFlag)).asJsonResponse(entityGson);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) Flag(org.ambraproject.rhino.model.Flag) CommentFlagInputView(org.ambraproject.rhino.view.comment.CommentFlagInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) 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