Search in sources :

Example 36 with Transactional

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();
    });
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Query(org.hibernate.Query) List(java.util.List) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with Transactional

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

Example 38 with Transactional

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());
    }
}
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)

Example 39 with Transactional

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ArticleRevisionIdentifier(org.ambraproject.rhino.identity.ArticleRevisionIdentifier) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 40 with Transactional

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Transactional (org.springframework.transaction.annotation.Transactional)4561 Test (org.junit.Test)1387 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)724 DAOException (com.tomasio.projects.trainning.exception.DAOException)385 CoreException (com.tomasio.projects.trainning.exeption.CoreException)372 ArrayList (java.util.ArrayList)324 Date (java.util.Date)252 Query (javax.persistence.Query)218 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)213 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)211 WithMockUser (org.springframework.security.test.context.support.WithMockUser)204 HashMap (java.util.HashMap)187 List (java.util.List)163 User (io.github.jhipster.sample.domain.User)150 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)135 HashSet (java.util.HashSet)135 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)132 UUID (java.util.UUID)131 Rollback (org.springframework.test.annotation.Rollback)109 ParseException (java.text.ParseException)108