Search in sources :

Example 76 with Transactional

use of org.springframework.transaction.annotation.Transactional in project rhino by PLOS.

the class IngestibleZipController method zipUpload.

/**
   * Create an article based on a POST containing an article .zip archive file.
   *
   * @param requestFile body of the archive param, with the encoded article .zip file
   * @throws java.io.IOException
   */
@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/articles", method = RequestMethod.POST)
public ResponseEntity<?> zipUpload(@RequestParam(value = "archive", required = true) MultipartFile requestFile, @RequestParam(value = "bucket", required = false) String bucket) throws IOException {
    String ingestedFileName = requestFile.getOriginalFilename();
    ArticleIngestion ingestion;
    try (InputStream requestInputStream = requestFile.getInputStream();
        Archive archive = Archive.readZipFile(ingestedFileName, requestInputStream)) {
        ingestion = ingestionService.ingest(archive, Optional.ofNullable(bucket));
    } catch (ManifestXml.ManifestDataException e) {
        throw new RestClientException("Invalid manifest: " + e.getMessage(), HttpStatus.BAD_REQUEST, e);
    }
    // Report the written data, as JSON, in the response.
    ArticleIngestionView view = articleIngestionViewFactory.getView(ingestion);
    return ServiceResponse.reportCreated(view).asJsonResponse(entityGson);
}
Also used : ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) Archive(org.ambraproject.rhino.util.Archive) InputStream(java.io.InputStream) ManifestXml(org.ambraproject.rhino.content.xml.ManifestXml) RestClientException(org.ambraproject.rhino.rest.RestClientException) ArticleIngestionView(org.ambraproject.rhino.view.article.ArticleIngestionView) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 77 with Transactional

use of org.springframework.transaction.annotation.Transactional in project rhino by PLOS.

the class IssueCrudController method update.

@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/journals/{journalKey}/volumes/{volumeDoi}/issues/{issueDoi:.+}", method = RequestMethod.PATCH)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "IssueInputView", value = "example #1: {\"displayName\": \"July\"}<br>" + "example #2: {\"imageArticleDoi\": \"10.1371/image.pbio.v02.i07\"}<br>" + "example #3: {\"articleOrder\": [\"10.1371/journal.pbio.0020213\", \"10.1371/journal.pbio.0020214\", " + "\"10.1371/journal.pbio.0020228\"]}")
public ResponseEntity<?> update(HttpServletRequest request, @RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) Date ifModifiedSince, @PathVariable("journalKey") String journalKey, @PathVariable("volumeDoi") String volumeDoi, @PathVariable("issueDoi") String issueDoi) throws IOException {
    // TODO: Validate journalKey and volumeDoiObj
    IssueIdentifier issueId = getIssueId(issueDoi);
    IssueInputView input = readJsonFromRequest(request, IssueInputView.class);
    issueCrudService.update(issueId, input);
    return issueCrudService.serveIssue(issueId).getIfModified(ifModifiedSince).asJsonResponse(entityGson);
}
Also used : IssueIdentifier(org.ambraproject.rhino.identity.IssueIdentifier) IssueInputView(org.ambraproject.rhino.view.journal.IssueInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 78 with Transactional

use of org.springframework.transaction.annotation.Transactional in project rhino by PLOS.

the class DoiController method resolve.

@Transactional(readOnly = true)
@RequestMapping(value = "/dois/{doi:.+}", method = RequestMethod.GET)
public ResponseEntity<?> resolve(@PathVariable("doi") String escapedDoi) throws IOException {
    Doi doi = DoiEscaping.unescape(escapedDoi);
    ResolvedDoiView view = findDoiTarget(doi);
    return ServiceResponse.serveView(view).asJsonResponse(entityGson);
}
Also used : ResolvedDoiView(org.ambraproject.rhino.view.ResolvedDoiView) Doi(org.ambraproject.rhino.identity.Doi) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 79 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class LayoutDaoIT method verifyCRUD.

@Test
@Transactional
public void verifyCRUD() {
    // Nothing created yet
    Assert.assertEquals(0, layoutDao.countAll());
    Assert.assertEquals(0, layoutDao.countMatching(new Criteria(VertexPositionEntity.class)));
    // Create dummy
    LayoutEntity layout = new LayoutEntity();
    layout.setId("hash");
    layout.setCreated(new Date());
    layout.setCreator("mvrueden");
    layout.setUpdated(layout.getCreated());
    layout.setUpdator(layout.getCreator());
    layout.addVertexPosition(createVertexPosition("dummy", "1", 0, 0));
    layout.addVertexPosition(createVertexPosition("dummy", "2", 1, 1));
    // create and verify creation
    layoutDao.saveOrUpdate(layout);
    Assert.assertEquals(1, layoutDao.countAll());
    Assert.assertEquals(2, layoutDao.countMatching(new Criteria(VertexPositionEntity.class)));
    // Update
    // Remove Vertex
    layout.getVertexPositions().remove(0);
    layoutDao.update(layout);
    Assert.assertEquals(1, layoutDao.countAll());
    Assert.assertEquals(1, layoutDao.countMatching(new Criteria(VertexPositionEntity.class)));
    // Add Vertex
    layout.addVertexPosition(createVertexPosition("dummy", "3", 2, 2));
    layoutDao.update(layout);
    Assert.assertEquals(1, layoutDao.countAll());
    Assert.assertEquals(2, layoutDao.countMatching(new Criteria(VertexPositionEntity.class)));
    // Update layout
    layout.setUpdated(new Date());
    layout.setUpdator("ulf");
    Assert.assertEquals(1, layoutDao.countAll());
    Assert.assertEquals(2, layoutDao.countMatching(new Criteria(VertexPositionEntity.class)));
    // Delete
    layoutDao.delete(layout);
    Assert.assertEquals(0, layoutDao.countAll());
    Assert.assertEquals(0, layoutDao.countMatching(new Criteria(VertexPositionEntity.class)));
}
Also used : Criteria(org.opennms.core.criteria.Criteria) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 80 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class DaoWebEventRepositoryIT method testFilterBySeverity.

@Test
@Transactional
public void testFilterBySeverity() {
    NegativeSeverityFilter filter = new NegativeSeverityFilter(OnmsSeverity.NORMAL.getId());
    EventCriteria criteria = new EventCriteria(filter);
    Event[] events = m_daoEventRepo.getMatchingEvents(criteria);
    assertTrue(events.length > 0);
    EventCriteria sortedCriteria = new EventCriteria(new Filter[] { filter }, SortStyle.ID, AcknowledgeType.UNACKNOWLEDGED, 100, 0);
    Event[] sortedEvents = m_daoEventRepo.getMatchingEvents(sortedCriteria);
    assertTrue(sortedEvents.length > 0);
}
Also used : NegativeSeverityFilter(org.opennms.web.event.filter.NegativeSeverityFilter) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) EventCriteria(org.opennms.web.event.filter.EventCriteria) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Transactional (org.springframework.transaction.annotation.Transactional)1415 Test (org.junit.Test)507 Query (javax.persistence.Query)166 Date (java.util.Date)121 ArrayList (java.util.ArrayList)99 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)89 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)87 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)84 OnmsNode (org.opennms.netmgt.model.OnmsNode)83 TypedQuery (javax.persistence.TypedQuery)81 Rollback (org.springframework.test.annotation.Rollback)81 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)67 HashMap (java.util.HashMap)65 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)61 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)58 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)58 DBUnitTest (org.orcid.test.DBUnitTest)57 List (java.util.List)56 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)41 User (com.arnaugarcia.uplace.domain.User)39