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.
9 package eu
.etaxonomy
.cdm
.api
.service
;
11 import static org
.junit
.Assert
.assertEquals
;
12 import static org
.junit
.Assert
.assertNotNull
;
13 import static org
.junit
.Assert
.assertNull
;
14 import static org
.junit
.Assert
.assertTrue
;
16 import java
.io
.FileNotFoundException
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Iterator
;
19 import java
.util
.List
;
21 import java
.util
.UUID
;
23 import org
.apache
.log4j
.Logger
;
24 import org
.junit
.Assert
;
25 import org
.junit
.Test
;
26 import org
.unitils
.dbunit
.annotation
.DataSet
;
27 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
29 import eu
.etaxonomy
.cdm
.api
.service
.config
.IdentifiableServiceConfiguratorImpl
;
30 import eu
.etaxonomy
.cdm
.api
.service
.config
.IncludedTaxonConfiguration
;
31 import eu
.etaxonomy
.cdm
.api
.service
.config
.MatchingTaxonConfigurator
;
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
.api
.service
.pager
.Pager
;
39 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
40 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
41 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
42 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
43 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
44 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
45 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
46 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
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
.metadata
.SecReferenceHandlingEnum
;
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
.OriginalSourceType
;
70 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
71 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
72 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
73 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
74 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymType
;
75 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
76 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
77 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
78 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
79 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
80 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
81 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
82 import eu
.etaxonomy
.cdm
.test
.unitils
.CleanSweepInsertLoadStrategy
;
87 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 SYNONYM2_UUID
= UUID
.fromString("2520b103-bd89-4ac1-99e4-e3bfcedfd4eb");
143 public static UUID SPECIES5_NAME_UUID
= UUID
.fromString("0c6ecaac-804d-49e5-a33f-1b7ee77439e3");
145 /****************** TESTS *****************************/
149 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#getTaxonByUuid(java.util.UUID)}.
152 public final void testGetTaxonByUuid() {
153 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
154 UUID uuid
= service
.save(expectedTaxon
).getUuid();
155 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
156 assertEquals(expectedTaxon
, actualTaxon
);
160 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#getTaxonByUuid(java.util.UUID)}.
163 public final void testGetTaxonByTitle() {
164 TaxonName name
= TaxonName
.NewInstance(NomenclaturalCode
.ICNAFP
, Rank
.SPECIES(), "Abies", null, "alba", null, null, null, null, null);
165 Taxon expectedTaxon
= Taxon
.NewInstance(name
, null);
166 expectedTaxon
.setDoubtful(true);
167 service
.save(expectedTaxon
);
168 IdentifiableServiceConfiguratorImpl
<TaxonBase
> config
= new IdentifiableServiceConfiguratorImpl
<TaxonBase
>();
169 config
.setTitleSearchString("Abies alba*");
170 //doubtful taxa should be found
171 Pager
<TaxonBase
> actualTaxa
= service
.findByTitle(config
);
172 assertEquals(expectedTaxon
, actualTaxa
.getRecords().get(0));
174 //and other taxa as well
175 expectedTaxon
.setDoubtful(false);
176 service
.saveOrUpdate(expectedTaxon
);
177 actualTaxa
= service
.findByTitle(config
);
178 assertEquals(expectedTaxon
, actualTaxa
.getRecords().get(0));
183 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#saveTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
186 public final void testSaveTaxon() {
187 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
188 UUID uuid
= service
.save(expectedTaxon
).getUuid();
189 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
190 assertEquals(expectedTaxon
, actualTaxon
);
194 public final void testSaveOrUpdateTaxon() {
195 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
196 UUID uuid
= service
.save(expectedTaxon
).getUuid();
197 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
198 assertEquals(expectedTaxon
, actualTaxon
);
200 actualTaxon
.setName(TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES()));
202 service
.saveOrUpdate(actualTaxon
);
209 public final void testSaveOrUpdateTaxonWithMisappliedName() {
210 Taxon expectedTaxon
= Taxon
.NewInstance(null, null);
211 TaxonName misappliedNameName
= TaxonName
.NewInstance(NomenclaturalCode
.ICNAFP
, Rank
.SPECIES(), "Abies", null, "alba", null, null, null, null, null);
213 UUID misappliedNameNameUuid
= nameService
.save(misappliedNameName
).getUuid();
214 misappliedNameName
= nameService
.find(misappliedNameNameUuid
);
215 SpecimenTypeDesignation typedes
= SpecimenTypeDesignation
.NewInstance();
216 DerivedUnit derivedUnit
= DerivedUnit
.NewPreservedSpecimenInstance();
217 FieldUnit fieldUnit
= FieldUnit
.NewInstance();
218 DerivationEvent derivationEvent
= DerivationEvent
.NewSimpleInstance(fieldUnit
, derivedUnit
, DerivationEventType
.ACCESSIONING());
219 // derivedUnit.addDerivationEvent(derivationEvent);
220 typedes
.setTypeSpecimen(derivedUnit
);
221 misappliedNameName
.addTypeDesignation(typedes
, false);
222 Taxon misappliedName
= Taxon
.NewInstance(misappliedNameName
, null);
223 UUID misappliedNameUuid
= service
.save(misappliedName
).getUuid();
224 misappliedName
= (Taxon
) service
.find(misappliedNameUuid
);
225 expectedTaxon
.addMisappliedName(misappliedName
, null, null);
226 UUID uuid
= service
.save(expectedTaxon
).getUuid();
227 TaxonBase
<?
> actualTaxon
= service
.find(uuid
);
228 assertEquals(expectedTaxon
, actualTaxon
);
229 misappliedName
.setSec(ReferenceFactory
.newArticle());
232 service
.saveOrUpdate(actualTaxon
);
233 misappliedName
= (Taxon
)service
.find(misappliedNameUuid
);
234 Assert
.assertNotNull(misappliedName
.getSec());
238 commitAndStartNewTransaction(null);
239 actualTaxon
= service
.find(uuid
);
240 ((Taxon
)actualTaxon
).getTaxonRelations(misappliedName
).iterator().next().getFromTaxon().setSec(null);
242 service
.saveOrUpdate(actualTaxon
);
243 misappliedName
= (Taxon
)service
.find(misappliedNameUuid
);
244 Assert
.assertNull(misappliedName
.getSec());
252 public final void testSwapSynonymAndAcceptedTaxon() throws FileNotFoundException
{
255 synonym
.setSec(ReferenceFactory
.newArticle());
256 service
.saveOrUpdate(synonym
);
257 UpdateResult result
= service
.swapSynonymAndAcceptedTaxon(synonym
, taxWithSyn
, true);
260 Taxon tax
= (Taxon
)service
.find(result
.getCdmEntity().getUuid());
261 MatchingTaxonConfigurator configurator
= MatchingTaxonConfigurator
.NewInstance();
262 configurator
.setTaxonNameTitle("Test3");
263 List
<TaxonBase
> synList
= service
.findTaxaByName(configurator
);
265 if (synList
.size() > 0){
266 TaxonBase syn
= synList
.get(0);
267 assertTrue(tax
.getSynonyms().contains(syn
));
269 Assert
.fail("There should be a synonym with name Test3");
271 assertTrue(tax
.getName().getTitleCache().equals("Test2"));
275 public final void testSwapSynonymAndAcceptedTaxonNewUuid() throws FileNotFoundException
{
278 synonym
.setSec(ReferenceFactory
.newArticle());
279 service
.saveOrUpdate(synonym
);
280 UpdateResult result
= service
.swapSynonymAndAcceptedTaxonNewUuid(synonym
, taxWithSyn
, true);
283 Taxon tax
= (Taxon
)service
.find(result
.getCdmEntity().getUuid());
284 MatchingTaxonConfigurator configurator
= MatchingTaxonConfigurator
.NewInstance();
285 configurator
.setTaxonNameTitle("Test3");
286 @SuppressWarnings("rawtypes")
287 List
<TaxonBase
> synList
= service
.findTaxaByName(configurator
);
289 if (synList
.size() > 0){
290 TaxonBase
<?
> syn
= synList
.get(0);
291 assertTrue(tax
.getSynonyms().contains(syn
));
293 Assert
.fail("There should be a synonym with name Test3");
295 assertTrue(tax
.getName().getTitleCache().equals("Test2"));
299 public final void testChangeSynonymToAcceptedTaxon() throws FileNotFoundException
{
303 UpdateResult result
= new UpdateResult();
305 result
= service
.changeSynonymToAcceptedTaxon(synonym
, taxWithSyn
, null, null, null, true);
306 } catch (HomotypicalGroupChangeException e
) {
307 Assert
.fail("Invocation of change method should not throw an exception");
310 //test flush (resave deleted object)
311 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
312 taxWithSyn
= (Taxon
)service
.find(uuidTaxWithSyn
);
313 Taxon taxNew
= (Taxon
)service
.find(result
.getCdmEntity().getUuid());
315 assertNotNull(taxWithSyn
);
316 assertNotNull(taxNew
);
318 Assert
.assertEquals("New taxon should have 1 synonym relationship (the old homotypic synonym)", 1, ((Taxon
)result
.getCdmEntity()).getSynonyms().size());
322 public final void testChangeSynonymToAcceptedTaxonWithSecHandlingAlwaysDelete(){
323 Taxon genus
= getTestTaxon();
324 TaxonNode node
= genus
.getTaxonNodes().iterator().next();
326 UpdateResult result
= new UpdateResult();
328 result
= service
.changeSynonymToAcceptedTaxon(SYNONYM2_UUID
, SPECIES2_UUID
, node
.getUuid(), null, null, SecReferenceHandlingEnum
.AlwaysDelete
, true);
329 } catch (HomotypicalGroupChangeException e
) {
330 Assert
.fail("Invocation of change method should not throw an exception");
333 //test flush (resave deleted object)
334 TaxonBase
<?
> syn
= service
.find(SYNONYM2_UUID
);
335 taxWithSyn
= (Taxon
)service
.find(SPECIES2_UUID
);
336 TaxonNode taxNodeNew
= nodeService
.find(result
.getCdmEntity().getUuid());
337 Taxon taxNew
= taxNodeNew
.getTaxon();
339 assertNotNull(taxWithSyn
);
340 assertNotNull(taxNew
);
341 assertNull(taxNew
.getSec());
347 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testMoveSynonymToAnotherTaxon.xml")
348 public final void testChangeSynonymToAcceptedTaxonWithSecHandlingAlwaysKeep(){
349 Taxon genus
= getTestTaxon();
350 TaxonNode node
= genus
.getTaxonNodes().iterator().next();
351 UpdateResult result
= new UpdateResult();
352 TaxonBase
<?
> syn
= service
.find(SYNONYM2_UUID
);
353 Reference sec
= ReferenceFactory
.newBook();
354 sec
.setTitleCache("Flora Cuba", true);
356 service
.saveOrUpdate(syn
);
358 result
= service
.changeSynonymToAcceptedTaxon(SYNONYM2_UUID
, SPECIES2_UUID
, node
.getUuid(), null, null, SecReferenceHandlingEnum
.KeepAlways
, true);
359 } catch (HomotypicalGroupChangeException e
) {
360 Assert
.fail("Invocation of change method should not throw an exception");
363 //test flush (resave deleted object)
364 syn
= service
.find(SYNONYM2_UUID
);
365 taxWithSyn
= (Taxon
)service
.find(SPECIES2_UUID
);
366 TaxonNode taxNodeNew
= nodeService
.find(result
.getCdmEntity().getUuid());
367 Taxon taxNew
= taxNodeNew
.getTaxon();
369 assertNotNull(taxWithSyn
);
370 assertNotNull(taxNew
);
371 assertNotNull(taxNew
.getSec());
372 assertEquals(sec
, taxNew
.getSec());
377 public final void testChangeSynonymToAcceptedTaxonWithSecHandlingUseNewParentSec(){
378 Taxon genus
= getTestTaxon();
379 TaxonNode node
= genus
.getTaxonNodes().iterator().next();
380 UpdateResult result
= new UpdateResult();
381 TaxonBase
<?
> syn
= service
.find(SYNONYM2_UUID
);
382 Reference sec
= ReferenceFactory
.newBook();
383 sec
.setTitleCache("Flora Cuba", true);
385 service
.saveOrUpdate(syn
);
387 result
= service
.changeSynonymToAcceptedTaxon(SYNONYM2_UUID
, SPECIES2_UUID
, node
.getUuid(), null, null, SecReferenceHandlingEnum
.UseNewParentSec
, true);
388 } catch (HomotypicalGroupChangeException e
) {
389 Assert
.fail("Invocation of change method should not throw an exception");
392 //test flush (resave deleted object)
393 syn
= service
.find(SYNONYM2_UUID
);
394 taxWithSyn
= (Taxon
)service
.find(SPECIES2_UUID
);
395 TaxonNode taxNodeNew
= nodeService
.find(result
.getCdmEntity().getUuid());
396 Taxon taxNew
= taxNodeNew
.getTaxon();
398 assertNotNull(taxWithSyn
);
399 assertNotNull(taxNew
);
400 assertNotNull(taxNew
.getSec());
401 assertEquals(taxWithSyn
.getSec(), taxNew
.getSec());
406 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testMoveSynonymToAnotherTaxon.xml")
407 public final void testChangeSynonymToAcceptedTaxonWithSecHandlingWarningSelect(){
408 Taxon genus
= getTestTaxon();
409 TaxonNode node
= genus
.getTaxonNodes().iterator().next();
411 UpdateResult result
= new UpdateResult();
412 TaxonBase
<?
> syn
= service
.find(SYNONYM2_UUID
);
413 Reference sec
= ReferenceFactory
.newBook();
414 sec
.setTitleCache("Flora Cuba", true);
415 Reference newSec
= ReferenceFactory
.newBook();
416 newSec
.setTitleCache("Flora Hawaii", true);
417 UUID newSecUuid
= referenceService
.saveOrUpdate(newSec
);
419 service
.saveOrUpdate(syn
);
421 result
= service
.changeSynonymToAcceptedTaxon(SYNONYM2_UUID
, SPECIES2_UUID
, node
.getUuid(), newSecUuid
, "23", SecReferenceHandlingEnum
.WarningSelect
, true);
422 } catch (HomotypicalGroupChangeException e
) {
423 Assert
.fail("Invocation of change method should not throw an exception");
426 //test flush (resave deleted object)
427 syn
= service
.find(SYNONYM2_UUID
);
428 taxWithSyn
= (Taxon
)service
.find(SPECIES2_UUID
);
429 TaxonNode taxNodeNew
= nodeService
.find(result
.getCdmEntity().getUuid());
430 Taxon taxNew
= taxNodeNew
.getTaxon();
432 assertNotNull(taxWithSyn
);
433 assertNotNull(taxNew
);
434 assertNotNull(taxNew
.getSec());
435 assertEquals(newSec
, taxNew
.getSec());
441 public final void testChangeSynonymToAcceptedTaxonSynonymForTwoTaxa(){
444 } catch (FileNotFoundException e1
) {
445 // TODO Auto-generated catch block
446 e1
.printStackTrace();
451 UpdateResult result
= new UpdateResult();
453 result
= service
.changeSynonymToAcceptedTaxon(synonym
, taxWithSyn
, null, null, null, true);
455 } catch (HomotypicalGroupChangeException e
) {
456 Assert
.fail("Invocation of change method should not throw an exception");
461 //test flush (resave deleted object)
462 TaxonBase
<?
> syn
= service
.find(uuidSyn
);
463 taxWithSyn
= (Taxon
)service
.find(uuidTaxWithSyn
);
464 Taxon taxNew
= (Taxon
)service
.find(((Taxon
)result
.getCdmEntity()).getUuid());
466 assertNotNull(taxWithSyn
);
467 assertNotNull(taxNew
);
469 // Assert.assertEquals("New taxon should have 1 synonym relationship (the old homotypic synonym)", 1, taxon.getSynonymRelations().size());
473 * Old implementation taken from {@link TaxonServiceImplBusinessTest} for old version of method.
476 public final void testMoveSynonymToAnotherTaxon_OLD() {
477 SynonymType heteroTypicSynonymType
= SynonymType
.HETEROTYPIC_SYNONYM_OF();
478 Reference reference
= ReferenceFactory
.newGeneric();
479 String referenceDetail
= "test";
481 INonViralName t1n
= TaxonNameFactory
.NewNonViralInstance(null);
482 Taxon t1
= Taxon
.NewInstance(t1n
, reference
);
483 INonViralName t2n
= TaxonNameFactory
.NewNonViralInstance(null);
484 Taxon t2
= Taxon
.NewInstance(t2n
, reference
);
485 INonViralName s1n
= TaxonNameFactory
.NewNonViralInstance(null);
486 Synonym s1
= Synonym
.NewInstance(s1n
, reference
);
487 t1
.addSynonym(s1
, heteroTypicSynonymType
);
488 service
.saveOrUpdate(t1
);
490 Synonym synonym
= t1
.getSynonyms().iterator().next();
492 boolean keepReference
= false;
493 boolean moveHomotypicGroup
= false;
495 service
.moveSynonymToAnotherTaxon(synonym
, t2
, moveHomotypicGroup
, heteroTypicSynonymType
, reference
.getUuid(), referenceDetail
, keepReference
);
496 } catch (HomotypicalGroupChangeException e
) {
497 Assert
.fail("Method call should not throw exception");
500 Assert
.assertTrue("t1 should have no synonyms", t1
.getSynonyms().isEmpty());
502 Set
<Synonym
> synonyms
= t2
.getSynonyms();
503 Assert
.assertTrue("t2 should have exactly one synonym", synonyms
.size() == 1);
505 synonym
= synonyms
.iterator().next();
507 Assert
.assertEquals(t2
, synonym
.getAcceptedTaxon());
508 Assert
.assertEquals(heteroTypicSynonymType
, synonym
.getType());
509 Assert
.assertEquals(reference
, synonym
.getSec());
510 Assert
.assertEquals(referenceDetail
, synonym
.getSecMicroReference());
514 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testMoveSynonymToAnotherTaxon.xml")
515 public final void testMoveSynonymToAnotherTaxon() throws Exception
{
516 final String
[] tableNames
= new String
[]{};
518 // printDataSet(System.err, new String[]{"AgentBase", "TaxonBase"});
519 // printDataSet(System.err, new String[]{"TaxonNode"});
521 UUID uuidNewTaxon
= UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
522 UUID uuidOldTaxon
= UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
523 UUID uuidSyn1
= UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
524 UUID uuidSyn3
= UUID
.fromString("3fba2b22-22ae-4291-af67-faab748a5232");
525 UUID uuidSyn4
= UUID
.fromString("f9b589c7-50cf-4df2-a52e-1b85eb7e4805");
526 UUID uuidSyn5
= UUID
.fromString("fcc0bcf8-8bac-43bd-9508-1e97821587dd");
527 UUID uuidSyn6
= UUID
.fromString("0ccd4e7c-6fbd-4b7c-bd47-29e45b92f34b");
528 UUID uuidRef1
= UUID
.fromString("336f9b38-698c-45d7-be7b-993ed3355bdc");
529 UUID uuidRef2
= UUID
.fromString("c8f49d1a-69e1-48a3-98bb-45d61f3da3e7");
532 boolean moveHomotypicGroup
= true;
533 SynonymType newSynonymType
= null;
534 boolean keepReference
= true;
535 Reference newReference
= null;
536 String newReferenceDetail
= null;
538 Taxon newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
539 Synonym homotypicSynonym
= (Synonym
)service
.load(uuidSyn1
);
540 Assert
.assertNotNull("Synonym should exist", homotypicSynonym
);
541 Assert
.assertNotNull("Synonym should have 1 relation", homotypicSynonym
.getAcceptedTaxon());
542 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, homotypicSynonym
.getAcceptedTaxon().getUuid());
543 Taxon oldTaxon
= homotypicSynonym
.getAcceptedTaxon();
546 service
.moveSynonymToAnotherTaxon(homotypicSynonym
, newTaxon
, moveHomotypicGroup
, newSynonymType
, null, newReferenceDetail
, keepReference
);
547 Assert
.fail("Homotypic synonym move to other taxon should throw an exception");
548 } catch (HomotypicalGroupChangeException e
) {
549 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")){
551 commitAndStartNewTransaction(tableNames
);
553 Assert
.fail("Unexpected exception occurred: " + e
.getMessage());
557 homotypicSynonym
= (Synonym
)service
.load(uuidSyn1
);
558 Assert
.assertNotNull("Synonym should still exist", homotypicSynonym
);
559 Assert
.assertNotNull("Synonym should still have 1 relation", homotypicSynonym
.getAcceptedTaxon());
560 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", oldTaxon
, homotypicSynonym
.getAcceptedTaxon());
562 //test heterotypic synonym with other synonym in homotypic group
563 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
564 Synonym heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
565 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
566 Assert
.assertNotNull("Synonym should have 1 relation", heterotypicSynonym
.getAcceptedTaxon());
567 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, heterotypicSynonym
.getAcceptedTaxon().getUuid());
568 oldTaxon
= heterotypicSynonym
.getAcceptedTaxon();
569 moveHomotypicGroup
= false;
572 service
.moveSynonymToAnotherTaxon(heterotypicSynonym
, newTaxon
, moveHomotypicGroup
, newSynonymType
, null, newReferenceDetail
, keepReference
);
573 Assert
.fail("Heterotypic synonym move to other taxon should throw an exception");
574 } catch (HomotypicalGroupChangeException e
) {
575 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")){
577 commitAndStartNewTransaction(tableNames
);
579 Assert
.fail("Unexpected exception occurred: " + e
.getMessage());
583 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
584 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
585 Assert
.assertNotNull("Synonym should have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
586 Assert
.assertEquals("Accepted taxon of single relation should still be the old taxon", oldTaxon
, heterotypicSynonym
.getAcceptedTaxon());
589 //test heterotypic synonym with no other synonym in homotypic group
592 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
593 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn5
);
594 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
595 Assert
.assertNotNull("Synonym should have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
596 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, heterotypicSynonym
.getAcceptedTaxon().getUuid());
597 oldTaxon
= heterotypicSynonym
.getAcceptedTaxon();
598 moveHomotypicGroup
= false;
601 service
.moveSynonymToAnotherTaxon(heterotypicSynonym
, newTaxon
, moveHomotypicGroup
, newSynonymType
, null, newReferenceDetail
, keepReference
);
602 } catch (HomotypicalGroupChangeException e
) {
603 Assert
.fail("Move of single heterotypic synonym should not throw exception: " + e
.getMessage());
606 commitAndStartNewTransaction(tableNames
);
608 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn5
);
609 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
610 Assert
.assertNotNull("Synonym should have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
611 Assert
.assertEquals("Accepted taxon of single relation should be new taxon", newTaxon
, heterotypicSynonym
.getAcceptedTaxon());
612 Assert
.assertEquals("Old detail should be kept", "rel5", heterotypicSynonym
.getSecMicroReference());
614 //test heterotypic synonym with other synonym in homotypic group and moveHomotypicGroup="true"
616 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
617 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
618 Reference ref1
= referenceService
.load(uuidRef1
);
619 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
620 Assert
.assertNotNull("Synonym should have 1 relation", heterotypicSynonym
.getAcceptedTaxon());
621 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, heterotypicSynonym
.getAcceptedTaxon().getUuid());
622 oldTaxon
= heterotypicSynonym
.getAcceptedTaxon();
623 Assert
.assertEquals("Detail should be ref1", ref1
, heterotypicSynonym
.getSec());
624 Assert
.assertEquals("Detail should be 'rel3'", "rel3", heterotypicSynonym
.getSecMicroReference());
625 TaxonName oldSynName3
= heterotypicSynonym
.getName();
627 Synonym heterotypicSynonym4
= (Synonym
)service
.load(uuidSyn4
);
628 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym4
);
629 Assert
.assertNotNull("Synonym should have accepted taxon", heterotypicSynonym4
.getAcceptedTaxon());
630 Assert
.assertEquals("Accepted taxon of other synonym in group should be the old taxon", uuidOldTaxon
, heterotypicSynonym4
.getAcceptedTaxon().getUuid());
631 Assert
.assertSame("Homotypic group of both synonyms should be same", oldSynName3
.getHomotypicalGroup() , heterotypicSynonym4
.getName().getHomotypicalGroup() );
633 moveHomotypicGroup
= true;
634 keepReference
= false;
637 service
.moveSynonymToAnotherTaxon(heterotypicSynonym4
, newTaxon
, moveHomotypicGroup
, newSynonymType
, null, newReferenceDetail
, keepReference
);
638 } catch (HomotypicalGroupChangeException e
) {
639 Assert
.fail("Move with 'moveHomotypicGroup = true' should not throw exception: " + e
.getMessage());
642 commitAndStartNewTransaction(tableNames
);
643 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn3
);
644 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
645 Assert
.assertNotNull("Synonym should still have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
646 Assert
.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon
, heterotypicSynonym
.getAcceptedTaxon());
647 TaxonName synName3
= heterotypicSynonym
.getName();
649 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn4
);
650 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
651 Assert
.assertNotNull("Synonym should still have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
652 Assert
.assertEquals("Accepted taxon of relation should be new taxon now", newTaxon
, heterotypicSynonym
.getAcceptedTaxon());
653 Assert
.assertNull("Old citation should be removed", heterotypicSynonym
.getSec());
654 Assert
.assertNull("Old detail should be removed", heterotypicSynonym
.getSecMicroReference());
655 TaxonName synName4
= heterotypicSynonym
.getName();
656 Assert
.assertEquals("Homotypic group of both synonyms should be equal", synName3
.getHomotypicalGroup() , synName4
.getHomotypicalGroup() );
657 Assert
.assertSame("Homotypic group of both synonyms should be same", synName3
.getHomotypicalGroup() , synName4
.getHomotypicalGroup() );
658 Assert
.assertEquals("Homotypic group of both synonyms should be equal to old homotypic group", oldSynName3
.getHomotypicalGroup() , synName3
.getHomotypicalGroup() );
660 //test single heterotypic synonym to homotypic synonym of new taxon
662 newTaxon
= (Taxon
)service
.load(uuidNewTaxon
);
663 Reference ref2
= referenceService
.load(uuidRef2
);
664 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn6
);
665 Assert
.assertNotNull("Synonym should exist", heterotypicSynonym
);
666 Assert
.assertNotNull("Synonym should have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
667 Assert
.assertEquals("Accepted taxon of single relation should be the old taxon", uuidOldTaxon
, heterotypicSynonym
.getAcceptedTaxon().getUuid());
668 oldTaxon
= heterotypicSynonym
.getAcceptedTaxon();
669 moveHomotypicGroup
= false;
670 keepReference
= false;
672 newReferenceDetail
= "newRefDetail";
673 newSynonymType
= SynonymType
.HOMOTYPIC_SYNONYM_OF();
676 service
.moveSynonymToAnotherTaxon(heterotypicSynonym
, newTaxon
, moveHomotypicGroup
, newSynonymType
, newReference
.getUuid(), newReferenceDetail
, keepReference
);
677 } catch (HomotypicalGroupChangeException e
) {
678 Assert
.fail("Move of single heterotypic synonym should not throw exception: " + e
.getMessage());
681 commitAndStartNewTransaction(tableNames
);
682 heterotypicSynonym
= (Synonym
)service
.load(uuidSyn6
);
683 Assert
.assertNotNull("Synonym should still exist", heterotypicSynonym
);
684 Assert
.assertNotNull("Synonym should still have accepted taxon", heterotypicSynonym
.getAcceptedTaxon());
685 Assert
.assertEquals("Relationship type should be 'homotypic synonym'", newSynonymType
, heterotypicSynonym
.getType());
686 Assert
.assertEquals("Accepted taxon of single relation should be new taxon", newTaxon
, heterotypicSynonym
.getAcceptedTaxon());
687 Assert
.assertEquals("New citation should be ref2", ref2
,heterotypicSynonym
.getSec());
688 Assert
.assertEquals("New detail should be kept", "newRefDetail", heterotypicSynonym
.getSecMicroReference());
690 Assert
.assertEquals("New taxon and new synonym should have equal homotypical group", heterotypicSynonym
.getHomotypicGroup(), heterotypicSynonym
.getAcceptedTaxon().getHomotypicGroup());
691 Assert
.assertSame("New taxon and new synonym should have same homotypical group", heterotypicSynonym
.getHomotypicGroup(), heterotypicSynonym
.getAcceptedTaxon().getHomotypicGroup());
695 public final void testGetHeterotypicSynonymyGroups(){
696 Rank rank
= Rank
.SPECIES();
697 Reference ref1
= ReferenceFactory
.newGeneric();
698 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
699 Taxon taxon1
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
700 Synonym synonym0
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
701 Synonym synonym1
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
702 Synonym synonym2
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
703 synonym0
.getName().setHomotypicalGroup(taxon1
.getHomotypicGroup());
704 synonym2
.getName().setHomotypicalGroup(synonym1
.getHomotypicGroup());
705 //tax2.addHeterotypicSynonymName(synonym.getName());
706 taxon1
.addSynonym(synonym1
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
707 taxon1
.addSynonym(synonym2
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
709 service
.save(synonym1
);
710 service
.save(synonym2
);
711 service
.save(taxon1
);
713 List
<List
<Synonym
>> heteroSyns
= service
.getHeterotypicSynonymyGroups(taxon1
, null);
714 Assert
.assertEquals("There should be 1 heterotypic group", 1, heteroSyns
.size());
715 List
<Synonym
> synList
= heteroSyns
.get(0);
716 Assert
.assertEquals("There should be 2 heterotypic syns in group 1", 2, synList
.size());
719 synonym2
.setSec(ref1
);
720 heteroSyns
= service
.getHeterotypicSynonymyGroups(taxon1
, null);
721 Assert
.assertEquals("There should be 1 heterotypic group", 1, heteroSyns
.size());
722 synList
= heteroSyns
.get(0);
723 Assert
.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 2, synList
.size());
727 public final void testGetHomotypicSynonymsByHomotypicGroup(){
728 Rank rank
= Rank
.SPECIES();
729 Reference ref1
= ReferenceFactory
.newGeneric();
730 //HomotypicalGroup group = HomotypicalGroup.NewInstance();
731 Taxon taxon1
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
732 Synonym synonym0
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
733 Synonym synonym1
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
734 Synonym synonym2
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
735 synonym0
.getName().setHomotypicalGroup(taxon1
.getHomotypicGroup());
736 synonym2
.getName().setHomotypicalGroup(synonym1
.getHomotypicGroup());
737 //tax2.addHeterotypicSynonymName(synonym.getName());
738 taxon1
.addSynonym(synonym0
, SynonymType
.HOMOTYPIC_SYNONYM_OF());
739 taxon1
.addSynonym(synonym1
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
740 taxon1
.addSynonym(synonym2
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
742 service
.save(synonym1
);
743 service
.save(synonym2
);
744 service
.save(taxon1
);
746 List
<Synonym
> homoSyns
= service
.getHomotypicSynonymsByHomotypicGroup(taxon1
, null);
747 Assert
.assertEquals("There should be 1 heterotypic group", 1, homoSyns
.size());
748 Assert
.assertSame("The homotypic synonym should be synonym0", synonym0
, homoSyns
.get(0));
751 synonym0
.setSec(ref1
);
752 homoSyns
= service
.getHomotypicSynonymsByHomotypicGroup(taxon1
, null);
753 Assert
.assertEquals("getHeterotypicSynonymyGroups should be independent of sec reference", 1, homoSyns
.size());
757 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
758 //test delete synonym, but the name will not be deleted
759 public final void testDeleteSynonymSynonymTaxonDontDeleteName(){
760 final String
[]tableNames
= {
761 // "TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
762 // "HomotypicalGroup","HomotypicalGroup_AUD"
765 int nSynonyms
= service
.count(Synonym
.class);
766 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
767 int nNames
= nameService
.count(TaxonName
.class);
768 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
769 long nRelations
= service
.countSynonyms(true);
770 Assert
.assertEquals("There should be two relationship left in the database", 2, nRelations
);
772 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
774 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
775 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
776 config
.setDeleteNameIfPossible(false);
777 config
.setNewHomotypicGroupIfNeeded(true);
778 service
.deleteSynonym(synonym1
, config
);
780 this.commitAndStartNewTransaction(tableNames
);
782 nSynonyms
= service
.count(Synonym
.class);
783 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
784 nNames
= nameService
.count(TaxonName
.class);
785 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
786 nRelations
= service
.countSynonyms(true);
787 Assert
.assertEquals("There should be no relationship left in the database", 1, nRelations
);
791 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
792 //test delete synonym and his name
793 public final void testDeleteSynonymSynonymTaxonDeleteName(){
794 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
795 "HomotypicalGroup","HomotypicalGroup_AUD"};
797 int nSynonyms
= service
.count(Synonym
.class);
798 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
799 int nNames
= nameService
.count(TaxonName
.class);
800 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
801 long nRelations
= service
.countSynonyms(true);
802 Assert
.assertEquals("There should be 2 relationship left in the database", 2, nRelations
);
804 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
805 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
806 service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
808 this.commitAndStartNewTransaction(tableNames
);
810 nSynonyms
= service
.count(Synonym
.class);
811 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
812 nNames
= nameService
.count(TaxonName
.class);
813 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
814 nRelations
= service
.countSynonyms(true);
815 Assert
.assertEquals("There should be 1 relationship left in the database", 1, nRelations
);
819 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
820 //test remove synonym from taxon -> synonym and name still in the db and the synonymrelationship to the other taxon
821 //test delete synonym -> all relationships are deleted, the name is deleted and the synonym itself
822 public final void testDeleteSynonymSynonymTaxonBooleanRelToOneTaxon(){
823 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
824 "HomotypicalGroup","HomotypicalGroup_AUD"};
826 int nSynonyms
= service
.count(Synonym
.class);
827 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
828 int nNames
= nameService
.count(TaxonName
.class);
829 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
831 UUID uuidTaxon1
=UUID
.fromString("c47fdb72-f32c-452e-8305-4b44f01179d0");
832 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
834 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon1
);
836 List
<String
> initStrat
= new ArrayList
<>();
837 initStrat
.add("markers");
838 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
, initStrat
);
839 long nRelations
= service
.countSynonyms(true);
840 Assert
.assertEquals("There should be 2 relationship left in the database", 2, nRelations
);
842 taxon2
.removeSynonym(synonym1
, false);
843 service
.saveOrUpdate(taxon2
);
845 commitAndStartNewTransaction(null);
847 nSynonyms
= service
.count(Synonym
.class);
848 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
849 nNames
= nameService
.count(TaxonName
.class);
850 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
851 nRelations
= service
.countSynonyms(true);
852 Assert
.assertEquals("There should be 1 relationship left in the database", 1, nRelations
);
853 Marker marker1
= Marker
.NewInstance(MarkerType
.IMPORTED(), true);
854 Marker marker2
= Marker
.NewInstance(MarkerType
.COMPUTED(), true);
855 synonym1
.addMarker(marker1
);
856 synonym1
.addMarker(marker2
);
857 service
.update(synonym1
);
858 synonym1
=(Synonym
) service
.load(uuidSynonym1
);
860 Set
<Marker
> markers
= synonym1
.getMarkers();
861 Marker marker
= markers
.iterator().next();
862 UUID markerUUID
= marker
.getUuid();
863 // taxon2 = (Taxon)service.load(uuidTaxon2);
864 synonym1
= (Synonym
)service
.load(uuidSynonym1
);
865 //the marker should not prevent the deletion
866 DeleteResult result
= service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
871 commitAndStartNewTransaction(tableNames
);
872 nSynonyms
= service
.count(Synonym
.class);
873 Assert
.assertEquals("There should be 1 synonym left in the database", 1, nSynonyms
);
874 nNames
= nameService
.count(TaxonName
.class);
875 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
876 nRelations
= service
.countSynonyms(true);
877 Assert
.assertEquals("There should be no relationship left in the database", 1, nRelations
);
878 marker
= markerService
.load(markerUUID
);
883 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
884 //this test is more or less obsolete since we have no synonym relationships anymore
885 //test delete synonym, only for a special taxon, but because of other relationships it will not be deleted at all
886 public final void testDeleteSynonymSynonymTaxonBooleanDeleteOneTaxon(){
887 final String
[]tableNames
= {
888 // "TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
889 // "HomotypicalGroup","HomotypicalGroup_AUD"
891 int nSynonyms
= service
.count(Synonym
.class);
892 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
893 int nNames
= nameService
.count(TaxonName
.class);
894 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
896 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
897 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
899 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon2
);
900 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
901 synonym1
.setSec(ReferenceFactory
.newArticle());
903 taxon2
.addSynonym(synonym1
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
904 service
.saveOrUpdate(synonym1
);
905 long nRelations
= service
.countSynonyms(true);
906 //this was "3" when we still had synonym relationships
907 Assert
.assertEquals("There should be 2 relationship left in the database", 2, nRelations
);
908 service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
910 this.commitAndStartNewTransaction(tableNames
);
912 nSynonyms
= service
.count(Synonym
.class);
913 //this was "2" when we still had synonym relationships
914 Assert
.assertEquals("There should still be 1 synonym left in the database", 1, nSynonyms
);
915 nNames
= nameService
.count(TaxonName
.class);
917 Assert
.assertEquals("There should be 3 names left in the database", 3, nNames
);
918 nRelations
= service
.countSynonyms(true);
919 Assert
.assertEquals("There should be 1 related synonym left in the database", 1, nRelations
);
923 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
925 public final void testDeleteSynonymWithAnnotations(){
926 final String
[]tableNames
= {
927 // "TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
928 // "HomotypicalGroup","HomotypicalGroup_AUD"
931 UUID uuidTaxon2
=UUID
.fromString("2d9a642d-5a82-442d-8fec-95efa978e8f8");
932 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
934 Taxon taxon2
= (Taxon
)service
.load(uuidTaxon2
);
935 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
936 taxon2
.addSynonym(synonym1
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
938 Annotation annotation
= Annotation
.NewDefaultLanguageInstance("test");
939 synonym1
.addAnnotation(annotation
);
940 service
.saveOrUpdate(synonym1
);
942 DeleteResult result
= service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
943 if (result
.isError()){
946 this.commitAndStartNewTransaction(tableNames
);
950 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
952 public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedName(){
953 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
954 "HomotypicalGroup","HomotypicalGroup_AUD"};
956 int nSynonyms
= service
.count(Synonym
.class);
957 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
958 int nNames
= nameService
.count(TaxonName
.class);
959 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
961 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
962 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
964 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
965 TaxonName name2
= nameService
.load(uuidSynonymName2
);
966 UUID name3Uuid
= synonym1
.getName().getUuid();
967 TaxonName name3
= nameService
.load(name3Uuid
);
968 name3
.addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null, null);
970 service
.saveOrUpdate(synonym1
);
972 long nRelations
= nameService
.listNameRelationships(null, 1000, 0, null, null).size();
973 logger
.info("number of name relations: " + nRelations
);
974 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
975 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
977 service
.deleteSynonym(synonym1
, config
);
979 this.commitAndStartNewTransaction(tableNames
);
980 //synonym is deleted, but the name can not be deleted because of a name relationship
981 nSynonyms
= service
.count(Synonym
.class);
982 Assert
.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms
);
983 nNames
= nameService
.count(TaxonName
.class);
984 Assert
.assertEquals("There should be 4 names left in the database (name is related to synonymName2)", 4, nNames
);
985 nRelations
= service
.countSynonyms(true);
986 //may change with better implementation of countAllRelationships (see #2653)
987 nRelations
= nameService
.listNameRelationships(null, 1000, 0, null, null).size();
988 logger
.info("number of name relations: " + nRelations
);
989 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
992 name2
= nameService
.load(uuidSynonymName2
);
993 NameRelationship rel
= CdmBase
.deproxy(name2
.getNameRelations().iterator().next(), NameRelationship
.class);
994 name2
.removeNameRelationship(rel
);
995 nameService
.save(name2
);
997 this.endTransaction();
1001 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
1002 public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedNameDeleteAllNameRelations(){
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
);
1011 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
1012 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
1014 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
1015 TaxonName name2
= nameService
.load(uuidSynonymName2
);
1016 UUID name3Uuid
= synonym1
.getName().getUuid();
1017 TaxonName name3
= nameService
.load(name3Uuid
);
1018 name3
.addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null, null);
1020 service
.saveOrUpdate(synonym1
);
1022 long nRelations
= nameService
.listNameRelationships(null, 1000, 0, null, null).size();
1023 logger
.info("number of name relations: " + nRelations
);
1024 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
1025 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
1026 NameDeletionConfigurator nameDeletionConfig
= new NameDeletionConfigurator();
1027 nameDeletionConfig
.setRemoveAllNameRelationships(true);
1028 config
.setNameDeletionConfig(nameDeletionConfig
);
1030 service
.deleteSynonym(synonym1
, config
);
1032 this.commitAndStartNewTransaction(tableNames
);
1034 nSynonyms
= service
.count(Synonym
.class);
1035 Assert
.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms
);
1036 nNames
= nameService
.count(TaxonName
.class);
1037 Assert
.assertEquals("There should be 3 names left in the database ", 3, nNames
);
1038 nRelations
= service
.countSynonyms(true);
1039 //may change with better implementation of countAllRelationships (see #2653)
1040 nRelations
= nameService
.listNameRelationships(null, 1000, 0, null, null).size();
1041 logger
.info("number of name relations: " + nRelations
);
1042 Assert
.assertEquals("There should be no name relationship left in the database", 0, nRelations
);
1046 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="TaxonServiceImplTest.testDeleteSynonym.xml")
1047 public final void testDeleteSynonymSynonymTaxonBooleanWithRelatedNameIgnoreIsBasionym(){
1048 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
1049 "HomotypicalGroup","HomotypicalGroup_AUD"};
1051 int nSynonyms
= service
.count(Synonym
.class);
1052 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
1053 int nNames
= nameService
.count(TaxonName
.class);
1054 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
1056 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
1057 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
1059 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
1060 TaxonName synName2
= nameService
.load(uuidSynonymName2
);
1061 UUID name3Uuid
= synonym1
.getName().getUuid();
1062 TaxonName synName1
= nameService
.load(name3Uuid
);
1063 synName1
.addRelationshipFromName(synName2
, NameRelationshipType
.BASIONYM(), null, null);
1065 service
.saveOrUpdate(synonym1
);
1067 long nRelations
= nameService
.listNameRelationships(null, 1000, 0, null, null).size();
1068 logger
.info("number of name relations: " + nRelations
);
1069 Assert
.assertEquals("There should be 1 name relationship left in the database", 1, nRelations
);
1070 SynonymDeletionConfigurator config
= new SynonymDeletionConfigurator();
1071 NameDeletionConfigurator nameDeletionConfig
= new NameDeletionConfigurator();
1072 nameDeletionConfig
.setIgnoreIsBasionymFor(true);
1073 config
.setNameDeletionConfig(nameDeletionConfig
);
1075 DeleteResult result
=service
.deleteSynonym(synonym1
, config
);
1076 if (!result
.isOk()){
1080 logger
.debug(result
);
1081 this.commitAndStartNewTransaction(tableNames
);
1083 nSynonyms
= service
.count(Synonym
.class);
1084 Assert
.assertEquals("There should still be 1 synonyms left in the database", 1, nSynonyms
);
1085 nNames
= nameService
.count(TaxonName
.class);
1086 Assert
.assertEquals("There should be 3 names left in the database ", 3, nNames
);
1087 nRelations
= service
.countSynonyms(true);
1088 //may change with better implementation of countAllRelationships (see #2653)
1089 nRelations
= nameService
.listNameRelationships(null, 1000, 0, null, null).size();
1090 logger
.info("number of name relations: " + nRelations
);
1091 Assert
.assertEquals("There should be no name relationship left in the database", 0, nRelations
);
1095 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
1096 public final void testDeleteSynonymSynonymTaxonBooleanWithRollback(){
1097 // final String[]tableNames = {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
1098 // "HomotypicalGroup","HomotypicalGroup_AUD"};
1100 int nSynonyms
= service
.count(Synonym
.class);
1101 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
1102 int nNames
= nameService
.count(TaxonName
.class);
1103 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
1104 long nRelations
= service
.countSynonyms(true);
1106 //may change with better implementation of countAllRelationships (see #2653)
1109 Assert
.assertEquals("There should be 2 relationships in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
1111 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
1112 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
1114 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
1115 TaxonName name2
= nameService
.load(uuidSynonymName2
);
1116 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null, null);
1118 service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
1121 // printDataSet(System.out, tableNames);
1122 this.startNewTransaction();
1124 nSynonyms
= service
.count(Synonym
.class);
1125 Assert
.assertEquals("There should still be 2 synonyms left in the database", 2, nSynonyms
);
1126 nNames
= nameService
.count(TaxonName
.class);
1127 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
1128 nRelations
= service
.countSynonyms(true);
1129 //may change with better implementation of countAllRelationships (see #2653)
1130 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationship) but no name relationship", 2, nRelations
);
1134 @DataSet("TaxonServiceImplTest.testDeleteSynonym.xml")
1135 public final void testDeleteSynonymSynonymTaxonBooleanWithoutTransaction(){
1136 @SuppressWarnings("unused")
1137 final String
[]tableNames
= {"TaxonBase","TaxonBase_AUD", "TaxonName","TaxonName_AUD",
1138 "HomotypicalGroup","HomotypicalGroup_AUD"};
1140 int nSynonyms
= service
.count(Synonym
.class);
1141 Assert
.assertEquals("There should be 2 synonyms in the database", 2, nSynonyms
);
1142 int nNames
= nameService
.count(TaxonName
.class);
1143 Assert
.assertEquals("There should be 4 names in the database", 4, nNames
);
1144 long nRelations
= service
.countSynonyms(true);
1145 //may change with better implementation of countAllRelationships (see #2653)
1146 Assert
.assertEquals("There should be 2 relationship in the database (the 2 synonym relationships) but no name relationship", 2, nRelations
);
1148 UUID uuidSynonym1
=UUID
.fromString("7da85381-ad9d-4886-9d4d-0eeef40e3d88");
1149 UUID uuidSynonymName2
=UUID
.fromString("613f3c93-013e-4ffc-aadc-1c98d71c335e");
1151 Synonym synonym1
= (Synonym
)service
.load(uuidSynonym1
);
1152 TaxonName name2
= nameService
.load(uuidSynonymName2
);
1153 synonym1
.getName().addRelationshipFromName(name2
, NameRelationshipType
.LATER_HOMONYM(), null, null);
1155 service
.saveOrUpdate(synonym1
);
1156 nRelations
= service
.countSynonyms(true);
1157 Assert
.assertEquals("There should be two relationships in the database", 2, nRelations
);
1159 this.endTransaction();
1161 // printDataSet(System.out, tableNames);
1163 //out of wrapping transaction
1164 service
.deleteSynonym(synonym1
, new SynonymDeletionConfigurator());
1166 this.startNewTransaction();
1168 nSynonyms
= service
.count(Synonym
.class);
1169 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
);
1170 nNames
= nameService
.count(TaxonName
.class);
1171 Assert
.assertEquals("There should be 4 names left in the database", 4, nNames
);
1172 nRelations
= service
.countSynonyms(true);
1173 Assert
.assertEquals("There should be no taxon or synonym relationship in the database", 1, nRelations
);
1174 nRelations
= nameService
.listNameRelationships(null, 1000, 0, null, null).size();
1175 Assert
.assertEquals("There should be one name relationship in the database", 1, nRelations
);
1179 @DataSet("TaxonServiceImplTest.testInferredSynonyms.xml")
1180 public void testCreateInferredSynonymy(){
1182 UUID classificationUuid
= UUID
.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9");
1183 Classification tree
= classificationService
.find(classificationUuid
);
1184 UUID taxonUuid
= UUID
.fromString("bc09aca6-06fd-4905-b1e7-cbf7cc65d783");
1185 TaxonBase
<?
> taxonBase
= service
.find(taxonUuid
);
1186 List
<Synonym
> synonyms
= service
.list(Synonym
.class, null, null, null, null);
1187 assertEquals("Number of synonyms should be 2",2,synonyms
.size());
1188 Taxon taxon
= (Taxon
)taxonBase
;
1190 //synonyms = taxonDao.getAllSynonyms(null, null);
1191 //assertEquals("Number of synonyms should be 2",2,synonyms.size());
1192 List
<Synonym
> inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymType
.INFERRED_EPITHET_OF(), true);
1193 assertNotNull("there should be a new synonym ", inferredSynonyms
);
1194 assertEquals ("the name of inferred epithet should be SynGenus lachesis", "SynGenus lachesis syn. sec. Sp. Pl.", inferredSynonyms
.get(0).getTitleCache());
1196 inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymType
.INFERRED_GENUS_OF(), true);
1197 assertNotNull("there should be a new synonym ", inferredSynonyms
);
1198 assertEquals ("the name of inferred epithet should be SynGenus lachesis", "Acherontia ciprosus syn. sec. Sp. Pl.", inferredSynonyms
.get(0).getTitleCache());
1200 inferredSynonyms
= service
.createInferredSynonyms(taxon
, tree
, SynonymType
.POTENTIAL_COMBINATION_OF(), true);
1201 assertNotNull("there should be a new synonym ", inferredSynonyms
);
1202 assertEquals ("the name of inferred epithet should be SynGenus lachesis", "SynGenus ciprosus syn. sec. Sp. Pl.", inferredSynonyms
.get(0).getTitleCache());
1203 //assertTrue("set of synonyms should contain an inferred Synonym ", synonyms.contains(arg0))
1207 @DataSet("../../database/ClearDBDataSet.xml")
1208 public final void testTaxonDeletionConfig(){
1209 final String
[]tableNames
= {}
1210 // "Classification", "Classification_AUD",
1211 // "TaxonBase","TaxonBase_AUD",
1212 // "TaxonNode","TaxonNode_AUD",
1213 // "TaxonName","TaxonName_AUD",
1214 // "TaxonRelationship", "TaxonRelationship_AUD",
1215 // "TaxonDescription", "TaxonDescription_AUD",
1216 // "HomotypicalGroup","HomotypicalGroup_AUD",
1217 // "PolytomousKey","PolytomousKey_AUD",
1218 // "PolytomousKeyNode","PolytomousKeyNode_AUD",
1219 // "Media","Media_AUD",
1220 // "DescriptiveDataSet","DescriptiveDataSet_AUD",
1221 // "DescriptionElementBase","DescriptionElementBase_AUD",
1222 // "DeterminationEvent","DeterminationEvent_AUD",
1223 // "SpecimenOrObservationBase","SpecimenOrObservationBase_AUD"}
1226 commitAndStartNewTransaction(tableNames
);
1228 commitAndStartNewTransaction(tableNames
);
1229 int nTaxa
= service
.count(Taxon
.class);
1231 Assert
.assertEquals("There should be 4 taxa in the database", 4, nTaxa
);
1232 Taxon parent
= (Taxon
)service
.find(GENUS_UUID
);
1233 Assert
.assertNotNull("Parent taxon should exist", parent
);
1234 Taxon child1
= (Taxon
)service
.find(SPECIES1_UUID
);
1235 Assert
.assertNotNull("Child taxon should exist", child1
);
1236 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1237 config
.setDeleteTaxonNodes(false);
1238 config
.setDeleteMisappliedNames(false);
1240 //commitAndStartNewTransaction(tableNames);
1242 DeleteResult result
= service
.deleteTaxon(child1
.getUuid(), config
, null);
1244 Assert
.fail("Delete should throw an error as long as name is used in classification.");
1247 nTaxa
= service
.count(Taxon
.class);
1248 Assert
.assertEquals("There should be 4 taxa in the database", 4, nTaxa
);
1249 child1
= (Taxon
)service
.find(SPECIES1_UUID
);
1250 Assert
.assertNotNull("Child taxon should exist", child1
);
1251 Assert
.assertEquals("Child should belong to 1 node", 1, child1
.getTaxonNodes().size());
1253 TaxonNode node
= child1
.getTaxonNodes().iterator().next();
1254 child1
.addSource(IdentifiableSource
.NewInstance(OriginalSourceType
.Import
));
1256 SpecimenOrObservationBase
<?
> identifiedUnit
= DerivedUnit
.NewInstance(SpecimenOrObservationType
.DerivedUnit
);
1257 DeterminationEvent
.NewInstance(child1
, identifiedUnit
);
1258 //UUID eventUUID = eventService.save(determinationEvent);
1259 UUID identifiedUnitUUID
= occurenceService
.save(identifiedUnit
).getUuid();
1261 TaxonNode parentNode
= node
.getParent();
1262 parentNode
=CdmBase
.deproxy(parentNode
, TaxonNode
.class);
1263 parentNode
.deleteChildNode(node
);
1264 nodeService
.save(parentNode
);
1265 //commitAndStartNewTransaction(tableNames);
1269 result
= service
.deleteTaxon(child1
1270 .getUuid(), config
, null);
1272 Assert
.fail("Delete should throw an exception because of the determination event");
1275 //determinationEvent = (DeterminationEvent)eventService.load(eventUUID);
1276 commitAndStartNewTransaction(tableNames
);
1277 identifiedUnit
= occurenceService
.load(identifiedUnitUUID
);
1279 occurenceService
.delete(identifiedUnit
);
1281 commitAndStartNewTransaction(tableNames
);
1282 child1
= (Taxon
)service
.find(SPECIES1_UUID
);
1284 assertEquals(0, child1
.getTaxonNodes().size());
1287 result
= service
.deleteTaxon(child1
.getUuid(), config
, null);
1289 if (!result
.isOk()){
1290 Assert
.fail("Delete should not throw an exception anymore");
1293 nTaxa
= service
.count(Taxon
.class);
1294 Assert
.assertEquals("There should be 3 taxa in the database", 3, nTaxa
);
1296 config
.setDeleteTaxonNodes(true);
1297 Taxon child2
=(Taxon
) service
.find(SPECIES2_UUID
);
1300 result
= service
.deleteTaxon(child2
.getUuid(), config
, child2
.getTaxonNodes().iterator().next().getClassification().getUuid());
1301 if (!result
.isOk()){
1302 Assert
.fail("Delete should not throw an exception");
1305 //service.find(uuid);
1307 nTaxa
= service
.count(Taxon
.class);
1308 Assert
.assertEquals("There should be 2 taxa in the database",2, nTaxa
);
1309 // nNames = nameService.count(TaxonName.class);
1310 // Assert.assertEquals("There should be 3 names left in the database", 3, nNames);
1311 // int nRelations = service.countAllRelationships();
1312 // Assert.assertEquals("There should be no relationship left in the database", 0, nRelations);
1316 @DataSet(value
="../../database/ClearDBDataSet.xml")
1317 public final void testDeleteTaxon(){
1319 //create a small classification
1320 Taxon testTaxon
= getTestTaxon();
1321 service
.save(testTaxon
).getUuid();
1323 Taxon speciesTaxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1324 Iterator
<TaxonDescription
> descriptionIterator
= speciesTaxon
.getDescriptions().iterator();
1325 UUID descrUUID
= null;
1326 UUID descrElementUUID
= null;
1327 if (descriptionIterator
.hasNext()){
1328 TaxonDescription descr
= descriptionIterator
.next();
1329 descrUUID
= descr
.getUuid();
1330 descrElementUUID
= descr
.getElements().iterator().next().getUuid();
1332 IBotanicalName taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1333 assertNotNull(taxonName
);
1335 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1336 config
.setDeleteNameIfPossible(false);
1338 DeleteResult result
= service
.deleteTaxon(speciesTaxon
.getUuid(), config
, speciesTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1339 if (!result
.isOk()){
1342 commitAndStartNewTransaction(null);
1344 taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1345 Taxon taxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1347 //descriptionService.find(descrUUID);
1348 assertNull(descriptionService
.find(descrUUID
));
1349 assertNull(descriptionService
.getDescriptionElementByUuid(descrElementUUID
));
1350 //assertNull(synName);
1351 assertNotNull(taxonName
);
1353 config
.setDeleteNameIfPossible(true);
1354 Taxon newTaxon
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES()), null);
1355 service
.save(newTaxon
);
1356 result
= service
.deleteTaxon(newTaxon
.getUuid()
1358 if (!result
.isOk()){
1364 @DataSet(value
="../../database/ClearDBDataSet.xml")
1365 public final void testDeleteTaxonWithAnnotations(){
1367 //create a small classification
1368 Taxon testTaxon
= getTestTaxon();
1369 service
.save(testTaxon
).getUuid();
1371 Taxon speciesTaxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1372 Iterator
<TaxonDescription
> descriptionIterator
= speciesTaxon
.getDescriptions().iterator();
1373 UUID descrUUID
= null;
1374 UUID descrElementUUID
= null;
1375 if (descriptionIterator
.hasNext()){
1376 TaxonDescription descr
= descriptionIterator
.next();
1377 descrUUID
= descr
.getUuid();
1378 descrElementUUID
= descr
.getElements().iterator().next().getUuid();
1380 IBotanicalName taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1381 assertNotNull(taxonName
);
1383 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1384 config
.setDeleteNameIfPossible(false);
1385 Annotation annotation
= Annotation
.NewDefaultLanguageInstance("test");
1386 speciesTaxon
.addAnnotation(annotation
);
1389 DeleteResult result
= service
.deleteTaxon(speciesTaxon
.getUuid(), config
, speciesTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1390 if (!result
.isOk()){
1393 commitAndStartNewTransaction(null);
1395 taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1396 Taxon taxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1398 //descriptionService.find(descrUUID);
1399 assertNull(descriptionService
.find(descrUUID
));
1400 assertNull(descriptionService
.getDescriptionElementByUuid(descrElementUUID
));
1401 //assertNull(synName);
1402 assertNotNull(taxonName
);
1404 config
.setDeleteNameIfPossible(true);
1405 Taxon newTaxon
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES()), null);
1406 service
.save(newTaxon
);
1407 result
= service
.deleteTaxon(newTaxon
.getUuid()
1409 if (!result
.isOk()){
1415 @DataSet(value
="../../database/ClearDBDataSet.xml")
1416 public final void testDeleteTaxonUsedInTaxonRelation(){
1418 //create a small classification
1419 Taxon testTaxon
= getTestTaxon();
1420 service
.save(testTaxon
).getUuid();
1422 Taxon speciesTaxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1423 Taxon speciesTaxon2
= (Taxon
)service
.find(SPECIES2_UUID
);
1424 speciesTaxon
.addTaxonRelation(speciesTaxon2
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR(), null, null);
1426 IBotanicalName taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1427 assertNotNull(taxonName
);
1429 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1430 config
.setDeleteNameIfPossible(false);
1431 config
.setDeleteTaxonRelationships(false);
1434 DeleteResult result
= service
.deleteTaxon(speciesTaxon
.getUuid(), config
, speciesTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1438 commitAndStartNewTransaction(null);
1440 taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1441 Taxon taxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1443 assertNotNull(taxonName
);
1444 assertNotNull(taxon
);
1446 config
.setDeleteNameIfPossible(false);
1447 config
.setDeleteTaxonRelationships(true);
1450 result
= service
.deleteTaxon(speciesTaxon
.getUuid(), config
, speciesTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1451 if (!result
.isOk()){
1454 commitAndStartNewTransaction(null);
1456 config
.setDeleteNameIfPossible(true);
1457 Taxon newTaxon
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES()), null);
1458 service
.save(newTaxon
);
1459 result
= service
.deleteTaxon(newTaxon
.getUuid()
1461 if (!result
.isOk()){
1467 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="../../database/ClearDBDataSet.xml")
1468 public final void testDeleteTaxonDeleteSynonymRelations(){
1470 final String
[]tableNames
= {
1471 "Classification", "Classification_AUD",
1472 "TaxonBase","TaxonBase_AUD",
1473 "TaxonNode","TaxonNode_AUD",
1474 "TaxonName","TaxonName_AUD"};
1475 commitAndStartNewTransaction(tableNames
);
1476 //create a small classification
1477 Taxon testTaxon
= getTestTaxon();
1478 service
.save(testTaxon
).getUuid();
1479 Taxon speciesTaxon
= (Taxon
)service
.find(SPECIES2_UUID
);
1481 Synonym synonym
= speciesTaxon
.getSynonyms().iterator().next();
1482 UUID synonymUuid
= synonym
.getUuid();
1483 service
.countSynonyms(true);
1485 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1486 config
.setDeleteSynonymsIfPossible(false);
1489 DeleteResult result
= service
.deleteTaxon(speciesTaxon
.getUuid(), config
, speciesTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1490 if (!result
.isOk()){
1493 commitAndStartNewTransaction(null);
1495 Taxon taxon
= (Taxon
)service
.find(SPECIES2_UUID
);
1496 assertNull("The deleted taxon should no longer exist", taxon
);
1498 Synonym syn
= (Synonym
)service
.find(synonymUuid
);
1499 assertNotNull("The synonym should still exist since DeleteSynonymsIfPossible was false", service
.find(synonymUuid
));
1500 assertNull("The synonym should not be attached to an accepted taxon anymore", syn
.getAcceptedTaxon());
1504 @DataSet(value
="../../database/ClearDBDataSet.xml")
1505 public final void testDeleteTaxonNameUsedInOtherContext(){
1507 //create a small classification
1508 Taxon testTaxon
= getTestTaxon();
1509 service
.save(testTaxon
).getUuid();
1510 Taxon speciesTaxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1512 IBotanicalName taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1513 assertNotNull(taxonName
);
1514 TaxonName fromName
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
1515 taxonName
.addRelationshipFromName(fromName
, NameRelationshipType
.VALIDATED_BY_NAME(), null, null);
1516 nameService
.save(fromName
);
1518 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1519 config
.setDeleteNameIfPossible(true);
1520 DeleteResult result
= service
.deleteTaxon(speciesTaxon
.getUuid(), config
, speciesTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1521 if (!result
.isOk()){
1524 commitAndStartNewTransaction(null);
1526 taxonName
= nameService
.find(SPECIES1_NAME_UUID
);
1527 Taxon taxon
= (Taxon
)service
.find(SPECIES1_UUID
);
1528 //because of the namerelationship the name cannot be deleted
1529 assertNotNull(taxonName
);
1534 @DataSet(value
="../../database/ClearDBDataSet.xml")
1535 public final void testDeleteTaxonNameUsedInTwoClassificationsDeleteAllNodes(){
1536 commitAndStartNewTransaction(null);
1537 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator();
1538 //create a small classification
1539 Taxon testTaxon
= getTestTaxon();
1541 UUID uuid
= service
.save(testTaxon
).getUuid();
1542 //BotanicalName name = nameService.find(uuid);
1543 Set
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes();
1544 TaxonNode node
= nodes
.iterator().next();
1545 List
<TaxonNode
> childNodes
= node
.getChildNodes();
1546 TaxonNode childNode
= childNodes
.iterator().next();
1547 UUID childUUID
= childNode
.getTaxon().getUuid();
1548 Classification secondClassification
= getTestClassification("secondClassification");
1550 secondClassification
.addChildTaxon(testTaxon
, null, null);
1551 //delete the taxon in all classifications
1552 config
.setDeleteInAllClassifications(true);
1553 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, null);
1554 if (!result
.isOk()){
1557 commitAndStartNewTransaction(null);
1558 Taxon tax
= (Taxon
)service
.find(uuid
);
1560 Taxon childTaxon
= (Taxon
)service
.find(childUUID
);
1562 commitAndStartNewTransaction(null);
1566 @DataSet(value
="../../database/ClearDBDataSet.xml")
1567 public final void testDeleteTaxonNameUsedInTwoClassificationsDoNotDeleteAllNodes(){
1568 // delete the taxon only in second classification, this should delete only the nodes, not the taxa
1569 Taxon testTaxon
= getTestTaxon();
1570 UUID uuid
= service
.save(testTaxon
).getUuid();
1571 Classification secondClassification
= getTestClassification("secondClassification");
1572 Set
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes();
1573 TaxonNode node
= nodes
.iterator().next();
1574 List
<TaxonNode
> childNodes
= node
.getChildNodes();
1575 TaxonNode childNode
= childNodes
.iterator().next();
1576 UUID childUUID
= childNode
.getTaxon().getUuid();
1577 childNode
= secondClassification
.addChildTaxon(testTaxon
, null, null);
1578 UUID childNodeUUID
= childNode
.getUuid();
1580 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1581 config
.setDeleteInAllClassifications(false);
1583 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, secondClassification
.getUuid());
1584 /* Assert.fail("The taxon should not be deletable because it is used in a second classification and the configuration is set to deleteInAllClassifications = false");
1585 } catch (DataChangeNoRollbackException e) {
1586 logger.debug(e.getMessage());
1591 Assert
.fail("The taxon should not be deletable because it is used in a second classification and the configuration is set to deleteInAllClassifications = false");
1594 //commitAndStartNewTransaction(null);
1595 Taxon tax
= (Taxon
)service
.find(uuid
);
1597 Taxon childTaxon
= (Taxon
)service
.find(childUUID
);
1599 //when calling delete taxon and the taxon can not be deleted the children should not be deleted as well. If children should be deleted call delete taxonnode
1600 node
= nodeService
.find(childNodeUUID
);
1601 assertNotNull(node
);
1605 @DataSet(value
="../../database/ClearDBDataSet.xml")
1606 public final void testTaxonNodeDeletionConfiguratorMoveToParent(){
1607 //test childHandling MOVE_TO_PARENT:
1608 Taxon testTaxon
= getTestTaxon();
1609 UUID uuid
= service
.save(testTaxon
).getUuid();
1611 Taxon topMost
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.FAMILY()), null);
1613 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1614 TaxonNode node
=nodes
.next();
1615 Classification classification
= node
.getClassification();
1616 classification
.addParentChild(topMost
, testTaxon
, null, null);
1617 UUID topMostUUID
= service
.save(topMost
).getUuid();
1619 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1620 config
.getTaxonNodeConfig().setChildHandling(ChildHandling
.MOVE_TO_PARENT
);
1623 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, classification
.getUuid());
1628 commitAndStartNewTransaction(null);
1629 Taxon tax
= (Taxon
)service
.find(uuid
);
1631 tax
= (Taxon
)service
.find(topMostUUID
);
1632 Set
<TaxonNode
> topMostNodes
= tax
.getTaxonNodes();
1633 assertNotNull(topMostNodes
);
1634 assertEquals("there should be one taxon node", 1, topMostNodes
.size());
1635 nodes
= topMostNodes
.iterator();
1636 TaxonNode topMostNode
= nodes
.next();
1637 int size
= topMostNode
.getChildNodes().size();
1639 assertEquals(2, size
);
1643 @DataSet(value
="../../database/ClearDBDataSet.xml")
1644 public final void testTaxonNodeDeletionConfiguratorDeleteChildren(){
1645 //test childHandling DELETE:
1646 Taxon testTaxon
= getTestTaxon();
1647 UUID uuid
= service
.save(testTaxon
).getUuid();
1649 Taxon topMost
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.FAMILY()), null);
1651 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1652 TaxonNode node
=nodes
.next();
1653 UUID taxonNodeUUID
= node
.getUuid();
1654 Classification classification
= node
.getClassification();
1655 classification
.addParentChild(topMost
, testTaxon
, null, null);
1656 UUID topMostUUID
= service
.save(topMost
).getUuid();
1658 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1659 config
.getTaxonNodeConfig().setChildHandling(ChildHandling
.DELETE
);
1662 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, testTaxon
.getTaxonNodes().iterator().next().getClassification().getUuid());
1666 commitAndStartNewTransaction(null);
1667 Taxon tax
= (Taxon
)service
.find(uuid
);
1669 tax
= (Taxon
)service
.find(topMostUUID
);
1670 Set
<TaxonNode
> topMostNodes
= tax
.getTaxonNodes();
1671 assertNotNull(topMostNodes
);
1672 assertEquals("there should be one taxon node", 1, topMostNodes
.size());
1673 nodes
= topMostNodes
.iterator();
1674 TaxonNode topMostNode
= nodes
.next();
1675 int size
= topMostNode
.getChildNodes().size();
1676 node
= nodeService
.find(taxonNodeUUID
);
1678 assertEquals(0, size
);
1683 @DataSet(value
="../../database/ClearDBDataSet.xml")
1684 public final void testTaxonDeletionConfiguratorDeleteMarker(){
1685 //test childHandling DELETE:
1686 Taxon testTaxon
= getTestTaxon();
1687 UUID uuid
= service
.save(testTaxon
).getUuid();
1689 Taxon topMost
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.FAMILY()), null);
1691 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1692 TaxonNode node
=nodes
.next();
1693 Classification classification
= node
.getClassification();
1694 classification
.addParentChild(topMost
, testTaxon
, null, null);
1695 UUID topMostUUID
= service
.save(topMost
).getUuid();
1696 Marker marker
= Marker
.NewInstance(testTaxon
, true, MarkerType
.IS_DOUBTFUL());
1697 testTaxon
.addMarker(marker
);
1698 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1699 config
.getTaxonNodeConfig().setChildHandling(ChildHandling
.DELETE
);
1701 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, node
.getClassification().getUuid());
1706 commitAndStartNewTransaction(null);
1707 Taxon tax
= (Taxon
)service
.find(uuid
);
1709 tax
= (Taxon
)service
.find(topMostUUID
);
1710 Set
<TaxonNode
> topMostNodes
= tax
.getTaxonNodes();
1711 assertNotNull(topMostNodes
);
1712 assertEquals("there should be one taxon node", 1, topMostNodes
.size());
1713 nodes
= topMostNodes
.iterator();
1714 TaxonNode topMostNode
= nodes
.next();
1715 int size
= topMostNode
.getChildNodes().size();
1717 assertEquals(0, size
);
1722 @DataSet(value
="../../database/ClearDBDataSet.xml")
1723 public final void testTaxonDeletionConfiguratorTaxonWithMisappliedName(){
1725 Taxon testTaxon
= getTestTaxon();
1726 UUID uuid
= service
.save(testTaxon
).getUuid();
1728 Taxon misappliedName
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.GENUS()), null);
1730 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1731 TaxonNode node
=nodes
.next();
1732 testTaxon
.addMisappliedName(misappliedName
, null, null);
1733 UUID misappliedNameUUID
= service
.save(misappliedName
).getUuid();
1735 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1736 config
.setDeleteMisappliedNames(true);
1738 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, node
.getClassification().getUuid());
1742 commitAndStartNewTransaction(null);
1743 Taxon tax
= (Taxon
)service
.find(uuid
);
1745 tax
= (Taxon
)service
.find(misappliedNameUUID
);
1746 //TODO: is that correct or should it be deleted because there is no relation to anything
1751 @DataSet(value
="../../database/ClearDBDataSet.xml")
1752 public final void testTaxonDeletionConfiguratorTaxonWithMisappliedNameDoNotDelete(){
1754 Taxon testTaxon
= getTestTaxon();
1755 UUID uuid
= service
.save(testTaxon
).getUuid();
1757 Taxon misappliedName
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.GENUS()), null);
1759 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1760 TaxonNode node
=nodes
.next();
1761 testTaxon
.addMisappliedName(misappliedName
, null, null);
1762 UUID misappliedNameUUID
= service
.save(misappliedName
).getUuid();
1764 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1765 config
.setDeleteMisappliedNames(false);
1767 DeleteResult result
= service
.deleteTaxon(testTaxon
.getUuid(), config
, node
.getClassification().getUuid());
1771 commitAndStartNewTransaction(null);
1772 Taxon tax
= (Taxon
)service
.find(uuid
);
1774 tax
= (Taxon
)service
.find(misappliedNameUUID
);
1775 //TODO: is that correct or should it be deleted because there is no relation to anything
1780 @DataSet(value
="../../database/ClearDBDataSet.xml")
1781 public final void testTaxonDeletionConfiguratorTaxonMisappliedName(){
1783 Taxon testTaxon
= getTestTaxon();
1784 UUID uuid
= service
.save(testTaxon
).getUuid();
1786 Taxon misappliedNameTaxon
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(Rank
.GENUS()), null);
1788 Iterator
<TaxonNode
> nodes
= testTaxon
.getTaxonNodes().iterator();
1789 TaxonNode node
=nodes
.next();
1790 testTaxon
.addMisappliedName(misappliedNameTaxon
, null, null);
1791 UUID misappliedNameUUID
= service
.save(misappliedNameTaxon
).getUuid();
1792 misappliedNameTaxon
= (Taxon
)service
.find(misappliedNameUUID
);
1793 UUID misNameUUID
= misappliedNameTaxon
.getName().getUuid();
1795 TaxonDeletionConfigurator config
= new TaxonDeletionConfigurator() ;
1797 service
.deleteTaxon(misappliedNameTaxon
.getUuid(), config
,null);
1799 commitAndStartNewTransaction(null);
1800 Taxon tax
= (Taxon
)service
.find(uuid
);
1802 tax
= (Taxon
)service
.find(misappliedNameUUID
);
1803 IBotanicalName name
= nameService
.find(misNameUUID
);
1810 @DataSet(value
="../../database/ClearDBDataSet.xml")
1811 public final void testListIncludedTaxa(){
1812 Reference citation
= null;
1813 String microcitation
= null;
1816 Classification cl1
= Classification
.NewInstance("testClassification1");
1817 Classification cl2
= Classification
.NewInstance("testClassification2");
1818 Classification cl3
= Classification
.NewInstance("testClassification3");
1820 classificationService
.save(cl1
);
1821 classificationService
.save(cl2
);
1822 classificationService
.save(cl3
);
1824 Taxon c1Genus
= Taxon
.NewInstance(null, null);c1Genus
.setUuid(UUID
.fromString("daa24f6f-7e38-4668-b385-10c789212e4e"));
1825 Taxon c1Species
= Taxon
.NewInstance(null, null);c1Species
.setUuid(UUID
.fromString("1c1d0566-67d0-4806-bf23-ecf55f4b9118"));
1826 Taxon c1SubSpecies1
= Taxon
.NewInstance(null, null);c1SubSpecies1
.setUuid(UUID
.fromString("96ae2fad-76df-429f-b179-42e00838fea4"));
1827 Taxon c1SubSpecies2
= Taxon
.NewInstance(null, null);c1SubSpecies2
.setUuid(UUID
.fromString("5d3f6147-ca72-40e0-be8a-6c835a09a579"));
1828 TaxonNode c1childNodeSpecies1
= cl1
.addParentChild(c1Genus
, c1Species
, null, null);
1829 nodeService
.saveOrUpdate(c1childNodeSpecies1
.getParent());
1830 nodeService
.saveOrUpdate(c1childNodeSpecies1
);
1831 TaxonNode c1childNodeSubSpecies1
=cl1
.addParentChild(c1Species
, c1SubSpecies1
, null, null);
1832 nodeService
.saveOrUpdate(c1childNodeSubSpecies1
);
1833 TaxonNode c1childNodeSubSpecies2
=cl1
.addParentChild(c1Species
, c1SubSpecies2
, null, null);
1834 nodeService
.saveOrUpdate(c1childNodeSubSpecies2
);
1836 Taxon c2Genus
= Taxon
.NewInstance(null, null);c2Genus
.setUuid(UUID
.fromString("ed0ec006-3ac8-4a12-ae13-fdf2a13dedbe"));
1837 Taxon c2Species
= Taxon
.NewInstance(null, null);c2Species
.setUuid(UUID
.fromString("1027eb18-1c26-450e-a299-981b775ebc3c"));
1838 Taxon c2SubSpecies1
= Taxon
.NewInstance(null, null);c2SubSpecies1
.setUuid(UUID
.fromString("61f039c8-01f3-4f5d-8e16-1602139774e7"));
1839 Taxon c2SubSpecies2
= Taxon
.NewInstance(null, null);c2SubSpecies2
.setUuid(UUID
.fromString("2ed6b6f8-05f9-459a-a075-2bca57e3013e"));
1840 TaxonNode c2childNodeSpecies1
= cl2
.addParentChild(c2Genus
, c2Species
, null, null);
1841 nodeService
.saveOrUpdate(c2childNodeSpecies1
.getParent());
1842 nodeService
.saveOrUpdate(c2childNodeSpecies1
);
1843 TaxonNode c2childNodeSubSpecies1
= cl2
.addParentChild(c2Species
, c2SubSpecies1
, null, null);
1844 nodeService
.saveOrUpdate(c2childNodeSubSpecies1
);
1845 TaxonNode c2childNodeSubSpecies2
= cl2
.addParentChild(c2Species
, c2SubSpecies2
, null, null);
1846 nodeService
.saveOrUpdate(c2childNodeSubSpecies2
);
1848 Taxon c3Genus
= Taxon
.NewInstance(null, null);c3Genus
.setUuid(UUID
.fromString("407dfc8d-7a4f-4370-ada4-76c1a8279d1f"));
1849 Taxon c3Species
= Taxon
.NewInstance(null, null);c3Species
.setUuid(UUID
.fromString("b6d34fc7-4aa7-41e5-b633-86f474edbbd5"));
1850 Taxon c3SubSpecies1
= Taxon
.NewInstance(null, null);c3SubSpecies1
.setUuid(UUID
.fromString("01c07585-a422-40cd-9339-a74c56901d9f"));
1851 Taxon c3SubSpecies2
= Taxon
.NewInstance(null, null);c3SubSpecies2
.setUuid(UUID
.fromString("390c8e23-e05f-4f89-b417-50cf080f4c91"));
1852 TaxonNode c3childNodeSpecies1
= cl3
.addParentChild(c3Genus
, c3Species
, null, null);
1853 nodeService
.saveOrUpdate(c3childNodeSpecies1
.getParent());
1854 nodeService
.saveOrUpdate(c3childNodeSpecies1
);
1855 TaxonNode c3childNodeSubSpecies1
= cl3
.addParentChild(c3Species
, c3SubSpecies1
, null, null);
1856 nodeService
.saveOrUpdate(c3childNodeSubSpecies1
);
1857 TaxonNode c3childNodeSubSpecies2
= cl3
.addParentChild(c3Species
, c3SubSpecies2
, null, null);
1858 nodeService
.saveOrUpdate(c3childNodeSubSpecies2
);
1860 Taxon c4Genus
= Taxon
.NewInstance(null, null);c4Genus
.setUuid(UUID
.fromString("bfd6bbdd-0116-4ab2-a781-9316224aad78"));
1861 Taxon c4Species
= Taxon
.NewInstance(null, null);c4Species
.setUuid(UUID
.fromString("9347a3d9-5ece-4d64-9035-e8aaf5d3ee02"));
1862 Taxon c4SubSpecies
= Taxon
.NewInstance(null, null);c4SubSpecies
.setUuid(UUID
.fromString("777aabbe-4c3a-449c-ab99-a91f2fec9f07"));
1864 TaxonRelationship rel
= c1Species
.addTaxonRelation(c2Species
, TaxonRelationshipType
.CONGRUENT_TO(), citation
, microcitation
);
1865 rel
.setDoubtful(true);
1866 c1Species
.addTaxonRelation(c4Species
, TaxonRelationshipType
.INCLUDES(), citation
, microcitation
);
1867 c2Species
.addTaxonRelation(c1SubSpecies2
, TaxonRelationshipType
.INCLUDES(), citation
, microcitation
);
1869 service
.saveOrUpdate(c1Species
);
1870 service
.saveOrUpdate(c2Species
);
1871 service
.save(c4Species
);
1872 commitAndStartNewTransaction();
1875 //default starting at species 1
1876 IncludedTaxaDTO dto
= service
.listIncludedTaxa(c1Species
.getUuid(), new IncludedTaxonConfiguration(null, true, false));
1877 Assert
.assertNotNull("IncludedTaxaDTO", dto
);
1878 Assert
.assertEquals("Result should contain 7 taxa: c1Species", 7, dto
.getIncludedTaxa().size());
1879 Assert
.assertNotNull("date should not be null", dto
.getDate());
1880 // Assert.assertTrue(dto.contains(taxonUuid));
1881 //same without doubtful
1882 dto
= service
.listIncludedTaxa(c1Species
.getUuid(), new IncludedTaxonConfiguration(null, false, false));
1883 Assert
.assertEquals(4, dto
.getIncludedTaxa().size());
1885 //other example starting at Genus2
1886 dto
= service
.listIncludedTaxa(c2Genus
.getUuid(), new IncludedTaxonConfiguration(null, true, false));
1887 Assert
.assertEquals(8, dto
.getIncludedTaxa().size());
1888 //same without doubtful
1889 dto
= service
.listIncludedTaxa(c2Genus
.getUuid(), new IncludedTaxonConfiguration(null, false, false));
1890 Assert
.assertEquals(5, dto
.getIncludedTaxa().size());
1893 dto
= service
.listIncludedTaxa(c1Species
.getUuid(), new IncludedTaxonConfiguration(null, true, true));
1894 Assert
.assertEquals(2, dto
.getIncludedTaxa().size());
1895 //same without doubtful
1896 dto
= service
.listIncludedTaxa(c1Species
.getUuid(), new IncludedTaxonConfiguration(null, false, true));
1897 Assert
.assertEquals(1, dto
.getIncludedTaxa().size());
1901 public void testDeleteDescriptions(){
1903 createTestDataSet();
1904 } catch (FileNotFoundException e
) {
1905 // TODO Auto-generated catch block
1906 e
.printStackTrace();
1908 TaxonDescription description
= TaxonDescription
.NewInstance(taxWithoutSyn
);
1909 SpecimenOrObservationBase
<IIdentifiableEntityCacheStrategy
<FieldUnit
>> specimen
= FieldUnit
.NewInstance();
1910 UUID uuid
= occurenceService
.saveOrUpdate(specimen
);
1911 DescriptionElementBase element
= IndividualsAssociation
.NewInstance(specimen
);
1912 description
.addElement(element
);
1913 service
.saveOrUpdate(taxWithoutSyn
);
1916 Taxon tax
= (Taxon
)service
.find(uuidTaxWithoutSyn
);
1917 Set
<TaxonDescription
> descr
= tax
.getDescriptions();
1918 assertEquals(1, descr
.size());
1919 description
= descr
.iterator().next();
1920 UUID uuidDescr
= description
.getUuid();
1921 UUID uuidDescEl
= description
.getElements().iterator().next().getUuid();
1923 descriptionService
.deleteDescription(description
);
1924 service
.saveOrUpdate(tax
);
1926 description
= (TaxonDescription
) descriptionService
.find(uuidDescr
);
1927 specimen
= occurenceService
.find(uuid
);
1928 assertNull(description
);
1929 DeleteResult result
= occurenceService
.delete(specimen
);
1930 assertTrue(result
.isOk());
1935 public void testRemoveDescriptionsFromTaxa(){
1937 createTestDataSet();
1938 } catch (FileNotFoundException e
) {
1939 // TODO Auto-generated catch block
1940 e
.printStackTrace();
1942 TaxonDescription description
= TaxonDescription
.NewInstance(taxWithoutSyn
);
1943 SpecimenOrObservationBase
<IIdentifiableEntityCacheStrategy
<FieldUnit
>> specimen
= FieldUnit
.NewInstance();
1944 UUID uuid
= occurenceService
.saveOrUpdate(specimen
);
1945 DescriptionElementBase element
= IndividualsAssociation
.NewInstance(specimen
);
1946 description
.addElement(element
);
1947 service
.saveOrUpdate(taxWithoutSyn
);
1950 Taxon tax
= (Taxon
)service
.find(uuidTaxWithoutSyn
);
1951 Set
<TaxonDescription
> descr
= tax
.getDescriptions();
1952 assertEquals(1, descr
.size());
1953 description
= descr
.iterator().next();
1954 UUID uuidDescr
= description
.getUuid();
1957 tax
.removeDescription(description
, true);
1958 service
.saveOrUpdate(tax
);
1960 description
= (TaxonDescription
) descriptionService
.find(uuidDescr
);
1961 specimen
= occurenceService
.find(uuid
);
1962 assertNotNull(description
);
1963 DeleteResult result
= occurenceService
.delete(specimen
);
1964 assertTrue(result
.isOk());
1968 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="ClearDBDataSet.xml")
1969 public void createTestDataSet() throws FileNotFoundException
{
1970 Rank rank
= Rank
.SPECIES();
1971 taxWithoutSyn
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test1", null, null, null, null, null, null, null), null);
1972 taxWithSyn
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test3", null, null, null, null, null, null, null), null);
1973 tax2WithSyn
= Taxon
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test5", null, null, null, null, null, null, null), null);
1974 synonym
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test2", null, null, null, null, null, null, null), null);
1975 synonym2
= Synonym
.NewInstance(TaxonNameFactory
.NewBotanicalInstance(rank
, "Test4", null, null, null, null, null, null, null), null);
1976 synonym2
.getName().setHomotypicalGroup(synonym
.getHomotypicGroup());
1978 taxWithSyn
.addSynonym(synonym
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
1979 taxWithSyn
.addSynonym(synonym2
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
1981 uuidTaxWithoutSyn
= service
.save(taxWithoutSyn
).getUuid();
1982 uuidSyn
= service
.save(synonym
).getUuid();
1983 uuidSyn2
= service
.save(synonym2
).getUuid();
1984 uuidTaxWithSyn
=service
.save(taxWithSyn
).getUuid();
1988 //public static UUID DESCRIPTION1_UUID = UUID.fromString("f3e061f6-c5df-465c-a253-1e18ab4c7e50");
1989 //public static UUID DESCRIPTION2_UUID = UUID.fromString("1b009a40-ebff-4f7e-9f7f-75a850ba995d");
1991 public Taxon
getTestTaxon(){
1992 int descrIndex
= 6000;
1993 Person deCandolle
= Person
.NewInstance();
1994 deCandolle
.setTitleCache("DC.", true);
1996 Reference sec
= ReferenceFactory
.newDatabase();
1997 sec
.setTitleCache("Flora lunaea", true);
1998 Reference citationRef
= ReferenceFactory
.newBook();
1999 citationRef
.setTitleCache("Sp. lunarum", true);
2001 //genus taxon with Name, combinationAuthor,
2002 IBotanicalName botName
= TaxonNameFactory
.NewBotanicalInstance(Rank
.GENUS());
2003 botName
.setTitleCache("Hieracium L.", true);
2004 botName
.setGenusOrUninomial("Hieracium");
2005 botName
.setCombinationAuthorship(Person
.NewInstance());
2006 botName
.getCombinationAuthorship().setNomenclaturalTitle("L.");
2007 botName
.setUuid(GENUS_NAME_UUID
);
2008 Taxon genusTaxon
= Taxon
.NewInstance(botName
, sec
);
2009 genusTaxon
.setUuid(GENUS_UUID
);
2010 service
.save(genusTaxon
);
2011 //a name that is the basionym of genusTaxon's name
2012 TaxonName basionym
= TaxonNameFactory
.NewBotanicalInstance(Rank
.GENUS());
2013 basionym
.setTitleCache("Hieracilla DC.", true);
2014 basionym
.setGenusOrUninomial("Hieracilla");
2015 basionym
.setCombinationAuthorship(deCandolle
);
2016 basionym
.setUuid(BASIONYM_UUID
);
2017 botName
.addBasionym(basionym
, null, null,"216", null);
2018 nameService
.saveOrUpdate(basionym
);
2019 //species taxon that is the child of genus taxon
2020 IBotanicalName botSpecies
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
2021 botSpecies
.setTitleCache("Hieracium asturianum Pau", true);
2022 botSpecies
.setGenusOrUninomial("Hieracium");
2023 botSpecies
.setSpecificEpithet("asturianum");
2024 botSpecies
.setCombinationAuthorship(Person
.NewInstance());
2025 botSpecies
.getCombinationAuthorship().setNomenclaturalTitle("Pau");
2026 botSpecies
.setUuid(SPECIES1_NAME_UUID
);
2027 Taxon childTaxon
= Taxon
.NewInstance(botSpecies
, sec
);
2028 childTaxon
.setUuid(SPECIES1_UUID
);
2029 TaxonDescription taxDesc
= getTestDescription(descrIndex
++);
2030 //taxDesc.setUuid(DESCRIPTION1_UUID);
2031 childTaxon
.addDescription(taxDesc
);
2032 service
.saveOrUpdate(childTaxon
);
2033 Classification classification
= getTestClassification("TestClassification");
2034 classification
.addParentChild(genusTaxon
, childTaxon
, citationRef
, "456");
2035 // childTaxon.setTaxonomicParent(genusTaxon, citationRef, "456");
2036 classificationService
.save(classification
);
2037 //homotypic synonym of childTaxon1
2038 IBotanicalName botSpecies4
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
2039 botSpecies4
.setTitleCache("Hieracium gueri DC.", true);
2040 botSpecies4
.setGenusOrUninomial("Hieracium");
2041 botSpecies4
.setSpecificEpithet("gueri");
2042 botSpecies4
.setCombinationAuthorship(deCandolle
);
2043 botSpecies4
.setUuid(SYNONYM_NAME_UUID
);
2044 Synonym homoSynonym
= Synonym
.NewInstance(botSpecies4
, sec
);
2046 childTaxon
.addSynonym(homoSynonym
, SynonymType
.HOMOTYPIC_SYNONYM_OF());
2047 service
.saveOrUpdate(childTaxon
);
2049 //2nd child species taxon that is the child of genus taxon
2050 IBotanicalName botSpecies2
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
2051 botSpecies2
.setTitleCache("Hieracium wolffii Zahn", true);
2052 botSpecies2
.setGenusOrUninomial("Hieracium");
2053 botSpecies2
.setSpecificEpithet("wolffii");
2054 botSpecies2
.setCombinationAuthorship(Person
.NewInstance());
2055 botSpecies2
.getCombinationAuthorship().setNomenclaturalTitle("Zahn");
2056 botSpecies2
.setUuid(SPECIES2_NAME_UUID
);
2057 Taxon childTaxon2
= Taxon
.NewInstance(botSpecies2
, sec
);
2058 childTaxon2
.setUuid(SPECIES2_UUID
);
2059 classification
.addParentChild(genusTaxon
, childTaxon2
, citationRef
, "499");
2060 //childTaxon2.setTaxonomicParent(genusTaxon, citationRef, "499");
2061 service
.saveOrUpdate(childTaxon2
);
2062 //heterotypic synonym of childTaxon2
2063 IBotanicalName botSpecies3
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
2064 botSpecies3
.setTitleCache("Hieracium lupium DC.", true);
2065 botSpecies3
.setGenusOrUninomial("Hieracium");
2066 botSpecies3
.setSpecificEpithet("lupium");
2067 botSpecies3
.setCombinationAuthorship(deCandolle
);
2068 botSpecies3
.setUuid(SYNONYM2_NAME_UUID
);
2069 Synonym heteroSynonym
= Synonym
.NewInstance(botSpecies3
, sec
);
2070 heteroSynonym
.setUuid(SYNONYM2_UUID
);
2071 childTaxon2
.addSynonym(heteroSynonym
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
2072 service
.saveOrUpdate(childTaxon2
);
2073 //missaplied Name for childTaxon2
2074 IBotanicalName missName
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
2075 missName
.setTitleCache("Hieracium lupium DC.", true);
2076 missName
.setGenusOrUninomial("Hieracium");
2077 missName
.setSpecificEpithet("lupium");
2078 missName
.setCombinationAuthorship(deCandolle
);
2079 missName
.setUuid(SPECIES5_NAME_UUID
);
2080 Taxon misappliedNameTaxon
= Taxon
.NewInstance(missName
, sec
);
2081 childTaxon2
.addMisappliedName(misappliedNameTaxon
, citationRef
, "125");
2082 taxDesc
= getTestDescription(descrIndex
++);
2083 // taxDesc.setUuid(DESCRIPTION2_UUID);
2084 genusTaxon
.addDescription(taxDesc
);
2085 service
.saveOrUpdate(genusTaxon
);
2086 service
.save(misappliedNameTaxon
);
2091 public TaxonDescription
getTestDescription(int index
){
2092 TaxonDescription taxonDescription
= TaxonDescription
.NewInstance();
2093 Language language
= Language
.DEFAULT();
2094 //taxonDescription.setId(index);
2097 TextData textData
= TextData
.NewInstance();
2098 String descriptionText
= "this is a desciption for a taxon";
2099 LanguageString languageString
= LanguageString
.NewInstance(descriptionText
, language
);
2100 textData
.putText(languageString
);
2101 taxonDescription
.addElement(textData
);
2105 String commonNameString
= "Schönveilchen";
2106 CommonTaxonName commonName
= CommonTaxonName
.NewInstance(commonNameString
, language
);
2107 taxonDescription
.addElement(commonName
);
2109 return taxonDescription
;
2112 public Classification
getTestClassification(String name
){
2113 return Classification
.NewInstance(name
);