Search in sources :

Example 41 with Transactional

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();
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Category(org.ambraproject.rhino.model.Category) Article(org.ambraproject.rhino.model.Article) RestClientException(org.ambraproject.rhino.rest.RestClientException) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 42 with Transactional

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

Example 43 with Transactional

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

Example 44 with Transactional

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

Example 45 with Transactional

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);
}
Also used : ArticleListIdentity(org.ambraproject.rhino.identity.ArticleListIdentity) ResponseEntity(org.springframework.http.ResponseEntity) ListInputView(org.ambraproject.rhino.view.article.ListInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) 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