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