+ @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
+ TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();\r
+ config.setDeleteNameIfPossible(false);\r
+ this.deleteTaxon(fromTaxon, config, 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.getReferencingObjectsForDeletion(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
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public IncludedTaxaDTO listIncludedTaxa(UUID taxonUuid, IncludedTaxonConfiguration config) {\r
+ IncludedTaxaDTO result = new IncludedTaxaDTO(taxonUuid);\r