Search in sources :

Example 1 with SingleSourcedEntityBase

use of eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase 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 SingleSourcedEntityBase

use of eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase in project cdmlib by cybertaxonomy.

the class OriginalSourceDaoImpl method findSingleSourceBySourceId.

@Override
public <S extends SingleSourcedEntityBase> S findSingleSourceBySourceId(Class<S> clazz, int sourceId) {
    if (clazz == null) {
        clazz = (Class) SingleSourcedEntityBase.class;
    }
    Query q = getSession().createQuery("SELECT c " + "FROM " + clazz.getName() + " AS c " + "INNER JOIN c.source AS source " + "WHERE source.id= :sourceId ");
    q.setInteger("sourceId", sourceId);
    @SuppressWarnings("unchecked") S result = (S) q.uniqueResult();
    return result;
}
Also used : Query(org.hibernate.Query) SingleSourcedEntityBase(eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase)

Aggregations

SingleSourcedEntityBase (eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase)2 CdmBase (eu.etaxonomy.cdm.model.common.CdmBase)1 IdentifiableEntity (eu.etaxonomy.cdm.model.common.IdentifiableEntity)1 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)1 DescriptionBase (eu.etaxonomy.cdm.model.description.DescriptionBase)1 DescriptionElementBase (eu.etaxonomy.cdm.model.description.DescriptionElementBase)1 DescriptionElementSource (eu.etaxonomy.cdm.model.description.DescriptionElementSource)1 NomenclaturalSource (eu.etaxonomy.cdm.model.name.NomenclaturalSource)1 NamedSource (eu.etaxonomy.cdm.model.reference.NamedSource)1 SecundumSource (eu.etaxonomy.cdm.model.taxon.SecundumSource)1 UuidAndTitleCache (eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache)1 Query (org.hibernate.Query)1