Search in sources :

Example 26 with TaxonNodeDto

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);
}
Also used : Arrays(java.util.Arrays) TermDto(eu.etaxonomy.cdm.persistence.dto.TermDto) IProgressMonitor(eu.etaxonomy.cdm.common.monitor.IProgressMonitor) StatisticalMeasurementValueDto(eu.etaxonomy.cdm.api.service.dto.StatisticalMeasurementValueDto) Autowired(org.springframework.beans.factory.annotation.Autowired) IdentifiableServiceConfiguratorImpl(eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl) CategoricalData(eu.etaxonomy.cdm.model.description.CategoricalData) DescriptiveSystemRole(eu.etaxonomy.cdm.model.description.DescriptiveSystemRole) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto) BigDecimal(java.math.BigDecimal) Logger(org.apache.log4j.Logger) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) Classification(eu.etaxonomy.cdm.model.taxon.Classification) QuantitativeDataDto(eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto) TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) DescriptionBaseDto(eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto) Map(java.util.Map) Query(org.hibernate.Query) TaxonNodeFilter(eu.etaxonomy.cdm.filter.TaxonNodeFilter) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) Collection(java.util.Collection) Set(java.util.Set) StateDataDto(eu.etaxonomy.cdm.api.service.dto.StateDataDto) CdmLinkSource(eu.etaxonomy.cdm.model.reference.CdmLinkSource) UUID(java.util.UUID) DescriptiveDataSetBaseDto(eu.etaxonomy.cdm.persistence.dto.DescriptiveDataSetBaseDto) QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) Collectors(java.util.stream.Collectors) PolytomousKeyGeneratorConfigurator(eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGeneratorConfigurator) SpecimenOrObservationDTOFactory(eu.etaxonomy.cdm.api.service.dto.SpecimenOrObservationDTOFactory) PolytomousKeyGenerator(eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGenerator) List(java.util.List) DeleteDescriptiveDataSetConfigurator(eu.etaxonomy.cdm.api.service.config.DeleteDescriptiveDataSetConfigurator) DescriptionType(eu.etaxonomy.cdm.model.description.DescriptionType) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) Optional(java.util.Optional) DescriptionBase(eu.etaxonomy.cdm.model.description.DescriptionBase) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) IDefinedTermDao(eu.etaxonomy.cdm.persistence.dao.term.IDefinedTermDao) MergeResult(eu.etaxonomy.cdm.persistence.dto.MergeResult) IIdentifiableEntityCacheStrategy(eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy) TextData(eu.etaxonomy.cdm.model.description.TextData) Session(org.hibernate.Session) StatisticalMeasure(eu.etaxonomy.cdm.model.description.StatisticalMeasure) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) HashMap(java.util.HashMap) Status(eu.etaxonomy.cdm.api.service.UpdateResult.Status) IndividualsAssociation(eu.etaxonomy.cdm.model.description.IndividualsAssociation) RowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) ArrayList(java.util.ArrayList) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource) HashSet(java.util.HashSet) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) SpecimenNodeWrapper(eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper) TermTreeDto(eu.etaxonomy.cdm.persistence.dto.TermTreeDto) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) Service(org.springframework.stereotype.Service) RemoveDescriptionsFromDescriptiveDataSetConfigurator(eu.etaxonomy.cdm.api.service.config.RemoveDescriptionsFromDescriptiveDataSetConfigurator) State(eu.etaxonomy.cdm.model.description.State) StatisticalMeasurementValue(eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue) IDescriptiveDataSetDao(eu.etaxonomy.cdm.persistence.dao.description.IDescriptiveDataSetDao) DefaultQuantitativeDescriptionBuilder(eu.etaxonomy.cdm.format.description.DefaultQuantitativeDescriptionBuilder) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) TaxonRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO) DescriptionElementDto(eu.etaxonomy.cdm.api.service.dto.DescriptionElementDto) HibernateProxyHelper(eu.etaxonomy.cdm.hibernate.HibernateProxyHelper) MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) CategoricalDataDto(eu.etaxonomy.cdm.api.service.dto.CategoricalDataDto) FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) Language(eu.etaxonomy.cdm.model.common.Language) DefaultCategoricalDescriptionBuilder(eu.etaxonomy.cdm.format.description.DefaultCategoricalDescriptionBuilder) SpecimenRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO) Feature(eu.etaxonomy.cdm.model.description.Feature) DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) DescriptionBaseDto(eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto) Classification(eu.etaxonomy.cdm.model.taxon.Classification) TaxonRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO) HashSet(java.util.HashSet) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Example 27 with TaxonNodeDto

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);
}
Also used : UUID(java.util.UUID) OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Example 28 with TaxonNodeDto

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;
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) ArrayList(java.util.ArrayList) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Example 29 with TaxonNodeDto

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);
}
Also used : DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) ArrayList(java.util.ArrayList) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Example 30 with TaxonNodeDto

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;
}
Also used : Query(org.hibernate.Query) TermDto(eu.etaxonomy.cdm.persistence.dto.TermDto) TermTreeDto(eu.etaxonomy.cdm.persistence.dto.TermTreeDto) UUID(java.util.UUID) DescriptiveDataSetBaseDto(eu.etaxonomy.cdm.persistence.dto.DescriptiveDataSetBaseDto) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto) HashSet(java.util.HashSet)

Aggregations

TaxonNodeDto (eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)34 ArrayList (java.util.ArrayList)16 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)15 UUID (java.util.UUID)11 Query (org.hibernate.Query)10 Classification (eu.etaxonomy.cdm.model.taxon.Classification)8 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)8 SortableTaxonNodeQueryResult (eu.etaxonomy.cdm.persistence.dto.SortableTaxonNodeQueryResult)6 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)4 DescriptiveDataSetBaseDto (eu.etaxonomy.cdm.persistence.dto.DescriptiveDataSetBaseDto)4 Test (org.junit.Test)4 DescriptionBaseDto (eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto)3 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)3 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)3 BigInteger (java.math.BigInteger)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 DataSet (org.unitils.dbunit.annotation.DataSet)3 SpecimenRowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO)2 TaxonRowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO)2 IProgressMonitor (eu.etaxonomy.cdm.common.monitor.IProgressMonitor)2