Search in sources :

Example 16 with Journal

use of org.ambraproject.rhino.model.Journal in project rhino by PLOS.

the class RhinoTestHelper method createDummyJournal.

/**
   * Create a dummy journal with required non-null fields filled in.
   *
   * @param eissn the dummy journal's eIssn
   * @return a new dummy journal object
   */
public static Journal createDummyJournal(String eissn) {
    Preconditions.checkNotNull(eissn);
    Journal journal = new Journal();
    String title = "Test Journal " + eissn;
    journal.setTitle(title);
    journal.setJournalKey(title.replaceAll("\\s|-", ""));
    journal.seteIssn(eissn);
    return journal;
}
Also used : Journal(org.ambraproject.rhino.model.Journal)

Example 17 with Journal

use of org.ambraproject.rhino.model.Journal in project rhino by PLOS.

the class VolumeCrudServiceImpl method getJournalOf.

@Override
public Journal getJournalOf(Volume volume) {
    return hibernateTemplate.execute(session -> {
        Query query = session.createQuery("FROM Journal WHERE :volume IN ELEMENTS(volumes)");
        query.setParameter("volume", volume);
        return (Journal) query.uniqueResult();
    });
}
Also used : Query(org.hibernate.Query) Journal(org.ambraproject.rhino.model.Journal)

Example 18 with Journal

use of org.ambraproject.rhino.model.Journal in project rhino by PLOS.

the class JournalCrudServiceImpl method readJournalByVolume.

@Override
public Journal readJournalByVolume(Volume volume) {
    return hibernateTemplate.execute(session -> {
        Query query = session.createQuery("FROM Journal j WHERE :volume IN ELEMENTS(volumes)");
        query.setParameter("volume", volume);
        return (Journal) query.uniqueResult();
    });
}
Also used : Query(org.hibernate.Query) Journal(org.ambraproject.rhino.model.Journal)

Example 19 with Journal

use of org.ambraproject.rhino.model.Journal in project rhino by PLOS.

the class SyndicationCrudServiceImpl method getSyndications.

@Transactional
@Override
public Collection<Syndication> getSyndications(final String journalKey, final List<String> statuses) {
    int numDaysInPast = runtimeConfiguration.getQueueConfiguration().getSyndicationRange();
    LocalDate startDate = LocalDate.now().minus(numDaysInPast, ChronoUnit.DAYS);
    Instant startTime = startDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
    final Journal journal = journalService.readJournal(journalKey);
    if (journal == null) {
        throw new RuntimeException("Could not find journal for journal key: " + journalKey);
    }
    return hibernateTemplate.execute(session -> {
        Query query = session.createQuery("" + "SELECT s " + "FROM Syndication s " + "JOIN s.articleVersion av " + "JOIN av.journals j " + "WHERE j.journalKey = :journalKey " + "AND s.status in (:statuses)" + "AND s.lastModified > :startTime");
        query.setParameter("journalKey", journalKey);
        query.setParameterList("statuses", statuses);
        query.setDate("startTime", Date.from(startTime));
        return (Collection<Syndication>) query.list();
    });
}
Also used : Query(org.hibernate.Query) Instant(java.time.Instant) Collection(java.util.Collection) Journal(org.ambraproject.rhino.model.Journal) LocalDate(java.time.LocalDate) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Journal (org.ambraproject.rhino.model.Journal)19 Query (org.hibernate.Query)6 RestClientException (org.ambraproject.rhino.rest.RestClientException)4 Volume (org.ambraproject.rhino.model.Volume)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Collection (java.util.Collection)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ImmutableList (com.google.common.collect.ImmutableList)1 Instant (java.time.Instant)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BaseRhinoTest (org.ambraproject.rhino.BaseRhinoTest)1 Doi (org.ambraproject.rhino.identity.Doi)1 VolumeIdentifier (org.ambraproject.rhino.identity.VolumeIdentifier)1 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)1 ArticleList (org.ambraproject.rhino.model.ArticleList)1 Comment (org.ambraproject.rhino.model.Comment)1 Issue (org.ambraproject.rhino.model.Issue)1 ResolvedDoiView (org.ambraproject.rhino.view.ResolvedDoiView)1