commit 9ec434f6b3262d99f5f7de343b143ed0f06a79d5
Author: Andreas Müller <a.mueller@bgbm.org>
Date:   Wed Aug 12 15:03:21 2020 +0200

    cleanup

diff --git a/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java b/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
index c3983160c0..ac30060871 100644
--- a/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
+++ b/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
@@ -188,10 +188,6 @@ public class TaxonServiceImpl
 
 // ****************************** METHODS ********************************/
 
-
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public TaxonBase load(UUID uuid, boolean includeUnpublished, List<String> propertyPaths) {
         return dao.load(uuid, includeUnpublished, propertyPaths);
@@ -238,7 +234,6 @@ public class TaxonServiceImpl
             newTaxon.removeTaxonRelation(taxonRelationship);
         }
 
-
         for(TaxonRelationship taxonRelationship : acceptedTaxon.getTaxonRelations()){
             Taxon fromTaxon = HibernateProxyHelper.deproxy(taxonRelationship.getFromTaxon());
             Taxon toTaxon = HibernateProxyHelper.deproxy(taxonRelationship.getToTaxon());
@@ -262,7 +257,6 @@ public class TaxonServiceImpl
             taxonRelationship.setFromTaxon(null);
         }
 
-
         //Move descriptions to new taxon
         List<TaxonDescription> descriptions = new ArrayList<TaxonDescription>( newTaxon.getDescriptions()); //to avoid concurrent modification errors (newAcceptedTaxon.addDescription() modifies also oldtaxon.descritpions())
         for(TaxonDescription description : descriptions){
@@ -281,7 +275,7 @@ public class TaxonServiceImpl
 //            //oldTaxon.removeDescription(description, false);
  //           newTaxon.addDescription(description);
         }
-        List<TaxonNode> nodes = new ArrayList(acceptedTaxon.getTaxonNodes());
+        List<TaxonNode> nodes = new ArrayList<>(acceptedTaxon.getTaxonNodes());
         for (TaxonNode node: nodes){
             node = HibernateProxyHelper.deproxy(node, TaxonNode.class);
             TaxonNode parent = node.getParent();
@@ -315,11 +309,8 @@ public class TaxonServiceImpl
         }
         result.includeResult(deleteResult);
 		return result;
-
-
     }
 
-
     @Override
     @Transactional(readOnly = false)
     public UpdateResult changeSynonymToAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon, boolean deleteSynonym) {
@@ -388,9 +379,6 @@ public class TaxonServiceImpl
         return result;
     }
 
-
-
-
     @Override
     @Transactional(readOnly = false)
     public UpdateResult changeSynonymToRelatedTaxon(UUID synonymUuid,
@@ -486,7 +474,6 @@ public class TaxonServiceImpl
             SynonymType relType = isHomotypicToTaxon? SynonymType.HOMOTYPIC_SYNONYM_OF() : SynonymType.HETEROTYPIC_SYNONYM_OF();
             targetTaxon.addSynonym(synonym, relType);
         }
-
     }
 
     @Override
@@ -504,7 +491,6 @@ public class TaxonServiceImpl
         this.dao = dao;
     }
 
-
     @Override
     public <T extends TaxonBase> Pager<T> findTaxaByName(Class<T> clazz, String uninomial,	String infragenericEpithet, String specificEpithet,
             String infraspecificEpithet, String authorshipCache, Rank rank, Integer pageSize,Integer pageNumber, List<String> propertyPaths) {
@@ -656,7 +642,6 @@ public class TaxonServiceImpl
         return relatedTaxa;
     }
 
-
     /**
      * Recursively collect related taxa for the given <code>taxon</code> . The returned list will also include the
      *  <code>taxon</code> supplied as parameter.
@@ -737,7 +722,6 @@ public class TaxonServiceImpl
         taxon = (Taxon)dao.load(taxon.getUuid(), propertyPaths);
         HomotypicGroupTaxonComparator comparator = new HomotypicGroupTaxonComparator(taxon);
 
-
         //homotypic
         result.add(taxon.getHomotypicSynonymsByHomotypicGroup(comparator));
 
@@ -748,7 +732,6 @@ public class TaxonServiceImpl
         }
 
         return result;
-
     }
 
     @Override
@@ -786,6 +769,7 @@ public class TaxonServiceImpl
     @Override
     public Pager<IdentifiableEntity> findTaxaAndNames(IFindTaxaAndNamesConfigurator configurator) {
 
+        @SuppressWarnings("rawtypes")
         List<IdentifiableEntity> results = new ArrayList<>();
         long numberOfResults = 0; // overall number of results (as opposed to number of results per page)
         List<TaxonBase> taxa = null;
@@ -814,7 +798,7 @@ public class TaxonServiceImpl
                     configurator.getMatchMode(), configurator.getNamedAreas(), configurator.isIncludeUnpublished(),
                     configurator.getOrder(), configurator.getPageSize(), configurator.getPageNumber(), propertyPath);
             }
-       }
+        }
 
         if (logger.isDebugEnabled()) { logger.debug(numberTaxaResults + " matching taxa counted"); }
 
@@ -913,6 +897,7 @@ public class TaxonServiceImpl
 
         if(includeOccurrences != null && includeOccurrences) {
             logger.trace("listMedia() - includeOccurrences");
+            @SuppressWarnings("rawtypes")
             Set<SpecimenOrObservationBase> specimensOrObservations = new HashSet<>();
             // --- Specimens
             for (Taxon t : taxa) {
@@ -968,7 +953,6 @@ public class TaxonServiceImpl
             }
         }
 
-
         logger.trace("listMedia() - initialize");
         beanInitializer.initializeAll(taxonMedia, propertyPath);
 
@@ -992,8 +976,6 @@ public class TaxonServiceImpl
         return this.dao.countSynonyms(onlyAttachedToTaxon);
     }
 
-
-
     @Override
     @Transactional(readOnly=false)
     public DeleteResult deleteTaxon(UUID taxonUUID, TaxonDeletionConfigurator config, UUID classificationUuid)  {
@@ -1076,8 +1058,6 @@ public class TaxonServiceImpl
                         break;
                     }
                     removeDescriptions.add(desc);
-
-
                 }
                 if (result.isOk()){
                     for (TaxonDescription desc: removeDescriptions){
@@ -1089,101 +1069,99 @@ public class TaxonServiceImpl
                 }
             }
 
-
-         if (! config.isDeleteTaxonNodes() || (!config.isDeleteInAllClassifications() && classification == null && taxon.getTaxonNodes().size() > 1)){
-             result.addException(new Exception( "Taxon can't be deleted as it is used in more than one classification."));
-         }else{
-             if (taxon.getTaxonNodes().size() != 0){
-                Set<TaxonNode> nodes = taxon.getTaxonNodes();
-                Iterator<TaxonNode> iterator = nodes.iterator();
-                TaxonNode node = null;
-                boolean deleteChildren;
-                if (config.getTaxonNodeConfig().getChildHandling().equals(ChildHandling.DELETE)){
-                    deleteChildren = true;
-                }else {
-                    deleteChildren = false;
-                }
-                boolean success = true;
-                if (!config.isDeleteInAllClassifications() && !(classification == null)){
-                    while (iterator.hasNext()){
-                        node = iterator.next();
-                        if (node.getClassification().equals(classification)){
-                            break;
-                        }
-                        node = null;
-                    }
-                    if (node != null){
-                        HibernateProxyHelper.deproxy(node, TaxonNode.class);
-                        success =taxon.removeTaxonNode(node, deleteChildren);
-                        nodeService.delete(node);
-                        result.addDeletedObject(node);
-                    } else {
-                    	result.setError();
-                    	result.addException(new Exception("The taxon can not be deleted because it is not used in defined classification."));
+             if (! config.isDeleteTaxonNodes() || (!config.isDeleteInAllClassifications() && classification == null && taxon.getTaxonNodes().size() > 1)){
+                 result.addException(new Exception( "Taxon can't be deleted as it is used in more than one classification."));
+             }else{
+                 if (taxon.getTaxonNodes().size() != 0){
+                    Set<TaxonNode> nodes = taxon.getTaxonNodes();
+                    Iterator<TaxonNode> iterator = nodes.iterator();
+                    TaxonNode node = null;
+                    boolean deleteChildren;
+                    if (config.getTaxonNodeConfig().getChildHandling().equals(ChildHandling.DELETE)){
+                        deleteChildren = true;
+                    }else {
+                        deleteChildren = false;
                     }
-                } else if (config.isDeleteInAllClassifications()){
-                    List<TaxonNode> nodesList = new ArrayList<>();
-                    nodesList.addAll(taxon.getTaxonNodes());
-                    for (ITaxonTreeNode treeNode: nodesList){
-                        TaxonNode taxonNode = (TaxonNode) treeNode;
-                        if(!deleteChildren){
-                            Object[] childNodes = taxonNode.getChildNodes().toArray();
-                            for (Object childNode: childNodes){
-                                TaxonNode childNodeCast = (TaxonNode) childNode;
-                                taxonNode.getParent().addChildNode(childNodeCast, childNodeCast.getReference(), childNodeCast.getMicroReference());
+                    boolean success = true;
+                    if (!config.isDeleteInAllClassifications() && !(classification == null)){
+                        while (iterator.hasNext()){
+                            node = iterator.next();
+                            if (node.getClassification().equals(classification)){
+                                break;
+                            }
+                            node = null;
+                        }
+                        if (node != null){
+                            HibernateProxyHelper.deproxy(node, TaxonNode.class);
+                            success =taxon.removeTaxonNode(node, deleteChildren);
+                            nodeService.delete(node);
+                            result.addDeletedObject(node);
+                        } else {
+                        	result.setError();
+                        	result.addException(new Exception("The taxon can not be deleted because it is not used in defined classification."));
+                        }
+                    } else if (config.isDeleteInAllClassifications()){
+                        List<TaxonNode> nodesList = new ArrayList<>();
+                        nodesList.addAll(taxon.getTaxonNodes());
+                        for (ITaxonTreeNode treeNode: nodesList){
+                            TaxonNode taxonNode = (TaxonNode) treeNode;
+                            if(!deleteChildren){
+                                Object[] childNodes = taxonNode.getChildNodes().toArray();
+                                for (Object childNode: childNodes){
+                                    TaxonNode childNodeCast = (TaxonNode) childNode;
+                                    taxonNode.getParent().addChildNode(childNodeCast, childNodeCast.getReference(), childNodeCast.getMicroReference());
+                                }
                             }
                         }
+                        config.getTaxonNodeConfig().setDeleteElement(false);
+                        DeleteResult resultNodes = nodeService.deleteTaxonNodes(nodesList, config);
+                        if (!resultNodes.isOk()){
+                        	result.addExceptions(resultNodes.getExceptions());
+                        	result.setStatus(resultNodes.getStatus());
+                        } else {
+                            result.addUpdatedObjects(resultNodes.getUpdatedObjects());
+                        }
                     }
-                    config.getTaxonNodeConfig().setDeleteElement(false);
-                    DeleteResult resultNodes = nodeService.deleteTaxonNodes(nodesList, config);
-                    if (!resultNodes.isOk()){
-                    	result.addExceptions(resultNodes.getExceptions());
-                    	result.setStatus(resultNodes.getStatus());
-                    } else {
-                        result.addUpdatedObjects(resultNodes.getUpdatedObjects());
+                    if (!success){
+                        result.setError();
+                        result.addException(new Exception("The taxon can not be deleted because the taxon node can not be removed."));
                     }
                 }
-                if (!success){
-                    result.setError();
-                    result.addException(new Exception("The taxon can not be deleted because the taxon node can not be removed."));
-                }
-            }
-         }
-         TaxonName name = taxon.getName();
-         taxon.setName(null);
-         this.saveOrUpdate(taxon);
-
-         if ((taxon.getTaxonNodes() == null || taxon.getTaxonNodes().size()== 0)  && result.isOk()){
-             try{
-                 dao.delete(taxon);
-                 result.addDeletedObject(taxon);
-             }catch(Exception e){
-                 result.addException(e);
-                 result.setError();
              }
-         } else {
-             result.setError();
-             result.addException(new Exception("The Taxon can't be deleted because it is used in a classification."));
+             TaxonName name = taxon.getName();
+             taxon.setName(null);
+             this.saveOrUpdate(taxon);
+
+             if ((taxon.getTaxonNodes() == null || taxon.getTaxonNodes().size()== 0)  && result.isOk()){
+                 try{
+                     dao.delete(taxon);
+                     result.addDeletedObject(taxon);
+                 }catch(Exception e){
+                     result.addException(e);
+                     result.setError();
+                 }
+             } else {
+                 result.setError();
+                 result.addException(new Exception("The Taxon can't be deleted because it is used in a classification."));
 
-         }
-         //TaxonName
-         if (config.isDeleteNameIfPossible() && result.isOk()){
-            DeleteResult nameResult = new DeleteResult();
-            //remove name if possible (and required)
-            if (name != null ){
-                nameResult = nameService.delete(name.getUuid(), config.getNameDeletionConfig());
-            }
-            if (nameResult.isError() || nameResult.isAbort()){
-                result.addRelatedObject(name);
-                result.addExceptions(nameResult.getExceptions());
-            }else{
-                result.includeResult(nameResult);
-            }
-         }
+             }
+             //TaxonName
+             if (config.isDeleteNameIfPossible() && result.isOk()){
+                 DeleteResult nameResult = new DeleteResult();
+                 //remove name if possible (and required)
+                 if (name != null ){
+                     nameResult = nameService.delete(name.getUuid(), config.getNameDeletionConfig());
+                 }
+                 if (nameResult.isError() || nameResult.isAbort()){
+                     result.addRelatedObject(name);
+                     result.addExceptions(nameResult.getExceptions());
+                 }else{
+                     result.includeResult(nameResult);
+                 }
+             }
        }
 
        return result;
-
     }
 
     @Override
@@ -1197,10 +1175,8 @@ public class TaxonServiceImpl
     @Transactional(readOnly = false)
     public DeleteResult deleteSynonym(UUID synonymUuid, SynonymDeletionConfigurator config) {
         return deleteSynonym((Synonym)dao.load(synonymUuid), config);
-
     }
 
-
     @Override
     @Transactional(readOnly = false)
     public DeleteResult deleteSynonym(Synonym synonym, SynonymDeletionConfigurator config) {
@@ -1251,7 +1227,6 @@ public class TaxonServiceImpl
                         result.addDeletedObject(name);
                     }
             }
-
         }
         return result;
     }
@@ -1261,7 +1236,6 @@ public class TaxonServiceImpl
         return this.dao.findIdenticalNames(sourceRefUuids, propertyPaths);
     }
 
-
     @Override
     public Taxon findBestMatchingTaxon(String taxonName) {
         MatchingTaxonConfigurator config = MatchingTaxonConfigurator.NewInstance();
@@ -1307,7 +1281,6 @@ public class TaxonServiceImpl
                         countEqualCandidates = 1;
                         continue;
                     }
-
                 }else{  //not Taxon.class
                     continue;
                 }
@@ -1324,7 +1297,6 @@ public class TaxonServiceImpl
                 }
             }
 
-
             // 2. search for synonyms
             if (config.isIncludeSynonyms()){
                 List<TaxonBase> synonymList = dao.findByNameTitleCache(false, true, config.isIncludeUnpublished(),
@@ -1506,6 +1478,7 @@ public class TaxonServiceImpl
 
         // ---  initialize taxa, thighlight matches ....
         ISearchResultBuilder searchResultBuilder = new SearchResultBuilder(luceneSearch, luceneSearch.getQuery());
+        @SuppressWarnings("rawtypes")
         List<SearchResult<TaxonBase>> searchResults = searchResultBuilder.createResultSet(
                 topDocsResultSet, luceneSearch.getHighlightFields(), dao, idFieldMap, propertyPaths);
 
@@ -1513,8 +1486,6 @@ public class TaxonServiceImpl
         return new DefaultPagerImpl<>(pageNumber, totalHits, pageSize, searchResults);
     }
 
-
-
     @Transactional(readOnly = true)
     @Override
     public <S extends TaxonBase> Pager<S> findByTitleWithRestrictions(Class<S> clazz, String queryString, MatchMode matchmode, List<Restriction<?>> restrictions, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
@@ -1531,7 +1502,6 @@ public class TaxonServiceImpl
          return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
     }
 
-
     @Transactional(readOnly = true)
     @Override
     public <S extends TaxonBase> Pager<S> findByTitle(Class<S> clazz, String queryString,MatchMode matchmode, List<Criterion> criteria, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
@@ -1553,7 +1523,6 @@ public class TaxonServiceImpl
         return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
     }
 
-
     @Override
     public Pager<SearchResult<TaxonBase>> findByDistribution(List<NamedArea> areaFilter, List<PresenceAbsenceTerm> statusFilter,
             Classification classification, TaxonNode subtree,
@@ -1780,7 +1749,6 @@ public class TaxonServiceImpl
 //        SortField[] sortFields = new SortField[]{SortField.FIELD_SCORE, new SortField("id", SortField.STRING, false)};
 //        SortField[] sortFields = new SortField[]{new SortField(NomenclaturalSortOrderBrigde.NAME_SORT_FIELD_NAME, SortField.STRING, false)};
 
-
         boolean addDistributionFilter = namedAreas != null && namedAreas.size() > 0;
 
         List<LuceneSearch> luceneSearches = new ArrayList<>();
@@ -1984,7 +1952,6 @@ public class TaxonServiceImpl
             }
         }
 
-
         // search by pro parte synonyms
         if(searchModes.contains(TaxaAndNamesSearchMode.doSynonyms)) {
             //TODO merge with misapplied name search once #7487 is fixed
@@ -2006,12 +1973,9 @@ public class TaxonServiceImpl
             }
         }//end pro parte synonyms
 
-
-
         LuceneMultiSearch multiSearch = new LuceneMultiSearch(luceneIndexToolProvider,
                 luceneSearches.toArray(new LuceneSearch[luceneSearches.size()]));
 
-
         if(addDistributionFilter){
 
             // B)
@@ -2153,7 +2117,6 @@ public class TaxonServiceImpl
             Classification classification, TaxonNode subtree, List<Feature> features, List<Language> languages,
             boolean highlightFragments, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws IOException, LuceneParseException {
 
-
         LuceneSearch luceneSearch = prepareByDescriptionElementFullTextSearch(clazz, queryString, classification, subtree, features, languages, highlightFragments);
 
         // --- execute search
@@ -2177,10 +2140,8 @@ public class TaxonServiceImpl
 
         int totalHits = topDocsResultSet != null ? topDocsResultSet.totalGroupCount : 0;
         return new DefaultPagerImpl<>(pageNumber, Long.valueOf(totalHits), pageSize, searchResults);
-
     }
 
-
     @Override
     public Pager<SearchResult<TaxonBase>> findByEverythingFullText(String queryString,
             Classification classification, TaxonNode subtree, boolean includeUnpublished, List<Language> languages, boolean highlightFragments,
@@ -2216,10 +2177,8 @@ public class TaxonServiceImpl
 
         int totalHits = topDocsResultSet != null ? topDocsResultSet.totalGroupCount : 0;
         return new DefaultPagerImpl<>(pageNumber, Long.valueOf(totalHits), pageSize, searchResults);
-
     }
 
-
     /**
      * @param clazz
      * @param queryString
@@ -2331,7 +2290,6 @@ public class TaxonServiceImpl
     @Override
     public List<Synonym> createInferredSynonyms(Taxon taxon, Classification classification, SynonymType type, boolean doWithMisappliedNames){
 
-
         List <Synonym> inferredSynonyms = new ArrayList<>();
         List<Synonym> inferredSynonymsToBeRemoved = new ArrayList<>();
 
@@ -2428,140 +2386,87 @@ public class TaxonServiceImpl
                             }
 
                             if (!taxonNames.isEmpty()){
-                            List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);
-                            IZoologicalName name;
-                            if (!synNotInCDM.isEmpty()){
-                                inferredSynonymsToBeRemoved.clear();
-
-                                for (Synonym syn :inferredSynonyms){
-                                    name = getZoologicalName(syn.getName().getUuid(), zooHashMap);
-                                    if (!synNotInCDM.contains(name.getNameCache())){
-                                        inferredSynonymsToBeRemoved.add(syn);
+                                List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);
+                                if (!synNotInCDM.isEmpty()){
+                                    inferredSynonymsToBeRemoved.clear();
+
+                                    for (Synonym syn :inferredSynonyms){
+                                        IZoologicalName name = getZoologicalName(syn.getName().getUuid(), zooHashMap);
+                                        if (!synNotInCDM.contains(name.getNameCache())){
+                                            inferredSynonymsToBeRemoved.add(syn);
+                                        }
                                     }
-                                }
 
-                                // Remove identified Synonyms from inferredSynonyms
-                                for (Synonym synonym : inferredSynonymsToBeRemoved) {
-                                    inferredSynonyms.remove(synonym);
+                                    // Remove identified Synonyms from inferredSynonyms
+                                    for (Synonym synonym : inferredSynonymsToBeRemoved) {
+                                        inferredSynonyms.remove(synonym);
+                                    }
                                 }
                             }
-                        }
-
-                    }else if (type.equals(SynonymType.INFERRED_GENUS_OF())){
 
-                        for (Synonym synonymRelationOfTaxon:synonymsOfTaxon){
+                        }else if (type.equals(SynonymType.INFERRED_GENUS_OF())){
 
-                            inferredGenus = createInferredGenus(taxon,
-                                    zooHashMap, taxonName, epithetOfTaxon,
-                                    genusOfTaxon, taxonNames, zooParentName, synonymRelationOfTaxon);
-
-                            inferredSynonyms.add(inferredGenus);
-                            zooHashMap.put(inferredGenus.getName().getUuid(), inferredGenus.getName());
-                            taxonNames.add(inferredGenus.getName().getNameCache());
-                        }
-
-                        if (doWithMisappliedNames){
+                            for (Synonym synonymRelationOfTaxon:synonymsOfTaxon){
 
-                            for (TaxonRelationship taxonRelationship: taxonRelListTaxon){
-                                Taxon misappliedName = taxonRelationship.getFromTaxon();
-                                inferredGenus = createInferredGenus(taxon, zooHashMap, taxonName, infraspecificEpithetOfTaxon, genusOfTaxon, taxonNames, zooParentName,  misappliedName);
+                                inferredGenus = createInferredGenus(taxon,
+                                        zooHashMap, taxonName, epithetOfTaxon,
+                                        genusOfTaxon, taxonNames, zooParentName, synonymRelationOfTaxon);
 
                                 inferredSynonyms.add(inferredGenus);
                                 zooHashMap.put(inferredGenus.getName().getUuid(), inferredGenus.getName());
-                                 taxonNames.add(inferredGenus.getName().getNameCache());
+                                taxonNames.add(inferredGenus.getName().getNameCache());
                             }
-                        }
-
 
-                        if (!taxonNames.isEmpty()){
-                            List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);
-                            IZoologicalName name;
-                            if (!synNotInCDM.isEmpty()){
-                                inferredSynonymsToBeRemoved.clear();
+                            if (doWithMisappliedNames){
 
-                                for (Synonym syn :inferredSynonyms){
-                                    name = getZoologicalName(syn.getName().getUuid(), zooHashMap);
-                                    if (!synNotInCDM.contains(name.getNameCache())){
-                                        inferredSynonymsToBeRemoved.add(syn);
-                                    }
-                                }
+                                for (TaxonRelationship taxonRelationship: taxonRelListTaxon){
+                                    Taxon misappliedName = taxonRelationship.getFromTaxon();
+                                    inferredGenus = createInferredGenus(taxon, zooHashMap, taxonName, infraspecificEpithetOfTaxon, genusOfTaxon, taxonNames, zooParentName,  misappliedName);
 
-                                // Remove identified Synonyms from inferredSynonyms
-                                for (Synonym synonym : inferredSynonymsToBeRemoved) {
-                                    inferredSynonyms.remove(synonym);
+                                    inferredSynonyms.add(inferredGenus);
+                                    zooHashMap.put(inferredGenus.getName().getUuid(), inferredGenus.getName());
+                                     taxonNames.add(inferredGenus.getName().getNameCache());
                                 }
                             }
-                        }
-
-                    }else if (type.equals(SynonymType.POTENTIAL_COMBINATION_OF())){
-
-                        Reference sourceReference = null; // TODO: Determination of sourceReference is redundant
-                        //for all synonyms of the parent...
-                        for (Synonym synonymRelationOfParent:synonyMsOfParent){
-                            TaxonName synName;
-                            HibernateProxyHelper.deproxy(synonymRelationOfParent);
-
-                            synName = synonymRelationOfParent.getName();
-
-                            // Set the sourceReference
-                            sourceReference = synonymRelationOfParent.getSec();
-
-                            // Determine the idInSource
-                            String idInSourceParent = getIdInSource(synonymRelationOfParent);
-
-                            IZoologicalName parentSynZooName = getZoologicalName(synName.getUuid(), zooHashMap);
-                            String synParentGenus = parentSynZooName.getGenusOrUninomial();
-                            String synParentInfragenericName = null;
-                            String synParentSpecificEpithet = null;
-
-                            if (parentSynZooName.isInfraGeneric()){
-                                synParentInfragenericName = parentSynZooName.getInfraGenericEpithet();
-                            }
-                            if (parentSynZooName.isSpecies()){
-                                synParentSpecificEpithet = parentSynZooName.getSpecificEpithet();
-                            }
-
-                           /* if (synGenusName != null && !synonymsGenus.containsKey(synGenusName)){
-                                synonymsGenus.put(synGenusName, idInSource);
-                            }*/
 
-                            //for all synonyms of the taxon
 
-                            for (Synonym synonymRelationOfTaxon:synonymsOfTaxon){
-
-                                IZoologicalName zooSynName = getZoologicalName(synonymRelationOfTaxon.getName().getUuid(), zooHashMap);
-                                potentialCombination = createPotentialCombination(idInSourceParent, parentSynZooName, zooSynName,
-                                        synParentGenus,
-                                        synParentInfragenericName,
-                                        synParentSpecificEpithet, synonymRelationOfTaxon, zooHashMap);
+                            if (!taxonNames.isEmpty()){
+                                List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);
+                                IZoologicalName name;
+                                if (!synNotInCDM.isEmpty()){
+                                    inferredSynonymsToBeRemoved.clear();
 
-                                taxon.addSynonym(potentialCombination, SynonymType.POTENTIAL_COMBINATION_OF());
-                                inferredSynonyms.add(potentialCombination);
-                                zooHashMap.put(potentialCombination.getName().getUuid(), potentialCombination.getName());
-                                 taxonNames.add(potentialCombination.getName().getNameCache());
+                                    for (Synonym syn :inferredSynonyms){
+                                        name = getZoologicalName(syn.getName().getUuid(), zooHashMap);
+                                        if (!synNotInCDM.contains(name.getNameCache())){
+                                            inferredSynonymsToBeRemoved.add(syn);
+                                        }
+                                    }
 
+                                    // Remove identified Synonyms from inferredSynonyms
+                                    for (Synonym synonym : inferredSynonymsToBeRemoved) {
+                                        inferredSynonyms.remove(synonym);
+                                    }
+                                }
                             }
 
-                        }
-
-                        if (doWithMisappliedNames){
+                        }else if (type.equals(SynonymType.POTENTIAL_COMBINATION_OF())){
 
-                            for (TaxonRelationship parentRelationship: taxonRelListParent){
-
-                                TaxonName misappliedParentName;
-
-                                Taxon misappliedParent = parentRelationship.getFromTaxon();
-                                misappliedParentName = misappliedParent.getName();
+                            Reference sourceReference = null; // TODO: Determination of sourceReference is redundant
+                            //for all synonyms of the parent...
+                            for (Synonym synonymRelationOfParent:synonyMsOfParent){
+                                TaxonName synName;
+                                HibernateProxyHelper.deproxy(synonymRelationOfParent);
 
-                                HibernateProxyHelper.deproxy(misappliedParent);
+                                synName = synonymRelationOfParent.getName();
 
                                 // Set the sourceReference
-                                sourceReference = misappliedParent.getSec();
+                                sourceReference = synonymRelationOfParent.getSec();
 
                                 // Determine the idInSource
-                                String idInSourceParent = getIdInSource(misappliedParent);
+                                String idInSourceParent = getIdInSource(synonymRelationOfParent);
 
-                                IZoologicalName parentSynZooName = getZoologicalName(misappliedParentName.getUuid(), zooHashMap);
+                                IZoologicalName parentSynZooName = getZoologicalName(synName.getUuid(), zooHashMap);
                                 String synParentGenus = parentSynZooName.getGenusOrUninomial();
                                 String synParentInfragenericName = null;
                                 String synParentSpecificEpithet = null;
@@ -2573,16 +2478,19 @@ public class TaxonServiceImpl
                                     synParentSpecificEpithet = parentSynZooName.getSpecificEpithet();
                                 }
 
+                               /* if (synGenusName != null && !synonymsGenus.containsKey(synGenusName)){
+                                    synonymsGenus.put(synGenusName, idInSource);
+                                }*/
 
-                                for (TaxonRelationship taxonRelationship: taxonRelListTaxon){
-                                    Taxon misappliedName = taxonRelationship.getFromTaxon();
-                                    IZoologicalName zooMisappliedName = getZoologicalName(misappliedName.getName().getUuid(), zooHashMap);
-                                    potentialCombination = createPotentialCombination(
-                                            idInSourceParent, parentSynZooName, zooMisappliedName,
+                                //for all synonyms of the taxon
+
+                                for (Synonym synonymRelationOfTaxon:synonymsOfTaxon){
+
+                                    IZoologicalName zooSynName = getZoologicalName(synonymRelationOfTaxon.getName().getUuid(), zooHashMap);
+                                    potentialCombination = createPotentialCombination(idInSourceParent, parentSynZooName, zooSynName,
                                             synParentGenus,
                                             synParentInfragenericName,
-                                            synParentSpecificEpithet, misappliedName, zooHashMap);
-
+                                            synParentSpecificEpithet, synonymRelationOfTaxon, zooHashMap);
 
                                     taxon.addSynonym(potentialCombination, SynonymType.POTENTIAL_COMBINATION_OF());
                                     inferredSynonyms.add(potentialCombination);
@@ -2590,29 +2498,74 @@ public class TaxonServiceImpl
                                      taxonNames.add(potentialCombination.getName().getNameCache());
                                 }
                             }
-                        }
 
-                        if (!taxonNames.isEmpty()){
-                            List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);
-                            IZoologicalName name;
-                            if (!synNotInCDM.isEmpty()){
-                                inferredSynonymsToBeRemoved.clear();
-                                for (Synonym syn :inferredSynonyms){
-                                    try{
-                                        name = syn.getName();
-                                    }catch (ClassCastException e){
-                                        name = getZoologicalName(syn.getName().getUuid(), zooHashMap);
+                            if (doWithMisappliedNames){
+
+                                for (TaxonRelationship parentRelationship: taxonRelListParent){
+
+                                    TaxonName misappliedParentName;
+
+                                    Taxon misappliedParent = parentRelationship.getFromTaxon();
+                                    misappliedParentName = misappliedParent.getName();
+
+                                    HibernateProxyHelper.deproxy(misappliedParent);
+
+                                    // Set the sourceReference
+                                    sourceReference = misappliedParent.getSec();
+
+                                    // Determine the idInSource
+                                    String idInSourceParent = getIdInSource(misappliedParent);
+
+                                    IZoologicalName parentSynZooName = getZoologicalName(misappliedParentName.getUuid(), zooHashMap);
+                                    String synParentGenus = parentSynZooName.getGenusOrUninomial();
+                                    String synParentInfragenericName = null;
+                                    String synParentSpecificEpithet = null;
+
+                                    if (parentSynZooName.isInfraGeneric()){
+                                        synParentInfragenericName = parentSynZooName.getInfraGenericEpithet();
                                     }
-                                    if (!synNotInCDM.contains(name.getNameCache())){
-                                        inferredSynonymsToBeRemoved.add(syn);
+                                    if (parentSynZooName.isSpecies()){
+                                        synParentSpecificEpithet = parentSynZooName.getSpecificEpithet();
+                                    }
+
+                                    for (TaxonRelationship taxonRelationship: taxonRelListTaxon){
+                                        Taxon misappliedName = taxonRelationship.getFromTaxon();
+                                        IZoologicalName zooMisappliedName = getZoologicalName(misappliedName.getName().getUuid(), zooHashMap);
+                                        potentialCombination = createPotentialCombination(
+                                                idInSourceParent, parentSynZooName, zooMisappliedName,
+                                                synParentGenus,
+                                                synParentInfragenericName,
+                                                synParentSpecificEpithet, misappliedName, zooHashMap);
+
+                                        taxon.addSynonym(potentialCombination, SynonymType.POTENTIAL_COMBINATION_OF());
+                                        inferredSynonyms.add(potentialCombination);
+                                        zooHashMap.put(potentialCombination.getName().getUuid(), potentialCombination.getName());
+                                         taxonNames.add(potentialCombination.getName().getNameCache());
+                                    }
+                                }
+                            }
+
+                            if (!taxonNames.isEmpty()){
+                                List<String> synNotInCDM = dao.taxaByNameNotInDB(taxonNames);
+                                IZoologicalName name;
+                                if (!synNotInCDM.isEmpty()){
+                                    inferredSynonymsToBeRemoved.clear();
+                                    for (Synonym syn :inferredSynonyms){
+                                        try{
+                                            name = syn.getName();
+                                        }catch (ClassCastException e){
+                                            name = getZoologicalName(syn.getName().getUuid(), zooHashMap);
+                                        }
+                                        if (!synNotInCDM.contains(name.getNameCache())){
+                                            inferredSynonymsToBeRemoved.add(syn);
+                                        }
+                                     }
+                                    // Remove identified Synonyms from inferredSynonyms
+                                    for (Synonym synonym : inferredSynonymsToBeRemoved) {
+                                        inferredSynonyms.remove(synonym);
                                     }
-                                 }
-                                // Remove identified Synonyms from inferredSynonyms
-                                for (Synonym synonym : inferredSynonymsToBeRemoved) {
-                                    inferredSynonyms.remove(synonym);
                                 }
                             }
-                         }
                         }
                     }else {
                         logger.info("The synonym type is not defined.");
@@ -2620,7 +2573,6 @@ public class TaxonServiceImpl
                     }
                 }
             }
-
         }
 
         return inferredSynonyms;
@@ -2676,7 +2628,6 @@ public class TaxonServiceImpl
             inferredSynName.setInfraGenericEpithet(synParentInfragenericName);
         }
 
-
         potentialCombination = Synonym.NewInstance(inferredSynName, null);
 
         // Set the sourceReference
@@ -2719,14 +2670,13 @@ public class TaxonServiceImpl
         synName = syn.getName();
         IZoologicalName synZooName = getZoologicalName(synName.getUuid(), zooHashMap);
         String synSpeciesEpithetName = synZooName.getSpecificEpithet();
-                     /* if (synonymsEpithet != null && !synonymsEpithet.contains(synSpeciesEpithetName)){
+         /* if (synonymsEpithet != null && !synonymsEpithet.contains(synSpeciesEpithetName)){
             synonymsEpithet.add(synSpeciesEpithetName);
         }*/
 
         inferredSynName = TaxonNameFactory.NewZoologicalInstance(taxon.getName().getRank());
         //TODO:differ between parent is genus and taxon is species, parent is subgenus and taxon is species, parent is species and taxon is subspecies and parent is genus and taxon is subgenus...
 
-
         inferredSynName.setGenusOrUninomial(genusOfTaxon);
         if (zooParentName.isInfraGeneric()){
             inferredSynName.setInfraGenericEpithet(zooParentName.getInfraGenericEpithet());
@@ -2740,7 +2690,6 @@ public class TaxonServiceImpl
             inferredSynName.setInfraSpecificEpithet(synZooName.getInfraGenericEpithet());
         }
 
-
         inferredGenus = Synonym.NewInstance(inferredSynName, null);
 
         // Set the sourceReference
@@ -2810,7 +2759,7 @@ public class TaxonServiceImpl
             synSpecificEpithet = zooSynName.getSpecificEpithet();
         }
 
-                     /* if (synGenusName != null && !synonymsGenus.containsKey(synGenusName)){
+           /* if (synGenusName != null && !synonymsGenus.containsKey(synGenusName)){
             synonymsGenus.put(synGenusName, idInSource);
         }*/
 
@@ -2861,8 +2810,6 @@ public class TaxonServiceImpl
 
         inferredSynName.addSource(originalSource);
 
-
-
         taxon.addSynonym(inferredEpithet, SynonymType.INFERRED_EPITHET_OF());
 
         return inferredEpithet;
@@ -2909,11 +2856,9 @@ public class TaxonServiceImpl
             logger.warn("No idInSource for TaxonBase " + taxonBase.getUuid() + " - " + taxonBase.getTitleCache());
         }
 
-
         return idInSource;
     }
 
-
     /**
      * Returns the citation for a given Synonym.
      * @param syn
@@ -3031,7 +2976,7 @@ public class TaxonServiceImpl
         Set<CdmBase> references = commonService.getReferencingObjectsForDeletion(taxonBase);
         if (taxonBase instanceof Taxon){
             TaxonDeletionConfigurator taxonConfig = (TaxonDeletionConfigurator) config;
-            List<String> propertyPaths = new ArrayList();
+            List<String> propertyPaths = new ArrayList<>();
             propertyPaths.add("taxonNodes");
             Taxon taxon = (Taxon)load(taxonBaseUuid, propertyPaths);
 
@@ -3058,8 +3003,6 @@ public class TaxonServiceImpl
         return result;
     }
 
-
-
     private DeleteResult isDeletableForTaxon(Set<CdmBase> references, TaxonDeletionConfigurator config){
         String message = null;
         DeleteResult result = new DeleteResult();
@@ -3097,7 +3040,6 @@ public class TaxonServiceImpl
                    message = "Taxon can't be deleted as it is used in an identification key. Remove from identification key prior to deleting this taxon";
                 }
 
-
                /* //PolytomousKeyNode
                 if (referencingObject.isInstanceOf(PolytomousKeyNode.class)){
                     String message = "Taxon" + taxon.getTitleCache() + " can't be deleted as it is used in polytomous key node";
@@ -3256,6 +3198,7 @@ public class TaxonServiceImpl
 
     @Override
     public List<TaxonBase> findTaxaByName(MatchingTaxonConfigurator config){
+        @SuppressWarnings("rawtypes")
         List<TaxonBase> taxonList = dao.getTaxaByName(true, config.isIncludeSynonyms(), false, false, false,
                 config.getTaxonNameTitle(), null, null, MatchMode.EXACT, null, config.isIncludeSynonyms(), null, 0, 0, config.getPropertyPath());
         return taxonList;
@@ -3375,9 +3318,6 @@ public class TaxonServiceImpl
 		return this.swapSynonymAndAcceptedTaxon(syn, taxon, setNameInSource);
 	}
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public TaxonRelationshipsDTO listTaxonRelationships(UUID taxonUuid, Set<TaxonRelationshipType> directTypes,
             Set<TaxonRelationshipType> inversTypes,
@@ -3430,5 +3370,4 @@ public class TaxonServiceImpl
             return dto;
         }
     }
-
 }
