Search in sources :

Example 1 with SecundumSource

use of eu.etaxonomy.cdm.model.taxon.SecundumSource in project cdmlib by cybertaxonomy.

the class CommonServiceImpl method getReferencingObjectTarget.

private UuidAndTitleCache<CdmBase> getReferencingObjectTarget(CdmBase entity) {
    CdmBase targetEntity;
    entity = CdmBase.deproxy(entity);
    if (entity instanceof SecundumSource) {
        targetEntity = ((SecundumSource) entity).getSourcedTaxon();
    } else if (entity instanceof NomenclaturalSource) {
        targetEntity = ((NomenclaturalSource) entity).getSourcedName();
    } else if (entity instanceof DescriptionElementSource) {
        DescriptionElementBase element = ((DescriptionElementSource) entity).getSourcedElement();
        targetEntity = getTarget(element);
    } else if (entity instanceof DescriptionElementBase) {
        targetEntity = getTarget((DescriptionElementBase) entity);
    } else if (entity instanceof IdentifiableSource) {
        IdentifiableSource source = (IdentifiableSource) entity;
        targetEntity = originalSourceDao.findIdentifiableBySourceId(IdentifiableEntity.class, source.getId());
    } else if (entity instanceof NamedSource) {
        NamedSource source = (NamedSource) entity;
        SingleSourcedEntityBase singleSourced = originalSourceDao.findSingleSourceBySourceId(SingleSourcedEntityBase.class, source.getId());
        if (singleSourced != null) {
            targetEntity = singleSourced;
        } else {
            // TODO
            targetEntity = entity;
        }
    } else if (entity instanceof DescriptionBase) {
        targetEntity = getTarget((DescriptionBase<?>) entity);
    } else {
        targetEntity = entity;
    }
    targetEntity = CdmBase.deproxy(targetEntity);
    if (targetEntity == null) {
        targetEntity = entity;
    }
    String targetLabel = targetEntity instanceof IdentifiableEntity ? ((IdentifiableEntity<?>) targetEntity).getTitleCache() : null;
    UuidAndTitleCache<CdmBase> result = new UuidAndTitleCache<>(targetEntity.getClass(), targetEntity.getUuid(), targetEntity.getId(), targetLabel);
    return result;
}
Also used : DescriptionBase(eu.etaxonomy.cdm.model.description.DescriptionBase) IdentifiableEntity(eu.etaxonomy.cdm.model.common.IdentifiableEntity) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) SecundumSource(eu.etaxonomy.cdm.model.taxon.SecundumSource) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) NamedSource(eu.etaxonomy.cdm.model.reference.NamedSource) NomenclaturalSource(eu.etaxonomy.cdm.model.name.NomenclaturalSource) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) DescriptionElementSource(eu.etaxonomy.cdm.model.description.DescriptionElementSource) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource) SingleSourcedEntityBase(eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase)

Example 2 with SecundumSource

use of eu.etaxonomy.cdm.model.taxon.SecundumSource in project cdmlib by cybertaxonomy.

the class TaxonServiceImpl method isDeletableForTaxon.

private DeleteResult isDeletableForTaxon(Set<CdmBase> references, TaxonDeletionConfigurator config) {
    String message = null;
    DeleteResult result = new DeleteResult();
    for (CdmBase ref : references) {
        if (!(ref instanceof TaxonName || ref instanceof SecundumSource)) {
            message = null;
            if (!config.isDeleteSynonymRelations() && (ref instanceof Synonym)) {
                message = "The taxon can't be deleted as long as it has synonyms.";
            }
            if (!config.isDeleteDescriptions() && (ref instanceof DescriptionBase)) {
                message = "The taxon can't be deleted as long as it has factual data.";
            }
            if (!config.isDeleteTaxonNodes() && (ref instanceof TaxonNode)) {
                message = "The taxon can't be deleted as long as it belongs to a taxon node.";
            }
            if (ref instanceof TaxonNode && config.getClassificationUuid() != null && !config.isDeleteInAllClassifications() && !((TaxonNode) ref).getClassification().getUuid().equals(config.getClassificationUuid())) {
                message = "The taxon can't be deleted as long as it is used in more than one classification";
            }
            if (!config.isDeleteTaxonRelationships() && (ref instanceof TaxonRelationship)) {
                if (!config.isDeleteMisappliedNames() && (((TaxonRelationship) ref).getType().isMisappliedName())) {
                    message = "The taxon can't be deleted as long as it has misapplied names or invalid designations.";
                } else {
                    message = "The taxon can't be deleted as long as it belongs to taxon relationship.";
                }
            }
            if (ref instanceof PolytomousKeyNode) {
                message = "The taxon can't be deleted as long as it is referenced by a polytomous key node.";
            }
            if (HibernateProxyHelper.isInstanceOf(ref, IIdentificationKey.class)) {
                message = "Taxon can't be deleted as it is used in an identification key. Remove from identification key prior to deleting this taxon";
            }
            // TaxonInteraction
            if (ref.isInstanceOf(TaxonInteraction.class)) {
                message = "Taxon can't be deleted as it is used in taxonInteraction#taxon2";
            }
            // TaxonInteraction
            if (ref.isInstanceOf(DeterminationEvent.class)) {
                message = "Taxon can't be deleted as it is used in a determination event";
            }
        }
        if (message != null) {
            result.addException(new ReferencedObjectUndeletableException(message));
            result.addRelatedObject(ref);
            result.setAbort();
        }
    }
    return result;
}
Also used : DescriptionBase(eu.etaxonomy.cdm.model.description.DescriptionBase) TaxonRelationship(eu.etaxonomy.cdm.model.taxon.TaxonRelationship) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) ReferencedObjectUndeletableException(eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) SecundumSource(eu.etaxonomy.cdm.model.taxon.SecundumSource)

Example 3 with SecundumSource

use of eu.etaxonomy.cdm.model.taxon.SecundumSource in project cdmlib by cybertaxonomy.

the class ReferencingObjectFormatter method format.

public static String format(CdmBase element, String target, Language defaultLanguage) {
    String resultString = null;
    if (element == null) {
        return null;
    } else if (element instanceof IdentifiableEntity) {
        resultString = ((IdentifiableEntity<?>) element).getTitleCache();
    } else if (element instanceof OriginalSourceBase) {
        OriginalSourceBase originalSource = (OriginalSourceBase) element;
        // ISourceable sourcedObject = originalSource.getSourcedObj();
        // due to #5743 the bidirectionality for sourced object had to be removed
        String sourceObjectTitle = "sourced object data not available (#5743)";
        // it is now possible for NomenclaturalSource as they link to the sourced name
        if (originalSource instanceof NomenclaturalSource) {
            TaxonName sourcedName = ((NomenclaturalSource) originalSource).getSourcedName();
            sourceObjectTitle = sourcedName == null ? "Source orphaned, not attached to a name" : "for " + sourcedName.getTitleCache();
        } else if (originalSource instanceof SecundumSource) {
            TaxonBase<?> sourcedTaxon = ((SecundumSource) originalSource).getSourcedTaxon();
            sourceObjectTitle = sourcedTaxon == null ? "Source orphaned, not attached to a taxon" : "for " + sourcedTaxon.getTitleCache();
        } else if (originalSource instanceof DescriptionElementSource) {
            sourceObjectTitle = getCache((DescriptionElementSource) originalSource, defaultLanguage);
        } else if (originalSource instanceof IdentifiableSource && isNotBlank(target)) {
            sourceObjectTitle = "for " + target;
        } else if (originalSource instanceof NamedSource && isNotBlank(target)) {
            sourceObjectTitle = "for " + target;
        }
        resultString = CdmUtils.concat("; ", new String[] { originalSource.getIdNamespace(), originalSource.getIdInSource(), sourceObjectTitle });
    } else if (element instanceof LanguageStringBase) {
        resultString = ((LanguageStringBase) element).getText();
    } else if (element instanceof DescriptionElementBase) {
        resultString = getCache((DescriptionElementBase) element, defaultLanguage);
    } else if (element instanceof RelationshipBase<?, ?, ?>) {
        resultString = getCache((RelationshipBase<?, ?, ?>) element, defaultLanguage);
    } else if (element instanceof TypeDesignationBase<?>) {
        resultString = getCache((TypeDesignationBase<?>) element, defaultLanguage);
    } else if (element instanceof HomotypicalGroup) {
        resultString = getCache((HomotypicalGroup) element);
    } else if (element instanceof TaxonNode) {
        resultString = getCache((TaxonNode) element);
    } else if (element instanceof DeterminationEvent) {
        resultString = getCache((DeterminationEvent) element);
    } else if (element instanceof NomenclaturalStatus) {
        resultString = getCache((NomenclaturalStatus) element);
    } else if (element instanceof GatheringEvent) {
        resultString = getCache((GatheringEvent) element);
    } else if (element instanceof Marker) {
        Marker marker = (Marker) element;
        MarkerType type = marker.getMarkerType();
        resultString = (type == null ? "- no marker type -" : marker.getMarkerType().getLabel()) + " (" + marker.getFlag() + ")";
    } else if (element instanceof User) {
        User user = (User) element;
        resultString = user.getUsername();
    } else if (element instanceof Group) {
        Group group = (Group) element;
        resultString = group.getName();
    } else if (element instanceof KeyStatement) {
        KeyStatement keyStatement = (KeyStatement) element;
        resultString = getCache(keyStatement);
    } else {
        // TODO write return texts for HomotypicalGroup, etc.
        resultString = element.toString();
    }
    if (resultString == null) {
        resultString = element.toString();
    }
    return resultString;
}
Also used : IdentifiableEntity(eu.etaxonomy.cdm.model.common.IdentifiableEntity) GatheringEvent(eu.etaxonomy.cdm.model.occurrence.GatheringEvent) Group(eu.etaxonomy.cdm.model.permission.Group) HomotypicalGroup(eu.etaxonomy.cdm.model.name.HomotypicalGroup) OriginalSourceBase(eu.etaxonomy.cdm.model.reference.OriginalSourceBase) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) User(eu.etaxonomy.cdm.model.permission.User) LanguageStringBase(eu.etaxonomy.cdm.model.common.LanguageStringBase) TypeDesignationBase(eu.etaxonomy.cdm.model.name.TypeDesignationBase) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) Marker(eu.etaxonomy.cdm.model.common.Marker) DeterminationEvent(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent) SecundumSource(eu.etaxonomy.cdm.model.taxon.SecundumSource) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) NamedSource(eu.etaxonomy.cdm.model.reference.NamedSource) HomotypicalGroup(eu.etaxonomy.cdm.model.name.HomotypicalGroup) NomenclaturalSource(eu.etaxonomy.cdm.model.name.NomenclaturalSource) NomenclaturalStatus(eu.etaxonomy.cdm.model.name.NomenclaturalStatus) KeyStatement(eu.etaxonomy.cdm.model.description.KeyStatement) DescriptionElementSource(eu.etaxonomy.cdm.model.description.DescriptionElementSource) MarkerType(eu.etaxonomy.cdm.model.common.MarkerType) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource)

Example 4 with SecundumSource

use of eu.etaxonomy.cdm.model.taxon.SecundumSource in project cdmlib by cybertaxonomy.

the class Cdm2CdmImportBase method handlePersistedSecundumSource.

protected SecundumSource handlePersistedSecundumSource(DescriptionElementSource source, Cdm2CdmImportState state) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException, SecurityException, IllegalArgumentException, NoSuchMethodException {
    SecundumSource result = handlePersisted((NamedSourceBase) source, state);
    // TODO correct?
    result.setSourcedTaxon(detache(result.getSourcedTaxon(), state));
    return result;
}
Also used : SecundumSource(eu.etaxonomy.cdm.model.taxon.SecundumSource)

Example 5 with SecundumSource

use of eu.etaxonomy.cdm.model.taxon.SecundumSource in project cdmlib by cybertaxonomy.

the class TaxonNodeDaoHibernateImpl method setSecundum.

private <T extends TaxonBase<?>> Set<CdmBase> setSecundum(Reference newSec, boolean emptyDetail, String queryStr, IProgressMonitor monitor) {
    Set<CdmBase> result = new HashSet<>();
    Query query = getSession().createQuery(queryStr);
    @SuppressWarnings("unchecked") List<List<Integer>> partitionList = splitIdList(query.list(), DEFAULT_SET_SUBTREE_PARTITION_SIZE);
    for (List<Integer> taxonIdList : partitionList) {
        @SuppressWarnings({ "unchecked", "rawtypes" }) List<T> taxonList = (List) taxonDao.loadList(taxonIdList, null, null);
        for (T taxonBase : taxonList) {
            if (taxonBase != null) {
                taxonBase = CdmBase.deproxy(taxonBase);
                SecundumSource secSourceBefore = taxonBase.getSecSource();
                Reference refBefore = taxonBase.getSec();
                String refDetailBefore = taxonBase.getSecMicroReference();
                if (newSec == null && taxonBase.getSec() != null || newSec != null && (taxonBase.getSec() == null || !newSec.equals(taxonBase.getSec()))) {
                    taxonBase.setSec(newSec);
                }
                if (emptyDetail) {
                    if (taxonBase.getSecMicroReference() != null) {
                        taxonBase.setSecMicroReference(null);
                    }
                }
                // compute updated objects
                SecundumSource secSourceAfter = taxonBase.getSecSource();
                if (!CdmUtils.nullSafeEqual(secSourceBefore, secSourceAfter)) {
                    result.add(taxonBase);
                    // FIXME #9627 remove if fixed
                    result.add(taxonBase);
                // EMXIF
                } else if (secSourceBefore != null && secSourceBefore.equals(secSourceAfter) && (!CdmUtils.nullSafeEqual(refBefore, secSourceAfter.getCitation()) || !CdmUtils.nullSafeEqual(refDetailBefore, secSourceAfter.getCitationMicroReference()))) {
                    result.add(secSourceBefore);
                    // FIXME #9627 remove if fixed
                    result.add(taxonBase);
                // EMXIF
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    return result;
                }
            }
        }
        commitAndRestartTransaction(newSec);
        monitor.worked(taxonIdList.size());
    }
    return result;
}
Also used : Query(org.hibernate.Query) Reference(eu.etaxonomy.cdm.model.reference.Reference) SecundumSource(eu.etaxonomy.cdm.model.taxon.SecundumSource) BigInteger(java.math.BigInteger) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

SecundumSource (eu.etaxonomy.cdm.model.taxon.SecundumSource)7 CdmBase (eu.etaxonomy.cdm.model.common.CdmBase)4 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)3 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)3 ReferencedObjectUndeletableException (eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException)2 IdentifiableEntity (eu.etaxonomy.cdm.model.common.IdentifiableEntity)2 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)2 DescriptionBase (eu.etaxonomy.cdm.model.description.DescriptionBase)2 DescriptionElementBase (eu.etaxonomy.cdm.model.description.DescriptionElementBase)2 DescriptionElementSource (eu.etaxonomy.cdm.model.description.DescriptionElementSource)2 NomenclaturalSource (eu.etaxonomy.cdm.model.name.NomenclaturalSource)2 NamedSource (eu.etaxonomy.cdm.model.reference.NamedSource)2 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)2 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)1 LanguageStringBase (eu.etaxonomy.cdm.model.common.LanguageStringBase)1 Marker (eu.etaxonomy.cdm.model.common.Marker)1 MarkerType (eu.etaxonomy.cdm.model.common.MarkerType)1 SingleSourcedEntityBase (eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase)1 KeyStatement (eu.etaxonomy.cdm.model.description.KeyStatement)1 PolytomousKeyNode (eu.etaxonomy.cdm.model.description.PolytomousKeyNode)1