use of org.ambraproject.rhino.model.Syndication in project rhino by PLOS.
the class ArticleCrudController method readSyndications.
@RequestMapping(value = "/articles/{doi}/revisions/{number}/syndications", method = RequestMethod.GET)
public ResponseEntity<?> readSyndications(@PathVariable("doi") String doi, @PathVariable("number") int revisionNumber) throws IOException {
ArticleRevisionIdentifier revisionId = ArticleRevisionIdentifier.create(DoiEscaping.unescape(doi), revisionNumber);
List<Syndication> syndications = syndicationCrudService.getSyndications(revisionId);
// TODO: If revision does not exist, need to respond with 404 instead of empty list?
List<SyndicationView> views = syndications.stream().map(SyndicationView::new).collect(Collectors.toList());
return ServiceResponse.serveView(views).asJsonResponse(entityGson);
}
use of org.ambraproject.rhino.model.Syndication in project rhino by PLOS.
the class ArticleCrudController method createSyndication.
@RequestMapping(value = "/articles/{doi}/revisions/{number}/syndications", method = RequestMethod.POST)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "SyndicationInputView", value = "example: {\"targetQueue\": \"activemq:plos.pmc\"}")
public ResponseEntity<?> createSyndication(HttpServletRequest request, @PathVariable("doi") String doi, @PathVariable("number") int revisionNumber) throws IOException {
ArticleRevisionIdentifier revisionId = ArticleRevisionIdentifier.create(DoiEscaping.unescape(doi), revisionNumber);
SyndicationInputView input = readJsonFromRequest(request, SyndicationInputView.class);
Syndication syndication = syndicationCrudService.createSyndication(revisionId, input.getTargetQueue());
return ServiceResponse.reportCreated(new SyndicationView(syndication)).asJsonResponse(entityGson);
}
use of org.ambraproject.rhino.model.Syndication 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.ambraproject.rhino.model.Syndication in project rhino by PLOS.
the class SyndicationCrudServiceImpl method createSyndication.
@Override
public Syndication createSyndication(ArticleRevisionIdentifier revisionId, String syndicationTargetQueue) {
ArticleRevision articleVersion = articleCrudService.readRevision(revisionId);
Syndication syndication = new Syndication(articleVersion, syndicationTargetQueue);
syndication.setStatus(SyndicationStatus.PENDING.getLabel());
syndication.setSubmissionCount(0);
hibernateTemplate.save(syndication);
return syndication;
}
use of org.ambraproject.rhino.model.Syndication 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());
}
}
Aggregations