Search in sources :

Example 1 with Synonym

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

the class TaxonServiceImplTest method testDeleteSynonymSynonymTaxonBooleanDeleteOneTaxon.

@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonServiceImplTest.testDeleteSynonym.xml")
public final // test delete synonym, only for a special taxon, but because of other relationships it will not be deleted at all
void testDeleteSynonymSynonymTaxonBooleanDeleteOneTaxon() {
    final String[] tableNames = {// "TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
    // "HomotypicalGroup","HomotypicalGroup_AUD"
    };
    int nSynonyms = service.count(Synonym.class);
    Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);
    int nNames = nameService.count(TaxonName.class);
    Assert.assertEquals("There should  be 4 names in the database", 4, nNames);
    UUID uuidTaxon2 = UUID.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
    UUID uuidSynonym1 = UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
    Taxon taxon2 = (Taxon) service.load(uuidTaxon2);
    Synonym synonym1 = (Synonym) service.load(uuidSynonym1);
    synonym1.setSec(ReferenceFactory.newArticle());
    taxon2.addSynonym(synonym1, SynonymType.HETEROTYPIC_SYNONYM_OF());
    service.saveOrUpdate(synonym1);
    long nRelations = service.countSynonyms(true);
    // this was "3" when we still had synonym relationships
    Assert.assertEquals("There should be 2 relationship left in the database", 2, nRelations);
    service.deleteSynonym(synonym1, new SynonymDeletionConfigurator());
    this.commitAndStartNewTransaction(tableNames);
    nSynonyms = service.count(Synonym.class);
    // this was "2" when we still had synonym relationships
    Assert.assertEquals("There should still be 1 synonym left in the database", 1, nSynonyms);
    nNames = nameService.count(TaxonName.class);
    // was 3
    Assert.assertEquals("There should be 3 names left in the database", 3, nNames);
    nRelations = service.countSynonyms(true);
    Assert.assertEquals("There should be 1 related synonym left in the database", 1, nRelations);
}
Also used : SynonymDeletionConfigurator(eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) UUID(java.util.UUID) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 2 with Synonym

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

the class TaxonServiceImplTest method testGetHeterotypicSynonymyGroups.

@Test
public final void testGetHeterotypicSynonymyGroups() {
    Rank rank = Rank.SPECIES();
    Reference ref1 = ReferenceFactory.newGeneric();
    // HomotypicalGroup group = HomotypicalGroup.NewInstance();
    Taxon taxon1 = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(rank, "Test3", null, null, null, null, null, null, null), null);
    Synonym synonym0 = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(rank, "Test2", null, null, null, null, null, null, null), null);
    Synonym synonym1 = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(rank, "Test2", null, null, null, null, null, null, null), null);
    Synonym synonym2 = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(rank, "Test4", null, null, null, null, null, null, null), null);
    synonym0.getName().setHomotypicalGroup(taxon1.getHomotypicGroup());
    synonym2.getName().setHomotypicalGroup(synonym1.getHomotypicGroup());
    // tax2.addHeterotypicSynonymName(synonym.getName());
    taxon1.addSynonym(synonym1, SynonymType.HETEROTYPIC_SYNONYM_OF());
    taxon1.addSynonym(synonym2, SynonymType.HETEROTYPIC_SYNONYM_OF());
    service.save(synonym1);
    service.save(synonym2);
    service.save(taxon1);
    List<List<Synonym>> heteroSyns = service.getHeterotypicSynonymyGroups(taxon1, null);
    Assert.assertEquals("There should be 1 heterotypic group", 1, heteroSyns.size());
    List<Synonym> synList = heteroSyns.get(0);
    Assert.assertEquals("There should be 2 heterotypic syns in group 1", 2, synList.size());
    // test sec
    synonym2.setSec(ref1);
    heteroSyns = service.getHeterotypicSynonymyGroups(taxon1, null);
    Assert.assertEquals("There should be 1 heterotypic group", 1, heteroSyns.size());
    synList = heteroSyns.get(0);
    Assert.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 2, synList.size());
}
Also used : Reference(eu.etaxonomy.cdm.model.reference.Reference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) Rank(eu.etaxonomy.cdm.model.name.Rank) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) List(java.util.List) ArrayList(java.util.ArrayList) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test)

Example 3 with Synonym

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

the class TaxonServiceImplTest method testDeleteSynonymSynonymTaxonBooleanWithRelatedNameDeleteAllNameRelations.

@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonServiceImplTest.testDeleteSynonym.xml")
public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedNameDeleteAllNameRelations() {
    final String[] tableNames = { "TaxonBase", "TaxonBase_AUD", "TaxonName", "TaxonName_AUD", "HomotypicalGroup", "HomotypicalGroup_AUD" };
    int nSynonyms = service.count(Synonym.class);
    Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);
    int nNames = nameService.count(TaxonName.class);
    Assert.assertEquals("There should  be 4 names in the database", 4, nNames);
    UUID uuidSynonym1 = UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
    UUID uuidSynonymName2 = UUID.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
    Synonym synonym1 = (Synonym) service.load(uuidSynonym1);
    TaxonName name2 = nameService.load(uuidSynonymName2);
    UUID name3Uuid = synonym1.getName().getUuid();
    TaxonName name3 = nameService.load(name3Uuid);
    name3.addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null, null);
    service.saveOrUpdate(synonym1);
    long nRelations = nameService.listNameRelationships(null, 1000, 0, null, null).size();
    logger.info("number of name relations: " + nRelations);
    Assert.assertEquals("There should be 1 name relationship left in the database", 1, nRelations);
    SynonymDeletionConfigurator config = new SynonymDeletionConfigurator();
    NameDeletionConfigurator nameDeletionConfig = new NameDeletionConfigurator();
    nameDeletionConfig.setRemoveAllNameRelationships(true);
    config.setNameDeletionConfig(nameDeletionConfig);
    service.deleteSynonym(synonym1, config);
    this.commitAndStartNewTransaction(tableNames);
    nSynonyms = service.count(Synonym.class);
    Assert.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms);
    nNames = nameService.count(TaxonName.class);
    Assert.assertEquals("There should be 3 names left in the database ", 3, nNames);
    nRelations = service.countSynonyms(true);
    // may change with better implementation of countAllRelationships (see #2653)
    nRelations = nameService.listNameRelationships(null, 1000, 0, null, null).size();
    logger.info("number of name relations: " + nRelations);
    Assert.assertEquals("There should be no name relationship left in the database", 0, nRelations);
}
Also used : SynonymDeletionConfigurator(eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) NameDeletionConfigurator(eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) UUID(java.util.UUID) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 4 with Synonym

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

the class TaxonServiceImplTest method testDeleteSynonymSynonymTaxonBooleanWithRollback.

@Test
@DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
public final void testDeleteSynonymSynonymTaxonBooleanWithRollback() {
    // final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
    // "HomotypicalGroup","HomotypicalGroup_AUD"};
    int nSynonyms = service.count(Synonym.class);
    Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);
    int nNames = nameService.count(TaxonName.class);
    Assert.assertEquals("There should  be 4 names in the database", 4, nNames);
    long nRelations = service.countSynonyms(true);
    // may change with better implementation of countAllRelationships (see #2653)
    logger.debug("");
    Assert.assertEquals("There should be 2 relationships in the database (the 2 synonym relationship) but no name relationship", 2, nRelations);
    UUID uuidSynonym1 = UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
    UUID uuidSynonymName2 = UUID.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
    Synonym synonym1 = (Synonym) service.load(uuidSynonym1);
    TaxonName name2 = nameService.load(uuidSynonymName2);
    synonym1.getName().addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null, null);
    service.deleteSynonym(synonym1, new SynonymDeletionConfigurator());
    this.rollback();
    // printDataSet(System.out, tableNames);
    this.startNewTransaction();
    nSynonyms = service.count(Synonym.class);
    Assert.assertEquals("There should still be 2 synonyms left in the database", 2, nSynonyms);
    nNames = nameService.count(TaxonName.class);
    Assert.assertEquals("There should be 4 names left in the database", 4, nNames);
    nRelations = service.countSynonyms(true);
    // may change with better implementation of countAllRelationships (see #2653)
    Assert.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations);
}
Also used : SynonymDeletionConfigurator(eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) UUID(java.util.UUID) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 5 with Synonym

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

the class TaxonServiceImplTest method testDeleteSynonymSynonymTaxonDontDeleteName.

@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonServiceImplTest.testDeleteSynonym.xml")
public final // test delete synonym, but the name will not be deleted
void testDeleteSynonymSynonymTaxonDontDeleteName() {
    final String[] tableNames = {// "TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
    // "HomotypicalGroup","HomotypicalGroup_AUD"
    };
    int nSynonyms = service.count(Synonym.class);
    Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);
    int nNames = nameService.count(TaxonName.class);
    Assert.assertEquals("There should  be 4 names in the database", 4, nNames);
    long nRelations = service.countSynonyms(true);
    Assert.assertEquals("There should be two relationship left in the database", 2, nRelations);
    UUID uuidSynonym1 = UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
    Synonym synonym1 = (Synonym) service.load(uuidSynonym1);
    SynonymDeletionConfigurator config = new SynonymDeletionConfigurator();
    config.setDeleteNameIfPossible(false);
    config.setNewHomotypicGroupIfNeeded(true);
    service.deleteSynonym(synonym1, config);
    this.commitAndStartNewTransaction(tableNames);
    nSynonyms = service.count(Synonym.class);
    Assert.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms);
    nNames = nameService.count(TaxonName.class);
    Assert.assertEquals("There should be 4 names left in the database", 4, nNames);
    nRelations = service.countSynonyms(true);
    Assert.assertEquals("There should be no relationship left in the database", 1, nRelations);
}
Also used : SynonymDeletionConfigurator(eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) UUID(java.util.UUID) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Aggregations

Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)119 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)85 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)60 Test (org.junit.Test)40 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)37 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)34 Reference (eu.etaxonomy.cdm.model.reference.Reference)33 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)28 DataSet (org.unitils.dbunit.annotation.DataSet)28 ArrayList (java.util.ArrayList)27 UUID (java.util.UUID)27 Classification (eu.etaxonomy.cdm.model.taxon.Classification)25 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)23 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)21 TaxonBase (eu.etaxonomy.cdm.model.taxon.TaxonBase)20 SynonymDeletionConfigurator (eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator)14 HashSet (java.util.HashSet)14 SynonymType (eu.etaxonomy.cdm.model.taxon.SynonymType)12 DescriptionElementBase (eu.etaxonomy.cdm.model.description.DescriptionElementBase)10 TaxonRelationship (eu.etaxonomy.cdm.model.taxon.TaxonRelationship)10