commit 5e97e1b299c10bca15dec48ef79aaa9743bd5f0f
Author: Andreas Müller <a.mueller@bgbm.org>
Date:   Mon Aug 22 18:28:23 2011 +0000

    bugfix for #2558 (concurrent modification in TaxonNodeServiceImpl.makeTaxonNodeASynonymOfAnotherTaxonNode(...) )

diff --git a/.gitattributes b/.gitattributes
index 362f1821cb..edaf47ade3 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1879,7 +1879,7 @@ cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/IdentifiableServ
 cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/MediaDaoImplTest.xml -text
 cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/OregonScientificDS6639-DSC_0307-small.jpg -text
 cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/OregonScientificDS6639-DSC_0307-small.tif -text
-cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest -text
+cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest.xml -text
 cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/TaxonServiceImplTest.xml -text
 cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/TaxonServiceSearchTest.xml -text
 cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/UserServiceImplTest.xml -text
diff --git a/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImpl.java b/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImpl.java
index 0d0f80dab1..8ef79274b6 100644
--- a/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImpl.java
+++ b/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImpl.java
@@ -46,8 +46,7 @@ import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao;
 @Service
 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
 public class TaxonNodeServiceImpl extends AnnotatableServiceBase<TaxonNode, ITaxonNodeDao> implements ITaxonNodeService{
-	private static final Logger logger = Logger
-			.getLogger(TaxonNodeServiceImpl.class);
+	private static final Logger logger = Logger.getLogger(TaxonNodeServiceImpl.class);
 
 	@Autowired
 	private BeanInitializer defaultBeanInitializer;
@@ -146,8 +145,11 @@ public class TaxonNodeServiceImpl extends AnnotatableServiceBase<TaxonNode, ITax
 		}
 		
 		//Move descriptions to new taxon
-		for(TaxonDescription description : oldTaxon.getDescriptions()){
-			description.setTitleCache("Description copied from former accepted taxon: " + oldTaxon.getTitleCache() + "(Old title: " + description.getTitleCache()  + ")");
+		List<TaxonDescription> descriptions = new ArrayList<TaxonDescription>( oldTaxon.getDescriptions()); //to avoid concurrent modification errors (newAcceptedTaxon.addDescription() modifies also oldtaxon.descritpions()) 
+		for(TaxonDescription description : descriptions){
+			String message = "Description copied from former accepted taxon: %s (Old title: %s)"; 
+			message = String.format(message, oldTaxon.getTitleCache(), description.getTitleCache());
+			description.setTitleCache(message, true);
 			newAcceptedTaxon.addDescription(description);
 		}
 				
diff --git a/cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest.java b/cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest.java
index 56458fc2fa..3a349303a2 100644
--- a/cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest.java
+++ b/cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest.java
@@ -16,6 +16,7 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.unitils.dbunit.annotation.DataSet;
 import org.unitils.spring.annotation.SpringBeanByType;
 
 import eu.etaxonomy.cdm.model.reference.Reference;
@@ -31,6 +32,7 @@ import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
  * @created Dec 16, 2010
  * @version 1.0
  */
+
 public class TaxonNodeServiceImplTest extends CdmIntegrationTest{
 
 	@SpringBeanByType
@@ -53,7 +55,7 @@ public class TaxonNodeServiceImplTest extends CdmIntegrationTest{
 	private Taxon t2;
 	private Synonym s1;
 	private SynonymRelationshipType synonymRelationshipType;
-	private Reference reference;
+	private Reference<?> reference;
 	private String referenceDetail;
 	private Classification classification;
 	private TaxonNode node2;
@@ -64,32 +66,36 @@ public class TaxonNodeServiceImplTest extends CdmIntegrationTest{
 	 */
 	@Before
 	public void setUp() throws Exception {
-		
-		classification = classificationService.load(classificationUuid);
-		
-		node1 = taxonNodeService.load(node1Uuid);
-		
-		node2 = taxonNodeService.load(node2Uuid);
-		
-		reference = referenceService.load(referenceUuid);
-		
-		// referencing
-		synonymRelationshipType = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF();
-		referenceDetail = "test"; 
 	}
 	
 	/**
 	 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonNodeServiceImpl#makeTaxonNodeASynonymOfAnotherTaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
 	 */
 	@Test
-	@Ignore
+	@DataSet
 	public final void testMakeTaxonNodeASynonymOfAnotherTaxonNode() {
+		classification = classificationService.load(classificationUuid);
+		node1 = taxonNodeService.load(node1Uuid);
+		node2 = taxonNodeService.load(node2Uuid);
+		reference = referenceService.load(referenceUuid);
+		synonymRelationshipType = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF();
+		referenceDetail = "test"; 
+
+		//
+		//TODO
+		
+
 		// descriptions
+		t1 = node1.getTaxon();
+		t2 = node2.getTaxon();
+		Assert.assertEquals(2, t1.getDescriptions().size());
+		Assert.assertTrue(t2.getSynonyms().isEmpty());
+		Assert.assertTrue(t2.getDescriptions().size() == 0);
 		
 		taxonNodeService.makeTaxonNodeASynonymOfAnotherTaxonNode(node1, node2, synonymRelationshipType, reference, referenceDetail);
 		
 		Assert.assertFalse(t2.getSynonyms().isEmpty());
-		Assert.assertTrue(t2.getDescriptions().size() == 2);
+		Assert.assertEquals(2, t2.getDescriptions().size());
 		
 	}
 
diff --git a/cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest b/cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest
deleted file mode 100644
index 1c5c112fe9..0000000000
--- a/cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="dataset.xsd">
-    <REFERENCE ID="1" UUID="de7d1205-291f-45d9-9059-ca83fc7ade14"/>
-    <CLASSIFICATION ID="1" UUID="6c2bc8d9-ee62-4222-be89-4a8e31770878"/>
-    <TAXONNODE ID="1" CLASSIFICATION_ID="1"/>
-    <CLASSIFICATION_TAXONNODE CLASSIFICATION_ID="1" ROOTNODES_ID="1" />
-    <TAXONNODE ID="2" TAXON_ID="1" PARENT_ID="1" CLASSIFICATION_ID="1" UUID="484a1a77-689c-44be-8e65-347d835f47e8"/>
-    <TAXONNODE ID="3" TAXON_ID="2" PARENT_ID="1" CLASSIFICATION_ID="1" UUID="2d41f0c2-b785-4f73-a436-cc2d5e93cc5b"/>
-    <TAXONBASE DTYPE="Taxon" ID="1" NAME_ID="1" UUID="55c3e41a-c629-40e6-aa6a-ff274ac6ddb1"/>
-    <TAXONBASE DTYPE="Taxon" ID="2"  NAME_ID="2" UUID="2659a7e0-ff35-4ee4-8493-b453756ab955"/>
-    <TAXONBASE DTYPE="Synonym" ID="3" NAME_ID="3" UUID="3034249e-9491-4439-bcb6-9c7d68e29bce"/>
-    <TAXONBASE DTYPE="Synonym" ID="4" NAME_ID="4" UUID="ac6c5bb1-d36d-4068-af7c-4f0bb009880d"/>
-    <TAXONNAMEBASE DTYPE="BotanicalName" ID="1" UUID="54a1d7f9-79ab-4fb3-bff5-152e1046cf75"/>
-    <TAXONNAMEBASE DTYPE="BotanicalName" ID="2" UUID="e7f50b04-9648-479b-bc8a-ffebf295dce9"/>
-    <TAXONNAMEBASE DTYPE="BotanicalName" ID="3" UUID="c0439dd6-8d2b-4428-86f4-37f4a90d4583"/>
-    <TAXONNAMEBASE DTYPE="BotanicalName" ID="4" UUID="6a5774bd-c8aa-42dc-91dd-d62d27e7ea2a"/>
-    <SYNONYMRELATIONSHIP ID="1" UUID="cc769418-3ba4-4c1f-a4cb-b18bf42ec8e9" CITATION_ID="1" RELATEDFROM_ID="3" RELATEDTO_ID="1"/>
-    <DESCRIPTIONBASE ID="1" UUID="56cf0c8c-18e3-4bea-9525-b9804cf57c5d" DTYPE="TaxonDescription"/>
-</dataset>
\ No newline at end of file
diff --git a/cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest.xml b/cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest.xml
new file mode 100644
index 0000000000..492bbbb660
--- /dev/null
+++ b/cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest.xml
@@ -0,0 +1,27 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="dataset.xsd">
+    <REFERENCE ID="1" UUID="de7d1205-291f-45d9-9059-ca83fc7ade14" protectedTitleCache="false" refType="5" nomenclaturallyRelevant="false" parsingProblem="0" problemEnds="-1" problemStarts="-1" />
+    <CLASSIFICATION ID="1" UUID="6c2bc8d9-ee62-4222-be89-4a8e31770878"  protectedTitleCache="true"/>
+    <TAXONNODE ID="1" CLASSIFICATION_ID="1" countChildren="2"/>
+    <CLASSIFICATION_TAXONNODE CLASSIFICATION_ID="1" ROOTNODES_ID="1"/>
+    <TAXONNODE ID="2" TAXON_ID="1" PARENT_ID="1" CLASSIFICATION_ID="1" UUID="484a1a77-689c-44be-8e65-347d835f47e8"  countChildren="0"/>
+    <TAXONNODE ID="3" TAXON_ID="2" PARENT_ID="1" CLASSIFICATION_ID="1" UUID="2d41f0c2-b785-4f73-a436-cc2d5e93cc5b"  countChildren="0"/>
+    <TAXONBASE DTYPE="Taxon" ID="1" NAME_ID="1" UUID="55c3e41a-c629-40e6-aa6a-ff274ac6ddb1" protectedTitleCache="false" doubtful="false" useNameCache="false" excluded="false" taxonStatusUnknown="false" unplaced="false" taxonomicChildrenCount="0"/>
+    <TAXONBASE DTYPE="Taxon" ID="2"  NAME_ID="2" UUID="2659a7e0-ff35-4ee4-8493-b453756ab955" protectedTitleCache="false" doubtful="false" useNameCache="false" excluded="false" taxonStatusUnknown="false" unplaced="false" taxonomicChildrenCount="0"/>
+    <TAXONBASE DTYPE="Synonym" ID="3" NAME_ID="3" UUID="3034249e-9491-4439-bcb6-9c7d68e29bce" protectedTitleCache="false" doubtful="false" useNameCache="false"/>
+    <TAXONBASE DTYPE="Synonym" ID="4" NAME_ID="4" UUID="ac6c5bb1-d36d-4068-af7c-4f0bb009880d" protectedTitleCache="false" doubtful="false" useNameCache="false"/>
+    <TAXONNAMEBASE DTYPE="BotanicalName" ID="1" UUID="54a1d7f9-79ab-4fb3-bff5-152e1046cf75" protectedTitleCache="false" parsingProblem="0" problemEnds="-1" problemStarts="-1" protectedFullTitleCache="false" protectedAuthorshipCache="false" protectedNameCache="false" hybridFormula="false" monomHybrid="false" binomHybrid="false" trinomHybrid="false" anamorphic="false"/>
+    <TAXONNAMEBASE DTYPE="BotanicalName" ID="2" UUID="e7f50b04-9648-479b-bc8a-ffebf295dce9" protectedTitleCache="false" parsingProblem="0" problemEnds="-1" problemStarts="-1" protectedFullTitleCache="false" protectedAuthorshipCache="false" protectedNameCache="false" hybridFormula="false" monomHybrid="false" binomHybrid="false" trinomHybrid="false" anamorphic="false"/>
+    <TAXONNAMEBASE DTYPE="BotanicalName" ID="3" UUID="c0439dd6-8d2b-4428-86f4-37f4a90d4583" protectedTitleCache="false" parsingProblem="0" problemEnds="-1" problemStarts="-1" protectedFullTitleCache="false" protectedAuthorshipCache="false" protectedNameCache="false" hybridFormula="false" monomHybrid="false" binomHybrid="false" trinomHybrid="false" anamorphic="false"/>
+    <TAXONNAMEBASE DTYPE="BotanicalName" ID="4" UUID="6a5774bd-c8aa-42dc-91dd-d62d27e7ea2a" protectedTitleCache="false" parsingProblem="0" problemEnds="-1" problemStarts="-1" protectedFullTitleCache="false" protectedAuthorshipCache="false" protectedNameCache="false" hybridFormula="false" monomHybrid="false" binomHybrid="false" trinomHybrid="false" anamorphic="false"/>
+    <SYNONYMRELATIONSHIP ID="1" UUID="cc769418-3ba4-4c1f-a4cb-b18bf42ec8e9" CITATION_ID="1" RELATEDFROM_ID="3" RELATEDTO_ID="1" DOUBTFUL="false" PARTIAL="false" PROPARTE="false"/>
+    <DESCRIPTIONBASE ID="1" UUID="56cf0c8c-18e3-4bea-9525-b9804cf57c5d" DTYPE="TaxonDescription" TAXON_ID="1" protectedTitleCache="false" imageGallery="false" />
+    <DESCRIPTIONBASE ID="2" UUID="36af5c7c-18e3-4bec-6535-a9804cf57c6e" DTYPE="TaxonDescription" TAXON_ID="1" protectedTitleCache="false" imageGallery="false" />
+    <DESCRIPTIONELEMENTBASE DTYPE="TextData" ID="1" indescription_id="1" orderRelevant="false"/>
+    <DESCRIPTIONELEMENTBASE DTYPE="TextData" ID="2" indescription_id="2" orderRelevant="false"/>
+    <DESCRIPTIONELEMENTBASE_LANGUAGESTRING descriptionElementBase_id="1" multilanguagetext_id="1" multilanguagetext_mapkey_id="124" />
+    <DESCRIPTIONELEMENTBASE_LANGUAGESTRING descriptionElementBase_id="2" multilanguagetext_id="2" multilanguagetext_mapkey_id="124" />
+    <LANGUAGESTRING ID="1" TEXT="Any text"/>
+    <LANGUAGESTRING ID="2" TEXT="Second text"/>
+    
+</dataset>
\ No newline at end of file
