use of org.ambraproject.rhino.model.ArticleList 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.ArticleList in project rhino by PLOS.
the class ArticleListCrudServiceImpl method update.
@Override
public ArticleListView update(ArticleListIdentity identity, Optional<String> displayName, Optional<? extends Set<ArticleIdentifier>> articleIds) {
ArticleListView listView = getArticleList(identity);
ArticleList list = listView.getArticleList();
if (displayName.isPresent()) {
list.setDisplayName(displayName.get());
}
if (articleIds.isPresent()) {
List<Article> newArticles = fetchArticles(articleIds.get());
List<Article> oldArticles = list.getArticles();
oldArticles.clear();
oldArticles.addAll(newArticles);
}
hibernateTemplate.update(list);
return listView;
}
use of org.ambraproject.rhino.model.ArticleList in project rhino by PLOS.
the class ArticleListCrudServiceImpl method asArticleListViews.
private Collection<ArticleListView> asArticleListViews(List<Object[]> results, boolean excludeArticleMetadata) {
Collection<ArticleListView> views = new ArrayList<>(results.size());
for (Object[] result : results) {
String journalKey = (String) result[0];
ArticleList articleList = (ArticleList) result[1];
views.add(articleListViewFactory.getView(articleList, journalKey, excludeArticleMetadata));
}
return views;
}
use of org.ambraproject.rhino.model.ArticleList in project rhino by PLOS.
the class ArticleListCrudServiceImpl method getArticleList.
private ArticleListView getArticleList(final ArticleListIdentity identity) {
Object[] result = DataAccessUtils.uniqueResult(hibernateTemplate.execute((HibernateCallback<List<Object[]>>) session -> {
Query query = queryFor(session, "select j.journalKey, l", identity);
return query.list();
}));
if (result == null) {
throw nonexistentList(identity);
}
String journalKey = (String) result[0];
ArticleList articleList = (ArticleList) result[1];
return articleListViewFactory.getView(articleList, journalKey);
}
Aggregations