ReferenceMetadataToMatchableConverter implements Serializable { public MatchableEntity convertToMatchableEntity(String citationId, ReferenceMetadata refMetadata) { BasicMetadata metadata = refMetadata.getBasicMetadata(); String authors = extractAuthors(metadata); String journal = extractJournal(metadata); String pages = extractPages(metadata); String title = extractTitle(metadata); String year = extractYear(metadata); String rawText = StringUtils.isNotBlank(refMetadata.getRawText()) ? refMetadata.getRawText().toString() : (authors + ": " + title + ". " + journal + " (" + year + ") " + pages); MatchableEntity entity = MatchableEntity.fromParameters(citationId, authors, journal, title, pages, year, rawText); return entity; }  MatchableEntity convertToMatchableEntity(String citationId, ReferenceMetadata refMetadata);  }
@Test public void convertToMatchableEntity() { BasicMetadata basicMetadata = BasicMetadata.newBuilder() .setAuthors(Lists.newArrayList("John Doe")) .setJournal("Some Journal") .setTitle("Some Title") .setPages("55-64") .setYear("2002") .build(); ReferenceMetadata referenceMetadata = ReferenceMetadata.newBuilder() .setPosition(5) .setBasicMetadata(basicMetadata) .setRawText("rawText") .build(); MatchableEntity actualMatchableEntity = converter.convertToMatchableEntity("cit_someId", referenceMetadata); MatchableEntity expectedMatchableEntity = MatchableEntity.fromParameters("cit_someId", "John Doe", "Some Journal", "Some Title", "55-64", "2002", "rawText"); assertTrue(Arrays.equals(actualMatchableEntity.data().toByteArray(), expectedMatchableEntity.data().toByteArray())); }
@Test public void convertToMatchableEntity_MULTIPLE_AUTHORS() { BasicMetadata basicMetadata = BasicMetadata.newBuilder() .setAuthors(Lists.newArrayList("John Doe", "Jane Doe")) .build(); ReferenceMetadata referenceMetadata = ReferenceMetadata.newBuilder() .setPosition(5) .setBasicMetadata(basicMetadata) .setRawText("rawText") .build(); MatchableEntity actualMatchableEntity = converter.convertToMatchableEntity("cit_someId", referenceMetadata); MatchableEntity expectedMatchableEntity = MatchableEntity.fromParameters("cit_someId", "John Doe, Jane Doe", null, null, null, null, "rawText"); assertTrue(Arrays.equals(actualMatchableEntity.data().toByteArray(), expectedMatchableEntity.data().toByteArray())); }
@Test public void convertToMatchableEntity_NULL_RAW_TEXT() { BasicMetadata basicMetadata = BasicMetadata.newBuilder() .setAuthors(Lists.newArrayList("John Doe")) .setJournal("Some Journal") .setTitle("Some Title") .setPages("55-64") .setYear("2002") .build(); ReferenceMetadata referenceMetadata = ReferenceMetadata.newBuilder() .setPosition(5) .setBasicMetadata(basicMetadata) .setRawText(null) .build(); MatchableEntity actualMatchableEntity = converter.convertToMatchableEntity("cit_someId", referenceMetadata); MatchableEntity expectedMatchableEntity = MatchableEntity.fromParameters("cit_someId", "John Doe", "Some Journal", "Some Title", "55-64", "2002", "John Doe: Some Title. Some Journal (2002) 55-64"); assertTrue(Arrays.equals(actualMatchableEntity.data().toByteArray(), expectedMatchableEntity.data().toByteArray())); }