Search in sources :

Example 1 with CdmLinkSource

use of eu.etaxonomy.cdm.model.reference.CdmLinkSource 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 2 with CdmLinkSource

use of eu.etaxonomy.cdm.model.reference.CdmLinkSource 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 3 with CdmLinkSource

use of eu.etaxonomy.cdm.model.reference.CdmLinkSource in project cdmlib by cybertaxonomy.

the class DescriptionServiceImpl method deleteDescription.

@Override
@Transactional(readOnly = false)
public DeleteResult deleteDescription(DescriptionBase<?> description) {
    DeleteResult deleteResult = new DeleteResult();
    if (description == null) {
        return deleteResult;
    }
    // avoid lazy init exception
    description = load(description.getId(), Arrays.asList("descriptiveDataSets"));
    deleteResult = isDeletable(description.getUuid());
    if (deleteResult.getRelatedObjects() != null && deleteResult.getRelatedObjects().size() == 1) {
        Iterator<CdmBase> relObjects = deleteResult.getRelatedObjects().iterator();
        CdmBase next = relObjects.next();
        if (next instanceof CdmLinkSource) {
            CdmLinkSource source = (CdmLinkSource) next;
            ICdmTarget target = source.getTarget();
        }
    }
    if (deleteResult.isOk()) {
        CdmBase.deproxy(description);
        if (description instanceof TaxonDescription) {
            TaxonDescription taxDescription = (TaxonDescription) description;
            Taxon tax = taxDescription.getTaxon();
            if (tax != null) {
                tax.removeDescription(taxDescription, true);
                deleteResult.addUpdatedObject(tax);
            }
        } else if (description instanceof SpecimenDescription) {
            SpecimenDescription specimenDescription = (SpecimenDescription) description;
            SpecimenOrObservationBase<?> specimen = specimenDescription.getDescribedSpecimenOrObservation();
            if (specimen != null) {
                specimen.removeDescription(specimenDescription);
                deleteResult.addUpdatedObject(specimen);
            }
        }
        for (DescriptiveDataSet dataset : description.getDescriptiveDataSets()) {
            dataset.removeDescription(description);
        }
        dao.delete(description);
        deleteResult.addDeletedObject(description);
        deleteResult.setCdmEntity(description);
    } else {
        logger.info(deleteResult.getExceptions().toString());
    }
    return deleteResult;
}
Also used : DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) CdmLinkSource(eu.etaxonomy.cdm.model.reference.CdmLinkSource) ICdmTarget(eu.etaxonomy.cdm.model.reference.ICdmTarget) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CdmBase (eu.etaxonomy.cdm.model.common.CdmBase)3 SpecimenDescription (eu.etaxonomy.cdm.model.description.SpecimenDescription)3 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)3 SpecimenOrObservationBase (eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)3 CdmLinkSource (eu.etaxonomy.cdm.model.reference.CdmLinkSource)3 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)3 DescriptionElementBase (eu.etaxonomy.cdm.model.description.DescriptionElementBase)2 DescriptiveDataSet (eu.etaxonomy.cdm.model.description.DescriptiveDataSet)2 Status (eu.etaxonomy.cdm.api.service.UpdateResult.Status)1 DeleteDescriptiveDataSetConfigurator (eu.etaxonomy.cdm.api.service.config.DeleteDescriptiveDataSetConfigurator)1 IdentifiableServiceConfiguratorImpl (eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl)1 RemoveDescriptionsFromDescriptiveDataSetConfigurator (eu.etaxonomy.cdm.api.service.config.RemoveDescriptionsFromDescriptiveDataSetConfigurator)1 CategoricalDataDto (eu.etaxonomy.cdm.api.service.dto.CategoricalDataDto)1 DescriptionBaseDto (eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto)1 DescriptionElementDto (eu.etaxonomy.cdm.api.service.dto.DescriptionElementDto)1 QuantitativeDataDto (eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto)1 RowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO)1 SpecimenOrObservationDTOFactory (eu.etaxonomy.cdm.api.service.dto.SpecimenOrObservationDTOFactory)1 SpecimenRowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO)1 StateDataDto (eu.etaxonomy.cdm.api.service.dto.StateDataDto)1