use of org.ambraproject.wombat.model.ArticleType in project wombat by PLOS.
the class BrowseController method buildArticleGroups.
private List<TypedArticleGroup> buildArticleGroups(Site site, String issueId, List<Map<String, ?>> articles) throws IOException {
// Articles grouped by their type. Order within the value lists is significant.
ArticleType.Dictionary typeDictionary = ArticleType.getDictionary(site.getTheme());
ListMultimap<ArticleType, Map<String, Object>> groupedArticles = LinkedListMultimap.create();
for (Map<String, ?> article : articles) {
// Omit unpublished articles
if (!article.containsKey("revisionNumber"))
continue;
String doi = (String) article.get("doi");
Map<String, Object> populatedArticle = new HashMap<>(article);
Map<String, ?> ingestion = (Map<String, ?>) article.get("ingestion");
ArticleType articleType = typeDictionary.lookUp((String) ingestion.get("articleType"));
populatedArticle.put("relatedArticles", articleMetadataFactory.fetchRelatedArticles(doi));
populateAuthors(populatedArticle, site);
groupedArticles.put(articleType, populatedArticle);
}
// The article types supported by this site, in the order in which they are supposed to appear.
ImmutableList<ArticleType> articleTypes = typeDictionary.getSequence();
// Produce a correctly ordered list of TypedArticleGroup, populated with the article groups.
List<TypedArticleGroup> articleGroups = new ArrayList<>(articleTypes.size());
for (ArticleType articleType : articleTypes) {
List<Map<String, Object>> articlesOfType = groupedArticles.removeAll(articleType);
if (!articlesOfType.isEmpty()) {
articleGroups.add(new TypedArticleGroup(articleType, articlesOfType));
}
}
// If any article groups were not matched, append them to the end.
for (Map.Entry<ArticleType, List<Map<String, Object>>> entry : Multimaps.asMap(groupedArticles).entrySet()) {
ArticleType type = entry.getKey();
TypedArticleGroup group = new TypedArticleGroup(type, entry.getValue());
articleGroups.add(group);
log.warn(String.format("Issue %s has articles of type \"%s\", which is not configured for %s: %s", issueId, type.getName(), site.getKey(), Lists.transform(group.articles, article -> article.get("doi"))));
}
return articleGroups;
}
Aggregations