use of org.ambraproject.rhino.view.journal.ArticleListView 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.view.journal.ArticleListView 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.view.journal.ArticleListView in project rhino by PLOS.
the class ArticleListCrudController method create.
@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/lists", method = RequestMethod.POST)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "ListInputView", value = "example: {\"journal\": \"PLoSONE\", \"type\": \"admin\", \"key\": \"plosone_news\", " + "\"title\": \"test\", \"articleDois\": [\"10.1371/journal.pone.0095668\"]}")
public ResponseEntity<?> create(HttpServletRequest request) throws IOException {
final ListInputView inputView;
try {
inputView = readJsonFromRequest(request, ListInputView.class);
} catch (ListInputView.PartialIdentityException e) {
throw complainAboutRequiredListIdentity(e);
}
Optional<ArticleListIdentity> identity = inputView.getIdentity();
if (!identity.isPresent()) {
throw complainAboutRequiredListIdentity(null);
}
Optional<String> title = inputView.getTitle();
if (!title.isPresent()) {
throw new RestClientException("title required", HttpStatus.BAD_REQUEST);
}
Optional<ImmutableSet<ArticleIdentifier>> articleDois = inputView.getArticleIds();
if (!articleDois.isPresent()) {
throw new RestClientException("articleDois required", HttpStatus.BAD_REQUEST);
}
ArticleListView listView = articleListCrudService.create(identity.get(), title.get(), articleDois.get());
return ServiceResponse.reportCreated(listView).asJsonResponse(entityGson);
}
Aggregations