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