Search in sources :

Example 1 with ArticleListView

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;
}
Also used : Article(org.ambraproject.rhino.model.Article) ArticleListView(org.ambraproject.rhino.view.journal.ArticleListView) ArticleList(org.ambraproject.rhino.model.ArticleList)

Example 2 with ArticleListView

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;
}
Also used : ArrayList(java.util.ArrayList) ArticleListView(org.ambraproject.rhino.view.journal.ArticleListView) ArticleList(org.ambraproject.rhino.model.ArticleList)

Example 3 with ArticleListView

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);
}
Also used : ArticleListIdentity(org.ambraproject.rhino.identity.ArticleListIdentity) ImmutableSet(com.google.common.collect.ImmutableSet) ListInputView(org.ambraproject.rhino.view.article.ListInputView) RestClientException(org.ambraproject.rhino.rest.RestClientException) ArticleListView(org.ambraproject.rhino.view.journal.ArticleListView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ArticleListView (org.ambraproject.rhino.view.journal.ArticleListView)3 ArticleList (org.ambraproject.rhino.model.ArticleList)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)1 ArrayList (java.util.ArrayList)1 ArticleListIdentity (org.ambraproject.rhino.identity.ArticleListIdentity)1 Article (org.ambraproject.rhino.model.Article)1 RestClientException (org.ambraproject.rhino.rest.RestClientException)1 ListInputView (org.ambraproject.rhino.view.article.ListInputView)1 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1