use of eu.etaxonomy.cdm.model.reference.IArticle in project cdmlib by cybertaxonomy.
the class MarkupNomenclatureImport method handleCitationSpecific.
/**
* Handles references used in the citation tag
* @param appendix
* @see #handleNonCitationSpecific(String, String, String, String, String, String, String, String)
*/
private Reference handleCitationSpecific(MarkupImportState state, String type, String authorStr, String titleStr, String titleCache, String volume, String issue, String edition, String editors, String pubName, String pages, String appendix, Map<String, String> refMap, XMLEvent parentEvent) {
if (titleStr != null) {
String message = "Currently it is not expected that a titleStr exists in a citation";
fireWarningEvent(message, parentEvent, 4);
}
if (isBlank(volume) && isNotBlank(issue)) {
String message = "Issue ('" + issue + "') exists but no volume";
fireWarningEvent(message, parentEvent, 4);
volume = issue;
} else if (isNotBlank(issue)) {
volume = volume + "(" + issue + ")";
}
RefType refType = defineRefTypeForCitation(type, volume, editors, authorStr, pubName, parentEvent);
Reference reference;
if (isNotBlank(appendix)) {
pubName = pubName == null ? appendix : (pubName + " " + appendix).replaceAll(" ", " ");
}
if (refType == RefType.Article) {
IArticle article = ReferenceFactory.newArticle();
if (pubName != null) {
IJournal journal = ReferenceFactory.newJournal();
journal.setTitle(pubName);
article.setInJournal(journal);
article.setVolume(volume);
if (isNotBlank(edition)) {
String message = "Article must not have an edition.";
fireWarningEvent(message, parentEvent, 4);
}
}
reference = (Reference) article;
} else if (refType == RefType.BookSection) {
// Book Section
reference = ReferenceFactory.newBookSection();
IBook book = ReferenceFactory.newBook();
reference.setInBook(book);
book.setTitle(pubName);
book.setVolume(volume);
book.setEdition(edition);
if (state.getConfig().isUseEditorAsInAuthorWhereNeeded()) {
TeamOrPersonBase<?> inAuthor = createAuthor(state, editors);
book.setAuthorship(inAuthor);
editors = null;
}
} else if (refType == RefType.Book) {
// Book
reference = ReferenceFactory.newBook();
reference.setTitle(pubName);
reference.setVolume(volume);
reference.setEdition(edition);
} else if (refType == RefType.Generic) {
// Generic - undefinable
// String message = "Can't define the type of the reference. Use generic instead";
// fireWarningEvent(message, parentEvent, 4);
reference = ReferenceFactory.newGeneric();
reference.setTitle(pubName);
reference.setEdition(edition);
// volume indicates an in-reference
if (isNotBlank(volume)) {
Reference partOf = ReferenceFactory.newGeneric();
partOf.setVolume(volume);
partOf.setInReference(reference);
reference = partOf;
}
} else if (refType == RefType.LatestUsed) {
Reference latestReference = state.getLatestReferenceInHomotype();
if (latestReference == null) {
String message = "No former reference available for incomplete citation";
fireWarningEvent(message, parentEvent, 6);
reference = ReferenceFactory.newGeneric();
} else {
if (latestReference.getInReference() != null) {
reference = latestReference.clone();
} else {
String message = "Latest reference is not an in-reference. This is not yet handled.";
fireWarningEvent(message, parentEvent, 6);
reference = ReferenceFactory.newGeneric();
}
}
reference.setVolume(volume);
if (isNotBlank(edition)) {
String message = "Edition not yet handled for incomplete citations";
fireWarningEvent(message, parentEvent, 4);
}
} else {
String message = "Unhandled reference type: %s";
fireWarningEvent(String.format(message, refType.toString()), parentEvent, 8);
reference = ReferenceFactory.newGeneric();
}
// author
TeamOrPersonBase<?> author;
if (isBlank(authorStr)) {
if (refType != RefType.LatestUsed) {
author = state.getLatestAuthorInHomotype();
reference.setAuthorship(author);
}
} else {
author = createAuthor(state, authorStr);
state.setLatestAuthorInHomotype(author);
reference.setAuthorship(author);
}
// title, titleCache
handleTitlesInCitation(titleStr, titleCache, parentEvent, reference);
// editors
handleEditorsInCitation(edition, editors, reference, parentEvent);
// pages
handlePages(state, refMap, parentEvent, reference, pages);
// state.getDeduplicationHelper(docImport).getExistingReference(state, reference);
// remember reference for following citation
state.setLatestReferenceInHomotype(reference);
return reference;
}
use of eu.etaxonomy.cdm.model.reference.IArticle in project cdmlib by cybertaxonomy.
the class ReferenceTest method testUnmarshalReference.
@Test
public void testUnmarshalReference() throws Exception {
CdmDocumentBuilder cdmDocumentBuilder = new CdmDocumentBuilder();
URI uri = new URI(URIEncoder.encode(this.getClass().getResource(resource).toString()));
DataSet dataSet = cdmDocumentBuilder.unmarshal(DataSet.class, new InputStreamReader(this.getClass().getResourceAsStream(resource)), uri.toString());
assertNotSame("Reference list should not be empty", 0, dataSet.getReferences().size());
IArticle article = dataSet.getReferences().get(0);
assertNotNull("Article must not be null", article);
IJournal journal = dataSet.getReferences().get(1);
assertNotNull("Journal must not be null", journal);
assertEquals("Journal must equal Article.inJournal", journal, article.getInJournal());
}
use of eu.etaxonomy.cdm.model.reference.IArticle in project cdmlib by cybertaxonomy.
the class ReferenceTest method testCastReferences.
@Test
public void testCastReferences() throws Exception {
CdmDocumentBuilder cdmDocumentBuilder = new CdmDocumentBuilder();
URI uri = new URI(URIEncoder.encode(this.getClass().getResource(resource).toString()));
DataSet dataSet = cdmDocumentBuilder.unmarshal(DataSet.class, new InputStreamReader(this.getClass().getResourceAsStream(resource)), uri.toString());
IArticle article = dataSet.getReferences().get(0);
assertNotNull("Article must not be null", article);
IJournal journal = ((Reference) article).castReferenceToJournal();
assertEquals("Journal", journal.getType().name());
IGeneric generic = ((Reference) journal).castReferenceToGeneric();
assertEquals("Generic", generic.getType().name());
}
use of eu.etaxonomy.cdm.model.reference.IArticle in project cdmlib by cybertaxonomy.
the class MatchStrategyFactoryTest method testParsedArticle.
@Test
public void testParsedArticle() throws MatchException {
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedArticleInstance();
Assert.assertNotNull(matchStrategy);
IArticle fullArticle;
IArticle parsedArticle;
fullArticle = getMatchingFullArticle();
parsedArticle = getDefaultParsedArticle();
Assert.assertTrue("Having only paramters both have in common like author, book and date published " + "should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
fullArticle.setDoi(DOI.fromString("10.1234/abc"));
Assert.assertFalse("Full article having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
// no match due to missing abbrev title match
fullArticle = getDefaultFullArticle();
Assert.assertFalse("Abbrev. title must be equal or null", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
parsedArticle.setAbbrevTitle(fullArticle.getAbbrevTitle());
Assert.assertFalse("Still not match because pages are not equal (parsed is null)", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
// FIXME in future this should not fail, but parsed articles never have really pages, they only have page or a page span in the parsed detail which is not the same as the pages of the article
parsedArticle.setPages(fullArticle.getPages());
Assert.assertFalse("Now they should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
// differing nom. title.
parsedArticle.setAbbrevTitle("Wrong");
Assert.assertFalse("Differing abbrev. title. should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
// differing family
parsedArticle = getDefaultParsedArticle();
parsedArticle.setTitle("Wrong title");
Assert.assertFalse("Differing title should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
fullArticle.setTitle(null);
Assert.assertFalse("Title only for parsed book should not match. Wrong direction.", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
// change author
fullArticle = getMatchingFullArticle();
parsedArticle = getDefaultParsedArticle();
fullArticle.getAuthorship().setNomenclaturalTitleCache("Wrong", true);
Assert.assertFalse("Differing author in nomencl. title should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
// change author
fullArticle = getMatchingFullArticle();
parsedArticle = getDefaultParsedArticle();
((Team) fullArticle.getAuthorship()).getTeamMembers().get(0).setFamilyName("Changed");
Assert.assertTrue("Full book family name author changed should still match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
}
use of eu.etaxonomy.cdm.model.reference.IArticle in project cdmlib by cybertaxonomy.
the class MatchStrategyFactoryTest method getMatchingFullArticle.
/**
* Article with {@link #getDefaultFullTeam() full team},
* {@link #getDefaultFullJournal() full journal} and date published
*/
private IArticle getMatchingFullArticle() {
IArticle article = ReferenceFactory.newArticle();
article.setAuthorship(getDefaultFullTeam());
article.setInJournal(getDefaultFullJournal());
article.setDatePublished(TimePeriodParser.parseStringVerbatim("1950"));
((Reference) article).updateCaches();
return article;
}
Aggregations