Project

General

Profile

Revision 818cfd67

ID818cfd6726cc2ee1345da074697c2edebc8b03f1
Parent 8eaa553b
Child 3429c491

Added by Andreas Müller almost 2 years ago

ref #2342 fix bug in higherClassification handling in DwC-A export and adapt tests

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaTaxonExport.java
220 220
			Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class);
221 221
		    handleHigherClassification(state, record, taxon, classification);
222 222

  
223
			record.setHigherClassification(null);
224 223
			//... higher ranks
225 224
			handleUninomialOrGenus(record, name);
226 225
			if (name.getRank() != null &&  name.getRank().equals(Rank.SUBGENUS())){
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/dwca/out/DwcaExportTest.java
148 148
//        Assert.assertTrue(coreStr.contains(expected));
149 149

  
150 150

  
151
        String expected = "\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"f983cc5e-4c77-4c80-8cb0-73d43df31ee9\",\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",\"Genus species subsp. subspec Mill.\",\"Subspecies\",\"accepted\",,\"4b6acca1-959b-4790-b76e-e474a0882990\",\"a0dd7f4a-0c7f-4372-bc5d-3b676363bc0e\",\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"Genus species subsp. subspec Mill.\",\"Genus species subsp. subspec Mill. sec. My sec ref\",";
151
        String expected = "\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"3483cc5e-4c77-4c80-8cb0-73d43df31ee3\",\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",\"Genus species subsp. subspec Mill.\",\"Subspecies\",\"accepted\",,\"4b6acca1-959b-4790-b76e-e474a0882990\",\"b8dd7f4a-0c7f-4372-bc5d-3b676363bc0f\",\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"Genus species subsp. subspec Mill.\",\"Genus species Mill. sec. My sec ref\",";
152
//        System.out.println(coreStr);
152 153
        Assert.assertTrue(coreStr.contains(expected));
153 154

  
154

  
155
        expected = "\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"f983cc5e-4c77-4c80-8cb0-73d43df31ee9\",\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",\"Genus species subsp. subspec Mill.\",\"Subspecies\",\"accepted\",,\"4b6acca1-959b-4790-b76e-e474a0882990\",\"a0dd7f4a-0c7f-4372-bc5d-3b676363bc0e\",\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"Genus species subsp. subspec Mill.\",\"Genus species subsp. subspec Mill. sec. My sec ref\",,\"My sec ref\",\"Mill., The book of botany 3. 1804\",,\"Genus\",,\"species\",\"subspec\",\"subsp.\",,\"ICNAFP\",,,,,,,,,,\"DwcaExportTest Classificaiton\",";
155
        expected = "\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"3483cc5e-4c77-4c80-8cb0-73d43df31ee3\",\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",\"Genus species subsp. subspec Mill.\",\"Subspecies\",\"accepted\",,\"4b6acca1-959b-4790-b76e-e474a0882990\",\"b8dd7f4a-0c7f-4372-bc5d-3b676363bc0f\",\"b2c86698-500e-4efb-b9ae-6bb6e701d4bc\",\"Genus species subsp. subspec Mill.\",\"Genus species Mill. sec. My sec ref\",,\"My sec ref\",\"Mill., The book of botany 3. 1804\",,\"Genus\",,\"species\",\"subspec\",\"subsp.\",,\"ICNAFP\",,,,,,,,,,\"DwcaExportTest Classification\",";
156 156
        Assert.assertTrue(coreStr.contains(expected));
157 157

  
158 158
        //distribution
......
176 176
        File destinationFolder = null;
177 177
        DwcaTaxExportConfigurator config = DwcaTaxExportConfigurator.NewInstance(null, destinationFolder, null);
178 178
        config.setTarget(TARGET.EXPORT_DATA);
179
        config.setWithHigherClassification(true);
179 180
        ExportResult result = defaultExport.invoke(config);
180
        System.out.println(result.createReport());
181
//        System.out.println(result.createReport());
181 182
        ExportDataWrapper<?> exportData = result.getExportData();
182 183
        @SuppressWarnings("unchecked")
183 184
        Map<String, byte[]> data = (Map<String, byte[]>) exportData.getExportData();
......
185 186
            byte[] byt = data.get(key);
186 187
            System.out.println(key + ": " + new String(byt) );
187 188
        }
188
        System.out.println();
189
//        System.out.println();
189 190
        //metadata
190 191
        byte[] metadata = data.get(DwcaTaxExportFile.METADATA.getTableName());
191 192
        Assert.assertNotNull("Metadata must not be null", metadata);
......
200 201
                + "<field index=\"8\" term=\"http://rs.tdwg.org/dwc/terms/nameAccordingToID\"></field>"
201 202
                + "<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>"
202 203
                + "<field index=\"15\" term=\"http://rs.tdwg.org/dwc/terms/namePublishedIn\"></field>"
203
                + "<field index=\"16\" term=\"http://rs.tdwg.org/ontology/voc/TaxonName#uninomial\"></field>"
204
                + "<field index=\"17\" term=\"http://rs.tdwg.org/ontology/voc/TaxonName#genusPart\"></field><field index=\"18\" term=\"http://rs.tdwg.org/ontology/voc/TaxonName#infragenericEpithet\"></field><field index=\"19\" term=\"http://rs.tdwg.org/dwc/terms/specificEpithet\"></field><field index=\"20\" term=\"http://rs.tdwg.org/dwc/terms/infraspecificEpithet\"></field><field index=\"21\" term=\"http://rs.tdwg.org/dwc/terms/verbatimTaxonRank\"></field><field index=\"22\" term=\"http://rs.tdwg.org/dwc/terms/vernacularName\"></field>"
205
                + "<field index=\"23\" term=\"http://rs.tdwg.org/dwc/terms/nomenclaturalCode\"></field><field index=\"24\" term=\"http://rs.tdwg.org/dwc/terms/nomenclaturalStatus\"></field><field index=\"25\" term=\"http://rs.tdwg.org/dwc/terms/taxonRemarks\"></field><field index=\"26\" term=\"http://purl.org/dc/terms/modified\"></field>"
206
                + "<field index=\"27\" term=\"http://purl.org/dc/terms/language\"></field><field index=\"28\" term=\"http://purl.org/dc/terms/rights\"></field><field index=\"29\" term=\"http://purl.org/dc/terms/rightsHolder\"></field><field index=\"30\" term=\"http://purl.org/dc/terms/accessRights\"></field>"
207
                + "<field index=\"31\" term=\"http://purl.org/dc/terms/bibliographicCitation\"></field><field index=\"32\" term=\"http://rs.tdwg.org/dwc/terms/informationWithheld\"></field><field index=\"33\" term=\"http://rs.tdwg.org/dwc/terms/datasetName\"></field><field index=\"34\" term=\"http://purl.org/dc/terms/source\"></field></core>";
204

  
205
                + "<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>"
206
                + "<field index=\"24\" term=\"http://rs.tdwg.org/ontology/voc/TaxonName#uninomial\"></field>"
207
                + "<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>"
208

  
209
                + "<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>"
210
                + "<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>"
211
                + "<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>" +
212
                "";
208 213
        //TODO continue
209
        System.out.println(metaDataStr);
214
//        System.out.println(metaDataStr);
210 215
        Assert.assertTrue(metaDataStr.contains(metaCore));
211 216

  
212 217
        //core
213 218
        byte[] core = data.get(DwcaTaxExportFile.TAXON.getTableName());
214 219
        Assert.assertNotNull("Core must not be null", core);
215 220
        String coreStr = new String(core);
216
        String expected =  "\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",\"f983cc5e-4c77-4c80-8cb0-73d43df31ee9\",\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",,\"Genus species subsp. subspec Mill.\",\"Subspecies\",\"accepted\"";
221
        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\"";
222
//        System.out.println(coreStr);
217 223
        Assert.assertTrue(coreStr.contains(expected));
224
        String expectedClassification = "\"Family L.|Genus Humb.|Genus species Mill.\"";
225
        Assert.assertTrue(coreStr.contains(expectedClassification));
218 226

  
219 227

  
220 228
        //reference
221 229
        byte[] ref = data.get(DwcaTaxExportFile.REFERENCE.getTableName());
222 230
        Assert.assertNotNull("Reference must not be null", ref);
223 231
        String refStr = new String(ref);
224
        expected = "\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",,,,,\"My sec ref\",\"My sec ref\",,,,,,,,,";
232
        expected = "\"3162e136-f2e2-4f9a-9010-3f35908fbae1\",,,,,\"My sec ref\",\"My sec ref\",,,,,,,,,";
233
//        System.out.println(refStr);
225 234
        Assert.assertTrue(refStr.contains(expected));
226 235
        expected = "\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",,,,,\"Mill., The book of botany 3. 1804\",,\"Mill.\",\"1804\",,,,,,,";
227 236
        Assert.assertTrue(refStr.contains(expected));
......
233 242
        expected =  "\"9182e136-f2e2-4f9a-9010-3f35908fb5e0\",\"c204c529-d8d2-458f-b939-96f0ebd2cbe8\",\"Africa\",,,\"present\",,\"uncertain\",,,,,,";
234 243
        Assert.assertTrue(distributionStr.contains(expected));
235 244

  
236

  
237

  
238 245
    }
239 246

  
240 247
    /**
......
246 253
        setUuid(sec1, "4b6acca1-959b-4790-b76e-e474a0882990");
247 254
        sec1.setTitle("My sec ref");
248 255

  
249
        Classification classification = Classification.NewInstance("DwcaExportTest Classificaiton");
256
        Classification classification = Classification.NewInstance("DwcaExportTest Classification");
250 257
        setUuid(classification, "4096df99-7274-421e-8843-211b603d832e");
251 258

  
252 259
        NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
253
        TaxonName name1 = parser.parseReferencedName("Genus species subsp. subspec Mill., The book of botany 3: 22. 1804",
254
                NomenclaturalCode.ICNAFP, Rank.SUBSPECIES());
255
        setUuid(name1,"f983cc5e-4c77-4c80-8cb0-73d43df31ee9");
256
        setUuid((Reference)name1.getNomenclaturalReference(), "a0dd7f4a-0c7f-4372-bc5d-3b676363bc0e");
257
        Taxon root = Taxon.NewInstance(name1, sec1);
258
        setUuid(root,"9182e136-f2e2-4f9a-9010-3f35908fb5e0");
259

  
260
        TaxonNode node1 = classification.addChildTaxon(root, sec1, "22");
260
        TaxonName familyName = parser.parseReferencedName("Family L., Sp. Pl. 3: 22. 1752",
261
                NomenclaturalCode.ICNAFP, Rank.FAMILY());
262
        setUuid(familyName,"e983cc5e-4c77-4c80-8cb0-73d43df31ef7");
263
        setUuid((Reference)familyName.getNomenclaturalReference(), "b0dd7f4a-0c7f-4372-bc5d-3b676363bc63");
264
        Taxon family = Taxon.NewInstance(familyName, sec1);
265
        setUuid(family,"3162e136-f2e2-4f9a-9010-3f35908fbae1");
266
        TaxonNode node1 = classification.addChildTaxon(family, sec1, "22");
261 267
        setUuid(node1, "0fae5ad5-ffa2-4100-bcd7-8aa9dda0aebc");
262 268
        nodesToSave.add(node1);
263 269

  
264
        Taxon child = Taxon.NewInstance(name1, sec1);
265
        setUuid(child, "b2c86698-500e-4efb-b9ae-6bb6e701d4bc");
266
        TaxonNode node2 = node1.addChildTaxon(child, sec1, "33");
267
        setUuid(node2, "f8c9933a-fe3a-42ce-8a92-000e27bfdfac");
270
        TaxonName genusName = parser.parseReferencedName("Genus Humb., The book of botany 3: 22. 1804",
271
                NomenclaturalCode.ICNAFP, Rank.GENUS());
272
        setUuid(genusName,"5e83cc5e-4c77-4d80-8cb0-73d63df35ee3");
273
        setUuid((Reference)genusName.getNomenclaturalReference(), "5ed27f4a-6c7f-4372-bc5d-3b67636abc52");
274
        Taxon genus = Taxon.NewInstance(genusName, sec1);
275
        setUuid(genus,"3f52e136-f2e1-4f9a-9010-2f35908fbd39");
276

  
277
        TaxonNode node2 = node1.addChildTaxon(genus, sec1, "33");
278
        setUuid(node2, "43ca733b-fe3a-42ce-8a92-000e27badf44");
268 279
        nodesToSave.add(node2);
269 280

  
281

  
282
        TaxonName speciesName = parser.parseReferencedName("Genus species Mill., The book of botany 3: 22. 1804",
283
                NomenclaturalCode.ICNAFP, Rank.SPECIES());
284
        setUuid(speciesName,"f983cc5e-4c77-4c80-8cb0-73d43df31ee9");
285
        setUuid((Reference)speciesName.getNomenclaturalReference(), "a0dd7f4a-0c7f-4372-bc5d-3b676363bc0e");
286
        Taxon species = Taxon.NewInstance(speciesName, sec1);
287
        setUuid(species,"9182e136-f2e2-4f9a-9010-3f35908fb5e0");
288

  
289
        TaxonNode node3 = node2.addChildTaxon(species, sec1, "33");
290
        setUuid(node3, "a0c9733a-fe3a-42ce-8a92-000e27bfdfa3");
291
        nodesToSave.add(node3);
292

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

  
298
        Taxon subspecies = Taxon.NewInstance(subspeciesName, sec1);
299
        setUuid(subspecies, "b2c86698-500e-4efb-b9ae-6bb6e701d4bc");
300
        TaxonNode node4 = node3.addChildTaxon(subspecies, sec1, "33");
301
        setUuid(node4, "f8c9933a-fe3a-42ce-8a92-000e27bfdfac");
302
        nodesToSave.add(node4);
303

  
270 304
        classificationService.save(classification);
271 305
        taxonNodeService.save(nodesToSave);
272 306

  
273
        TaxonDescription description = TaxonDescription.NewInstance(root);
307
        TaxonDescription description = TaxonDescription.NewInstance(species);
274 308

  
275 309
        Distribution distribution = Distribution.NewInstance(NamedArea.AFRICA(), PresenceAbsenceTerm.PRESENT());
276 310
        setUuid(distribution,"674e9e27-9102-4166-8626-8cb871a9a89b");

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)