Search in sources :

Example 1 with Syndication

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);
}
Also used : SyndicationView(org.ambraproject.rhino.view.article.SyndicationView) ArticleRevisionIdentifier(org.ambraproject.rhino.identity.ArticleRevisionIdentifier) Syndication(org.ambraproject.rhino.model.Syndication) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Syndication

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);
}
Also used : SyndicationView(org.ambraproject.rhino.view.article.SyndicationView) ArticleRevisionIdentifier(org.ambraproject.rhino.identity.ArticleRevisionIdentifier) SyndicationInputView(org.ambraproject.rhino.view.article.SyndicationInputView) Syndication(org.ambraproject.rhino.model.Syndication) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Syndication

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;
}
Also used : Syndication(org.ambraproject.rhino.model.Syndication) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with 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;
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Syndication(org.ambraproject.rhino.model.Syndication)

Example 5 with 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());
    }
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Syndication(org.ambraproject.rhino.model.Syndication) Date(java.util.Date) LocalDate(java.time.LocalDate) IOException(java.io.IOException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Syndication (org.ambraproject.rhino.model.Syndication)8 ArticleRevisionIdentifier (org.ambraproject.rhino.identity.ArticleRevisionIdentifier)4 SyndicationView (org.ambraproject.rhino.view.article.SyndicationView)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)3 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)3 SyndicationInputView (org.ambraproject.rhino.view.article.SyndicationInputView)3 Transactional (org.springframework.transaction.annotation.Transactional)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 IOException (java.io.IOException)1 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 Query (org.hibernate.Query)1