X-Git-Url: https://dev.e-taxonomy.eu/gitweb/cdmlib.git/blobdiff_plain/fcb1fc89f42addb1195896f9b31045f04b3c8fd8..4c525123433fbc5a7d36e2445302650bddc39307:/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ClassificationServiceImpl.java diff --git a/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ClassificationServiceImpl.java b/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ClassificationServiceImpl.java index 5adb7ba48a..496ace11c7 100644 --- a/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ClassificationServiceImpl.java +++ b/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ClassificationServiceImpl.java @@ -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; @@ -73,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; @@ -90,7 +90,7 @@ public class ClassificationServiceImpl extends IdentifiableServiceBase implements IClassificationService { - private static final Logger logger = Logger.getLogger(ClassificationServiceImpl.class); + private static final Logger logger = LogManager.getLogger(); @Autowired private ITaxonNodeDao taxonNodeDao; @@ -113,11 +113,11 @@ public class ClassificationServiceImpl this.dao = dao; } - private Comparator taxonNodeComparator; + private Comparator taxonNodeComparator; @Autowired - public void setTaxonNodeComparator(ITaxonNodeComparator taxonNodeComparator){ - this.taxonNodeComparator = (Comparator) taxonNodeComparator; + public void setTaxonNodeComparator(ITaxonNodeComparator taxonNodeComparator){ + this.taxonNodeComparator = (Comparator) taxonNodeComparator; } @Override @@ -280,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); @@ -329,8 +329,10 @@ public class ClassificationServiceImpl } @Override - public List listChildNodeDtosOfTaxon(UUID taxonUuid, UUID classificationUuid, UUID subtreeUuid, boolean includeUnpublished, - Integer pageSize, Integer pageIndex, TaxonNodeDtoSortMode sortMode, List propertyPaths) throws FilterException{ + public List 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); @@ -342,7 +344,10 @@ public class ClassificationServiceImpl taxon, classification, subtree, includeUnpublished, pageSize, pageIndex, propertyPaths); Comparator comparator = sortMode.comparator(); // TODO order during the hibernate query in the dao? - List dtos = results.stream().map(e -> new TaxonNodeDto(e)).sorted(comparator).collect(Collectors.toList()); + List dtos = results.stream() + .map(tn -> new TaxonNodeDto(tn)) + .sorted(comparator) + .collect(Collectors.toList()); return dtos; } @@ -556,7 +561,10 @@ public class ClassificationServiceImpl @Transactional(readOnly = false) @Override public UpdateResult createHierarchyInClassification(Classification classification, CreateHierarchyForClassificationConfigurator configurator){ + UpdateResult result = new UpdateResult(); + Set taxonNodesToSave = new HashSet<>(); + classification = dao.findByUuid(classification.getUuid()); Map> map = getSortedGenusList(classification.getAllNodes()); @@ -588,8 +596,7 @@ public class ClassificationServiceImpl //get all childNodes //save prior Hierarchy and remove them from the list List 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); @@ -610,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 @@ -623,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 @@ -637,6 +647,7 @@ public class ClassificationServiceImpl } } dao.saveOrUpdate(newClassification); + taxonNodeDao.saveOrUpdateAll(taxonNodesToSave); result.setCdmEntity(newClassification); return result; }