2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotNull
;
14 import static org
.junit
.Assert
.assertNull
;
15 import static org
.junit
.Assert
.assertTrue
;
17 import java
.io
.FileNotFoundException
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Iterator
;
20 import java
.util
.List
;
21 import java
.util
.Random
;
23 import java
.util
.UUID
;
25 import org
.apache
.log4j
.Logger
;
26 import org
.junit
.Assert
;
27 import org
.junit
.Test
;
28 import org
.unitils
.dbunit
.annotation
.DataSet
;
29 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
31 import eu
.etaxonomy
.cdm
.api
.service
.config
.IncludedTaxonConfiguration
;
32 import eu
.etaxonomy
.cdm
.api
.service
.config
.NameDeletionConfigurator
;
33 import eu
.etaxonomy
.cdm
.api
.service
.config
.NodeDeletionConfigurator
.ChildHandling
;
34 import eu
.etaxonomy
.cdm
.api
.service
.config
.SynonymDeletionConfigurator
;
35 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
36 import eu
.etaxonomy
.cdm
.api
.service
.dto
.IncludedTaxaDTO
;
37 import eu
.etaxonomy
.cdm
.api
.service
.exception
.HomotypicalGroupChangeException
;
38 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
39 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
40 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
41 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
42 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
43 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
44 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
45 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
46 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
47 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
48 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
49 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
50 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
51 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
52 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
53 import eu
.etaxonomy
.cdm
.model
.name
.IBotanicalName
;
54 import eu
.etaxonomy
.cdm
.model
.name
.INonViralName
;
55 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
56 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
57 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
58 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
59 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
60 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
61 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
62 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
63 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEventType
;
64 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
65 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
66 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
67 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
68 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
69 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
70 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
71 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
72 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
73 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymType
;
74 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
75 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
76 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
77 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
78 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
79 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
80 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
81 import eu
.etaxonomy
.cdm
.test
.unitils
.CleanSweepInsertLoadStrategy
;
88 public class TaxonServiceImplTest
extends CdmTransactionalIntegrationTest
{
89 private static final Logger logger
= Logger
.getLogger(TaxonServiceImplTest
.class);
92 private ITaxonService service
;
95 private INameService nameService
;
98 private IReferenceService referenceService
;
101 private IClassificationService classificationService
;
104 private ITaxonNodeService nodeService
;
107 private IDescriptionService descriptionService
;
110 private IMarkerService markerService
;
113 private IEventBaseService eventService
;
116 private IOccurrenceService occurenceService
;
118 private Synonym synonym
;
119 private Synonym synonym2
;
121 private Taxon taxWithSyn
;
122 private Taxon tax2WithSyn
;
123 private Taxon taxWithoutSyn
;
124 private UUID uuidSyn
;
125 private UUID uuidTaxWithoutSyn
;
126 private UUID uuidSyn2
;
127 private UUID uuidTaxWithSyn
;
129 private static String
[] genera
= {"Carex", "Abies", "Belladonna", "Dracula", "Maria", "Calendula", "Polygala", "Vincia"};
130 private static String
[] epitheta
= {"vulgaris", "magdalena", "officinalis", "alba", "negra", "communa", "alpina", "rotundifolia", "greutheriana", "helventica", "allemania", "franca"};
131 private static String
[] ranks
= {"subsp", "var", "f"};
133 public static UUID GENUS_NAME_UUID
= UUID
.fromString("8d761fc4-b509-42f4-9568-244161934336");
134 public static UUID GENUS_UUID
= UUID
.fromString("bf4298a8-1735-4353-a210-244442e1bd62");
135 public static UUID BASIONYM_UUID
= UUID
.fromString("7911c51d-ccb7-4708-8992-639eae58a0e3");
136 public static UUID SPECIES1_UUID
= UUID
.fromString("f0eb77d9-76e0-47f4-813f-9b5605b78685");
137 public static UUID SPECIES1_NAME_UUID
= UUID
.fromString("efd78713-126f-42e1-9070-a1ff83f12abf");
138 public static UUID SYNONYM_NAME_UUID
= UUID
.fromString("b9cbaa74-dbe0-4930-8050-b7754ce85dc0");
139 public static UUID SPECIES2_NAME_UUID
= UUID
.fromString("0267ab67-483e-4da5-b654-11013b242c22");
140 public static UUID SPECIES2_UUID
= UUID
.fromString("e20eb549-ced6-4e79-9d74-44f0792a4929");
141 public static UUID SYNONYM2_NAME_UUID
= UUID
.fromString("7c17c811-4201-454b-8108-7be7c91c0938");
142 public static UUID SPECIES5_NAME_UUID
= UUID
.fromString("0c6ecaac-804d-49e5-a33f-1b7ee77439e3");
144 /****************** TESTS *****************************/
148 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#getTaxonByUuid(java.util.UUID)}.
151 public final void testGetTaxonByUuid() {
152 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
153 UUID uuid
= service
.save(expectedTaxon
).getUuid();
154 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
155 assertEquals(expectedTaxon
, actualTaxon
);
159 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#saveTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
162 public final void testSaveTaxon() {
163 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
164 UUID uuid
= service
.save(expectedTaxon
).getUuid();
165 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
166 assertEquals(expectedTaxon
, actualTaxon
);
170 public final void testSaveOrUpdateTaxon() {
171 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
172 UUID uuid
= service
.save(expectedTaxon
).getUuid();
173 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
174 assertEquals(expectedTaxon
, actualTaxon
);
176 actualTaxon
.setName(TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES()));
178 service
.saveOrUpdate(actualTaxon
);
185 public final void testSaveOrUpdateTaxonWithMisappliedName() {
186 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
187 TaxonName misappliedNameName
= TaxonName
.NewInstance(NomenclaturalCode
.ICNAFP
, Rank
.SPECIES(), "Abies", null, "alba", null, null, null, null, null);
189 UUID misappliedNameNameUuid
= nameService
.save(misappliedNameName
).getUuid();
190 misappliedNameName
= nameService
.find(misappliedNameNameUuid
);
191 SpecimenTypeDesignation typedes
= SpecimenTypeDesignation
.NewInstance();
192 DerivedUnit derivedUnit
= DerivedUnit
.NewPreservedSpecimenInstance();
193 FieldUnit fieldUnit
= FieldUnit
.NewInstance();
194 DerivationEvent derivationEvent
= DerivationEvent
.NewSimpleInstance(fieldUnit
, derivedUnit
, DerivationEventType
.ACCESSIONING());
195 // derivedUnit.addDerivationEvent(derivationEvent);
196 typedes
.setTypeSpecimen(derivedUnit
);
197 misappliedNameName
.addTypeDesignation(typedes
, false);
198 Taxon misappliedName
= Taxon
.NewInstance(misappliedNameName
, null);
199 UUID misappliedNameUuid
= service
.save(misappliedName
).getUuid();
200 misappliedName
= (Taxon
) service
.find(misappliedNameUuid
);
201 expectedTaxon
.addMisappliedName(misappliedName
, null, null);
202 UUID uuid
= service
.save(expectedTaxon
).getUuid();
203 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
204 assertEquals(expectedTaxon
, actualTaxon
);
205 misappliedName
.setSec(ReferenceFactory
.newArticle());
208 service
.saveOrUpdate(actualTaxon
);
209 misappliedName
= (Taxon
)service
.find(misappliedNameUuid
);
210 Assert
.assertNotNull(misappliedName
.getSec());
215 service
.getSession().flush();
216 service
.getSession().beginTransaction();
217 actualTaxon
= service
.find(uuid
);
218 ((Taxon
)actualTaxon
).getTaxonRelations(misappliedName
).iterator().next().getFromTaxon().setSec(null);
220 service
.saveOrUpdate(actualTaxon
);
221 misappliedName
= (Taxon
)service
.find(misappliedNameUuid
);
222 Assert
.assertNull(misappliedName
.getSec());
229 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#removeTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
232 public final void testRemoveTaxon() {
233 Taxon taxon
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.UNKNOWN_RANK()), null);
234 UUID uuid
= service
.save(taxon
).getUuid();
236 service
.deleteTaxon(taxon
.getUuid(), null, null);
237 /*} catch (DataChangeNoRollbackException e) {
238 // TODO Auto-generated catch block
241 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
242 assertNull(actualTaxon
);
247 public final void testMakeTaxonSynonym() {
250 } catch (FileNotFoundException e
) {
251 // TODO Auto-generated catch block
255 service
.swapSynonymAndAcceptedTaxon(synonym
, taxWithSyn
);
258 Taxon tax
= (Taxon
)service
.find(uuidTaxWithSyn
);
259 tax
.removeSynonym(synonym
);
260 tax
.addHomotypicSynonym(synonym
);
261 service
.saveOrUpdate(tax
);
262 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
264 assertTrue(tax
.getName().getTitleCache().equals("Test2"));
266 HomotypicalGroup groupTest
= tax
.getHomotypicGroup();
267 HomotypicalGroup groupTest2
= syn
.getHomotypicGroup();
268 assertEquals(groupTest
, groupTest2
);
273 public final void testChangeSynonymToAcceptedTaxon(){
276 } catch (FileNotFoundException e1
) {
277 // TODO Auto-generated catch block
278 e1
.printStackTrace();
283 UpdateResult result
= new UpdateResult();
285 result
= service
.changeSynonymToAcceptedTaxon(synonym
, taxWithSyn
, true);
286 } catch (HomotypicalGroupChangeException e
) {
287 Assert
.fail("Invocation of change method should not throw an exception");
290 //test flush (resave deleted object)
291 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
292 taxWithSyn
= (Taxon
)service
.find(uuidTaxWithSyn
);
293 Taxon taxNew
= (Taxon
)service
.find(result
.getCdmEntity().getUuid());
295 assertNotNull(taxWithSyn
);
296 assertNotNull(taxNew
);
298 Assert
.assertEquals("New taxon should have 1 synonym relationship (the old homotypic synonym)", 1, ((Taxon
)result
.getCdmEntity()).getSynonyms().size());
304 public final void testChangeSynonymToAcceptedTaxonSynonymForTwoTaxa(){
307 } catch (FileNotFoundException e1
) {
308 // TODO Auto-generated catch block
309 e1
.printStackTrace();
314 UpdateResult result
= new UpdateResult();
316 result
= service
.changeSynonymToAcceptedTaxon(synonym
, taxWithSyn
, true);
318 } catch (HomotypicalGroupChangeException e
) {
319 Assert
.fail("Invocation of change method should not throw an exception");
324 //test flush (resave deleted object)
325 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
326 taxWithSyn
= (Taxon
)service
.find(uuidTaxWithSyn
);
327 Taxon taxNew
= (Taxon
)service
.find(((Taxon
)result
.getCdmEntity()).getUuid());
329 assertNotNull(taxWithSyn
);
330 assertNotNull(taxNew
);
332 // Assert.assertEquals("New taxon should have 1 synonym relationship (the old homotypic synonym)", 1, taxon.getSynonymRelations().size());
336 * Old implementation taken from {@link TaxonServiceImplBusinessTest} for old version of method.
339 public final void testMoveSynonymToAnotherTaxon_OLD() {
340 SynonymType heteroTypicSynonymType
= SynonymType
.HETEROTYPIC_SYNONYM_OF();
341 Reference reference
= ReferenceFactory
.newGeneric();
342 String referenceDetail
= "test";
344 INonViralName t1n
= TaxonNameFactory
.NewNonViralInstance(null);
345 Taxon t1
= Taxon
.NewInstance(t1n
, reference
);
346 INonViralName t2n
= TaxonNameFactory
.NewNonViralInstance(null);
347 Taxon t2
= Taxon
.NewInstance(t2n
, reference
);
348 INonViralName s1n
= TaxonNameFactory
.NewNonViralInstance(null);
349 Synonym s1
= Synonym
.NewInstance(s1n
, reference
);
350 t1
.addSynonym(s1
, heteroTypicSynonymType
);
351 service
.saveOrUpdate(t1
);
353 Synonym synonym
= t1
.getSynonyms().iterator().next();
355 boolean keepReference
= false;
356 boolean moveHomotypicGroup
= false;
358 service
.moveSynonymToAnotherTaxon(synonym
, t2
, moveHomotypicGroup
, heteroTypicSynonymType
, reference
, referenceDetail
, keepReference
);
359 } catch (HomotypicalGroupChangeException e
) {
360 Assert
.fail("Method call should not throw exception");
363 Assert
.assertTrue("t1 should have no synonyms", t1
.getSynonyms().isEmpty());
365 Set
<Synonym
> synonyms
= t2
.getSynonyms();
366 Assert
.assertTrue("t2 should have exactly one synonym", synonyms
.size() == 1);
368 synonym
= synonyms
.iterator().next();
370 Assert
.assertEquals(t2
, synonym
.getAcceptedTaxon());
371 Assert
.assertEquals(heteroTypicSynonymType
, synonym
.getType());
372 Assert
.assertEquals(reference
, synonym
.getSec());
373 Assert
.assertEquals(referenceDetail
, synonym
.getSecMicroReference());
377 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testMoveSynonymToAnotherTaxon.xml")
378 public final void testMoveSynonymToAnotherTaxon() throws Exception
{
379 final String
[] tableNames
= new String
[]{};
381 // printDataSet(System.err, new String[]{"AgentBase", "TaxonBase"});
382 // printDataSet(System.err, new String[]{"TaxonNode"});
384 UUID uuidNewTaxon
= UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
385 UUID uuidOldTaxon
= UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
386 UUID uuidSyn1
= UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
387 UUID uuidSyn3
= UUID
.fromString("3fba2b22-22ae-4291-af67-faab748a5232");
388 UUID uuidSyn4
= UUID
.fromString("f9b589c7-50cf-4df2-a52e-1b85eb7e4805");
389 UUID uuidSyn5
= UUID
.fromString("fcc0bcf8-8bac-43bd-9508-1e97821587dd");
390 UUID uuidSyn6
= UUID
.fromString("0ccd4e7c-6fbd-4b7c-bd47-29e45b92f34b");
391 UUID uuidRef1
= UUID
.fromString("336f9b38-698c-45d7-be7b-993ed3355bdc");
392 UUID uuidRef2
= UUID
.fromString("c8f49d1a-69e1-48a3-98bb-45d61f3da3e7");
395 boolean moveHomotypicGroup
= true;
396 SynonymType newSynonymType
= null;
397 boolean keepReference
= true;
398 Reference newReference
= null;
399 String newReferenceDetail
= null;
401 Taxon newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
402 Synonym homotypicSynonym
= (Synonym
)service
.load(uuidSyn1
);
403 Assert
.assertNotNull("Synonym should exist", homotypicSynonym
);
404 Assert
.assertNotNull("Synonym should have 1 relation", homotypicSynonym
.getAcceptedTaxon());
405 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, homotypicSynonym
.getAcceptedTaxon().getUuid());
406 Taxon oldTaxon
= homotypicSynonym
.getAcceptedTaxon();
409 service
.moveSynonymToAnotherTaxon(homotypicSynonym
, newTaxon
, moveHomotypicGroup
, newSynonymType
, newReference
, newReferenceDetail
, keepReference
);
410 Assert
.fail("Homotypic synonym move to other taxon should throw an exception");
411 } catch (HomotypicalGroupChangeException e
) {
412 if (e
.getMessage().contains("Synonym is in homotypic group with accepted taxon and other synonym(s). First remove synonym from homotypic group of accepted taxon before moving to other taxon")){
414 commitAndStartNewTransaction(tableNames
);
416 Assert
.fail("Unexpected exception occurred: " + e
.getMessage());
420 homotypicSynonym
= (Synonym
)service
.load(uuidSyn1
);
421 Assert
.assertNotNull("Synonym should still exist", homotypicSynonym
);
422 Assert
.assertNotNull("Synonym should still have 1 relation", homotypicSynonym
.getAcceptedTaxon());
423 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", oldTaxon
, homotypicSynonym
.getAcceptedTaxon());
425 //test heterotypic synonym with other synonym in homotypic group
426 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
427 Synonym heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
428 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
429 Assert
.assertNotNull("Synonym should have 1 relation", heterotypicSynonym
.getAcceptedTaxon());
430 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, heterotypicSynonym
.getAcceptedTaxon().getUuid());
431 oldTaxon
= heterotypicSynonym
.getAcceptedTaxon();
432 moveHomotypicGroup
= false;
435 service
.moveSynonymToAnotherTaxon(heterotypicSynonym
, newTaxon
, moveHomotypicGroup
, newSynonymType
, newReference
, newReferenceDetail
, keepReference
);
436 Assert
.fail("Heterotypic synonym move to other taxon should throw an exception");
437 } catch (HomotypicalGroupChangeException e
) {
438 if (e
.getMessage().contains("Synonym is in homotypic group with other synonym(s). Either move complete homotypic group or remove synonym from homotypic group prior to moving to other taxon")){
440 commitAndStartNewTransaction(tableNames
);
442 Assert
.fail("Unexpected exception occurred: " + e
.getMessage());
446 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
447 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
448 Assert
.assertNotNull("Synonym should have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
449 Assert
.assertEquals("Accepted taxon of single relation should still be the old taxon", oldTaxon
, heterotypicSynonym
.getAcceptedTaxon());
452 //test heterotypic synonym with no other synonym in homotypic group
455 // printDataSet(System.err, new String[]{"TaxonBase"});
457 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
458 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn5
);
459 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
460 Assert
.assertNotNull("Synonym should have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
461 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, heterotypicSynonym
.getAcceptedTaxon().getUuid());
462 oldTaxon
= heterotypicSynonym
.getAcceptedTaxon();
463 moveHomotypicGroup
= false;
467 service
.moveSynonymToAnotherTaxon(heterotypicSynonym
, newTaxon
, moveHomotypicGroup
, newSynonymType
, newReference
, newReferenceDetail
, keepReference
);
468 } catch (HomotypicalGroupChangeException e
) {
469 Assert
.fail("Move of single heterotypic synonym should not throw exception: " + e
.getMessage());
472 //FIXME throws exception
473 commitAndStartNewTransaction(tableNames
);
475 // printDataSet(System.err, new String[]{"AgentBase", "TaxonBase"});
477 // printDataSet(System.err, new String[]{"TaxonBase"});
479 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn5
);
481 // printDataSet(System.err, new String[]{"TaxonBase"});
484 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
485 Assert
.assertNotNull("Synonym should have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
486 Assert
.assertEquals("Accepted taxon of single relation should be new taxon", newTaxon
, heterotypicSynonym
.getAcceptedTaxon());
487 Assert
.assertEquals("Old detail should be kept", "rel5", heterotypicSynonym
.getSecMicroReference());
490 //test heterotypic synonym with other synonym in homotypic group and moveHomotypicGroup="true"
492 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
493 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
494 Reference ref1
= referenceService
.load(uuidRef1
);
495 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
496 Assert
.assertNotNull("Synonym should have 1 relation", heterotypicSynonym
.getAcceptedTaxon());
497 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, heterotypicSynonym
.getAcceptedTaxon().getUuid());
498 oldTaxon
= heterotypicSynonym
.getAcceptedTaxon();
499 Assert
.assertEquals("Detail should be ref1", ref1
, heterotypicSynonym
.getSec());
500 Assert
.assertEquals("Detail should be 'rel3'", "rel3", heterotypicSynonym
.getSecMicroReference());
501 TaxonName oldSynName3
= heterotypicSynonym
.getName();
503 Synonym heterotypicSynonym4
= (Synonym
)service
.load(uuidSyn4
);
504 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym4
);
505 Assert
.assertNotNull("Synonym should have accepted taxon", heterotypicSynonym4
.getAcceptedTaxon());
506 Assert
.assertEquals("Accepted taxon of other synonym in group should be the old taxon", uuidOldTaxon
, heterotypicSynonym4
.getAcceptedTaxon().getUuid());
507 Assert
.assertSame("Homotypic group of both synonyms should be same", oldSynName3
.getHomotypicalGroup() , heterotypicSynonym4
.getName().getHomotypicalGroup() );
509 moveHomotypicGroup
= true;
510 keepReference
= false;
513 service
.moveSynonymToAnotherTaxon(heterotypicSynonym4
, newTaxon
, moveHomotypicGroup
, newSynonymType
, newReference
, newReferenceDetail
, keepReference
);
514 } catch (HomotypicalGroupChangeException e
) {
515 Assert
.fail("Move with 'moveHomotypicGroup = true' should not throw exception: " + e
.getMessage());
518 commitAndStartNewTransaction(tableNames
);
519 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
520 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
521 Assert
.assertNotNull("Synonym should still have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
522 Assert
.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon
, heterotypicSynonym
.getAcceptedTaxon());
523 TaxonName synName3
= heterotypicSynonym
.getName();
525 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn4
);
526 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
527 Assert
.assertNotNull("Synonym should still have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
528 Assert
.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon
, heterotypicSynonym
.getAcceptedTaxon());
529 Assert
.assertNull("Old citation should be removed", heterotypicSynonym
.getSec());
530 Assert
.assertNull("Old detail should be removed", heterotypicSynonym
.getSecMicroReference());
531 TaxonName synName4
= heterotypicSynonym
.getName();
532 Assert
.assertEquals("Homotypic group of both synonyms should be equal", synName3
.getHomotypicalGroup() , synName4
.getHomotypicalGroup() );
533 Assert
.assertSame("Homotypic group of both synonyms should be same", synName3
.getHomotypicalGroup() , synName4
.getHomotypicalGroup() );
534 Assert
.assertEquals("Homotypic group of both synonyms should be equal to old homotypic group", oldSynName3
.getHomotypicalGroup() , synName3
.getHomotypicalGroup() );
537 //test single heterotypic synonym to homotypic synonym of new taxon
539 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
540 Reference ref2
= referenceService
.load(uuidRef2
);
541 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn6
);
542 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
543 Assert
.assertNotNull("Synonym should have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
544 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, heterotypicSynonym
.getAcceptedTaxon().getUuid());
545 oldTaxon
= heterotypicSynonym
.getAcceptedTaxon();
546 moveHomotypicGroup
= false;
547 keepReference
= false;
549 newReferenceDetail
= "newRefDetail";
550 newSynonymType
= SynonymType
.HOMOTYPIC_SYNONYM_OF();
553 service
.moveSynonymToAnotherTaxon(heterotypicSynonym
, newTaxon
, moveHomotypicGroup
, newSynonymType
, newReference
, newReferenceDetail
, keepReference
);
554 } catch (HomotypicalGroupChangeException e
) {
555 Assert
.fail("Move of single heterotypic synonym should not throw exception: " + e
.getMessage());
558 commitAndStartNewTransaction(tableNames
);
559 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn6
);
560 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
561 Assert
.assertNotNull("Synonym should still have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
562 Assert
.assertEquals("Relationship type should be 'homotypic synonym'", newSynonymType
, heterotypicSynonym
.getType());
563 Assert
.assertEquals("Accepted taxon of single relation should be new taxon", newTaxon
, heterotypicSynonym
.getAcceptedTaxon());
564 Assert
.assertEquals("New citation should be ref2", ref2
,heterotypicSynonym
.getSec());
565 Assert
.assertEquals("New detail should be kept", "newRefDetail", heterotypicSynonym
.getSecMicroReference());
567 Assert
.assertEquals("New taxon and new synonym should have equal homotypical group", heterotypicSynonym
.getHomotypicGroup(), heterotypicSynonym
.getAcceptedTaxon().getHomotypicGroup());
568 Assert
.assertSame("New taxon and new synonym should have same homotypical group", heterotypicSynonym
.getHomotypicGroup(), heterotypicSynonym
.getAcceptedTaxon().getHomotypicGroup());
574 public final void testGetHeterotypicSynonymyGroups(){
575 Rank rank
= Rank
.SPECIES();
576 Reference ref1
= ReferenceFactory
.newGeneric();
577 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
578 Taxon taxon1
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
579 Synonym synonym0
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
580 Synonym synonym1
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
581 Synonym synonym2
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
582 synonym0
.getName().setHomotypicalGroup(taxon1
.getHomotypicGroup());
583 synonym2
.getName().setHomotypicalGroup(synonym1
.getHomotypicGroup());
584 //tax2.addHeterotypicSynonymName(synonym.getName());
585 taxon1
.addSynonym(synonym1
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
586 taxon1
.addSynonym(synonym2
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
588 service
.save(synonym1
);
589 service
.save(synonym2
);
590 service
.save(taxon1
);
592 List
<List
<Synonym
>> heteroSyns
= service
.getHeterotypicSynonymyGroups(taxon1
, null);
593 Assert
.assertEquals("There should be 1 heterotypic group", 1, heteroSyns
.size());
594 List
<Synonym
> synList
= heteroSyns
.get(0);
595 Assert
.assertEquals("There should be 2 heterotypic syns in group 1", 2, synList
.size());
598 synonym2
.setSec(ref1
);
599 heteroSyns
= service
.getHeterotypicSynonymyGroups(taxon1
, null);
600 Assert
.assertEquals("There should be 1 heterotypic group", 1, heteroSyns
.size());
601 synList
= heteroSyns
.get(0);
602 Assert
.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 2, synList
.size());
608 public final void testGetHomotypicSynonymsByHomotypicGroup(){
609 Rank rank
= Rank
.SPECIES();
610 Reference ref1
= ReferenceFactory
.newGeneric();
611 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
612 Taxon taxon1
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
613 Synonym synonym0
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
614 Synonym synonym1
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
615 Synonym synonym2
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
616 synonym0
.getName().setHomotypicalGroup(taxon1
.getHomotypicGroup());
617 synonym2
.getName().setHomotypicalGroup(synonym1
.getHomotypicGroup());
618 //tax2.addHeterotypicSynonymName(synonym.getName());
619 taxon1
.addSynonym(synonym0
, SynonymType
.HOMOTYPIC_SYNONYM_OF());
620 taxon1
.addSynonym(synonym1
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
621 taxon1
.addSynonym(synonym2
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
623 service
.save(synonym1
);
624 service
.save(synonym2
);
625 service
.save(taxon1
);
627 List
<Synonym
> homoSyns
= service
.getHomotypicSynonymsByHomotypicGroup(taxon1
, null);
628 Assert
.assertEquals("There should be 1 heterotypic group", 1, homoSyns
.size());
629 Assert
.assertSame("The homotypic synonym should be synonym0", synonym0
, homoSyns
.get(0));
632 synonym0
.setSec(ref1
);
633 homoSyns
= service
.getHomotypicSynonymsByHomotypicGroup(taxon1
, null);
634 Assert
.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 1, homoSyns
.size());
639 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
640 //test delete synonym, but the name will not be deleted
641 public final void testDeleteSynonymSynonymTaxonDontDeleteName(){
642 final String
[]tableNames
= {
643 // "TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
644 // "HomotypicalGroup","HomotypicalGroup_AUD"
647 int nSynonyms
= service
.count(Synonym
.class);
648 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
649 int nNames
= nameService
.count(TaxonName
.class);
650 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
651 int nRelations
= service
.countSynonyms(true);
652 Assert
.assertEquals("There should be two relationship left in the database", 2, nRelations
);
654 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
657 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
658 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
659 config
.setDeleteNameIfPossible(false);
660 config
.setNewHomotypicGroupIfNeeded(true);
661 service
.deleteSynonym(synonym1
, config
);
663 this.commitAndStartNewTransaction(tableNames
);
665 nSynonyms
= service
.count(Synonym
.class);
666 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
667 nNames
= nameService
.count(TaxonName
.class);
668 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
669 nRelations
= service
.countSynonyms(true);
670 Assert
.assertEquals("There should be no relationship left in the database", 1, nRelations
);
674 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
675 //test delete synonym and his name
676 public final void testDeleteSynonymSynonymTaxonDeleteName(){
677 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
678 "HomotypicalGroup","HomotypicalGroup_AUD"};
680 int nSynonyms
= service
.count(Synonym
.class);
681 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
682 int nNames
= nameService
.count(TaxonName
.class);
683 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
684 int nRelations
= service
.countSynonyms(true);
685 Assert
.assertEquals("There should be 2 relationship left in the database", 2, nRelations
);
687 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
690 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
691 service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
693 this.commitAndStartNewTransaction(tableNames
);
695 nSynonyms
= service
.count(Synonym
.class);
696 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
697 nNames
= nameService
.count(TaxonName
.class);
698 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
699 nRelations
= service
.countSynonyms(true);
700 Assert
.assertEquals("There should be 1 relationship left in the database", 1, nRelations
);
705 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
706 //test remove synonym from taxon -> synonym and name still in the db and the synonymrelationship to the other taxon
707 //test delete synonym -> all relationships are deleted, the name is deleted and the synonym itself
708 public final void testDeleteSynonymSynonymTaxonBooleanRelToOneTaxon(){
709 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
710 "HomotypicalGroup","HomotypicalGroup_AUD"};
712 int nSynonyms
= service
.count(Synonym
.class);
713 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
714 int nNames
= nameService
.count(TaxonName
.class);
715 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
717 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
718 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
719 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
722 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon1
);
724 List
<String
> initStrat
= new ArrayList
<String
>();
725 initStrat
.add("markers");
726 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
, initStrat
);
727 int nRelations
= service
.countSynonyms(true);
728 Assert
.assertEquals("There should be 2 relationship left in the database", 2, nRelations
);
730 taxon2
.removeSynonym(synonym1
, false);
731 service
.saveOrUpdate(taxon2
);
733 commitAndStartNewTransaction(null);
735 nSynonyms
= service
.count(Synonym
.class);
736 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
737 nNames
= nameService
.count(TaxonName
.class);
738 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
739 nRelations
= service
.countSynonyms(true);
740 Assert
.assertEquals("There should be 1 relationship left in the database", 1, nRelations
);
741 Marker marker1
= Marker
.NewInstance(MarkerType
.IMPORTED(), true);
742 Marker marker2
= Marker
.NewInstance(MarkerType
.COMPUTED(), true);
743 synonym1
.addMarker(marker1
);
744 synonym1
.addMarker(marker2
);
745 service
.update(synonym1
);
746 synonym1
=(Synonym
) service
.load(uuidSynonym1
);
749 Set
<Marker
> markers
= synonym1
.getMarkers();
750 Marker marker
= markers
.iterator().next();
751 UUID markerUUID
= marker
.getUuid();
752 // taxon2 = (Taxon)service.load(uuidTaxon2);
753 synonym1
= (Synonym
)service
.load(uuidSynonym1
);
754 //the marker should not prevent the deletion
755 DeleteResult result
= service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
761 commitAndStartNewTransaction(tableNames
);
762 nSynonyms
= service
.count(Synonym
.class);
763 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
764 nNames
= nameService
.count(TaxonName
.class);
765 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
766 nRelations
= service
.countSynonyms(true);
767 Assert
.assertEquals("There should be no relationship left in the database", 1, nRelations
);
768 marker
= markerService
.load(markerUUID
);
774 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
775 //this test is more or less obsolete since we have no synonym relationships anymore
776 //test delete synonym, only for a special taxon, but because of other relationships it will not be deleted at all
777 public final void testDeleteSynonymSynonymTaxonBooleanDeleteOneTaxon(){
778 final String
[]tableNames
= {
779 // "TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
780 // "HomotypicalGroup","HomotypicalGroup_AUD"
782 int nSynonyms
= service
.count(Synonym
.class);
783 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
784 int nNames
= nameService
.count(TaxonName
.class);
785 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
787 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
788 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
790 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon2
);
791 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
792 taxon2
.addSynonym(synonym1
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
793 service
.saveOrUpdate(synonym1
);
794 int nRelations
= service
.countSynonyms(true);
795 //this was "3" when we still had synonym relationships
796 Assert
.assertEquals("There should be 2 relationship left in the database", 2, nRelations
);
797 service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
799 this.commitAndStartNewTransaction(tableNames
);
801 nSynonyms
= service
.count(Synonym
.class);
802 //this was "2" when we still had synonym relationships
803 Assert
.assertEquals("There should still be 1 synonym left in the database", 1, nSynonyms
);
804 nNames
= nameService
.count(TaxonName
.class);
806 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
807 nRelations
= service
.countSynonyms(true);
808 Assert
.assertEquals("There should be 1 related synonym left in the database", 1, nRelations
);
812 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
814 public final void testDeleteSynonymWithAnnotations(){
815 final String
[]tableNames
= {
816 // "TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
817 // "HomotypicalGroup","HomotypicalGroup_AUD"
821 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
822 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
824 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon2
);
825 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
826 taxon2
.addSynonym(synonym1
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
828 Annotation annotation
= Annotation
.NewDefaultLanguageInstance("test");
829 synonym1
.addAnnotation(annotation
);
830 service
.saveOrUpdate(synonym1
);
832 DeleteResult result
= service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
833 if (result
.isError()){
836 this.commitAndStartNewTransaction(tableNames
);
843 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
845 public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedName(){
846 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
847 "HomotypicalGroup","HomotypicalGroup_AUD"};
849 int nSynonyms
= service
.count(Synonym
.class);
850 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
851 int nNames
= nameService
.count(TaxonName
.class);
852 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
854 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
855 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
856 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
857 UUID uuidSynonym2
=UUID
.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
858 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
860 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
861 TaxonName name2
= nameService
.load(uuidSynonymName2
);
862 UUID name3Uuid
= synonym1
.getName().getUuid();
863 TaxonName name3
= nameService
.load(name3Uuid
);
864 name3
.addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
866 service
.saveOrUpdate(synonym1
);
868 int nRelations
= nameService
.getAllRelationships(1000, 0).size();
869 logger
.info("number of name relations: " + nRelations
);
870 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
871 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
873 service
.deleteSynonym(synonym1
, config
);
875 this.commitAndStartNewTransaction(tableNames
);
876 //synonym is deleted, but the name can not be deleted because of a name relationship
877 nSynonyms
= service
.count(Synonym
.class);
878 Assert
.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms
);
879 nNames
= nameService
.count(TaxonName
.class);
880 Assert
.assertEquals("There should be 4 names left in the database (name is related to synonymName2)", 4, nNames
);
881 nRelations
= service
.countSynonyms(true);
882 //may change with better implementation of countAllRelationships (see #2653)
883 nRelations
= nameService
.getAllRelationships(1000, 0).size();
884 logger
.info("number of name relations: " + nRelations
);
885 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
889 name2
= nameService
.load(uuidSynonymName2
);
890 NameRelationship rel
= CdmBase
.deproxy(name2
.getNameRelations().iterator().next(), NameRelationship
.class);
891 name2
.removeNameRelationship(rel
);
892 nameService
.save(name2
);
894 this.endTransaction();
899 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
900 public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedNameDeleteAllNameRelations(){
901 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
902 "HomotypicalGroup","HomotypicalGroup_AUD"};
904 int nSynonyms
= service
.count(Synonym
.class);
905 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
906 int nNames
= nameService
.count(TaxonName
.class);
907 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
909 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
910 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
911 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
912 UUID uuidSynonym2
=UUID
.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
913 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
915 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
916 TaxonName name2
= nameService
.load(uuidSynonymName2
);
917 UUID name3Uuid
= synonym1
.getName().getUuid();
918 TaxonName name3
= nameService
.load(name3Uuid
);
919 name3
.addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
921 service
.saveOrUpdate(synonym1
);
923 int nRelations
= nameService
.getAllRelationships(1000, 0).size();
924 logger
.info("number of name relations: " + nRelations
);
925 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
926 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
927 NameDeletionConfigurator nameDeletionConfig
= new NameDeletionConfigurator();
928 nameDeletionConfig
.setRemoveAllNameRelationships(true);
929 config
.setNameDeletionConfig(nameDeletionConfig
);
931 service
.deleteSynonym(synonym1
, config
);
933 this.commitAndStartNewTransaction(tableNames
);
935 nSynonyms
= service
.count(Synonym
.class);
936 Assert
.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms
);
937 nNames
= nameService
.count(TaxonName
.class);
938 Assert
.assertEquals("There should be 3 names left in the database ", 3, nNames
);
939 nRelations
= service
.countSynonyms(true);
940 //may change with better implementation of countAllRelationships (see #2653)
941 nRelations
= nameService
.getAllRelationships(1000, 0).size();
942 logger
.info("number of name relations: " + nRelations
);
943 Assert
.assertEquals("There should be no name relationship left in the database", 0, nRelations
);
947 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
948 public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedNameIgnoreIsBasionym(){
949 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
950 "HomotypicalGroup","HomotypicalGroup_AUD"};
952 int nSynonyms
= service
.count(Synonym
.class);
953 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
954 int nNames
= nameService
.count(TaxonName
.class);
955 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
957 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
958 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
959 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
960 UUID uuidSynonym2
=UUID
.fromString("f8d86dc9-5f18-4877-be46-fbb9412465e4");
961 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
963 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
964 TaxonName synName2
= nameService
.load(uuidSynonymName2
);
965 UUID name3Uuid
= synonym1
.getName().getUuid();
966 TaxonName synName1
= nameService
.load(name3Uuid
);
967 synName1
.addRelationshipFromName(synName2
, NameRelationshipType
.BASIONYM(), null);
969 service
.saveOrUpdate(synonym1
);
971 int nRelations
= nameService
.getAllRelationships(1000, 0).size();
972 logger
.info("number of name relations: " + nRelations
);
973 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
974 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
975 NameDeletionConfigurator nameDeletionConfig
= new NameDeletionConfigurator();
976 nameDeletionConfig
.setIgnoreIsBasionymFor(true);
977 config
.setNameDeletionConfig(nameDeletionConfig
);
979 DeleteResult result
=service
.deleteSynonym(synonym1
, config
);
985 logger
.debug(result
);
986 this.commitAndStartNewTransaction(tableNames
);
988 nSynonyms
= service
.count(Synonym
.class);
989 Assert
.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms
);
990 nNames
= nameService
.count(TaxonName
.class);
991 Assert
.assertEquals("There should be 3 names left in the database ", 3, nNames
);
992 nRelations
= service
.countSynonyms(true);
993 //may change with better implementation of countAllRelationships (see #2653)
994 nRelations
= nameService
.getAllRelationships(1000, 0).size();
995 logger
.info("number of name relations: " + nRelations
);
996 Assert
.assertEquals("There should be no name relationship left in the database", 0, nRelations
);
1001 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
1002 public final void testDeleteSynonymSynonymTaxonBooleanWithRollback(){
1003 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
1004 "HomotypicalGroup","HomotypicalGroup_AUD"};
1006 int nSynonyms
= service
.count(Synonym
.class);
1007 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
1008 int nNames
= nameService
.count(TaxonName
.class);
1009 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
1010 int nRelations
= service
.countSynonyms(true);
1013 //may change with better implementation of countAllRelationships (see #2653)
1016 Assert
.assertEquals("There should be 2 relationships in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
1018 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
1019 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
1021 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
1022 TaxonName name2
= nameService
.load(uuidSynonymName2
);
1023 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
1025 service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
1028 // printDataSet(System.out, tableNames);
1029 this.startNewTransaction();
1031 nSynonyms
= service
.count(Synonym
.class);
1032 Assert
.assertEquals("There should still be 2 synonyms left in the database", 2, nSynonyms
);
1033 nNames
= nameService
.count(TaxonName
.class);
1034 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
1035 nRelations
= service
.countSynonyms(true);
1036 //may change with better implementation of countAllRelationships (see #2653)
1037 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
1042 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
1043 public final void testDeleteSynonymSynonymTaxonBooleanWithoutTransaction(){
1044 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
1045 "HomotypicalGroup","HomotypicalGroup_AUD"};
1047 int nSynonyms
= service
.count(Synonym
.class);
1048 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
1049 int nNames
= nameService
.count(TaxonName
.class);
1050 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
1051 int nRelations
= service
.countSynonyms(true);
1052 //may change with better implementation of countAllRelationships (see #2653)
1053 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationships) but no name relationship", 2, nRelations
);
1055 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
1056 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
1058 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
1059 TaxonName name2
= nameService
.load(uuidSynonymName2
);
1060 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null);
1062 service
.saveOrUpdate(synonym1
);
1063 nRelations
= service
.countSynonyms(true);
1064 Assert
.assertEquals("There should be two relationships in the database", 2, nRelations
);
1066 this.endTransaction();
1068 // printDataSet(System.out, tableNames);
1070 //out of wrapping transaction
1071 service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
1073 this.startNewTransaction();
1075 nSynonyms
= service
.count(Synonym
.class);
1076 Assert
.assertEquals("There should still be 1 synonyms left in the database. The rollback on name delete should not lead to rollback in synonym delete.", 1, nSynonyms
);
1077 nNames
= nameService
.count(TaxonName
.class);
1078 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
1079 nRelations
= service
.countSynonyms(true);
1080 Assert
.assertEquals("There should be no taxon or synonym relationship in the database", 1, nRelations
);
1081 nRelations
= nameService
.getAllRelationships(1000,0).size();
1082 Assert
.assertEquals("There should be one name relationship in the database", 1, nRelations
);
1087 @DataSet("TaxonServiceImplTest.testInferredSynonyms.xml")
1088 public void testCreateInferredSynonymy(){
1090 UUID classificationUuid
= UUID
.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9");
1091 Classification tree
= classificationService
.find(classificationUuid
);
1092 UUID taxonUuid
= UUID
.fromString("bc09aca6-06fd-4905-b1e7-cbf7cc65d783");
1093 TaxonBase
<?
> taxonBase
= service
.find(taxonUuid
);
1094 List
<Synonym
> synonyms
= service
.list(Synonym
.class, null, null, null, null);
1095 assertEquals("Number of synonyms should be 2",2,synonyms
.size());
1096 Taxon taxon
= (Taxon
)taxonBase
;
1098 //synonyms = taxonDao.getAllSynonyms(null, null);
1099 //assertEquals("Number of synonyms should be 2",2,synonyms.size());
1100 List
<Synonym
> inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymType
.INFERRED_EPITHET_OF(), true);
1101 assertNotNull("there should be a new synonym ", inferredSynonyms
);
1102 assertEquals ("the name of inferred epithet should be SynGenus lachesis", "SynGenus lachesis syn. sec. Sp. Pl.", inferredSynonyms
.get(0).getTitleCache());
1104 inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymType
.INFERRED_GENUS_OF(), true);
1105 assertNotNull("there should be a new synonym ", inferredSynonyms
);
1106 assertEquals ("the name of inferred epithet should be SynGenus lachesis", "Acherontia ciprosus syn. sec. Sp. Pl.", inferredSynonyms
.get(0).getTitleCache());
1108 inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymType
.POTENTIAL_COMBINATION_OF(), true);
1109 assertNotNull("there should be a new synonym ", inferredSynonyms
);
1110 assertEquals ("the name of inferred epithet should be SynGenus lachesis", "SynGenus ciprosus syn. sec. Sp. Pl.", inferredSynonyms
.get(0).getTitleCache());
1111 //assertTrue("set of synonyms should contain an inferred Synonym ", synonyms.contains(arg0))
1115 @DataSet("../../database/BlankDataSet.xml")
1116 public final void testTaxonDeletionConfig(){
1117 final String
[]tableNames
= {}
1118 // "Classification", "Classification_AUD",
1119 // "TaxonBase","TaxonBase_AUD",
1120 // "TaxonNode","TaxonNode_AUD",
1121 // "TaxonName","TaxonName_AUD",
1122 // "TaxonRelationship", "TaxonRelationship_AUD",
1123 // "TaxonDescription", "TaxonDescription_AUD",
1124 // "HomotypicalGroup","HomotypicalGroup_AUD",
1125 // "PolytomousKey","PolytomousKey_AUD",
1126 // "PolytomousKeyNode","PolytomousKeyNode_AUD",
1127 // "Media","Media_AUD",
1128 // "DescriptiveDataSet","DescriptiveDataSet_AUD",
1129 // "DescriptionElementBase","DescriptionElementBase_AUD",
1130 // "DeterminationEvent","DeterminationEvent_AUD",
1131 // "SpecimenOrObservationBase","SpecimenOrObservationBase_AUD"}
1134 UUID uuidParent
=UUID
.fromString("b5271d4f-e203-4577-941f-00d76fa9f4ca");
1135 UUID uuidChild1
=UUID
.fromString("326167f9-0b97-4e7d-b1bf-4ca47b82e21e");
1136 UUID uuidSameAs
=UUID
.fromString("c2bb0f01-f2dd-43fb-ba12-2a85727ccb8d");
1137 commitAndStartNewTransaction(tableNames
);
1138 Taxon testTaxon
=getTestTaxon();
1139 // service.save(testTaxon);
1140 commitAndStartNewTransaction(tableNames
);
1141 int nTaxa
= service
.count(Taxon
.class);
1143 Assert
.assertEquals("There should be 4 taxa in the database", 4, nTaxa
);
1144 Taxon parent
= (Taxon
)service
.find(GENUS_UUID
);
1145 Assert
.assertNotNull("Parent taxon should exist", parent
);
1146 Taxon child1
= (Taxon
)service
.find(SPECIES1_UUID
);
1147 Assert
.assertNotNull("Child taxon should exist", child1
);
1148 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1149 config
.setDeleteTaxonNodes(false);
1150 config
.setDeleteMisappliedNamesAndInvalidDesignations(false);
1152 //commitAndStartNewTransaction(tableNames);
1154 DeleteResult result
= service
.deleteTaxon(child1
.getUuid(), config
, null);
1156 Assert
.fail("Delete should throw an error as long as name is used in classification.");
1159 nTaxa
= service
.count(Taxon
.class);
1160 Assert
.assertEquals("There should be 4 taxa in the database", 4, nTaxa
);
1161 child1
= (Taxon
)service
.find(SPECIES1_UUID
);
1162 Assert
.assertNotNull("Child taxon should exist", child1
);
1163 Assert
.assertEquals("Child should belong to 1 node", 1, child1
.getTaxonNodes().size());
1165 TaxonNode node
= child1
.getTaxonNodes().iterator().next();
1166 child1
.addSource(IdentifiableSource
.NewInstance(OriginalSourceType
.Import
));
1168 SpecimenOrObservationBase
<?
> identifiedUnit
= DerivedUnit
.NewInstance(SpecimenOrObservationType
.DerivedUnit
);
1169 DeterminationEvent
.NewInstance(child1
, identifiedUnit
);
1170 //UUID eventUUID = eventService.save(determinationEvent);
1171 UUID identifiedUnitUUID
= occurenceService
.save(identifiedUnit
).getUuid();
1174 TaxonNode parentNode
= node
.getParent();
1175 parentNode
=CdmBase
.deproxy(parentNode
, TaxonNode
.class);
1176 parentNode
.deleteChildNode(node
);
1177 nodeService
.save(parentNode
);
1178 //commitAndStartNewTransaction(tableNames);
1182 result
= service
.deleteTaxon(child1
1183 .getUuid(), config
, null);
1185 Assert
.fail("Delete should throw an exception because of the determination event");
1190 //determinationEvent = (DeterminationEvent)eventService.load(eventUUID);
1191 commitAndStartNewTransaction(tableNames
);
1192 identifiedUnit
= occurenceService
.load(identifiedUnitUUID
);
1194 occurenceService
.delete(identifiedUnit
);
1196 commitAndStartNewTransaction(tableNames
);
1197 child1
= (Taxon
)service
.find(SPECIES1_UUID
);
1199 assertEquals(0, child1
.getTaxonNodes().size());
1202 result
= service
.deleteTaxon(child1
.getUuid(), config
, null);
1204 if (!result
.isOk()){
1205 Assert
.fail("Delete should not throw an exception anymore");
1208 nTaxa
= service
.count(Taxon
.class);
1209 Assert
.assertEquals("There should be 3 taxa in the database", 3, nTaxa
);
1211 config
.setDeleteTaxonNodes(true);
1212 Taxon child2
=(Taxon
) service
.find(SPECIES2_UUID
);
1215 result
= service
.deleteTaxon(child2
.getUuid(), config
, child2
.getTaxonNodes().iterator().next().getClassification().getUuid());
1216 if (!result
.isOk()){
1217 Assert
.fail("Delete should not throw an exception");
1221 //service.find(uuid);
1223 nTaxa
= service
.count(Taxon
.class);
1224 Assert
.assertEquals("There should be 2 taxa in the database",2, nTaxa
);
1225 // nNames = nameService.count(TaxonName.class);
1226 // Assert.assertEquals("There should be 3 names left in the database", 3, nNames);
1227 // int nRelations = service.countAllRelationships();
1228 // Assert.assertEquals("There should be no relationship left in the database", 0, nRelations);
1233 @DataSet(value
="../../database/BlankDataSet.xml")
1234 public final void testDeleteTaxon(){
1236 //create a small classification
1238 Taxon testTaxon
= getTestTaxon();
1240 service
.save(testTaxon
).getUuid();
1242 Taxon speciesTaxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1243 Iterator
<TaxonDescription
> descriptionIterator
= speciesTaxon
.getDescriptions().iterator();
1244 UUID descrUUID
= null;
1245 UUID descrElementUUID
= null;
1246 if (descriptionIterator
.hasNext()){
1247 TaxonDescription descr
= descriptionIterator
.next();
1248 descrUUID
= descr
.getUuid();
1249 descrElementUUID
= descr
.getElements().iterator().next().getUuid();
1251 IBotanicalName taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1252 assertNotNull(taxonName
);
1254 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1255 config
.setDeleteNameIfPossible(false);
1261 DeleteResult result
= service
.deleteTaxon(speciesTaxon
.getUuid(), config
, speciesTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1262 if (!result
.isOk()){
1265 commitAndStartNewTransaction(null);
1267 taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1268 Taxon taxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1270 //descriptionService.find(descrUUID);
1271 assertNull(descriptionService
.find(descrUUID
));
1272 assertNull(descriptionService
.getDescriptionElementByUuid(descrElementUUID
));
1273 //assertNull(synName);
1274 assertNotNull(taxonName
);
1276 config
.setDeleteNameIfPossible(true);
1277 Taxon newTaxon
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES()), null);
1278 service
.save(newTaxon
);
1279 result
= service
.deleteTaxon(newTaxon
.getUuid()
1281 if (!result
.isOk()){
1289 @DataSet(value
="../../database/BlankDataSet.xml")
1290 public final void testDeleteTaxonWithAnnotations(){
1292 //create a small classification
1294 Taxon testTaxon
= getTestTaxon();
1296 service
.save(testTaxon
).getUuid();
1298 Taxon speciesTaxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1299 Iterator
<TaxonDescription
> descriptionIterator
= speciesTaxon
.getDescriptions().iterator();
1300 UUID descrUUID
= null;
1301 UUID descrElementUUID
= null;
1302 if (descriptionIterator
.hasNext()){
1303 TaxonDescription descr
= descriptionIterator
.next();
1304 descrUUID
= descr
.getUuid();
1305 descrElementUUID
= descr
.getElements().iterator().next().getUuid();
1307 IBotanicalName taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1308 assertNotNull(taxonName
);
1310 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1311 config
.setDeleteNameIfPossible(false);
1312 Annotation annotation
= Annotation
.NewDefaultLanguageInstance("test");
1313 speciesTaxon
.addAnnotation(annotation
);
1318 DeleteResult result
= service
.deleteTaxon(speciesTaxon
.getUuid(), config
, speciesTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1319 if (!result
.isOk()){
1322 commitAndStartNewTransaction(null);
1324 taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1325 Taxon taxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1327 //descriptionService.find(descrUUID);
1328 assertNull(descriptionService
.find(descrUUID
));
1329 assertNull(descriptionService
.getDescriptionElementByUuid(descrElementUUID
));
1330 //assertNull(synName);
1331 assertNotNull(taxonName
);
1333 config
.setDeleteNameIfPossible(true);
1334 Taxon newTaxon
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES()), null);
1335 service
.save(newTaxon
);
1336 result
= service
.deleteTaxon(newTaxon
.getUuid()
1338 if (!result
.isOk()){
1346 @DataSet(value
="../../database/BlankDataSet.xml")
1347 public final void testDeleteTaxonUsedInTaxonRelation(){
1349 //create a small classification
1350 Taxon testTaxon
= getTestTaxon();
1352 service
.save(testTaxon
).getUuid();
1354 Taxon speciesTaxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1355 Taxon speciesTaxon2
= (Taxon
)service
.find(SPECIES2_UUID
);
1356 speciesTaxon
.addTaxonRelation(speciesTaxon2
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR(), null, null);
1358 IBotanicalName taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1359 assertNotNull(taxonName
);
1361 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1362 config
.setDeleteNameIfPossible(false);
1363 config
.setDeleteTaxonRelationships(false);
1368 DeleteResult result
= service
.deleteTaxon(speciesTaxon
.getUuid(), config
, speciesTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1372 commitAndStartNewTransaction(null);
1374 taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1375 Taxon taxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1378 assertNotNull(taxonName
);
1379 assertNotNull(taxon
);
1382 config
.setDeleteNameIfPossible(false);
1383 config
.setDeleteTaxonRelationships(true);
1388 result
= service
.deleteTaxon(speciesTaxon
.getUuid(), config
, speciesTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1389 if (!result
.isOk()){
1392 commitAndStartNewTransaction(null);
1395 config
.setDeleteNameIfPossible(true);
1396 Taxon newTaxon
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES()), null);
1397 service
.save(newTaxon
);
1398 result
= service
.deleteTaxon(newTaxon
.getUuid()
1400 if (!result
.isOk()){
1408 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="../../database/BlankDataSet.xml")
1409 public final void testDeleteTaxonDeleteSynonymRelations(){
1411 final String
[]tableNames
= {
1412 "Classification", "Classification_AUD",
1413 "TaxonBase","TaxonBase_AUD",
1414 "TaxonNode","TaxonNode_AUD",
1415 "TaxonName","TaxonName_AUD"};
1416 commitAndStartNewTransaction(tableNames
);
1417 //create a small classification
1418 Taxon testTaxon
= getTestTaxon();
1420 service
.save(testTaxon
).getUuid();
1422 Taxon speciesTaxon
= (Taxon
)service
.find(SPECIES2_UUID
);
1424 Synonym synonym
= speciesTaxon
.getSynonyms().iterator().next();
1425 UUID synonymUuid
= synonym
.getUuid();
1426 service
.countSynonyms(true);
1428 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1429 config
.setDeleteSynonymsIfPossible(false);
1432 DeleteResult result
= service
.deleteTaxon(speciesTaxon
.getUuid(), config
, speciesTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1433 if (!result
.isOk()){
1436 commitAndStartNewTransaction(null);
1438 Taxon taxon
= (Taxon
)service
.find(SPECIES2_UUID
);
1439 assertNull("The deleted taxon should no longer exist", taxon
);
1441 Synonym syn
= (Synonym
)service
.find(synonymUuid
);
1442 assertNotNull("The synonym should still exist since DeleteSynonymsIfPossible was false", service
.find(synonymUuid
));
1443 assertNull("The synonym should not be attached to an accepted taxon anymore", syn
.getAcceptedTaxon());
1448 @DataSet(value
="../../database/BlankDataSet.xml")
1449 public final void testDeleteTaxonNameUsedInOtherContext(){
1451 //create a small classification
1452 Taxon testTaxon
= getTestTaxon();
1454 service
.save(testTaxon
).getUuid();
1456 Taxon speciesTaxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1458 IBotanicalName taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1459 assertNotNull(taxonName
);
1460 TaxonName fromName
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
1461 taxonName
.addRelationshipFromName(fromName
, NameRelationshipType
.VALIDATED_BY_NAME(), null);
1462 nameService
.save(fromName
);
1464 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1465 config
.setDeleteNameIfPossible(true);
1466 DeleteResult result
= service
.deleteTaxon(speciesTaxon
.getUuid(), config
, speciesTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1467 if (!result
.isOk()){
1470 commitAndStartNewTransaction(null);
1472 taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1473 Taxon taxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1474 //because of the namerelationship the name cannot be deleted
1475 assertNotNull(taxonName
);
1481 @DataSet(value
="../../database/BlankDataSet.xml")
1482 public final void testDeleteTaxonNameUsedInTwoClassificationsDeleteAllNodes(){
1483 commitAndStartNewTransaction(null);
1484 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1485 //create a small classification
1486 Taxon testTaxon
= getTestTaxon();
1488 UUID uuid
= service
.save(testTaxon
).getUuid();
1489 //BotanicalName name = nameService.find(uuid);
1490 Set
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes();
1491 TaxonNode node
= nodes
.iterator().next();
1492 List
<TaxonNode
> childNodes
= node
.getChildNodes();
1493 TaxonNode childNode
= childNodes
.iterator().next();
1494 UUID childUUID
= childNode
.getTaxon().getUuid();
1495 Classification secondClassification
= getTestClassification("secondClassification");
1497 secondClassification
.addChildTaxon(testTaxon
, null, null);
1498 //delete the taxon in all classifications
1499 config
.setDeleteInAllClassifications(true);
1500 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, null);
1501 if (!result
.isOk()){
1504 commitAndStartNewTransaction(null);
1505 Taxon tax
= (Taxon
)service
.find(uuid
);
1507 Taxon childTaxon
= (Taxon
)service
.find(childUUID
);
1509 commitAndStartNewTransaction(null);
1518 @DataSet(value
="../../database/BlankDataSet.xml")
1519 public final void testDeleteTaxonNameUsedInTwoClassificationsDoNotDeleteAllNodes(){
1520 // delete the taxon only in second classification, this should delete only the nodes, not the taxa
1521 Taxon testTaxon
= getTestTaxon();
1522 UUID uuid
= service
.save(testTaxon
).getUuid();
1523 Classification secondClassification
= getTestClassification("secondClassification");
1524 Set
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes();
1525 TaxonNode node
= nodes
.iterator().next();
1526 List
<TaxonNode
> childNodes
= node
.getChildNodes();
1527 TaxonNode childNode
= childNodes
.iterator().next();
1528 UUID childUUID
= childNode
.getTaxon().getUuid();
1529 childNode
= secondClassification
.addChildTaxon(testTaxon
, null, null);
1530 UUID childNodeUUID
= childNode
.getUuid();
1532 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1533 config
.setDeleteInAllClassifications(false);
1535 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, secondClassification
.getUuid());
1536 /* Assert.fail("The taxon should not be deletable because it is used in a second classification and the configuration is set to deleteInAllClassifications = false");
1537 } catch (DataChangeNoRollbackException e) {
1538 logger.debug(e.getMessage());
1543 Assert
.fail("The taxon should not be deletable because it is used in a second classification and the configuration is set to deleteInAllClassifications = false");
1546 //commitAndStartNewTransaction(null);
1547 Taxon tax
= (Taxon
)service
.find(uuid
);
1549 Taxon childTaxon
= (Taxon
)service
.find(childUUID
);
1551 node
= nodeService
.find(childNodeUUID
);
1556 @DataSet(value
="../../database/BlankDataSet.xml")
1557 public final void testTaxonNodeDeletionConfiguratorMoveToParent(){
1558 //test childHandling MOVE_TO_PARENT:
1559 Taxon testTaxon
= getTestTaxon();
1560 UUID uuid
= service
.save(testTaxon
).getUuid();
1562 Taxon topMost
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.FAMILY()), null);
1564 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1565 TaxonNode node
=nodes
.next();
1566 Classification classification
= node
.getClassification();
1567 classification
.addParentChild(topMost
, testTaxon
, null, null);
1568 UUID topMostUUID
= service
.save(topMost
).getUuid();
1570 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1571 config
.getTaxonNodeConfig().setChildHandling(ChildHandling
.MOVE_TO_PARENT
);
1574 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, classification
.getUuid());
1579 commitAndStartNewTransaction(null);
1580 Taxon tax
= (Taxon
)service
.find(uuid
);
1582 tax
= (Taxon
)service
.find(topMostUUID
);
1583 Set
<TaxonNode
> topMostNodes
= tax
.getTaxonNodes();
1584 assertNotNull(topMostNodes
);
1585 assertEquals("there should be one taxon node", 1, topMostNodes
.size());
1586 nodes
= topMostNodes
.iterator();
1587 TaxonNode topMostNode
= nodes
.next();
1588 int size
= topMostNode
.getChildNodes().size();
1590 assertEquals(2, size
);
1594 @DataSet(value
="../../database/BlankDataSet.xml")
1595 public final void testTaxonNodeDeletionConfiguratorDeleteChildren(){
1596 //test childHandling DELETE:
1597 Taxon testTaxon
= getTestTaxon();
1598 UUID uuid
= service
.save(testTaxon
).getUuid();
1600 Taxon topMost
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.FAMILY()), null);
1602 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1603 TaxonNode node
=nodes
.next();
1604 UUID taxonNodeUUID
= node
.getUuid();
1605 Classification classification
= node
.getClassification();
1606 classification
.addParentChild(topMost
, testTaxon
, null, null);
1607 UUID topMostUUID
= service
.save(topMost
).getUuid();
1609 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1610 config
.getTaxonNodeConfig().setChildHandling(ChildHandling
.DELETE
);
1613 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, testTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1617 commitAndStartNewTransaction(null);
1618 Taxon tax
= (Taxon
)service
.find(uuid
);
1620 tax
= (Taxon
)service
.find(topMostUUID
);
1621 Set
<TaxonNode
> topMostNodes
= tax
.getTaxonNodes();
1622 assertNotNull(topMostNodes
);
1623 assertEquals("there should be one taxon node", 1, topMostNodes
.size());
1624 nodes
= topMostNodes
.iterator();
1625 TaxonNode topMostNode
= nodes
.next();
1626 int size
= topMostNode
.getChildNodes().size();
1627 node
= nodeService
.find(taxonNodeUUID
);
1629 assertEquals(0, size
);
1634 @DataSet(value
="../../database/BlankDataSet.xml")
1635 public final void testTaxonDeletionConfiguratorDeleteMarker(){
1636 //test childHandling DELETE:
1637 Taxon testTaxon
= getTestTaxon();
1638 UUID uuid
= service
.save(testTaxon
).getUuid();
1640 Taxon topMost
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.FAMILY()), null);
1642 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1643 TaxonNode node
=nodes
.next();
1644 Classification classification
= node
.getClassification();
1645 classification
.addParentChild(topMost
, testTaxon
, null, null);
1646 UUID topMostUUID
= service
.save(topMost
).getUuid();
1647 Marker marker
= Marker
.NewInstance(testTaxon
, true, MarkerType
.IS_DOUBTFUL());
1648 testTaxon
.addMarker(marker
);
1649 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1650 config
.getTaxonNodeConfig().setChildHandling(ChildHandling
.DELETE
);
1652 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, node
.getClassification().getUuid());
1657 commitAndStartNewTransaction(null);
1658 Taxon tax
= (Taxon
)service
.find(uuid
);
1660 tax
= (Taxon
)service
.find(topMostUUID
);
1661 Set
<TaxonNode
> topMostNodes
= tax
.getTaxonNodes();
1662 assertNotNull(topMostNodes
);
1663 assertEquals("there should be one taxon node", 1, topMostNodes
.size());
1664 nodes
= topMostNodes
.iterator();
1665 TaxonNode topMostNode
= nodes
.next();
1666 int size
= topMostNode
.getChildNodes().size();
1668 assertEquals(0, size
);
1673 @DataSet(value
="../../database/BlankDataSet.xml")
1674 public final void testTaxonDeletionConfiguratorTaxonWithMisappliedName(){
1676 Taxon testTaxon
= getTestTaxon();
1677 UUID uuid
= service
.save(testTaxon
).getUuid();
1679 Taxon misappliedName
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.GENUS()), null);
1681 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1682 TaxonNode node
=nodes
.next();
1683 testTaxon
.addMisappliedName(misappliedName
, null, null);
1684 UUID misappliedNameUUID
= service
.save(misappliedName
).getUuid();
1686 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1687 config
.setDeleteMisappliedNamesAndInvalidDesignations(true);
1689 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, node
.getClassification().getUuid());
1693 commitAndStartNewTransaction(null);
1694 Taxon tax
= (Taxon
)service
.find(uuid
);
1696 tax
= (Taxon
)service
.find(misappliedNameUUID
);
1697 //TODO: is that correct or should it be deleted because there is no relation to anything
1702 @DataSet(value
="../../database/BlankDataSet.xml")
1703 public final void testTaxonDeletionConfiguratorTaxonWithMisappliedNameDoNotDelete(){
1705 Taxon testTaxon
= getTestTaxon();
1706 UUID uuid
= service
.save(testTaxon
).getUuid();
1708 Taxon misappliedName
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.GENUS()), null);
1710 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1711 TaxonNode node
=nodes
.next();
1712 testTaxon
.addMisappliedName(misappliedName
, null, null);
1713 UUID misappliedNameUUID
= service
.save(misappliedName
).getUuid();
1715 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1716 config
.setDeleteMisappliedNamesAndInvalidDesignations(false);
1718 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, node
.getClassification().getUuid());
1722 commitAndStartNewTransaction(null);
1723 Taxon tax
= (Taxon
)service
.find(uuid
);
1725 tax
= (Taxon
)service
.find(misappliedNameUUID
);
1726 //TODO: is that correct or should it be deleted because there is no relation to anything
1732 @DataSet(value
="../../database/BlankDataSet.xml")
1733 public final void testTaxonDeletionConfiguratorTaxonMisappliedName(){
1735 Taxon testTaxon
= getTestTaxon();
1736 UUID uuid
= service
.save(testTaxon
).getUuid();
1738 Taxon misappliedNameTaxon
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.GENUS()), null);
1740 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1741 TaxonNode node
=nodes
.next();
1742 testTaxon
.addMisappliedName(misappliedNameTaxon
, null, null);
1743 UUID misappliedNameUUID
= service
.save(misappliedNameTaxon
).getUuid();
1744 misappliedNameTaxon
= (Taxon
)service
.find(misappliedNameUUID
);
1745 UUID misNameUUID
= misappliedNameTaxon
.getName().getUuid();
1747 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1751 service
.deleteTaxon(misappliedNameTaxon
.getUuid(), config
,null);
1752 // } catch (DataChangeNoRollbackException e) {
1753 // e.printStackTrace();
1757 commitAndStartNewTransaction(null);
1758 Taxon tax
= (Taxon
)service
.find(uuid
);
1760 tax
= (Taxon
)service
.find(misappliedNameUUID
);
1761 IBotanicalName name
= nameService
.find(misNameUUID
);
1769 @DataSet(value
="../../database/BlankDataSet.xml")
1770 public final void testLlistIncludedTaxa(){
1771 Reference citation
= null;
1772 String microcitation
= null;
1775 Classification cl1
= Classification
.NewInstance("testClassification1");
1776 Classification cl2
= Classification
.NewInstance("testClassification2");
1777 Classification cl3
= Classification
.NewInstance("testClassification3");
1779 classificationService
.save(cl1
);
1780 classificationService
.save(cl2
);
1781 classificationService
.save(cl3
);
1783 Taxon c1Genus
= Taxon
.NewInstance(null, null);c1Genus
.setUuid(UUID
.fromString("daa24f6f-7e38-4668-b385-10c789212e4e"));
1784 Taxon c1Species
= Taxon
.NewInstance(null, null);c1Species
.setUuid(UUID
.fromString("1c1d0566-67d0-4806-bf23-ecf55f4b9118"));
1785 Taxon c1SubSpecies1
= Taxon
.NewInstance(null, null);c1SubSpecies1
.setUuid(UUID
.fromString("96ae2fad-76df-429f-b179-42e00838fea4"));
1786 Taxon c1SubSpecies2
= Taxon
.NewInstance(null, null);c1SubSpecies2
.setUuid(UUID
.fromString("5d3f6147-ca72-40e0-be8a-6c835a09a579"));
1787 TaxonNode c1childNodeSpecies1
= cl1
.addParentChild(c1Genus
, c1Species
, null, null);
1788 nodeService
.saveOrUpdate(c1childNodeSpecies1
);
1789 TaxonNode c1childNodeSubSpecies1
=cl1
.addParentChild(c1Species
, c1SubSpecies1
, null, null);
1790 nodeService
.saveOrUpdate(c1childNodeSubSpecies1
);
1791 TaxonNode c1childNodeSubSpecies2
=cl1
.addParentChild(c1Species
, c1SubSpecies2
, null, null);
1792 nodeService
.saveOrUpdate(c1childNodeSubSpecies2
);
1794 Taxon c2Genus
= Taxon
.NewInstance(null, null);c2Genus
.setUuid(UUID
.fromString("ed0ec006-3ac8-4a12-ae13-fdf2a13dedbe"));
1795 Taxon c2Species
= Taxon
.NewInstance(null, null);c2Species
.setUuid(UUID
.fromString("1027eb18-1c26-450e-a299-981b775ebc3c"));
1796 Taxon c2SubSpecies1
= Taxon
.NewInstance(null, null);c2SubSpecies1
.setUuid(UUID
.fromString("61f039c8-01f3-4f5d-8e16-1602139774e7"));
1797 Taxon c2SubSpecies2
= Taxon
.NewInstance(null, null);c2SubSpecies2
.setUuid(UUID
.fromString("2ed6b6f8-05f9-459a-a075-2bca57e3013e"));
1798 TaxonNode c2childNodeSpecies1
= cl2
.addParentChild(c2Genus
, c2Species
, null, null);
1799 nodeService
.saveOrUpdate(c2childNodeSpecies1
);
1800 TaxonNode c2childNodeSubSpecies1
= cl2
.addParentChild(c2Species
, c2SubSpecies1
, null, null);
1801 nodeService
.saveOrUpdate(c2childNodeSubSpecies1
);
1802 TaxonNode c2childNodeSubSpecies2
= cl2
.addParentChild(c2Species
, c2SubSpecies2
, null, null);
1803 nodeService
.saveOrUpdate(c2childNodeSubSpecies2
);
1805 Taxon c3Genus
= Taxon
.NewInstance(null, null);c3Genus
.setUuid(UUID
.fromString("407dfc8d-7a4f-4370-ada4-76c1a8279d1f"));
1806 Taxon c3Species
= Taxon
.NewInstance(null, null);c3Species
.setUuid(UUID
.fromString("b6d34fc7-4aa7-41e5-b633-86f474edbbd5"));
1807 Taxon c3SubSpecies1
= Taxon
.NewInstance(null, null);c3SubSpecies1
.setUuid(UUID
.fromString("01c07585-a422-40cd-9339-a74c56901d9f"));
1808 Taxon c3SubSpecies2
= Taxon
.NewInstance(null, null);c3SubSpecies2
.setUuid(UUID
.fromString("390c8e23-e05f-4f89-b417-50cf080f4c91"));
1809 TaxonNode c3childNodeSpecies1
= cl3
.addParentChild(c3Genus
, c3Species
, null, null);
1810 nodeService
.saveOrUpdate(c3childNodeSpecies1
);
1811 TaxonNode c3childNodeSubSpecies1
= cl3
.addParentChild(c3Species
, c3SubSpecies1
, null, null);
1812 nodeService
.saveOrUpdate(c3childNodeSubSpecies1
);
1813 TaxonNode c3childNodeSubSpecies2
= cl3
.addParentChild(c3Species
, c3SubSpecies2
, null, null);
1814 nodeService
.saveOrUpdate(c3childNodeSubSpecies2
);
1818 Taxon c4Genus
= Taxon
.NewInstance(null, null);c4Genus
.setUuid(UUID
.fromString("bfd6bbdd-0116-4ab2-a781-9316224aad78"));
1819 Taxon c4Species
= Taxon
.NewInstance(null, null);c4Species
.setUuid(UUID
.fromString("9347a3d9-5ece-4d64-9035-e8aaf5d3ee02"));
1820 Taxon c4SubSpecies
= Taxon
.NewInstance(null, null);c4SubSpecies
.setUuid(UUID
.fromString("777aabbe-4c3a-449c-ab99-a91f2fec9f07"));
1822 TaxonRelationship rel
= c1Species
.addTaxonRelation(c2Species
, TaxonRelationshipType
.CONGRUENT_TO(), citation
, microcitation
);
1823 rel
.setDoubtful(true);
1824 c1Species
.addTaxonRelation(c4Species
, TaxonRelationshipType
.INCLUDES(), citation
, microcitation
);
1825 c2Species
.addTaxonRelation(c1SubSpecies2
, TaxonRelationshipType
.INCLUDES(), citation
, microcitation
);
1827 service
.saveOrUpdate(c1Species
);
1828 service
.saveOrUpdate(c2Species
);
1829 service
.save(c4Species
);
1832 //default starting at species 1
1833 IncludedTaxaDTO dto
= service
.listIncludedTaxa(c1Species
.getUuid(), new IncludedTaxonConfiguration(null, true, false));
1834 Assert
.assertNotNull("IncludedTaxaDTO", dto
);
1835 Assert
.assertEquals("Result should contain 7 taxa: c1Species", 7, dto
.getIncludedTaxa().size());
1836 Assert
.assertNotNull("date should not be null", dto
.getDate());
1837 // Assert.assertTrue(dto.contains(taxonUuid));
1838 //same without doubtful
1839 dto
= service
.listIncludedTaxa(c1Species
.getUuid(), new IncludedTaxonConfiguration(null, false, false));
1840 Assert
.assertEquals(4, dto
.getIncludedTaxa().size());
1842 //other example starting at Genus2
1843 dto
= service
.listIncludedTaxa(c2Genus
.getUuid(), new IncludedTaxonConfiguration(null, true, false));
1844 Assert
.assertEquals(8, dto
.getIncludedTaxa().size());
1845 //same without doubtful
1846 dto
= service
.listIncludedTaxa(c2Genus
.getUuid(), new IncludedTaxonConfiguration(null, false, false));
1847 Assert
.assertEquals(5, dto
.getIncludedTaxa().size());
1850 dto
= service
.listIncludedTaxa(c1Species
.getUuid(), new IncludedTaxonConfiguration(null, true, true));
1851 Assert
.assertEquals(2, dto
.getIncludedTaxa().size());
1852 //same without doubtful
1853 dto
= service
.listIncludedTaxa(c1Species
.getUuid(), new IncludedTaxonConfiguration(null, false, true));
1854 Assert
.assertEquals(1, dto
.getIncludedTaxa().size());
1858 public void testDeleteDescriptions(){
1860 createTestDataSet();
1861 } catch (FileNotFoundException e
) {
1862 // TODO Auto-generated catch block
1863 e
.printStackTrace();
1865 TaxonDescription description
= TaxonDescription
.NewInstance(taxWithoutSyn
);
1866 SpecimenOrObservationBase
<IIdentifiableEntityCacheStrategy
<FieldUnit
>> specimen
= FieldUnit
.NewInstance();
1867 UUID uuid
= occurenceService
.saveOrUpdate(specimen
);
1868 DescriptionElementBase element
= IndividualsAssociation
.NewInstance(specimen
);
1869 description
.addElement(element
);
1870 service
.saveOrUpdate(taxWithoutSyn
);
1873 Taxon tax
= (Taxon
)service
.find(uuidTaxWithoutSyn
);
1874 Set
<TaxonDescription
> descr
= tax
.getDescriptions();
1875 assertEquals(1, descr
.size());
1876 description
= descr
.iterator().next();
1877 UUID uuidDescr
= description
.getUuid();
1878 UUID uuidDescEl
= description
.getElements().iterator().next().getUuid();
1880 descriptionService
.deleteDescription(description
);
1881 service
.saveOrUpdate(tax
);
1883 description
= (TaxonDescription
) descriptionService
.find(uuidDescr
);
1884 specimen
= occurenceService
.find(uuid
);
1885 assertNull(description
);
1886 DeleteResult result
= occurenceService
.delete(specimen
);
1887 assertTrue(result
.isOk());
1892 public void testRemoveDescriptionsFromTaxa(){
1894 createTestDataSet();
1895 } catch (FileNotFoundException e
) {
1896 // TODO Auto-generated catch block
1897 e
.printStackTrace();
1899 TaxonDescription description
= TaxonDescription
.NewInstance(taxWithoutSyn
);
1900 SpecimenOrObservationBase
<IIdentifiableEntityCacheStrategy
<FieldUnit
>> specimen
= FieldUnit
.NewInstance();
1901 UUID uuid
= occurenceService
.saveOrUpdate(specimen
);
1902 DescriptionElementBase element
= IndividualsAssociation
.NewInstance(specimen
);
1903 description
.addElement(element
);
1904 service
.saveOrUpdate(taxWithoutSyn
);
1907 Taxon tax
= (Taxon
)service
.find(uuidTaxWithoutSyn
);
1908 Set
<TaxonDescription
> descr
= tax
.getDescriptions();
1909 assertEquals(1, descr
.size());
1910 description
= descr
.iterator().next();
1911 UUID uuidDescr
= description
.getUuid();
1914 tax
.removeDescription(description
, true);
1915 service
.saveOrUpdate(tax
);
1917 description
= (TaxonDescription
) descriptionService
.find(uuidDescr
);
1918 specimen
= occurenceService
.find(uuid
);
1919 assertNotNull(description
);
1920 DeleteResult result
= occurenceService
.delete(specimen
);
1921 assertTrue(result
.isOk());
1927 public void createTestDataSet() throws FileNotFoundException
{
1928 Rank rank
= Rank
.SPECIES();
1930 taxWithoutSyn
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test1", null, null, null, null, null, null, null), null);
1931 taxWithSyn
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
1932 tax2WithSyn
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test5", null, null, null, null, null, null, null), null);
1933 synonym
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
1934 synonym2
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
1935 synonym2
.getName().setHomotypicalGroup(synonym
.getHomotypicGroup());
1937 taxWithSyn
.addSynonym(synonym
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
1938 taxWithSyn
.addSynonym(synonym2
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
1940 uuidTaxWithoutSyn
= service
.save(taxWithoutSyn
).getUuid();
1941 uuidSyn
= service
.save(synonym
).getUuid();
1942 uuidSyn2
= service
.save(synonym2
).getUuid();
1943 uuidTaxWithSyn
=service
.save(taxWithSyn
).getUuid();
1949 //public static UUID DESCRIPTION1_UUID = UUID.fromString("f3e061f6-c5df-465c-a253-1e18ab4c7e50");
1950 //public static UUID DESCRIPTION2_UUID = UUID.fromString("1b009a40-ebff-4f7e-9f7f-75a850ba995d");
1954 private final Random rnd
= new Random();
1956 public Taxon
getTestTaxon(){
1957 int descrIndex
= 6000;
1958 Person deCandolle
= Person
.NewInstance();
1959 deCandolle
.setTitleCache("DC.", true);
1961 Reference sec
= ReferenceFactory
.newDatabase();
1962 sec
.setTitleCache("Flora lunaea", true);
1963 Reference citationRef
= ReferenceFactory
.newBook();
1964 citationRef
.setTitleCache("Sp. lunarum", true);
1966 //genus taxon with Name, combinationAuthor,
1967 IBotanicalName botName
= TaxonNameFactory
.NewBotanicalInstance(Rank
.GENUS());
1968 botName
.setTitleCache("Hieracium L.", true);
1969 botName
.setGenusOrUninomial("Hieracium");
1970 botName
.setCombinationAuthorship(Person
.NewInstance());
1971 botName
.getCombinationAuthorship().setNomenclaturalTitle("L.");
1972 botName
.setUuid(GENUS_NAME_UUID
);
1973 Taxon genusTaxon
= Taxon
.NewInstance(botName
, sec
);
1974 genusTaxon
.setUuid(GENUS_UUID
);
1975 service
.save(genusTaxon
);
1976 //a name that is the basionym of genusTaxon's name
1977 TaxonName basionym
= TaxonNameFactory
.NewBotanicalInstance(Rank
.GENUS());
1978 basionym
.setTitleCache("Hieracilla DC.", true);
1979 basionym
.setGenusOrUninomial("Hieracilla");
1980 basionym
.setCombinationAuthorship(deCandolle
);
1981 basionym
.setUuid(BASIONYM_UUID
);
1982 botName
.addBasionym(basionym
, null, null,"216");
1983 nameService
.saveOrUpdate(basionym
);
1984 //species taxon that is the child of genus taxon
1985 IBotanicalName botSpecies
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
1986 botSpecies
.setTitleCache("Hieracium asturianum Pau", true);
1987 botSpecies
.setGenusOrUninomial("Hieracium");
1988 botSpecies
.setSpecificEpithet("asturianum");
1989 botSpecies
.setCombinationAuthorship(Person
.NewInstance());
1990 botSpecies
.getCombinationAuthorship().setNomenclaturalTitle("Pau");
1991 botSpecies
.setUuid(SPECIES1_NAME_UUID
);
1992 Taxon childTaxon
= Taxon
.NewInstance(botSpecies
, sec
);
1993 childTaxon
.setUuid(SPECIES1_UUID
);
1994 TaxonDescription taxDesc
= getTestDescription(descrIndex
++);
1995 //taxDesc.setUuid(DESCRIPTION1_UUID);
1996 childTaxon
.addDescription(taxDesc
);
1997 service
.saveOrUpdate(childTaxon
);
1998 Classification classification
= getTestClassification("TestClassification");
1999 classification
.addParentChild(genusTaxon
, childTaxon
, citationRef
, "456");
2000 // childTaxon.setTaxonomicParent(genusTaxon, citationRef, "456");
2001 classificationService
.save(classification
);
2002 //homotypic synonym of childTaxon1
2003 IBotanicalName botSpecies4
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
2004 botSpecies4
.setTitleCache("Hieracium gueri DC.", true);
2005 botSpecies4
.setGenusOrUninomial("Hieracium");
2006 botSpecies4
.setSpecificEpithet("gueri");
2007 botSpecies4
.setCombinationAuthorship(deCandolle
);
2008 botSpecies4
.setUuid(SYNONYM_NAME_UUID
);
2009 Synonym homoSynonym
= Synonym
.NewInstance(botSpecies4
, sec
);
2010 childTaxon
.addSynonym(homoSynonym
, SynonymType
.HOMOTYPIC_SYNONYM_OF());
2011 service
.saveOrUpdate(childTaxon
);
2013 //2nd child species taxon that is the child of genus taxon
2014 IBotanicalName botSpecies2
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
2015 botSpecies2
.setTitleCache("Hieracium wolffii Zahn", true);
2016 botSpecies2
.setGenusOrUninomial("Hieracium");
2017 botSpecies2
.setSpecificEpithet("wolffii");
2018 botSpecies2
.setCombinationAuthorship(Person
.NewInstance());
2019 botSpecies2
.getCombinationAuthorship().setNomenclaturalTitle("Zahn");
2020 botSpecies2
.setUuid(SPECIES2_NAME_UUID
);
2021 Taxon childTaxon2
= Taxon
.NewInstance(botSpecies2
, sec
);
2022 childTaxon2
.setUuid(SPECIES2_UUID
);
2023 classification
.addParentChild(genusTaxon
, childTaxon2
, citationRef
, "499");
2024 //childTaxon2.setTaxonomicParent(genusTaxon, citationRef, "499");
2025 service
.saveOrUpdate(childTaxon2
);
2026 //heterotypic synonym of childTaxon2
2027 IBotanicalName botSpecies3
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
2028 botSpecies3
.setTitleCache("Hieracium lupium DC.", true);
2029 botSpecies3
.setGenusOrUninomial("Hieracium");
2030 botSpecies3
.setSpecificEpithet("lupium");
2031 botSpecies3
.setCombinationAuthorship(deCandolle
);
2032 botSpecies3
.setUuid(SYNONYM2_NAME_UUID
);
2033 Synonym heteroSynonym
= Synonym
.NewInstance(botSpecies3
, sec
);
2034 childTaxon2
.addSynonym(heteroSynonym
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
2035 service
.saveOrUpdate(childTaxon2
);
2036 //missaplied Name for childTaxon2
2037 IBotanicalName missName
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
2038 missName
.setTitleCache("Hieracium lupium DC.", true);
2039 missName
.setGenusOrUninomial("Hieracium");
2040 missName
.setSpecificEpithet("lupium");
2041 missName
.setCombinationAuthorship(deCandolle
);
2042 missName
.setUuid(SPECIES5_NAME_UUID
);
2043 Taxon misappliedNameTaxon
= Taxon
.NewInstance(missName
, sec
);
2044 childTaxon2
.addMisappliedName(misappliedNameTaxon
, citationRef
, "125");
2045 taxDesc
= getTestDescription(descrIndex
++);
2046 // taxDesc.setUuid(DESCRIPTION2_UUID);
2047 genusTaxon
.addDescription(taxDesc
);
2048 service
.saveOrUpdate(genusTaxon
);
2049 service
.save(misappliedNameTaxon
);
2054 public TaxonDescription
getTestDescription(int index
){
2055 TaxonDescription taxonDescription
= TaxonDescription
.NewInstance();
2056 Language language
= Language
.DEFAULT();
2057 //taxonDescription.setId(index);
2060 TextData textData
= TextData
.NewInstance();
2061 String descriptionText
= "this is a desciption for a taxon";
2062 LanguageString languageString
= LanguageString
.NewInstance(descriptionText
, language
);
2063 textData
.putText(languageString
);
2064 taxonDescription
.addElement(textData
);
2068 String commonNameString
= "Schönveilchen";
2069 CommonTaxonName commonName
= CommonTaxonName
.NewInstance(commonNameString
, language
);
2070 taxonDescription
.addElement(commonName
);
2072 return taxonDescription
;
2075 public Classification
getTestClassification(String name
){
2076 return Classification
.NewInstance(name
);