use of org.springframework.transaction.annotation.Transactional in project rhino by PLOS.
the class ArticleCrudController method deleteRevision.
@Transactional(readOnly = false)
@RequestMapping(value = "/articles/{doi}/revisions/{revision}", method = RequestMethod.DELETE)
public ResponseEntity<?> deleteRevision(@PathVariable("doi") String doi, @PathVariable("revision") int revisionNumber) {
ArticleRevisionIdentifier revisionId = ArticleRevisionIdentifier.create(DoiEscaping.unescape(doi), revisionNumber);
articleRevisionWriteService.deleteRevision(revisionId);
return new ResponseEntity<>(HttpStatus.OK);
}
use of org.springframework.transaction.annotation.Transactional in project rhino by PLOS.
the class ArticleCrudController method getRawCategoriesAndText.
/**
* Retrieves the raw taxonomy categories associated with the article along with the text that is sent to the taxonomy
* server for classification
*
* @param request
* @return a String containing the text and raw categories in the form of <text> \n\n <categories>
* @throws IOException
*/
// TODO: Get rid of this?
@Transactional(readOnly = true)
@RequestMapping(value = "/articles/{doi}/categories", method = RequestMethod.GET, params = "rawCategoriesAndText")
public ResponseEntity<String> getRawCategoriesAndText(HttpServletRequest request, @PathVariable("doi") String doi) throws IOException {
ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(doi));
String categoriesAndText = articleCrudService.getRawCategoriesAndText(articleId);
HttpHeaders responseHeader = new HttpHeaders();
responseHeader.setContentType(MediaType.TEXT_HTML);
return new ResponseEntity<>(categoriesAndText, responseHeader, HttpStatus.OK);
}
use of org.springframework.transaction.annotation.Transactional in project rhino by PLOS.
the class ArticleCrudController method flagArticleCategory.
@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/articles/{doi}/categories", params = { "flag" }, method = RequestMethod.POST)
@ResponseBody
public Map<String, String> flagArticleCategory(@PathVariable("doi") String articleDoi, @RequestParam(value = "categoryTerm", required = true) String categoryTerm, @RequestParam(value = "userId", required = false) String userId, @RequestParam(value = "flag", required = true) String action) throws IOException {
ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
Article article = articleCrudService.readArticle(articleId);
Optional<Long> userIdObj = Optional.ofNullable(userId).map(Long::parseLong);
Collection<Category> categories = taxonomyService.getArticleCategoriesWithTerm(article, categoryTerm);
switch(action) {
case "add":
for (Category category : categories) {
taxonomyService.flagArticleCategory(article, category, userIdObj);
}
break;
case "remove":
for (Category category : categories) {
taxonomyService.deflagArticleCategory(article, category, userIdObj);
}
break;
default:
throw new RestClientException("action must be 'add' or 'remove'", HttpStatus.BAD_REQUEST);
}
// ajax call expects returned data so provide an empty map for the body
return ImmutableMap.of();
}
use of org.springframework.transaction.annotation.Transactional in project rhino by PLOS.
the class ArticleCrudController method populateCategories.
/**
* Populates article category information by making a call to the taxonomy server.
*
* @throws IOException
*/
@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/articles/{doi}/categories", method = RequestMethod.POST)
public ResponseEntity<?> populateCategories(@PathVariable("doi") String doi) throws IOException {
ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(doi));
articleCrudService.populateCategories(articleId);
// Report the current categories
return articleCrudService.serveCategories(articleId).asJsonResponse(entityGson);
}
use of org.springframework.transaction.annotation.Transactional 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);
}
Aggregations