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;
}
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;
}
Aggregations