fix #8315: fix Parser in TaxEditor to avoid inReference change of existing references
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / parser / ParseHandler.java
index ece1e56aa30f15f4e41891354d1b0e0977e3004c..5d6c5388aea5ba48936d686c1dd9d4349bcf3c03 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());
                        }