Search in sources :

Example 1 with IBookSection

use of eu.etaxonomy.cdm.model.reference.IBookSection in project cdmlib by cybertaxonomy.

the class ReferenceDaoHibernateImpl method rebuildIndex.

@Override
public void rebuildIndex() {
    FullTextSession fullTextSession = Search.getFullTextSession(getSession());
    for (Reference reference : list(null, null)) {
        // re-index all agents
        Hibernate.initialize(reference.getAuthorship());
        if (reference.getType().equals(ReferenceType.Article)) {
            Hibernate.initialize(((IArticle) reference).getInJournal());
        } else if (reference.getType().equals(ReferenceType.BookSection)) {
            Hibernate.initialize(((IBookSection) reference).getInBook());
        } else if (reference.getType().equals(ReferenceType.InProceedings)) {
            Hibernate.initialize(((IInProceedings) reference).getInProceedings());
        } else if (reference.getType().equals(ReferenceType.Thesis)) {
            Hibernate.initialize(((IThesis) reference).getSchool());
        } else if (reference.getType().equals(ReferenceType.Report)) {
            Hibernate.initialize(((IReport) reference).getInstitution());
        } else if (reference.getType().isPrintedUnit()) {
            Hibernate.initialize(((IPrintedUnitBase) reference).getInSeries());
        }
        fullTextSession.index(reference);
    }
    fullTextSession.flushToIndexes();
}
Also used : IThesis(eu.etaxonomy.cdm.model.reference.IThesis) FullTextSession(org.hibernate.search.FullTextSession) Reference(eu.etaxonomy.cdm.model.reference.Reference) IBookSection(eu.etaxonomy.cdm.model.reference.IBookSection) IPrintedUnitBase(eu.etaxonomy.cdm.model.reference.IPrintedUnitBase)

Example 2 with IBookSection

use of eu.etaxonomy.cdm.model.reference.IBookSection in project cdmlib by cybertaxonomy.

the class DefaultMatchStrategyTest method testInvokeReferences.

@Test
public void testInvokeReferences() throws MatchException {
    matchStrategy = DefaultMatchStrategy.NewInstance(Reference.class);
    Assert.assertTrue("Same object should always match", matchStrategy.invoke(book1, book1).isSuccessful());
    IBook bookClone = ((Reference) book1).clone();
    Assert.assertTrue("Cloned book should match", matchStrategy.invoke(book1, bookClone).isSuccessful());
    bookClone.setTitle("Any title");
    Assert.assertFalse("Books with differing titles should not match", matchStrategy.invoke(book1, bookClone).isSuccessful());
    String originalTitle = book1.getTitle();
    bookClone.setTitle(originalTitle);
    Assert.assertTrue("Cloned book should match", matchStrategy.invoke(book1, bookClone).isSuccessful());
    book1.setTitle(null);
    bookClone.setTitle(null);
    Assert.assertFalse("Books with no title should not match", matchStrategy.invoke(book1, bookClone).isSuccessful());
    book1.setTitle(originalTitle);
    bookClone.setTitle(originalTitle);
    bookClone.setInSeries(printSeries2);
    Assert.assertFalse("Cloned book with differing print series should not match", matchStrategy.invoke(book1, bookClone).isSuccessful());
    IPrintSeries seriesClone = ((Reference) printSeries1).clone();
    bookClone.setInSeries(seriesClone);
    Assert.assertTrue("Cloned book with cloned bookSeries should match", matchStrategy.invoke(book1, bookClone).isSuccessful());
    seriesClone.setTitle("Another title");
    Assert.assertFalse("Cloned book should not match with differing series title", matchStrategy.invoke(book1, bookClone).isSuccessful());
    bookClone.setInSeries(printSeries1);
    Assert.assertTrue("Original printSeries should match", matchStrategy.invoke(book1, bookClone).isSuccessful());
    IBook bookTitle1 = ReferenceFactory.newBook();
    IBook bookTitle2 = ReferenceFactory.newBook();
    Assert.assertFalse("Books without title should not match", matchStrategy.invoke(bookTitle1, bookTitle2).isSuccessful());
    String title = "Any title";
    bookTitle1.setTitle(title);
    bookTitle2.setTitle(title);
    Assert.assertTrue("Books with same title (not empty) should match", matchStrategy.invoke(bookTitle1, bookTitle2).isSuccessful());
    bookTitle1.setTitle("");
    bookTitle2.setTitle("");
    Assert.assertFalse("Books with empty title should not match", matchStrategy.invoke(bookTitle1, bookTitle2).isSuccessful());
    // Time period
    bookTitle1.setTitle(title);
    bookTitle2.setTitle(title);
    bookTitle1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1999, 2002));
    Assert.assertFalse("Books with differing publication dates should not match", matchStrategy.invoke(bookTitle1, bookTitle2).isSuccessful());
    bookTitle2.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1998));
    Assert.assertFalse("Books with differing publication dates should not match", matchStrategy.invoke(bookTitle1, bookTitle2).isSuccessful());
    bookTitle2.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1999));
    Assert.assertFalse("Books with differing publication dates should not match", matchStrategy.invoke(bookTitle1, bookTitle2).isSuccessful());
    bookTitle2.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1999, 2002));
    Assert.assertTrue("Books with same publication dates should match", matchStrategy.invoke(bookTitle1, bookTitle2).isSuccessful());
    // BookSection
    IBookSection section1 = ReferenceFactory.newBookSection();
    section1.setInBook(bookTitle1);
    section1.setTitle("SecTitle");
    section1.setPages("22-33");
    IBookSection section2 = ReferenceFactory.newBookSection();
    section2.setInBook(bookTitle1);
    section2.setTitle("SecTitle");
    section2.setPages("22-33");
    IMatchStrategyEqual bookSectionMatchStrategy = DefaultMatchStrategy.NewInstance(Reference.class);
    Assert.assertTrue("Equal BookSections should match", bookSectionMatchStrategy.invoke(section1, section2).isSuccessful());
    section2.setInBook(bookTitle2);
    Assert.assertTrue("Matching books should result in matching book sections", bookSectionMatchStrategy.invoke(section1, section2).isSuccessful());
    bookTitle2.setPages("xx");
    Assert.assertFalse("Sections with differing books should not match", bookSectionMatchStrategy.invoke(section1, section2).isSuccessful());
    // restore
    bookTitle2.setPages(null);
    Assert.assertTrue("Matching books should result in matching book sections", bookSectionMatchStrategy.invoke(section1, section2).isSuccessful());
    printSeries2.setTitle("A new series title");
    IMatchStrategyEqual printSeriesMatchStrategy = DefaultMatchStrategy.NewInstance(Reference.class);
    Assert.assertFalse("Print series with differing titles should not match", printSeriesMatchStrategy.invoke(printSeries1, printSeries2).isSuccessful());
    bookTitle1.setInSeries(printSeries1);
    bookTitle2.setInSeries(printSeries2);
    Assert.assertFalse("Books with not matching in series should not match", matchStrategy.invoke(bookTitle1, bookTitle2).isSuccessful());
    Assert.assertFalse("Sections with differing print series should not match", bookSectionMatchStrategy.invoke(section1, section2).isSuccessful());
    // Authorship
    Person person1 = Person.NewTitledInstance("person");
    Person person2 = Person.NewTitledInstance("person");
    person1.setPrefix("pre1");
    person2.setPrefix("pre2");
    book2 = ((Reference) book1).clone();
    Assert.assertTrue("Equal books should match", matchStrategy.invoke(book1, book2).isSuccessful());
    book1.setAuthorship(person1);
    book2.setAuthorship(person1);
    Assert.assertTrue("Books with same author should match", matchStrategy.invoke(book1, book2).isSuccessful());
    book2.setAuthorship(person2);
    Assert.assertFalse("Books with different authors should not match", matchStrategy.invoke(book1, book2).isSuccessful());
    person2.setPrefix("pre1");
    Assert.assertTrue("Books with matching authors should not match", matchStrategy.invoke(book1, book2).isSuccessful());
}
Also used : Reference(eu.etaxonomy.cdm.model.reference.Reference) IBook(eu.etaxonomy.cdm.model.reference.IBook) IPrintSeries(eu.etaxonomy.cdm.model.reference.IPrintSeries) IBookSection(eu.etaxonomy.cdm.model.reference.IBookSection) Person(eu.etaxonomy.cdm.model.agent.Person) Test(org.junit.Test)

Example 3 with IBookSection

use of eu.etaxonomy.cdm.model.reference.IBookSection in project cdmlib by cybertaxonomy.

the class MatchStrategyFactoryTest method getDefaultFullBookSection.

private IBookSection getDefaultFullBookSection() {
    IBookSection bookSection = getMatchingFullBookSection();
    bookSection.setTitle("Book section title");
    bookSection.setAbbrevTitle("Bk. sct. tit.");
    bookSection.setPages("22-33");
    ((Reference) bookSection).updateCaches();
    return bookSection;
}
Also used : Reference(eu.etaxonomy.cdm.model.reference.Reference) IBookSection(eu.etaxonomy.cdm.model.reference.IBookSection)

Example 4 with IBookSection

use of eu.etaxonomy.cdm.model.reference.IBookSection in project cdmlib by cybertaxonomy.

the class MatchStrategyFactoryTest method testParsedBookSection.

@Test
public void testParsedBookSection() throws MatchException {
    IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedBookSectionInstance();
    Assert.assertNotNull(matchStrategy);
    IBookSection fullBookSection;
    IBookSection parsedBookSection;
    fullBookSection = getMatchingFullBookSection();
    parsedBookSection = getDefaultParsedBookSection();
    Assert.assertTrue("Only author, book and date published should match", matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
    fullBookSection.setDoi(DOI.fromString("10.1234/abc"));
    Assert.assertFalse("Full book section having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page", matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
    fullBookSection.setDoi(null);
    fullBookSection.setReferenceAbstract("My abstract");
    Assert.assertFalse("Full book section having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page", matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
    // should match
    fullBookSection = getDefaultFullBookSection();
    Assert.assertFalse("Abbrev. title must be equal or null", matchStrategy.invoke(fullBookSection, parsedBookSection).isSuccessful());
    parsedBookSection.setAbbrevTitle(fullBookSection.getAbbrevTitle());
    Assert.assertFalse("Still not match because pages are not equal (parsed is null)", matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
    parsedBookSection.setPages(fullBookSection.getPages());
    Assert.assertFalse("Now they should match", matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
    // differing nom. title.
    parsedBookSection.setAbbrevTitle("Wrong");
    Assert.assertFalse("Differing abbrev. title. should not match", matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
    // differing family
    parsedBookSection = getDefaultParsedBookSection();
    parsedBookSection.setTitle("Wrong title");
    Assert.assertFalse("Differing title should not match", matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
    fullBookSection.setTitle(null);
    Assert.assertFalse("Title only for parsed book should not match. Wrong direction.", matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
    // change author
    fullBookSection = getMatchingFullBookSection();
    parsedBookSection = getDefaultParsedBookSection();
    fullBookSection.getAuthorship().setNomenclaturalTitleCache("Wrong", true);
    Assert.assertFalse("Differing author in nomencl. title should not match", matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
    // change author
    fullBookSection = getMatchingFullBookSection();
    parsedBookSection = getDefaultParsedBookSection();
    ((Person) fullBookSection.getAuthorship()).setFamilyName("Changed");
    Assert.assertTrue("Full book family name author changed should still match", matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
}
Also used : IBookSection(eu.etaxonomy.cdm.model.reference.IBookSection) Person(eu.etaxonomy.cdm.model.agent.Person) Test(org.junit.Test)

Example 5 with IBookSection

use of eu.etaxonomy.cdm.model.reference.IBookSection in project cdmlib by cybertaxonomy.

the class MarkupImportBase method handleNonCitationSpecific.

/**
 * Create reference for non nomenclatural references
 * @return
 */
protected Reference handleNonCitationSpecific(MarkupImportState state, String type, String authorStr, String titleStr, String titleCache, String volume, String issue, String edition, String editors, String pubName, String appendix, String pages, XMLEvent parentEvent) {
    Reference reference;
    // volume / issue
    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 + ")";
    }
    // pubName / appendix
    if (isNotBlank(appendix)) {
        pubName = pubName == null ? appendix : (pubName + " " + appendix).replaceAll("  ", " ");
    }
    if (isArticleNonCitation(type, pubName, volume, editors)) {
        IArticle article = ReferenceFactory.newArticle();
        if (pubName != null) {
            IJournal journal = ReferenceFactory.newJournal();
            journal.setTitle(pubName);
            article.setInJournal(journal);
        } else {
            fireWarningEvent("Article has no journal", parentEvent, 4);
        }
        reference = (Reference) article;
    } else {
        if (isBookSection(type, authorStr, titleStr, editors, pubName, volume)) {
            IBookSection bookSection = ReferenceFactory.newBookSection();
            if (pubName != null) {
                IBook book = ReferenceFactory.newBook();
                book.setTitle(pubName);
                bookSection.setInBook(book);
            }
            reference = (Reference) bookSection;
        } else {
            // ??
            Reference bookOrPartOf = ReferenceFactory.newGeneric();
            if (pubName != null && titleStr != null) {
                Reference inReference = ReferenceFactory.newGeneric();
                inReference.setTitle(pubName);
                bookOrPartOf.setInReference(inReference);
            }
            reference = bookOrPartOf;
        }
    }
    // author
    TeamOrPersonBase<?> author = createAuthor(state, authorStr);
    reference.setAuthorship(author);
    // title
    reference.setTitle(titleStr);
    if (StringUtils.isNotBlank(titleCache)) {
        reference.setTitleCache(titleCache, true);
    }
    // edition
    if (reference.getInReference() != null) {
        reference.getInReference().setEdition(edition);
        reference.getInReference().setEditor(editors);
    } else {
        // edition
        reference.setEdition(edition);
        reference.setEditor(editors);
    }
    // volume
    reference.setVolume(volume);
    // pages
    reference.setPages(pages);
    return reference;
}
Also used : IntextReference(eu.etaxonomy.cdm.model.common.IntextReference) Reference(eu.etaxonomy.cdm.model.reference.Reference) IBook(eu.etaxonomy.cdm.model.reference.IBook) IArticle(eu.etaxonomy.cdm.model.reference.IArticle) IBookSection(eu.etaxonomy.cdm.model.reference.IBookSection) IJournal(eu.etaxonomy.cdm.model.reference.IJournal)

Aggregations

IBookSection (eu.etaxonomy.cdm.model.reference.IBookSection)12 Reference (eu.etaxonomy.cdm.model.reference.Reference)8 IBook (eu.etaxonomy.cdm.model.reference.IBook)6 Test (org.junit.Test)6 Person (eu.etaxonomy.cdm.model.agent.Person)3 IArticle (eu.etaxonomy.cdm.model.reference.IArticle)2 IJournal (eu.etaxonomy.cdm.model.reference.IJournal)2 Team (eu.etaxonomy.cdm.model.agent.Team)1 IntextReference (eu.etaxonomy.cdm.model.common.IntextReference)1 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)1 INonViralName (eu.etaxonomy.cdm.model.name.INonViralName)1 IZoologicalName (eu.etaxonomy.cdm.model.name.IZoologicalName)1 Rank (eu.etaxonomy.cdm.model.name.Rank)1 INomenclaturalReference (eu.etaxonomy.cdm.model.reference.INomenclaturalReference)1 IPrintSeries (eu.etaxonomy.cdm.model.reference.IPrintSeries)1 IPrintedUnitBase (eu.etaxonomy.cdm.model.reference.IPrintedUnitBase)1 IThesis (eu.etaxonomy.cdm.model.reference.IThesis)1 StringNotParsableException (eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException)1 IMatchStrategyEqual (eu.etaxonomy.cdm.strategy.match.IMatchStrategyEqual)1 MatchException (eu.etaxonomy.cdm.strategy.match.MatchException)1