import java.util.Set;\r
import java.util.UUID;\r
\r
+import javax.persistence.EntityNotFoundException;\r
+\r
import org.apache.log4j.Logger;\r
import org.apache.lucene.index.CorruptIndexException;\r
import org.apache.lucene.queryParser.ParseException;\r
import org.springframework.stereotype.Service;\r
import org.springframework.transaction.annotation.Transactional;\r
\r
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;\r
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;\r
import eu.etaxonomy.cdm.api.service.config.MatchingTaxonConfigurator;\r
import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;\r
import eu.etaxonomy.cdm.model.molecular.Sequence;\r
import eu.etaxonomy.cdm.model.molecular.SingleRead;\r
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;\r
+import eu.etaxonomy.cdm.model.name.NameRelationship;\r
import eu.etaxonomy.cdm.model.name.Rank;\r
import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
import eu.etaxonomy.cdm.model.name.ZoologicalName;\r
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
+import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;\r
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;\r
import eu.etaxonomy.cdm.model.reference.Reference;\r
import eu.etaxonomy.cdm.model.taxon.Classification;\r
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;\r
import eu.etaxonomy.cdm.model.taxon.Synonym;\r
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;\r
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;\r
import eu.etaxonomy.cdm.persistence.dao.initializer.AbstractBeanInitializer;\r
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;\r
import eu.etaxonomy.cdm.persistence.dao.occurrence.IOccurrenceDao;\r
+import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao;\r
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;\r
import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;\r
import eu.etaxonomy.cdm.persistence.query.MatchMode;\r
\r
@Autowired\r
private INameService nameService;\r
- \r
+\r
@Autowired\r
private ITaxonNodeService nodeService;\r
- \r
\r
@Autowired\r
private ICdmGenericDao genericDao;\r
@Autowired\r
private IOccurrenceDao occurrenceDao;\r
\r
+ @Autowired\r
+ private IClassificationDao classificationDao;\r
+\r
@Autowired\r
private AbstractBeanInitializer beanInitializer;\r
\r
return dao.getTaxaByName(name, sec);\r
}\r
\r
- /**\r
- * FIXME Candidate for harmonization\r
- * list(Synonym.class, ...)\r
- * (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.api.service.ITaxonService#getAllSynonyms(int, int)\r
- */\r
- @Override\r
- public List<Synonym> getAllSynonyms(int limit, int start) {\r
- return dao.getAllSynonyms(limit, start);\r
- }\r
-\r
- /**\r
- * FIXME Candidate for harmonization\r
- * list(Taxon.class, ...)\r
- * (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.api.service.ITaxonService#getAllTaxa(int, int)\r
- */\r
- @Override\r
- public List<Taxon> getAllTaxa(int limit, int start) {\r
- return dao.getAllTaxa(limit, start);\r
- }\r
-\r
/**\r
* FIXME Candidate for harmonization\r
* merge with getRootTaxa(Reference sec, ..., ...)\r
return dao.getRootTaxa(sec, cdmFetch, onlyWithChildren, false);\r
}\r
\r
-\r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.api.service.ITaxonService#getRootTaxa(eu.etaxonomy.cdm.model.name.Rank, eu.etaxonomy.cdm.model.reference.Reference, boolean, boolean)\r
- */\r
@Override\r
public List<Taxon> getRootTaxa(Rank rank, Reference sec, boolean onlyWithChildren,boolean withMisapplications, List<String> propertyPaths) {\r
return dao.getRootTaxa(rank, sec, null, onlyWithChildren, withMisapplications, propertyPaths);\r
}\r
\r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.api.service.ITaxonService#getAllRelationships(int, int)\r
- */\r
@Override\r
public List<RelationshipBase> getAllRelationships(int limit, int start){\r
return dao.getAllRelationships(limit, start);\r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#changeSynonymToAcceptedTaxon(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon)\r
*/\r
- \r
+\r
@Override\r
@Transactional(readOnly = false)\r
public Taxon changeSynonymToAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon, boolean deleteSynonym, boolean copyCitationInfo, Reference citation, String microCitation) throws HomotypicalGroupChangeException{\r
- \r
+\r
TaxonNameBase<?,?> acceptedName = acceptedTaxon.getName();\r
TaxonNameBase<?,?> synonymName = synonym.getName();\r
HomotypicalGroup synonymHomotypicGroup = synonymName.getHomotypicalGroup();\r
\r
SynonymRelationshipType relTypeForGroup = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF();\r
List<Synonym> heteroSynonyms = acceptedTaxon.getSynonymsInGroup(synonymHomotypicGroup);\r
+ Set<NameRelationship> basionymsAndReplacedSynonyms = synonymHomotypicGroup.getBasionymAndReplacedSynonymRelations();\r
\r
for (Synonym heteroSynonym : heteroSynonyms){\r
if (synonym.equals(heteroSynonym)){\r
acceptedTaxon.removeSynonym(heteroSynonym, false);\r
+\r
}else{\r
//move synonyms in same homotypic group to new accepted taxon\r
heteroSynonym.replaceAcceptedTaxon(newAcceptedTaxon, relTypeForGroup, copyCitationInfo, citation, microCitation);\r
}\r
\r
//synonym.getName().removeTaxonBase(synonym);\r
- \r
+\r
if (deleteSynonym){\r
// deleteSynonym(synonym, taxon, false);\r
try {\r
this.dao.flush();\r
- this.deleteSynonym(synonym, acceptedTaxon, new SynonymDeletionConfigurator());\r
+ SynonymDeletionConfigurator config = new SynonymDeletionConfigurator();\r
+ config.setDeleteNameIfPossible(false);\r
+ this.deleteSynonym(synonym, acceptedTaxon, config);\r
\r
} catch (Exception e) {\r
logger.info("Can't delete old synonym from database");\r
// Get name from synonym\r
TaxonNameBase<?, ?> synonymName = synonym.getName();\r
\r
- // remove synonym from taxon\r
+ /* // remove synonym from taxon\r
toTaxon.removeSynonym(synonym);\r
-\r
+*/\r
// Create a taxon with synonym name\r
Taxon fromTaxon = Taxon.NewInstance(synonymName, null);\r
\r
\r
// since we are swapping names, we have to detach the name from the synonym completely.\r
// Otherwise the synonym will still be in the list of typified names.\r
- synonym.getName().removeTaxonBase(synonym);\r
+ // synonym.getName().removeTaxonBase(synonym);\r
+ this.deleteSynonym(synonym, null);\r
\r
return fromTaxon;\r
}\r
return new DefaultPagerImpl<TaxonRelationship>(pageNumber, numberOfResults, pageSize, results);\r
}\r
\r
+ @Override\r
+ public List<Taxon> listAcceptedTaxaFor(UUID synonymUuid, UUID classificationUuid, Integer pageSize, Integer pageNumber,\r
+ List<OrderHint> orderHints, List<String> propertyPaths){\r
+ return pageAcceptedTaxaFor(synonymUuid, classificationUuid, pageSize, pageNumber, orderHints, propertyPaths).getRecords();\r
+ }\r
+\r
+ @Override\r
+ public Pager<Taxon> pageAcceptedTaxaFor(UUID synonymUuid, UUID classificationUuid, Integer pageSize, Integer pageNumber,\r
+ List<OrderHint> orderHints, List<String> propertyPaths){\r
+\r
+ List<Taxon> list = new ArrayList<Taxon>();\r
+ Long count = 0l;\r
+\r
+ Synonym synonym = null;\r
+\r
+ try {\r
+ synonym = (Synonym) dao.load(synonymUuid);\r
+ } catch (ClassCastException e){\r
+ throw new EntityNotFoundException("The TaxonBase entity referenced by " + synonymUuid + " is not a Synonmy");\r
+ } catch (NullPointerException e){\r
+ throw new EntityNotFoundException("No TaxonBase entity found for " + synonymUuid);\r
+ }\r
+\r
+ Classification classificationFilter = null;\r
+ if(classificationUuid != null){\r
+ try {\r
+ classificationFilter = classificationDao.load(classificationUuid);\r
+ } catch (NullPointerException e){\r
+ throw new EntityNotFoundException("No Classification entity found for " + classificationUuid);\r
+ }\r
+ if(classificationFilter == null){\r
+\r
+ }\r
+ }\r
+\r
+ count = dao.countAcceptedTaxaFor(synonym, classificationFilter) ;\r
+ if(count > (pageSize * pageNumber)){\r
+ list = dao.listAcceptedTaxaFor(synonym, classificationFilter, pageSize, pageNumber, orderHints, propertyPaths);\r
+ }\r
+\r
+ return new DefaultPagerImpl<Taxon>(pageNumber, count.intValue(), pageSize, list);\r
+ }\r
+\r
+\r
/**\r
* @param taxon\r
* @param includeRelationships\r
taxa.add(taxon);\r
}\r
\r
+ if(includeRelationships.isEmpty()){\r
+ return taxa;\r
+ }\r
+\r
if(maxDepth != null) {\r
maxDepth--;\r
}\r
return new DefaultPagerImpl<SynonymRelationship>(pageNumber, numberOfResults, pageSize, results);\r
}\r
\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.api.service.ITaxonService#getHomotypicSynonymsByHomotypicGroup(eu.etaxonomy.cdm.model.taxon.Taxon, java.util.List)\r
+ */\r
+ @Override\r
+ public List<List<Synonym>> getSynonymsByHomotypicGroup(Taxon taxon, List<String> propertyPaths){\r
+ List<List<Synonym>> result = new ArrayList<List<Synonym>>();\r
+ Taxon t = (Taxon)dao.load(taxon.getUuid(), propertyPaths);\r
+\r
+ //homotypic\r
+ result.add(t.getHomotypicSynonymsByHomotypicGroup());\r
+\r
+ //heterotypic\r
+ List<HomotypicalGroup> homotypicalGroups = t.getHeterotypicSynonymyGroups();\r
+ for(HomotypicalGroup homotypicalGroup : homotypicalGroups){\r
+ result.add(t.getSynonymsInGroup(homotypicalGroup));\r
+ }\r
+\r
+ return result;\r
+\r
+ }\r
+\r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#getHomotypicSynonymsByHomotypicGroup(eu.etaxonomy.cdm.model.taxon.Taxon, java.util.List)\r
*/\r
Boolean limitToGalleries, Boolean includeTaxonDescriptions, Boolean includeOccurrences,\r
Boolean includeTaxonNameDescriptions, List<String> propertyPath) {\r
\r
+ logger.trace("listMedia() - START");\r
+\r
Set<Taxon> taxa = new HashSet<Taxon>();\r
List<Media> taxonMedia = new ArrayList<Media>();\r
\r
}\r
\r
// --- resolve related taxa\r
- if (includeRelationships != null) {\r
+ if (includeRelationships != null && ! includeRelationships.isEmpty()) {\r
+ logger.trace("listMedia() - resolve related taxa");\r
taxa = listRelatedTaxa(taxon, includeRelationships, null, null, null, null);\r
}\r
\r
taxa.add((Taxon) dao.load(taxon.getUuid()));\r
\r
if(includeTaxonDescriptions != null && includeTaxonDescriptions){\r
+ logger.trace("listMedia() - includeTaxonDescriptions");\r
List<TaxonDescription> taxonDescriptions = new ArrayList<TaxonDescription>();\r
// --- TaxonDescriptions\r
for (Taxon t : taxa) {\r
}\r
}\r
\r
+\r
if(includeOccurrences != null && includeOccurrences) {\r
+ logger.trace("listMedia() - includeOccurrences");\r
Set<SpecimenOrObservationBase> specimensOrObservations = new HashSet<SpecimenOrObservationBase>();\r
// --- Specimens\r
for (Taxon t : taxa) {\r
}\r
\r
if(includeTaxonNameDescriptions != null && includeTaxonNameDescriptions) {\r
+ logger.trace("listMedia() - includeTaxonNameDescriptions");\r
// --- TaxonNameDescription\r
Set<TaxonNameDescription> nameDescriptions = new HashSet<TaxonNameDescription>();\r
for (Taxon t : taxa) {\r
}\r
}\r
\r
+\r
+ logger.trace("listMedia() - initialize");\r
beanInitializer.initializeAll(taxonMedia, propertyPath);\r
+\r
+ logger.trace("listMedia() - END");\r
+\r
return taxonMedia;\r
}\r
\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteTaxon(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator)\r
*/\r
@Override\r
- public UUID deleteTaxon(Taxon taxon, TaxonDeletionConfigurator config, Classification classification) throws DataChangeNoRollbackException {\r
+ public String deleteTaxon(Taxon taxon, TaxonDeletionConfigurator config, Classification classification) {\r
if (config == null){\r
config = new TaxonDeletionConfigurator();\r
}\r
-\r
- // SynonymRelationShip\r
+ \r
+ List<String> referencedObjects = isDeletable(taxon, config);\r
+ \r
+ if (referencedObjects.isEmpty()){\r
+ // --- DeleteSynonymRelations\r
if (config.isDeleteSynonymRelations()){\r
boolean removeSynonymNameFromHomotypicalGroup = false;\r
- for (SynonymRelationship synRel : taxon.getSynonymRelations()){\r
+ // use tmp Set to avoid concurrent modification\r
+ Set<SynonymRelationship> synRelsToDelete = new HashSet<SynonymRelationship>();\r
+ synRelsToDelete.addAll(taxon.getSynonymRelations());\r
+ for (SynonymRelationship synRel : synRelsToDelete){\r
Synonym synonym = synRel.getSynonym();\r
+ // taxon.removeSynonymRelation will set the accepted taxon and the synonym to NULL\r
+ // this will cause hibernate to delete the relationship since\r
+ // the SynonymRelationship field on both is annotated with removeOrphan\r
+ // so no further explicit deleting of the relationship should be done here\r
taxon.removeSynonymRelation(synRel, removeSynonymNameFromHomotypicalGroup);\r
+\r
+ // --- DeleteSynonymsIfPossible\r
if (config.isDeleteSynonymsIfPossible()){\r
//TODO which value\r
boolean newHomotypicGroupIfNeeded = true;\r
SynonymDeletionConfigurator synConfig = new SynonymDeletionConfigurator();\r
- \r
deleteSynonym(synonym, taxon, synConfig);\r
- }else{\r
- deleteSynonymRelationships(synonym, taxon);\r
}\r
+ // relationship will be deleted by hibernate automatically,\r
+ // see comment above and http://dev.e-taxonomy.eu/trac/ticket/3797\r
+ // else{\r
+ // deleteSynonymRelationships(synonym, taxon);\r
+ // }\r
}\r
}\r
\r
- // TaxonRelationship\r
+ // --- DeleteTaxonRelationships\r
if (! config.isDeleteTaxonRelationships()){\r
if (taxon.getTaxonRelations().size() > 0){\r
- String message = "Taxon can't be deleted as it is related to another taxon. Remove taxon from all relations to other taxa prior to deletion.";\r
- throw new ReferencedObjectUndeletableException(message);\r
+ String message = "Taxon can't be deleted as it is related to another taxon. " +\r
+ "Remove taxon from all relations to other taxa prior to deletion.";\r
+ // throw new ReferencedObjectUndeletableException(message);\r
}\r
} else{\r
- for (TaxonRelationship taxRel: taxon.getTaxonRelations()){\r
- \r
- \r
- \r
- if (config.isDeleteMisappliedNamesAndInvalidDesignations()){\r
- if (taxRel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR()) || taxRel.getType().equals(TaxonRelationshipType.INVALID_DESIGNATION_FOR())){\r
- if (taxon.equals(taxRel.getToTaxon())){\r
- this.deleteTaxon(taxRel.getFromTaxon(), config, classification);\r
- }\r
- }\r
- }\r
- taxon.removeTaxonRelation(taxRel);\r
- /*if (taxFrom.equals(taxon)){\r
- try{\r
- this.deleteTaxon(taxTo, taxConf, classification);\r
- } catch(DataChangeNoRollbackException e){\r
- logger.debug("A related taxon will not be deleted." + e.getMessage());\r
- }\r
- } else {\r
- try{\r
- this.deleteTaxon(taxFrom, taxConf, classification);\r
- } catch(DataChangeNoRollbackException e){\r
- logger.debug("A related taxon will not be deleted." + e.getMessage());\r
- }\r
- \r
- }*/\r
- }\r
- }\r
+ for (TaxonRelationship taxRel: taxon.getTaxonRelations()){\r
+ if (config.isDeleteMisappliedNamesAndInvalidDesignations()){\r
+ if (taxRel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR()) || taxRel.getType().equals(TaxonRelationshipType.INVALID_DESIGNATION_FOR())){\r
+ if (taxon.equals(taxRel.getToTaxon())){\r
+ this.deleteTaxon(taxRel.getFromTaxon(), config, classification);\r
+ }\r
+ }\r
+ }\r
+ taxon.removeTaxonRelation(taxRel);\r
+ /*if (taxFrom.equals(taxon)){\r
+ try{\r
+ this.deleteTaxon(taxTo, taxConf, classification);\r
+ } catch(DataChangeNoRollbackException e){\r
+ logger.debug("A related taxon will not be deleted." + e.getMessage());\r
+ }\r
+ } else {\r
+ try{\r
+ this.deleteTaxon(taxFrom, taxConf, classification);\r
+ } catch(DataChangeNoRollbackException e){\r
+ logger.debug("A related taxon will not be deleted." + e.getMessage());\r
+ }\r
\r
+ }*/\r
+ }\r
+ }\r
\r
- \r
- \r
// TaxonDescription\r
if (config.isDeleteDescriptions()){\r
- Set<TaxonDescription> descriptions = taxon.getDescriptions();\r
-\r
- for (TaxonDescription desc: descriptions){\r
- //TODO use description delete configurator ?\r
- //FIXME check if description is ALWAYS deletable\r
- if (desc.getDescribedSpecimenOrObservation() != null){\r
- String message = "Taxon can't be deleted as it is used in a TaxonDescription" +\r
- " which also describes specimens or abservations";\r
- throw new ReferencedObjectUndeletableException(message);\r
- }\r
- descriptionService.delete(desc);\r
- taxon.removeDescription(desc);\r
+ Set<TaxonDescription> descriptions = taxon.getDescriptions();\r
+ List<TaxonDescription> removeDescriptions = new ArrayList<TaxonDescription>();\r
+ for (TaxonDescription desc: descriptions){\r
+ //TODO use description delete configurator ?\r
+ //FIXME check if description is ALWAYS deletable\r
+ if (desc.getDescribedSpecimenOrObservation() != null){\r
+ String message = "Taxon can't be deleted as it is used in a TaxonDescription" +\r
+ " which also describes specimens or abservations";\r
+ //throw new ReferencedObjectUndeletableException(message);\r
}\r
+ removeDescriptions.add(desc);\r
+ descriptionService.delete(desc);\r
+\r
+ }\r
+ for (TaxonDescription desc: removeDescriptions){\r
+ taxon.removeDescription(desc);\r
+ }\r
}\r
\r
\r
- //check references with only reverse mapping\r
+ /* //check references with only reverse mapping\r
String message = checkForReferences(taxon);\r
- if (message != null){\r
- throw new ReferencedObjectUndeletableException(message.toString());\r
- }\r
- \r
- if (! config.isDeleteTaxonNodes() || (!config.isDeleteInAllClassifications() && classification == null )){\r
- if (taxon.getTaxonNodes().size() > 0){\r
- message = "Taxon can't be deleted as it is used in a classification node. Remove taxon from all classifications prior to deletion or define a classification where it should be deleted or adapt the taxon deletion configurator.";\r
- throw new ReferencedObjectUndeletableException(message);\r
- }\r
+ if (message != null){\r
+ //throw new ReferencedObjectUndeletableException(message.toString());\r
+ }*/\r
+\r
+ if (! config.isDeleteTaxonNodes() || (!config.isDeleteInAllClassifications() && classification == null )){\r
+ //if (taxon.getTaxonNodes().size() > 0){\r
+ // message = "Taxon can't be deleted as it is used in a classification node. Remove taxon from all classifications prior to deletion or define a classification where it should be deleted or adapt the taxon deletion configurator.";\r
+ // throw new ReferencedObjectUndeletableException(message);\r
+ //}\r
}else{\r
- if (taxon.getTaxonNodes().size() != 0){\r
- Set<TaxonNode> nodes = taxon.getTaxonNodes();\r
- Iterator<TaxonNode> iterator = nodes.iterator();\r
- TaxonNode node = null;\r
- boolean deleteChildren;\r
- if (config.getTaxonNodeConfig().getChildHandling().equals(ChildHandling.DELETE)){\r
- deleteChildren = true;\r
- }else {\r
- deleteChildren = false;\r
- }\r
- boolean success = true;\r
- if (!config.isDeleteInAllClassifications() && !(classification == null)){\r
- while (iterator.hasNext()){\r
- node = iterator.next();\r
- if (node.getClassification().equals(classification)){\r
- break;\r
- }\r
- node = null;\r
- }\r
- if (node != null){\r
- success =taxon.removeTaxonNode(node, deleteChildren);\r
- } else {\r
- message = "Taxon is not used in defined classification";\r
- throw new DataChangeNoRollbackException(message);\r
- }\r
- } else if (config.isDeleteInAllClassifications()){\r
- List<TaxonNode> nodesList = new ArrayList<TaxonNode>();\r
- nodesList.addAll(taxon.getTaxonNodes());\r
- \r
- for (TaxonNode taxonNode: nodesList){\r
- if(deleteChildren){\r
- Object[] childNodes = taxonNode.getChildNodes().toArray();\r
- for (Object childNode: childNodes){\r
- TaxonNode childNodeCast = (TaxonNode) childNode;\r
- deleteTaxon(childNodeCast.getTaxon(), config, classification);\r
- \r
- }\r
- \r
- /*for (TaxonNode childNode: taxonNode.getChildNodes()){\r
- deleteTaxon(childNode.getTaxon(), config, classification);\r
- \r
- }*/\r
- //taxon.removeTaxonNode(taxonNode);\r
- } else{\r
- Object[] childNodes = taxonNode.getChildNodes().toArray();\r
- for (Object childNode: childNodes){\r
- TaxonNode childNodeCast = (TaxonNode) childNode;\r
- taxonNode.getParent().addChildNode(childNodeCast, childNodeCast.getReference(), childNodeCast.getMicroReference());\r
- }\r
- \r
- //taxon.removeTaxonNode(taxonNode);\r
- }\r
- }\r
- \r
- \r
- \r
- nodeService.deleteTaxonNodes(nodesList);\r
- \r
- }\r
- if (!success){\r
- message = "The taxon node could not be deleted.";\r
- throw new DataChangeNoRollbackException(message);\r
- }\r
- }\r
+ if (taxon.getTaxonNodes().size() != 0){\r
+ Set<TaxonNode> nodes = taxon.getTaxonNodes();\r
+ Iterator<TaxonNode> iterator = nodes.iterator();\r
+ TaxonNode node = null;\r
+ boolean deleteChildren;\r
+ if (config.getTaxonNodeConfig().getChildHandling().equals(ChildHandling.DELETE)){\r
+ deleteChildren = true;\r
+ }else {\r
+ deleteChildren = false;\r
+ }\r
+ boolean success = true;\r
+ if (!config.isDeleteInAllClassifications() && !(classification == null)){\r
+ while (iterator.hasNext()){\r
+ node = iterator.next();\r
+ if (node.getClassification().equals(classification)){\r
+ break;\r
+ }\r
+ node = null;\r
+ }\r
+ if (node != null){\r
+ success =taxon.removeTaxonNode(node, deleteChildren);\r
+ nodeService.delete(node);\r
+ } else {\r
+ // message = "Taxon is not used in defined classification";\r
+ // throw new DataChangeNoRollbackException(message);\r
+ }\r
+ } else if (config.isDeleteInAllClassifications()){\r
+ Set<ITaxonTreeNode> nodesList = new HashSet<ITaxonTreeNode>();\r
+ nodesList.addAll(taxon.getTaxonNodes());\r
+\r
+ for (ITaxonTreeNode treeNode: nodesList){\r
+ TaxonNode taxonNode = (TaxonNode) treeNode;\r
+ if(!deleteChildren){\r
+ /* Object[] childNodes = taxonNode.getChildNodes().toArray();\r
+ //nodesList.addAll(taxonNode.getChildNodes());\r
+ for (Object childNode: childNodes){\r
+ TaxonNode childNodeCast = (TaxonNode) childNode;\r
+ deleteTaxon(childNodeCast.getTaxon(), config, classification);\r
+\r
+ }\r
+\r
+ /*for (TaxonNode childNode: taxonNode.getChildNodes()){\r
+ deleteTaxon(childNode.getTaxon(), config, classification);\r
+\r
+ }\r
+ // taxon.removeTaxonNode(taxonNode);\r
+ //nodeService.delete(taxonNode);\r
+ } else{\r
+ */\r
+ Object[] childNodes = taxonNode.getChildNodes().toArray();\r
+ for (Object childNode: childNodes){\r
+ TaxonNode childNodeCast = (TaxonNode) childNode;\r
+ taxonNode.getParent().addChildNode(childNodeCast, childNodeCast.getReference(), childNodeCast.getMicroReference());\r
+ }\r
+\r
+ //taxon.removeTaxonNode(taxonNode);\r
+ }\r
+ }\r
+ config.getTaxonNodeConfig().setDeleteTaxon(false);\r
+ nodeService.deleteTaxonNodes(nodesList, config);\r
+ }\r
+ if (!success){\r
+ // message = "The taxon node could not be deleted.";\r
+ //throw new DataChangeNoRollbackException(message);\r
+ }\r
+ }\r
}\r
+\r
+\r
+ //PolytomousKey TODO\r
+\r
+ boolean usedInPolytomousKey = checkForPolytomousKeys(taxon);\r
//TaxonNameBase\r
if (config.isDeleteNameIfPossible()){\r
- try {\r
- \r
- //TaxonNameBase name = nameService.find(taxon.getName().getUuid());\r
- TaxonNameBase name = (TaxonNameBase)HibernateProxyHelper.deproxy(taxon.getName());\r
- //check whether taxon will be deleted or not\r
- if (taxon.getTaxonNodes() == null || taxon.getTaxonNodes().size()== 0){\r
- taxon = (Taxon) HibernateProxyHelper.deproxy(taxon);\r
- name.removeTaxonBase(taxon);\r
- nameService.save(name);\r
- nameService.delete(name, config.getNameDeletionConfig());\r
- }\r
- } catch (ReferencedObjectUndeletableException e) {\r
- //do nothing\r
- if (logger.isDebugEnabled()){logger.debug("Name could not be deleted");}\r
- \r
- }\r
+ \r
+\r
+ //TaxonNameBase name = nameService.find(taxon.getName().getUuid());\r
+ TaxonNameBase name = (TaxonNameBase)HibernateProxyHelper.deproxy(taxon.getName());\r
+ //check whether taxon will be deleted or not\r
+ if ((taxon.getTaxonNodes() == null || taxon.getTaxonNodes().size()== 0) && name != null ){\r
+ taxon = (Taxon) HibernateProxyHelper.deproxy(taxon);\r
+ name.removeTaxonBase(taxon);\r
+ nameService.save(name);\r
+ String uuidString = nameService.delete(name, config.getNameDeletionConfig());\r
+ logger.debug(uuidString);\r
+ }\r
+ \r
}\r
- \r
+\r
// TaxonDescription\r
/* Set<TaxonDescription> descriptions = taxon.getDescriptions();\r
\r
if (config.isDeleteDescriptions()){\r
//TODO use description delete configurator ?\r
//FIXME check if description is ALWAYS deletable\r
- taxon.removeDescription(desc);\r
+ taxon.removeDescription(desc);\r
descriptionService.delete(desc);\r
}else{\r
if (desc.getDescribedSpecimenOrObservations().size()>0){\r
}\r
}\r
}*/\r
- \r
- \r
-\r
- if (taxon.getTaxonNodes() == null || taxon.getTaxonNodes().size()== 0){\r
- dao.delete(taxon);\r
- return taxon.getUuid();\r
- } else{\r
- message = "Taxon can't be deleted as it is used in another Taxonnode";\r
- throw new ReferencedObjectUndeletableException(message);\r
+ \r
+ if ((taxon.getTaxonNodes() == null || taxon.getTaxonNodes().size()== 0) ){\r
+ UUID uuid = dao.delete(taxon);\r
+ return uuid.toString();\r
+ } else {\r
+ return "The Taxon can't be deleted.";\r
}\r
- \r
+ }else {\r
+ return referencedObjects.toString();\r
+ }\r
+\r
\r
}\r
- \r
+\r
private String checkForReferences(Taxon taxon){\r
- Set<CdmBase> referencingObjects = genericDao.getReferencingObjects(taxon);\r
+ Set<CdmBase> referencingObjects = genericDao.getReferencingObjects(taxon);\r
for (CdmBase referencingObject : referencingObjects){\r
//IIdentificationKeys (Media, Polytomous, MultiAccess)\r
if (HibernateProxyHelper.isInstanceOf(referencingObject, IIdentificationKey.class)){\r
String message = "Taxon" + taxon.getTitleCache() + "can't be deleted as it is used in an identification key. Remove from identification key prior to deleting this name";\r
- \r
+\r
return message;\r
}\r
\r
\r
- //PolytomousKeyNode\r
+ /* //PolytomousKeyNode\r
if (referencingObject.isInstanceOf(PolytomousKeyNode.class)){\r
String message = "Taxon" + taxon.getTitleCache() + " can't be deleted as it is used in polytomous key node";\r
return message;\r
- }\r
+ }*/\r
\r
//TaxonInteraction\r
if (referencingObject.isInstanceOf(TaxonInteraction.class)){\r
String message = "Taxon can't be deleted as it is used in taxonInteraction#taxon2";\r
return message;\r
}\r
+\r
+ //TaxonInteraction\r
+ if (referencingObject.isInstanceOf(DeterminationEvent.class)){\r
+ String message = "Taxon can't be deleted as it is used in a determination event";\r
+ return message;\r
+ }\r
+\r
}\r
+\r
referencingObjects = null;\r
return null;\r
}\r
- \r
+\r
+ private boolean checkForPolytomousKeys(Taxon taxon){\r
+ boolean result = false;\r
+ List<CdmBase> list = genericDao.getCdmBasesByFieldAndClass(PolytomousKeyNode.class, "taxon", taxon);\r
+ if (!list.isEmpty()) {\r
+ result = true;\r
+ }\r
+ return result;\r
+ }\r
+\r
@Transactional(readOnly = false)\r
public UUID delete(Synonym syn){\r
- UUID result = syn.getUuid();\r
- this.deleteSynonym(syn, null);\r
- return result;\r
+ UUID result = syn.getUuid();\r
+ this.deleteSynonym(syn, null);\r
+ return result;\r
}\r
- \r
+\r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteSynonym(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon, boolean, boolean)\r
*/\r
@Transactional(readOnly = false)\r
@Override\r
- public void deleteSynonym(Synonym synonym, SynonymDeletionConfigurator config) {\r
- deleteSynonym(synonym, null, config);\r
- \r
- }\r
- \r
+ public String deleteSynonym(Synonym synonym, SynonymDeletionConfigurator config) {\r
+ return deleteSynonym(synonym, null, config);\r
\r
- /* (non-Javadoc)\r
+ }\r
+\r
+\r
+ /* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteSynonym(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon, boolean, boolean)\r
*/\r
@Transactional(readOnly = false)\r
@Override\r
- public void deleteSynonym(Synonym synonym, Taxon taxon, SynonymDeletionConfigurator config) {\r
+ public String deleteSynonym(Synonym synonym, Taxon taxon, SynonymDeletionConfigurator config) {\r
if (synonym == null){\r
- return;\r
+ return null;\r
}\r
+ \r
if (config == null){\r
- config = new SynonymDeletionConfigurator();\r
- }\r
- synonym = CdmBase.deproxy(dao.merge(synonym), Synonym.class);\r
-\r
- //remove synonymRelationship\r
- Set<Taxon> taxonSet = new HashSet<Taxon>();\r
- if (taxon != null){\r
- taxonSet.add(taxon);\r
+ config = new SynonymDeletionConfigurator();\r
+ }\r
+ List<String> messages = isDeletable(synonym, config);\r
+ if (messages.isEmpty()){\r
+ synonym = CdmBase.deproxy(dao.merge(synonym), Synonym.class);\r
+ \r
+ //remove synonymRelationship\r
+ Set<Taxon> taxonSet = new HashSet<Taxon>();\r
+ if (taxon != null){\r
+ taxonSet.add(taxon);\r
+ }else{\r
+ taxonSet.addAll(synonym.getAcceptedTaxa());\r
+ }\r
+ for (Taxon relatedTaxon : taxonSet){\r
+ // dao.deleteSynonymRelationships(synonym, relatedTaxon);\r
+ relatedTaxon.removeSynonym(synonym, config.isNewHomotypicGroupIfNeeded());\r
+ }\r
+ this.saveOrUpdate(synonym);\r
+ \r
+ //TODO remove name from homotypical group?\r
+ \r
+ //remove synonym (if necessary)\r
+ \r
+ UUID uuid = null;\r
+ if (synonym.getSynonymRelations().isEmpty()){\r
+ TaxonNameBase<?,?> name = synonym.getName();\r
+ synonym.setName(null);\r
+ uuid = dao.delete(synonym);\r
+ \r
+ //remove name if possible (and required)\r
+ if (name != null && config.isDeleteNameIfPossible()){\r
+ \r
+ nameService.delete(name, config.getNameDeletionConfig());\r
+ \r
+ }\r
+ \r
+ }else {\r
+ return null;\r
+ }\r
+ return uuid.toString();\r
}else{\r
- taxonSet.addAll(synonym.getAcceptedTaxa());\r
+ return messages.toString();\r
}\r
- for (Taxon relatedTaxon : taxonSet){\r
-// dao.deleteSynonymRelationships(synonym, relatedTaxon);\r
- relatedTaxon.removeSynonym(synonym, config.isNewHomotypicGroupIfNeeded());\r
- }\r
- this.saveOrUpdate(synonym);\r
-\r
- //TODO remove name from homotypical group?\r
-\r
- //remove synonym (if necessary)\r
- \r
\r
- if (synonym.getSynonymRelations().isEmpty()){\r
- TaxonNameBase<?,?> name = synonym.getName();\r
- synonym.setName(null);\r
- dao.delete(synonym);\r
-\r
- //remove name if possible (and required)\r
- if (name != null && config.isDeleteNameIfPossible()){\r
- try{\r
- nameService.delete(name, config.getNameDeletionConfig());\r
- }catch (ReferencedObjectUndeletableException ex){\r
- System.err.println("Name wasn't deleted as it is referenced");\r
- if (logger.isDebugEnabled()) {\r
- logger.debug("Name wasn't deleted as it is referenced");\r
- }\r
- }\r
- }\r
- }\r
+ \r
}\r
\r
\r
boolean highlightFragments, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws CorruptIndexException, IOException, ParseException {\r
\r
\r
- LuceneSearch luceneSearch = prepareFindByFullTextSearch(clazz, queryString, classification, languages, highlightFragments);\r
+ LuceneSearch luceneSearch = prepareFindByFullTextSearch(clazz, queryString, classification, languages, highlightFragments, null);\r
\r
// --- execute search\r
TopGroupsWithMaxScore topDocsResultSet = luceneSearch.executeSearch(pageSize, pageNumber);\r
* @param classification\r
* @param languages\r
* @param highlightFragments\r
+ * @param sortFields TODO\r
* @param directorySelectClass\r
* @return\r
*/\r
protected LuceneSearch prepareFindByFullTextSearch(Class<? extends CdmBase> clazz, String queryString, Classification classification, List<Language> languages,\r
- boolean highlightFragments) {\r
+ boolean highlightFragments, SortField[] sortFields) {\r
BooleanQuery finalQuery = new BooleanQuery();\r
BooleanQuery textQuery = new BooleanQuery();\r
\r
LuceneSearch luceneSearch = new LuceneSearch(luceneIndexToolProvider, GroupByTaxonClassBridge.GROUPBY_TAXON_FIELD, TaxonBase.class);\r
QueryFactory taxonBaseQueryFactory = luceneIndexToolProvider.newQueryFactoryFor(TaxonBase.class);\r
\r
- SortField[] sortFields = new SortField[]{SortField.FIELD_SCORE, new SortField("titleCache__sort", SortField.STRING, false)};\r
+ if(sortFields == null){\r
+ sortFields = new SortField[]{SortField.FIELD_SCORE, new SortField("titleCache__sort", SortField.STRING, false)};\r
+ }\r
luceneSearch.setSortFields(sortFields);\r
\r
// ---- search criteria\r
* <li>direct, everted: {@link Direction.relatedTo}: TaxonRelationShip.relatedTo.id --> Taxon.id </li>\r
* <li>inverse: {@link Direction.relatedFrom}: TaxonRelationShip.relatedFrom.id --> Taxon.id </li>\r
* <ul>\r
- *\r
* @param queryString\r
* @param classification\r
* @param languages\r
* @param highlightFragments\r
+ * @param sortFields TODO\r
+ *\r
* @return\r
* @throws IOException\r
*/\r
protected LuceneSearch prepareFindByTaxonRelationFullTextSearch(TaxonRelationshipEdge edge, String queryString, Classification classification, List<Language> languages,\r
- boolean highlightFragments) throws IOException {\r
+ boolean highlightFragments, SortField[] sortFields) throws IOException {\r
\r
String fromField;\r
String queryTermField;\r
joinFromQuery.add(taxonBaseQueryFactory.newEntityIdQuery("type.id", edge.getTaxonRelationshipType()), Occur.MUST);\r
Query joinQuery = taxonBaseQueryFactory.newJoinQuery(fromField, toField, joinFromQuery, TaxonRelationship.class);\r
\r
- SortField[] sortFields = new SortField[]{SortField.FIELD_SCORE, new SortField("titleCache__sort", SortField.STRING, false)};\r
+ if(sortFields == null){\r
+ sortFields = new SortField[]{SortField.FIELD_SCORE, new SortField("titleCache__sort", SortField.STRING, false)};\r
+ }\r
luceneSearch.setSortFields(sortFields);\r
\r
finalQuery.add(joinQuery, Occur.MUST);\r
searchModes = EnumSet.of(TaxaAndNamesSearchMode.doTaxa);\r
}\r
\r
+ // set sort order and thus override any sort orders which may have been\r
+ // defindes by prepare*Search methods\r
+ if(orderHints == null){\r
+ orderHints = OrderHint.NOMENCLATURAL_SORT_ORDER;\r
+ }\r
+ SortField[] sortFields = new SortField[orderHints.size()];\r
+ int i = 0;\r
+ for(OrderHint oh : orderHints){\r
+ sortFields[i++] = oh.toSortField();\r
+ }\r
+// SortField[] sortFields = new SortField[]{SortField.FIELD_SCORE, new SortField("id", SortField.STRING, false)};\r
+// SortField[] sortFields = new SortField[]{new SortField(NomenclaturalSortOrderBrigde.NAME_SORT_FIELD_NAME, SortField.STRING, false)};\r
+\r
+\r
boolean addDistributionFilter = namedAreas != null && namedAreas.size() > 0;\r
\r
List<LuceneSearch> luceneSearches = new ArrayList<LuceneSearch>();\r
} else if (!searchModes.contains(TaxaAndNamesSearchMode.doTaxa) && searchModes.contains(TaxaAndNamesSearchMode.doSynonyms)) {\r
taxonBaseSubclass = Synonym.class;\r
}\r
- luceneSearches.add(prepareFindByFullTextSearch(taxonBaseSubclass, queryString, classification, languages, highlightFragments));\r
+ luceneSearches.add(prepareFindByFullTextSearch(taxonBaseSubclass, queryString, classification, languages, highlightFragments, sortFields));\r
idFieldMap.put(CdmBaseType.TAXON, "id");\r
/* A) does not work!!!!\r
if(addDistributionFilter){\r
LuceneSearch byCommonNameSearch = new LuceneSearch(luceneIndexToolProvider, GroupByTaxonClassBridge.GROUPBY_TAXON_FIELD, Taxon.class);\r
byCommonNameSearch.setCdmTypRestriction(Taxon.class);\r
byCommonNameSearch.setQuery(byCommonNameJoinQuery);\r
+ byCommonNameSearch.setSortFields(sortFields);\r
idFieldMap.put(CdmBaseType.TAXON, "id");\r
\r
luceneSearches.add(byCommonNameSearch);\r
//\r
luceneSearches.add(prepareFindByTaxonRelationFullTextSearch(\r
new TaxonRelationshipEdge(TaxonRelationshipType.MISAPPLIED_NAME_FOR(), Direction.relatedTo),\r
- queryString, classification, languages, highlightFragments));\r
+ queryString, classification, languages, highlightFragments, sortFields));\r
idFieldMap.put(CdmBaseType.TAXON, "id");\r
\r
if(addDistributionFilter){\r
if (addDistributionFilter){\r
multiSearch.setFilter(multiIndexByAreaFilter);\r
}\r
+\r
+\r
// --- execute search\r
TopGroupsWithMaxScore topDocsResultSet = multiSearch.executeSearch(pageSize, pageNumber);\r
\r
Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws CorruptIndexException, IOException, ParseException, LuceneMultiSearchException {\r
\r
LuceneSearch luceneSearchByDescriptionElement = prepareByDescriptionElementFullTextSearch(null, queryString, classification, null, languages, highlightFragments);\r
- LuceneSearch luceneSearchByTaxonBase = prepareFindByFullTextSearch(null, queryString, classification, languages, highlightFragments);\r
+ LuceneSearch luceneSearchByTaxonBase = prepareFindByFullTextSearch(null, queryString, classification, languages, highlightFragments, null);\r
\r
LuceneMultiSearch multiSearch = new LuceneMultiSearch(luceneIndexToolProvider, luceneSearchByDescriptionElement, luceneSearchByTaxonBase);\r
\r
}\r
String genusOfTaxon = taxonName.getGenusOrUninomial();\r
Set<TaxonNode> nodes = taxon.getTaxonNodes();\r
- List<String> taxonNames = new ArrayList<String>();\r
+ List<String> taxonNames = new ArrayList<String>();\r
\r
for (TaxonNode node: nodes){\r
// HashMap<String, String> synonymsGenus = new HashMap<String, String>(); // Changed this to be able to store the idInSource to a genusName\r
Reference<?> sourceReference = syn.getSec();\r
\r
if (sourceReference == null){\r
- logger.warn("The synonym has no sec reference because it is a misapplied name! Take the sec reference of taxon" + taxon.getSec());\r
+ logger.warn("The synonym has no sec reference because it is a misapplied name! Take the sec reference of taxon" + taxon.getSec());\r
sourceReference = taxon.getSec();\r
}\r
\r
return list;\r
}\r
\r
+ @Override\r
+ public Synonym changeRelatedTaxonToSynonym(Taxon fromTaxon, Taxon toTaxon, TaxonRelationshipType oldRelationshipType,\r
+ SynonymRelationshipType synonymRelationshipType) throws DataChangeNoRollbackException {\r
+ // Create new synonym using concept name\r
+ TaxonNameBase<?, ?> synonymName = fromTaxon.getName();\r
+ Synonym synonym = Synonym.NewInstance(synonymName, fromTaxon.getSec());\r
+\r
+ // Remove concept relation from taxon\r
+ toTaxon.removeTaxon(fromTaxon, oldRelationshipType);\r
+\r
+\r
+\r
+\r
+ // Create a new synonym for the taxon\r
+ SynonymRelationship synonymRelationship;\r
+ if (synonymRelationshipType != null\r
+ && synonymRelationshipType.equals(SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF())){\r
+ synonymRelationship = toTaxon.addHomotypicSynonym(synonym, null, null);\r
+ } else{\r
+ synonymRelationship = toTaxon.addHeterotypicSynonymName(synonymName);\r
+ }\r
+\r
+ this.saveOrUpdate(toTaxon);\r
+ //TODO: configurator and classification\r
+ this.deleteTaxon(fromTaxon, null, null);\r
+ return synonymRelationship.getSynonym();\r
+\r
+ }\r
+ @Override\r
+ public List<String> isDeletable(TaxonBase taxonBase, DeleteConfiguratorBase config){\r
+ List<String> result = new ArrayList<String>();\r
+ Set<CdmBase> references = commonService.getReferencingObjects(taxonBase);\r
+ if (taxonBase instanceof Taxon){\r
+ TaxonDeletionConfigurator taxonConfig = (TaxonDeletionConfigurator) config;\r
+ result = isDeletableForTaxon(references, taxonConfig);\r
+ }else{\r
+ SynonymDeletionConfigurator synonymConfig = (SynonymDeletionConfigurator) config;\r
+ result = isDeletableForSynonym(references, synonymConfig);\r
+ }\r
+ return result;\r
+ }\r
+ \r
+ private List<String> isDeletableForSynonym(Set<CdmBase> references, SynonymDeletionConfigurator config){\r
+ String message;\r
+ List<String> result = new ArrayList<String>();\r
+ for (CdmBase ref: references){\r
+ if (!(ref instanceof SynonymRelationship || ref instanceof Taxon || ref instanceof TaxonNameBase)){\r
+ message = "The Synonym can't be deleted as long as it is referenced by " + ref.getClass().getSimpleName() + " with id "+ ref.getId();\r
+ result.add(message);\r
+ }\r
+ }\r
+ \r
+ return result;\r
+ }\r
+ private List<String> isDeletableForTaxon(Set<CdmBase> references, TaxonDeletionConfigurator config){\r
+ String message;\r
+ List<String> result = new ArrayList<String>();\r
+ for (CdmBase ref: references){\r
+ if (!(ref instanceof TaxonNameBase)){\r
+ if (!config.isDeleteSynonymRelations() && (ref instanceof SynonymRelationship)){\r
+ message = "The Taxon can't be deleted as long as it has synonyms.";\r
+ result.add(message);\r
+ }\r
+ if (!config.isDeleteDescriptions() && (ref instanceof DescriptionBase)){\r
+ message = "The Taxon can't be deleted as long as it has factual data.";\r
+ result.add(message);\r
+ }\r
+ \r
+ if (!config.isDeleteTaxonNodes() && (ref instanceof TaxonNode)){\r
+ message = "The Taxon can't be deleted as long as it belongs to a taxon node.";\r
+ result.add(message);\r
+ }\r
+ if (!config.isDeleteTaxonRelationships() && (ref instanceof TaxonNode)){\r
+ if (!config.isDeleteMisappliedNamesAndInvalidDesignations() && (((TaxonRelationship)ref).getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())|| ((TaxonRelationship)ref).getType().equals(TaxonRelationshipType.INVALID_DESIGNATION_FOR()))){\r
+ message = "The Taxon can't be deleted as long as it has misapplied names or invalid designations.";\r
+ result.add(message);\r
+ } else{\r
+ message = "The Taxon can't be deleted as long as it belongs to a taxon node.";\r
+ result.add(message);\r
+ }\r
+ }\r
+ if (ref instanceof PolytomousKeyNode){\r
+ message = "The Taxon can't be deleted as long as it is referenced by a polytomous key node.";\r
+ result.add(message);\r
+ }\r
+ \r
+ if (HibernateProxyHelper.isInstanceOf(ref, IIdentificationKey.class)){\r
+ message = "Taxon can't be deleted as it is used in an identification key. Remove from identification key prior to deleting this name";\r
+ result.add(message);\r
+ \r
+ }\r
+\r
\r
+ /* //PolytomousKeyNode\r
+ if (referencingObject.isInstanceOf(PolytomousKeyNode.class)){\r
+ String message = "Taxon" + taxon.getTitleCache() + " can't be deleted as it is used in polytomous key node";\r
+ return message;\r
+ }*/\r
\r
+ //TaxonInteraction\r
+ if (ref.isInstanceOf(TaxonInteraction.class)){\r
+ message = "Taxon can't be deleted as it is used in taxonInteraction#taxon2";\r
+ result.add(message);\r
+ }\r
\r
+ //TaxonInteraction\r
+ if (ref.isInstanceOf(DeterminationEvent.class)){\r
+ message = "Taxon can't be deleted as it is used in a determination event";\r
+ result.add(message);\r
+ }\r
\r
+ }\r
\r
-}\r
+ }\r
+ \r
+ return result;\r
+ }\r
+\r
+\r
+\r
+\r
+\r
+ }\r