Search in sources :

Example 1 with DescriptionBase

use of eu.etaxonomy.cdm.model.description.DescriptionBase 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 DescriptionBase

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

the class DescriptiveDataSetService method removeDescriptionFromDataSet.

private void removeDescriptionFromDataSet(DeleteResult result, DescriptiveDataSet dataSet, DescriptionBase<?> description, RemoveDescriptionsFromDescriptiveDataSetConfigurator config) {
    if (description == null) {
        return;
    }
    boolean success = dataSet.removeDescription(description);
    // remove taxon description with IndividualsAssociation from data set
    result.addDeletedObject(description);
    if (description instanceof SpecimenDescription) {
        @SuppressWarnings({ "unchecked", "cast" }) Set<IndividualsAssociation> // NOTE: don't remove cast as it does not compile on some systems
        associations = (Set<IndividualsAssociation>) dataSet.getDescriptions().stream().flatMap(// put all description element in one stream
        desc -> desc.getElements().stream()).filter(element -> element instanceof IndividualsAssociation).map(ia -> (IndividualsAssociation) ia).collect(Collectors.toSet());
        for (IndividualsAssociation individualsAssociation : associations) {
            if (individualsAssociation.getAssociatedSpecimenOrObservation().equals(description.getDescribedSpecimenOrObservation())) {
                dataSet.removeDescription(individualsAssociation.getInDescription());
                result.addUpdatedObject(individualsAssociation.getInDescription());
            }
        }
    }
    if (description instanceof TaxonDescription) {
        DeleteResult isDeletable = descriptionService.isDeletable(description.getUuid());
        for (CdmBase relatedCdmBase : isDeletable.getRelatedObjects()) {
            if (relatedCdmBase instanceof CdmLinkSource) {
                CdmLinkSource linkSource = (CdmLinkSource) relatedCdmBase;
                if (linkSource.getTarget().equals(this)) {
                }
            }
        }
    }
    if (!config.isOnlyRemoveDescriptionsFromDataSet()) {
        DeleteResult deleteResult = descriptionService.deleteDescription(description);
        result.includeResult(deleteResult);
        result.addUpdatedObject(dataSet);
    } else {
        MergeResult<DescriptiveDataSet> mergeResult = dao.merge(dataSet, true);
        result.addUpdatedObject(mergeResult.getMergedEntity());
    }
    result.setStatus(success ? Status.OK : Status.ERROR);
}
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) Set(java.util.Set) HashSet(java.util.HashSet) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) IndividualsAssociation(eu.etaxonomy.cdm.model.description.IndividualsAssociation) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) CdmLinkSource(eu.etaxonomy.cdm.model.reference.CdmLinkSource)

Example 3 with DescriptionBase

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

the class DescriptiveDataSetService method removeDescriptions.

@Override
@Transactional(readOnly = false)
public DeleteResult removeDescriptions(List<UUID> descriptionUuids, UUID descriptiveDataSetUuid, RemoveDescriptionsFromDescriptiveDataSetConfigurator config) {
    DeleteResult result = new DeleteResult();
    DescriptiveDataSet dataSet = load(descriptiveDataSetUuid);
    List<DescriptionBase> descriptions = descriptionService.load(descriptionUuids, null);
    if (dataSet == null || descriptions == null) {
        result.setError();
    } else {
        for (DescriptionBase<?> description : descriptions) {
            removeDescriptionFromDataSet(result, dataSet, description, config);
        }
    }
    return result;
}
Also used : DescriptionBase(eu.etaxonomy.cdm.model.description.DescriptionBase) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with DescriptionBase

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

the class DescriptiveDataSetService method delete.

@Override
@Transactional(readOnly = false)
public DeleteResult delete(UUID datasetUuid, DeleteDescriptiveDataSetConfigurator config, IProgressMonitor monitor) {
    DescriptiveDataSet dataSet = dao.load(datasetUuid);
    monitor.beginTask("Delete Descriptive Dataset", dataSet.getDescriptions().size() + 1);
    DeleteResult result = new DeleteResult();
    DeleteResult descriptionResult = new DeleteResult();
    if (!dataSet.getDescriptions().isEmpty()) {
        Set<DescriptionBase> descriptions = new HashSet<>();
        ;
        for (DescriptionBase<?> desc : dataSet.getDescriptions()) {
            descriptions.add(desc);
        }
        monitor.subTask("Delete descriptions");
        for (DescriptionBase<?> desc : descriptions) {
            dataSet.removeDescription(desc);
            if (desc instanceof SpecimenDescription && config.isDeleteAllSpecimenDescriptions()) {
                descriptionResult.includeResult(descriptionService.deleteDescription(desc));
            } else if (desc instanceof TaxonDescription) {
                if (desc.getTypes().contains(DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION) && config.isDeleteAllDefaultDescriptions()) {
                    descriptionResult.includeResult(descriptionService.deleteDescription(desc));
                } else if (desc.getTypes().contains(DescriptionType.SECONDARY_DATA) && config.isDeleteAllLiteratureDescriptions()) {
                    descriptionResult.includeResult(descriptionService.deleteDescription(desc));
                } else if (desc.getTypes().contains(DescriptionType.AGGREGATED_STRUC_DESC) && config.isDeleteAllAggregatedDescriptions()) {
                    descriptionResult.includeResult(descriptionService.deleteDescription(desc));
                }
            }
        }
    }
    dao.delete(dataSet);
    monitor.worked(1);
    monitor.done();
    result.includeResult(descriptionResult);
    result.setStatus(Status.OK);
    result.addDeletedObject(dataSet);
    return result;
}
Also used : DescriptionBase(eu.etaxonomy.cdm.model.description.DescriptionBase) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with DescriptionBase

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

the class DescriptionServiceImpl method moveDescriptionElementsToDescription.

@Override
@Transactional(readOnly = false)
public UpdateResult moveDescriptionElementsToDescription(Set<UUID> descriptionElementUUIDs, DescriptionBase targetDescription, boolean isCopy, boolean setNameInSource) {
    Set<DescriptionElementBase> descriptionElements = new HashSet<DescriptionElementBase>();
    for (UUID deUuid : descriptionElementUUIDs) {
        DescriptionElementBase element = descriptionElementDao.load(deUuid);
        if (element != null) {
            descriptionElements.add(element);
        }
    }
    DescriptionBase newTargetDescription;
    if (targetDescription.isPersited()) {
        newTargetDescription = dao.load(targetDescription.getUuid());
    } else {
        if (targetDescription instanceof TaxonDescription) {
            Taxon taxon = (Taxon) taxonDao.load(((TaxonDescription) targetDescription).getTaxon().getUuid());
            newTargetDescription = TaxonDescription.NewInstance(taxon, targetDescription.isImageGallery());
        } else if (targetDescription instanceof TaxonNameDescription) {
            TaxonName name = nameDao.load(((TaxonNameDescription) targetDescription).getTaxonName().getUuid());
            newTargetDescription = TaxonNameDescription.NewInstance(name);
        } else {
            SpecimenOrObservationBase specimen = occurrenceDao.load(((SpecimenDescription) targetDescription).getDescribedSpecimenOrObservation().getUuid());
            newTargetDescription = SpecimenDescription.NewInstance(specimen);
        }
        newTargetDescription.addSources(targetDescription.getSources());
        newTargetDescription.setTitleCache(targetDescription.getTitleCache(), targetDescription.isProtectedTitleCache());
    }
    return moveDescriptionElementsToDescription(descriptionElements, newTargetDescription, isCopy, setNameInSource);
}
Also used : DescriptionBase(eu.etaxonomy.cdm.model.description.DescriptionBase) TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) UUID(java.util.UUID) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DescriptionBase (eu.etaxonomy.cdm.model.description.DescriptionBase)24 DescriptionElementBase (eu.etaxonomy.cdm.model.description.DescriptionElementBase)12 HashSet (java.util.HashSet)10 SpecimenDescription (eu.etaxonomy.cdm.model.description.SpecimenDescription)9 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)9 SpecimenOrObservationBase (eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)9 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)9 ArrayList (java.util.ArrayList)9 Transactional (org.springframework.transaction.annotation.Transactional)9 CdmBase (eu.etaxonomy.cdm.model.common.CdmBase)8 DescriptiveDataSet (eu.etaxonomy.cdm.model.description.DescriptiveDataSet)8 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)7 CategoricalData (eu.etaxonomy.cdm.model.description.CategoricalData)6 State (eu.etaxonomy.cdm.model.description.State)6 HashMap (java.util.HashMap)6 Set (java.util.Set)6 UUID (java.util.UUID)6 IProgressMonitor (eu.etaxonomy.cdm.common.monitor.IProgressMonitor)5 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)5 DescriptionType (eu.etaxonomy.cdm.model.description.DescriptionType)5