Search in sources :

Example 1 with TaxonNodeDto

use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.

the class TaxonNodeDaoHibernateImplTest method testGetTaxonNodeUuidAndTitleCache.

@Test
@DataSet("TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
public final void testGetTaxonNodeUuidAndTitleCache() {
    String pattern = "";
    List<TaxonNodeDto> result = taxonNodeDao.getUuidAndTitleCache(100, pattern, classificationUuid, true);
    assertNotNull(result);
    assertEquals(6, result.size());
    // test limit
    int limit = 2;
    result = taxonNodeDao.getUuidAndTitleCache(limit, pattern, classificationUuid, true);
    assertEquals(2, result.size());
    // test pattern & classification
    pattern = "*Rothschi*";
    result = taxonNodeDao.getUuidAndTitleCache(100, pattern, classificationUuid, true);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals("0b5846e5-b8d2-4ca9-ac51-099286ea4adc", result.get(0).getUuid().toString());
    // test pattern without classification
    pattern = "*Rothschi*";
    result = taxonNodeDao.getUuidAndTitleCache(100, pattern, null, true);
    assertNotNull(result);
    assertEquals(2, result.size());
    // test doubtful & pattern
    pattern = "Aus*";
    result = taxonNodeDao.getUuidAndTitleCache(100, pattern, classificationUuid, true);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals("ebf8ea46-9f24-47be-8fb5-02bd67f90348", result.get(0).getUuid().toString());
}
Also used : LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 2 with TaxonNodeDto

use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.

the class DescriptiveDataSetService method createSpecimenRowWrapper.

private SpecimenRowWrapperDTO createSpecimenRowWrapper(DescriptionBaseDto description, UUID taxonNodeUuid, UUID datasetUuid) {
    TaxonNodeDto taxonNode = taxonNodeService.dto(taxonNodeUuid);
    DescriptiveDataSetBaseDto descriptiveDataSet = getDescriptiveDataSetDtoByUuid(datasetUuid);
    // UuidAndTitleCache<SpecimenOrObservationBase> specimen = description.getSpecimenDto();
    SpecimenOrObservationBase specimen = occurrenceService.find(description.getSpecimenDto().getUuid());
    // supplemental information
    if (taxonNode == null) {
        taxonNode = findTaxonNodeForDescription(description, descriptiveDataSet);
    }
    FieldUnit fieldUnit = null;
    String identifier = null;
    NamedArea country = null;
    if (taxonNode == null) {
        return null;
    }
    // taxon node was found
    // get field unit
    Collection<FieldUnit> fieldUnits = occurrenceService.findFieldUnits(specimen.getUuid(), Arrays.asList(new String[] { "gatheringEvent", "gatheringEvent.country" }));
    if (fieldUnits.size() > 1) {
        // $NON-NLS-1$
        logger.error("More than one or no field unit found for specimen");
        return null;
    } else {
        if (fieldUnits.size() > 0) {
            fieldUnit = fieldUnits.iterator().next();
        }
    }
    // get identifier
    identifier = occurrenceService.getMostSignificantIdentifier(specimen.getUuid());
    // get country
    if (fieldUnit != null && fieldUnit.getGatheringEvent() != null) {
        country = fieldUnit.getGatheringEvent().getCountry();
    }
    // get default taxon description
    // TaxonDescription defaultTaxonDescription = findDefaultDescription(description.getUuid(), descriptiveDataSet.getUuid());
    DescriptionBaseDto defaultTaxonDescription = recurseDefaultDescription(taxonNode, descriptiveDataSet);
    TaxonRowWrapperDTO taxonRowWrapper = defaultTaxonDescription != null ? createTaxonRowWrapper(defaultTaxonDescription.getDescriptionUuid(), descriptiveDataSet.getUuid()) : null;
    // use description not specimen for specimenRow
    SpecimenRowWrapperDTO specimenRowWrapperDTO = new SpecimenRowWrapperDTO(description, SpecimenOrObservationDTOFactory.fromEntity(specimen), specimen.getRecordBasis(), taxonNode, fieldUnit, identifier, country);
    specimenRowWrapperDTO.setDefaultDescription(taxonRowWrapper);
    return specimenRowWrapperDTO;
}
Also used : FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) DescriptionBaseDto(eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto) SpecimenRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) TaxonRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO) DescriptiveDataSetBaseDto(eu.etaxonomy.cdm.persistence.dto.DescriptiveDataSetBaseDto) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Example 3 with TaxonNodeDto

use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.

the class DescriptiveDataSetService method findDefaultDescription.

@Override
public DescriptionBaseDto findDefaultDescription(UUID specimenDescriptionUuid, UUID dataSetUuid) {
    DescriptionBaseDto specimenDescription = descriptionService.loadDto(specimenDescriptionUuid);
    DescriptiveDataSetBaseDto dataSet = dao.getDescriptiveDataSetDtoByUuid(dataSetUuid);
    TaxonNodeDto node = findTaxonNodeForDescription(specimenDescription, dataSet);
    return recurseDefaultDescription(node, dataSet);
}
Also used : DescriptionBaseDto(eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto) DescriptiveDataSetBaseDto(eu.etaxonomy.cdm.persistence.dto.DescriptiveDataSetBaseDto) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Example 4 with TaxonNodeDto

use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.

the class ClassificationServiceImpl method getTaxonInContext.

@Override
public TaxonInContextDTO getTaxonInContext(UUID classificationUuid, UUID taxonBaseUuid, Boolean doChildren, Boolean doSynonyms, boolean includeUnpublished, List<UUID> ancestorMarkers, TaxonNodeSortMode sortMode) {
    TaxonInContextDTO result = new TaxonInContextDTO();
    TaxonBase<?> taxonBase = taxonDao.load(taxonBaseUuid);
    if (taxonBase == null) {
        throw new EntityNotFoundException("Taxon with uuid " + taxonBaseUuid + " not found in datasource");
    }
    boolean isSynonym = false;
    Taxon acceptedTaxon;
    if (taxonBase.isInstanceOf(Synonym.class)) {
        isSynonym = true;
        Synonym synonym = CdmBase.deproxy(taxonBase, Synonym.class);
        acceptedTaxon = synonym.getAcceptedTaxon();
        if (acceptedTaxon == null) {
            throw new EntityNotFoundException("Accepted taxon not found for synonym");
        }
        TaxonStatus taxonStatus = TaxonStatus.Synonym;
        if (synonym.getName() != null && acceptedTaxon.getName() != null && synonym.getName().getHomotypicalGroup().equals(acceptedTaxon.getName().getHomotypicalGroup())) {
            taxonStatus = TaxonStatus.SynonymObjective;
        }
        result.setTaxonStatus(taxonStatus);
    } else {
        acceptedTaxon = CdmBase.deproxy(taxonBase, Taxon.class);
        result.setTaxonStatus(TaxonStatus.Accepted);
    }
    UUID acceptedTaxonUuid = acceptedTaxon.getUuid();
    UUID taxonNodeUuid = getTaxonNodeUuidByTaxonUuid(classificationUuid, acceptedTaxonUuid);
    if (taxonNodeUuid == null) {
        throw new EntityNotFoundException("Taxon not found in classficiation with uuid " + classificationUuid + ". Either classification does not exist or does not contain taxon/synonym with uuid " + taxonBaseUuid);
    }
    result.setTaxonNodeUuid(taxonNodeUuid);
    // TODO make it a dao call
    Taxon parentTaxon = getParentTaxon(classificationUuid, acceptedTaxon);
    if (parentTaxon != null) {
        result.setParentTaxonUuid(parentTaxon.getUuid());
        result.setParentTaxonLabel(parentTaxon.getTitleCache());
        if (parentTaxon.getName() != null) {
            result.setParentNameLabel(parentTaxon.getName().getTitleCache());
        }
    }
    result.setTaxonUuid(taxonBaseUuid);
    result.setClassificationUuid(classificationUuid);
    if (taxonBase.getSec() != null) {
        result.setSecundumUuid(taxonBase.getSec().getUuid());
        result.setSecundumLabel(taxonBase.getSec().getTitleCache());
    }
    result.setTaxonLabel(taxonBase.getTitleCache());
    TaxonName name = taxonBase.getName();
    result.setNameUuid(name.getUuid());
    result.setNameLabel(name.getTitleCache());
    result.setNameWithoutAuthor(name.getNameCache());
    result.setGenusOrUninomial(name.getGenusOrUninomial());
    result.setInfraGenericEpithet(name.getInfraGenericEpithet());
    result.setSpeciesEpithet(name.getSpecificEpithet());
    result.setInfraSpecificEpithet(name.getInfraSpecificEpithet());
    result.setAuthorship(name.getAuthorshipCache());
    Rank rank = name.getRank();
    if (rank != null) {
        result.setRankUuid(rank.getUuid());
        String rankLabel = rank.getAbbreviation();
        if (StringUtils.isBlank(rankLabel)) {
            rankLabel = rank.getLabel();
        }
        result.setRankLabel(rankLabel);
    }
    boolean recursive = false;
    Integer pageSize = null;
    Integer pageIndex = null;
    Pager<TaxonNodeDto> children = taxonNodeService.pageChildNodesDTOs(taxonNodeUuid, recursive, includeUnpublished, doSynonyms, sortMode, pageSize, pageIndex);
    // children
    if (!isSynonym) {
        for (TaxonNodeDto childDto : children.getRecords()) {
            if (doChildren && childDto.getTaxonStatus().equals(TaxonStatus.Accepted)) {
                EntityDTO<Taxon> child = new EntityDTO<Taxon>(childDto.getTaxonUuid(), childDto.getTitleCache());
                result.addChild(child);
            } else if (doSynonyms && childDto.getTaxonStatus().isSynonym()) {
                EntityDTO<Synonym> child = new EntityDTO<>(childDto.getTaxonUuid(), childDto.getTitleCache());
                result.addSynonym(child);
            }
        }
    } else {
        result.setAcceptedTaxonUuid(acceptedTaxonUuid);
        String nameTitel = acceptedTaxon.getName() == null ? null : acceptedTaxon.getName().getTitleCache();
        result.setAcceptedTaxonLabel(acceptedTaxon.getTitleCache());
        result.setAcceptedNameLabel(nameTitel);
    }
    // marked ancestors
    if (ancestorMarkers != null && !ancestorMarkers.isEmpty()) {
        @SuppressWarnings("rawtypes") List<DefinedTermBase> markerTypesTerms = termDao.list(ancestorMarkers, pageSize, null, null, null);
        List<MarkerType> markerTypes = new ArrayList<>();
        for (DefinedTermBase<?> term : markerTypesTerms) {
            if (term.isInstanceOf(MarkerType.class)) {
                markerTypes.add(CdmBase.deproxy(term, MarkerType.class));
            }
        }
        if (!markerTypes.isEmpty()) {
            TaxonNode node = taxonNodeDao.findByUuid(taxonNodeUuid);
            handleAncestorsForMarkersRecursive(result, markerTypes, node);
        }
    }
    return result;
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) ArrayList(java.util.ArrayList) TaxonStatus(eu.etaxonomy.cdm.persistence.dto.TaxonStatus) MarkedEntityDTO(eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO) EntityDTO(eu.etaxonomy.cdm.api.service.dto.EntityDTO) DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) TaxonInContextDTO(eu.etaxonomy.cdm.api.service.dto.TaxonInContextDTO) UUID(java.util.UUID) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) Rank(eu.etaxonomy.cdm.model.name.Rank) EntityNotFoundException(javax.persistence.EntityNotFoundException) MarkerType(eu.etaxonomy.cdm.model.common.MarkerType) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Example 5 with TaxonNodeDto

use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.

the class ClassificationServiceImpl method listChildNodeDtosOfTaxon.

@Override
public List<TaxonNodeDto> listChildNodeDtosOfTaxon(UUID taxonUuid, UUID classificationUuid, UUID subtreeUuid, boolean includeUnpublished, Integer pageSize, Integer pageIndex, TaxonNodeDtoSortMode sortMode, List<String> propertyPaths) throws FilterException {
    Classification classification = dao.load(classificationUuid);
    Taxon taxon = (Taxon) taxonDao.load(taxonUuid);
    TaxonNode subtree = taxonNodeDao.load(subtreeUuid);
    if (subtreeUuid != null && subtree == null) {
        throw new FilterException("Taxon node for subtree filter can not be found in database", true);
    }
    List<TaxonNode> results = dao.listChildrenOf(taxon, classification, subtree, includeUnpublished, pageSize, pageIndex, propertyPaths);
    Comparator<TaxonNodeDto> comparator = sortMode.comparator();
    // TODO order during the hibernate query in the dao?
    List<TaxonNodeDto> dtos = results.stream().map(e -> new TaxonNodeDto(e)).sorted(comparator).collect(Collectors.toList());
    return dtos;
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Classification(eu.etaxonomy.cdm.model.taxon.Classification) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) FilterException(eu.etaxonomy.cdm.exception.FilterException) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

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