Search in sources :

Example 1 with StatisticalMeasurementValue

use of eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue in project cdmlib by cybertaxonomy.

the class DescriptiveDataSetService method addRowWrapperToDataset.

@Override
@Transactional(readOnly = false)
public UpdateResult addRowWrapperToDataset(Collection<SpecimenRowWrapperDTO> wrappers, UUID datasetUuid, boolean addDatasetSource) {
    UpdateResult result = new UpdateResult();
    DescriptiveDataSet dataSet = load(datasetUuid);
    result.setCdmEntity(dataSet);
    List<UUID> taxonUuids = wrappers.stream().map(wrapper -> wrapper.getTaxonNode().getTaxonUuid()).collect(Collectors.toList());
    List<TaxonBase> taxa = taxonService.load(taxonUuids, Arrays.asList(new String[] { "descriptions" }));
    for (SpecimenRowWrapperDTO wrapper : wrappers) {
        Optional<TaxonBase> findAny = taxa.stream().filter(taxon -> taxon.getUuid().equals(wrapper.getTaxonNode().getTaxonUuid())).findAny();
        if (!findAny.isPresent()) {
            result.addException(new IllegalArgumentException("Could not create wrapper for " + wrapper.getSpecimenDto().getLabel()));
            continue;
        }
        Taxon taxon = (Taxon) findAny.get();
        SpecimenOrObservationBase<?> specimen = occurrenceService.load(wrapper.getSpecimenDto().getUuid());
        TaxonDescription taxonDescription = taxon.getDescriptions().stream().filter(desc -> desc.getTypes().contains(DescriptionType.INDIVIDUALS_ASSOCIATION)).findFirst().orElseGet(() -> {
            TaxonDescription td = TaxonDescription.NewInstance(taxon);
            td.addType(DescriptionType.INDIVIDUALS_ASSOCIATION);
            td.setTitleCache("Specimens used by " + dataSet.getTitleCache() + " for " + getTaxonLabel(taxon), true);
            return td;
        });
        IndividualsAssociation association = null;
        for (DescriptionElementBase el : taxonDescription.getElements()) {
            if (el instanceof IndividualsAssociation) {
                IndividualsAssociation indAss = (IndividualsAssociation) el;
                if (indAss.getAssociatedSpecimenOrObservation().getUuid().equals(specimen.getUuid())) {
                    association = indAss;
                }
            }
        }
        if (association == null) {
            association = IndividualsAssociation.NewInstance(specimen);
            taxonDescription.addElement(association);
            taxonService.saveOrUpdate(taxon);
            result.addUpdatedObject(taxon);
        }
        UUID specimenDescriptionUuid = wrapper.getDescription().getDescriptionUuid();
        DescriptionBaseDto descriptionDto = wrapper.getDescription();
        DescriptionBase<?> specimenDescription = descriptionService.load(specimenDescriptionUuid);
        // if description already exist use the loaded one and add changed data otherwise create a new one and add to specimen
        if (specimenDescription == null) {
            specimenDescription = SpecimenDescription.NewInstance(specimen);
            specimenDescription.setUuid(specimenDescriptionUuid);
            List<DescriptionElementDto> elementDtos = descriptionDto.getElements();
            for (DescriptionElementDto elementDto : elementDtos) {
                if (elementDto instanceof CategoricalDataDto) {
                    eu.etaxonomy.cdm.model.description.Character feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, elementDto.getFeatureUuid());
                    CategoricalData data = CategoricalData.NewInstance(feature);
                    for (StateDataDto stateDto : ((CategoricalDataDto) elementDto).getStates()) {
                        State state = DefinedTermBase.getTermByClassAndUUID(State.class, stateDto.getState().getUuid());
                        data.addStateData(state);
                        specimenDescription.addElement(data);
                    }
                }
                if (elementDto instanceof QuantitativeDataDto) {
                    eu.etaxonomy.cdm.model.description.Character feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, elementDto.getFeatureUuid());
                    QuantitativeData data = QuantitativeData.NewInstance(feature);
                    if (((QuantitativeDataDto) elementDto).getMeasurementUnit() != null) {
                        MeasurementUnit unit = DefinedTermBase.getTermByClassAndUUID(MeasurementUnit.class, ((QuantitativeDataDto) elementDto).getMeasurementUnit().getUuid());
                        data.setUnit(unit);
                    }
                    for (StatisticalMeasurementValueDto stateDto : ((QuantitativeDataDto) elementDto).getValues()) {
                        StatisticalMeasure statMeasure = DefinedTermBase.getTermByClassAndUUID(StatisticalMeasure.class, stateDto.getType().getUuid());
                        StatisticalMeasurementValue value = StatisticalMeasurementValue.NewInstance(statMeasure, stateDto.getValue());
                        data.addStatisticalValue(value);
                        specimenDescription.addElement(data);
                    }
                }
            }
        } else {
            List<DescriptionElementDto> elementDtos = descriptionDto.getElements();
            for (DescriptionElementDto elementDto : elementDtos) {
                if (elementDto instanceof CategoricalDataDto) {
                    eu.etaxonomy.cdm.model.description.Character feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, elementDto.getFeatureUuid());
                    List<DescriptionElementBase> uniqueElementList = specimenDescription.getElements().stream().filter(element -> element.getUuid().equals(elementDto.getElementUuid())).collect(Collectors.toList());
                    List<State> allStates = new ArrayList<>();
                    CategoricalData element = null;
                    if (uniqueElementList.size() == 1) {
                        element = HibernateProxyHelper.deproxy(uniqueElementList.get(0), CategoricalData.class);
                    } else {
                        element = CategoricalData.NewInstance(feature);
                    }
                    for (StateDataDto stateDto : ((CategoricalDataDto) elementDto).getStates()) {
                        State state = DefinedTermBase.getTermByClassAndUUID(State.class, stateDto.getState().getUuid());
                        allStates.add(state);
                    }
                    element.setStateDataOnly(allStates);
                }
                if (elementDto instanceof QuantitativeDataDto) {
                    eu.etaxonomy.cdm.model.description.Character feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, elementDto.getFeatureUuid());
                    QuantitativeData data = QuantitativeData.NewInstance(feature);
                    if (((QuantitativeDataDto) elementDto).getMeasurementUnit() != null) {
                        MeasurementUnit unit = DefinedTermBase.getTermByClassAndUUID(MeasurementUnit.class, ((QuantitativeDataDto) elementDto).getMeasurementUnit().getUuid());
                        data.setUnit(unit);
                    }
                    for (StatisticalMeasurementValueDto stateDto : ((QuantitativeDataDto) elementDto).getValues()) {
                        StatisticalMeasure statMeasure = DefinedTermBase.getTermByClassAndUUID(StatisticalMeasure.class, stateDto.getType().getUuid());
                        StatisticalMeasurementValue value = StatisticalMeasurementValue.NewInstance(statMeasure, stateDto.getValue());
                        data.addStatisticalValue(value);
                        specimenDescription.addElement(data);
                    }
                }
            }
        }
        if (addDatasetSource) {
            for (IdentifiableSource source : dataSet.getSources()) {
                try {
                    specimenDescription.addSource(source.clone());
                } catch (CloneNotSupportedException e) {
                // nothing
                }
            }
        }
        // add specimen description to data set
        specimenDescription.addDescriptiveDataSet(dataSet);
        // add taxon description with IndividualsAssociation to the specimen to data set
        taxonDescription.addDescriptiveDataSet(dataSet);
        result.addUpdatedObject(specimen);
        result.addUpdatedObject(specimenDescription);
        result.addUpdatedObject(taxonDescription);
    }
    saveOrUpdate(dataSet);
    return result;
}
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) StateDataDto(eu.etaxonomy.cdm.api.service.dto.StateDataDto) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) ArrayList(java.util.ArrayList) QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) QuantitativeDataDto(eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto) StatisticalMeasure(eu.etaxonomy.cdm.model.description.StatisticalMeasure) CategoricalDataDto(eu.etaxonomy.cdm.api.service.dto.CategoricalDataDto) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource) UUID(java.util.UUID) StatisticalMeasurementValue(eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue) MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) DescriptionBaseDto(eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto) SpecimenRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) DescriptionElementDto(eu.etaxonomy.cdm.api.service.dto.DescriptionElementDto) StatisticalMeasurementValueDto(eu.etaxonomy.cdm.api.service.dto.StatisticalMeasurementValueDto) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) IndividualsAssociation(eu.etaxonomy.cdm.model.description.IndividualsAssociation) State(eu.etaxonomy.cdm.model.description.State) CategoricalData(eu.etaxonomy.cdm.model.description.CategoricalData) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with StatisticalMeasurementValue

use of eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue in project cdmlib by cybertaxonomy.

the class DescriptionServiceImpl method mergeDescriptions.

@Override
@Transactional(readOnly = false)
public UpdateResult mergeDescriptions(Collection<DescriptionBaseDto> descriptions, UUID descriptiveDataSetUuid) {
    UpdateResult result = new UpdateResult();
    DescriptiveDataSet dataSet = descriptiveDataSetDao.load(descriptiveDataSetUuid);
    Set<DescriptionBase> descriptionsOfDataSet = dataSet.getDescriptions();
    HashMap<UUID, Set<DescriptionBase>> descriptionSpecimenMap = new HashMap<>();
    Set<DescriptionBase> specimenDescriptions;
    for (DescriptionBase<?> descriptionBase : descriptionsOfDataSet) {
        if (descriptionBase.getDescribedSpecimenOrObservation() != null) {
            specimenDescriptions = descriptionSpecimenMap.get(descriptionBase.getDescribedSpecimenOrObservation().getUuid());
            if (specimenDescriptions == null) {
                specimenDescriptions = new HashSet<>();
            }
            specimenDescriptions.add(descriptionBase);
            descriptionSpecimenMap.put(descriptionBase.getDescribedSpecimenOrObservation().getUuid(), specimenDescriptions);
        }
        if (descriptionBase instanceof TaxonDescription) {
            specimenDescriptions = descriptionSpecimenMap.get(((TaxonDescription) descriptionBase).getTaxon().getUuid());
            if (specimenDescriptions == null) {
                specimenDescriptions = new HashSet<>();
            }
            specimenDescriptions.add(descriptionBase);
            descriptionSpecimenMap.put(((TaxonDescription) descriptionBase).getTaxon().getUuid(), specimenDescriptions);
        }
        if (descriptionBase instanceof TaxonNameDescription) {
            specimenDescriptions = descriptionSpecimenMap.get(((TaxonNameDescription) descriptionBase).getTaxonName().getUuid());
            if (specimenDescriptions == null) {
                specimenDescriptions = new HashSet<>();
            }
            specimenDescriptions.add(descriptionBase);
            descriptionSpecimenMap.put(((TaxonNameDescription) descriptionBase).getTaxonName().getUuid(), specimenDescriptions);
        }
    }
    MergeResult<DescriptionBase> mergeResult = null;
    for (DescriptionBaseDto descDto : descriptions) {
        UUID descriptionUUID = descDto.getDescriptionUuid();
        DescriptionBase<?> description = load(descriptionUUID);
        UUID describedObjectUuid = null;
        if (description instanceof SpecimenDescription) {
            describedObjectUuid = descDto.getSpecimenDto().getUuid();
        } else if (description instanceof TaxonDescription) {
            describedObjectUuid = descDto.getTaxonDto().getUuid();
        } else if (description instanceof TaxonNameDescription) {
            describedObjectUuid = descDto.getNameDto().getUuid();
        }
        Set<DescriptionBase> descSpecimen = descriptionSpecimenMap.get(describedObjectUuid);
        if (descSpecimen != null) {
            // TODO: elements are Dtos now, no cdm entities, needs to get the value and replace or create new description element
            Set<DescriptionElementDto> elements = new HashSet<>();
            for (Object element : descDto.getElements()) {
                elements.add((DescriptionElementDto) element);
            }
            DescriptionBase<?> desc = null;
            for (DescriptionBase<?> tempDesc : descSpecimen) {
                if (tempDesc.getUuid().equals(descDto.getDescriptionUuid())) {
                    desc = tempDesc;
                    break;
                }
            }
            Set<DescriptionElementBase> removeElements = new HashSet<>();
            Set<DescriptionElementBase> descriptionElements = desc.getElements();
            for (DescriptionElementBase elementBase : descriptionElements) {
                UUID descElementUuid = elementBase.getUuid();
                if (descElementUuid != null) {
                    List<DescriptionElementDto> equalUuidsElements = elements.stream().filter(e -> e != null && e.getElementUuid() != null && e.getElementUuid().equals(descElementUuid)).collect(Collectors.toList());
                    if (equalUuidsElements.size() == 0 || (equalUuidsElements.size() == 1 && equalUuidsElements.get(0) instanceof QuantitativeDataDto && ((QuantitativeDataDto) equalUuidsElements.get(0)).getValues().isEmpty())) {
                        removeElements.add(elementBase);
                    }
                }
            }
            if (!removeElements.isEmpty()) {
                for (DescriptionElementBase el : removeElements) {
                    desc.removeElement(el);
                }
            }
            for (DescriptionElementDto descElement : elements) {
                if (descElement == null) {
                    continue;
                }
                UUID descElementUuid = descElement.getElementUuid();
                if (descElement instanceof CategoricalDataDto && ((CategoricalDataDto) descElement).getStates().isEmpty() || descElement instanceof QuantitativeDataDto && ((QuantitativeDataDto) descElement).getValues().isEmpty()) {
                    continue;
                }
                List<DescriptionElementBase> equalUuidsElements = descriptionElements.stream().filter(e -> e.getUuid().equals(descElementUuid)).collect(Collectors.toList());
                eu.etaxonomy.cdm.model.description.Feature feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Feature.class, descElement.getFeatureUuid());
                if (feature == null) {
                    feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, descElement.getFeatureUuid());
                }
                if (equalUuidsElements.size() == 0) {
                    if (descElement instanceof CategoricalDataDto) {
                        CategoricalData elementBase = CategoricalData.NewInstance(feature);
                        List<StateDataDto> stateDtos = ((CategoricalDataDto) descElement).getStates();
                        for (StateDataDto dataDto : stateDtos) {
                            // create new statedata
                            State newState = DefinedTermBase.getTermByClassAndUUID(State.class, dataDto.getState().getUuid());
                            StateData newStateData = StateData.NewInstance(newState);
                            elementBase.addStateData(newStateData);
                        }
                        desc.addElement(elementBase);
                    }
                    if (descElement instanceof QuantitativeDataDto) {
                        QuantitativeData data = QuantitativeData.NewInstance(feature);
                        if (((QuantitativeDataDto) descElement).getMeasurementUnit() != null) {
                            MeasurementUnit unit = DefinedTermBase.getTermByClassAndUUID(MeasurementUnit.class, ((QuantitativeDataDto) descElement).getMeasurementUnit().getUuid());
                            data.setUnit(unit);
                        }
                        Set<StatisticalMeasurementValue> statisticalValues = new HashSet<>();
                        Set<StatisticalMeasurementValueDto> valueDtos = ((QuantitativeDataDto) descElement).getValues();
                        data.getStatisticalValues().clear();
                        for (StatisticalMeasurementValueDto dataDto : valueDtos) {
                            // create new statedata
                            StatisticalMeasurementValue newStatisticalMeasurement = StatisticalMeasurementValue.NewInstance(DefinedTermBase.getTermByClassAndUUID(StatisticalMeasure.class, dataDto.getType().getUuid()), dataDto.getValue());
                            statisticalValues.add(newStatisticalMeasurement);
                            data.addStatisticalValue(newStatisticalMeasurement);
                        }
                        // data.getStatisticalValues().addAll(statisticalValues);
                        data = StructuredDescriptionAggregation.handleMissingMinOrMax(data, MissingMinimumMode.MinToZero, MissingMaximumMode.MaxToMin);
                        desc.addElement(data);
                    }
                // create new element
                } else {
                    DescriptionElementBase elementBase = equalUuidsElements.get(0);
                    if (elementBase.isInstanceOf(CategoricalData.class)) {
                        CategoricalData data = HibernateProxyHelper.deproxy(elementBase, CategoricalData.class);
                        List<StateData> states = new ArrayList<>(data.getStateData());
                        List<StateDataDto> stateDtos = ((CategoricalDataDto) descElement).getStates();
                        data.getStateData().clear();
                        if (stateDtos.isEmpty()) {
                            desc.removeElement(data);
                        } else {
                            for (StateDataDto dataDto : stateDtos) {
                                State newState = DefinedTermBase.getTermByClassAndUUID(State.class, dataDto.getState().getUuid());
                                StateData newStateData = StateData.NewInstance(newState);
                                data.addStateData(newStateData);
                            }
                        }
                    } else if (elementBase.isInstanceOf(QuantitativeData.class)) {
                        QuantitativeData data = HibernateProxyHelper.deproxy(elementBase, QuantitativeData.class);
                        Set<StatisticalMeasurementValue> statisticalValues = new HashSet<>();
                        if (((QuantitativeDataDto) descElement).getMeasurementUnit() != null) {
                            MeasurementUnit unit = DefinedTermBase.getTermByClassAndUUID(MeasurementUnit.class, ((QuantitativeDataDto) descElement).getMeasurementUnit().getUuid());
                            if (data.getUnit() == null || (data.getUnit() != null && !data.getUnit().equals(unit))) {
                                data.setUnit(unit);
                            }
                        }
                        Set<StatisticalMeasurementValueDto> valueDtos = ((QuantitativeDataDto) descElement).getValues();
                        data.getStatisticalValues().clear();
                        if (valueDtos.isEmpty()) {
                            desc.removeElement(data);
                        } else {
                            for (StatisticalMeasurementValueDto dataDto : valueDtos) {
                                // create new statedata
                                StatisticalMeasure statMeasure = DefinedTermBase.getTermByClassAndUUID(StatisticalMeasure.class, dataDto.getType().getUuid());
                                StatisticalMeasurementValue newStatisticalMeasurement = StatisticalMeasurementValue.NewInstance(statMeasure, dataDto.getValue());
                                statisticalValues.add(newStatisticalMeasurement);
                                data.addStatisticalValue(newStatisticalMeasurement);
                            }
                            // data.getStatisticalValues().addAll(statisticalValues);
                            data = StructuredDescriptionAggregation.handleMissingMinOrMax(data, MissingMinimumMode.MinToZero, MissingMaximumMode.MaxToMin);
                        }
                    }
                }
            // remove deleted elements
            }
            descriptionSpecimenMap.get(describedObjectUuid).add(desc);
            description = desc;
        }
        try {
            if (description != null) {
                mergeResult = dao.merge(description, true);
                result.addUpdatedObject(mergeResult.getMergedEntity());
            }
        // if (description instanceof SpecimenDescription){
        // result.addUpdatedObject(mergeResult.getMergedEntity().getDescribedSpecimenOrObservation());
        // }else if (description instanceof TaxonDescription){
        // result.addUpdatedObject(((TaxonDescription)mergeResult.getMergedEntity()).getTaxon());
        // }else if (description instanceof TaxonNameDescription){
        // result.addUpdatedObject(((TaxonNameDescription)mergeResult.getMergedEntity()).getTaxonName());
        // }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return result;
}
Also used : DescriptionBase(eu.etaxonomy.cdm.model.description.DescriptionBase) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) TermVocabulary(eu.etaxonomy.cdm.model.term.TermVocabulary) Pager(eu.etaxonomy.cdm.api.service.pager.Pager) TermDto(eu.etaxonomy.cdm.persistence.dto.TermDto) IProgressMonitor(eu.etaxonomy.cdm.common.monitor.IProgressMonitor) FeatureDto(eu.etaxonomy.cdm.persistence.dto.FeatureDto) StatisticalMeasurementValueDto(eu.etaxonomy.cdm.api.service.dto.StatisticalMeasurementValueDto) DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) Autowired(org.springframework.beans.factory.annotation.Autowired) StructuredDescriptionAggregation(eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregation) CategoricalData(eu.etaxonomy.cdm.model.description.CategoricalData) IDescriptionDao(eu.etaxonomy.cdm.persistence.dao.description.IDescriptionDao) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto) Logger(org.apache.log4j.Logger) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) ITermNodeDao(eu.etaxonomy.cdm.persistence.dao.term.ITermNodeDao) QuantitativeDataDto(eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto) DescriptionBaseDto(eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto) Map(java.util.Map) IDescriptionElementDao(eu.etaxonomy.cdm.persistence.dao.description.IDescriptionElementDao) Query(org.hibernate.Query) PagerUtils(eu.etaxonomy.cdm.api.service.pager.PagerUtils) PresenceAbsenceTerm(eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm) ReferencedObjectUndeletableException(eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException) ITermTreeDao(eu.etaxonomy.cdm.persistence.dao.term.ITermTreeDao) ICdmTarget(eu.etaxonomy.cdm.model.reference.ICdmTarget) ITaxonDao(eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao) 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) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm) QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) Collectors(java.util.stream.Collectors) List(java.util.List) DescriptionElementSource(eu.etaxonomy.cdm.model.description.DescriptionElementSource) MissingMaximumMode(eu.etaxonomy.cdm.api.service.description.MissingMaximumMode) DescriptionType(eu.etaxonomy.cdm.model.description.DescriptionType) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) DescriptionBase(eu.etaxonomy.cdm.model.description.DescriptionBase) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) IDefinedTermDao(eu.etaxonomy.cdm.persistence.dao.term.IDefinedTermDao) MergeResult(eu.etaxonomy.cdm.persistence.dto.MergeResult) MissingMinimumMode(eu.etaxonomy.cdm.api.service.description.MissingMinimumMode) IIdentifiableEntityCacheStrategy(eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy) TextData(eu.etaxonomy.cdm.model.description.TextData) ITaxonNameDao(eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao) StatisticalMeasure(eu.etaxonomy.cdm.model.description.StatisticalMeasure) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) HashMap(java.util.HashMap) MicroFormatQuantitativeDescriptionBuilder(eu.etaxonomy.cdm.format.description.MicroFormatQuantitativeDescriptionBuilder) Media(eu.etaxonomy.cdm.model.media.Media) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) TermTree(eu.etaxonomy.cdm.model.term.TermTree) Service(org.springframework.stereotype.Service) StateData(eu.etaxonomy.cdm.model.description.StateData) IOccurrenceDao(eu.etaxonomy.cdm.persistence.dao.occurrence.IOccurrenceDao) State(eu.etaxonomy.cdm.model.description.State) StatisticalMeasurementValue(eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue) IDescriptiveDataSetDao(eu.etaxonomy.cdm.persistence.dao.description.IDescriptiveDataSetDao) IStatisticalMeasurementValueDao(eu.etaxonomy.cdm.persistence.dao.description.IStatisticalMeasurementValueDao) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) Iterator(java.util.Iterator) Annotation(eu.etaxonomy.cdm.model.common.Annotation) DescriptionElementDto(eu.etaxonomy.cdm.api.service.dto.DescriptionElementDto) TaxonDistributionDTO(eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO) AnnotationType(eu.etaxonomy.cdm.model.common.AnnotationType) MarkerType(eu.etaxonomy.cdm.model.common.MarkerType) SortableTaxonNodeQueryResult(eu.etaxonomy.cdm.persistence.dto.SortableTaxonNodeQueryResult) HibernateProxyHelper(eu.etaxonomy.cdm.hibernate.HibernateProxyHelper) Marker(eu.etaxonomy.cdm.model.common.Marker) AbstractPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.AbstractPagerImpl) MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) CategoricalDataDto(eu.etaxonomy.cdm.api.service.dto.CategoricalDataDto) ITermVocabularyDao(eu.etaxonomy.cdm.persistence.dao.term.ITermVocabularyDao) Language(eu.etaxonomy.cdm.model.common.Language) ITaxonNodeDao(eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao) Feature(eu.etaxonomy.cdm.model.description.Feature) DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) Transactional(org.springframework.transaction.annotation.Transactional) TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) StateDataDto(eu.etaxonomy.cdm.api.service.dto.StateDataDto) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) ArrayList(java.util.ArrayList) QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) QuantitativeDataDto(eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto) StatisticalMeasure(eu.etaxonomy.cdm.model.description.StatisticalMeasure) CategoricalDataDto(eu.etaxonomy.cdm.api.service.dto.CategoricalDataDto) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) UUID(java.util.UUID) StatisticalMeasurementValue(eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue) HashSet(java.util.HashSet) MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) DescriptionBaseDto(eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto) TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) DescriptionElementDto(eu.etaxonomy.cdm.api.service.dto.DescriptionElementDto) StateData(eu.etaxonomy.cdm.model.description.StateData) ReferencedObjectUndeletableException(eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException) StatisticalMeasurementValueDto(eu.etaxonomy.cdm.api.service.dto.StatisticalMeasurementValueDto) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) State(eu.etaxonomy.cdm.model.description.State) CategoricalData(eu.etaxonomy.cdm.model.description.CategoricalData) Feature(eu.etaxonomy.cdm.model.description.Feature) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with StatisticalMeasurementValue

use of eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue in project cdmlib by cybertaxonomy.

the class DescriptiveDataSetServiceTest method addQuantitativeData.

private void addQuantitativeData(DescriptionBase<?> desc, UUID uuidFeature, StatisticalMeasure type, BigDecimal value) {
    Feature feature = (Feature) termService.find(uuidFeature);
    QuantitativeData qd = QuantitativeData.NewInstance(feature);
    StatisticalMeasurementValue smv = StatisticalMeasurementValue.NewInstance(type, value);
    qd.addStatisticalValue(smv);
    desc.addElement(qd);
}
Also used : QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) Feature(eu.etaxonomy.cdm.model.description.Feature) StatisticalMeasurementValue(eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue)

Example 4 with StatisticalMeasurementValue

use of eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue in project cdmlib by cybertaxonomy.

the class FullCoverageDataGenerator method createDescriptions.

private void createDescriptions(List<CdmBase> cdmBases) {
    TermVocabulary<AnnotationType> voc = TermVocabulary.NewInstance(TermType.AnnotationType, AnnotationType.class, "my termVoc desc", "myTerm voc", "mtv", URI.create("http://www.abc.de"));
    handleIdentifiableEntity(voc);
    cdmBases.add(voc);
    Representation rep = voc.getRepresentations().iterator().next();
    handleAnnotatableEntity(rep);
    // Representation engRep = Language.ENGLISH().getRepresentations().iterator().next();
    // handleAnnotatableEntity(engRep);
    // cdmBases.add(engRep);  //needed?
    // Categorical data
    State state = State.NewInstance("Test state", "state", "st.");
    state.addMedia(Media.NewInstance());
    cdmBases.add(state);
    CategoricalData categoricalData = CategoricalData.NewInstance(state, Feature.CONSERVATION());
    StateData stateData = categoricalData.getStateData().get(0);
    stateData.addModifier(DefinedTerm.SEX_FEMALE());
    handleAnnotatableEntity(categoricalData);
    State nextState = State.NewInstance();
    cdmBases.add(nextState);
    StateData stateData2 = StateData.NewInstance(nextState);
    stateData2.setCount(3);
    stateData2.putModifyingText(Language.ENGLISH(), "State2 modifying text");
    categoricalData.addStateData(stateData2);
    categoricalData.setOrderRelevant(true);
    // Quantitative data
    Feature leaveLength = Feature.NewInstance("Leave length description", "leave length", "l.l.");
    cdmBases.add(leaveLength);
    leaveLength.setSupportsQuantitativeData(true);
    QuantitativeData quantitativeData = QuantitativeData.NewInstance(leaveLength);
    MeasurementUnit measurementUnit = MeasurementUnit.NewInstance("Measurement Unit", "munit", null);
    cdmBases.add(measurementUnit);
    quantitativeData.setUnit(measurementUnit);
    quantitativeData.setUuid(UUID.fromString("920fce5e-4913-4a3f-89bf-1611f5081869"));
    StatisticalMeasurementValue statisticalMeasurementValue = quantitativeData.setAverage(new BigDecimal("22.9215"), null);
    handleAnnotatableEntity(quantitativeData);
    handleIdentifiableEntity(measurementUnit);
    DefinedTerm valueModifier = DefinedTerm.NewModifierInstance("about", "about", null);
    statisticalMeasurementValue.addModifier(valueModifier);
    cdmBases.add(valueModifier);
    // Feature
    TermVocabulary<DefinedTerm> recommendedModifierEnumeration = TermVocabulary.NewInstance(TermType.Modifier, DefinedTerm.class);
    leaveLength.addRecommendedModifierEnumeration(recommendedModifierEnumeration);
    cdmBases.add(recommendedModifierEnumeration);
    TermVocabulary<State> supportedCategoricalEnumeration = TermVocabulary.NewInstance(TermType.State, State.class);
    leaveLength.addSupportedCategoricalEnumeration(supportedCategoricalEnumeration);
    cdmBases.add(supportedCategoricalEnumeration);
    leaveLength.addRecommendedMeasurementUnit(measurementUnit);
    leaveLength.addRecommendedStatisticalMeasure(StatisticalMeasure.AVERAGE());
    // CommonTaxonName
    CommonTaxonName commonTaxonName = CommonTaxonName.NewInstance("common name", Language.ENGLISH(), Country.UNITEDSTATESOFAMERICA());
    handleAnnotatableEntity(commonTaxonName);
    // TextData
    TextData textData = TextData.NewInstance(Feature.DIAGNOSIS());
    Language eng = Language.ENGLISH();
    textData.putText(eng, "My text data");
    LanguageString languageString = textData.getLanguageText(eng);
    Taxon referencedTaxon = getTaxon();
    cdmBases.add(referencedTaxon);
    languageString.addIntextReference(IntextReference.NewInstance(referencedTaxon, languageString, 2, 5));
    textData.putModifyingText(eng, "nice diagnosis");
    handleAnnotatableEntity(textData);
    handleAnnotatableEntity(languageString);
    TextFormat format = TextFormat.NewInstance("format", "format", null);
    textData.setFormat(format);
    cdmBases.add(format);
    handleAnnotatableEntity(format);
    // IndividualsAssociation
    DerivedUnit specimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
    IndividualsAssociation indAssoc = IndividualsAssociation.NewInstance(specimen);
    indAssoc.putDescription(Language.ENGLISH(), "description for individuals association");
    handleAnnotatableEntity(indAssoc);
    // TaxonInteraction
    TaxonInteraction taxonInteraction = TaxonInteraction.NewInstance(Feature.HOSTPLANT());
    taxonInteraction.putDescription(Language.ENGLISH(), "interaction description");
    handleAnnotatableEntity(taxonInteraction);
    // Distribution
    NamedArea inCountryArea = NamedArea.NewInstance("My area in a country", "my area", "ma");
    inCountryArea.addCountry(Country.TURKEYREPUBLICOF());
    cdmBases.add(inCountryArea);
    Distribution distribution = Distribution.NewInstance(inCountryArea, PresenceAbsenceTerm.CULTIVATED());
    handleAnnotatableEntity(distribution);
    // TemporalData
    Feature floweringSeason = Feature.FLOWERING_PERIOD();
    TemporalData temporalData = TemporalData.NewInstance(ExtendedTimePeriod.NewExtendedMonthInstance(5, 8, 4, 9));
    temporalData.setFeature(floweringSeason);
    temporalData.getPeriod().setFreeText("My temporal text");
    handleAnnotatableEntity(temporalData);
    temporalData.setUuid(UUID.fromString("9a1c91c0-fc58-4310-94cb-8c26115985d3"));
    Taxon taxon = getTaxon();
    TaxonDescription taxonDescription = TaxonDescription.NewInstance(taxon);
    taxonDescription.addElements(categoricalData, quantitativeData, textData, commonTaxonName, taxonInteraction, indAssoc, distribution, temporalData);
    DerivedUnit describedSpecimenOrObservation = DerivedUnit.NewInstance(SpecimenOrObservationType.DerivedUnit);
    taxonDescription.setDescribedSpecimenOrObservation(describedSpecimenOrObservation);
    taxonDescription.addScope(DefinedTerm.SEX_FEMALE());
    taxonDescription.addGeoScope(Country.GERMANY());
    handleIdentifiableEntity(taxonDescription);
    taxon.addAggregationSource(taxonDescription);
    cdmBases.add(taxon);
    // DescriptionElmenetBase  + source
    textData.addMedia(Media.NewInstance());
    textData.addModifier(DefinedTerm.SEX_HERMAPHRODITE());
    textData.putModifyingText(Language.ENGLISH(), "no modification");
    textData.setTimeperiod(TimePeriodParser.parseString("1970-1980"));
    Reference ref = ReferenceFactory.newArticle();
    DescriptionElementSource source = textData.addSource(OriginalSourceType.Import, "22", "taxon description table", ref, "detail");
    source.setNameUsedInSource(TaxonNameFactory.NewBotanicalInstance(Rank.GENUS()));
    ExternalLink link = ExternalLink.NewInstance(ExternalLinkType.WebSite, URI.create("http://wwww.abd.de"), "Somehow useful link", 445);
    source.addLink(link);
    handleAnnotatableEntity(source);
    // as long as it still exists
    taxonDescription.addDescriptionSource(ref);
    // Specimen description
    SpecimenOrObservationBase<?> describedSpecimen = getSpecimen();
    SpecimenDescription specDesc = SpecimenDescription.NewInstance(specimen);
    cdmBases.add(describedSpecimen);
    handleAnnotatableEntity(specDesc);
    // Name description
    TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
    TaxonNameDescription nameDesc = TaxonNameDescription.NewInstance(name);
    cdmBases.add(name);
    handleAnnotatableEntity(nameDesc);
    // Feature Tree
    TermTree<Feature> featureTree = TermTree.NewFeatureInstance();
    // featureTree
    TermNode<Feature> descriptionTermNode = featureTree.getRoot().addChild(Feature.DESCRIPTION());
    TermNode<Feature> leaveLengthNode = descriptionTermNode.addChild(leaveLength);
    handleIdentifiableEntity(featureTree);
    State inapplicableState = State.NewInstance("inapplicableState", "inapplicableState", null);
    State applicableState = State.NewInstance("only applicable state", "only applicable state", null);
    cdmBases.add(applicableState);
    cdmBases.add(inapplicableState);
    // this is semantically not correct, should be a parent feature
    leaveLengthNode.addInapplicableState(leaveLength, inapplicableState);
    leaveLengthNode.addApplicableState(leaveLength, applicableState);
    cdmBases.add(featureTree);
    cdmBases.add(leaveLengthNode);
    // DescriptiveDataSet
    DescriptiveDataSet descriptiveDataSet = DescriptiveDataSet.NewInstance();
    descriptiveDataSet.addDescription(taxonDescription);
    descriptiveDataSet.setLabel("My Descriptive Dataset");
    descriptiveDataSet.getDescriptiveSystem();
    handleAnnotatableEntity(descriptiveDataSet);
    descriptiveDataSet.addGeoFilterArea(Country.GERMANY());
    Classification classification = Classification.NewInstance("DescriptiveDataSet subtree classification");
    Taxon subTreeTaxon = getTaxon();
    TaxonNode subtree = classification.addChildTaxon(subTreeTaxon, null, null);
    descriptiveDataSet.addTaxonSubtree(subtree);
    cdmBases.add(classification);
    cdmBases.add(subtree);
    // polytomous keys
    Taxon coveredTaxon = Taxon.NewInstance(name, null);
    PolytomousKey key = PolytomousKey.NewTitledInstance("My Polykey");
    handleIdentificationKey(key, taxon, coveredTaxon);
    key.setStartNumber(10);
    PolytomousKeyNode firstChildNode = PolytomousKeyNode.NewInstance("Green", "What is the leave length?", coveredTaxon, leaveLength);
    key.getRoot().addChild(firstChildNode);
    PolytomousKeyNode secondChildNode = PolytomousKeyNode.NewInstance("234");
    firstChildNode.addChild(secondChildNode);
    PolytomousKey subkey = PolytomousKey.NewTitledInstance("Sub-key");
    firstChildNode.setSubkey(subkey);
    PolytomousKeyNode subKeyNode = PolytomousKeyNode.NewInstance("sub key couplet");
    subkey.getRoot().addChild(subKeyNode);
    secondChildNode.setOtherNode(subKeyNode);
    secondChildNode.putModifyingText(Language.GERMAN(), "manchmal");
    cdmBases.add(key);
    cdmBases.add(subkey);
    MediaKey mediaKey = MediaKey.NewInstance();
    mediaKey.addKeyRepresentation(Representation.NewInstance("Media Key Representation", "media key", null, Language.ENGLISH()));
    handleIdentificationKey(mediaKey, taxon, coveredTaxon);
    MultiAccessKey multiAccessKey = MultiAccessKey.NewInstance();
    handleIdentificationKey(multiAccessKey, taxon, coveredTaxon);
    cdmBases.add(mediaKey);
    cdmBases.add(multiAccessKey);
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) Feature(eu.etaxonomy.cdm.model.description.Feature) AnnotationType(eu.etaxonomy.cdm.model.common.AnnotationType) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) MediaKey(eu.etaxonomy.cdm.model.description.MediaKey) Language(eu.etaxonomy.cdm.model.common.Language) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) TextData(eu.etaxonomy.cdm.model.description.TextData) Classification(eu.etaxonomy.cdm.model.taxon.Classification) TextFormat(eu.etaxonomy.cdm.model.description.TextFormat) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) StatisticalMeasurementValue(eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) Reference(eu.etaxonomy.cdm.model.reference.Reference) IntextReference(eu.etaxonomy.cdm.model.common.IntextReference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonInteraction(eu.etaxonomy.cdm.model.description.TaxonInteraction) MultiAccessKey(eu.etaxonomy.cdm.model.description.MultiAccessKey) Representation(eu.etaxonomy.cdm.model.term.Representation) MediaRepresentation(eu.etaxonomy.cdm.model.media.MediaRepresentation) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) StateData(eu.etaxonomy.cdm.model.description.StateData) BigDecimal(java.math.BigDecimal) ExternalLink(eu.etaxonomy.cdm.model.media.ExternalLink) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) State(eu.etaxonomy.cdm.model.description.State) IndividualsAssociation(eu.etaxonomy.cdm.model.description.IndividualsAssociation) CategoricalData(eu.etaxonomy.cdm.model.description.CategoricalData) Distribution(eu.etaxonomy.cdm.model.description.Distribution) TemporalData(eu.etaxonomy.cdm.model.description.TemporalData) DescriptionElementSource(eu.etaxonomy.cdm.model.description.DescriptionElementSource) PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm)

Example 5 with StatisticalMeasurementValue

use of eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue in project cdmlib by cybertaxonomy.

the class NaturalLanguageGeneratorTest method setUp.

@Before
public void setUp() throws Exception {
    // set up your test objects here
    INonViralName tnb = TaxonNameFactory.NewNonViralInstance(null);
    Taxon taxon = Taxon.NewInstance(tnb, null);
    description = TaxonDescription.NewInstance(taxon);
    featureTree = TermTree.NewFeatureInstance();
    TermNode<Feature> root = featureTree.getRoot();
    String[][][] tableStrings = { { { "a", "b" } }, { { "a1", "a2" }, { "b1" } } };
    buildBranches(root, tableStrings, 0, 2, 0);
    for (Iterator<Feature> f = featureSet.iterator(); f.hasNext(); ) {
        Feature feature = f.next();
        CategoricalData cg = CategoricalData.NewInstance();
        cg.setFeature(feature);
        State state = State.NewInstance(null, feature.getLabel() + "state", null);
        StateData stateData = StateData.NewInstance();
        stateData.setState(state);
        cg.addStateData(stateData);
        description.addElement(cg);
    }
    Feature qFeature = Feature.NewInstance(null, "c", null);
    QuantitativeData qd = QuantitativeData.NewInstance();
    MeasurementUnit munit = MeasurementUnit.NewInstance(null, "mm", null);
    StatisticalMeasurementValue smv = StatisticalMeasurementValue.NewInstance();
    smv.setType(StatisticalMeasure.AVERAGE());
    smv.setValue(new BigDecimal(12));
    qd.addStatisticalValue(smv);
    qd.setUnit(munit);
    qd.setFeature(qFeature);
    description.addElement(qd);
    root.addChild(qFeature);
}
Also used : INonViralName(eu.etaxonomy.cdm.model.name.INonViralName) MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) Feature(eu.etaxonomy.cdm.model.description.Feature) StateData(eu.etaxonomy.cdm.model.description.StateData) BigDecimal(java.math.BigDecimal) State(eu.etaxonomy.cdm.model.description.State) CategoricalData(eu.etaxonomy.cdm.model.description.CategoricalData) StatisticalMeasurementValue(eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue) Before(org.junit.Before)

Aggregations

StatisticalMeasurementValue (eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue)16 Feature (eu.etaxonomy.cdm.model.description.Feature)11 QuantitativeData (eu.etaxonomy.cdm.model.description.QuantitativeData)11 MeasurementUnit (eu.etaxonomy.cdm.model.description.MeasurementUnit)6 StatisticalMeasure (eu.etaxonomy.cdm.model.description.StatisticalMeasure)6 CategoricalData (eu.etaxonomy.cdm.model.description.CategoricalData)5 BigDecimal (java.math.BigDecimal)5 Language (eu.etaxonomy.cdm.model.common.Language)4 State (eu.etaxonomy.cdm.model.description.State)4 StateData (eu.etaxonomy.cdm.model.description.StateData)4 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)4 TextData (eu.etaxonomy.cdm.model.description.TextData)4 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 DescriptionElementBase (eu.etaxonomy.cdm.model.description.DescriptionElementBase)3 DescriptiveDataSet (eu.etaxonomy.cdm.model.description.DescriptiveDataSet)3 SpecimenDescription (eu.etaxonomy.cdm.model.description.SpecimenDescription)3 NamedArea (eu.etaxonomy.cdm.model.location.NamedArea)3 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)3