remove unused property path
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / ClassificationServiceImpl.java
index 02a0f875da73fa9d628a6a5a242ecfb475bce0d0..496ace11c7fd47687d161d64d545b9bf1151d536 100644 (file)
@@ -6,7 +6,6 @@
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
-
 package eu.etaxonomy.cdm.api.service;
 
 import java.util.ArrayList;
@@ -26,8 +25,9 @@ import java.util.stream.Collectors;
 import javax.persistence.EntityNotFoundException;
 
 import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -35,7 +35,6 @@ import org.springframework.transaction.annotation.Transactional;
 import eu.etaxonomy.cdm.api.service.config.CreateHierarchyForClassificationConfigurator;
 import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
-import eu.etaxonomy.cdm.api.service.dto.EntityDTO;
 import eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO;
 import eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO;
 import eu.etaxonomy.cdm.api.service.dto.TaxonInContextDTO;
@@ -45,6 +44,7 @@ import eu.etaxonomy.cdm.api.service.pager.impl.AbstractPagerImpl;
 import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
 import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
 import eu.etaxonomy.cdm.compare.taxon.ITaxonNodeComparator;
+import eu.etaxonomy.cdm.compare.taxon.TaxonNodeSortMode;
 import eu.etaxonomy.cdm.exception.FilterException;
 import eu.etaxonomy.cdm.exception.UnpublishedException;
 import eu.etaxonomy.cdm.model.common.CdmBase;
@@ -72,6 +72,7 @@ import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
 import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao;
 import eu.etaxonomy.cdm.persistence.dao.term.IDefinedTermDao;
 import eu.etaxonomy.cdm.persistence.dto.ClassificationLookupDTO;
+import eu.etaxonomy.cdm.persistence.dto.EntityDTO;
 import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
 import eu.etaxonomy.cdm.persistence.dto.TaxonStatus;
 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
@@ -89,7 +90,7 @@ public class ClassificationServiceImpl
              extends IdentifiableServiceBase<Classification, IClassificationDao>
              implements IClassificationService {
 
-    private static final Logger logger = Logger.getLogger(ClassificationServiceImpl.class);
+    private static final Logger logger = LogManager.getLogger();
 
     @Autowired
     private ITaxonNodeDao taxonNodeDao;
@@ -112,11 +113,11 @@ public class ClassificationServiceImpl
         this.dao = dao;
     }
 
-    private Comparator<? super TaxonNode> taxonNodeComparator;
+    private Comparator<TaxonNode> taxonNodeComparator;
 
     @Autowired
-    public void setTaxonNodeComparator(ITaxonNodeComparator<? super TaxonNode> taxonNodeComparator){
-        this.taxonNodeComparator = (Comparator<? super TaxonNode>) taxonNodeComparator;
+    public void setTaxonNodeComparator(ITaxonNodeComparator<TaxonNode> taxonNodeComparator){
+        this.taxonNodeComparator = (Comparator<TaxonNode>) taxonNodeComparator;
     }
 
     @Override
@@ -143,7 +144,7 @@ public class ClassificationServiceImpl
             Rank rank, boolean includeUnpublished, Integer pageSize, Integer pageIndex, TaxonNodeDtoSortMode sortMode,
             List<String> propertyPaths) {
         List<TaxonNode> list = listRankSpecificRootNodes(classification, subtree, rank, includeUnpublished, pageSize, pageIndex, propertyPaths);
-        return list.stream().filter(e ->  e != null).map(e -> new TaxonNodeDto(e)).sorted(sortMode.newComparator()).collect(Collectors.toList());
+        return list.stream().filter(e ->  e != null).map(e -> new TaxonNodeDto(e)).sorted(sortMode.comparator()).collect(Collectors.toList());
     }
 
     @Override
@@ -279,11 +280,11 @@ public class ClassificationServiceImpl
         TaxonNode node = taxonNodeService.find(nodeUuid);
         if(node == null){
             logger.warn("The specified taxon is not found in the given tree.");
-            return null;
+            return new ArrayList<>(0);
         }else if (subtree != null && !node.isDescendant(subtree)){
             //TODO handle as exception? E.g. FilterException, AccessDeniedException?
             logger.warn("The specified taxon is not found for the given subtree.");
-            return null;
+            return new ArrayList<>(0);
         }
 
         return loadTreeBranch(node, subtree, baseRank, includeUnpublished, propertyPaths);
@@ -328,8 +329,10 @@ public class ClassificationServiceImpl
     }
 
     @Override
-    public List<TaxonNodeDto> listChildNodeDtosOfTaxon(UUID taxonUuid, UUID classificationUuid, UUID subtreeUuid, boolean includeUnpublished,
-            Integer pageSize, Integer pageIndex, TaxonNodeDtoSortMode sortMode, List<String> propertyPaths) throws FilterException{
+    public List<TaxonNodeDto> listChildNodeDtosOfTaxon(UUID taxonUuid, UUID classificationUuid,
+            UUID subtreeUuid, boolean includeUnpublished,
+            Integer pageSize, Integer pageIndex, TaxonNodeDtoSortMode sortMode) throws FilterException{
+
         Classification classification = dao.load(classificationUuid);
         Taxon taxon = (Taxon) taxonDao.load(taxonUuid);
         TaxonNode subtree = taxonNodeDao.load(subtreeUuid);
@@ -339,9 +342,12 @@ public class ClassificationServiceImpl
 
         List<TaxonNode> results = dao.listChildrenOf(
                 taxon, classification, subtree, includeUnpublished, pageSize, pageIndex, propertyPaths);
-        Comparator<TaxonNodeDto> comparator = sortMode.newComparator();
+        Comparator<TaxonNodeDto> comparator = sortMode.comparator();
         // TODO order during the hibernate query in the dao?
-        List<TaxonNodeDto> dtos = results.stream().map(e -> new TaxonNodeDto(e)).sorted(comparator).collect(Collectors.toList());
+        List<TaxonNodeDto> dtos = results.stream()
+                .map(tn -> new TaxonNodeDto(tn))
+                .sorted(comparator)
+                .collect(Collectors.toList());
         return dtos;
     }
 
@@ -555,7 +561,10 @@ public class ClassificationServiceImpl
        @Transactional(readOnly = false)
        @Override
     public UpdateResult createHierarchyInClassification(Classification classification, CreateHierarchyForClassificationConfigurator configurator){
+
         UpdateResult result = new UpdateResult();
+        Set<TaxonNode> taxonNodesToSave = new HashSet<>();
+
        classification = dao.findByUuid(classification.getUuid());
        Map<String, List<TaxonNode>> map = getSortedGenusList(classification.getAllNodes());
 
@@ -587,8 +596,7 @@ public class ClassificationServiceImpl
                                        //get all childNodes
                                        //save prior Hierarchy and remove them from the list
                                        List<TaxonNode> copyAllChildrenToTaxonNode = copyAllChildrenToTaxonNode(tNode, clone, result);
-//                                     parentNode = newClassification.addChildNode(clone, 0, classification.getCitation(), classification.getMicroReference());
-                                       //FIXME remove classification
+//                                     //FIXME remove classification
                                        parentNode = newClassification.addChildNode(clone, 0, clone.getReference(), clone.getMicroReference());
                                        //remove taxonNode from list because just added to classification
                                        result.addUpdatedObject(tNode);
@@ -609,7 +617,9 @@ public class ClassificationServiceImpl
                        parentNode = newClassification.addChildTaxon(taxon, 0, null, null);
                        result.addUpdatedObject(parentNode);
                }
-               //iterate over the rest of the list
+               taxonNodesToSave.add(parentNode);
+
+               //iterate over the remaining list
                for(TaxonNode tn : listOfTaxonNodes){
                        //if TaxonNode has a parent and this is not the classification then skip it
                        //and add to new classification via the parentNode as children of it
@@ -622,9 +632,10 @@ public class ClassificationServiceImpl
 
                        TaxonNode clone = tn.clone();
                        //FIXME: citation from node
-                       //TODO: addchildNode without citation and references
-//                     TaxonNode taxonNode = parentNode.addChildNode(clone, classification.getCitation(), classification.getMicroReference());
+                       //TODO: addChildNode without citation and references
                        TaxonNode taxonNode = parentNode.addChildNode(clone, clone.getReference(), clone.getMicroReference());
+                       taxonNodesToSave.add(taxonNode);
+
                        result.addUnChangedObject(clone);
                        if(tn.hasChildNodes()){
                                //save hierarchy in new classification
@@ -636,6 +647,7 @@ public class ClassificationServiceImpl
                }
        }
        dao.saveOrUpdate(newClassification);
+       taxonNodeDao.saveOrUpdateAll(taxonNodesToSave);
        result.setCdmEntity(newClassification);
        return result;
     }