Search in sources :

Example 1 with TaxonNameDescription

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

the class TaxonNameTest method testAddAndRemoveDescriptionTaxonNameDescription.

@Test
public void testAddAndRemoveDescriptionTaxonNameDescription() {
    TaxonNameDescription description = TaxonNameDescription.NewInstance();
    // test if reflection method in addDescription() works
    nameBase2.addDescription(description);
    assertTrue("The description has not properly been added to the taxonName", nameBase2.getDescriptions().contains(description));
    assertEquals("The taxon name has not properly been added to the description", nameBase2, description.getTaxonName());
    // test if reflection method in removeDescription() works
    nameBase2.removeDescription(description);
    assertFalse("The description has not properly been removed from the taxon name", nameBase2.getDescriptions().contains(description));
    assertEquals("The taxon name has not properly been removed from the description", null, description.getTaxonName());
}
Also used : TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) Test(org.junit.Test)

Example 2 with TaxonNameDescription

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

the class StatisticsDaoHibernateImplTest method createDataSet.

private void createDataSet() {
    // create NO_OF_CLASSIFICATIONS classifications
    classifications = new ArrayList<Classification>();
    for (int i = 1; i <= NO_OF_CLASSIFICATIONS; i++) {
        Classification classification = Classification.NewInstance("European Abies" + i);
        classifications.add(classification);
        classificationDao.save(classification);
    }
    // create all taxa, references and synonyms and attach them to one or
    // more classifications
    // variables: flags
    int remainder = NO_OF_ACCEPTED_TAXA;
    Reference sec = ReferenceFactory.newBook();
    boolean secondClassificationForTaxonFlag = false;
    boolean synonymFlag = false;
    boolean tNomRefFlag = false;
    boolean sNomRefFlag = false;
    boolean tDescrSourceRefFlag = false;
    boolean sDescrSourceRefFlag = false;
    // variables: counter (pre-loop)
    int descriptiveElementsPerTaxon = (NO_OF_DESCRIPTIVE_SOURCE_REFERENCES / NO_OF_ACCEPTED_TAXA) + 1;
    int taxaInClass;
    int classiCounter = 0, sharedClassification = 0, synonymCounter = 0, nomRefCounter = 0;
    // iterate over classifications and add taxa
    for (; /* see above */
    remainder > 0 && classiCounter < NO_OF_CLASSIFICATIONS; ) /* see below */
    {
        // compute no of taxa to be created in this classification
        if (classiCounter >= NO_OF_CLASSIFICATIONS - 1) {
            // last classification
            // gets all left taxa
            taxaInClass = remainder;
        } else {
            // take half of left taxa for this class:
            taxaInClass = remainder / 2;
        }
        // iterate over amount of taxa meant to be in this classification
        for (int taxonCounter = 1; taxonCounter <= taxaInClass; taxonCounter++) {
            // create a String for the Name
            RandomStringUtils.randomAlphabetic(10);
            String randomName = RandomStringUtils.randomAlphabetic(5) + " " + RandomStringUtils.randomAlphabetic(10);
            // create a name for the taxon
            IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
            name.setNameCache(randomName, true);
            // create nomenclatural reference for taxon name (if left)
            if (nomRefCounter < NO_OF_NOMENCLATURAL_REFERENCES) {
                // we remember this taxon has a nomenclatural reference:
                tNomRefFlag = true;
                Reference nomRef = ReferenceFactory.newBook();
                name.setNomenclaturalReference(nomRef);
                referenceDao.save(nomRef);
                nomRefCounter++;
            }
            // create a new sec for every other taxon
            if (taxonCounter % 2 != 0) {
                sec = createSecReference(classiCounter, taxonCounter);
            }
            // create the taxon
            Taxon taxon = Taxon.NewInstance(name, sec);
            if (no_of_descriptive_source_references < NO_OF_DESCRIPTIVE_SOURCE_REFERENCES) {
                tDescrSourceRefFlag = true;
                // create a description and 2 description elements with
                // references for taxon name
                TaxonNameDescription nameDescr = TaxonNameDescription.NewInstance();
                CommonTaxonName nameElement = CommonTaxonName.NewInstance("Veilchen" + taxonCounter, Language.GERMAN());
                TextData textElement = new TextData();
                Reference nameElementRef = ReferenceFactory.newArticle();
                Reference textElementRef = ReferenceFactory.newBookSection();
                nameElement.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, nameElementRef, "name: ");
                textElement.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, textElementRef, "text: ");
                nameDescr.addElement(nameElement);
                nameDescr.addElement(textElement);
                name.addDescription(nameDescr);
                // taxon.getName().addDescription(nameDescr);
                referenceDao.save(nameElementRef);
                referenceDao.save(textElementRef);
                descriptionDao.save(nameDescr);
                // create descriptions, description sources and their
                // references
                // for taxon
                TaxonDescription taxonDescription = new TaxonDescription();
                for (int i = 0; i < descriptiveElementsPerTaxon; i++) {
                    DescriptionElementBase descriptionElement = new TextData();
                    DescriptionElementSource descriptionElementSource = DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
                    Reference article = ReferenceFactory.newArticle();
                    descriptionElementSource.setCitation(article);
                    descriptionElement.addSource(descriptionElementSource);
                    taxonDescription.addElement(descriptionElement);
                    referenceDao.save(article);
                    descriptionElementDao.save(descriptionElement);
                }
                descriptionDao.save(taxonDescription);
                taxon.addDescription(taxonDescription);
                // create a Specimen for taxon with description, descr.
                // element and referece
                // 
                // Specimen specimen = Specimen.NewInstance();
                // SpecimenDescription specimenDescription =
                // SpecimenDescription.NewInstance(specimen);
                // DescriptionElementBase descrElement = new TextData();
                // Reference specimenRef = ReferenceFactory.newArticle();
                // descrElement.addSource(null, null, specimenRef, null);
                // 
                // 
                // descriptionService.save(specimenDescription);
                // taxon.add(specimen);
                no_of_descriptive_source_references += descriptiveElementsPerTaxon + 2 + 1;
            }
            // add taxon to classification
            classifications.get(classiCounter).addChildTaxon(taxon, null, null);
            // now if there are any left, we create a synonym for the taxon
            if (synonymCounter < NO_OF_SYNONYMS) {
                synonymFlag = true;
                randomName = RandomStringUtils.randomAlphabetic(5) + " " + RandomStringUtils.randomAlphabetic(10);
                // name for synonym
                name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
                name.setNameCache(randomName, true);
                // create nomenclatural reference for synonym name (if left)
                if (nomRefCounter < NO_OF_NOMENCLATURAL_REFERENCES) {
                    sNomRefFlag = true;
                    Reference nomRef = ReferenceFactory.newBook();
                    name.setNomenclaturalReference(nomRef);
                    referenceDao.save(nomRef);
                    nomRefCounter++;
                }
                if (no_of_descriptive_source_references < NO_OF_DESCRIPTIVE_SOURCE_REFERENCES) {
                    sDescrSourceRefFlag = true;
                    // create a description and 2 description elements with
                    // references for synonym name
                    TaxonNameDescription nameDescr = TaxonNameDescription.NewInstance();
                    CommonTaxonName nameElement = CommonTaxonName.NewInstance("anderes Veilchen" + taxonCounter, Language.GERMAN());
                    TextData textElement = new TextData();
                    Reference nameElementRef = ReferenceFactory.newArticle();
                    Reference textElementRef = ReferenceFactory.newBookSection();
                    nameElement.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, nameElementRef, "name: ");
                    textElement.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, textElementRef, "text: ");
                    nameDescr.addElement(nameElement);
                    nameDescr.addElement(textElement);
                    name.addDescription(nameDescr);
                    // taxon.getName().addDescription(nameDescr);
                    referenceDao.save(nameElementRef);
                    referenceDao.save(textElementRef);
                    descriptionDao.save(nameDescr);
                    no_of_descriptive_source_references += 2;
                }
                // create a new reference for every other synonym:
                if (taxonCounter % 2 != 0) {
                    sec = createSecReference(classiCounter, taxonCounter);
                }
                Synonym synonym = Synonym.NewInstance(name, sec);
                taxonDao.save(synonym);
                taxon.addSynonym(synonym, SynonymType.SYNONYM_OF());
                synonymCounter++;
            }
            // we add the taxon to the next class in the list too.
            if (classiCounter < NO_OF_CLASSIFICATIONS && sharedClassification < NO_OF_SHARED_TAXA) {
                classifications.get(classiCounter + 1).addChildTaxon(taxon, null, null);
                // we remember that this taxon is attached to 2
                // classifications:
                secondClassificationForTaxonFlag = true;
                sharedClassification++;
                classificationDao.saveOrUpdate(classifications.get(classiCounter + 1));
            }
            taxonDao.save(taxon);
            classificationDao.saveOrUpdate(classifications.get(classiCounter));
            // count the data created with this taxon:
            int c = classiCounter;
            if (secondClassificationForTaxonFlag) {
                c++;
            }
            // twice, if it is attached to 2 classifications
            for (int i = classiCounter; i <= c; i++) {
                // count everything just created for this taxon:
                increment(no_of_accepted_taxa_c, i);
                increment(no_of_taxon_names_c, i);
                if (tNomRefFlag) {
                    increment(no_of_nomenclatural_references_c, i);
                }
                if (sNomRefFlag) {
                    increment(no_of_nomenclatural_references_c, i);
                }
                if (synonymFlag) {
                    increment(no_of_synonyms_c, i);
                    increment(no_of_taxon_names_c, i);
                }
                if (taxonCounter % 2 != 0) {
                    increment(no_of_all_references_c, i);
                    if (synonymFlag) {
                        increment(no_of_all_references_c, i);
                    }
                }
                if (tDescrSourceRefFlag) {
                    increment(no_of_descriptive_source_references_c, i, descriptiveElementsPerTaxon + 2);
                }
                if (sDescrSourceRefFlag) {
                    increment(no_of_descriptive_source_references_c, i, 2);
                }
            }
            // put flags back:
            secondClassificationForTaxonFlag = false;
            tNomRefFlag = false;
            sNomRefFlag = false;
            synonymFlag = false;
            tDescrSourceRefFlag = false;
            sDescrSourceRefFlag = false;
        }
        // modify variables (post-loop)
        classiCounter++;
        remainder -= taxaInClass;
    }
    merge(no_of_accepted_taxa_c, no_of_synonyms_c, no_of_all_taxa_c);
    merge(no_of_all_references_c, no_of_nomenclatural_references_c, no_of_all_references_c);
}
Also used : CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) Reference(eu.etaxonomy.cdm.model.reference.Reference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) IBotanicalName(eu.etaxonomy.cdm.model.name.IBotanicalName) Classification(eu.etaxonomy.cdm.model.taxon.Classification) TextData(eu.etaxonomy.cdm.model.description.TextData) DescriptionElementSource(eu.etaxonomy.cdm.model.description.DescriptionElementSource) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym)

Example 3 with TaxonNameDescription

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

Example 4 with TaxonNameDescription

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

the class DescriptionServiceImpl method isDeletable.

@Override
public DeleteResult isDeletable(UUID descriptionUuid) {
    DeleteResult result = new DeleteResult();
    DescriptionBase<?> description = this.load(descriptionUuid);
    Set<CdmBase> references = commonService.getReferencingObjectsForDeletion(description);
    if (references == null || references.isEmpty()) {
        return result;
    }
    for (CdmBase ref : references) {
        if (description instanceof TaxonDescription && ref instanceof Taxon && ref.equals(((TaxonDescription) description).getTaxon())) {
            continue;
        } else if (description instanceof TaxonNameDescription && ref instanceof TaxonName && ref.equals(((TaxonNameDescription) description).getTaxonName())) {
            continue;
        } else if (description instanceof SpecimenDescription && ref instanceof SpecimenOrObservationBase && ref.equals(((SpecimenDescription) description).getDescribedSpecimenOrObservation())) {
            continue;
        } else if (ref instanceof DescriptionElementBase) {
            continue;
        } else if (ref instanceof CdmLinkSource && ((CdmLinkSource) ref).hasNoTarget()) {
            // maybe only workaround #9801
            continue;
        } else {
            String message = "The description can't be completely deleted because it is referenced by " + ref.getUserFriendlyTypeName();
            result.setAbort();
            result.addException(new ReferencedObjectUndeletableException(message));
            result.addRelatedObject(ref);
        }
    }
    return result;
}
Also used : TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) ReferencedObjectUndeletableException(eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) CdmLinkSource(eu.etaxonomy.cdm.model.reference.CdmLinkSource)

Example 5 with TaxonNameDescription

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

Aggregations

TaxonNameDescription (eu.etaxonomy.cdm.model.description.TaxonNameDescription)23 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)15 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)14 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)14 DescriptionElementBase (eu.etaxonomy.cdm.model.description.DescriptionElementBase)9 TextData (eu.etaxonomy.cdm.model.description.TextData)8 SpecimenDescription (eu.etaxonomy.cdm.model.description.SpecimenDescription)7 SpecimenOrObservationBase (eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)7 Reference (eu.etaxonomy.cdm.model.reference.Reference)6 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)5 DescriptionElementSource (eu.etaxonomy.cdm.model.description.DescriptionElementSource)5 Media (eu.etaxonomy.cdm.model.media.Media)5 HashSet (java.util.HashSet)5 CdmBase (eu.etaxonomy.cdm.model.common.CdmBase)4 DerivedUnit (eu.etaxonomy.cdm.model.occurrence.DerivedUnit)4 Classification (eu.etaxonomy.cdm.model.taxon.Classification)4 ArrayList (java.util.ArrayList)4 ReferencedObjectUndeletableException (eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException)3 CategoricalData (eu.etaxonomy.cdm.model.description.CategoricalData)3 DescriptionBase (eu.etaxonomy.cdm.model.description.DescriptionBase)3