fix #8315: fix Parser in TaxEditor to avoid inReference change of existing references hotfix/5.7.3
authorKatja Luther <k.luther@bgbm.org>
Wed, 29 May 2019 07:19:22 +0000 (09:19 +0200)
committerKatja Luther <k.luther@bgbm.org>
Tue, 4 Jun 2019 09:38:45 +0000 (11:38 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/parser/ParseHandler.java

index ece1e56..5d6c538 100644 (file)
@@ -61,7 +61,7 @@ public class ParseHandler{
                if(name == null){
                        this.name = nonViralNameParser.getNonViralNameInstance("", PreferencesUtil.getPreferredNomenclaturalCode());
                }else{
-                       this.name = (INonViralName) HibernateProxyHelper.deproxy(name);
+                       this.name = HibernateProxyHelper.deproxy(name);
                }
        }
 
@@ -102,7 +102,7 @@ public class ParseHandler{
        public static TaxonName parseName(String unparsedNameString, Rank rank){
                INonViralName name = nonViralNameParser.parseFullName(unparsedNameString,
                                PreferencesUtil.getPreferredNomenclaturalCode(), rank);
-               
+
                return (TaxonName)name;
        }
 
@@ -180,9 +180,9 @@ public class ParseHandler{
 
                resolveDuplicateReferences(name, matchMatrix);
 
-               if(matchMatrix.duplicateInReferences != null) {
-            resolveDuplicateInReferences(name, matchMatrix);
-        }
+//             if(matchMatrix.duplicateInReferences != null) {
+//            resolveDuplicateInReferences(name, matchMatrix);
+//        }
        }
 
 
@@ -212,13 +212,17 @@ public class ParseHandler{
                        INomenclaturalReference duplicate = matchMatrix.duplicateReferences.iterator().next();
                        name.setNomenclaturalReference(duplicate);
                }
+               //if reference is new but the in reference is already in db
+               if (matchMatrix.duplicateReferences.size() == 0 && name.getNomenclaturalReference().getInReference() != null && matchMatrix.duplicateInReferences.size() > 0){
+                   resolveDuplicateInReferences(name, matchMatrix);
+               }
        }
 
        /**
         * @param name The name to resolve duplicates for.
         */
-       private void resolveDuplicateInReferences(INonViralName name, MatchMatrix matchMatrix) {
-               Reference reference = (Reference) HibernateProxyHelper.deproxy(name.getNomenclaturalReference());
+       private void resolveDuplicateInReferences(INonViralName name, MatchMatrix matchMatrix) {
+               Reference reference = HibernateProxyHelper.deproxy(name.getNomenclaturalReference());
 
                if(matchMatrix.duplicateInReferences.size() > 0){
                        Reference inReference = (Reference) matchMatrix.duplicateInReferences.iterator().next();
@@ -237,7 +241,7 @@ public class ParseHandler{
 
                if(matchMatrix.duplicateCombinationAuthorships.size() > 0){
                        name.setCombinationAuthorship(matchMatrix.duplicateCombinationAuthorships.iterator().next());
-                       Reference reference = (Reference) name.getNomenclaturalReference();
+                       Reference reference = name.getNomenclaturalReference();
                        if(reference != null){
                                reference.setAuthorship(matchMatrix.duplicateCombinationAuthorships.iterator().next());
                        }