* 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;
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;
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;
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;
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;
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;
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
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
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);
}
@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);
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;
}
@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());
//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);
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
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
}
}
dao.saveOrUpdate(newClassification);
+ taxonNodeDao.saveOrUpdateAll(taxonNodesToSave);
result.setCdmEntity(newClassification);
return result;
}