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());
}
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;
}
Aggregations