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;
}
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;
}
Aggregations