use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.
the class DescriptiveDataSetService method createTaxonRowWrapper.
@Override
public TaxonRowWrapperDTO createTaxonRowWrapper(DescriptionBaseDto description, UUID descriptiveDataSetUuid) {
Classification classification = null;
DescriptiveDataSet descriptiveDataSet = dao.load(descriptiveDataSetUuid, null);
Optional<TaxonNode> first = descriptiveDataSet.getTaxonSubtreeFilter().stream().filter(node -> node.getClassification() != null).findFirst();
Optional<Classification> classificationOptional = first.map(node -> node.getClassification());
Set<DescriptionBaseDto> descriptions = new HashSet<>();
TaxonNodeDto nodeDto = null;
if (classificationOptional.isPresent()) {
classification = classificationOptional.get();
nodeDto = taxonNodeService.dto(description.getTaxonDto().getUuid(), classification.getUuid());
}
return new TaxonRowWrapperDTO(description, nodeDto, descriptions);
}
use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.
the class TaxonNodeServiceImpl method getParentUuidAndTitleCache.
@Override
public TaxonNodeDto getParentUuidAndTitleCache(ITaxonTreeNode child) {
UUID uuid = child.getUuid();
int id = child.getId();
TaxonNodeDto uuidAndTitleCache = new TaxonNodeDto(uuid, id, null);
return getParentUuidAndTitleCache(uuidAndTitleCache);
}
use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.
the class TaxonNodeServiceImpl method findCommonParentDto.
@Override
public TaxonNodeDto findCommonParentDto(Collection<TaxonNodeDto> nodes) {
TaxonNodeDto commonParent = null;
List<String> treePath = null;
for (TaxonNodeDto nodeDto : nodes) {
if (nodeDto == null) {
continue;
}
String nodeTreeIndex = nodeDto.getTreeIndex();
nodeTreeIndex = nodeTreeIndex.replaceFirst("#", "");
String[] split = nodeTreeIndex.split("#");
if (treePath == null) {
treePath = Arrays.asList(split);
} else {
List<String> match = new ArrayList<>();
for (int i = 0; i < treePath.size(); i++) {
if (i >= split.length) {
// current tree index is shorter so break
break;
} else if (split[i].equals(treePath.get(i))) {
// match found
match.add(treePath.get(i));
} else {
// first mismatch found
break;
}
}
treePath = match;
if (treePath.isEmpty()) {
// -> they belong to a different classification
break;
}
}
}
if (treePath != null && !treePath.isEmpty()) {
// get last index
int nodeId = Integer.parseInt(treePath.get(treePath.size() - 1));
TaxonNode taxonNode = dao.load(nodeId, null);
commonParent = new TaxonNodeDto(taxonNode);
}
return commonParent;
}
use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.
the class TaxonNodeServiceImpl method pageChildNodesDTOs.
@Override
public Pager<TaxonNodeDto> pageChildNodesDTOs(UUID taxonNodeUuid, boolean recursive, boolean includeUnpublished, boolean doSynonyms, TaxonNodeSortMode sortMode, Integer pageSize, Integer pageIndex) {
TaxonNode parentNode = dao.load(taxonNodeUuid);
List<CdmBase> allRecords = new ArrayList<>();
// acceptedTaxa
List<TaxonNode> childNodes = loadChildNodesOfTaxonNode(parentNode, null, recursive, includeUnpublished, sortMode);
allRecords.addAll(childNodes);
// add synonyms if pager is not yet full synonyms
if (doSynonyms) {
List<Synonym> synList = new ArrayList<>(parentNode.getTaxon().getSynonyms());
Collections.sort(synList, new HomotypicGroupTaxonComparator(null));
// TODO: test sorting
allRecords.addAll(synList);
}
List<TaxonNodeDto> dtos = new ArrayList<>(pageSize == null ? 25 : pageSize);
long totalCount = Long.valueOf(allRecords.size());
TaxonName parentName = null;
for (CdmBase item : PagerUtils.pageList(allRecords, pageIndex, pageSize)) {
if (item.isInstanceOf(TaxonNode.class)) {
dtos.add(new TaxonNodeDto(CdmBase.deproxy(item, TaxonNode.class)));
} else if (item.isInstanceOf(Synonym.class)) {
Synonym synonym = CdmBase.deproxy(item, Synonym.class);
parentName = parentName == null ? parentNode.getTaxon().getName() : parentName;
boolean isHomotypic = synonym.getName().isHomotypic(parentName);
dtos.add(new TaxonNodeDto(synonym, isHomotypic));
}
}
return new DefaultPagerImpl<>(pageIndex, totalCount, pageSize, dtos);
}
use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.
the class DescriptiveDataSetDao method getDescriptiveDataSetDtoByUuid.
@Override
public DescriptiveDataSetBaseDto getDescriptiveDataSetDtoByUuid(UUID uuid) {
String queryString = DescriptiveDataSetBaseDto.getDescriptiveDataSetDtoSelect() + " WHERE a.uuid = :uuid" + " ORDER BY a.titleCache";
Query query = getSession().createQuery(queryString);
query.setParameter("uuid", uuid);
@SuppressWarnings("unchecked") List<Object[]> result = query.list();
List<DescriptiveDataSetBaseDto> list = DescriptiveDataSetBaseDto.descriptiveDataSetBaseDtoListFrom(result);
UUID descriptiveSystemUuid = null;
UUID minRankUuid = null;
UUID maxRankUuid = null;
if (result != null && !result.isEmpty()) {
Object[] descriptiveDataSetResult = result.get(0);
descriptiveSystemUuid = (UUID) descriptiveDataSetResult[4];
minRankUuid = (UUID) descriptiveDataSetResult[5];
maxRankUuid = (UUID) descriptiveDataSetResult[6];
} else {
return null;
}
// get descriptiveSystem
DescriptiveDataSetBaseDto dto = list.get(0);
if (descriptiveSystemUuid != null) {
TermTreeDto treeDto = termTreeDao.getTermTreeDtosByUuid(descriptiveSystemUuid);
dto.setDescriptiveSystem(treeDto);
}
// get taxon nodes
List<UUID> nodeUuids = getNodeUuidsForDescriptiveDataSet(uuid);
List<TaxonNodeDto> nodeDtos = nodeDao.getTaxonNodeDtos(nodeUuids);
Set<TaxonNodeDto> nodeSet = new HashSet<>(nodeDtos);
dto.setSubTreeFilter(nodeSet);
List<UUID> descriptionUuidList = getDescriptionUuidsForDescriptiveDataSet(uuid);
Set<UUID> descriptionUuids = new HashSet<>(descriptionUuidList);
dto.setDescriptionUuids(descriptionUuids);
TermDto minRank = termDao.getTermDto(minRankUuid);
TermDto maxRank = termDao.getTermDto(maxRankUuid);
dto.setMaxRank(maxRank);
dto.setMinRank(minRank);
return dto;
}
Aggregations