Project

General

Profile

Revision 47cbcb0f

ID47cbcb0fbb606563f53552ddbca87cece78dd1f4
Parent 52594f55
Child 6ef55556

Added by Katja Luther almost 4 years ago

add test for cdmLight export

View differences:

cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/cdmLight/out/CdmLightExportTest.java
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.File;
14
import java.io.FileNotFoundException;
15
import java.io.IOException;
16
import java.io.InputStreamReader;
17
import java.nio.charset.Charset;
18
import java.util.HashSet;
19
import java.util.Map;
20
import java.util.Set;
21
import java.util.UUID;
22

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

  
58
/**
59
 * @author k.luther
60
 * @date 17.01.2018
61
 *
62
 */
63
public class CdmLightExportTest extends CdmTransactionalIntegrationTest{
64

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

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

  
71
        @SpringBeanByType
72
        private IClassificationService classificationService;
73

  
74
        @SpringBeanByType
75
        private ITermService termService;
76

  
77
        @SpringBeanByType
78
        private ITaxonNodeService taxonNodeService;
79

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

  
98

  
99

  
100

  
101
        @Test
102
        @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/BlankDataSet.xml")
103
        public void testSubTree(){
104

  
105

  
106
            CdmLightExportConfigurator config = new CdmLightExportConfigurator(null);
107
            config.setTaxonNodeFilter(TaxonNodeFilter.NewSubtreeInstance(UUID.fromString("f8c9933a-fe3a-42ce-8a92-000e27bfdfac")));
108

  
109
            config.setTarget(TARGET.EXPORT_DATA);
110
            ExportResult result = defaultExport.invoke(config);
111
            System.out.println(result.createReport());
112
            ExportDataWrapper<?> exportData = result.getExportData();
113
            @SuppressWarnings("unchecked")
114
            Map<String, byte[]> data = (Map<String, byte[]>) exportData.getExportData();
115
            for (String key : data.keySet()){
116

  
117
                byte[] byt = data.get(key);
118
                System.out.print(key + ": " + new String(byt) );
119

  
120
            }
121

  
122

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

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

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

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

  
149
            byte[] scientificName = data.get(CdmLightExportTable.SCIENTIFIC_NAME.getTableName());
150
            String scientificNameString = new String(scientificName);
151
            Assert.assertNotNull("Scientific Name table must not be null", scientificName);
152
            expected ="\"3483cc5e-4c77-4c80-8cb0-73d43df31ee3\",\"\",\"Subspecies\",\"43\",\"Genus species subsp. subspec Mill.\",\"Genus species subsp. subspec\",\"Genus\",\"\",\"\",\"species\",\"subsp.\",\"subspec\",\"\",\"\",\"\",";
153
            Assert.assertTrue(scientificNameString.contains(expected));
154
            expected ="\"Book\",\"The book of botany\",\"Mill., The book of botany 3. 1804\",\"Mill.\",\"Mill.\",\"3:22\",\"3\",\"22\",\"1804\",\"1804\",\"\",\"\",\"\",\"\"";
155
            Assert.assertTrue(scientificNameString.contains(expected));
156

  
157
            byte[] homotypicGroup = data.get(CdmLightExportTable.HOMOTYPIC_GROUP.getTableName());
158
            String homotypicGroupString = new String(homotypicGroup);
159
            Assert.assertNotNull("Reference table must not be null", homotypicGroup);
160
            expected ="\"Genus species subsp. subspec Mill.\",\"\"";
161
            Assert.assertTrue(homotypicGroupString.contains(expected));
162

  
163

  
164
            config.setTaxonNodeFilter(TaxonNodeFilter.NewSubtreeInstance(UUID.fromString("5ed27f4a-6c7f-4372-bc5d-3b67636abc52")));
165

  
166
            config.setTarget(TARGET.EXPORT_DATA);
167
            result = defaultExport.invoke(config);
168
            System.out.println(result.createReport());
169
            exportData = result.getExportData();
170

  
171
            data = (Map<String, byte[]>) exportData.getExportData();
172
            for (String key : data.keySet()){
173

  
174
                byte[] byt = data.get(key);
175
                System.out.print(key + ": " + new String(byt) );
176

  
177
            }
178

  
179
        }
180

  
181
        @Test
182
        @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/BlankDataSet.xml")
183
        public void testFullData(){
184

  
185
            File destinationFolder = null;
186
            CdmLightExportConfigurator config = new CdmLightExportConfigurator(null);
187
            config.setTarget(TARGET.EXPORT_DATA);
188

  
189
            ExportResult result = defaultExport.invoke(config);
190
           System.out.println(result.createReport());
191
            ExportDataWrapper<?> exportData = result.getExportData();
192
            @SuppressWarnings("unchecked")
193
            Map<String, byte[]> data = (Map<String, byte[]>) exportData.getExportData();
194
            for (String key : data.keySet()){
195
                byte[] byt = data.get(key);
196
                System.out.println(key + ": " + new String(byt) );
197
            }
198
            ByteArrayInputStream stream = new ByteArrayInputStream( data.get(CdmLightExportTable.TAXON.getTableName()));
199
            BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
200
            String line;
201
            int count = 0;
202
            try {
203
                while ((line = reader.readLine()) != null) {
204
                    count ++;
205
                }
206
                Assert.assertTrue("There should be 4 taxa", count == 5);// 5 because of the header line
207

  
208
                stream = new ByteArrayInputStream(data.get(CdmLightExportTable.REFERENCE.getTableName()));
209
                reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
210
                count = 0;
211
                while ((line = reader.readLine()) != null) {
212
                    count ++;
213
                }
214
                Assert.assertTrue("There should be 4 references", count == 5);
215

  
216
            } catch (IOException e) {
217
                // TODO Auto-generated catch block
218
                e.printStackTrace();
219
            }
220
//            System.out.println();
221
            //metadata
222
//            byte[] metadata = data.get(DwcaTaxExportFile.METADATA.getTableName());
223
//            Assert.assertNotNull("Metadata must not be null", metadata);
224
//            String metaDataStr = new String(metadata);
225
//            String metaHeader = "<?xml version=\"1.0\" ?><archive xmlns=\"http://rs.tdwg.org/dwc/text/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd\">";
226
//            Assert.assertTrue(metaDataStr.contains(metaHeader));
227
//
228
//            String metaCore = "<core encoding=\"UTF-8\" linesTerminatedBy=\"\r\n\" fieldsEnclosedBy=\"&quot;\""
229
//                    + " fieldsTerminatedBy=\",\" ignoreHeaderLines=\"1\" rowType=\"http://rs.tdwg.org/dwc/terms/Taxon\">"
230
//                    + "<files><location>coreTax.txt</location></files><id index=\"0\"></id><field index=\"1\" term=\"http://rs.tdwg.org/dwc/terms/scientificNameID\"></field><field index=\"2\" term=\"http://rs.tdwg.org/dwc/terms/acceptedNameUsageID\"></field><field index=\"3\" term=\"http://rs.tdwg.org/dwc/terms/parentNameUsageID\"></field><field index=\"4\" term=\"http://rs.tdwg.org/dwc/terms/scientificName\"></field><field index=\"5\" term=\"http://rs.tdwg.org/dwc/terms/taxonRank\"></field>"
231
//                    + "<field index=\"6\" term=\"http://rs.tdwg.org/dwc/terms/taxonomicStatus\"></field><field index=\"7\" term=\"http://rs.tdwg.org/dwc/terms/originalNameUsageID\"></field>"
232
//                    + "<field index=\"8\" term=\"http://rs.tdwg.org/dwc/terms/nameAccordingToID\"></field>"
233
//                    + "<field index=\"9\" term=\"http://rs.tdwg.org/dwc/terms/namePublishedInID\"></field><field index=\"10\" term=\"http://rs.tdwg.org/dwc/terms/taxonConceptID\"></field><field index=\"11\" term=\"http://rs.tdwg.org/dwc/terms/acceptedNameUsage\"></field><field index=\"12\" term=\"http://rs.tdwg.org/dwc/terms/parentNameUsage\"></field><field index=\"13\" term=\"http://rs.tdwg.org/dwc/terms/originalNameUsage\"></field><field index=\"14\" term=\"http://rs.tdwg.org/dwc/terms/nameAccordingTo\"></field>"
234
//                    + "<field index=\"15\" term=\"http://rs.tdwg.org/dwc/terms/namePublishedIn\"></field>"
235
//
236
//                    + "<field index=\"16\" term=\"http://rs.tdwg.org/dwc/terms/higherClassification\"></field><field index=\"17\" term=\"http://rs.tdwg.org/dwc/terms/kingdom\"></field><field index=\"18\" term=\"http://rs.tdwg.org/dwc/terms/phylum\"></field><field index=\"19\" term=\"http://rs.tdwg.org/dwc/terms/class\"></field><field index=\"20\" term=\"http://rs.tdwg.org/dwc/terms/order\"></field><field index=\"21\" term=\"http://rs.tdwg.org/dwc/terms/family\"></field><field index=\"22\" term=\"http://rs.tdwg.org/dwc/terms/genus\"></field><field index=\"23\" term=\"http://rs.tdwg.org/dwc/terms/subgenus\"></field>"
237
//                    + "<field index=\"24\" term=\"http://rs.tdwg.org/ontology/voc/TaxonName#uninomial\"></field>"
238
//                    + "<field index=\"25\" term=\"http://rs.tdwg.org/ontology/voc/TaxonName#genusPart\"></field><field index=\"26\" term=\"http://rs.tdwg.org/ontology/voc/TaxonName#infragenericEpithet\"></field><field index=\"27\" term=\"http://rs.tdwg.org/dwc/terms/specificEpithet\"></field><field index=\"28\" term=\"http://rs.tdwg.org/dwc/terms/infraspecificEpithet\"></field><field index=\"29\" term=\"http://rs.tdwg.org/dwc/terms/verbatimTaxonRank\"></field><field index=\"30\" term=\"http://rs.tdwg.org/dwc/terms/vernacularName\"></field>"
239
//
240
//                    + "<field index=\"31\" term=\"http://rs.tdwg.org/dwc/terms/nomenclaturalCode\"></field><field index=\"32\" term=\"http://rs.tdwg.org/dwc/terms/nomenclaturalStatus\"></field><field index=\"33\" term=\"http://rs.tdwg.org/dwc/terms/taxonRemarks\"></field><field index=\"34\" term=\"http://purl.org/dc/terms/modified\"></field>"
241
//                    + "<field index=\"35\" term=\"http://purl.org/dc/terms/language\"></field><field index=\"36\" term=\"http://purl.org/dc/terms/rights\"></field><field index=\"37\" term=\"http://purl.org/dc/terms/rightsHolder\"></field><field index=\"38\" term=\"http://purl.org/dc/terms/accessRights\"></field>"
242
//                    + "<field index=\"39\" term=\"http://purl.org/dc/terms/bibliographicCitation\"></field><field index=\"40\" term=\"http://rs.tdwg.org/dwc/terms/informationWithheld\"></field><field index=\"41\" term=\"http://rs.tdwg.org/dwc/terms/datasetName\"></field><field index=\"42\" term=\"http://purl.org/dc/terms/source\"></field></core>" +
243
//                    "";
244
//            //TODO continue
245
////            System.out.println(metaDataStr);
246
//            Assert.assertTrue(metaDataStr.contains(metaCore));
247
//
248
//            //core
249
//            byte[] core = data.get(DwcaTaxExportFile.TAXON.getTableName());
250
//            Assert.assertNotNull("Core must not be null", core);
251
//            String coreStr = new String(core);
252
//            String expected =  "\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",\"f983cc5e-4c77-4c80-8cb0-73d43df31ee9\",\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",\"3f52e136-f2e1-4f9a-9010-2f35908fbd39\",\"Genus species Mill.\",\"Species\",\"accepted\"";
253
////            System.out.println(coreStr);
254
//            Assert.assertTrue(coreStr.contains(expected));
255
//            String expectedClassification = "\"Family|Genus|Genus species\"";
256
//            Assert.assertTrue(coreStr.contains(expectedClassification));
257

  
258

  
259
            //reference
260
//            byte[] ref = data.get(DwcaTaxExportFile.REFERENCE.getTableName());
261
//            Assert.assertNotNull("Reference must not be null", ref);
262
//            String refStr = new String(ref);
263
//            expected = "\"3162e136-f2e2-4f9a-9010-3f35908fbae1\",,,,,\"My sec ref\",\"My sec ref\",,,,,,,,,";
264
////            System.out.println(refStr);
265
//            Assert.assertTrue(refStr.contains(expected));
266
//            expected = "\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",,,,,\"Mill., The book of botany 3. 1804\",,\"Mill.\",\"1804\",,,,,,,";
267
//            Assert.assertTrue(refStr.contains(expected));
268
//
269
//            //distribution
270
//            byte[] distribution = data.get(DwcaTaxExportFile.DISTRIBUTION.getTableName());
271
//            Assert.assertNotNull("Distribution must not be null", distribution);
272
//            String distributionStr = new String(distribution);
273
//            expected =  "\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",\"c204c529-d8d2-458f-b939-96f0ebd2cbe8\",\"Africa\",,,\"present\",,\"uncertain\",,,,,,";
274
//            Assert.assertTrue(distributionStr.contains(expected));
275

  
276
        }
277

  
278
        /**
279
         * {@inheritDoc}
280
         */
281
        public void createFullTestDataSet() {
282
            Set<TaxonNode> nodesToSave = new HashSet<>();
283

  
284
            Reference sec1 = ReferenceFactory.newGeneric();
285
            setUuid(sec1, "4b6acca1-959b-4790-b76e-e474a0882990");
286
            sec1.setTitle("My sec ref");
287

  
288
            Classification classification = Classification.NewInstance("DwcaExportTest Classification");
289
            setUuid(classification, "4096df99-7274-421e-8843-211b603d832e");
290

  
291
            NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
292
            TaxonName familyName = parser.parseReferencedName("Family L., Sp. Pl. 3: 22. 1752",
293
                    NomenclaturalCode.ICNAFP, Rank.FAMILY());
294
            setUuid(familyName,"e983cc5e-4c77-4c80-8cb0-73d43df31ef7");
295
            setUuid((Reference)familyName.getNomenclaturalReference(), "b0dd7f4a-0c7f-4372-bc5d-3b676363bc63");
296
            Taxon family = Taxon.NewInstance(familyName, sec1);
297
            setUuid(family,"3162e136-f2e2-4f9a-9010-3f35908fbae1");
298
            TaxonNode node1 = classification.addChildTaxon(family, sec1, "22");
299
            setUuid(node1, "0fae5ad5-ffa2-4100-bcd7-8aa9dda0aebc");
300
            nodesToSave.add(node1);
301

  
302
            TaxonName genusName = parser.parseReferencedName("Genus Humb., The book of botany 3: 22. 1804",
303
                    NomenclaturalCode.ICNAFP, Rank.GENUS());
304
            setUuid(genusName,"5e83cc5e-4c77-4d80-8cb0-73d63df35ee3");
305
            setUuid((Reference)genusName.getNomenclaturalReference(), "5ed27f4a-6c7f-4372-bc5d-3b67636abc52");
306
            Taxon genus = Taxon.NewInstance(genusName, sec1);
307
            setUuid(genus,"3f52e136-f2e1-4f9a-9010-2f35908fbd39");
308

  
309
            TaxonNode node2 = node1.addChildTaxon(genus, sec1, "33");
310
            setUuid(node2, "43ca733b-fe3a-42ce-8a92-000e27badf44");
311
            nodesToSave.add(node2);
312

  
313

  
314
            TaxonName speciesName = parser.parseReferencedName("Genus species Mill., The book of botany 3: 22. 1804",
315
                    NomenclaturalCode.ICNAFP, Rank.SPECIES());
316
            setUuid(speciesName,"f983cc5e-4c77-4c80-8cb0-73d43df31ee9");
317
            setUuid((Reference)speciesName.getNomenclaturalReference(), "a0dd7f4a-0c7f-4372-bc5d-3b676363bc0e");
318
            Taxon species = Taxon.NewInstance(speciesName, sec1);
319
            setUuid(species,"9182e136-f2e2-4f9a-9010-3f35908fb5e0");
320

  
321
            TaxonNode node3 = node2.addChildTaxon(species, sec1, "33");
322
            setUuid(node3, "a0c9733a-fe3a-42ce-8a92-000e27bfdfa3");
323
            nodesToSave.add(node3);
324

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

  
330
            Taxon subspecies = Taxon.NewInstance(subspeciesName, sec1);
331
            setUuid(subspecies, "b2c86698-500e-4efb-b9ae-6bb6e701d4bc");
332
            TaxonNode node4 = node3.addChildTaxon(subspecies, sec1, "33");
333
            setUuid(node4, "f8c9933a-fe3a-42ce-8a92-000e27bfdfac");
334
            nodesToSave.add(node4);
335

  
336
            classificationService.save(classification);
337
            taxonNodeService.save(nodesToSave);
338

  
339
            TaxonDescription description = TaxonDescription.NewInstance(species);
340

  
341
            Distribution distribution = Distribution.NewInstance(NamedArea.AFRICA(), PresenceAbsenceTerm.PRESENT());
342
            setUuid(distribution,"674e9e27-9102-4166-8626-8cb871a9a89b");
343
            description.addElement(distribution);
344

  
345
            subspecies.addDescription(description);
346
            commitAndStartNewTransaction(null);
347

  
348

  
349
        }
350

  
351
        @Override
352
        public void createTestDataSet() throws FileNotFoundException {
353
            //      try {
354
            //      writeDbUnitDataSetFile(new String[] {
355
            //              "Classification",
356
            //      }, "testAttachDnaSampleToDerivedUnit");
357
            //  } catch (FileNotFoundException e) {
358
            //      e.printStackTrace();
359
            //  }
360
        }
361

  
362

  
363
        private void setUuid(CdmBase cdmBase, String uuidStr) {
364
            cdmBase.setUuid(UUID.fromString(uuidStr));
365
        }
366

  
367

  
368

  
369
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)