Search in sources :

Example 61 with Transactional

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);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

Example 62 with Transactional

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);
}
Also used : NodeNameLikeFilter(org.opennms.web.alarm.filter.NodeNameLikeFilter) SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) Filter(org.opennms.web.filter.Filter) AlarmIdFilter(org.opennms.web.alarm.filter.AlarmIdFilter) NodeNameLikeFilter(org.opennms.web.alarm.filter.NodeNameLikeFilter) AcknowledgedByFilter(org.opennms.web.alarm.filter.AcknowledgedByFilter) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

Example 63 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 64 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 65 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)

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