use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class AlarmRepositoryFilterIT method testBeforeFirstEventTimeFilter.
@Test
@Transactional
@JUnitTemporaryDatabase
public void testBeforeFirstEventTimeFilter() {
OnmsAlarm[] alarms = m_daoAlarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(new AlarmCriteria(new BeforeFirstEventTimeFilter(new Date()))));
assertEquals(1, alarms.length);
alarms = m_daoAlarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(new AlarmCriteria(new BeforeLastEventTimeFilter(new Date()))));
assertEquals(1, alarms.length);
}
use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class AlarmRepositoryIT method testSortAndSearchBySameProperty.
@Test
@Transactional
@JUnitTemporaryDatabase
public void testSortAndSearchBySameProperty() {
Filter[] filters = new Filter[] { new NodeNameLikeFilter("node") };
AlarmCriteria sorted = new AlarmCriteria(filters, SortStyle.NODE, AcknowledgeType.UNACKNOWLEDGED, 100, 0);
OnmsAlarm[] alarms = m_alarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(sorted));
assertTrue("Failed to sort with style " + SortStyle.NODE, alarms.length > 0);
}
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();
});
}
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;
}
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());
}
}
Aggregations