Search in sources :

Example 11 with Journal

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

the class ArticleListCrudServiceImpl method create.

@Override
public ArticleListView create(ArticleListIdentity identity, String displayName, Set<ArticleIdentifier> articleIds) {
    if (listExists(identity)) {
        throw new RestClientException("List already exists: " + identity, HttpStatus.BAD_REQUEST);
    }
    ArticleList list = new ArticleList();
    list.setListType(identity.getType());
    list.setListKey(identity.getKey());
    list.setDisplayName(displayName);
    list.setArticles(fetchArticles(articleIds));
    Journal journal = (Journal) DataAccessUtils.uniqueResult(hibernateTemplate.findByCriteria(DetachedCriteria.forClass(Journal.class).add(Restrictions.eq("journalKey", identity.getJournalKey()))));
    if (journal == null) {
        throw new RestClientException("Journal not found: " + identity.getJournalKey(), HttpStatus.BAD_REQUEST);
    }
    Collection<ArticleList> journalLists = journal.getArticleLists();
    if (journalLists == null) {
        journal.setArticleLists(journalLists = new ArrayList<>(1));
    }
    journalLists.add(list);
    hibernateTemplate.update(journal);
    return articleListViewFactory.getView(list, journal.getJournalKey());
}
Also used : RestClientException(org.ambraproject.rhino.rest.RestClientException) ArrayList(java.util.ArrayList) Journal(org.ambraproject.rhino.model.Journal) ArticleList(org.ambraproject.rhino.model.ArticleList)

Example 12 with Journal

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

the class JournalCrudController method readCurrentIssue.

@Transactional(readOnly = true)
@RequestMapping(value = "/journals/{journalKey}/currentIssue", method = RequestMethod.GET)
public ResponseEntity<?> readCurrentIssue(@PathVariable String journalKey) throws IOException {
    Journal journal = journalCrudService.readJournal(journalKey);
    IssueOutputView view = issueOutputViewFactory.getCurrentIssueViewFor(journal).orElseThrow(() -> new RestClientException("Current issue is not set for " + journalKey, HttpStatus.NOT_FOUND));
    return ServiceResponse.serveView(view).asJsonResponse(entityGson);
}
Also used : IssueOutputView(org.ambraproject.rhino.view.journal.IssueOutputView) RestClientException(org.ambraproject.rhino.rest.RestClientException) Journal(org.ambraproject.rhino.model.Journal) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with Journal

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

the class VolumeCrudController method readVolumesForJournal.

@Transactional(readOnly = true)
@RequestMapping(value = "/journals/{journalKey}/volumes", method = RequestMethod.GET)
public ResponseEntity<?> readVolumesForJournal(@PathVariable("journalKey") String journalKey) throws IOException {
    Journal journal = journalCrudService.readJournal(journalKey);
    List<VolumeOutputView> views = journal.getVolumes().stream().map(volumeOutputViewFactory::getView).collect(Collectors.toList());
    return ServiceResponse.serveView(views).asJsonResponse(entityGson);
}
Also used : VolumeOutputView(org.ambraproject.rhino.view.journal.VolumeOutputView) Journal(org.ambraproject.rhino.model.Journal) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with Journal

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

the class DoiController method findDoiTarget.

private ResolvedDoiView findDoiTarget(Doi doi) throws IOException {
    // Look for the DOI in the corpus of articles
    Optional<ResolvedDoiView> itemOverview = articleCrudService.getItemOverview(doi);
    if (itemOverview.isPresent()) {
        return itemOverview.get();
    }
    // Not found as an Article or ArticleItem. Check other object types that use DOIs.
    Optional<Comment> comment = commentCrudService.getComment(CommentIdentifier.create(doi));
    if (comment.isPresent()) {
        ArticleOverview article = articleCrudService.buildOverview(comment.get().getArticle());
        return ResolvedDoiView.createForArticle(doi, ResolvedDoiView.DoiWorkType.COMMENT, article);
    }
    Optional<Issue> issue = issueCrudService.getIssue(IssueIdentifier.create(doi));
    if (issue.isPresent()) {
        Journal journal = issueCrudService.getJournalOf(issue.get());
        return ResolvedDoiView.create(doi, ResolvedDoiView.DoiWorkType.ISSUE, journal);
    }
    Optional<Volume> volume = volumeCrudService.getVolume(VolumeIdentifier.create(doi));
    if (volume.isPresent()) {
        Journal journal = volumeCrudService.getJournalOf(volume.get());
        return ResolvedDoiView.create(doi, ResolvedDoiView.DoiWorkType.VOLUME, journal);
    }
    throw new RestClientException("DOI not found: " + doi.getName(), HttpStatus.NOT_FOUND);
}
Also used : Comment(org.ambraproject.rhino.model.Comment) ResolvedDoiView(org.ambraproject.rhino.view.ResolvedDoiView) Issue(org.ambraproject.rhino.model.Issue) Volume(org.ambraproject.rhino.model.Volume) RestClientException(org.ambraproject.rhino.rest.RestClientException) ArticleOverview(org.ambraproject.rhino.view.article.ArticleOverview) Journal(org.ambraproject.rhino.model.Journal)

Example 15 with Journal

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

the class IngestionTest method createTestJournal.

/**
   * Persist a dummy Journal object with a particular eIssn into the test environment, if it doesn't already exist.
   *
   * @param eissn the journal eIssn
   */
private void createTestJournal(String eissn) {
    Journal journal = (Journal) DataAccessUtils.uniqueResult((List<?>) hibernateTemplate.findByCriteria(DetachedCriteria.forClass(Journal.class).add(Restrictions.eq("eIssn", eissn)).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)));
    if (journal == null) {
        journal = RhinoTestHelper.createDummyJournal(eissn);
        hibernateTemplate.save(journal);
    }
}
Also used : Journal(org.ambraproject.rhino.model.Journal) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

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