Search in sources :

Example 1 with TaxonDistributionDTO

use of eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO in project cdmlib by cybertaxonomy.

the class TaxonNodeServiceImpl method getTaxonDistributionDTO.

@Override
public List<TaxonDistributionDTO> getTaxonDistributionDTO(List<UUID> nodeUuids, List<String> propertyPaths, Authentication authentication, boolean openChildren, TaxonNodeSortMode sortMode) {
    nodeUuids = nodeUuids.stream().distinct().collect(Collectors.toList());
    List<TaxonNode> nodes = new ArrayList<>();
    List<TaxonNode> parentNodes = load(nodeUuids, propertyPaths);
    if (sortMode != null) {
        parentNodes.sort(sortMode.comparator());
    }
    if (openChildren) {
        // TODO we could remove nodes which are children of other nodes in parentNodes list here as they are duplicates
        for (TaxonNode node : parentNodes) {
            if (node == null || nodes.contains(node)) {
                continue;
            }
            nodes.add(node);
            List<TaxonNode> children = new ArrayList<>();
            children.addAll(loadChildNodesOfTaxonNode(node, propertyPaths, true, true, sortMode));
            for (TaxonNode child : children) {
                if (!nodes.contains(child)) {
                    nodes.add(child);
                }
            }
        }
    } else {
        nodes.addAll(nodes);
    }
    List<TaxonDistributionDTO> result = new ArrayList<>();
    boolean hasPermission = false;
    for (TaxonNode node : nodes) {
        if (authentication != null) {
            hasPermission = permissionEvaluator.hasPermission(authentication, node, Operation.UPDATE);
        } else {
            hasPermission = true;
        }
        if (node.getTaxon() != null && hasPermission) {
            try {
                TaxonDistributionDTO dto = new TaxonDistributionDTO(node);
                result.add(dto);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
    return result;
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) ArrayList(java.util.ArrayList) TaxonDistributionDTO(eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO)

Example 2 with TaxonDistributionDTO

use of eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO in project cdmlib by cybertaxonomy.

the class DescriptionServiceImpl method mergeDescriptionElements.

@Override
@Transactional(readOnly = false)
public List<MergeResult<DescriptionBase>> mergeDescriptionElements(Collection<TaxonDistributionDTO> descriptionElements, boolean returnTransientEntity) {
    List<MergeResult<DescriptionBase>> mergedObjects = new ArrayList<>();
    for (TaxonDistributionDTO obj : descriptionElements) {
        Iterator<TaxonDescription> iterator = obj.getDescriptionsWrapper().getDescriptions().iterator();
        List<DescriptionBase> list = new ArrayList(obj.getDescriptionsWrapper().getDescriptions());
        // mergedObjects.add(map.values());
        while (iterator.hasNext()) {
            TaxonDescription desc = iterator.next();
            mergedObjects.add(dao.merge(desc, returnTransientEntity));
        }
    }
    return mergedObjects;
}
Also used : DescriptionBase(eu.etaxonomy.cdm.model.description.DescriptionBase) MergeResult(eu.etaxonomy.cdm.persistence.dto.MergeResult) ArrayList(java.util.ArrayList) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) TaxonDistributionDTO(eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TaxonDistributionDTO (eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO)2 ArrayList (java.util.ArrayList)2 DescriptionBase (eu.etaxonomy.cdm.model.description.DescriptionBase)1 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)1 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)1 MergeResult (eu.etaxonomy.cdm.persistence.dto.MergeResult)1 Transactional (org.springframework.transaction.annotation.Transactional)1