1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.cdm.io.specimen.abcd206.in;
|
11
|
|
12
|
import java.io.IOException;
|
13
|
import java.io.InputStream;
|
14
|
import java.net.URL;
|
15
|
import java.util.ArrayList;
|
16
|
import java.util.HashMap;
|
17
|
import java.util.Iterator;
|
18
|
import java.util.List;
|
19
|
import java.util.Set;
|
20
|
|
21
|
import javax.xml.parsers.DocumentBuilder;
|
22
|
import javax.xml.parsers.DocumentBuilderFactory;
|
23
|
import javax.xml.parsers.ParserConfigurationException;
|
24
|
|
25
|
import org.apache.log4j.Logger;
|
26
|
import org.springframework.stereotype.Component;
|
27
|
import org.springframework.transaction.TransactionStatus;
|
28
|
import org.w3c.dom.Document;
|
29
|
import org.w3c.dom.Element;
|
30
|
import org.w3c.dom.Node;
|
31
|
import org.w3c.dom.NodeList;
|
32
|
import org.xml.sax.SAXException;
|
33
|
|
34
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
35
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade.DerivedUnitType;
|
36
|
import eu.etaxonomy.cdm.common.mediaMetaData.ImageMetaData;
|
37
|
import eu.etaxonomy.cdm.io.common.ICdmIO;
|
38
|
import eu.etaxonomy.cdm.io.specimen.SpecimenIoBase;
|
39
|
import eu.etaxonomy.cdm.io.specimen.UnitsGatheringArea;
|
40
|
import eu.etaxonomy.cdm.io.specimen.UnitsGatheringEvent;
|
41
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
42
|
import eu.etaxonomy.cdm.model.agent.Team;
|
43
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
44
|
import eu.etaxonomy.cdm.model.media.ImageFile;
|
45
|
import eu.etaxonomy.cdm.model.media.Media;
|
46
|
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
|
47
|
import eu.etaxonomy.cdm.model.name.BacterialName;
|
48
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
49
|
import eu.etaxonomy.cdm.model.name.CultivarPlantName;
|
50
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
51
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
52
|
import eu.etaxonomy.cdm.model.name.Rank;
|
53
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
54
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
55
|
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
|
56
|
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
|
57
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
58
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
59
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
60
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
61
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
62
|
|
63
|
|
64
|
/**
|
65
|
* @author p.kelbert
|
66
|
* @created 20.10.2008
|
67
|
* @version 1.0
|
68
|
*/
|
69
|
@Component
|
70
|
public class Abcd206Import extends SpecimenIoBase<Abcd206ImportConfigurator, Abcd206ImportState> implements ICdmIO<Abcd206ImportState> {
|
71
|
private static final Logger logger = Logger.getLogger(Abcd206Import.class);
|
72
|
|
73
|
|
74
|
public Abcd206Import() {
|
75
|
super();
|
76
|
}
|
77
|
|
78
|
|
79
|
@Override
|
80
|
protected boolean doCheck(Abcd206ImportState state) {
|
81
|
logger.warn("Checking not yet implemented for " + this.getClass().getSimpleName());
|
82
|
return true;
|
83
|
}
|
84
|
|
85
|
|
86
|
@Override
|
87
|
public boolean doInvoke(Abcd206ImportState state){
|
88
|
logger.info("INVOKE Specimen Import from ABCD2.06 XML File");
|
89
|
boolean result = true;
|
90
|
Abcd206ImportConfigurator config = state.getConfig();
|
91
|
//AbcdIO test = new AbcdIO();
|
92
|
String sourceName = config.getSource();
|
93
|
NodeList unitsList = getUnitsNodeList(sourceName);
|
94
|
if (unitsList != null){
|
95
|
String message = "nb units to insert: "+unitsList.getLength();
|
96
|
logger.info(message);
|
97
|
config.updateProgress(message);
|
98
|
|
99
|
Abcd206DataHolder dataHolder = new Abcd206DataHolder();
|
100
|
|
101
|
for (int i=0 ; i<unitsList.getLength() ; i++){
|
102
|
this.setUnitPropertiesXML((Element)unitsList.item(i), dataHolder);
|
103
|
result &= this.handleSingleUnit(config, dataHolder);
|
104
|
|
105
|
//compare the ABCD elements added in to the CDM and the unhandled ABCD elements
|
106
|
compareABCDtoCDM(sourceName, dataHolder.knownABCDelements, dataHolder);
|
107
|
|
108
|
//reset the ABCD elements added in CDM
|
109
|
//knownABCDelements = new ArrayList<String>();
|
110
|
dataHolder.allABCDelements = new HashMap<String,String>();
|
111
|
}
|
112
|
}
|
113
|
|
114
|
return result;
|
115
|
|
116
|
}
|
117
|
|
118
|
/*
|
119
|
* Store the unit with its Gathering informations in the CDM
|
120
|
*/
|
121
|
private boolean handleSingleUnit(Abcd206ImportConfigurator config, Abcd206DataHolder dataHolder){
|
122
|
boolean result = true;
|
123
|
|
124
|
TransactionStatus tx = startTransaction();
|
125
|
try {
|
126
|
config.updateProgress("Importing data for unit: " + dataHolder.unitID);
|
127
|
|
128
|
// ReferenceBase sec = Database.NewInstance();
|
129
|
// sec.setTitleCache("XML DATA");
|
130
|
ReferenceBase sec = config.getTaxonReference();
|
131
|
|
132
|
//create facade
|
133
|
DerivedUnitFacade derivedUnitFacade = getFacade(dataHolder);
|
134
|
|
135
|
|
136
|
//handle identifications
|
137
|
handleIdentifications(config, derivedUnitFacade, sec, dataHolder);
|
138
|
|
139
|
//handle collection data
|
140
|
setCollectionData(config, dataHolder, derivedUnitFacade);
|
141
|
|
142
|
/**
|
143
|
* GATHERING EVENT
|
144
|
*/
|
145
|
|
146
|
//gathering event
|
147
|
UnitsGatheringEvent unitsGatheringEvent = new UnitsGatheringEvent(
|
148
|
getTermService(), dataHolder.locality, dataHolder.languageIso, dataHolder.longitude,
|
149
|
dataHolder.latitude, dataHolder.gatheringAgentList);
|
150
|
|
151
|
//country
|
152
|
UnitsGatheringArea unitsGatheringArea =
|
153
|
new UnitsGatheringArea(dataHolder.isocountry, dataHolder.country, getOccurrenceService());
|
154
|
NamedArea areaCountry = unitsGatheringArea.getArea();
|
155
|
|
156
|
//other areas
|
157
|
unitsGatheringArea = new UnitsGatheringArea(dataHolder.namedAreaList);
|
158
|
ArrayList<NamedArea> nas = unitsGatheringArea.getAreas();
|
159
|
for (NamedArea namedArea : nas){
|
160
|
unitsGatheringEvent.addArea(namedArea);
|
161
|
}
|
162
|
|
163
|
//copy gathering event to facade
|
164
|
GatheringEvent gatheringEvent = unitsGatheringEvent.getGatheringEvent();
|
165
|
derivedUnitFacade.setLocality(gatheringEvent.getLocality());
|
166
|
derivedUnitFacade.setExactLocation(gatheringEvent.getExactLocation());
|
167
|
derivedUnitFacade.setCollector(gatheringEvent.getCollector());
|
168
|
derivedUnitFacade.addCollectingArea(areaCountry);
|
169
|
//FIXME setCountry
|
170
|
derivedUnitFacade.addCollectingArea(areaCountry);
|
171
|
derivedUnitFacade.addCollectingAreas(unitsGatheringArea.getAreas());
|
172
|
|
173
|
//TODO exsiccatum
|
174
|
|
175
|
|
176
|
//add fieldNumber
|
177
|
derivedUnitFacade.setFieldNumber(dataHolder.fieldNumber);
|
178
|
|
179
|
//join gatheringEvent to fieldObservation
|
180
|
|
181
|
// //add Multimedia URLs
|
182
|
if(dataHolder.multimediaObjects.size() > 0){
|
183
|
MediaRepresentation representation;
|
184
|
Media media;
|
185
|
ImageMetaData imd ;
|
186
|
URL url ;
|
187
|
ImageFile imf;
|
188
|
for (String multimediaObject : dataHolder.multimediaObjects){
|
189
|
if( multimediaObject != null){
|
190
|
imd = ImageMetaData.newInstance();
|
191
|
url = new URL(multimediaObject);
|
192
|
try {
|
193
|
imd.readMetaData(url.toURI(), 0);
|
194
|
} catch (Exception e) {
|
195
|
String message = "An error occurred when trying to read image meta data: " + e.getMessage();
|
196
|
logger.warn(message);
|
197
|
}
|
198
|
//TODO do we really want to check the url?
|
199
|
if (imd != null){
|
200
|
imf = ImageFile.NewInstance(multimediaObject, null, imd);
|
201
|
representation = MediaRepresentation.NewInstance();
|
202
|
representation.addRepresentationPart(imf);
|
203
|
media = Media.NewInstance();
|
204
|
media.addRepresentation(representation);
|
205
|
|
206
|
derivedUnitFacade.addFieldObjectMedia(media);
|
207
|
}
|
208
|
}
|
209
|
}
|
210
|
}
|
211
|
|
212
|
/**
|
213
|
* SAVE AND STORE DATA
|
214
|
*/
|
215
|
getTermService().save(areaCountry);//TODO save area sooner
|
216
|
for (NamedArea area : nas){
|
217
|
getTermService().save(area);//save it sooner (foreach area)
|
218
|
}
|
219
|
getTermService().saveLanguageData(unitsGatheringEvent.getLocality());//TODO needs to be saved ?? save it sooner
|
220
|
|
221
|
getOccurrenceService().save(derivedUnitFacade.getDerivedUnit());
|
222
|
logger.info("saved ABCD specimen ...");
|
223
|
|
224
|
|
225
|
} catch (Exception e) {
|
226
|
logger.warn("Error when reading record!!");
|
227
|
e.printStackTrace();
|
228
|
result = false;
|
229
|
}
|
230
|
commitTransaction(tx);
|
231
|
|
232
|
return result;
|
233
|
}
|
234
|
|
235
|
|
236
|
private void setCollectionData(Abcd206ImportConfigurator config,
|
237
|
Abcd206DataHolder dataHolder, DerivedUnitFacade derivedUnitFacade) {
|
238
|
//set catalogue number (unitID)
|
239
|
derivedUnitFacade.setCatalogNumber(dataHolder.unitID);
|
240
|
derivedUnitFacade.setAccessionNumber(dataHolder.accessionNumber);
|
241
|
derivedUnitFacade.setCollectorsNumber(dataHolder.collectorsNumber);
|
242
|
|
243
|
|
244
|
/**
|
245
|
* INSTITUTION & COLLECTION
|
246
|
*/
|
247
|
//manage institution
|
248
|
Institution institution = this.getInstitution(dataHolder.institutionCode, config, dataHolder);
|
249
|
//manage collection
|
250
|
Collection collection = this.getCollection(dataHolder.collectionCode, institution, config, dataHolder);
|
251
|
//link specimen & collection
|
252
|
derivedUnitFacade.setCollection(collection);
|
253
|
}
|
254
|
|
255
|
|
256
|
private DerivedUnitFacade getFacade(Abcd206DataHolder dataHolder) {
|
257
|
/**
|
258
|
* SPECIMEN OR OBSERVATION OR LIVING
|
259
|
*/
|
260
|
// DerivedUnitBase derivedThing = null;
|
261
|
DerivedUnitType type = null;
|
262
|
|
263
|
//create specimen
|
264
|
if (dataHolder.recordBasis != null){
|
265
|
if (dataHolder.recordBasis.toLowerCase().startsWith("s")) {//specimen
|
266
|
type = DerivedUnitType.Specimen;
|
267
|
}else if (dataHolder.recordBasis.toLowerCase().startsWith("o")) {//observation
|
268
|
type = DerivedUnitType.Observation;
|
269
|
}else if (dataHolder.recordBasis.toLowerCase().startsWith("l")) {//living -> fossil, herbarium sheet....???
|
270
|
type = DerivedUnitType.LivingBeing;
|
271
|
}
|
272
|
if (type == null){
|
273
|
logger.info("The basis of record does not seem to be known: " + dataHolder.recordBasis);
|
274
|
type = DerivedUnitType.DerivedUnit;
|
275
|
}
|
276
|
//TODO fossils?
|
277
|
}else{
|
278
|
logger.info("The basis of record is null");
|
279
|
type = DerivedUnitType.DerivedUnit;
|
280
|
}
|
281
|
DerivedUnitFacade derivedUnitFacade = DerivedUnitFacade.NewInstance(type);
|
282
|
return derivedUnitFacade;
|
283
|
}
|
284
|
|
285
|
|
286
|
/*
|
287
|
* Return the list of root nodes for an ABCD 2.06 XML file
|
288
|
* @param fileName: the file's location
|
289
|
* @return the list of root nodes ("Unit")
|
290
|
*/
|
291
|
private static NodeList getUnitsNodeList(String urlFileName){
|
292
|
NodeList unitList = null;
|
293
|
try {
|
294
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
295
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
296
|
URL url = new URL(urlFileName);
|
297
|
Object o = url.getContent();
|
298
|
InputStream is = (InputStream)o;
|
299
|
Document document = builder.parse(is);
|
300
|
Element root = document.getDocumentElement();
|
301
|
unitList = root.getElementsByTagName("Unit");
|
302
|
|
303
|
}catch(Exception e){
|
304
|
logger.warn(e);
|
305
|
}
|
306
|
return unitList;
|
307
|
}
|
308
|
|
309
|
|
310
|
/*
|
311
|
* Store the unit's properties into variables
|
312
|
* Look which unit is the preferred one
|
313
|
* Look what kind of name it is supposed to be, for the parsing (Botanical, Zoological)
|
314
|
* @param racine: the root node for a single unit
|
315
|
*/
|
316
|
private void setUnitPropertiesXML(Element root, Abcd206DataHolder dataHolder){
|
317
|
try{
|
318
|
NodeList group;
|
319
|
|
320
|
// try{afficherInfos(racine, 0);}catch (Exception e) {logger.info(e);}
|
321
|
group = root.getChildNodes();
|
322
|
// logger.info("ABCD ELEMENT not stored: "+group.item(i).getNodeName().toString()+" - value: "+group.item(i).getTextContent());
|
323
|
for (int i = 0; i < group.getLength(); i++){
|
324
|
if (group.item(i).getNodeName().equals("Identifications")){
|
325
|
group = group.item(i).getChildNodes();
|
326
|
break;
|
327
|
}
|
328
|
}
|
329
|
dataHolder.identificationList = new ArrayList<String>();
|
330
|
dataHolder.atomisedIdentificationList = new ArrayList<HashMap<String, String>>();
|
331
|
dataHolder.referenceList = new ArrayList<String>();
|
332
|
dataHolder.multimediaObjects = new ArrayList<String>();
|
333
|
|
334
|
this.getScientificNames(group, dataHolder);
|
335
|
|
336
|
// logger.info("this.identificationList "+this.identificationList.toString());
|
337
|
this.getIDs(root, dataHolder);
|
338
|
this.getRecordBasis(root, dataHolder);
|
339
|
this.getMultimedia(root, dataHolder);
|
340
|
this.getNumbers(root, dataHolder);
|
341
|
this.getGeolocation(root, dataHolder);
|
342
|
this.getGatheringPeople(root, dataHolder);
|
343
|
|
344
|
} catch (Exception e) {
|
345
|
logger.info("Error occured while parsing XML file"+e);
|
346
|
}
|
347
|
}
|
348
|
|
349
|
String path= "";
|
350
|
private void getHierarchie(Node node){
|
351
|
while (node != null && node.getNodeName() != "DataSets"){
|
352
|
// logger.info(node.getParentNode().getNodeName());
|
353
|
path = node.getParentNode().getNodeName()+"/"+path;
|
354
|
node = node.getParentNode();
|
355
|
}
|
356
|
// logger.info("path: "+path);
|
357
|
}
|
358
|
|
359
|
private void getScientificNames(NodeList group, Abcd206DataHolder dataHolder){
|
360
|
NodeList identifications,results;
|
361
|
String tmpName = null;
|
362
|
for (int j=0; j< group.getLength(); j++){
|
363
|
if(group.item(j).getNodeName().equals("Identification")){
|
364
|
dataHolder.nomenclatureCode ="";
|
365
|
identifications = group.item(j).getChildNodes();
|
366
|
for (int m=0; m<identifications.getLength();m++){
|
367
|
if(identifications.item(m).getNodeName().equals("Result")){
|
368
|
results = identifications.item(m).getChildNodes();
|
369
|
for(int k=0; k<results.getLength();k++){
|
370
|
if (results.item(k).getNodeName().equals("TaxonIdentified")){
|
371
|
tmpName=this.getScientificName(results.item(k), dataHolder);
|
372
|
}
|
373
|
}
|
374
|
}else if(identifications.item(m).getNodeName().equals("PreferredFlag")){
|
375
|
if (dataHolder.nomenclatureCode != null && dataHolder.nomenclatureCode !=""){
|
376
|
dataHolder.identificationList.add(tmpName+"_preferred_"+identifications.item(m).getTextContent()+"_code_" + dataHolder.nomenclatureCode);
|
377
|
}else{
|
378
|
dataHolder.identificationList.add(tmpName+"_preferred_"+identifications.item(m).getTextContent());
|
379
|
}
|
380
|
path=identifications.item(m).getNodeName();
|
381
|
getHierarchie(identifications.item(m));
|
382
|
dataHolder.knownABCDelements.add(path);
|
383
|
path="";
|
384
|
}else if (identifications.item(m).getNodeName().equals("References")){
|
385
|
this.getReferences(identifications.item(m), dataHolder);
|
386
|
}
|
387
|
}
|
388
|
}
|
389
|
}
|
390
|
boolean hasPref=false;
|
391
|
for (int j=0; j< group.getLength(); j++){
|
392
|
if(group.item(j).getNodeName().equals("Identification")){
|
393
|
dataHolder.nomenclatureCode ="";
|
394
|
identifications = group.item(j).getChildNodes();
|
395
|
for (int m=0; m<identifications.getLength();m++){
|
396
|
if(identifications.item(m).getNodeName().equals("Result")){
|
397
|
results = identifications.item(m).getChildNodes();
|
398
|
for(int k=0; k<results.getLength();k++){
|
399
|
if (results.item(k).getNodeName().equals("TaxonIdentified")){
|
400
|
tmpName=this.getScientificName(results.item(k), dataHolder);
|
401
|
}
|
402
|
}
|
403
|
}
|
404
|
if(identifications.item(m).getNodeName().equals("PreferredFlag")){
|
405
|
hasPref=true;
|
406
|
}
|
407
|
}
|
408
|
if ( !hasPref && tmpName != null){
|
409
|
if (dataHolder.nomenclatureCode != null && dataHolder.nomenclatureCode !=""){
|
410
|
dataHolder.identificationList.add(tmpName+"_preferred_"+"0"+"_code_" + dataHolder.nomenclatureCode);
|
411
|
} else {
|
412
|
dataHolder.identificationList.add(tmpName+"_preferred_"+"0");
|
413
|
}
|
414
|
}
|
415
|
}
|
416
|
}
|
417
|
}
|
418
|
|
419
|
|
420
|
|
421
|
private void getReferences(Node result, Abcd206DataHolder dataHolder){
|
422
|
NodeList results,reference;
|
423
|
results = result.getChildNodes();
|
424
|
for(int k=0; k<results.getLength();k++){
|
425
|
if (results.item(k).getNodeName().equals("Reference")){
|
426
|
reference = results.item(k).getChildNodes();
|
427
|
for(int l=0;l<reference.getLength();l++){
|
428
|
if (reference.item(l).getNodeName().equals("TitleCitation")){
|
429
|
path = reference.item(l).getNodeName();
|
430
|
dataHolder.referenceList.add(reference.item(l).getTextContent());
|
431
|
getHierarchie(reference.item(l));
|
432
|
dataHolder.knownABCDelements.add(path);
|
433
|
path="";
|
434
|
}
|
435
|
}
|
436
|
}
|
437
|
}
|
438
|
}
|
439
|
|
440
|
private String getScientificName(Node result, Abcd206DataHolder dataHolder){
|
441
|
NodeList taxonsIdentified, scnames, atomised;
|
442
|
String tmpName = "";
|
443
|
dataHolder.atomisedStr = "";
|
444
|
taxonsIdentified = result.getChildNodes();
|
445
|
for (int l=0; l<taxonsIdentified.getLength(); l++){
|
446
|
if (taxonsIdentified.item(l).getNodeName().equals("ScientificName")){
|
447
|
scnames = taxonsIdentified.item(l).getChildNodes();
|
448
|
for (int n=0;n<scnames.getLength();n++){
|
449
|
if (scnames.item(n).getNodeName().equals("FullScientificNameString")){
|
450
|
path=scnames.item(n).getNodeName();
|
451
|
tmpName = scnames.item(n).getTextContent();
|
452
|
getHierarchie(scnames.item(n));
|
453
|
dataHolder.knownABCDelements.add(path);
|
454
|
path="";
|
455
|
}
|
456
|
if (scnames.item(n).getNodeName().equals("NameAtomised")){
|
457
|
try {
|
458
|
if (scnames.item(n).hasChildNodes()){
|
459
|
dataHolder.nomenclatureCode = scnames.item(n).getChildNodes().item(1).getNodeName();
|
460
|
}
|
461
|
} catch (Exception e) {
|
462
|
dataHolder.nomenclatureCode ="";
|
463
|
}
|
464
|
atomised = scnames.item(n).getChildNodes().item(1).getChildNodes();
|
465
|
dataHolder.atomisedIdentificationList.add(this.getAtomisedNames(dataHolder.nomenclatureCode, atomised, dataHolder));
|
466
|
}
|
467
|
}
|
468
|
}
|
469
|
}
|
470
|
return tmpName;
|
471
|
}
|
472
|
|
473
|
private HashMap<String,String> getAtomisedNames(String code, NodeList atomised, Abcd206DataHolder dataHolder){
|
474
|
if (code.equals("Botanical")){
|
475
|
return this.getAtomisedBotanical(atomised, dataHolder);
|
476
|
}
|
477
|
if (code.equals("Bacterial")){
|
478
|
return this.getAtomisedBacterial(atomised, dataHolder);
|
479
|
}
|
480
|
if (code.equals("NameViral")){
|
481
|
return this.getAtomisedViral(atomised, dataHolder);
|
482
|
}
|
483
|
if (code.equals("NameZoological")){
|
484
|
return this.getAtomisedZoological(atomised,dataHolder);
|
485
|
}
|
486
|
return new HashMap<String,String>();
|
487
|
}
|
488
|
|
489
|
private HashMap<String,String> getAtomisedZoological(NodeList atomised, Abcd206DataHolder dataHolder){
|
490
|
HashMap<String,String> atomisedMap = new HashMap<String,String>();
|
491
|
for (int i=0;i<atomised.getLength();i++){
|
492
|
if(atomised.item(i).getNodeName().equals("GenusOrMonomial")){
|
493
|
atomisedMap.put("Genus",atomised.item(i).getTextContent());
|
494
|
path=atomised.item(i).getNodeName();
|
495
|
getHierarchie(atomised.item(i));
|
496
|
dataHolder.knownABCDelements.add(path);
|
497
|
path="";
|
498
|
}
|
499
|
if(atomised.item(i).getNodeName().equals("Subgenus")){
|
500
|
atomisedMap.put("Subgenus",atomised.item(i).getTextContent());
|
501
|
path=atomised.item(i).getNodeName();
|
502
|
getHierarchie(atomised.item(i));
|
503
|
dataHolder.knownABCDelements.add(path);
|
504
|
path="";
|
505
|
}
|
506
|
if(atomised.item(i).getNodeName().equals("SpeciesEpithet")){
|
507
|
atomisedMap.put("SpeciesEpithet",atomised.item(i).getTextContent());
|
508
|
path=atomised.item(i).getNodeName();
|
509
|
getHierarchie(atomised.item(i));
|
510
|
dataHolder.knownABCDelements.add(path);
|
511
|
path="";
|
512
|
}
|
513
|
if(atomised.item(i).getNodeName().equals("SubspeciesEpithet")){
|
514
|
atomisedMap.put("SubspeciesEpithet",atomised.item(i).getTextContent());
|
515
|
path=atomised.item(i).getNodeName();
|
516
|
getHierarchie(atomised.item(i));
|
517
|
dataHolder.knownABCDelements.add(path);
|
518
|
path="";
|
519
|
}
|
520
|
if(atomised.item(i).getNodeName().equals("AuthorTeamOriginalAndYear")){
|
521
|
atomisedMap.put("AuthorTeamOriginalAndYear",atomised.item(i).getTextContent());
|
522
|
path=atomised.item(i).getNodeName();
|
523
|
getHierarchie(atomised.item(i));
|
524
|
dataHolder.knownABCDelements.add(path);
|
525
|
path="";
|
526
|
}
|
527
|
if(atomised.item(i).getNodeName().equals("AuthorTeamParenthesisAndYear")){
|
528
|
atomisedMap.put("AuthorTeamParenthesisAndYear",atomised.item(i).getTextContent());
|
529
|
path=atomised.item(i).getNodeName();
|
530
|
getHierarchie(atomised.item(i));
|
531
|
dataHolder.knownABCDelements.add(path);
|
532
|
path="";
|
533
|
}
|
534
|
if(atomised.item(i).getNodeName().equals("CombinationAuthorTeamAndYear")){
|
535
|
atomisedMap.put("CombinationAuthorTeamAndYear",atomised.item(i).getTextContent());
|
536
|
path=atomised.item(i).getNodeName();
|
537
|
getHierarchie(atomised.item(i));
|
538
|
dataHolder.knownABCDelements.add(path);
|
539
|
path="";
|
540
|
}
|
541
|
if(atomised.item(i).getNodeName().equals("Breed")){
|
542
|
atomisedMap.put("Breed",atomised.item(i).getTextContent());
|
543
|
path=atomised.item(i).getNodeName();
|
544
|
getHierarchie(atomised.item(i));
|
545
|
dataHolder.knownABCDelements.add(path);
|
546
|
path="";
|
547
|
}
|
548
|
if(atomised.item(i).getNodeName().equals("NamedIndividual")){
|
549
|
atomisedMap.put("NamedIndividual",atomised.item(i).getTextContent());
|
550
|
path=atomised.item(i).getNodeName();
|
551
|
getHierarchie(atomised.item(i));
|
552
|
dataHolder.knownABCDelements.add(path);
|
553
|
path="";
|
554
|
}
|
555
|
}
|
556
|
return atomisedMap;
|
557
|
}
|
558
|
|
559
|
private HashMap<String,String> getAtomisedViral(NodeList atomised, Abcd206DataHolder dataHolder){
|
560
|
HashMap<String,String> atomisedMap = new HashMap<String,String>();
|
561
|
for (int i=0;i<atomised.getLength();i++){
|
562
|
if(atomised.item(i).getNodeName().equals("GenusOrMonomial")){
|
563
|
atomisedMap.put("Genus",atomised.item(i).getTextContent());
|
564
|
path=atomised.item(i).getNodeName();
|
565
|
getHierarchie(atomised.item(i));
|
566
|
dataHolder.knownABCDelements.add(path);
|
567
|
path="";
|
568
|
}
|
569
|
if(atomised.item(i).getNodeName().equals("ViralSpeciesDesignation")){
|
570
|
atomisedMap.put("ViralSpeciesDesignation", atomised.item(i).getTextContent());
|
571
|
path=atomised.item(i).getNodeName();
|
572
|
getHierarchie(atomised.item(i));
|
573
|
dataHolder.knownABCDelements.add(path);
|
574
|
path="";
|
575
|
}
|
576
|
if(atomised.item(i).getNodeName().equals("Acronym")){
|
577
|
atomisedMap.put("Acronym",atomised.item(i).getTextContent());
|
578
|
path=atomised.item(i).getNodeName();
|
579
|
getHierarchie(atomised.item(i));
|
580
|
dataHolder.knownABCDelements.add(path);
|
581
|
path="";
|
582
|
}
|
583
|
}
|
584
|
return atomisedMap;
|
585
|
}
|
586
|
|
587
|
private HashMap<String,String> getAtomisedBotanical(NodeList atomised, Abcd206DataHolder dataHolder){
|
588
|
HashMap<String,String> atomisedMap = new HashMap<String,String>();
|
589
|
for (int i=0;i<atomised.getLength();i++){
|
590
|
if(atomised.item(i).getNodeName().equals("GenusOrMonomial")){
|
591
|
atomisedMap.put("Genus",atomised.item(i).getTextContent());
|
592
|
path=atomised.item(i).getNodeName();
|
593
|
getHierarchie(atomised.item(i));
|
594
|
dataHolder.knownABCDelements.add(path);
|
595
|
path="";
|
596
|
}
|
597
|
if(atomised.item(i).getNodeName().equals("FirstEpithet")){
|
598
|
atomisedMap.put("FirstEpithet",atomised.item(i).getTextContent());
|
599
|
path=atomised.item(i).getNodeName();
|
600
|
getHierarchie(atomised.item(i));
|
601
|
dataHolder.knownABCDelements.add(path);
|
602
|
path="";
|
603
|
}
|
604
|
if(atomised.item(i).getNodeName().equals("InfraspecificEpithet")){
|
605
|
atomisedMap.put("InfraSpeEpithet", atomised.item(i).getTextContent());
|
606
|
path=atomised.item(i).getNodeName();
|
607
|
getHierarchie(atomised.item(i));
|
608
|
dataHolder.knownABCDelements.add(path);
|
609
|
path="";
|
610
|
}
|
611
|
if(atomised.item(i).getNodeName().equals("Rank")){
|
612
|
atomisedMap.put("Rank",atomised.item(i).getTextContent());
|
613
|
path=atomised.item(i).getNodeName();
|
614
|
getHierarchie(atomised.item(i));
|
615
|
dataHolder.knownABCDelements.add(path);
|
616
|
path="";
|
617
|
}
|
618
|
if(atomised.item(i).getNodeName().equals("HybridFlag")){
|
619
|
atomisedMap.put("HybridFlag",atomised.item(i).getTextContent());
|
620
|
path=atomised.item(i).getNodeName();
|
621
|
getHierarchie(atomised.item(i));
|
622
|
dataHolder.knownABCDelements.add(path);
|
623
|
path="";
|
624
|
}
|
625
|
if(atomised.item(i).getNodeName().equals("AuthorTeamParenthesis")){
|
626
|
atomisedMap.put("AuthorTeamParenthesis",atomised.item(i).getTextContent());
|
627
|
path=atomised.item(i).getNodeName();
|
628
|
getHierarchie(atomised.item(i));
|
629
|
dataHolder.knownABCDelements.add(path);
|
630
|
path="";
|
631
|
}
|
632
|
if(atomised.item(i).getNodeName().equals("AuthorTeam")){
|
633
|
atomisedMap.put("AuthorTeam",atomised.item(i).getTextContent());
|
634
|
path=atomised.item(i).getNodeName();
|
635
|
getHierarchie(atomised.item(i));
|
636
|
dataHolder.knownABCDelements.add(path);
|
637
|
path="";
|
638
|
}
|
639
|
if(atomised.item(i).getNodeName().equals("CultivarGroupName")){
|
640
|
atomisedMap.put("CultivarGroupName",atomised.item(i).getTextContent());
|
641
|
path=atomised.item(i).getNodeName();
|
642
|
getHierarchie(atomised.item(i));
|
643
|
dataHolder.knownABCDelements.add(path);
|
644
|
path="";
|
645
|
}
|
646
|
if(atomised.item(i).getNodeName().equals("CultivarName")){
|
647
|
atomisedMap.put("CultivarName",atomised.item(i).getTextContent());
|
648
|
path=atomised.item(i).getNodeName();
|
649
|
getHierarchie(atomised.item(i));
|
650
|
dataHolder.knownABCDelements.add(path);
|
651
|
path="";
|
652
|
}
|
653
|
if(atomised.item(i).getNodeName().equals("TradeDesignationNames")){
|
654
|
atomisedMap.put("Trade",atomised.item(i).getTextContent());
|
655
|
path=atomised.item(i).getNodeName();
|
656
|
getHierarchie(atomised.item(i));
|
657
|
dataHolder.knownABCDelements.add(path);
|
658
|
path="";
|
659
|
}
|
660
|
}
|
661
|
return atomisedMap;
|
662
|
}
|
663
|
|
664
|
private HashMap<String,String> getAtomisedBacterial(NodeList atomised, Abcd206DataHolder dataHolder){
|
665
|
HashMap<String,String> atomisedMap = new HashMap<String,String>();
|
666
|
for (int i=0;i<atomised.getLength();i++){
|
667
|
if(atomised.item(i).getNodeName().equals("GenusOrMonomial")){
|
668
|
atomisedMap.put("Genus",atomised.item(i).getTextContent());
|
669
|
path=atomised.item(i).getNodeName();
|
670
|
getHierarchie(atomised.item(i));
|
671
|
dataHolder.knownABCDelements.add(path);
|
672
|
path="";
|
673
|
}
|
674
|
if(atomised.item(i).getNodeName().equals("Subgenus")){
|
675
|
atomisedMap.put("SubGenus",atomised.item(i).getTextContent());
|
676
|
path=atomised.item(i).getNodeName();
|
677
|
getHierarchie(atomised.item(i));
|
678
|
dataHolder.knownABCDelements.add(path);
|
679
|
path="";
|
680
|
}
|
681
|
if(atomised.item(i).getNodeName().equals("SubgenusAuthorAndYear")){
|
682
|
atomisedMap.put("SubgenusAuthorAndYear",atomised.item(i).getTextContent());
|
683
|
path=atomised.item(i).getNodeName();
|
684
|
getHierarchie(atomised.item(i));
|
685
|
dataHolder.knownABCDelements.add(path);
|
686
|
path="";
|
687
|
}
|
688
|
if(atomised.item(i).getNodeName().equals("SpeciesEpithet")){
|
689
|
atomisedMap.put("SpeciesEpithet",atomised.item(i).getTextContent());
|
690
|
path=atomised.item(i).getNodeName();
|
691
|
getHierarchie(atomised.item(i));
|
692
|
dataHolder.knownABCDelements.add(path);
|
693
|
path="";
|
694
|
}
|
695
|
if(atomised.item(i).getNodeName().equals("SubspeciesEpithet")){
|
696
|
atomisedMap.put("SubspeciesEpithet",atomised.item(i).getTextContent());
|
697
|
path=atomised.item(i).getNodeName();
|
698
|
getHierarchie(atomised.item(i));
|
699
|
dataHolder.knownABCDelements.add(path);
|
700
|
path="";
|
701
|
}
|
702
|
if(atomised.item(i).getNodeName().equals("ParentheticalAuthorTeamAndYear")){
|
703
|
atomisedMap.put("ParentheticalAuthorTeamAndYear",atomised.item(i).getTextContent());
|
704
|
path=atomised.item(i).getNodeName();
|
705
|
getHierarchie(atomised.item(i));
|
706
|
dataHolder.knownABCDelements.add(path);
|
707
|
path="";
|
708
|
}
|
709
|
if(atomised.item(i).getNodeName().equals("AuthorTeamAndYear")){
|
710
|
atomisedMap.put("AuthorTeamAndYear",atomised.item(i).getTextContent());
|
711
|
path=atomised.item(i).getNodeName();
|
712
|
getHierarchie(atomised.item(i));
|
713
|
dataHolder.knownABCDelements.add(path);
|
714
|
path="";
|
715
|
}
|
716
|
if(atomised.item(i).getNodeName().equals("NameApprobation")){
|
717
|
atomisedMap.put("NameApprobation",atomised.item(i).getTextContent());
|
718
|
path=atomised.item(i).getNodeName();
|
719
|
getHierarchie(atomised.item(i));
|
720
|
dataHolder.knownABCDelements.add(path);
|
721
|
path="";
|
722
|
}
|
723
|
}
|
724
|
return atomisedMap;
|
725
|
}
|
726
|
|
727
|
private void getIDs(Element root, Abcd206DataHolder dataHolder){
|
728
|
NodeList group;
|
729
|
try {
|
730
|
group = root.getElementsByTagName("SourceInstitutionID");
|
731
|
path=group.item(0).getNodeName();
|
732
|
getHierarchie(group.item(0));
|
733
|
dataHolder.knownABCDelements.add(path);
|
734
|
path="";
|
735
|
dataHolder.institutionCode = group.item(0).getTextContent();
|
736
|
} catch (NullPointerException e) {
|
737
|
dataHolder.institutionCode= "";
|
738
|
}
|
739
|
try {
|
740
|
group = root.getElementsByTagName("SourceID");
|
741
|
path=group.item(0).getNodeName();
|
742
|
getHierarchie(group.item(0));
|
743
|
dataHolder.knownABCDelements.add(path);
|
744
|
path="";
|
745
|
dataHolder.collectionCode = group.item(0).getTextContent();
|
746
|
} catch (NullPointerException e) {
|
747
|
dataHolder.collectionCode = "";
|
748
|
}
|
749
|
try {
|
750
|
group = root.getElementsByTagName("UnitID");
|
751
|
path=group.item(0).getNodeName();
|
752
|
getHierarchie(group.item(0));
|
753
|
dataHolder.knownABCDelements.add(path);
|
754
|
path="";
|
755
|
dataHolder.unitID = group.item(0).getTextContent();
|
756
|
} catch (NullPointerException e) {
|
757
|
dataHolder.unitID = "";
|
758
|
}
|
759
|
}
|
760
|
|
761
|
private void getRecordBasis(Element root, Abcd206DataHolder dataHolder){
|
762
|
NodeList group;
|
763
|
try {
|
764
|
group = root.getElementsByTagName("RecordBasis");
|
765
|
path=group.item(0).getNodeName();
|
766
|
getHierarchie(group.item(0));
|
767
|
dataHolder.knownABCDelements.add(path);
|
768
|
path="";
|
769
|
dataHolder.recordBasis = group.item(0).getTextContent();
|
770
|
} catch (NullPointerException e) {
|
771
|
dataHolder.recordBasis = "";
|
772
|
}
|
773
|
}
|
774
|
|
775
|
private void getMultimedia(Element root, Abcd206DataHolder dataHolder){
|
776
|
NodeList group, multimedias, multimedia;
|
777
|
try {
|
778
|
group = root.getElementsByTagName("MultiMediaObjects");
|
779
|
for(int i=0;i<group.getLength();i++){
|
780
|
multimedias = group.item(i).getChildNodes();
|
781
|
for (int j=0;j<multimedias.getLength();j++){
|
782
|
if (multimedias.item(j).getNodeName().equals("MultiMediaObject")){
|
783
|
multimedia = multimedias.item(j).getChildNodes();
|
784
|
for (int k=0;k<multimedia.getLength();k++){
|
785
|
if(multimedia.item(k).getNodeName().equals("FileURI")){
|
786
|
dataHolder.multimediaObjects.add(multimedia.item(k).getTextContent());
|
787
|
path = multimedia.item(k).getNodeName();
|
788
|
getHierarchie(multimedia.item(k));
|
789
|
dataHolder.knownABCDelements.add(path);
|
790
|
path="";
|
791
|
}
|
792
|
}
|
793
|
}
|
794
|
}
|
795
|
}
|
796
|
} catch (NullPointerException e) {
|
797
|
logger.info(e);
|
798
|
}
|
799
|
}
|
800
|
|
801
|
private void getNumbers(Element root, Abcd206DataHolder dataHolder){
|
802
|
NodeList group;
|
803
|
try {
|
804
|
group = root.getElementsByTagName("AccessionNumber");
|
805
|
path=group.item(0).getNodeName();
|
806
|
getHierarchie(group.item(0));
|
807
|
dataHolder.knownABCDelements.add(path);
|
808
|
path="";
|
809
|
dataHolder.accessionNumber = group.item(0).getTextContent();
|
810
|
} catch (NullPointerException e) {
|
811
|
dataHolder.accessionNumber = "";
|
812
|
}
|
813
|
try {
|
814
|
group = root.getElementsByTagName("CollectorsFieldNumber");
|
815
|
path=group.item(0).getNodeName();
|
816
|
getHierarchie(group.item(0));
|
817
|
dataHolder.knownABCDelements.add(path);
|
818
|
path="";
|
819
|
dataHolder.fieldNumber = group.item(0).getTextContent();
|
820
|
} catch (NullPointerException e) {
|
821
|
dataHolder.fieldNumber = "";
|
822
|
}
|
823
|
|
824
|
try {
|
825
|
group = root.getElementsByTagName("CollectorsNumber");
|
826
|
path=group.item(0).getNodeName();
|
827
|
getHierarchie(group.item(0));
|
828
|
dataHolder.knownABCDelements.add(path);
|
829
|
path="";
|
830
|
dataHolder.collectorsNumber = group.item(0).getTextContent();
|
831
|
} catch (NullPointerException e) {
|
832
|
dataHolder.collectorsNumber = "";
|
833
|
}
|
834
|
|
835
|
try {
|
836
|
group = root.getElementsByTagName("AccessionNumber");
|
837
|
path=group.item(0).getNodeName();
|
838
|
getHierarchie(group.item(0));
|
839
|
dataHolder.knownABCDelements.add(path);
|
840
|
path="";
|
841
|
dataHolder.accessionNumber = group.item(0).getTextContent();
|
842
|
} catch (NullPointerException e) {
|
843
|
dataHolder.accessionNumber = "";
|
844
|
}
|
845
|
}
|
846
|
|
847
|
private void getGeolocation(Element root, Abcd206DataHolder dataHolder){
|
848
|
NodeList group, childs;
|
849
|
try {
|
850
|
group = root.getElementsByTagName("LocalityText");
|
851
|
path=group.item(0).getNodeName();
|
852
|
getHierarchie(group.item(0));
|
853
|
dataHolder.knownABCDelements.add(path);
|
854
|
path="";
|
855
|
dataHolder.locality = group.item(0).getTextContent();
|
856
|
if (group.item(0).hasAttributes())
|
857
|
if (group.item(0).getAttributes().getNamedItem("lang") != null)
|
858
|
dataHolder.languageIso = group.item(0).getAttributes().getNamedItem("lang").getTextContent();
|
859
|
} catch (NullPointerException e) {
|
860
|
dataHolder.locality = "";
|
861
|
}
|
862
|
try {
|
863
|
group = root.getElementsByTagName("LongitudeDecimal");
|
864
|
path=group.item(0).getNodeName();
|
865
|
getHierarchie(group.item(0));
|
866
|
dataHolder.knownABCDelements.add(path);
|
867
|
path="";
|
868
|
dataHolder.longitude = Double.valueOf(group.item(0).getTextContent());
|
869
|
} catch (NullPointerException e) {
|
870
|
dataHolder.longitude=0.0;
|
871
|
}
|
872
|
try {
|
873
|
group = root.getElementsByTagName("LatitudeDecimal");
|
874
|
path=group.item(0).getNodeName();
|
875
|
getHierarchie(group.item(0));
|
876
|
dataHolder.knownABCDelements.add(path);
|
877
|
path="";
|
878
|
dataHolder.latitude = Double.valueOf(group.item(0).getTextContent());
|
879
|
} catch (NullPointerException e) {
|
880
|
dataHolder.latitude=0.0;
|
881
|
}
|
882
|
try {
|
883
|
group = root.getElementsByTagName("Country");
|
884
|
childs = group.item(0).getChildNodes();
|
885
|
for (int i=0;i<childs.getLength(); i++){
|
886
|
if(childs.item(i).getNodeName() == "Name"){
|
887
|
path=childs.item(i).getNodeName();
|
888
|
getHierarchie(childs.item(i));
|
889
|
dataHolder.knownABCDelements.add(path);
|
890
|
path="";
|
891
|
dataHolder.country = childs.item(i).getTextContent();
|
892
|
}
|
893
|
}
|
894
|
} catch (NullPointerException e) {
|
895
|
dataHolder.country = "";
|
896
|
}
|
897
|
try {
|
898
|
group = root.getElementsByTagName("Country");
|
899
|
childs = group.item(0).getChildNodes();
|
900
|
for (int i=0;i<childs.getLength(); i++){
|
901
|
if(childs.item(i).getNodeName() == "ISO3166Code"){
|
902
|
path=childs.item(i).getNodeName();
|
903
|
getHierarchie(childs.item(i));
|
904
|
dataHolder.knownABCDelements.add(path);
|
905
|
path="";
|
906
|
dataHolder.isocountry = childs.item(i).getTextContent();
|
907
|
}
|
908
|
}
|
909
|
} catch (NullPointerException e) {
|
910
|
dataHolder.isocountry = "";
|
911
|
}
|
912
|
try {
|
913
|
group = root.getElementsByTagName("Altitude");
|
914
|
for (int i=0;i<group.getLength();i++){
|
915
|
childs = group.item(i).getChildNodes();
|
916
|
for (int j=0;j<childs.getLength();j++){
|
917
|
if (childs.item(j).getNodeName().equals("MeasurementOrFactText")){
|
918
|
path=childs.item(j).getNodeName();
|
919
|
getHierarchie(childs.item(j));
|
920
|
dataHolder.knownABCDelements.add(path);
|
921
|
path="";
|
922
|
dataHolder.altitude = Integer.valueOf(childs.item(j).getTextContent());
|
923
|
}
|
924
|
}
|
925
|
}
|
926
|
} catch (NullPointerException e) {
|
927
|
dataHolder.altitude = -9999;
|
928
|
}
|
929
|
|
930
|
try {
|
931
|
group = root.getElementsByTagName("Depth");
|
932
|
path=group.item(0).getNodeName();
|
933
|
getHierarchie(group.item(0));
|
934
|
dataHolder.knownABCDelements.add(path);
|
935
|
path="";
|
936
|
dataHolder.depth = Integer.valueOf(group.item(0).getTextContent());
|
937
|
} catch (NullPointerException e) {
|
938
|
dataHolder.depth = -9999;
|
939
|
}
|
940
|
|
941
|
try{
|
942
|
group = root.getElementsByTagName("NamedArea");
|
943
|
dataHolder.namedAreaList = new ArrayList<String>();
|
944
|
for (int i=0;i<group.getLength();i++){
|
945
|
childs = group.item(i).getChildNodes();
|
946
|
for (int j=0; j<childs.getLength();j++){
|
947
|
if (childs.item(j).getNodeName().equals("AreaName")){
|
948
|
path = childs.item(j).getNodeName();
|
949
|
getHierarchie(childs.item(j));
|
950
|
dataHolder.knownABCDelements.add(path);
|
951
|
path="";
|
952
|
dataHolder.namedAreaList.add(childs.item(j).getTextContent());
|
953
|
}
|
954
|
}
|
955
|
}
|
956
|
}catch(NullPointerException e){
|
957
|
dataHolder.namedAreaList = new ArrayList<String>();
|
958
|
}
|
959
|
}
|
960
|
|
961
|
private void getGatheringPeople(Element root, Abcd206DataHolder dataHolder){
|
962
|
NodeList group, childs, person;
|
963
|
try {
|
964
|
group = root.getElementsByTagName("GatheringAgent");
|
965
|
dataHolder.gatheringAgentList = new ArrayList<String>();
|
966
|
for (int i=0; i< group.getLength(); i++){
|
967
|
childs = group.item(i).getChildNodes();
|
968
|
for (int j=0; j<childs.getLength();j++){
|
969
|
if (childs.item(j).getNodeName().equals("Person")){
|
970
|
person = childs.item(j).getChildNodes();
|
971
|
for (int k=0; k<person.getLength(); k++){
|
972
|
if (person.item(k).getNodeName().equals("FullName")){
|
973
|
path=person.item(k).getNodeName();
|
974
|
getHierarchie(person.item(k));
|
975
|
dataHolder.knownABCDelements.add(path);
|
976
|
path="";
|
977
|
dataHolder.gatheringAgentList.add(person.item(k).getTextContent());
|
978
|
}
|
979
|
}
|
980
|
}
|
981
|
|
982
|
}
|
983
|
}
|
984
|
} catch (NullPointerException e) {
|
985
|
dataHolder.gatheringAgentList = new ArrayList<String>();
|
986
|
}
|
987
|
}
|
988
|
|
989
|
private Institution getInstitution(String institutionCode, Abcd206ImportConfigurator config, Abcd206DataHolder dataHolder){
|
990
|
Institution institution;
|
991
|
List<Institution> institutions;
|
992
|
try{
|
993
|
logger.info(dataHolder.institutionCode);
|
994
|
institutions = getAgentService().searchInstitutionByCode(dataHolder.institutionCode);
|
995
|
}catch(Exception e){
|
996
|
institutions=new ArrayList<Institution>();
|
997
|
}
|
998
|
if (institutions.size() ==0 || !config.getReUseExistingMetadata()){
|
999
|
logger.info("Institution (agent) unknown or not allowed to reuse existing metadata");
|
1000
|
//create institution
|
1001
|
institution = Institution.NewInstance();
|
1002
|
institution.setCode(dataHolder.institutionCode);
|
1003
|
}
|
1004
|
else{
|
1005
|
logger.info("Institution (agent) already in the db");
|
1006
|
institution = institutions.get(0);
|
1007
|
}
|
1008
|
return institution;
|
1009
|
}
|
1010
|
|
1011
|
/*
|
1012
|
* Look if the Collection does already exists
|
1013
|
* @param collectionCode: a string
|
1014
|
* @param institution: the current Institution
|
1015
|
* @param app
|
1016
|
* @return the Collection (existing or new)
|
1017
|
*/
|
1018
|
private Collection getCollection(String collectionCode, Institution institution, Abcd206ImportConfigurator config, Abcd206DataHolder dataHolder){
|
1019
|
Collection collection = Collection.NewInstance();
|
1020
|
List<Collection> collections;
|
1021
|
try{
|
1022
|
collections = getCollectionService().searchByCode(dataHolder.collectionCode);
|
1023
|
}catch(Exception e){
|
1024
|
collections=new ArrayList<Collection>();
|
1025
|
}
|
1026
|
if (collections.size() ==0 || !config.getReUseExistingMetadata()){
|
1027
|
logger.info("Collection not found or do not reuse existing metadata " + dataHolder.collectionCode);
|
1028
|
//create new collection
|
1029
|
collection.setCode(dataHolder.collectionCode);
|
1030
|
collection.setCodeStandard("GBIF");
|
1031
|
collection.setInstitute(institution);
|
1032
|
}
|
1033
|
else{
|
1034
|
boolean collectionFound=false;
|
1035
|
for (int i=0; i<collections.size(); i++){
|
1036
|
collection = collections.get(i);
|
1037
|
try {
|
1038
|
if (collection.getInstitute().getCode().equalsIgnoreCase(institution.getCode())){
|
1039
|
//found a collection with the same code and the same institution
|
1040
|
collectionFound=true;
|
1041
|
}
|
1042
|
} catch (NullPointerException e) {}
|
1043
|
}
|
1044
|
if (!collectionFound){
|
1045
|
collection.setCode(dataHolder.collectionCode);
|
1046
|
collection.setCodeStandard("GBIF");
|
1047
|
collection.setInstitute(institution);
|
1048
|
}
|
1049
|
|
1050
|
}
|
1051
|
return collection;
|
1052
|
}
|
1053
|
|
1054
|
/*
|
1055
|
*
|
1056
|
* @param app
|
1057
|
* @param derivedThing
|
1058
|
* @param sec
|
1059
|
*/
|
1060
|
private void handleIdentifications(Abcd206ImportConfigurator config, DerivedUnitFacade facade, ReferenceBase sec, Abcd206DataHolder dataHolder){
|
1061
|
NonViralName<?> taxonName = null;
|
1062
|
String fullScientificNameString;
|
1063
|
Taxon taxon = null;
|
1064
|
DeterminationEvent determinationEvent = null;
|
1065
|
List<TaxonBase> names = null;
|
1066
|
|
1067
|
String scientificName="";
|
1068
|
boolean preferredFlag=false;
|
1069
|
|
1070
|
for (int i = 0; i < dataHolder.identificationList.size(); i++) {
|
1071
|
fullScientificNameString = dataHolder.identificationList.get(i);
|
1072
|
fullScientificNameString = fullScientificNameString.replaceAll(" et ", " & ");
|
1073
|
if (fullScientificNameString.indexOf("_preferred_") != -1){
|
1074
|
scientificName = fullScientificNameString.split("_preferred_")[0];
|
1075
|
String pTmp = fullScientificNameString.split("_preferred_")[1].split("_code_")[0];
|
1076
|
if (pTmp.equals("1") || pTmp.toLowerCase().indexOf("true") != -1){
|
1077
|
preferredFlag=true;
|
1078
|
} else {
|
1079
|
preferredFlag=false;
|
1080
|
}
|
1081
|
}
|
1082
|
else{
|
1083
|
scientificName = fullScientificNameString;
|
1084
|
}
|
1085
|
logger.info(fullScientificNameString);
|
1086
|
if (fullScientificNameString.indexOf("_code_") != -1){
|
1087
|
dataHolder.nomenclatureCode = fullScientificNameString.split("_code_")[1];
|
1088
|
}
|
1089
|
if (config.getDoAutomaticParsing() || dataHolder.atomisedIdentificationList == null || dataHolder.atomisedIdentificationList.size()==0){
|
1090
|
taxonName = this.parseScientificName(scientificName, dataHolder);
|
1091
|
} else {
|
1092
|
if (dataHolder.atomisedIdentificationList != null || dataHolder.atomisedIdentificationList.size()>0){
|
1093
|
taxonName = this.setTaxonNameByType(dataHolder.atomisedIdentificationList.get(i), scientificName, dataHolder);
|
1094
|
}
|
1095
|
}
|
1096
|
if(taxonName == null){
|
1097
|
taxonName = NonViralName.NewInstance(null);
|
1098
|
taxonName.setFullTitleCache(scientificName);
|
1099
|
}
|
1100
|
if (config.getDoReUseTaxon()){
|
1101
|
try{
|
1102
|
names = getTaxonService().searchTaxaByName(scientificName, sec);
|
1103
|
taxon = (Taxon)names.get(0);
|
1104
|
} catch(Exception e){
|
1105
|
taxon=null;
|
1106
|
}
|
1107
|
}
|
1108
|
// taxonName = NonViralName.NewInstance(null);
|
1109
|
// taxonName.setFullTitleCache(scientificName);
|
1110
|
|
1111
|
if (!config.getDoReUseTaxon() || taxon == null){
|
1112
|
getNameService().save(taxonName);
|
1113
|
taxon = Taxon.NewInstance(taxonName, sec); //TODO sec set null
|
1114
|
}
|
1115
|
determinationEvent = DeterminationEvent.NewInstance();
|
1116
|
determinationEvent.setTaxon(taxon);
|
1117
|
determinationEvent.setPreferredFlag(preferredFlag);
|
1118
|
|
1119
|
for (String strReference : dataHolder.referenceList){
|
1120
|
|
1121
|
ReferenceBase reference = ReferenceFactory.newGeneric();
|
1122
|
reference.setTitleCache(strReference, true);
|
1123
|
determinationEvent.addReference(reference);
|
1124
|
}
|
1125
|
facade.addDetermination(determinationEvent);
|
1126
|
}
|
1127
|
|
1128
|
}
|
1129
|
|
1130
|
private NonViralName<?> parseScientificName(String scientificName, Abcd206DataHolder dataHolder){
|
1131
|
NonViralNameParserImpl nvnpi = NonViralNameParserImpl.NewInstance();
|
1132
|
NonViralName<?>taxonName = null;
|
1133
|
boolean problem=false;
|
1134
|
|
1135
|
if (dataHolder.nomenclatureCode.toString().equals("Zoological")){
|
1136
|
taxonName = (ZoologicalName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICZN,null);
|
1137
|
if (taxonName.hasProblem()){
|
1138
|
problem=true;
|
1139
|
}
|
1140
|
}
|
1141
|
if (dataHolder.nomenclatureCode.toString().equals("Botanical")){
|
1142
|
taxonName = (BotanicalName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICBN,null);
|
1143
|
if (taxonName.hasProblem()){
|
1144
|
problem=true;;
|
1145
|
}
|
1146
|
}
|
1147
|
if (dataHolder.nomenclatureCode.toString().equals("Bacterial")){
|
1148
|
taxonName = (BacterialName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICNB, null);
|
1149
|
if (taxonName.hasProblem()){
|
1150
|
problem=true;
|
1151
|
}
|
1152
|
}
|
1153
|
if (dataHolder.nomenclatureCode.toString().equals("Cultivar")){
|
1154
|
taxonName = (CultivarPlantName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICNCP, null);
|
1155
|
if (taxonName.hasProblem()){
|
1156
|
problem=true;
|
1157
|
}
|
1158
|
}
|
1159
|
// if (this.nomenclatureCode.toString().equals("Viral")){
|
1160
|
// ViralName taxonName = (ViralName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICVCN(), null);
|
1161
|
// if (taxonName.hasProblem())
|
1162
|
// logger.info("pb ICVCN");
|
1163
|
// }
|
1164
|
//TODO: parsing of ViralNames?
|
1165
|
if(problem){
|
1166
|
taxonName = NonViralName.NewInstance(null);
|
1167
|
taxonName.setTitleCache(scientificName, true);
|
1168
|
}
|
1169
|
return taxonName;
|
1170
|
|
1171
|
}
|
1172
|
|
1173
|
private NonViralName<?> setTaxonNameByType(HashMap<String, String> atomisedMap,String fullName, Abcd206DataHolder dataHolder){
|
1174
|
if (dataHolder.nomenclatureCode.equals("Zoological")){
|
1175
|
NonViralName<ZoologicalName> taxonName = ZoologicalName.NewInstance(null);
|
1176
|
taxonName.setFullTitleCache(fullName, true);
|
1177
|
taxonName.setGenusOrUninomial(getFromMap(atomisedMap,"Genus"));
|
1178
|
taxonName.setInfraGenericEpithet(getFromMap(atomisedMap,"SubGenus"));
|
1179
|
taxonName.setSpecificEpithet(getFromMap(atomisedMap,"SpeciesEpithet"));
|
1180
|
taxonName.setInfraSpecificEpithet(getFromMap(atomisedMap,"SubspeciesEpithet"));
|
1181
|
Team team = null;
|
1182
|
if(getFromMap(atomisedMap,"AuthorTeamParenthesis") != null){
|
1183
|
team = Team.NewInstance();
|
1184
|
team.setTitleCache(getFromMap(atomisedMap,"AuthorTeamParenthesis"), true);
|
1185
|
}else{
|
1186
|
if (getFromMap(atomisedMap,"AuthorTeamAndYear") != null){
|
1187
|
team = Team.NewInstance();
|
1188
|
team.setTitleCache(getFromMap(atomisedMap,"AuthorTeamAndYear"), true);
|
1189
|
}
|
1190
|
}
|
1191
|
if(team != null){
|
1192
|
taxonName.setBasionymAuthorTeam(team);
|
1193
|
}else{
|
1194
|
if(getFromMap(atomisedMap,"AuthorTeamParenthesis") != null){
|
1195
|
taxonName.setAuthorshipCache(getFromMap(atomisedMap,"AuthorTeamParenthesis"));
|
1196
|
} else if (getFromMap(atomisedMap,"AuthorTeamAndYear") != null){
|
1197
|
taxonName.setAuthorshipCache(getFromMap(atomisedMap,"AuthorTeamAndYear"));
|
1198
|
}
|
1199
|
}
|
1200
|
if(getFromMap(atomisedMap,"CombinationAuthorTeamAndYear") != null){
|
1201
|
team = Team.NewInstance();
|
1202
|
team.setTitleCache(getFromMap(atomisedMap,"CombinationAuthorTeamAndYear"), true);
|
1203
|
taxonName.setCombinationAuthorTeam(team);
|
1204
|
}
|
1205
|
if (taxonName.hasProblem()){
|
1206
|
logger.info("pb ICZN");
|
1207
|
}else{
|
1208
|
return taxonName;
|
1209
|
}
|
1210
|
}
|
1211
|
if (dataHolder.nomenclatureCode.equals("Botanical")){
|
1212
|
NonViralName<BotanicalName> taxonName = BotanicalName.NewInstance(null);
|
1213
|
taxonName.setFullTitleCache(fullName, true);
|
1214
|
taxonName.setGenusOrUninomial(getFromMap(atomisedMap,"Genus"));
|
1215
|
taxonName.setInfraGenericEpithet(getFromMap(atomisedMap,"FirstEpithet"));
|
1216
|
taxonName.setInfraSpecificEpithet(getFromMap(atomisedMap,"InfraSpeEpithet"));
|
1217
|
try{taxonName.setRank(Rank.getRankByName(getFromMap(atomisedMap,"Rank")));
|
1218
|
}catch(Exception e){}
|
1219
|
Team team = null;
|
1220
|
if(getFromMap(atomisedMap,"AuthorTeamParenthesis") != null){
|
1221
|
team = Team.NewInstance();
|
1222
|
team.setTitleCache(getFromMap(atomisedMap,"AuthorTeamParenthesis"), true);
|
1223
|
if(team != null){
|
1224
|
taxonName.setBasionymAuthorTeam(team);
|
1225
|
}
|
1226
|
}
|
1227
|
if (getFromMap(atomisedMap,"AuthorTeam") != null){
|
1228
|
team = Team.NewInstance();
|
1229
|
team.setTitleCache(getFromMap(atomisedMap,"AuthorTeam"), true);
|
1230
|
if(team != null){
|
1231
|
taxonName.setCombinationAuthorTeam(team);
|
1232
|
}
|
1233
|
}
|
1234
|
if (team == null) {
|
1235
|
if(getFromMap(atomisedMap,"AuthorTeamParenthesis") != null){
|
1236
|
taxonName.setAuthorshipCache(getFromMap(atomisedMap,"AuthorTeamParenthesis"));
|
1237
|
}else if (getFromMap(atomisedMap,"AuthorTeam") != null){
|
1238
|
taxonName.setAuthorshipCache(getFromMap(atomisedMap,"AuthorTeam"));
|
1239
|
}
|
1240
|
}
|
1241
|
if(getFromMap(atomisedMap,"CombinationAuthorTeamAndYear") != null){
|
1242
|
team = Team.NewInstance();
|
1243
|
team.setTitleCache(getFromMap(atomisedMap,"CombinationAuthorTeamAndYear"), true);
|
1244
|
taxonName.setCombinationAuthorTeam(team);
|
1245
|
}
|
1246
|
if (taxonName.hasProblem()){
|
1247
|
logger.info("pb ICBN");
|
1248
|
}else {
|
1249
|
return taxonName;
|
1250
|
}
|
1251
|
}
|
1252
|
if (dataHolder.nomenclatureCode.equals("Bacterial")){
|
1253
|
NonViralName<BacterialName> taxonName = BacterialName.NewInstance(null);
|
1254
|
taxonName.setFullTitleCache(fullName, true);
|
1255
|
taxonName.setGenusOrUninomial(getFromMap(atomisedMap,"Genus"));
|
1256
|
taxonName.setInfraGenericEpithet(getFromMap(atomisedMap,"SubGenus"));
|
1257
|
taxonName.setSpecificEpithet(getFromMap(atomisedMap,"Species"));
|
1258
|
taxonName.setInfraSpecificEpithet(getFromMap(atomisedMap,"SubspeciesEpithet"));
|
1259
|
if(getFromMap(atomisedMap,"AuthorTeamAndYear") != null){
|
1260
|
Team team = Team.NewInstance();
|
1261
|
team.setTitleCache(getFromMap(atomisedMap,"AuthorTeamAndYear"), true);
|
1262
|
taxonName.setCombinationAuthorTeam(team);
|
1263
|
}
|
1264
|
if(getFromMap(atomisedMap,"ParentheticalAuthorTeamAndYear") != null){
|
1265
|
Team team = Team.NewInstance();
|
1266
|
team.setTitleCache(getFromMap(atomisedMap,"ParentheticalAuthorTeamAndYear"), true);
|
1267
|
taxonName.setBasionymAuthorTeam(team);
|
1268
|
}
|
1269
|
if (taxonName.hasProblem()){
|
1270
|
logger.info("pb ICNB");
|
1271
|
}else{
|
1272
|
return taxonName;
|
1273
|
}
|
1274
|
}
|
1275
|
if (dataHolder.nomenclatureCode.equals("Cultivar")){
|
1276
|
CultivarPlantName taxonName = CultivarPlantName.NewInstance(null);
|
1277
|
|
1278
|
if (taxonName.hasProblem()){
|
1279
|
logger.info("pb ICNCP");
|
1280
|
}else {
|
1281
|
return taxonName;
|
1282
|
}
|
1283
|
}
|
1284
|
// if (this.nomenclatureCode.equals("Viral")){
|
1285
|
// ViralName taxonName = ViralName.NewInstance(null);
|
1286
|
// taxonName.setFullTitleCache(fullName, true);
|
1287
|
// taxonName.setAcronym(getFromMap(atomisedMap,"Acronym"));
|
1288
|
// if (taxonName.hasProblem())
|
1289
|
// logger.info("pb ICVCN");
|
1290
|
// else return taxonName;
|
1291
|
// }
|
1292
|
//TODO ViralName
|
1293
|
NonViralName<?>taxonName = NonViralName.NewInstance(null);
|
1294
|
taxonName.setFullTitleCache(fullName, true);
|
1295
|
return taxonName;
|
1296
|
}
|
1297
|
|
1298
|
private String getFromMap(HashMap<String, String> atomisedMap, String key){
|
1299
|
String value = null;
|
1300
|
if (atomisedMap.containsKey(key)){
|
1301
|
value = atomisedMap.get(key);
|
1302
|
}
|
1303
|
try{
|
1304
|
if (value != null && key.matches(".*Year.*")){
|
1305
|
value=value.trim();
|
1306
|
if (value.matches("[a-z A-Z ]*[0-9]{4}$")){
|
1307
|
String tmp=value.split("[0-9]{4}$")[0];
|
1308
|
int year = Integer.parseInt(value.split(tmp)[1]);
|
1309
|
if (year >= 1752){
|
1310
|
value=tmp;
|
1311
|
}else{
|
1312
|
value=null;
|
1313
|
}
|
1314
|
}else{
|
1315
|
value=null;
|
1316
|
}
|
1317
|
}
|
1318
|
}catch(Exception e){value=null;}
|
1319
|
|
1320
|
return value;
|
1321
|
}
|
1322
|
|
1323
|
private void compareABCDtoCDM(String urlFileName, ArrayList<String> knownElts, Abcd206DataHolder dataHolder){
|
1324
|
|
1325
|
try {
|
1326
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
1327
|
DocumentBuilder constructeur = factory.newDocumentBuilder();
|
1328
|
URL url = new URL(urlFileName);
|
1329
|
Object o = url.getContent();
|
1330
|
InputStream is = (InputStream)o;
|
1331
|
Document document = constructeur.parse(is);
|
1332
|
Element root = document.getDocumentElement();
|
1333
|
traverse(root, dataHolder);
|
1334
|
} catch (ParserConfigurationException e) {
|
1335
|
e.printStackTrace();
|
1336
|
} catch (SAXException e) {
|
1337
|
e.printStackTrace();
|
1338
|
} catch (IOException e) {
|
1339
|
e.printStackTrace();
|
1340
|
}
|
1341
|
Set<String> elts = dataHolder.allABCDelements.keySet();
|
1342
|
Iterator< String>it = elts.iterator();
|
1343
|
String elt;
|
1344
|
while (it.hasNext()){
|
1345
|
elt = it.next();
|
1346
|
if (knownElts.indexOf(elt) == -1){
|
1347
|
logger.info("Unsaved ABCD element: " + elt + " - " + dataHolder.allABCDelements.get(elt));
|
1348
|
}
|
1349
|
}
|
1350
|
}
|
1351
|
|
1352
|
|
1353
|
|
1354
|
/**
|
1355
|
* Traverses the tree for compareABCDtoCDM
|
1356
|
* @param node
|
1357
|
* @param dataHolder
|
1358
|
*/
|
1359
|
private void traverse(Node node, Abcd206DataHolder dataHolder){
|
1360
|
// Extract node info:
|
1361
|
String test = node.getTextContent();
|
1362
|
|
1363
|
// Print and continue traversing.
|
1364
|
if(test != null && test != "#text" && node.getNodeName() != "#text" && test.split("\n").length==1 && test.length()>0){
|
1365
|
path=node.getNodeName();
|
1366
|
getHierarchie(node);
|
1367
|
dataHolder.allABCDelements.put(path,test);
|
1368
|
path="";
|
1369
|
}
|
1370
|
// Now traverse the rest of the tree in depth-first order.
|
1371
|
if (node.hasChildNodes()) {
|
1372
|
// Get the children in a list.
|
1373
|
NodeList nl = node.getChildNodes();
|
1374
|
// How many of them?
|
1375
|
int size = nl.getLength();
|
1376
|
for (int i=0; i<size; i++){
|
1377
|
// Recursively traverse each of the children.
|
1378
|
traverse (nl.item(i), dataHolder);
|
1379
|
}
|
1380
|
}
|
1381
|
}
|
1382
|
|
1383
|
|
1384
|
|
1385
|
@Override
|
1386
|
protected boolean isIgnore(Abcd206ImportState state) {
|
1387
|
//return ! config.isDoNameFacts();
|
1388
|
return false;
|
1389
|
}
|
1390
|
|
1391
|
|
1392
|
|
1393
|
}
|