2 * Copyright (C) 2013 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
.Arrays
;
18 import java
.util
.Collection
;
19 import java
.util
.HashSet
;
20 import java
.util
.Iterator
;
21 import java
.util
.List
;
23 import java
.util
.UUID
;
25 import org
.apache
.log4j
.Logger
;
26 import org
.junit
.Before
;
27 import org
.junit
.Ignore
;
28 import org
.junit
.Test
;
29 import org
.unitils
.dbunit
.annotation
.DataSet
;
30 import org
.unitils
.dbunit
.annotation
.DataSets
;
31 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
33 import eu
.etaxonomy
.cdm
.api
.service
.description
.TransmissionEngineDistribution
;
34 import eu
.etaxonomy
.cdm
.api
.service
.description
.TransmissionEngineDistribution
.AggregationMode
;
35 import eu
.etaxonomy
.cdm
.common
.JvmLimitsException
;
36 import eu
.etaxonomy
.cdm
.model
.common
.Extension
;
37 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
38 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
39 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
40 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
41 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
42 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
43 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
44 import eu
.etaxonomy
.cdm
.model
.name
.IBotanicalName
;
45 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
46 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
47 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
48 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
49 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
50 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
51 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
52 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
53 import eu
.etaxonomy
.cdm
.test
.unitils
.CleanSweepInsertLoadStrategy
;
56 * @author a.kohlbecker
60 public class TransmissionEngineDistributionTest
extends CdmTransactionalIntegrationTest
{
62 private static Logger logger
= Logger
.getLogger(TransmissionEngineDistributionTest
.class);
64 private static final UUID T_LAPSANA_UUID
= UUID
.fromString("f65d47bd-4f49-4ab1-bc4a-bc4551eaa1a8");
66 private static final UUID T_LAPSANA_COMMUNIS_UUID
= UUID
.fromString("2a5ceebb-4830-4524-b330-78461bf8cb6b");
68 private static final UUID T_LAPSANA_COMMUNIS_COMMUNIS_UUID
= UUID
.fromString("441a3c40-0c84-11de-8c30-0800200c9a66");
70 private static final UUID T_LAPSANA_COMMUNIS_ADENOPHORA_UUID
= UUID
.fromString("e4acf200-63b6-11dd-ad8b-0800200c9a66");
72 private static final UUID T_LAPSANA_COMMUNIS_ALPINA_UUID
= UUID
.fromString("596b1325-be50-4b0a-9aa2-3ecd610215f2");
74 private static final UUID CLASSIFICATION_UUID
= UUID
.fromString("4b266053-a841-4980-b548-3f21d8d7d712");
78 private ITermService termService
;
81 private ITaxonService taxonService
;
84 private IClassificationService classificationService
;
87 private IReferenceService referenceService
;
90 private TransmissionEngineDistribution engine
;
92 // --- Distributions --- //
93 // tdwg3 level YUG : Yugoslavia
94 // contains tdwg4 level areas :
95 // YUG-BH Bosnia-Herzegovina
100 private NamedArea yug
= null;
101 private NamedArea yug_bh
= null;
102 private NamedArea yug_cr
= null;
103 private NamedArea yug_ko
= null;
104 private NamedArea yug_ma
= null;
105 private NamedArea yug_mn
= null;
107 List
<NamedArea
> superAreas
= null;
108 Rank upperRank
= null;
109 Rank lowerRank
= null;
111 private Classification classification
;
113 private Reference book_a
= null;
114 private Reference book_b
= null;
118 public void setUp() {
120 superAreas
= Arrays
.asList(new NamedArea
[]{
121 termService
.getAreaByTdwgAbbreviation("YUG")
123 lowerRank
= Rank
.SUBSPECIES();
124 upperRank
= Rank
.GENUS();
126 classification
= classificationService
.load(CLASSIFICATION_UUID
);
128 yug
= termService
.getAreaByTdwgAbbreviation("YUG");
129 yug_bh
= termService
.getAreaByTdwgAbbreviation("YUG-BH");
130 yug_cr
= termService
.getAreaByTdwgAbbreviation("YUG-CR");
131 yug_ko
= termService
.getAreaByTdwgAbbreviation("YUG-KO");
132 yug_ma
= termService
.getAreaByTdwgAbbreviation("YUG-MA");
133 yug_mn
= termService
.getAreaByTdwgAbbreviation("YUG-MN");
135 book_a
= ReferenceFactory
.newBook();
136 book_a
.setTitle("book_a");
137 book_b
= ReferenceFactory
.newBook();
138 book_b
.setTitle("book_a");
140 engine
.setBatchMinFreeHeap(100 * 1024 * 1024);
141 engine
.updatePriorities();
146 public void testPriorities(){
148 Set
<Extension
> extensions
= termService
.load(PresenceAbsenceTerm
.CULTIVATED().getUuid()).getExtensions();
149 assertEquals(TransmissionEngineDistribution
.EXTENSION_VALUE_PREFIX
+ "45", extensions
.iterator().next().getValue());
154 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
155 @DataSet(value
="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml"),
156 @DataSet(value
="TransmissionEngineDistributionTest.xml"),
158 // @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class) //, value="./BlankDataSet.xml")
159 public void test_ignore() throws JvmLimitsException
{
162 T_LAPSANA_COMMUNIS_ALPINA_UUID
,
163 Arrays
.asList(new Distribution
[] {
164 // should succeed during area aggregation be ignored by rank aggregation
165 // => yug will get status ENDEMIC_FOR_THE_RELEVANT_AREA
166 // but only for LAPSANA_COMMUNIS_ALPINA
167 Distribution
.NewInstance(yug_mn
, PresenceAbsenceTerm
.ENDEMIC_FOR_THE_RELEVANT_AREA()),
168 // should be ignored by area aggregation
169 // => LAPSANA_COMMUNIS will wave distribution with yug_ko and INTRODUCED_FORMERLY_INTRODUCED
170 Distribution
.NewInstance(yug_ko
, PresenceAbsenceTerm
.INTRODUCED_FORMERLY_INTRODUCED()),
174 engine
.accumulate(AggregationMode
.byAreasAndRanks
, superAreas
, lowerRank
, upperRank
, null, null);
176 Taxon lapsana_communis_alpina
= (Taxon
) taxonService
.load(T_LAPSANA_COMMUNIS_ALPINA_UUID
);
177 assertEquals(2, lapsana_communis_alpina
.getDescriptions().size());
178 // TODO test for yug => ENDEMIC_FOR_THE_RELEVANT_AREA in computed description
180 Taxon lapsana_communis
= (Taxon
) taxonService
.load(T_LAPSANA_COMMUNIS_UUID
);
181 assertEquals(1, lapsana_communis
.getDescriptions().size());
182 TaxonDescription description
= lapsana_communis
.getDescriptions().iterator().next();
183 assertEquals(1, description
.getElements().size());
184 int numExpectedFound
= 0;
185 for (DescriptionElementBase element
: description
.getElements()){
186 Distribution distribution
= (Distribution
)element
;
187 if(distribution
.getArea().equals(yug_ko
)){
189 assertEquals("aggregated status of area YUG-KO wrong", PresenceAbsenceTerm
.INTRODUCED_FORMERLY_INTRODUCED().getLabel(), distribution
.getStatus().getLabel());
192 assertEquals("All three expected areas should have been found before", numExpectedFound
, 1);
197 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
198 @DataSet(value
="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml"),
199 @DataSet(value
="TransmissionEngineDistributionTest.xml"),
201 public void testArea_area() throws JvmLimitsException
{
203 Set
<Distribution
> distributions_LCA
= new HashSet
<>();
205 distributions_LCA
.add(newDistribution(book_a
, yug_mn
, PresenceAbsenceTerm
.CULTIVATED(), "1"));
206 distributions_LCA
.add(newDistribution(book_a
, yug_ko
, PresenceAbsenceTerm
.NATIVE(), "2")); // NATIVE should succeed
207 distributions_LCA
.add(newDistribution(book_a
, yug_bh
, PresenceAbsenceTerm
.INTRODUCED(), "3"));
208 distributions_LCA
.add(newDistribution(book_a
, yug_ma
, PresenceAbsenceTerm
.NATIVE(), "4")); // NATIVE should succeed
211 T_LAPSANA_COMMUNIS_ALPINA_UUID
,
215 Taxon lapsana_communis_alpina
= (Taxon
) taxonService
.load(T_LAPSANA_COMMUNIS_ALPINA_UUID
);
216 assertEquals(1, lapsana_communis_alpina
.getDescriptions().size());
218 engine
.accumulate(AggregationMode
.byAreas
, superAreas
, lowerRank
, upperRank
, classification
, null);
220 lapsana_communis_alpina
= (Taxon
) taxonService
.load(T_LAPSANA_COMMUNIS_ALPINA_UUID
);
221 assertEquals(2, lapsana_communis_alpina
.getDescriptions().size());
223 Distribution accumulatedDistribution
= null;
224 for (TaxonDescription description
: lapsana_communis_alpina
.getDescriptions()) {
225 if(description
.hasMarker(MarkerType
.COMPUTED(), true)) {
226 assertNull("only one computed Distribution should exists", accumulatedDistribution
);
227 assertEquals("the computed Decsription should have only one element", 1, description
.getElements().size());
228 accumulatedDistribution
= (Distribution
) description
.getElements().iterator().next();
229 assertEquals("Expecting area to be YUG", yug
, accumulatedDistribution
.getArea());
230 assertEquals("Expecting status to be NATIVE", PresenceAbsenceTerm
.NATIVE().getLabel(), accumulatedDistribution
.getStatus().getLabel());
233 assertNotNull("The area YUG should have been found", accumulatedDistribution
);
234 assertEquals("Expecting two source references", 2, accumulatedDistribution
.getSources().size());
235 Iterator
<DescriptionElementSource
> sourceIt
= accumulatedDistribution
.getSources().iterator();
236 // should contain source_LCA_yug_ma and source_LCA_yug_ko, testing the microreference which is unique in the tests
237 assertTrue(" 2 4 ".contains(" " + sourceIt
.next().getCitationMicroReference() + " "));
238 assertTrue(" 2 4 ".contains(" " + sourceIt
.next().getCitationMicroReference() + " "));
243 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
244 @DataSet(value
="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml"),
245 @DataSet(value
="TransmissionEngineDistributionTest.xml"),
247 public void testArea_rank_and_area_1() throws JvmLimitsException
{
249 Set
<Distribution
> distributions_LCA
= new HashSet
<>();
250 distributions_LCA
.add(newDistribution(book_a
, yug_mn
, PresenceAbsenceTerm
.CULTIVATED(), "1"));
251 distributions_LCA
.add(newDistribution(book_a
, yug_ko
, PresenceAbsenceTerm
.NATIVE(), "2")); // NATIVE should succeed
254 T_LAPSANA_COMMUNIS_ALPINA_UUID
,
258 Set
<Distribution
> distributions_LC
= new HashSet
<>();
259 distributions_LC
.add(newDistribution(book_a
, yug_mn
, PresenceAbsenceTerm
.CULTIVATED(), "3"));
260 distributions_LC
.add(newDistribution(book_a
, yug_ko
, PresenceAbsenceTerm
.NATIVE(), "4")); // NATIVE should succeed
262 commitAndStartNewTransaction(null);
265 T_LAPSANA_COMMUNIS_UUID
,
269 engine
.accumulate(AggregationMode
.byAreasAndRanks
, superAreas
, lowerRank
, upperRank
, null, null);
271 Taxon lapsana_communis
= (Taxon
) taxonService
.load(T_LAPSANA_COMMUNIS_UUID
);
272 assertEquals("Lapsana communis alpina must only have 2 Descriptions", 2, lapsana_communis
.getDescriptions().size());
274 Taxon lapsana
= (Taxon
) taxonService
.load(T_LAPSANA_UUID
);
275 assertEquals("Lapsana communis must only have 1 Description", 1, lapsana
.getDescriptions().size());
276 TaxonDescription description
= lapsana
.getDescriptions().iterator().next();
277 assertTrue(description
.hasMarker(MarkerType
.COMPUTED(), true));
278 assertEquals(3, description
.getElements().size());
279 int numExpectedFound
= 0;
280 for (DescriptionElementBase element
: description
.getElements()){
281 Distribution distribution
= (Distribution
)element
;
282 if(distribution
.getArea().equals(yug
)){
284 assertEquals("aggregated status of area YUG is wrong", PresenceAbsenceTerm
.NATIVE().getLabel(), distribution
.getStatus().getLabel());
285 assertEquals(2, distribution
.getSources().size());
286 Iterator
<DescriptionElementSource
> sourceIt
= distribution
.getSources().iterator();
287 // should contain source_LCA_yug_ma and source_LCA_yug_ko, testing the microreference which is unique in the tests
288 assertTrue(" 2 4 ".contains(" " + sourceIt
.next().getCitationMicroReference() + " "));
289 assertTrue(" 2 4 ".contains(" " + sourceIt
.next().getCitationMicroReference() + " "));
291 if(distribution
.getArea().equals(yug_mn
)){
293 assertEquals("aggregated status of area YUG-MN is wrong", PresenceAbsenceTerm
.CULTIVATED().getLabel(), distribution
.getStatus().getLabel());
294 assertEquals(2, distribution
.getSources().size());
295 Iterator
<DescriptionElementSource
> sourceIt
= distribution
.getSources().iterator();
296 // should contain source_LCA_yug_ma and source_LCA_yug_ko, testing the microreference which is unique in the tests
297 assertTrue(" 1 3 ".contains(" " + sourceIt
.next().getCitationMicroReference() + " "));
298 assertTrue(" 1 3 ".contains(" " + sourceIt
.next().getCitationMicroReference() + " "));
300 if(distribution
.getArea().equals(yug_ko
)){
302 assertEquals("aggregated status of area YUG-KO wrong", PresenceAbsenceTerm
.NATIVE().getLabel(), distribution
.getStatus().getLabel());
303 assertEquals(2, distribution
.getSources().size());
304 Iterator
<DescriptionElementSource
> sourceIt
= distribution
.getSources().iterator();
305 // should contain source_LCA_yug_ma and source_LCA_yug_ko, testing the microreference which is unique in the tests
306 assertTrue(" 2 4 ".contains(" " + sourceIt
.next().getCitationMicroReference() + " "));
307 assertTrue(" 2 4 ".contains(" " + sourceIt
.next().getCitationMicroReference() + " "));
310 assertEquals("All three expected areas should have been found before", numExpectedFound
, 3);
314 * Variant of {@link #testArea_rank_and_area_1()} with alternate source references to check the
315 * suppression of duplicates.
317 * This test relies on {@link #testArea_rank_and_area_1()}
318 * an makes assertions only on the alternative source references
319 * @throws JvmLimitsException
323 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
324 @DataSet(value
="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml"),
325 @DataSet(value
="TransmissionEngineDistributionTest.xml"),
327 public void testArea_rank_and_area_2() throws JvmLimitsException
{
329 Set
<Distribution
> distributions_LCA
= new HashSet
<Distribution
>();
330 distributions_LCA
.add(newDistribution(book_a
, yug_ko
, PresenceAbsenceTerm
.NATIVE(), "1"));
331 distributions_LCA
.add(newDistribution(book_b
, yug_ko
, PresenceAbsenceTerm
.NATIVE(), "2"));
334 T_LAPSANA_COMMUNIS_ALPINA_UUID
,
338 engine
.accumulate(AggregationMode
.byAreasAndRanks
, superAreas
, lowerRank
, upperRank
, null, null);
340 Taxon lapsana_communis
= (Taxon
) taxonService
.load(T_LAPSANA_COMMUNIS_UUID
);
341 int computedDescriptionsCnt
= 0;
342 for(TaxonDescription description
: lapsana_communis
.getDescriptions()) {
343 if(description
.hasMarker(MarkerType
.COMPUTED(), true)) {
344 computedDescriptionsCnt
++;
345 assertEquals(2, description
.getElements().size()); // yug, yug_ko
346 for(DescriptionElementBase distribution
: description
.getElements()) {
347 logger
.debug(((Distribution
)distribution
).getArea() + " " + sourcesToString(distribution
));
348 if(((Distribution
)distribution
).getArea().equals(yug_ko
)){
349 assertEquals(2, distribution
.getSources().size());
351 if(((Distribution
)distribution
).getArea().equals(yug
)){
352 assertEquals(2, distribution
.getSources().size());
357 assertEquals(1, computedDescriptionsCnt
);
362 * Variant of {@link #testArea_rank_and_area_1()} with alternate source references to check the
363 * suppression of duplicates.
365 * This test relies on {@link #testArea_rank_and_area_1()}
366 * an makes assertions only on the alternative source references
367 * @throws JvmLimitsException
371 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
372 @DataSet(value
="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml"),
373 @DataSet(value
="TransmissionEngineDistributionTest.xml"),
375 public void testArea_rank_and_area_3() throws JvmLimitsException
{
377 Set
<Distribution
> distributions_LCA
= new HashSet
<Distribution
>();
378 distributions_LCA
.add(newDistribution(book_a
, yug_ko
, PresenceAbsenceTerm
.NATIVE(), "1"));
379 distributions_LCA
.add(newDistribution(book_a
, yug_ko
, PresenceAbsenceTerm
.NATIVE(), "3"));
382 T_LAPSANA_COMMUNIS_ALPINA_UUID
,
386 Set
<Distribution
> distributions_LC
= new HashSet
<>();
387 distributions_LC
.add(newDistribution(book_a
, yug_ko
, PresenceAbsenceTerm
.NATIVE(), "1"));
388 distributions_LC
.add(newDistribution(book_b
, yug_ko
, PresenceAbsenceTerm
.NATIVE(), "2"));
391 T_LAPSANA_COMMUNIS_UUID
,
395 engine
.accumulate(AggregationMode
.byAreasAndRanks
, superAreas
, lowerRank
, upperRank
, null, null);
397 Taxon lapsana_communis
= (Taxon
) taxonService
.load(T_LAPSANA_COMMUNIS_UUID
);
398 int computedDescriptionsCnt
= 0;
399 for(TaxonDescription description
: lapsana_communis
.getDescriptions()) {
400 if(description
.hasMarker(MarkerType
.COMPUTED(), true)) {
401 computedDescriptionsCnt
++;
402 assertEquals(2, description
.getElements().size());
403 for(DescriptionElementBase distribution
: description
.getElements()) {
404 logger
.debug(((Distribution
)distribution
).getArea() + " " + sourcesToString(distribution
));
405 if(((Distribution
)distribution
).getArea().equals(yug_ko
)){
406 assertEquals(2, distribution
.getSources().size());
408 if(((Distribution
)distribution
).getArea().equals(yug
)){
409 assertEquals(3, distribution
.getSources().size());
414 assertEquals(1, computedDescriptionsCnt
);
418 * Variant of {@link #testArea_rank_and_area_1()} with alternate source references to
419 * check the handling of the case where the target taxon already has the distribution which is the
420 * result of the aggregation (see http://dev.e-taxonomy.eu/trac/ticket/4366#comment:12)
422 * This test relies on {@link #testArea_rank_and_area_1()}
423 * an makes assertions only on the alternative source references
424 * @throws JvmLimitsException
429 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
430 @DataSet(value
="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml"),
431 @DataSet(value
="TransmissionEngineDistributionTest.xml"),
433 public void testArea_rank_and_area_4() throws JvmLimitsException
{
435 Set
<Distribution
> distributions_LCA
= new HashSet
<>();
436 distributions_LCA
.add(newDistribution(book_a
, yug_ko
, PresenceAbsenceTerm
.NATIVE(), "1"));
439 T_LAPSANA_COMMUNIS_ALPINA_UUID
,
443 Set
<Distribution
> distributions_LC
= new HashSet
<>();
444 distributions_LC
.add(newDistribution(book_a
, yug
, PresenceAbsenceTerm
.NATIVE(), "2")); // should succeed
447 T_LAPSANA_COMMUNIS_UUID
,
451 engine
.accumulate(AggregationMode
.byAreasAndRanks
, superAreas
, lowerRank
, upperRank
, null, null);
453 Taxon lapsana_communis
= (Taxon
) taxonService
.load(T_LAPSANA_COMMUNIS_UUID
);
454 int computedDescriptionsCnt
= 0;
455 for(TaxonDescription description
: lapsana_communis
.getDescriptions()) {
456 if(description
.hasMarker(MarkerType
.COMPUTED(), true)) {
457 computedDescriptionsCnt
++;
458 assertEquals(2, description
.getElements().size());
459 Distribution distribution
= (Distribution
)description
.getElements().iterator().next();
460 if(distribution
.getArea().equals(yug_ko
)){
461 assertEquals(2, distribution
.getSources().size());
462 DescriptionElementSource source
= distribution
.getSources().iterator().next();
463 assertEquals("2", source
.getCitationMicroReference());
467 assertEquals(1, computedDescriptionsCnt
);
471 * @param referenceTitle
474 * @param microCitation
477 private Distribution
newDistribution(Reference reference
, NamedArea area
, PresenceAbsenceTerm status
,
478 String microCitation
) {
479 DescriptionElementSource source
= DescriptionElementSource
.NewPrimarySourceInstance(reference
, microCitation
);
480 Distribution distribution
= Distribution
.NewInstance(area
, status
);
481 distribution
.getSources().add(source
);
486 * creates a new description for the taxon identified by the UUIDs
488 * @param distributions
490 private void addDistributions(UUID taxonUuid
, Collection
<Distribution
> distributions
) {
491 Taxon taxon
= (Taxon
) taxonService
.load(taxonUuid
);
493 throw new NullPointerException("No taxon found for " + taxonUuid
);
495 TaxonDescription description
= TaxonDescription
.NewInstance(taxon
);
497 for (Distribution distribution
: distributions
) {
498 description
.addElement(distribution
);
500 taxonService
.saveOrUpdate(taxon
);
501 // need to write to database for transmission engine
502 commitAndStartNewTransaction(null);
505 private String
sourcesToString(DescriptionElementBase deb
) {
506 StringBuffer out
= new StringBuffer();
507 for ( DescriptionElementSource source
: deb
.getSources()) {
508 out
.append(source
.getCitation().getTitle() + " : " + source
.getCitationMicroReference() + ", ");
510 return out
.toString();
514 //@Test // uncomment to create test data file//
516 public void createTestDataSet() throws FileNotFoundException
{
518 // --- References --- //
519 Reference sec
= ReferenceFactory
.newDatabase();
520 sec
.setTitleCache("Test", true);
521 Reference nomRef
= ReferenceFactory
.newBook();
522 sec
.setTitleCache("Sp.Pl.", true);
524 referenceService
.save(sec
);
525 referenceService
.save(nomRef
);
531 // L. communis subsp. communis
532 // L. communis subsp. adenophora
533 // L. communis subsp. alpina
537 IBotanicalName n_lapsana
= TaxonNameFactory
.NewBotanicalInstance(Rank
.GENUS());
538 n_lapsana
.setTitleCache("Lapsana", true);
539 Taxon t_lapsana
= Taxon
.NewInstance(n_lapsana
, sec
);
540 t_lapsana
.setUuid(T_LAPSANA_UUID
);
541 taxonService
.saveOrUpdate(t_lapsana
);
543 IBotanicalName n_lapsana_communis
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
544 n_lapsana_communis
.setTitleCache("L. communis", true);
545 Taxon t_lapsana_communis
= Taxon
.NewInstance(n_lapsana_communis
, sec
);
546 t_lapsana_communis
.setUuid(T_LAPSANA_COMMUNIS_UUID
);
547 taxonService
.saveOrUpdate(t_lapsana_communis
);
549 IBotanicalName n_lapsana_communis_communis
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SUBSPECIES());
550 n_lapsana_communis_communis
.setTitleCache("L. communis subsp. communis", true);
551 Taxon t_lapsana_communis_communis
= Taxon
.NewInstance(n_lapsana_communis_communis
, sec
);
552 t_lapsana_communis_communis
.setUuid(T_LAPSANA_COMMUNIS_COMMUNIS_UUID
);
553 taxonService
.saveOrUpdate(t_lapsana_communis_communis
);
555 IBotanicalName n_lapsana_communis_adenophora
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SUBSPECIES());
556 n_lapsana_communis_adenophora
.setTitleCache("L. communis subsp. adenophora", true);
557 Taxon t_lapsana_communis_adenophora
= Taxon
.NewInstance(n_lapsana_communis_adenophora
, sec
);
558 t_lapsana_communis_adenophora
.setUuid(T_LAPSANA_COMMUNIS_ADENOPHORA_UUID
);
559 taxonService
.saveOrUpdate(t_lapsana_communis_adenophora
);
561 IBotanicalName n_lapsana_communis_alpina
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SUBSPECIES());
562 n_lapsana_communis_alpina
.setTitleCache("L. communis subsp. alpina", true);
563 Taxon t_lapsana_communis_alpina
= Taxon
.NewInstance(n_lapsana_communis_alpina
, sec
);
564 t_lapsana_communis_alpina
.setUuid(T_LAPSANA_COMMUNIS_ALPINA_UUID
);
565 taxonService
.saveOrUpdate(t_lapsana_communis_alpina
);
567 // --- Classification --- //
568 Classification classification
= Classification
.NewInstance("TestClassification");
569 classification
.setUuid(CLASSIFICATION_UUID
);
570 classificationService
.save(classification
);
571 TaxonNode node_lapsana
= classification
.addChildTaxon(t_lapsana
, sec
, null);
572 TaxonNode node_lapsana_communis
= node_lapsana
.addChildTaxon(t_lapsana_communis
, sec
, null);
573 node_lapsana_communis
.addChildTaxon(t_lapsana_communis_communis
, sec
, null);
574 node_lapsana_communis
.addChildTaxon(t_lapsana_communis_adenophora
, sec
, null);
575 node_lapsana_communis
.addChildTaxon(t_lapsana_communis_alpina
, sec
, null);
576 classificationService
.saveOrUpdate(classification
);
578 // --- Distributions --- //
579 // tdwg3 level YUG : Yugoslavia
580 // contains tdwg4 level areas :
581 // YUG-BH Bosnia-Herzegovina
587 // assigning distribution information to taxa
588 // expectations regarding the aggregation can be found in the comments below
589 // TaxonDescription d_lapsana_communis_communis = TaxonDescription.NewInstance(t_lapsana_communis_communis);
590 // d_lapsana_communis_communis.addElement(Distribution.NewInstance(
591 // TdwgArea.getAreaByTdwgAbbreviation("YUG-MN"),
592 // PresenceTerm.ENDEMIC_FOR_THE_RELEVANT_AREA() // should be ignored
595 commitAndStartNewTransaction(null);
597 writeDbUnitDataSetFile(new String
[] {
598 "TAXONBASE", "TAXONNAME",
599 "REFERENCE", "DESCRIPTIONELEMENTBASE", "DESCRIPTIONBASE",
600 "AGENTBASE", "CLASSIFICATION", "TAXONNODE",
601 "HOMOTYPICALGROUP", "LANGUAGESTRING",
602 "HIBERNATE_SEQUENCES"