import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;\r
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;\r
+import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
import eu.etaxonomy.cdm.model.location.Country;\r
import eu.etaxonomy.cdm.model.location.NamedArea;\r
import eu.etaxonomy.cdm.model.media.Media;\r
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;\r
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;\r
import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
+import eu.etaxonomy.cdm.model.name.TypeDesignationBase;\r
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;\r
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;\r
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
@Override\r
public DeleteResult delete(SpecimenOrObservationBase<?> specimen, SpecimenDeleteConfigurator config) {\r
DeleteResult deleteResult = new DeleteResult();\r
+ //check for derivation events\r
Set<DerivationEvent> derivationEvents = specimen.getDerivationEvents();\r
for (DerivationEvent derivationEvent : derivationEvents) {\r
if(!derivationEvent.getDerivatives().isEmpty()){\r
return deleteResult;\r
}\r
}\r
+ //check for original (parent derivate)\r
if(specimen instanceof DerivedUnit){\r
DerivationEvent derivedFromEvent = ((DerivedUnit) specimen).getDerivedFrom();\r
if(derivedFromEvent!=null){\r
derivedFromEvent.removeDerivative((DerivedUnit) specimen);\r
}\r
}\r
+ //check for IndividualsAssociation (e.g. in TaxonDescriptions)\r
+ Collection<TaxonBase<?>> associatedTaxa = listAssociatedTaxa(specimen, null, null, null, null);\r
+ if(!associatedTaxa.isEmpty()){\r
+ if(config.isDeleteFromIndividualsAssociation()){\r
+ for (TaxonBase<?> taxonBase : associatedTaxa) {\r
+ if(taxonBase instanceof Taxon){\r
+ Set<TaxonDescription> descriptions = ((Taxon) taxonBase).getDescriptions();\r
+ for (TaxonDescription taxonDescription : descriptions) {\r
+ Set<DescriptionElementBase> elements = taxonDescription.getElements();\r
+ for (DescriptionElementBase descriptionElementBase : elements) {\r
+ if(descriptionElementBase instanceof IndividualsAssociation){\r
+ IndividualsAssociation individualsAssociation = (IndividualsAssociation) descriptionElementBase;\r
+ if(individualsAssociation.getAssociatedSpecimenOrObservation().equals(specimen)){\r
+ individualsAssociation.setAssociatedSpecimenOrObservation(null);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ else{\r
+ deleteResult.addRelatedObjects(new HashSet<CdmBase>(associatedTaxa));\r
+ deleteResult.setAbort();\r
+ deleteResult.addException(new ReferencedObjectUndeletableException("Specimen is still associated with taxa."));\r
+ return deleteResult;\r
+ }\r
+ }\r
+ //check for TypeDesignations\r
+ Collection<TaxonBase<?>> typedTaxa = listTypedTaxa(specimen, null, null, null, null);\r
+ if(!typedTaxa.isEmpty()){\r
+ if(config.isdeleteFromTypeDesignation()){\r
+ for (TaxonBase<?> taxonBase : typedTaxa) {\r
+ if(taxonBase.getName()!=null){\r
+ Set<TypeDesignationBase> typeDesignations = taxonBase.getName().getTypeDesignations();\r
+ for (TypeDesignationBase typeDesignationBase : typeDesignations) {\r
+ if(typeDesignationBase instanceof SpecimenTypeDesignation){\r
+ ((SpecimenTypeDesignation) typeDesignationBase).setTypeSpecimen(null);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ else{\r
+ deleteResult.addRelatedObjects(new HashSet<CdmBase>(typedTaxa));\r
+ deleteResult.setAbort();\r
+ deleteResult.addException(new ReferencedObjectUndeletableException("Specimen is a type specimen."));\r
+ return deleteResult;\r
+ }\r
+ }\r
if(!config.isDeleteChildren()){\r
Set<CdmBase> referencingObjects = genericDao.getReferencingObjects(specimen);\r
for (CdmBase referencingObject : referencingObjects){\r
* @see eu.etaxonomy.cdm.api.service.IOccurrenceService#listAssociatedTaxa(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)\r
*/\r
@Override\r
- public Collection<TaxonBase<?>> listAssociatedTaxa(SpecimenOrObservationBase<?> specimen) {\r
+ public Collection<TaxonBase<?>> listAssociatedTaxa(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {\r
return dao.listAssociatedTaxa(specimen, null, null, null, null);\r
}\r
\r
+ @Override\r
+ public Collection<TaxonBase<?>> listTypedTaxa(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {\r
+ return dao.listTypedTaxa(specimen, limit, start, orderHints, propertyPaths);\r
+ }\r
+\r
}\r