Search in sources :

Example 1 with RelatedArticleType

use of org.ambraproject.wombat.model.RelatedArticleType in project wombat by PLOS.

the class ArticleMetadataTest method testGetRelatedArticleByType.

@Test
public void testGetRelatedArticleByType() throws IOException {
    RelatedArticle rel1 = mock(RelatedArticle.class);
    RelatedArticle rel2 = mock(RelatedArticle.class);
    RelatedArticleType type1 = RelatedArticleType.get("retracted-article");
    RelatedArticleType type2 = RelatedArticleType.get("retraction-forward");
    when(rel1.isPublished()).thenReturn(true);
    when(rel1.getPublicationDate()).thenReturn(LocalDate.of(2018, 1, 1));
    when(rel1.getType()).thenReturn(type1);
    when(rel2.isPublished()).thenReturn(true);
    when(rel2.getPublicationDate()).thenReturn(LocalDate.of(2019, 1, 1));
    when(rel2.getType()).thenReturn(type2);
    List<RelatedArticle> relations = ImmutableList.of(rel1, rel2);
    ArticleMetadata articleMetadata = articleMetadataFactory.newInstance(mock(Site.class), mock(RequestedDoiVersion.class), mock(ArticlePointer.class), new HashMap(), new HashMap(), relations);
    SortedMap<RelatedArticleType, List<RelatedArticle>> map = articleMetadata.getRelatedArticlesByType();
    assertEquals(ImmutableSet.of(type1, type2), map.keySet());
}
Also used : Site(org.ambraproject.wombat.config.site.Site) RequestedDoiVersion(org.ambraproject.wombat.identity.RequestedDoiVersion) RelatedArticleType(org.ambraproject.wombat.model.RelatedArticleType) HashMap(java.util.HashMap) RelatedArticle(org.ambraproject.wombat.model.RelatedArticle) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer) Test(org.junit.Test)

Example 2 with RelatedArticleType

use of org.ambraproject.wombat.model.RelatedArticleType in project wombat by PLOS.

the class ArticleMetadata method buildAmendmentGroups.

/**
 * Combine adjacent amendments that have the same type into one AmendmentGroup object, for display purposes. If
 * multiple amendments share a type but are separated in order by a different type, they go in separate groups.
 *
 * @param amendments a list of amendment objects in their desired display order
 * @return the amendments grouped by type in the same order
 */
private static List<AmendmentGroup> buildAmendmentGroups(List<Amendment> amendments) {
    if (amendments.isEmpty())
        return ImmutableList.of();
    List<AmendmentGroup> retval = new ArrayList<>(amendments.size());
    AmendmentGroup.Builder builder = null;
    RelatedArticleType type = null;
    for (Amendment amendment : amendments) {
        RelatedArticleType nextType = amendment.getType();
        if (builder == null || !Objects.equals(type, nextType)) {
            if (builder != null) {
                retval.add(builder.build());
            }
            builder = AmendmentGroup.builder().setType(nextType);
            type = nextType;
        }
        builder.addAmendment(amendment);
    }
    retval.add(builder.build());
    return retval;
}
Also used : Amendment(org.ambraproject.wombat.model.Amendment) RelatedArticleType(org.ambraproject.wombat.model.RelatedArticleType) ArrayList(java.util.ArrayList) AmendmentGroup(org.ambraproject.wombat.model.AmendmentGroup)

Aggregations

ArrayList (java.util.ArrayList)2 RelatedArticleType (org.ambraproject.wombat.model.RelatedArticleType)2 ImmutableList (com.google.common.collect.ImmutableList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Site (org.ambraproject.wombat.config.site.Site)1 ArticlePointer (org.ambraproject.wombat.identity.ArticlePointer)1 RequestedDoiVersion (org.ambraproject.wombat.identity.RequestedDoiVersion)1 Amendment (org.ambraproject.wombat.model.Amendment)1 AmendmentGroup (org.ambraproject.wombat.model.AmendmentGroup)1 RelatedArticle (org.ambraproject.wombat.model.RelatedArticle)1 Test (org.junit.Test)1