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);
}
use of org.springframework.transaction.annotation.Transactional 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.springframework.transaction.annotation.Transactional in project rhino by PLOS.
the class ArticleListCrudController method update.
@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/lists/{type}/journals/{journal}/keys/{key}", method = RequestMethod.PATCH)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "ListInputView", value = "example #1: {\"title\": \"New Title\"}<br>" + "example #2: {\"articleDois\": [\"10.1371/journal.pone.0012345\", \"10.1371/journal.pone.0054321\"]}")
public ResponseEntity<?> update(HttpServletRequest request, @PathVariable("type") String type, @PathVariable("journal") String journalKey, @PathVariable("key") String key) throws IOException {
final ListInputView inputView;
try {
inputView = readJsonFromRequest(request, ListInputView.class);
} catch (ListInputView.PartialIdentityException e) {
throw complainAboutListIdentityOnPatch(e);
}
if (inputView.getIdentity().isPresent()) {
throw complainAboutListIdentityOnPatch(null);
}
ArticleListIdentity identity = new ArticleListIdentity(type, journalKey, key);
articleListCrudService.update(identity, inputView.getTitle(), inputView.getArticleIds());
return new ResponseEntity<>(HttpStatus.OK);
}
Aggregations