use of org.springframework.transaction.annotation.Transactional in project rhino by PLOS.
the class SyndicationCrudServiceImpl method getSyndications.
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
@Override
public List<Syndication> getSyndications(ArticleRevisionIdentifier revisionId) {
ArticleRevision articleRevision = articleCrudService.readRevision(revisionId);
return hibernateTemplate.execute(session -> {
Query query = session.createQuery("" + "FROM Syndication s " + "WHERE s.articleRevision = :articleRevision");
query.setParameter("articleRevision", articleRevision);
return (List<Syndication>) query.list();
});
}
use of org.springframework.transaction.annotation.Transactional in project rhino by PLOS.
the class SyndicationCrudServiceImpl method updateSyndication.
@Transactional(rollbackFor = { Throwable.class })
@Override
public Syndication updateSyndication(final ArticleRevisionIdentifier revisionId, final String syndicationTargetQueue, final String status, final String errorMessage) {
Syndication syndication = getSyndication(revisionId, syndicationTargetQueue);
if (syndication == null) {
throw new RuntimeException("No such syndication for doi " + revisionId + " and target " + syndicationTargetQueue);
}
syndication.setStatus(status);
syndication.setErrorMessage(errorMessage);
hibernateTemplate.update(syndication);
return syndication;
}
use of org.springframework.transaction.annotation.Transactional in project rhino by PLOS.
the class SyndicationCrudServiceImpl method syndicate.
@Transactional(rollbackFor = { Throwable.class })
@Override
public Syndication syndicate(ArticleRevisionIdentifier revisionId, String syndicationTargetQueue) {
ArticleRevision articleVersion = articleCrudService.readRevision(revisionId);
Syndication syndication = getSyndication(revisionId, syndicationTargetQueue);
if (syndication == null) {
syndication = new Syndication(articleVersion, syndicationTargetQueue);
syndication.setStatus(SyndicationStatus.IN_PROGRESS.getLabel());
syndication.setSubmissionCount(1);
syndication.setLastSubmitTimestamp(new Date());
hibernateTemplate.save(syndication);
} else {
syndication.setStatus(SyndicationStatus.IN_PROGRESS.getLabel());
syndication.setSubmissionCount(syndication.getSubmissionCount() + 1);
syndication.setLastSubmitTimestamp(new Date());
hibernateTemplate.update(syndication);
}
try {
messageSender.sendBody(syndicationTargetQueue, createBody(revisionId));
log.info("Successfully sent a Message to plos-queue for {} to be syndicated to {}", revisionId, syndicationTargetQueue);
return syndication;
} catch (Exception e) {
log.warn("Error syndicating " + revisionId + " to " + syndicationTargetQueue, e);
return updateSyndication(revisionId, syndicationTargetQueue, SyndicationStatus.FAILURE.getLabel(), e.getMessage());
}
}
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);
}
Aggregations