Search in sources :

Example 1 with TaxonBase

use of eu.etaxonomy.cdm.model.taxon.TaxonBase in project cdmlib by cybertaxonomy.

the class HomotypicalGroupComparator method compare.

@Override
public int compare(HomotypicalGroup group1, HomotypicalGroup group2) {
    TaxonBase<?> firstTypified1 = null;
    TaxonBase<?> firstTypified2 = null;
    if (group1.equals(group2)) {
        return 0;
    }
    TaxonComparator taxComparator = new HomotypicGroupTaxonComparator(null);
    Set<TaxonName> typifiedNames1 = group1.getTypifiedNames();
    List<TaxonBase> taxonBasesOfTypifiedNames = new ArrayList<>();
    for (TaxonName typifiedName : typifiedNames1) {
        if (!typifiedName.getTaxonBases().isEmpty()) {
            taxonBasesOfTypifiedNames.add(typifiedName.getTaxonBases().iterator().next());
        }
    }
    Collections.sort(taxonBasesOfTypifiedNames, taxComparator);
    firstTypified1 = taxonBasesOfTypifiedNames.get(0);
    Set<TaxonName> typifiedNames2 = group2.getTypifiedNames();
    taxonBasesOfTypifiedNames = new ArrayList<>();
    for (TaxonName typifiedName : typifiedNames2) {
        if (!typifiedName.getTaxonBases().isEmpty()) {
            taxonBasesOfTypifiedNames.add(typifiedName.getTaxonBases().iterator().next());
        }
    }
    Collections.sort(taxonBasesOfTypifiedNames, taxComparator);
    firstTypified2 = taxonBasesOfTypifiedNames.get(0);
    return taxComparator.compare(firstTypified1, firstTypified2);
}
Also used : TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) TaxonComparator(eu.etaxonomy.cdm.compare.taxon.TaxonComparator) ArrayList(java.util.ArrayList) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName)

Example 2 with TaxonBase

use of eu.etaxonomy.cdm.model.taxon.TaxonBase in project cdmlib by cybertaxonomy.

the class TaxonDaoHibernateImplTest method testGetTaxaByNameVariants.

/**
 * Test for all not covered possibilities of searches
 */
@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
public void testGetTaxaByNameVariants() {
    TaxonNode subtree = null;
    @SuppressWarnings("rawtypes") List<TaxonBase> results = taxonDao.getTaxaByName(noTaxa, noSynonyms, noMisapplied, doCommonNames, false, "c*", null, subtree, MatchMode.BEGINNING, null, includeUnpublished, null, null, null, null);
    Assert.assertEquals("There should be 2 Taxa", 2, results.size());
    results = taxonDao.getTaxaByName(noTaxa, noSynonyms, doMisapplied, doCommonNames, false, "R*", null, subtree, MatchMode.BEGINNING, null, includeUnpublished, null, null, null, null);
    Assert.assertEquals("There should be 1 Taxa", 1, results.size());
    results = taxonDao.getTaxaByName(noTaxa, doSynonyms, doMisapplied, doCommonNames, false, "R*", null, subtree, MatchMode.BEGINNING, null, includeUnpublished, null, null, null, null);
    Assert.assertEquals("There should be 1 Taxa", 1, results.size());
    results = taxonDao.getTaxaByName(noTaxa, doSynonyms, noMisapplied, doCommonNames, false, "c*", null, subtree, MatchMode.BEGINNING, null, includeUnpublished, null, null, null, null);
    Assert.assertEquals("There should be 2 Taxa", 2, results.size());
    results = taxonDao.getTaxaByName(doTaxa, noSynonyms, noMisapplied, doCommonNames, false, "c*", null, subtree, MatchMode.BEGINNING, null, includeUnpublished, null, null, null, null);
    Assert.assertEquals("There should be 2 Taxa", 2, results.size());
    Classification classification = classificationDao.load(classificationUuid);
    results = taxonDao.getTaxaByName(noTaxa, noSynonyms, noMisapplied, doCommonNames, false, "c*", classification, subtree, MatchMode.BEGINNING, null, includeUnpublished, null, null, null, null);
    Assert.assertEquals("There should be 1 Taxa", 1, results.size());
    Set<NamedArea> namedAreas = new HashSet<>();
    namedAreas.add((NamedArea) definedTermDao.load(southernAmericaUuid));
    results = taxonDao.getTaxaByName(noTaxa, noSynonyms, noMisapplied, doCommonNames, false, "c*", null, subtree, MatchMode.BEGINNING, namedAreas, includeUnpublished, null, null, null, null);
    Assert.assertEquals("There should be 1 Taxa", 1, results.size());
}
Also used : TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Classification(eu.etaxonomy.cdm.model.taxon.Classification) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) HashSet(java.util.HashSet) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 3 with TaxonBase

use of eu.etaxonomy.cdm.model.taxon.TaxonBase in project cdmlib by cybertaxonomy.

the class TaxonDaoHibernateImplTest method testGetTaxaByNameAndArea.

/**
 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#getTaxaByName(java.lang.String, eu.etaxonomy.cdm.model.reference.Reference)}
 * restricting the search by a set of Areas.
 */
@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
public void testGetTaxaByNameAndArea() {
    TaxonNode subtree = null;
    Set<NamedArea> namedAreas = new HashSet<>();
    namedAreas.add((NamedArea) definedTermDao.load(northernAmericaUuid));
    Classification classification = classificationDao.findByUuid(classificationUuid);
    // prepare some synonym relation ships for some tests
    Synonym synAtroposAgassiz = (Synonym) taxonDao.findByUuid(atroposAgassiz);
    Taxon taxonRethera = (Taxon) taxonDao.findByUuid(rethera);
    taxonRethera.addSynonym(synAtroposAgassiz, SynonymType.SYNONYM_OF());
    // logger.warn("addSynonym(..)");
    Synonym synAtroposLeach = (Synonym) taxonDao.findByUuid(atroposLeach);
    Taxon taxonRetheraSecCdmTest = (Taxon) taxonDao.findByUuid(retheraSecCdmtest);
    taxonRetheraSecCdmTest.addSynonym(synAtroposLeach, SynonymType.SYNONYM_OF());
    this.taxonDao.save(taxonRetheraSecCdmTest);
    Taxon test = (Taxon) this.taxonDao.findByUuid(retheraSecCdmtest);
    // Set<Synonym> synonyms3 = test.getSynonyms();
    // 1. searching for a taxon (Rethera)
    // long numberOfTaxa = taxonDao.countTaxaByName(Taxon.class, "Rethera", null, MatchMode.BEGINNING, namedAreas);
    @SuppressWarnings("rawtypes") List<TaxonBase> results = taxonDao.getTaxaByName(doTaxa, noSynonyms, noMisapplied, noCommonNames, false, "Rethera", null, subtree, MatchMode.BEGINNING, namedAreas, includeUnpublished, null, null, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertTrue("expected to find two taxa but found " + results.size(), results.size() == 2);
    results = taxonDao.getTaxaByName(noTaxa, noSynonyms, noMisapplied, doCommonNames, false, "com*", null, subtree, MatchMode.BEGINNING, namedAreas, includeUnpublished, null, null, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertTrue("expected to find one taxon but found " + results.size(), results.size() == 1);
    // 2. searching for a taxon (Rethera) contained in a specific classification
    results = taxonDao.getTaxaByName(doTaxa, noSynonyms, noMisapplied, noCommonNames, false, "Rethera", classification, subtree, MatchMode.BEGINNING, namedAreas, includeUnpublished, null, null, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertTrue("expected to find one taxon but found " + results.size(), results.size() == 1);
    // 3. searching for Synonyms
    results = taxonDao.getTaxaByName(noTaxa, doSynonyms, noMisapplied, noCommonNames, false, "Atropo", null, subtree, MatchMode.ANYWHERE, null, includeUnpublished, null, null, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    /*System.err.println(results.get(0).getTitleCache() + " - " +results.get(1).getTitleCache() + " - " +results.get(2).getTitleCache() );

        System.err.println(((Synonym)results.get(0)).getAcceptedTaxa().contains(taxonRethera)+ " - " +((Synonym)results.get(1)).getAcceptedTaxa().contains(taxonRethera)+ " - "  +((Synonym)results.get(2)).getAcceptedTaxa().contains(taxonRethera)+ " - "  );
        */
    assertTrue("expected to find three taxa but found " + results.size(), results.size() == 3);
    // 4. searching for Synonyms
    results = taxonDao.getTaxaByName(noTaxa, doSynonyms, noMisapplied, noCommonNames, false, "Atropo", null, subtree, MatchMode.BEGINNING, null, includeUnpublished, null, null, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertTrue("expected to find three taxa but found " + results.size(), results.size() == 3);
    // 5. searching for a Synonyms and Taxa
    results = taxonDao.getTaxaByName(doTaxa, doSynonyms, noMisapplied, noCommonNames, false, "A", null, subtree, MatchMode.BEGINNING, namedAreas, includeUnpublished, null, null, null, null);
    // only five taxa have a distribution
    assertNotNull("getTaxaByName should return a List", results);
    assertTrue("expected to find 8 taxa but found " + results.size(), results.size() == 8);
}
Also used : TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Classification(eu.etaxonomy.cdm.model.taxon.Classification) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) HashSet(java.util.HashSet) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 4 with TaxonBase

use of eu.etaxonomy.cdm.model.taxon.TaxonBase in project cdmlib by cybertaxonomy.

the class TaxonDaoHibernateImplTest method testFindByNameTitleCache.

/**
 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#findByNameTitleCache(Class<? extends TaxonBase>clazz, String queryString, Classification classification, TaxonNode subtree, MatchMode matchMode, Set<NamedArea> namedAreas, Integer pageNumber, Integer pageSize, List<String> propertyPaths)}
 * restricting the search by a set of Areas.
 */
@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
public void testFindByNameTitleCache() {
    TaxonNode subtree = null;
    Set<NamedArea> namedAreas = new HashSet<>();
    namedAreas.add((NamedArea) definedTermDao.load(northernAmericaUuid));
    Classification classification = classificationDao.findByUuid(classificationUuid);
    // prepare some synonym relation ships for some tests
    Synonym synAtroposAgassiz = (Synonym) taxonDao.findByUuid(atroposAgassiz);
    Taxon taxonRethera = (Taxon) taxonDao.findByUuid(rethera);
    taxonRethera.addSynonym(synAtroposAgassiz, SynonymType.SYNONYM_OF());
    // logger.warn("addSynonym(..)");
    this.taxonDao.clear();
    Synonym synAtroposLeach = (Synonym) taxonDao.findByUuid(atroposLeach);
    Taxon taxonRetheraSecCdmtest = (Taxon) taxonDao.findByUuid(retheraSecCdmtest);
    taxonRetheraSecCdmtest.addSynonym(synAtroposLeach, SynonymType.SYNONYM_OF());
    this.taxonDao.clear();
    // 1. searching for a taxon (Rethera)
    // long numberOfTaxa = taxonDao.countTaxaByName(Taxon.class, "Rethera", null, MatchMode.BEGINNING, namedAreas);
    @SuppressWarnings("rawtypes") List<TaxonBase> results = taxonDao.findByNameTitleCache(doTaxa, noSynonyms, includeUnpublished, "Rethera Rothschild & Jordan, 1903", null, subtree, MatchMode.EXACT, namedAreas, null, null, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertEquals("expected to find two taxa but found " + results.size(), 2, results.size());
    // 2. searching for a taxon (Rethera) contained in a specific classification
    results = taxonDao.findByNameTitleCache(doTaxa, noSynonyms, includeUnpublished, "Rethera Rothschild & Jordan, 1903", classification, subtree, MatchMode.EXACT, namedAreas, null, null, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertEquals("expected to find one taxon but found " + results.size(), 1, results.size());
    // 3. searching for Synonyms
    results = taxonDao.findByNameTitleCache(noTaxa, doSynonyms, includeUnpublished, "*Atropo", null, subtree, MatchMode.ANYWHERE, null, null, null, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertEquals("expected to find two taxa but found " + results.size(), 3, results.size());
    // 4. searching for Synonyms
    results = taxonDao.findByNameTitleCache(noTaxa, doSynonyms, includeUnpublished, "Atropo", null, subtree, MatchMode.BEGINNING, null, null, null, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertEquals("expected to find two taxa but found " + results.size(), 3, results.size());
    // 5. searching for a Synonyms and Taxa
    // attache a synonym first
    Synonym syn = (Synonym) taxonDao.findByUuid(this.atroposLeach);
    Taxon tax = (Taxon) taxonDao.findByUuid(rethera);
    tax.addSynonym(syn, SynonymType.HETEROTYPIC_SYNONYM_OF());
    taxonDao.save(tax);
    results = taxonDao.findByNameTitleCache(doTaxa, doSynonyms, includeUnpublished, "A", null, subtree, MatchMode.BEGINNING, namedAreas, null, null, null, null);
    assertNotNull("getTaxaByName should return a List", results);
    assertEquals("expected to find 8 taxa but found " + results.size(), 8, results.size());
}
Also used : TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Classification(eu.etaxonomy.cdm.model.taxon.Classification) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) HashSet(java.util.HashSet) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 5 with TaxonBase

use of eu.etaxonomy.cdm.model.taxon.TaxonBase in project cdmlib by cybertaxonomy.

the class TaxonDaoHibernateImplTest method testTaxonNameInTwoClassifications.

@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
public void testTaxonNameInTwoClassifications() {
    TaxonNode subtree = null;
    List<String> propertyPaths = new ArrayList<>();
    propertyPaths.add("taxonNodes");
    @SuppressWarnings("rawtypes") List<TaxonBase> taxa = taxonDao.getTaxaByName(doTaxa, doSynonyms, noMisapplied, noCommonNames, false, "P", null, subtree, MatchMode.BEGINNING, null, includeUnpublished, null, null, null, null);
    Taxon taxon = (Taxon) taxa.get(0);
    Set<TaxonNode> nodes = taxon.getTaxonNodes();
    assertTrue(nodes.size() == 1);
// assertNotNull(taxa);
// assertTrue(taxa.size() > 0);
}
Also used : TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) ArrayList(java.util.ArrayList) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet) DataSet(org.unitils.dbunit.annotation.DataSet)

Aggregations

TaxonBase (eu.etaxonomy.cdm.model.taxon.TaxonBase)101 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)48 ArrayList (java.util.ArrayList)38 Test (org.junit.Test)36 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)31 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)27 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)27 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)26 DataSet (org.unitils.dbunit.annotation.DataSet)24 Reference (eu.etaxonomy.cdm.model.reference.Reference)21 OrderHint (eu.etaxonomy.cdm.persistence.query.OrderHint)18 Classification (eu.etaxonomy.cdm.model.taxon.Classification)17 UUID (java.util.UUID)14 ExpectedDataSet (org.unitils.dbunit.annotation.ExpectedDataSet)12 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)10 HashSet (java.util.HashSet)10 Query (org.hibernate.Query)10 SpecimenOrObservationBase (eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)9 HashMap (java.util.HashMap)9 AuditQuery (org.hibernate.envers.query.AuditQuery)8