Project

General

Profile

Download (24 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;import org.apache.logging.log4j.Logger;
23
import org.junit.Assert;
24
import org.junit.Before;
25
import org.junit.Test;
26
import org.unitils.dbunit.annotation.DataSet;
27
import org.unitils.dbunit.annotation.DataSets;
28
import org.unitils.spring.annotation.SpringBeanByName;
29
import org.unitils.spring.annotation.SpringBeanByType;
30

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

    
60
/**
61
 * @author k.luther
62
 * @since 17.01.2018
63
 */
64
public class CdmLightExportTest extends CdmTransactionalIntegrationTest{
65

    
66
        @SuppressWarnings("unused")
67
        private static final Logger logger = LogManager.getLogger(CdmLightExportTest.class);
68

    
69
        @SpringBeanByName
70
        private CdmApplicationAwareDefaultExport<CdmLightExportConfigurator> defaultExport;
71

    
72
        @SpringBeanByType
73
        private IClassificationService classificationService;
74

    
75
        @SpringBeanByType
76
        private ITermService termService;
77

    
78
        @SpringBeanByType
79
        private ITaxonNodeService taxonNodeService;
80

    
81
        @SpringBeanByType
82
        private ICommonService commonService;
83

    
84
        @Before
85
        public void setUp()  {
86
//            DefinedTerm ipniIdentifierTerm = DefinedTerm.NewIdentifierTypeInstance("IPNI Identifier", "IPNI Identifier", "IPNI Identifier");
87
//            ipniIdentifierTerm.setUuid(DefinedTerm.uuidIpniNameIdentifier);
88
//
89
//            DefinedTerm tropicosIdentifierTerm = DefinedTerm.NewIdentifierTypeInstance("Tropicos Identifier", "Tropicos Identifier", "Tropicos Identifier");
90
//            tropicosIdentifierTerm.setUuid(DefinedTerm.uuidTropicosNameIdentifier);
91
//
92
//            DefinedTerm wfoIdentifierTerm = DefinedTerm.NewIdentifierTypeInstance("WFO Identifier", "WFO Identifier", "WFO Identifier");
93
//            wfoIdentifierTerm.setUuid(DefinedTerm.uuidWfoNameIdentifier);
94
//            List<DefinedTermBase> terms = new ArrayList();
95
//            terms.add(wfoIdentifierTerm);
96
//            terms.add(tropicosIdentifierTerm);
97
//            terms.add(ipniIdentifierTerm);
98
//            termService.saveOrUpdate(terms);
99
            createFullTestDataSet();
100
        }
101

    
102
        @Test
103
        @DataSets({
104
            @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
105
            @DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
106
        })
107
        public void testSubTree(){
108

    
109
            CdmLightExportConfigurator config = CdmLightExportConfigurator.NewInstance();
110
//            config.setCreateCondensedDistributionString(false);
111
            config.setTaxonNodeFilter(TaxonNodeFilter.NewSubtreeInstance(UUID.fromString("f8c9933a-fe3a-42ce-8a92-000e27bfdfac")));
112

    
113
            config.setTarget(TARGET.EXPORT_DATA);
114
            ExportResult result = defaultExport.invoke(config);
115
            ExportDataWrapper<?> exportData = result.getExportData();
116
            testExceptionsErrorsWarnings(result);
117

    
118
            @SuppressWarnings("unchecked")
119
            Map<String, byte[]> data = (Map<String, byte[]>) exportData.getExportData();
120

    
121
            byte[] taxon = data.get(CdmLightExportTable.TAXON.getTableName());
122
            Assert.assertNotNull("Taxon table must not be null", taxon);
123
            String taxonStr = new String(taxon);
124
            String notExpected =  "\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\"";
125
            Assert.assertFalse("Result must not contain root taxon", taxonStr.startsWith(notExpected));
126
            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\"";
127
            Assert.assertTrue(taxonStr.contains(expected));
128

    
129
            byte[] reference = data.get(CdmLightExportTable.REFERENCE.getTableName());
130
            String referenceString = new String(reference);
131
            Assert.assertNotNull("Reference table must not be null", reference);
132
            expected ="\"b8dd7f4a-0c7f-4372-bc5d-3b676363bc0f\",\"Mill. (1804)\",\"\",\"The book of botany\",\"1804\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"3\",\"1804\",\"Mill.\"";
133
            Assert.assertTrue(referenceString.contains(expected));
134

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

    
141
            byte[] nomenclaturalAuthor = data.get(CdmLightExportTable.NOMENCLATURAL_AUTHOR.getTableName());
142
            String nomenclaturalAuthorString = new String(nomenclaturalAuthor);
143
            Assert.assertNotNull("Nomenclatural Author table must not be null", nomenclaturalAuthor);
144
            expected ="\"Mill.\",\"Mill.\",\"\",\"\",\"\",\"\"";
145
            Assert.assertTrue(nomenclaturalAuthorString.contains(expected));
146

    
147
            byte[] scientificName = data.get(CdmLightExportTable.SCIENTIFIC_NAME.getTableName());
148
            String scientificNameString = new String(scientificName);
149
            Assert.assertNotNull("Scientific Name table must not be null", scientificName);
150
            expected ="\"3483cc5e-4c77-4c80-8cb0-73d43df31ee3\",\"\",\"Subspecies\",\"43\",\"Genus species subsp. subspec Mill.\",\"Genus species subsp. subspec\",\"Genus\",\"\",\"\",\"species\",\"subsp.\",\"subspec\",\"\",\"\",\"\",";
151
            Assert.assertTrue(scientificNameString.contains(expected));
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
                Assert.assertTrue(scientificNameString.contains(expected));
155
            }
156

    
157
            expected ="\"Book\",\"The book of botany\",\"The book of botany\",\"Mill.\",\"Mill.\",\"3:22\",\"3\",\"22\",\"1804\",\"1804\",\"\",\"\",\"\",\"\"";
158
            Assert.assertTrue(scientificNameString.contains(expected));
159

    
160
            byte[] homotypicGroup = data.get(CdmLightExportTable.HOMOTYPIC_GROUP.getTableName());
161
            String homotypicGroupString = new String(homotypicGroup);
162
            Assert.assertNotNull("Reference table must not be null", homotypicGroup);
163
            if (config.isAddHTML()){
164
                expected ="\"= <i>Genus</i> <i>species</i> subsp. <i>subspec</i> Mill., The book of botany 3: 22. 1804\",\"\"";
165
            }else{
166
                expected ="\"= Genus species subsp. subspec Mill., The book of botany 3: 22. 1804\",\"\"";
167
            }
168
            Assert.assertTrue(homotypicGroupString.contains(expected));
169
        }
170

    
171
        @Test
172
        @DataSets({
173
            @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
174
            @DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
175
        })
176
        public void testFullTreeWithUnpublished(){
177

    
178
            CdmLightExportConfigurator config = CdmLightExportConfigurator.NewInstance();
179
            config.setTarget(TARGET.EXPORT_DATA);
180
            config.getTaxonNodeFilter().setIncludeUnpublished(true);
181

    
182
            ExportResult result = defaultExport.invoke(config);
183
            testExceptionsErrorsWarnings(result);
184
            ExportDataWrapper<?> exportData = result.getExportData();
185
            @SuppressWarnings("unchecked")
186
            Map<String, byte[]> data = (Map<String, byte[]>) exportData.getExportData();
187

    
188
            ByteArrayInputStream stream = new ByteArrayInputStream( data.get(CdmLightExportTable.TAXON.getTableName()));
189
            BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
190
            String line;
191
            int count = 0;
192
            try {
193
                while ((line = reader.readLine()) != null) {
194
                    count ++;
195
                }
196
                Assert.assertTrue("There should be 5 taxa", count == 6);// 6 because of the header line
197

    
198
                stream = new ByteArrayInputStream(data.get(CdmLightExportTable.REFERENCE.getTableName()));
199
                reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
200
                count = 0;
201
                while ((line = reader.readLine()) != null) {
202
                    count ++;
203
                }
204
                Assert.assertTrue("There should be 7 references (6 nomenclatural references and 1 sec reference)", count == 8);
205
                stream = new ByteArrayInputStream(data.get(CdmLightExportTable.SYNONYM.getTableName()));
206
                reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
207
                count = 0;
208
                while ((line = reader.readLine()) != null) {
209
                    count ++;
210
                }
211
                Assert.assertTrue("There should be 1 synonym", count == 2);
212
            } catch (IOException e) {
213
                e.printStackTrace();
214
                Assert.fail("IO Exception thrown during test.");
215
            }
216
            byte[] taxon = data.get(CdmLightExportTable.TAXON.getTableName());
217
            Assert.assertNotNull("Taxon table must not be null", taxon);
218
            String taxonStr = new String(taxon);
219
            String notExpected =  "\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\"";
220
            Assert.assertFalse("Result must not contain root taxon", taxonStr.startsWith(notExpected));
221
            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\"";
222
            Assert.assertTrue(taxonStr.contains(expected));
223

    
224
            byte[] reference = data.get(CdmLightExportTable.REFERENCE.getTableName());
225
            String referenceString = new String(reference);
226
            Assert.assertNotNull("Reference table must not be null", reference);
227
            expected ="\"b8dd7f4a-0c7f-4372-bc5d-3b676363bc0f\",\"Mill. (1804)\",\"\",\"The book of botany\",\"1804\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"3\",\"1804\",\"Mill.\"";
228
            Assert.assertTrue(referenceString.contains(expected));
229

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

    
236
            byte[] nomenclaturalAuthor = data.get(CdmLightExportTable.NOMENCLATURAL_AUTHOR.getTableName());
237
            String nomenclaturalAuthorString = new String(nomenclaturalAuthor);
238
            Assert.assertNotNull("Nomenclatural Author table must not be null", nomenclaturalAuthor);
239
            expected ="\"Mill.\",\"Mill.\",\"\",\"\",\"\",\"\"";
240
            Assert.assertTrue(nomenclaturalAuthorString.contains(expected));
241

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

    
250
            byte[] homotypicGroup = data.get(CdmLightExportTable.HOMOTYPIC_GROUP.getTableName());
251
            String homotypicGroupString = new String(homotypicGroup);
252
            Assert.assertNotNull("Reference table must not be null", homotypicGroup);
253
            if (config.isAddHTML()){
254
                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\",\"\",\"\"";
255
            }else{
256
                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\",\"\",\"\"";
257
            }
258
            Assert.assertTrue(homotypicGroupString.contains(expected));
259
        }
260

    
261
        @Test
262
        @DataSets({
263
            @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
264
            @DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
265
        })
266
        public void testFullData(){
267

    
268
            CdmLightExportConfigurator config = CdmLightExportConfigurator.NewInstance();
269
            config.setTarget(TARGET.EXPORT_DATA);
270

    
271
            ExportResult result = defaultExport.invoke(config);
272
            testExceptionsErrorsWarnings(result);
273

    
274
            ExportDataWrapper<?> exportData = result.getExportData();
275
            @SuppressWarnings("unchecked")
276
            Map<String, byte[]> data = (Map<String, byte[]>) exportData.getExportData();
277

    
278
            ByteArrayInputStream stream = new ByteArrayInputStream( data.get(CdmLightExportTable.TAXON.getTableName()));
279
            BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
280
            String line;
281
            int count = 0;
282
            try {
283
                while ((line = reader.readLine()) != null) {
284
                    count ++;
285
                }
286
                Assert.assertTrue("There should be 4 taxa", count == 5);// 5 because of the header line
287

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

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

    
318
        @Test
319
        @DataSets({
320
            @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
321
            @DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
322
        })
323
        public void testFullSampleData(){
324

    
325
            commonService.createFullSampleData();
326
            commitAndStartNewTransaction();
327

    
328

    
329
            CdmLightExportConfigurator config = CdmLightExportConfigurator.NewInstance();
330
            config.setTarget(TARGET.EXPORT_DATA);
331

    
332
            ExportResult result = defaultExport.invoke(config);
333
            testExceptionsErrorsWarnings(result);
334
        }
335

    
336
        private void testExceptionsErrorsWarnings(ExportResult result) {
337
            Assert.assertTrue(result.getExceptions().size() == 0);
338
            Assert.assertTrue(result.getErrors().size() == 0);
339
            Assert.assertTrue(result.getWarnings().size() == 0);
340
        }
341

    
342
        public void createFullTestDataSet() {
343
            Set<TaxonNode> nodesToSave = new HashSet<>();
344

    
345
            Reference sec1 = ReferenceFactory.newGeneric();
346
            setUuid(sec1, "4b6acca1-959b-4790-b76e-e474a0882990");
347
            sec1.setTitle("My sec ref");
348

    
349
            Classification classification = Classification.NewInstance("CdmLightExportTest Classification");
350
            setUuid(classification, "4096df99-7274-421e-8843-211b603d832e");
351

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

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

    
370
            TaxonNode node2 = node1.addChildTaxon(genus, sec1, "33");
371
            setUuid(node2, "43ca733b-fe3a-42ce-8a92-000e27badf44");
372
            nodesToSave.add(node2);
373

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

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

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

    
396
            Taxon subspecies = Taxon.NewInstance(subspeciesName, sec1);
397
            setUuid(subspecies, "b2c86698-500e-4efb-b9ae-6bb6e701d4bc");
398
            TaxonNode node4 = node3.addChildTaxon(subspecies, sec1, "33");
399
            setUuid(node4, "f8c9933a-fe3a-42ce-8a92-000e27bfdfac");
400
            nodesToSave.add(node4);
401

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

    
406
            Taxon subspeciesUnpublished = Taxon.NewInstance(subspeciesNameUnpublished, sec1);
407
            setUuid(subspeciesUnpublished, "290e295a-9089-4616-a30c-15ded79e064f");
408
            subspeciesUnpublished.setPublish(false);
409
            TaxonNode node5 = node3.addChildTaxon(subspeciesUnpublished, sec1, "33");
410
            setUuid(node5, "81d9c9b2-c8fd-4d4f-a0b4-e7e656dcdc20");
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
            //      try {
433
            //      writeDbUnitDataSetFile(new String[] {
434
            //              "Classification",
435
            //      }, "testAttachDnaSampleToDerivedUnit");
436
            //  } catch (FileNotFoundException e) {
437
            //      e.printStackTrace();
438
            //  }
439
        }
440
}
    (1-1/1)