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.ArrayList;
|
18
|
import java.util.HashSet;
|
19
|
import java.util.List;
|
20
|
import java.util.Map;
|
21
|
import java.util.Set;
|
22
|
import java.util.UUID;
|
23
|
|
24
|
import org.apache.logging.log4j.LogManager;
|
25
|
import org.apache.logging.log4j.Logger;
|
26
|
import org.junit.Assert;
|
27
|
import org.junit.Before;
|
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.SpringBeanByName;
|
32
|
import org.unitils.spring.annotation.SpringBeanByType;
|
33
|
|
34
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
35
|
import eu.etaxonomy.cdm.api.service.ICommonService;
|
36
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
37
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
38
|
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
|
39
|
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
|
40
|
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportTable;
|
41
|
import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultExport;
|
42
|
import eu.etaxonomy.cdm.io.common.ExportDataWrapper;
|
43
|
import eu.etaxonomy.cdm.io.common.ExportResult;
|
44
|
import eu.etaxonomy.cdm.io.common.IExportConfigurator.TARGET;
|
45
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
46
|
import eu.etaxonomy.cdm.model.common.Language;
|
47
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
48
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
49
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
50
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
51
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
52
|
import eu.etaxonomy.cdm.model.name.Rank;
|
53
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
54
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
55
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
56
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
57
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
58
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
59
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
60
|
import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
|
61
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
62
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
63
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
64
|
|
65
|
/**
|
66
|
* @author k.luther
|
67
|
* @since 17.01.2018
|
68
|
*/
|
69
|
public class CdmLightExportTest extends CdmTransactionalIntegrationTest{
|
70
|
|
71
|
@SuppressWarnings("unused")
|
72
|
private static final Logger logger = LogManager.getLogger(CdmLightExportTest.class);
|
73
|
|
74
|
private static final UUID rootNodeUuid = UUID.fromString("a67b4efd-6148-46a9-a377-1efd14768cfa");
|
75
|
private static final UUID node1Uuid = UUID.fromString("0fae5ad5-ffa2-4100-bcd7-8aa9dda0aebc");
|
76
|
private static final UUID node2Uuid = UUID.fromString("43ca733b-fe3a-42ce-8a92-000e27badf44");
|
77
|
private static final UUID node3Uuid = UUID.fromString("a0c9733a-fe3a-42ce-8a92-000e27bfdfa3");
|
78
|
private static final UUID node4Uuid = UUID.fromString("f8c9933a-fe3a-42ce-8a92-000e27bfdfac");
|
79
|
private static final UUID node5Uuid = UUID.fromString("81d9c9b2-c8fd-4d4f-a0b4-e7e656dcdc20");
|
80
|
|
81
|
private static final UUID familyTaxonUuid = UUID.fromString("3162e136-f2e2-4f9a-9010-3f35908fbae1");
|
82
|
private static final UUID genusTaxonUuid = UUID.fromString("3f52e136-f2e1-4f9a-9010-2f35908fbd39");
|
83
|
private static final UUID speciesTaxonUuid = UUID.fromString("9182e136-f2e2-4f9a-9010-3f35908fb5e0");
|
84
|
private static final UUID subspeciesTaxonUuid = UUID.fromString("b2c86698-500e-4efb-b9ae-6bb6e701d4bc");
|
85
|
private static final UUID subspeciesUnpublishedTaxonUuid = UUID.fromString("290e295a-9089-4616-a30c-15ded79e064f");
|
86
|
|
87
|
@SpringBeanByName
|
88
|
private CdmApplicationAwareDefaultExport<CdmLightExportConfigurator> defaultExport;
|
89
|
|
90
|
@SpringBeanByType
|
91
|
private IClassificationService classificationService;
|
92
|
|
93
|
@SpringBeanByType
|
94
|
private ITermService termService;
|
95
|
|
96
|
@SpringBeanByType
|
97
|
private ITaxonNodeService taxonNodeService;
|
98
|
|
99
|
@SpringBeanByType
|
100
|
private ICommonService commonService;
|
101
|
|
102
|
@Before
|
103
|
public void setUp() {
|
104
|
createFullTestDataSet();
|
105
|
}
|
106
|
|
107
|
@Test
|
108
|
@DataSets({
|
109
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
110
|
@DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
|
111
|
})
|
112
|
public void testSubTree(){
|
113
|
|
114
|
CdmLightExportConfigurator config = CdmLightExportConfigurator.NewInstance();
|
115
|
config.setTaxonNodeFilter(TaxonNodeFilter.NewSubtreeInstance(UUID.fromString("f8c9933a-fe3a-42ce-8a92-000e27bfdfac")));
|
116
|
|
117
|
config.setTarget(TARGET.EXPORT_DATA);
|
118
|
ExportResult result = defaultExport.invoke(config);
|
119
|
ExportDataWrapper<?> exportData = result.getExportData();
|
120
|
testExceptionsErrorsWarnings(result);
|
121
|
|
122
|
@SuppressWarnings("unchecked")
|
123
|
Map<String, byte[]> data = (Map<String, byte[]>) exportData.getExportData();
|
124
|
|
125
|
byte[] taxonByte = data.get(CdmLightExportTable.TAXON.getTableName());
|
126
|
Assert.assertNotNull("Taxon table must not be null", taxonByte);
|
127
|
String taxonStr = new String(taxonByte);
|
128
|
String notExpected = "\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\"";
|
129
|
Assert.assertFalse("Result must not contain root taxon", taxonStr.startsWith(notExpected));
|
130
|
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\"";
|
131
|
Assert.assertTrue(taxonStr.contains(expected));
|
132
|
|
133
|
byte[] reference = data.get(CdmLightExportTable.REFERENCE.getTableName());
|
134
|
String referenceString = new String(reference);
|
135
|
Assert.assertNotNull("Reference table must not be null", reference);
|
136
|
expected ="\"b8dd7f4a-0c7f-4372-bc5d-3b676363bc0f\",\"Mill. (1804)\",\"\",\"The book of botany\",\"1804\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"3\",\"1804\",\"Mill.\"";
|
137
|
Assert.assertTrue(referenceString.contains(expected));
|
138
|
|
139
|
byte[] geographicAreaFact = data.get(CdmLightExportTable.GEOGRAPHIC_AREA_FACT.getTableName());
|
140
|
String geographicAreaFactString = new String(geographicAreaFact);
|
141
|
Assert.assertNotNull("Geographical fact table must not be null", geographicAreaFact);
|
142
|
expected ="\"674e9e27-9102-4166-8626-8cb871a9a89b\",\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"Africa\",\"present\"";
|
143
|
Assert.assertTrue(geographicAreaFactString.contains(expected));
|
144
|
|
145
|
byte[] nomenclaturalAuthor = data.get(CdmLightExportTable.NOMENCLATURAL_AUTHOR.getTableName());
|
146
|
String nomenclaturalAuthorString = new String(nomenclaturalAuthor);
|
147
|
Assert.assertNotNull("Nomenclatural Author table must not be null", nomenclaturalAuthor);
|
148
|
expected ="\"Mill.\",\"Mill.\",\"\",\"\",\"\",\"\"";
|
149
|
Assert.assertTrue(nomenclaturalAuthorString.contains(expected));
|
150
|
|
151
|
byte[] scientificName = data.get(CdmLightExportTable.SCIENTIFIC_NAME.getTableName());
|
152
|
String scientificNameString = new String(scientificName);
|
153
|
Assert.assertNotNull("Scientific Name table must not be null", scientificName);
|
154
|
expected ="\"3483cc5e-4c77-4c80-8cb0-73d43df31ee3\",\"\",\"Subspecies\",\"43\",\"Genus species subsp. subspec Mill.\",\"Genus species subsp. subspec\",\"Genus\",\"\",\"\",\"species\",\"subsp.\",\"subspec\",\"\",\"\",\"\",";
|
155
|
Assert.assertTrue(scientificNameString.contains(expected));
|
156
|
if (config.isAddHTML()){
|
157
|
expected = "\"<i>Genus</i> <i>species</i> subsp. <i>subspec</i> Mill., The book of botany 3: 22. 1804\"";
|
158
|
Assert.assertTrue(scientificNameString.contains(expected));
|
159
|
}
|
160
|
|
161
|
expected ="\"Book\",\"The book of botany\",\"The book of botany\",\"Mill.\",\"Mill.\",\"3:22\",\"3\",\"22\",\"1804\",\"1804\",\"\",\"\",\"\",\"\"";
|
162
|
Assert.assertTrue(scientificNameString.contains(expected));
|
163
|
|
164
|
byte[] homotypicGroup = data.get(CdmLightExportTable.HOMOTYPIC_GROUP.getTableName());
|
165
|
String homotypicGroupString = new String(homotypicGroup);
|
166
|
Assert.assertNotNull("Reference table must not be null", homotypicGroup);
|
167
|
if (config.isAddHTML()){
|
168
|
expected ="\"= <i>Genus</i> <i>species</i> subsp. <i>subspec</i> Mill., The book of botany 3: 22. 1804\",\"\"";
|
169
|
}else{
|
170
|
expected ="\"= Genus species subsp. subspec Mill., The book of botany 3: 22. 1804\",\"\"";
|
171
|
}
|
172
|
Assert.assertTrue(homotypicGroupString.contains(expected));
|
173
|
}
|
174
|
|
175
|
@Test
|
176
|
@DataSets({
|
177
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
178
|
@DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
|
179
|
})
|
180
|
public void testFullTreeWithUnpublished(){
|
181
|
|
182
|
CdmLightExportConfigurator config = CdmLightExportConfigurator.NewInstance();
|
183
|
config.setTarget(TARGET.EXPORT_DATA);
|
184
|
config.getTaxonNodeFilter().setIncludeUnpublished(true);
|
185
|
|
186
|
ExportResult result = defaultExport.invoke(config);
|
187
|
testExceptionsErrorsWarnings(result);
|
188
|
ExportDataWrapper<?> exportData = result.getExportData();
|
189
|
@SuppressWarnings("unchecked")
|
190
|
Map<String, byte[]> data = (Map<String, byte[]>) exportData.getExportData();
|
191
|
|
192
|
//test counts
|
193
|
List<String> taxonResult = getStringList(data, CdmLightExportTable.TAXON);
|
194
|
Assert.assertEquals("There should be 5 taxa", 5, taxonResult.size()-1);// 1 header line
|
195
|
|
196
|
List<String> referenceResult = getStringList(data, CdmLightExportTable.REFERENCE);
|
197
|
Assert.assertEquals("There should be 7 references (6 nomenclatural references and 1 sec reference)", 7, referenceResult.size()-1);// 1 header line
|
198
|
|
199
|
List<String> synonymResult = getStringList(data, CdmLightExportTable.SYNONYM);
|
200
|
Assert.assertEquals("There should be 1 synonym", 1, synonymResult.size()-1);// 1 header line
|
201
|
|
202
|
//test single data
|
203
|
Assert.assertEquals("Result must not contain root taxon",
|
204
|
0, taxonResult.stream().filter(line->line.contains(rootNodeUuid.toString())).count());
|
205
|
|
206
|
//subspecies
|
207
|
String subspeciesLine = getLine(taxonResult, subspeciesTaxonUuid);
|
208
|
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\"";
|
209
|
Assert.assertTrue(subspeciesLine.startsWith(expected));
|
210
|
String expectedSecNameUsedInSource = "\"My sec ref\",\"3483cc5e-4c77-4c80-8cb0-73d43df31ee3\",\"Genus species subsp. subspec\",\"Mill.\",";
|
211
|
Assert.assertTrue(subspeciesLine.contains(expectedSecNameUsedInSource));
|
212
|
|
213
|
//unpublished/excluded/note
|
214
|
String unpublishedLine = getLine(taxonResult, subspeciesUnpublishedTaxonUuid);
|
215
|
String expectedExcluded = "\"1\",\"0\",\"0\",\"My status note\",\"4b6acca1-959b-4790-b76e-e474a0882990\",\"My sec ref: 27\",\"0\"";
|
216
|
Assert.assertTrue(unpublishedLine.contains(expectedExcluded));
|
217
|
|
218
|
//references
|
219
|
String nomRefLine = getLine(referenceResult, UUID.fromString("b8dd7f4a-0c7f-4372-bc5d-3b676363bc0f"));
|
220
|
expected ="\"b8dd7f4a-0c7f-4372-bc5d-3b676363bc0f\",\"Mill. (1804)\",\"\",\"The book of botany\",\"1804\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"3\",\"1804\",\"Mill.\"";
|
221
|
Assert.assertEquals(expected, nomRefLine.substring(0, expected.length()));
|
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
|
private String getLine(List<String> list, UUID uuid) {
|
255
|
return list.stream().filter(line->line.startsWith("\""+ uuid.toString())).findFirst().get();
|
256
|
}
|
257
|
|
258
|
@Test
|
259
|
@DataSets({
|
260
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
261
|
@DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
|
262
|
})
|
263
|
public void testFullData(){
|
264
|
|
265
|
CdmLightExportConfigurator config = CdmLightExportConfigurator.NewInstance();
|
266
|
config.setTarget(TARGET.EXPORT_DATA);
|
267
|
|
268
|
ExportResult result = defaultExport.invoke(config);
|
269
|
testExceptionsErrorsWarnings(result);
|
270
|
|
271
|
ExportDataWrapper<?> exportData = result.getExportData();
|
272
|
@SuppressWarnings("unchecked")
|
273
|
Map<String, byte[]> data = (Map<String, byte[]>) exportData.getExportData();
|
274
|
|
275
|
ByteArrayInputStream stream = new ByteArrayInputStream( data.get(CdmLightExportTable.TAXON.getTableName()));
|
276
|
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
|
277
|
String line;
|
278
|
int count = 0;
|
279
|
try {
|
280
|
while ((line = reader.readLine()) != null) {
|
281
|
count ++;
|
282
|
}
|
283
|
Assert.assertTrue("There should be 4 taxa", count == 5);// 5 because of the header line
|
284
|
|
285
|
stream = new ByteArrayInputStream(data.get(CdmLightExportTable.REFERENCE.getTableName()));
|
286
|
reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
|
287
|
count = 0;
|
288
|
while ((line = reader.readLine()) != null) {
|
289
|
count ++;
|
290
|
}
|
291
|
Assert.assertTrue("There should be 5 references", count == 6);
|
292
|
try{
|
293
|
stream = new ByteArrayInputStream(data.get(CdmLightExportTable.SYNONYM.getTableName()));
|
294
|
// now there are always all tables also if empty
|
295
|
reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
|
296
|
|
297
|
boolean dummyLine = true;
|
298
|
count = 0;
|
299
|
while ((line = reader.readLine()) != null) {
|
300
|
if (!(line.startsWith("\"DUMMY") || line.startsWith("\"Synonym_ID"))){
|
301
|
dummyLine = dummyLine && false;
|
302
|
}
|
303
|
count++;
|
304
|
}
|
305
|
Assert.assertTrue("There should be 0 synomyms", dummyLine && count == 3);
|
306
|
// Assert.fail("There should not be a synonym table, because the only synonym is not public.");
|
307
|
}catch(NullPointerException e){
|
308
|
//OK, should be thrown
|
309
|
}
|
310
|
} catch (IOException e) {
|
311
|
throw new RuntimeException(e);
|
312
|
}
|
313
|
}
|
314
|
|
315
|
@Test
|
316
|
@DataSets({
|
317
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
318
|
@DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
|
319
|
})
|
320
|
public void testFullSampleData(){
|
321
|
|
322
|
commonService.createFullSampleData();
|
323
|
commitAndStartNewTransaction();
|
324
|
|
325
|
|
326
|
CdmLightExportConfigurator config = CdmLightExportConfigurator.NewInstance();
|
327
|
config.setTarget(TARGET.EXPORT_DATA);
|
328
|
|
329
|
ExportResult result = defaultExport.invoke(config);
|
330
|
testExceptionsErrorsWarnings(result);
|
331
|
}
|
332
|
|
333
|
private void testExceptionsErrorsWarnings(ExportResult result) {
|
334
|
Assert.assertTrue(result.getExceptions().size() == 0);
|
335
|
Assert.assertTrue(result.getErrors().size() == 0);
|
336
|
Assert.assertTrue(result.getWarnings().size() == 0);
|
337
|
}
|
338
|
|
339
|
private List<String> getStringList(Map<String, byte[]> data, CdmLightExportTable table) {
|
340
|
List<String> result = new ArrayList<>();
|
341
|
ByteArrayInputStream stream = new ByteArrayInputStream( data.get(table.getTableName()));
|
342
|
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
|
343
|
String line;
|
344
|
try {
|
345
|
while ((line = reader.readLine()) != null) {
|
346
|
result.add(line);
|
347
|
}
|
348
|
} catch (IOException e) {
|
349
|
Assert.fail("IOException during result read");
|
350
|
}
|
351
|
return result;
|
352
|
}
|
353
|
|
354
|
public void createFullTestDataSet() {
|
355
|
|
356
|
Set<TaxonNode> nodesToSave = new HashSet<>();
|
357
|
|
358
|
Reference sec1 = ReferenceFactory.newGeneric();
|
359
|
setUuid(sec1, "4b6acca1-959b-4790-b76e-e474a0882990");
|
360
|
sec1.setTitle("My sec ref");
|
361
|
|
362
|
Classification classification = Classification.NewInstance("CdmLightExportTest Classification");
|
363
|
setUuid(classification, "4096df99-7274-421e-8843-211b603d832e");
|
364
|
setUuid(classification.getRootNode(), rootNodeUuid);
|
365
|
|
366
|
NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
|
367
|
TaxonName familyName = parser.parseReferencedName("Family L., Sp. Pl. 3: 22. 1752",
|
368
|
NomenclaturalCode.ICNAFP, Rank.FAMILY());
|
369
|
setUuid(familyName,"e983cc5e-4c77-4c80-8cb0-73d43df31ef7");
|
370
|
setUuid(familyName.getNomenclaturalReference(), "b0dd7f4a-0c7f-4372-bc5d-3b676363bc63");
|
371
|
Taxon family = Taxon.NewInstance(familyName, sec1);
|
372
|
setUuid(family, familyTaxonUuid);
|
373
|
TaxonNode node1 = classification.addChildTaxon(family, sec1, "22");
|
374
|
setUuid(node1, node1Uuid.toString());
|
375
|
nodesToSave.add(node1);
|
376
|
|
377
|
TaxonName genusName = parser.parseReferencedName("Genus Humb., The book of botany 3: 22. 1804",
|
378
|
NomenclaturalCode.ICNAFP, Rank.GENUS());
|
379
|
setUuid(genusName,"5e83cc5e-4c77-4d80-8cb0-73d63df35ee3");
|
380
|
setUuid(genusName.getNomenclaturalReference(), "5ed27f4a-6c7f-4372-bc5d-3b67636abc52");
|
381
|
Taxon genus = Taxon.NewInstance(genusName, sec1);
|
382
|
setUuid(genus, genusTaxonUuid);
|
383
|
|
384
|
TaxonNode node2 = node1.addChildTaxon(genus, sec1, "33");
|
385
|
setUuid(node2, node2Uuid);
|
386
|
nodesToSave.add(node2);
|
387
|
|
388
|
TaxonName speciesName = parser.parseReferencedName("Genus species Mill., The book of botany 3: 22. 1804",
|
389
|
NomenclaturalCode.ICNAFP, Rank.SPECIES());
|
390
|
setUuid(speciesName,"f983cc5e-4c77-4c80-8cb0-73d43df31ee9");
|
391
|
setUuid(speciesName.getNomenclaturalReference(), "a0dd7f4a-0c7f-4372-bc5d-3b676363bc0e");
|
392
|
Taxon species = Taxon.NewInstance(speciesName, sec1);
|
393
|
setUuid(species, speciesTaxonUuid);
|
394
|
TaxonName synonymName = parser.parseReferencedName("Genus synonym Mill., The book of botany 3: 22. 1804", NomenclaturalCode.ICNAFP, Rank.SPECIES());
|
395
|
|
396
|
setUuid(synonymName, "1584157b-5c43-4150-b271-95b2c99377b2");
|
397
|
Synonym synonymUnpublished = Synonym.NewInstance(synonymName, sec1);
|
398
|
setUuid(synonymName, "a87c16b7-8299-4d56-a682-ce20973428ea");
|
399
|
synonymUnpublished.setPublish(false);
|
400
|
species.addHomotypicSynonym(synonymUnpublished);
|
401
|
TaxonNode node3 = node2.addChildTaxon(species, sec1, "33");
|
402
|
setUuid(node3, node3Uuid.toString());
|
403
|
nodesToSave.add(node3);
|
404
|
|
405
|
TaxonName subspeciesName = parser.parseReferencedName("Genus species subsp. subspec Mill., The book of botany 3: 22. 1804",
|
406
|
NomenclaturalCode.ICNAFP, Rank.SUBSPECIES());
|
407
|
setUuid(subspeciesName,"3483cc5e-4c77-4c80-8cb0-73d43df31ee3");
|
408
|
setUuid(subspeciesName.getNomenclaturalReference(), "b8dd7f4a-0c7f-4372-bc5d-3b676363bc0f");
|
409
|
|
410
|
Taxon subspecies = Taxon.NewInstance(subspeciesName, sec1);
|
411
|
subspecies.getSecSource().setNameUsedInSource(subspeciesName);
|
412
|
setUuid(subspecies, subspeciesTaxonUuid);
|
413
|
TaxonNode node4 = node3.addChildTaxon(subspecies, sec1, "33");
|
414
|
setUuid(node4, node4Uuid);
|
415
|
nodesToSave.add(node4);
|
416
|
|
417
|
TaxonName subspeciesNameUnpublished = parser.parseReferencedName("Genus species subsp. unpublished Mill., The book of botany 3: 22. 1804",
|
418
|
NomenclaturalCode.ICNAFP, Rank.SUBSPECIES());
|
419
|
setUuid(subspeciesNameUnpublished,"b6da7ab2-6c67-44b7-9719-2557542f5a23");
|
420
|
|
421
|
Taxon subspeciesUnpublished = Taxon.NewInstance(subspeciesNameUnpublished, sec1);
|
422
|
setUuid(subspeciesUnpublished, subspeciesUnpublishedTaxonUuid);
|
423
|
subspeciesUnpublished.setPublish(false);
|
424
|
TaxonNode node5 = node3.addChildTaxon(subspeciesUnpublished, sec1, "33");
|
425
|
//excluded node
|
426
|
setUuid(node5, node5Uuid.toString());
|
427
|
node5.setStatus(TaxonNodeStatus.EXCLUDED);
|
428
|
node5.setCitation(sec1);
|
429
|
node5.setCitationMicroReference("27");
|
430
|
node5.putStatusNote(Language.ENGLISH(), "My status note");
|
431
|
nodesToSave.add(node5);
|
432
|
|
433
|
classificationService.save(classification);
|
434
|
taxonNodeService.save(nodesToSave);
|
435
|
|
436
|
TaxonDescription description = TaxonDescription.NewInstance(species);
|
437
|
|
438
|
Distribution distribution = Distribution.NewInstance(NamedArea.AFRICA(), PresenceAbsenceTerm.PRESENT());
|
439
|
setUuid(distribution,"674e9e27-9102-4166-8626-8cb871a9a89b");
|
440
|
description.addElement(distribution);
|
441
|
|
442
|
subspecies.addDescription(description);
|
443
|
commitAndStartNewTransaction(null);
|
444
|
}
|
445
|
|
446
|
private void setUuid(CdmBase cdmBase, String uuidStr) {
|
447
|
cdmBase.setUuid(UUID.fromString(uuidStr));
|
448
|
}
|
449
|
|
450
|
private void setUuid(CdmBase cdmBase, UUID uuid) {
|
451
|
cdmBase.setUuid(uuid);
|
452
|
}
|
453
|
|
454
|
@Override
|
455
|
public void createTestDataSet() throws FileNotFoundException {}
|
456
|
}
|