Project

General

Profile

Download (23.5 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.cdm.io.cdmLight.out;
10

    
11
import java.io.BufferedReader;
12
import java.io.ByteArrayInputStream;
13
import java.io.FileNotFoundException;
14
import java.io.IOException;
15
import java.io.InputStreamReader;
16
import java.nio.charset.Charset;
17
import java.util.HashSet;
18
import java.util.Map;
19
import java.util.Set;
20
import java.util.UUID;
21

    
22
import org.apache.logging.log4j.LogManager;
23
import org.apache.logging.log4j.Logger;
24
import org.junit.Assert;
25
import org.junit.Before;
26
import org.junit.Test;
27
import org.unitils.dbunit.annotation.DataSet;
28
import org.unitils.dbunit.annotation.DataSets;
29
import org.unitils.spring.annotation.SpringBeanByName;
30
import org.unitils.spring.annotation.SpringBeanByType;
31

    
32
import eu.etaxonomy.cdm.api.service.IClassificationService;
33
import eu.etaxonomy.cdm.api.service.ICommonService;
34
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
35
import eu.etaxonomy.cdm.api.service.ITermService;
36
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
37
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
38
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportTable;
39
import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultExport;
40
import eu.etaxonomy.cdm.io.common.ExportDataWrapper;
41
import eu.etaxonomy.cdm.io.common.ExportResult;
42
import eu.etaxonomy.cdm.io.common.IExportConfigurator.TARGET;
43
import eu.etaxonomy.cdm.model.common.CdmBase;
44
import eu.etaxonomy.cdm.model.common.Language;
45
import eu.etaxonomy.cdm.model.description.Distribution;
46
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
47
import eu.etaxonomy.cdm.model.description.TaxonDescription;
48
import eu.etaxonomy.cdm.model.location.NamedArea;
49
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
50
import eu.etaxonomy.cdm.model.name.Rank;
51
import eu.etaxonomy.cdm.model.name.TaxonName;
52
import eu.etaxonomy.cdm.model.reference.Reference;
53
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
54
import eu.etaxonomy.cdm.model.taxon.Classification;
55
import eu.etaxonomy.cdm.model.taxon.Synonym;
56
import eu.etaxonomy.cdm.model.taxon.Taxon;
57
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
58
import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
59
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
60
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
61
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
62

    
63
/**
64
 * @author k.luther
65
 * @since 17.01.2018
66
 */
67
public class CdmLightExportTest extends CdmTransactionalIntegrationTest{
68

    
69
        @SuppressWarnings("unused")
70
        private static final Logger logger = LogManager.getLogger(CdmLightExportTest.class);
71

    
72
        @SpringBeanByName
73
        private CdmApplicationAwareDefaultExport<CdmLightExportConfigurator> defaultExport;
74

    
75
        @SpringBeanByType
76
        private IClassificationService classificationService;
77

    
78
        @SpringBeanByType
79
        private ITermService termService;
80

    
81
        @SpringBeanByType
82
        private ITaxonNodeService taxonNodeService;
83

    
84
        @SpringBeanByType
85
        private ICommonService commonService;
86

    
87
        @Before
88
        public void setUp()  {
89
            createFullTestDataSet();
90
        }
91

    
92
        @Test
93
        @DataSets({
94
            @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
95
            @DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
96
        })
97
        public void testSubTree(){
98

    
99
            CdmLightExportConfigurator config = CdmLightExportConfigurator.NewInstance();
100
            config.setTaxonNodeFilter(TaxonNodeFilter.NewSubtreeInstance(UUID.fromString("f8c9933a-fe3a-42ce-8a92-000e27bfdfac")));
101

    
102
            config.setTarget(TARGET.EXPORT_DATA);
103
            ExportResult result = defaultExport.invoke(config);
104
            ExportDataWrapper<?> exportData = result.getExportData();
105
            testExceptionsErrorsWarnings(result);
106

    
107
            @SuppressWarnings("unchecked")
108
            Map<String, byte[]> data = (Map<String, byte[]>) exportData.getExportData();
109

    
110
            byte[] taxonByte = data.get(CdmLightExportTable.TAXON.getTableName());
111
            Assert.assertNotNull("Taxon table must not be null", taxonByte);
112
            String taxonStr = new String(taxonByte);
113
            String notExpected = "\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\"";
114
            Assert.assertFalse("Result must not contain root taxon", taxonStr.startsWith(notExpected));
115
            String expected = "\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"4096df99-7274-421e-8843-211b603d832e\",\"CdmLightExportTest Classification\",\"3483cc5e-4c77-4c80-8cb0-73d43df31ee3\",\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",\"4b6acca1-959b-4790-b76e-e474a0882990\",\"My sec ref\"";
116
            Assert.assertTrue(taxonStr.contains(expected));
117

    
118
            byte[] reference = data.get(CdmLightExportTable.REFERENCE.getTableName());
119
            String referenceString = new String(reference);
120
            Assert.assertNotNull("Reference table must not be null", reference);
121
            expected ="\"b8dd7f4a-0c7f-4372-bc5d-3b676363bc0f\",\"Mill. (1804)\",\"\",\"The book of botany\",\"1804\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"3\",\"1804\",\"Mill.\"";
122
            Assert.assertTrue(referenceString.contains(expected));
123

    
124
            byte[] geographicAreaFact = data.get(CdmLightExportTable.GEOGRAPHIC_AREA_FACT.getTableName());
125
            String geographicAreaFactString = new String(geographicAreaFact);
126
            Assert.assertNotNull("Geographical fact table must not be null", geographicAreaFact);
127
            expected ="\"674e9e27-9102-4166-8626-8cb871a9a89b\",\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"Africa\",\"present\"";
128
            Assert.assertTrue(geographicAreaFactString.contains(expected));
129

    
130
            byte[] nomenclaturalAuthor = data.get(CdmLightExportTable.NOMENCLATURAL_AUTHOR.getTableName());
131
            String nomenclaturalAuthorString = new String(nomenclaturalAuthor);
132
            Assert.assertNotNull("Nomenclatural Author table must not be null", nomenclaturalAuthor);
133
            expected ="\"Mill.\",\"Mill.\",\"\",\"\",\"\",\"\"";
134
            Assert.assertTrue(nomenclaturalAuthorString.contains(expected));
135

    
136
            byte[] scientificName = data.get(CdmLightExportTable.SCIENTIFIC_NAME.getTableName());
137
            String scientificNameString = new String(scientificName);
138
            Assert.assertNotNull("Scientific Name table must not be null", scientificName);
139
            expected ="\"3483cc5e-4c77-4c80-8cb0-73d43df31ee3\",\"\",\"Subspecies\",\"43\",\"Genus species subsp. subspec Mill.\",\"Genus species subsp. subspec\",\"Genus\",\"\",\"\",\"species\",\"subsp.\",\"subspec\",\"\",\"\",\"\",";
140
            Assert.assertTrue(scientificNameString.contains(expected));
141
            if (config.isAddHTML()){
142
                expected = "\"<i>Genus</i> <i>species</i> subsp. <i>subspec</i> Mill., The book of botany 3: 22. 1804\"";
143
                Assert.assertTrue(scientificNameString.contains(expected));
144
            }
145

    
146
            expected ="\"Book\",\"The book of botany\",\"The book of botany\",\"Mill.\",\"Mill.\",\"3:22\",\"3\",\"22\",\"1804\",\"1804\",\"\",\"\",\"\",\"\"";
147
            Assert.assertTrue(scientificNameString.contains(expected));
148

    
149
            byte[] homotypicGroup = data.get(CdmLightExportTable.HOMOTYPIC_GROUP.getTableName());
150
            String homotypicGroupString = new String(homotypicGroup);
151
            Assert.assertNotNull("Reference table must not be null", homotypicGroup);
152
            if (config.isAddHTML()){
153
                expected ="\"= <i>Genus</i> <i>species</i> subsp. <i>subspec</i> Mill., The book of botany 3: 22. 1804\",\"\"";
154
            }else{
155
                expected ="\"= Genus species subsp. subspec Mill., The book of botany 3: 22. 1804\",\"\"";
156
            }
157
            Assert.assertTrue(homotypicGroupString.contains(expected));
158
        }
159

    
160
        @Test
161
        @DataSets({
162
            @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
163
            @DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
164
        })
165
        public void testFullTreeWithUnpublished(){
166

    
167
            CdmLightExportConfigurator config = CdmLightExportConfigurator.NewInstance();
168
            config.setTarget(TARGET.EXPORT_DATA);
169
            config.getTaxonNodeFilter().setIncludeUnpublished(true);
170

    
171
            ExportResult result = defaultExport.invoke(config);
172
            testExceptionsErrorsWarnings(result);
173
            ExportDataWrapper<?> exportData = result.getExportData();
174
            @SuppressWarnings("unchecked")
175
            Map<String, byte[]> data = (Map<String, byte[]>) exportData.getExportData();
176

    
177
            ByteArrayInputStream stream = new ByteArrayInputStream( data.get(CdmLightExportTable.TAXON.getTableName()));
178
            BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
179

    
180
            int count = 0;
181
            try {
182
                while (reader.readLine() != null) {
183
                    count ++;
184
                }
185
                Assert.assertTrue("There should be 5 taxa", count == 5+1);// 1 header line
186

    
187
                stream = new ByteArrayInputStream(data.get(CdmLightExportTable.REFERENCE.getTableName()));
188
                reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
189
                count = 0;
190
                while (reader.readLine() != null) {
191
                    count ++;
192
                }
193
                Assert.assertTrue("There should be 7 references (6 nomenclatural references and 1 sec reference)", count == 7+1);  //1 header line
194
                stream = new ByteArrayInputStream(data.get(CdmLightExportTable.SYNONYM.getTableName()));
195
                reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
196
                count = 0;
197
                while (reader.readLine() != null) {
198
                    count ++;
199
                }
200
                Assert.assertTrue("There should be 1 synonym", count == 1+1);  // 1 header line
201
            } catch (IOException e) {
202
                e.printStackTrace();
203
                Assert.fail("IO Exception thrown during test.");
204
            }
205
            byte[] taxonByte = data.get(CdmLightExportTable.TAXON.getTableName());
206
            Assert.assertNotNull("Taxon table must not be null", taxonByte);
207
            String taxonStr = new String(taxonByte);
208
            String notExpected = "\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\"";
209
            Assert.assertFalse("Result must not contain root taxon", taxonStr.startsWith(notExpected));
210
            String expected = "\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"4096df99-7274-421e-8843-211b603d832e\",\"CdmLightExportTest Classification\",\"3483cc5e-4c77-4c80-8cb0-73d43df31ee3\",\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",\"4b6acca1-959b-4790-b76e-e474a0882990\",\"My sec ref\"";
211
            Assert.assertTrue(taxonStr.contains(expected));
212
            String expectedExcluded = "\"1\",\"My status note [My sec ref: 27]\"";
213
            Assert.assertTrue(taxonStr.contains(expectedExcluded));
214
            String expectedSecNameUsedInSource = "\"My sec ref\",\"3483cc5e-4c77-4c80-8cb0-73d43df31ee3\",\"Genus species subsp. subspec\",\"Mill.\";";
215
            Assert.assertTrue(taxonStr.contains(expectedSecNameUsedInSource));
216

    
217
            byte[] reference = data.get(CdmLightExportTable.REFERENCE.getTableName());
218
            String referenceString = new String(reference);
219
            Assert.assertNotNull("Reference table must not be null", reference);
220
            expected ="\"b8dd7f4a-0c7f-4372-bc5d-3b676363bc0f\",\"Mill. (1804)\",\"\",\"The book of botany\",\"1804\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"3\",\"1804\",\"Mill.\"";
221
            Assert.assertTrue(referenceString.contains(expected));
222

    
223
            byte[] geographicAreaFact = data.get(CdmLightExportTable.GEOGRAPHIC_AREA_FACT.getTableName());
224
            String geographicAreaFactString = new String(geographicAreaFact);
225
            Assert.assertNotNull("Geographical fact table must not be null", geographicAreaFact);
226
            expected ="\"674e9e27-9102-4166-8626-8cb871a9a89b\",\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"Africa\",\"present\"";
227
            Assert.assertTrue(geographicAreaFactString.contains(expected));
228

    
229
            byte[] nomenclaturalAuthor = data.get(CdmLightExportTable.NOMENCLATURAL_AUTHOR.getTableName());
230
            String nomenclaturalAuthorString = new String(nomenclaturalAuthor);
231
            Assert.assertNotNull("Nomenclatural Author table must not be null", nomenclaturalAuthor);
232
            expected ="\"Mill.\",\"Mill.\",\"\",\"\",\"\",\"\"";
233
            Assert.assertTrue(nomenclaturalAuthorString.contains(expected));
234

    
235
            byte[] scientificName = data.get(CdmLightExportTable.SCIENTIFIC_NAME.getTableName());
236
            String scientificNameString = new String(scientificName);
237
            Assert.assertNotNull("Scientific Name table must not be null", scientificName);
238
            expected ="\"3483cc5e-4c77-4c80-8cb0-73d43df31ee3\",\"\",\"Subspecies\",\"43\",\"Genus species subsp. subspec Mill.\",\"Genus species subsp. subspec\",\"Genus\",\"\",\"\",\"species\",\"subsp.\",\"subspec\",\"\",\"\",\"\",";
239
            Assert.assertTrue(scientificNameString.contains(expected));
240
            expected ="\"Book\",\"The book of botany\",\"The book of botany\",\"Mill.\",\"Mill.\",\"3:22\",\"3\",\"22\",\"1804\",\"1804\",\"\",\"\",\"\",\"\"";
241
            Assert.assertTrue(scientificNameString.contains(expected));
242

    
243
            byte[] homotypicGroup = data.get(CdmLightExportTable.HOMOTYPIC_GROUP.getTableName());
244
            String homotypicGroupString = new String(homotypicGroup);
245
            Assert.assertNotNull("Reference table must not be null", homotypicGroup);
246
            if (config.isAddHTML()){
247
                expected ="\"= <i>Genus</i> <i>species</i> subsp. <i>subspec</i> Mill., The book of botany 3: 22. 1804\",\"\",\"\",\"= <i>Genus</i> <i>species</i> subsp. <i>subspec</i> Mill., The book of botany 3: 22. 1804 My sec ref\",\"\",\"\"";
248
            }else{
249
                expected ="\"= Genus species subsp. subspec Mill., The book of botany 3: 22. (1804)\",\"\",\"\",\"= Genus species subsp. subspec Mill., The book of botany 3: 22. (1804) My sec ref\",\"\",\"\"";
250
            }
251
            Assert.assertTrue(homotypicGroupString.contains(expected));
252
        }
253

    
254
        @Test
255
        @DataSets({
256
            @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
257
            @DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
258
        })
259
        public void testFullData(){
260

    
261
            CdmLightExportConfigurator config = CdmLightExportConfigurator.NewInstance();
262
            config.setTarget(TARGET.EXPORT_DATA);
263

    
264
            ExportResult result = defaultExport.invoke(config);
265
            testExceptionsErrorsWarnings(result);
266

    
267
            ExportDataWrapper<?> exportData = result.getExportData();
268
            @SuppressWarnings("unchecked")
269
            Map<String, byte[]> data = (Map<String, byte[]>) exportData.getExportData();
270

    
271
            ByteArrayInputStream stream = new ByteArrayInputStream( data.get(CdmLightExportTable.TAXON.getTableName()));
272
            BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
273
            String line;
274
            int count = 0;
275
            try {
276
                while ((line = reader.readLine()) != null) {
277
                    count ++;
278
                }
279
                Assert.assertTrue("There should be 4 taxa", count == 5);// 5 because of the header line
280

    
281
                stream = new ByteArrayInputStream(data.get(CdmLightExportTable.REFERENCE.getTableName()));
282
                reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
283
                count = 0;
284
                while ((line = reader.readLine()) != null) {
285
                    count ++;
286
                }
287
                Assert.assertTrue("There should be 5 references", count == 6);
288
                try{
289
                    stream = new ByteArrayInputStream(data.get(CdmLightExportTable.SYNONYM.getTableName()));
290
                    // now there are always all tables also if empty
291
                    reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
292

    
293
                    boolean dummyLine = true;
294
                    count = 0;
295
                    while ((line = reader.readLine()) != null) {
296
                        if (!(line.startsWith("\"DUMMY") || line.startsWith("\"Synonym_ID"))){
297
                            dummyLine = dummyLine && false;
298
                        }
299
                        count++;
300
                    }
301
                    Assert.assertTrue("There should be 0 synomyms", dummyLine && count == 3);
302
//                    Assert.fail("There should not be a synonym table, because the only synonym is not public.");
303
                }catch(NullPointerException e){
304
                    //OK, should be thrown
305
                }
306
            } catch (IOException e) {
307
                throw new RuntimeException(e);
308
            }
309
        }
310

    
311
        @Test
312
        @DataSets({
313
            @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
314
            @DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
315
        })
316
        public void testFullSampleData(){
317

    
318
            commonService.createFullSampleData();
319
            commitAndStartNewTransaction();
320

    
321

    
322
            CdmLightExportConfigurator config = CdmLightExportConfigurator.NewInstance();
323
            config.setTarget(TARGET.EXPORT_DATA);
324

    
325
            ExportResult result = defaultExport.invoke(config);
326
            testExceptionsErrorsWarnings(result);
327
        }
328

    
329
        private void testExceptionsErrorsWarnings(ExportResult result) {
330
            Assert.assertTrue(result.getExceptions().size() == 0);
331
            Assert.assertTrue(result.getErrors().size() == 0);
332
            Assert.assertTrue(result.getWarnings().size() == 0);
333
        }
334

    
335
        public void createFullTestDataSet() {
336

    
337
            Set<TaxonNode> nodesToSave = new HashSet<>();
338

    
339
            Reference sec1 = ReferenceFactory.newGeneric();
340
            setUuid(sec1, "4b6acca1-959b-4790-b76e-e474a0882990");
341
            sec1.setTitle("My sec ref");
342

    
343
            Classification classification = Classification.NewInstance("CdmLightExportTest Classification");
344
            setUuid(classification, "4096df99-7274-421e-8843-211b603d832e");
345

    
346
            NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
347
            TaxonName familyName = parser.parseReferencedName("Family L., Sp. Pl. 3: 22. 1752",
348
                    NomenclaturalCode.ICNAFP, Rank.FAMILY());
349
            setUuid(familyName,"e983cc5e-4c77-4c80-8cb0-73d43df31ef7");
350
            setUuid(familyName.getNomenclaturalReference(), "b0dd7f4a-0c7f-4372-bc5d-3b676363bc63");
351
            Taxon family = Taxon.NewInstance(familyName, sec1);
352
            setUuid(family,"3162e136-f2e2-4f9a-9010-3f35908fbae1");
353
            TaxonNode node1 = classification.addChildTaxon(family, sec1, "22");
354
            setUuid(node1, "0fae5ad5-ffa2-4100-bcd7-8aa9dda0aebc");
355
            nodesToSave.add(node1);
356

    
357
            TaxonName genusName = parser.parseReferencedName("Genus Humb., The book of botany 3: 22. 1804",
358
                    NomenclaturalCode.ICNAFP, Rank.GENUS());
359
            setUuid(genusName,"5e83cc5e-4c77-4d80-8cb0-73d63df35ee3");
360
            setUuid(genusName.getNomenclaturalReference(), "5ed27f4a-6c7f-4372-bc5d-3b67636abc52");
361
            Taxon genus = Taxon.NewInstance(genusName, sec1);
362
            setUuid(genus,"3f52e136-f2e1-4f9a-9010-2f35908fbd39");
363

    
364
            TaxonNode node2 = node1.addChildTaxon(genus, sec1, "33");
365
            setUuid(node2, "43ca733b-fe3a-42ce-8a92-000e27badf44");
366
            nodesToSave.add(node2);
367

    
368
            TaxonName speciesName = parser.parseReferencedName("Genus species Mill., The book of botany 3: 22. 1804",
369
                    NomenclaturalCode.ICNAFP, Rank.SPECIES());
370
            setUuid(speciesName,"f983cc5e-4c77-4c80-8cb0-73d43df31ee9");
371
            setUuid(speciesName.getNomenclaturalReference(), "a0dd7f4a-0c7f-4372-bc5d-3b676363bc0e");
372
            Taxon species = Taxon.NewInstance(speciesName, sec1);
373
            setUuid(species,"9182e136-f2e2-4f9a-9010-3f35908fb5e0");
374
            TaxonName synonymName = parser.parseReferencedName("Genus synonym Mill., The book of botany 3: 22. 1804", NomenclaturalCode.ICNAFP, Rank.SPECIES());
375

    
376
            setUuid(synonymName, "1584157b-5c43-4150-b271-95b2c99377b2");
377
            Synonym  synonymUnpublished = Synonym.NewInstance(synonymName, sec1);
378
            setUuid(synonymName, "a87c16b7-8299-4d56-a682-ce20973428ea");
379
            synonymUnpublished.setPublish(false);
380
            species.addHomotypicSynonym(synonymUnpublished);
381
            TaxonNode node3 = node2.addChildTaxon(species, sec1, "33");
382
            setUuid(node3, "a0c9733a-fe3a-42ce-8a92-000e27bfdfa3");
383
            nodesToSave.add(node3);
384

    
385
            TaxonName subspeciesName = parser.parseReferencedName("Genus species subsp. subspec Mill., The book of botany 3: 22. 1804",
386
                    NomenclaturalCode.ICNAFP, Rank.SUBSPECIES());
387
            setUuid(subspeciesName,"3483cc5e-4c77-4c80-8cb0-73d43df31ee3");
388
            setUuid(subspeciesName.getNomenclaturalReference(), "b8dd7f4a-0c7f-4372-bc5d-3b676363bc0f");
389

    
390
            Taxon subspecies = Taxon.NewInstance(subspeciesName, sec1);
391
            subspecies.getSecSource().setNameUsedInSource(subspeciesName);
392
            setUuid(subspecies, "b2c86698-500e-4efb-b9ae-6bb6e701d4bc");
393
            TaxonNode node4 = node3.addChildTaxon(subspecies, sec1, "33");
394
            setUuid(node4, "f8c9933a-fe3a-42ce-8a92-000e27bfdfac");
395
            nodesToSave.add(node4);
396

    
397
            TaxonName subspeciesNameUnpublished = parser.parseReferencedName("Genus species subsp. unpublished Mill., The book of botany 3: 22. 1804",
398
                    NomenclaturalCode.ICNAFP, Rank.SUBSPECIES());
399
            setUuid(subspeciesNameUnpublished,"b6da7ab2-6c67-44b7-9719-2557542f5a23");
400

    
401
            Taxon subspeciesUnpublished = Taxon.NewInstance(subspeciesNameUnpublished, sec1);
402
            setUuid(subspeciesUnpublished, "290e295a-9089-4616-a30c-15ded79e064f");
403
            subspeciesUnpublished.setPublish(false);
404
            TaxonNode node5 = node3.addChildTaxon(subspeciesUnpublished, sec1, "33");
405
            //excluded node
406
            setUuid(node5, "81d9c9b2-c8fd-4d4f-a0b4-e7e656dcdc20");
407
            node5.setStatus(TaxonNodeStatus.EXCLUDED);
408
            node5.setCitation(sec1);
409
            node5.setCitationMicroReference("27");
410
            node5.putStatusNote(Language.ENGLISH(), "My status note");
411
            nodesToSave.add(node5);
412

    
413
            classificationService.save(classification);
414
            taxonNodeService.save(nodesToSave);
415

    
416
            TaxonDescription description = TaxonDescription.NewInstance(species);
417

    
418
            Distribution distribution = Distribution.NewInstance(NamedArea.AFRICA(), PresenceAbsenceTerm.PRESENT());
419
            setUuid(distribution,"674e9e27-9102-4166-8626-8cb871a9a89b");
420
            description.addElement(distribution);
421

    
422
            subspecies.addDescription(description);
423
            commitAndStartNewTransaction(null);
424
        }
425

    
426
        private void setUuid(CdmBase cdmBase, String uuidStr) {
427
            cdmBase.setUuid(UUID.fromString(uuidStr));
428
        }
429

    
430
        @Override
431
        public void createTestDataSet() throws FileNotFoundException {}
432
}
    (1-1/1)