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