commit b9e54ec85d3579fa046662aa954f050de401963b
Author: Andreas Müller <a.mueller@bgbm.org>
Date:   Wed Jul 6 14:57:05 2016 +0200

    #5960 Use abbrevTitle for reference parsing

diff --git a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImpl.java b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImpl.java
index d87dea8424..1e1f251820 100644
--- a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImpl.java
+++ b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImpl.java
@@ -296,10 +296,10 @@ public class NonViralNameParserImpl extends NonViralNameParserImplRegExBase impl
 
 		//don't parse if name can't be separated
 		nameToBeFilled.addParsingProblem(ParserProblem.NameReferenceSeparation);
-		nameToBeFilled.setTitleCache(fullReferenceString,true);
-		nameToBeFilled.setFullTitleCache(fullReferenceString,true);
+		nameToBeFilled.setTitleCache(fullReferenceString, true);
+		nameToBeFilled.setFullTitleCache(fullReferenceString, true);
 		// FIXME Quick fix, otherwise search would not deliver results for unparsable names
-		nameToBeFilled.setNameCache(fullReferenceString,true);
+		nameToBeFilled.setNameCache(fullReferenceString, true);
 		// END
 		nameToBeFilled.setProblemStarts(start);
 		nameToBeFilled.setProblemEnds(fullReferenceString.length());
@@ -484,6 +484,7 @@ public class NonViralNameParserImpl extends NonViralNameParserImplRegExBase impl
 		//parse title and author
 		ref = parseReferenceTitle(strReference, yearPart, isInReference);
 		if (ref.hasProblem()){
+		    //we need to protect both caches otherwise the titleCache is incorrectly build from atomized parts
 			ref.setTitleCache( (isInReference ? "in ":"") +  originalStrReference, true);
 			ref.setAbbrevTitleCache( (isInReference ? "in ":"") +  originalStrReference, true);
 		}
@@ -497,12 +498,12 @@ public class NonViralNameParserImpl extends NonViralNameParserImplRegExBase impl
 	 * @param strReference
 	 * @return
 	 */
-	private INomenclaturalReference makeDetailYearUnparsable(NonViralName<?> nameToBeFilled, String strReference) {
-		INomenclaturalReference ref;
-		//ref = Generic.NewInstance();
+	private Reference makeDetailYearUnparsable(NonViralName<?> nameToBeFilled, String strReference) {
+		Reference ref;
 
 		ref = ReferenceFactory.newGeneric();
-		ref.setTitleCache(strReference,true);
+		ref.setTitleCache(strReference, true);
+        ref.setAbbrevTitleCache(strReference, true);
 		ref.setProblemEnds(strReference.length());
 		ref.addParsingProblem(ParserProblem.CheckDetailOrYear);
 		nameToBeFilled.addParsingProblem(ParserProblem.CheckDetailOrYear);
@@ -563,8 +564,9 @@ public class NonViralNameParserImpl extends NonViralNameParserImplRegExBase impl
 	}
 
 	private void makeUnparsableRefTitle(INomenclaturalReference result, String reference){
-		result.setTitleCache(reference,true);
-		result.setAbbrevTitleCache(reference,true);
+	    //need to set both to protected otherwise titleCache is created from atomized parts
+	    result.setTitleCache(reference, true);
+		result.setAbbrevTitleCache(reference, true);
 		result.addParsingProblem(ParserProblem.UnparsableReferenceTitle);
 	}
 
@@ -661,7 +663,7 @@ public class NonViralNameParserImpl extends NonViralNameParserImplRegExBase impl
 		IBook result = ReferenceFactory.newBook();
 		reference = makeEdition(result, reference);
 		reference = makeVolume(result, reference);
-		result.setTitle(reference);
+		result.setAbbrevTitle(reference);
 		return result;
 	}
 
@@ -672,7 +674,7 @@ public class NonViralNameParserImpl extends NonViralNameParserImplRegExBase impl
 		Reference result = ReferenceFactory.newArticle();
 		reference = makeVolume(result, reference);
 		Reference inJournal = ReferenceFactory.newJournal();
-		inJournal.setTitle(reference);
+		inJournal.setAbbrevTitle(reference);
 		result.setInReference(inJournal);
 		return result;
 	}
@@ -695,7 +697,8 @@ public class NonViralNameParserImpl extends NonViralNameParserImplRegExBase impl
 		}else{
 			logger.warn("Unexpected non matching book section author part");
 			//TODO do we want to record a 'problem' here?
-			result.setTitleCache(reference,true);
+			result.setTitleCache(reference, true);
+			result.setAbbrevTitleCache(reference, true);
 		}
 
 		return result;
@@ -895,7 +898,7 @@ public class NonViralNameParserImpl extends NonViralNameParserImplRegExBase impl
 					authorString = fullNameString.substring(epi[0].length()+ 1 + epi[1].length() +1 + epi[2].length() + 1 + epi[3].length());
 				}else{
 					nameToBeFilled.addParsingProblem(ParserProblem.OldInfraSpeciesNotSupported);
-					nameToBeFilled.setTitleCache(fullNameString,true);
+					nameToBeFilled.setTitleCache(fullNameString, true);
 					// FIXME Quick fix, otherwise search would not deilver results for unparsable names
 					nameToBeFilled.setNameCache(fullNameString,true);
 					// END
@@ -956,7 +959,7 @@ public class NonViralNameParserImpl extends NonViralNameParserImplRegExBase impl
 		    //none
 			else{
 				nameToBeFilled.addParsingProblem(ParserProblem.UnparsableNamePart);
-				nameToBeFilled.setTitleCache(fullNameString,true);
+				nameToBeFilled.setTitleCache(fullNameString, true);
 				// FIXME Quick fix, otherwise search would not deilver results for unparsable names
 				nameToBeFilled.setNameCache(fullNameString, true);
 				// END
@@ -980,7 +983,7 @@ public class NonViralNameParserImpl extends NonViralNameParserImplRegExBase impl
 		    return;
 		} catch (UnknownCdmTypeException e) {
 			nameToBeFilled.addParsingProblem(ParserProblem.RankNotSupported);
-			nameToBeFilled.setTitleCache(fullNameString,true);
+			nameToBeFilled.setTitleCache(fullNameString, true);
 			// FIXME Quick fix, otherwise search would not deilver results for unparsable names
 			nameToBeFilled.setNameCache(fullNameString,true);
 			// END
diff --git a/cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImplTest.java b/cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImplTest.java
index f97cef8eb0..d499cda3f1 100644
--- a/cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImplTest.java
+++ b/cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImplTest.java
@@ -412,8 +412,8 @@ public class NonViralNameParserImplTest {
         IReference nomRef = multipleAuthorRefName.getNomenclaturalReference();
         Assert.assertNotNull("nomRef must have inRef", ((Reference)nomRef).getInReference());
         Reference inRef = ((Reference)nomRef).getInReference();
-        String title = inRef.getTitle();
-        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", title);
+        String abbrevTitle = inRef.getAbbrevTitle();
+        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", abbrevTitle);
         assertTrue(inRef.getAuthorship() instanceof Team);
         Team team = (Team)inRef.getAuthorship();
         assertEquals(3, team.getTeamMembers().size());
@@ -438,8 +438,8 @@ public class NonViralNameParserImplTest {
 	    nomRef = multipleAuthorName.getNomenclaturalReference();
         Assert.assertNotNull("nomRef must have inRef", ((Reference)nomRef).getInReference());
         inRef = ((Reference)nomRef).getInReference();
-        title = inRef.getTitle();
-        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", title);
+        abbrevTitle = inRef.getAbbrevTitle();
+        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", abbrevTitle);
         assertTrue(inRef.getAuthorship() instanceof Person);
         Person person = (Person)inRef.getAuthorship();
         assertEquals("Book author should be L.", "L.", person.getNomenclaturalTitle());
@@ -454,8 +454,8 @@ public class NonViralNameParserImplTest {
 	    assertEquals("Second team member should be Aber", "Aber", team.getTeamMembers().get(1).getTitleCache());
 	    nomRef = multipleAuthorName.getNomenclaturalReference();
         Assert.assertNull("nomRef must not have inRef as it is a book itself", ((Reference)nomRef).getInReference());
-        title = nomRef.getTitle();
-        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", title);
+        abbrevTitle = nomRef.getAbbrevTitle();
+        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", abbrevTitle);
         assertTrue(nomRef.getAuthorship() instanceof Team);
         team = (Team)nomRef.getAuthorship();
         assertEquals(3, team.getTeamMembers().size());
@@ -997,7 +997,7 @@ public class NonViralNameParserImplTest {
 		assertNotNull(inBook.getAuthorship());
 		assertEquals("Otto", inBook.getAuthorship().getTitleCache());
 		assertEquals("Otto, Sp. Pl. 4(6)", inBook.getTitleCache());
-		assertEquals("Sp. Pl.", inBook.getTitle());
+		assertEquals("Sp. Pl.", inBook.getAbbrevTitle());
 		assertEquals("4(6)", inBook.getVolume());
 		assertTrue("Name author and reference author should be the same", name2.getCombinationAuthorship() == ((Reference)name2.getNomenclaturalReference()).getAuthorship());
 
@@ -1015,7 +1015,7 @@ public class NonViralNameParserImplTest {
 		assertNotNull(journal);
 		//assertEquals("Sp. Pl. 4(6)", inBook.getTitleCache());
 		assertEquals("Sp. Pl.",((Reference) journal).getTitleCache());
-		assertEquals("Sp. Pl.", journal.getTitle());
+		assertEquals("Sp. Pl.", journal.getAbbrevTitle());
 		assertEquals("4(6)",((IArticle)ref).getVolume());
 		assertTrue("Name author and reference author should be the same", name3.getCombinationAuthorship() == name3.getNomenclaturalReference().getAuthorship());
 
@@ -1047,7 +1047,7 @@ public class NonViralNameParserImplTest {
 		journal = ((IArticle)ref).getInJournal();
 		assertNotNull(journal);
 		assertEquals(journalTitle, ((Reference) journal).getTitleCache());
-		assertEquals(journalTitle, journal.getTitle());
+		assertEquals(journalTitle, journal.getAbbrevTitle());
 		assertEquals("4(6)", ((IArticle)ref).getVolume());
 
 		//Zoo name
@@ -1460,7 +1460,7 @@ public class NonViralNameParserImplTest {
 		assertNotNull(name.getNomenclaturalReference());
 		INomenclaturalReference ref = name.getNomenclaturalReference();
 		assertEquals("1987", ref.getYear());
-		assertEquals("Sp. Pl.", ref.getTitle());
+		assertEquals("Sp. Pl.", ref.getAbbrevTitle());
 	}
 
 
@@ -1930,7 +1930,7 @@ public class NonViralNameParserImplTest {
         assertEquals( "Nees & Mart.", combinationAuthor.getNomenclaturalTitle());
         nomRef = (Reference)name.getNomenclaturalReference();
         assertEquals(ReferenceType.Article, nomRef.getType());
-        assertEquals("Nova Acta Phys.-Med. Acad. Caes.\u2013Leop. Nat. Cur.", nomRef.getInReference().getTitle());
+        assertEquals("Nova Acta Phys.-Med. Acad. Caes.\u2013Leop. Nat. Cur.", nomRef.getInReference().getAbbrevTitle());
         assertEquals("12", nomRef.getVolume());
         assertEquals("14", name.getNomenclaturalMicroReference());
         assertEquals("1824", nomRef.getYear());
