+++ /dev/null
-// $Id$\r
-/**\r
-* Copyright (C) 2009 EDIT\r
-* European Distributed Institute of Taxonomy \r
-* http://www.e-taxonomy.eu\r
-* \r
-* The contents of this file are subject to the Mozilla Public License Version 1.1\r
-* See LICENSE.TXT at the top of this package for the full license terms.\r
-*/\r
-package eu.etaxonomy.cdm.api.service;\r
-\r
-import org.apache.log4j.Logger;\r
-\r
-/**\r
- * This class is used to configure name deletion.\r
- * \r
- * @see INameService#delete(eu.etaxonomy.cdm.model.name.TaxonNameBase)\r
- * \r
- * @author a.mueller\r
- * @date 19.09.2011\r
- *\r
- */\r
-public class NameDeletionConfigurator {\r
- @SuppressWarnings("unused")\r
- private static final Logger logger = Logger.getLogger(NameDeletionConfigurator.class);\r
-\r
-\r
- private boolean removeAllNameRelationships = false;\r
- \r
- private boolean ignoreIsBasionymFor = false;\r
- \r
- private boolean ignoreIsReplacedSynonymFor = false;\r
-\r
- private boolean ignoreHasBasionym = true;\r
- \r
- private boolean ignoreHasReplacedSynonym = true;\r
- \r
- /**\r
- * If true, all name relationships will be deleted prior to deleting the name.\r
- * Exceptions will not be thrown due to existing name relationships.\r
- * @return the removeAllNameRelationships\r
- */\r
- public boolean isRemoveAllNameRelationships() {\r
- return removeAllNameRelationships;\r
- }\r
-\r
- /**\r
- * @param removeAllNameRelationships the removeAllNameRelationships to set\r
- */\r
- public void setRemoveAllNameRelationships(boolean removeAllNameRelationships) {\r
- this.removeAllNameRelationships = removeAllNameRelationships;\r
- }\r
-\r
- /**\r
- * If true, all basionym relationships in which this name is the basionym/original name will be removed.\r
- * Exceptions will not be thrown due to existing basionym relationships.\r
- * This value is neglected if {@link #isRemoveAllNameRelationships()} is true.\r
- * @see #setIgnoreIsBasionymFor(boolean)\r
- * @return the ignoreIsBasionymFor\r
- */\r
- public boolean isIgnoreIsBasionymFor() {\r
- return ignoreIsBasionymFor;\r
- }\r
-\r
- /**\r
- * @see #isIgnoreIsBasionymFor()\r
- * @param ignoreIsBasionymFor the ignoreIsBasionymFor to set\r
- */\r
- public void setIgnoreIsBasionymFor(boolean ignoreIsBasionymFor) {\r
- this.ignoreIsBasionymFor = ignoreIsBasionymFor;\r
- }\r
-\r
- /**\r
- * If true, all name relationships in which this name is a replaced synonym will be removed.\r
- * Exceptions will not be thrown due to existing isReplacedSynonym relationships.\r
- * This value is neglected if {@link #isRemoveAllNameRelationships()} is true.\r
- * @see #setIgnoreIsReplacedSynonymFor(boolean)\r
- * @return the ignoreIsReplacedSynonymFor\r
- */\r
- public boolean isIgnoreIsReplacedSynonymFor() {\r
- return ignoreIsReplacedSynonymFor;\r
- }\r
-\r
- /**\r
- * @see #isIgnoreIsReplacedSynonymFor()\r
- * @param ignoreIsReplacedSynonymFor the ignoreIsReplacedSynonymFor to set\r
- */\r
- public void setIgnoreIsReplacedSynonymFor(boolean ignoreIsReplacedSynonymFor) {\r
- this.ignoreIsReplacedSynonymFor = ignoreIsReplacedSynonymFor;\r
- }\r
- \r
- /**\r
- * If true, all basionym relationships in which this name has a basionym/original name will \r
- * be removed.<BR>\r
- * Exceptions will not be thrown due to existing hasBasionym relationships.<BR>\r
- * This value is neglected if {@link #isRemoveAllNameRelationships()} is true.<BR>\r
- * Default value is <code>true</code>.<BR>\r
- * @see #setIgnoreHasBasionym(boolean)\r
- * @return the ignoreHasBasionym\r
- */\r
- public boolean isIgnoreHasBasionym() {\r
- return ignoreHasBasionym;\r
- }\r
-\r
- /**\r
- * @see #isIgnoreHasBasionym()\r
- * @param ignoreHasBasionym the ignoreHasBasionym to set\r
- */\r
- public void setIgnoreHasBasionym(boolean ignoreHasBasionym) {\r
- this.ignoreHasBasionym = ignoreHasBasionym;\r
- }\r
-\r
- /**\r
- * If true, all replaced synonym relationships in which this name has a \r
- * replaced synonym will be removed.<BR>\r
- * Exceptions will not be thrown due to existing hasReplacedSynonym relationships.<BR>\r
- * This value is neglected if {@link #isRemoveAllNameRelationships()} is true.<BR>\r
- * Default value is <code>true</code>.<BR>\r
- * @see #setIgnoreHasBasionym(boolean)\r
- * @return the ignoreHasReplacedSynonym\r
- */\r
- public boolean isIgnoreHasReplacedSynonym() {\r
- return ignoreHasReplacedSynonym;\r
- }\r
-\r
- /**\r
- * @see #isIgnoreHasReplacedSynonym()\r
- * @param ignoreHasReplacedSynonym the ignoreHasReplacedSynonym to set\r
- */\r
- public void setIgnoreHasReplacedSynonym(boolean ignoreHasReplacedSynonym) {\r
- this.ignoreHasReplacedSynonym = ignoreHasReplacedSynonym;\r
- }\r
- \r
-}\r
import org.apache.log4j.Logger;\r
import org.junit.Assert;\r
import org.junit.Test;\r
+import org.unitils.dbunit.annotation.DataSet;\r
import org.unitils.spring.annotation.SpringBeanByType;\r
\r
+import eu.etaxonomy.cdm.model.common.CdmBase;\r
import eu.etaxonomy.cdm.model.name.BotanicalName;\r
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;\r
+import eu.etaxonomy.cdm.model.name.NameRelationship;\r
+import eu.etaxonomy.cdm.model.name.NameRelationshipType;\r
import eu.etaxonomy.cdm.model.name.Rank;\r
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
import eu.etaxonomy.cdm.model.reference.Reference;\r
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;\r
import eu.etaxonomy.cdm.model.taxon.Synonym;\r
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;\r
import eu.etaxonomy.cdm.model.taxon.Taxon;\r
import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
-import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;\r
+import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;\r
\r
/**\r
* @author a.mueller\r
*\r
*/\r
-public class TaxonServiceImplTest extends CdmIntegrationTest {\r
+public class TaxonServiceImplTest extends CdmTransactionalIntegrationTest {\r
private static final Logger logger = Logger.getLogger(TaxonServiceImplTest.class);\r
\r
@SpringBeanByType\r
\r
}\r
\r
+ @Test\r
+ @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")\r
+ public final void testDeleteSynonymSynonymTaxonBoolean(){\r
+ final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",\r
+ "SynonymRelationship","SynonymRelationship_AUD",\r
+ "HomotypicalGroup","HomotypicalGroup_AUD"};\r
+// BotanicalName taxonName1 = BotanicalName.NewInstance(Rank.SPECIES());\r
+// taxonName1.setTitleCache("TaxonName1",true);\r
+// BotanicalName taxonName2 = BotanicalName.NewInstance(Rank.SPECIES());\r
+// taxonName2.setTitleCache("TaxonName2",true);\r
+// BotanicalName synonymName1 = BotanicalName.NewInstance(Rank.SPECIES());\r
+// synonymName1.setTitleCache("Synonym1",true);\r
+// BotanicalName synonymName2 = BotanicalName.NewInstance(Rank.SPECIES());\r
+// synonymName2.setTitleCache("Synonym2",true);\r
+// \r
+// Reference<?> sec = null;\r
+// Taxon taxon1 = Taxon.NewInstance(taxonName1, sec);\r
+// Taxon taxon2 = Taxon.NewInstance(taxonName2, sec);\r
+// Synonym synonym1 = Synonym.NewInstance(synonymName1, sec);\r
+// Synonym synonym2 = Synonym.NewInstance(synonymName2, sec);\r
+// \r
+// SynonymRelationship rel1 = taxon1.addSynonym(synonym1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());\r
+// SynonymRelationship rel = taxon2.addSynonym(synonym1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());\r
+// rel.setProParte(true);\r
+// rel1.setProParte(true);\r
+// \r
+// service.save(taxon1);\r
+// service.save(synonym2);\r
+// \r
+// this.setComplete();\r
+// this.endTransaction();\r
+// \r
+// \r
+ int nSynonyms = service.count(Synonym.class);\r
+ Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);\r
+ int nNames = nameService.count(TaxonNameBase.class);\r
+ Assert.assertEquals("There should be 4 names in the database", 4, nNames);\r
+ \r
+// UUID uuidTaxon1=UUID.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");\r
+// UUID uuidTaxon2=UUID.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");\r
+ UUID uuidSynonym1=UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");\r
+// UUID uuidSynonym2=UUID.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");\r
+ \r
+ Synonym synonym1 = (Synonym)service.load(uuidSynonym1);\r
+ service.deleteSynonym(synonym1, null, true);\r
+ \r
+ this.commitAndStartNewTransaction(tableNames);\r
+ \r
+ nSynonyms = service.count(Synonym.class);\r
+ Assert.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms);\r
+ nNames = nameService.count(TaxonNameBase.class);\r
+ Assert.assertEquals("There should be 3 names left in the database", 3, nNames);\r
+ int nRelations = service.countAllRelationships();\r
+ Assert.assertEquals("There should be no relationship left in the database", 0, nRelations);\r
+ }\r
+ \r
+ @Test\r
+ @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")\r
+ public final void testDeleteSynonymSynonymTaxonBooleanRelToOneTaxon(){\r
+ final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",\r
+ "SynonymRelationship","SynonymRelationship_AUD",\r
+ "HomotypicalGroup","HomotypicalGroup_AUD"};\r
+ \r
+ int nSynonyms = service.count(Synonym.class);\r
+ Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);\r
+ int nNames = nameService.count(TaxonNameBase.class);\r
+ Assert.assertEquals("There should be 4 names in the database", 4, nNames);\r
+ \r
+ UUID uuidTaxon1=UUID.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");\r
+ UUID uuidTaxon2=UUID.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");\r
+ UUID uuidSynonym1=UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");\r
+// UUID uuidSynonym2=UUID.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");\r
+ \r
+ Taxon taxon2 = (Taxon)service.load(uuidTaxon2);\r
+ Synonym synonym1 = (Synonym)service.load(uuidSynonym1);\r
+ \r
+ taxon2.removeSynonym(synonym1, false);\r
+ service.saveOrUpdate(taxon2);\r
+ this.setComplete();\r
+ this.endTransaction();\r
+ \r
+ this.startNewTransaction();\r
+ nSynonyms = service.count(Synonym.class);\r
+ Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);\r
+ nNames = nameService.count(TaxonNameBase.class);\r
+ Assert.assertEquals("There should be 4 names in the database", 4, nNames);\r
+ int nRelations = service.countAllRelationships();\r
+ Assert.assertEquals("There should be 1 relationship left in the database", 1, nRelations);\r
+\r
+ taxon2 = (Taxon)service.load(uuidTaxon2);\r
+ synonym1 = (Synonym)service.load(uuidSynonym1);\r
+ \r
+ service.deleteSynonym(synonym1, null, true);\r
+ \r
+ this.commitAndStartNewTransaction(tableNames);\r
+ \r
+ nSynonyms = service.count(Synonym.class);\r
+ Assert.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms);\r
+ nNames = nameService.count(TaxonNameBase.class);\r
+ Assert.assertEquals("There should be 3 names left in the database", 3, nNames);\r
+ nRelations = service.countAllRelationships();\r
+ Assert.assertEquals("There should be no relationship left in the database", 0, nRelations);\r
+\r
+ }\r
+ \r
+ @Test\r
+ @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")\r
+ public final void testDeleteSynonymSynonymTaxonBooleanDeleteOneTaxon(){\r
+ final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",\r
+ "SynonymRelationship","SynonymRelationship_AUD",\r
+ "HomotypicalGroup","HomotypicalGroup_AUD"};\r
+ \r
+ int nSynonyms = service.count(Synonym.class);\r
+ Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);\r
+ int nNames = nameService.count(TaxonNameBase.class);\r
+ Assert.assertEquals("There should be 4 names in the database", 4, nNames);\r
+ \r
+ UUID uuidTaxon1=UUID.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");\r
+ UUID uuidTaxon2=UUID.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");\r
+ UUID uuidSynonym1=UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");\r
+ UUID uuidSynonym2=UUID.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");\r
+ \r
+ Taxon taxon1 = (Taxon)service.load(uuidTaxon1);\r
+ Taxon taxon2 = (Taxon)service.load(uuidTaxon2);\r
+ Synonym synonym1 = (Synonym)service.load(uuidSynonym1);\r
+ \r
+ service.deleteSynonym(synonym1, taxon1, true);\r
+ \r
+ this.commitAndStartNewTransaction(tableNames);\r
+ \r
+ nSynonyms = service.count(Synonym.class);\r
+ Assert.assertEquals("There should still be 2 synonyms left in the database (synonym is related to taxon2)", 2, nSynonyms);\r
+ nNames = nameService.count(TaxonNameBase.class);\r
+ Assert.assertEquals("There should be 4 names left in the database (name not deleted as synonym was not deleted)", 4, nNames);\r
+ int nRelations = service.countAllRelationships();\r
+ Assert.assertEquals("There should be 1 relationship left in the database", 1, nRelations);\r
+ \r
+ }\r
+ \r
+ @Test\r
+ @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")\r
+ public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedName(){\r
+ final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",\r
+ "SynonymRelationship","SynonymRelationship_AUD",\r
+ "HomotypicalGroup","HomotypicalGroup_AUD"};\r
+ \r
+ int nSynonyms = service.count(Synonym.class);\r
+ Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);\r
+ int nNames = nameService.count(TaxonNameBase.class);\r
+ Assert.assertEquals("There should be 4 names in the database", 4, nNames);\r
+ \r
+ UUID uuidTaxon1=UUID.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");\r
+ UUID uuidTaxon2=UUID.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");\r
+ UUID uuidSynonym1=UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");\r
+ UUID uuidSynonym2=UUID.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");\r
+ UUID uuidSynonymName2=UUID.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");\r
+ \r
+ Synonym synonym1 = (Synonym)service.load(uuidSynonym1);\r
+ TaxonNameBase name2 = (TaxonNameBase)nameService.load(uuidSynonymName2);\r
+ synonym1.getName().addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null);\r
+ \r
+ service.deleteSynonym(synonym1, null, true);\r
+ \r
+ this.commitAndStartNewTransaction(tableNames);\r
+ \r
+ nSynonyms = service.count(Synonym.class);\r
+ Assert.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms);\r
+ nNames = nameService.count(TaxonNameBase.class);\r
+ Assert.assertEquals("There should be 4 names left in the database (name is related to synonymName2)", 4, nNames);\r
+ int nRelations = service.countAllRelationships();\r
+ //may change with better implementation of countAllRelationships (see #2653)\r
+ Assert.assertEquals("There should be 1 relationship left in the database (the name relationship)", 1, nRelations);\r
+\r
+ //clean up database\r
+ name2 = (TaxonNameBase)nameService.load(uuidSynonymName2);\r
+ NameRelationship rel = CdmBase.deproxy(name2.getNameRelations().iterator().next(), NameRelationship.class);\r
+ name2.removeNameRelationship(rel);\r
+ nameService.save(name2);\r
+ this.setComplete();\r
+ this.endTransaction();\r
+ \r
+ }\r
+\r
+ @Test\r
+ @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")\r
+ public final void testDeleteSynonymSynonymTaxonBooleanWithRollback(){\r
+ final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",\r
+ "SynonymRelationship","SynonymRelationship_AUD",\r
+ "HomotypicalGroup","HomotypicalGroup_AUD"};\r
+ \r
+ int nSynonyms = service.count(Synonym.class);\r
+ Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);\r
+ int nNames = nameService.count(TaxonNameBase.class);\r
+ Assert.assertEquals("There should be 4 names in the database", 4, nNames);\r
+ int nRelations = service.countAllRelationships();\r
+ //may change with better implementation of countAllRelationships (see #2653)\r
+ Assert.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations);\r
+ \r
+ UUID uuidSynonym1=UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");\r
+ UUID uuidSynonymName2=UUID.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");\r
+ \r
+ Synonym synonym1 = (Synonym)service.load(uuidSynonym1);\r
+ TaxonNameBase name2 = (TaxonNameBase)nameService.load(uuidSynonymName2);\r
+ synonym1.getName().addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null);\r
+ \r
+ service.deleteSynonym(synonym1, null, true);\r
+ \r
+ this.rollback();\r
+// printDataSet(System.out, tableNames);\r
+ this.startNewTransaction();\r
+ \r
+ nSynonyms = service.count(Synonym.class);\r
+ Assert.assertEquals("There should still be 2 synonyms left in the database", 2, nSynonyms);\r
+ nNames = nameService.count(TaxonNameBase.class);\r
+ Assert.assertEquals("There should be 4 names left in the database", 4, nNames);\r
+ nRelations = service.countAllRelationships();\r
+ //may change with better implementation of countAllRelationships (see #2653)\r
+ Assert.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations);\r
+ \r
+ }\r
+ \r
+ @Test\r
+ @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")\r
+ public final void testDeleteSynonymSynonymTaxonBooleanWithoutTransaction(){\r
+ final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonNameBase","TaxonNameBase_AUD",\r
+ "SynonymRelationship","SynonymRelationship_AUD",\r
+ "HomotypicalGroup","HomotypicalGroup_AUD"};\r
+ \r
+ int nSynonyms = service.count(Synonym.class);\r
+ Assert.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms);\r
+ int nNames = nameService.count(TaxonNameBase.class);\r
+ Assert.assertEquals("There should be 4 names in the database", 4, nNames);\r
+ int nRelations = service.countAllRelationships();\r
+ //may change with better implementation of countAllRelationships (see #2653)\r
+ Assert.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations);\r
+ \r
+ UUID uuidSynonym1=UUID.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");\r
+ UUID uuidSynonymName2=UUID.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");\r
+ \r
+ Synonym synonym1 = (Synonym)service.load(uuidSynonym1);\r
+ TaxonNameBase name2 = (TaxonNameBase)nameService.load(uuidSynonymName2);\r
+ synonym1.getName().addRelationshipFromName(name2, NameRelationshipType.LATER_HOMONYM(), null);\r
+ \r
+ service.saveOrUpdate(synonym1);\r
+ \r
+ this.setComplete();\r
+ this.endTransaction();\r
+ \r
+ printDataSet(System.out, tableNames);\r
+ \r
+ //out of wrapping transaction\r
+ service.deleteSynonym(synonym1, null, true);\r
+ \r
+ this.startNewTransaction();\r
+ \r
+ nSynonyms = service.count(Synonym.class);\r
+ Assert.assertEquals("There should still be 1 synonyms left in the database. The rollback on name delete should not lead to rollback in synonym delete.", 1, nSynonyms);\r
+ nNames = nameService.count(TaxonNameBase.class);\r
+ Assert.assertEquals("There should be 4 names left in the database", 4, nNames);\r
+ nRelations = service.countAllRelationships();\r
+ //may change with better implementation of countAllRelationships (see #2653)\r
+ Assert.assertEquals("There should be 1 name relationship and no synonym relationship in the database", 1, nRelations);\r
+ \r
+ }\r
\r
}\r