2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.specimen
.abcd206
.in
;
12 import java
.io
.IOException
;
13 import java
.io
.InputStream
;
15 import java
.util
.ArrayList
;
16 import java
.util
.HashMap
;
17 import java
.util
.Iterator
;
18 import java
.util
.List
;
21 import javax
.xml
.parsers
.DocumentBuilder
;
22 import javax
.xml
.parsers
.DocumentBuilderFactory
;
23 import javax
.xml
.parsers
.ParserConfigurationException
;
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
;
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
;
70 public class Abcd206Import
extends SpecimenIoBase
<Abcd206ImportConfigurator
, Abcd206ImportState
> implements ICdmIO
<Abcd206ImportState
> {
71 private static final Logger logger
= Logger
.getLogger(Abcd206Import
.class);
74 public Abcd206Import() {
80 protected boolean doCheck(Abcd206ImportState state
) {
81 logger
.warn("Checking not yet implemented for " + this.getClass().getSimpleName());
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 logger
.info("nb units to insert: "+unitsList
.getLength());
97 Abcd206DataHolder dataHolder
= new Abcd206DataHolder();
99 for (int i
=0 ; i
<unitsList
.getLength() ; i
++){
100 this.setUnitPropertiesXML((Element
)unitsList
.item(i
), dataHolder
);
101 result
&= this.handleSingleUnit(config
, dataHolder
);
103 //compare the ABCD elements added in to the CDM and the unhandled ABCD elements
104 compareABCDtoCDM(sourceName
, dataHolder
.knownABCDelements
, dataHolder
);
106 //reset the ABCD elements added in CDM
107 //knownABCDelements = new ArrayList<String>();
108 dataHolder
.allABCDelements
= new HashMap
<String
,String
>();
117 * Store the unit with its Gathering informations in the CDM
119 private boolean handleSingleUnit(Abcd206ImportConfigurator config
, Abcd206DataHolder dataHolder
){
120 boolean result
= true;
122 TransactionStatus tx
= startTransaction();
124 // ReferenceBase sec = Database.NewInstance();
125 // sec.setTitleCache("XML DATA");
126 ReferenceBase sec
= config
.getTaxonReference();
129 DerivedUnitFacade derivedUnitFacade
= getFacade(dataHolder
);
132 //handle identifications
133 handleIdentifications(config
, derivedUnitFacade
, sec
, dataHolder
);
135 //handle collection data
136 setCollectionData(config
, dataHolder
, derivedUnitFacade
);
143 UnitsGatheringEvent unitsGatheringEvent
= new UnitsGatheringEvent(
144 getTermService(), dataHolder
.locality
, dataHolder
.languageIso
, dataHolder
.longitude
,
145 dataHolder
.latitude
, dataHolder
.gatheringAgentList
);
148 UnitsGatheringArea unitsGatheringArea
=
149 new UnitsGatheringArea(dataHolder
.isocountry
, dataHolder
.country
, getOccurrenceService());
150 NamedArea areaCountry
= unitsGatheringArea
.getArea();
153 unitsGatheringArea
= new UnitsGatheringArea(dataHolder
.namedAreaList
);
154 ArrayList
<NamedArea
> nas
= unitsGatheringArea
.getAreas();
155 for (NamedArea namedArea
: nas
){
156 unitsGatheringEvent
.addArea(namedArea
);
159 //copy gathering event to facade
160 GatheringEvent gatheringEvent
= unitsGatheringEvent
.getGatheringEvent();
161 derivedUnitFacade
.setLocality(gatheringEvent
.getLocality());
162 derivedUnitFacade
.setExactLocation(gatheringEvent
.getExactLocation());
163 derivedUnitFacade
.setCollector(gatheringEvent
.getCollector());
164 derivedUnitFacade
.addCollectingArea(areaCountry
);
166 derivedUnitFacade
.addCollectingArea(areaCountry
);
167 derivedUnitFacade
.addCollectingAreas(unitsGatheringArea
.getAreas());
173 derivedUnitFacade
.setFieldNumber(dataHolder
.fieldNumber
);
175 //join gatheringEvent to fieldObservation
177 // //add Multimedia URLs
178 if(dataHolder
.multimediaObjects
.size() > 0){
179 MediaRepresentation representation
;
184 for (String multimediaObject
: dataHolder
.multimediaObjects
){
185 if( multimediaObject
!= null){
186 imd
= ImageMetaData
.newInstance();
187 url
= new URL(multimediaObject
);
189 imd
.readMetaData(url
.toURI(), 0);
190 } catch (Exception e
) {
191 String message
= "An error occurred when trying to read image meta data: " + e
.getMessage();
192 logger
.warn(message
);
194 //TODO do we really want to check the url?
196 imf
= ImageFile
.NewInstance(multimediaObject
, null, imd
);
197 representation
= MediaRepresentation
.NewInstance();
198 representation
.addRepresentationPart(imf
);
199 media
= Media
.NewInstance();
200 media
.addRepresentation(representation
);
202 derivedUnitFacade
.addFieldObjectMedia(media
);
209 * SAVE AND STORE DATA
211 getTermService().save(areaCountry
);//TODO save area sooner
212 for (NamedArea area
: nas
){
213 getTermService().save(area
);//save it sooner (foreach area)
215 getTermService().saveLanguageData(unitsGatheringEvent
.getLocality());//TODO needs to be saved ?? save it sooner
217 getOccurrenceService().save(derivedUnitFacade
.getDerivedUnit());
218 logger
.info("saved ABCD specimen ...");
221 } catch (Exception e
) {
222 logger
.warn("Error when reading record!!");
226 commitTransaction(tx
);
232 private void setCollectionData(Abcd206ImportConfigurator config
,
233 Abcd206DataHolder dataHolder
, DerivedUnitFacade derivedUnitFacade
) {
234 //set catalogue number (unitID)
235 derivedUnitFacade
.setCatalogNumber(dataHolder
.unitID
);
236 derivedUnitFacade
.setAccessionNumber(dataHolder
.accessionNumber
);
237 derivedUnitFacade
.setCollectorsNumber(dataHolder
.collectorsNumber
);
241 * INSTITUTION & COLLECTION
244 Institution institution
= this.getInstitution(dataHolder
.institutionCode
, config
, dataHolder
);
246 Collection collection
= this.getCollection(dataHolder
.collectionCode
, institution
, config
, dataHolder
);
247 //link specimen & collection
248 derivedUnitFacade
.setCollection(collection
);
252 private DerivedUnitFacade
getFacade(Abcd206DataHolder dataHolder
) {
254 * SPECIMEN OR OBSERVATION OR LIVING
256 // DerivedUnitBase derivedThing = null;
257 DerivedUnitType type
= null;
260 if (dataHolder
.recordBasis
!= null){
261 if (dataHolder
.recordBasis
.toLowerCase().startsWith("s")) {//specimen
262 type
= DerivedUnitType
.Specimen
;
263 }else if (dataHolder
.recordBasis
.toLowerCase().startsWith("o")) {//observation
264 type
= DerivedUnitType
.Observation
;
265 }else if (dataHolder
.recordBasis
.toLowerCase().startsWith("l")) {//living -> fossil, herbarium sheet....???
266 type
= DerivedUnitType
.LivingBeing
;
269 logger
.info("The basis of record does not seem to be known: " + dataHolder
.recordBasis
);
270 type
= DerivedUnitType
.DerivedUnit
;
274 logger
.info("The basis of record is null");
275 type
= DerivedUnitType
.DerivedUnit
;
277 DerivedUnitFacade derivedUnitFacade
= DerivedUnitFacade
.NewInstance(type
);
278 return derivedUnitFacade
;
283 * Return the list of root nodes for an ABCD 2.06 XML file
284 * @param fileName: the file's location
285 * @return the list of root nodes ("Unit")
287 private static NodeList
getUnitsNodeList(String urlFileName
){
288 NodeList unitList
= null;
290 DocumentBuilderFactory factory
= DocumentBuilderFactory
.newInstance();
291 DocumentBuilder builder
= factory
.newDocumentBuilder();
292 URL url
= new URL(urlFileName
);
293 Object o
= url
.getContent();
294 InputStream is
= (InputStream
)o
;
295 Document document
= builder
.parse(is
);
296 Element root
= document
.getDocumentElement();
297 unitList
= root
.getElementsByTagName("Unit");
307 * Store the unit's properties into variables
308 * Look which unit is the preferred one
309 * Look what kind of name it is supposed to be, for the parsing (Botanical, Zoological)
310 * @param racine: the root node for a single unit
312 private void setUnitPropertiesXML(Element root
, Abcd206DataHolder dataHolder
){
316 // try{afficherInfos(racine, 0);}catch (Exception e) {logger.info(e);}
317 group
= root
.getChildNodes();
318 // logger.info("ABCD ELEMENT not stored: "+group.item(i).getNodeName().toString()+" - value: "+group.item(i).getTextContent());
319 for (int i
= 0; i
< group
.getLength(); i
++){
320 if (group
.item(i
).getNodeName().equals("Identifications")){
321 group
= group
.item(i
).getChildNodes();
325 dataHolder
.identificationList
= new ArrayList
<String
>();
326 dataHolder
.atomisedIdentificationList
= new ArrayList
<HashMap
<String
, String
>>();
327 dataHolder
.referenceList
= new ArrayList
<String
>();
328 dataHolder
.multimediaObjects
= new ArrayList
<String
>();
330 this.getScientificNames(group
, dataHolder
);
332 // logger.info("this.identificationList "+this.identificationList.toString());
333 this.getIDs(root
, dataHolder
);
334 this.getRecordBasis(root
, dataHolder
);
335 this.getMultimedia(root
, dataHolder
);
336 this.getNumbers(root
, dataHolder
);
337 this.getGeolocation(root
, dataHolder
);
338 this.getGatheringPeople(root
, dataHolder
);
340 } catch (Exception e
) {
341 logger
.info("Error occured while parsing XML file"+e
);
346 private void getHierarchie(Node node
){
347 while (node
!= null && node
.getNodeName() != "DataSets"){
348 // logger.info(node.getParentNode().getNodeName());
349 path
= node
.getParentNode().getNodeName()+"/"+path
;
350 node
= node
.getParentNode();
352 // logger.info("path: "+path);
355 private void getScientificNames(NodeList group
, Abcd206DataHolder dataHolder
){
356 NodeList identifications
,results
;
357 String tmpName
= null;
358 for (int j
=0; j
< group
.getLength(); j
++){
359 if(group
.item(j
).getNodeName().equals("Identification")){
360 dataHolder
.nomenclatureCode
="";
361 identifications
= group
.item(j
).getChildNodes();
362 for (int m
=0; m
<identifications
.getLength();m
++){
363 if(identifications
.item(m
).getNodeName().equals("Result")){
364 results
= identifications
.item(m
).getChildNodes();
365 for(int k
=0; k
<results
.getLength();k
++){
366 if (results
.item(k
).getNodeName().equals("TaxonIdentified")){
367 tmpName
=this.getScientificName(results
.item(k
), dataHolder
);
370 }else if(identifications
.item(m
).getNodeName().equals("PreferredFlag")){
371 if (dataHolder
.nomenclatureCode
!= null && dataHolder
.nomenclatureCode
!=""){
372 dataHolder
.identificationList
.add(tmpName
+"_preferred_"+identifications
.item(m
).getTextContent()+"_code_" + dataHolder
.nomenclatureCode
);
374 dataHolder
.identificationList
.add(tmpName
+"_preferred_"+identifications
.item(m
).getTextContent());
376 path
=identifications
.item(m
).getNodeName();
377 getHierarchie(identifications
.item(m
));
378 dataHolder
.knownABCDelements
.add(path
);
380 }else if (identifications
.item(m
).getNodeName().equals("References")){
381 this.getReferences(identifications
.item(m
), dataHolder
);
386 boolean hasPref
=false;
387 for (int j
=0; j
< group
.getLength(); j
++){
388 if(group
.item(j
).getNodeName().equals("Identification")){
389 dataHolder
.nomenclatureCode
="";
390 identifications
= group
.item(j
).getChildNodes();
391 for (int m
=0; m
<identifications
.getLength();m
++){
392 if(identifications
.item(m
).getNodeName().equals("Result")){
393 results
= identifications
.item(m
).getChildNodes();
394 for(int k
=0; k
<results
.getLength();k
++){
395 if (results
.item(k
).getNodeName().equals("TaxonIdentified")){
396 tmpName
=this.getScientificName(results
.item(k
), dataHolder
);
400 if(identifications
.item(m
).getNodeName().equals("PreferredFlag")){
404 if ( !hasPref
&& tmpName
!= null){
405 if (dataHolder
.nomenclatureCode
!= null && dataHolder
.nomenclatureCode
!=""){
406 dataHolder
.identificationList
.add(tmpName
+"_preferred_"+"0"+"_code_" + dataHolder
.nomenclatureCode
);
408 dataHolder
.identificationList
.add(tmpName
+"_preferred_"+"0");
417 private void getReferences(Node result
, Abcd206DataHolder dataHolder
){
418 NodeList results
,reference
;
419 results
= result
.getChildNodes();
420 for(int k
=0; k
<results
.getLength();k
++){
421 if (results
.item(k
).getNodeName().equals("Reference")){
422 reference
= results
.item(k
).getChildNodes();
423 for(int l
=0;l
<reference
.getLength();l
++){
424 if (reference
.item(l
).getNodeName().equals("TitleCitation")){
425 path
= reference
.item(l
).getNodeName();
426 dataHolder
.referenceList
.add(reference
.item(l
).getTextContent());
427 getHierarchie(reference
.item(l
));
428 dataHolder
.knownABCDelements
.add(path
);
436 private String
getScientificName(Node result
, Abcd206DataHolder dataHolder
){
437 NodeList taxonsIdentified
, scnames
, atomised
;
439 dataHolder
.atomisedStr
= "";
440 taxonsIdentified
= result
.getChildNodes();
441 for (int l
=0; l
<taxonsIdentified
.getLength(); l
++){
442 if (taxonsIdentified
.item(l
).getNodeName().equals("ScientificName")){
443 scnames
= taxonsIdentified
.item(l
).getChildNodes();
444 for (int n
=0;n
<scnames
.getLength();n
++){
445 if (scnames
.item(n
).getNodeName().equals("FullScientificNameString")){
446 path
=scnames
.item(n
).getNodeName();
447 tmpName
= scnames
.item(n
).getTextContent();
448 getHierarchie(scnames
.item(n
));
449 dataHolder
.knownABCDelements
.add(path
);
452 if (scnames
.item(n
).getNodeName().equals("NameAtomised")){
454 if (scnames
.item(n
).hasChildNodes()){
455 dataHolder
.nomenclatureCode
= scnames
.item(n
).getChildNodes().item(1).getNodeName();
457 } catch (Exception e
) {
458 dataHolder
.nomenclatureCode
="";
460 atomised
= scnames
.item(n
).getChildNodes().item(1).getChildNodes();
461 dataHolder
.atomisedIdentificationList
.add(this.getAtomisedNames(dataHolder
.nomenclatureCode
, atomised
, dataHolder
));
469 private HashMap
<String
,String
> getAtomisedNames(String code
, NodeList atomised
, Abcd206DataHolder dataHolder
){
470 if (code
.equals("Botanical")){
471 return this.getAtomisedBotanical(atomised
, dataHolder
);
473 if (code
.equals("Bacterial")){
474 return this.getAtomisedBacterial(atomised
, dataHolder
);
476 if (code
.equals("NameViral")){
477 return this.getAtomisedViral(atomised
, dataHolder
);
479 if (code
.equals("NameZoological")){
480 return this.getAtomisedZoological(atomised
,dataHolder
);
482 return new HashMap
<String
,String
>();
485 private HashMap
<String
,String
> getAtomisedZoological(NodeList atomised
, Abcd206DataHolder dataHolder
){
486 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
487 for (int i
=0;i
<atomised
.getLength();i
++){
488 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
489 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
490 path
=atomised
.item(i
).getNodeName();
491 getHierarchie(atomised
.item(i
));
492 dataHolder
.knownABCDelements
.add(path
);
495 if(atomised
.item(i
).getNodeName().equals("Subgenus")){
496 atomisedMap
.put("Subgenus",atomised
.item(i
).getTextContent());
497 path
=atomised
.item(i
).getNodeName();
498 getHierarchie(atomised
.item(i
));
499 dataHolder
.knownABCDelements
.add(path
);
502 if(atomised
.item(i
).getNodeName().equals("SpeciesEpithet")){
503 atomisedMap
.put("SpeciesEpithet",atomised
.item(i
).getTextContent());
504 path
=atomised
.item(i
).getNodeName();
505 getHierarchie(atomised
.item(i
));
506 dataHolder
.knownABCDelements
.add(path
);
509 if(atomised
.item(i
).getNodeName().equals("SubspeciesEpithet")){
510 atomisedMap
.put("SubspeciesEpithet",atomised
.item(i
).getTextContent());
511 path
=atomised
.item(i
).getNodeName();
512 getHierarchie(atomised
.item(i
));
513 dataHolder
.knownABCDelements
.add(path
);
516 if(atomised
.item(i
).getNodeName().equals("AuthorTeamOriginalAndYear")){
517 atomisedMap
.put("AuthorTeamOriginalAndYear",atomised
.item(i
).getTextContent());
518 path
=atomised
.item(i
).getNodeName();
519 getHierarchie(atomised
.item(i
));
520 dataHolder
.knownABCDelements
.add(path
);
523 if(atomised
.item(i
).getNodeName().equals("AuthorTeamParenthesisAndYear")){
524 atomisedMap
.put("AuthorTeamParenthesisAndYear",atomised
.item(i
).getTextContent());
525 path
=atomised
.item(i
).getNodeName();
526 getHierarchie(atomised
.item(i
));
527 dataHolder
.knownABCDelements
.add(path
);
530 if(atomised
.item(i
).getNodeName().equals("CombinationAuthorTeamAndYear")){
531 atomisedMap
.put("CombinationAuthorTeamAndYear",atomised
.item(i
).getTextContent());
532 path
=atomised
.item(i
).getNodeName();
533 getHierarchie(atomised
.item(i
));
534 dataHolder
.knownABCDelements
.add(path
);
537 if(atomised
.item(i
).getNodeName().equals("Breed")){
538 atomisedMap
.put("Breed",atomised
.item(i
).getTextContent());
539 path
=atomised
.item(i
).getNodeName();
540 getHierarchie(atomised
.item(i
));
541 dataHolder
.knownABCDelements
.add(path
);
544 if(atomised
.item(i
).getNodeName().equals("NamedIndividual")){
545 atomisedMap
.put("NamedIndividual",atomised
.item(i
).getTextContent());
546 path
=atomised
.item(i
).getNodeName();
547 getHierarchie(atomised
.item(i
));
548 dataHolder
.knownABCDelements
.add(path
);
555 private HashMap
<String
,String
> getAtomisedViral(NodeList atomised
, Abcd206DataHolder dataHolder
){
556 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
557 for (int i
=0;i
<atomised
.getLength();i
++){
558 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
559 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
560 path
=atomised
.item(i
).getNodeName();
561 getHierarchie(atomised
.item(i
));
562 dataHolder
.knownABCDelements
.add(path
);
565 if(atomised
.item(i
).getNodeName().equals("ViralSpeciesDesignation")){
566 atomisedMap
.put("ViralSpeciesDesignation", atomised
.item(i
).getTextContent());
567 path
=atomised
.item(i
).getNodeName();
568 getHierarchie(atomised
.item(i
));
569 dataHolder
.knownABCDelements
.add(path
);
572 if(atomised
.item(i
).getNodeName().equals("Acronym")){
573 atomisedMap
.put("Acronym",atomised
.item(i
).getTextContent());
574 path
=atomised
.item(i
).getNodeName();
575 getHierarchie(atomised
.item(i
));
576 dataHolder
.knownABCDelements
.add(path
);
583 private HashMap
<String
,String
> getAtomisedBotanical(NodeList atomised
, Abcd206DataHolder dataHolder
){
584 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
585 for (int i
=0;i
<atomised
.getLength();i
++){
586 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
587 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
588 path
=atomised
.item(i
).getNodeName();
589 getHierarchie(atomised
.item(i
));
590 dataHolder
.knownABCDelements
.add(path
);
593 if(atomised
.item(i
).getNodeName().equals("FirstEpithet")){
594 atomisedMap
.put("FirstEpithet",atomised
.item(i
).getTextContent());
595 path
=atomised
.item(i
).getNodeName();
596 getHierarchie(atomised
.item(i
));
597 dataHolder
.knownABCDelements
.add(path
);
600 if(atomised
.item(i
).getNodeName().equals("InfraspecificEpithet")){
601 atomisedMap
.put("InfraSpeEpithet", atomised
.item(i
).getTextContent());
602 path
=atomised
.item(i
).getNodeName();
603 getHierarchie(atomised
.item(i
));
604 dataHolder
.knownABCDelements
.add(path
);
607 if(atomised
.item(i
).getNodeName().equals("Rank")){
608 atomisedMap
.put("Rank",atomised
.item(i
).getTextContent());
609 path
=atomised
.item(i
).getNodeName();
610 getHierarchie(atomised
.item(i
));
611 dataHolder
.knownABCDelements
.add(path
);
614 if(atomised
.item(i
).getNodeName().equals("HybridFlag")){
615 atomisedMap
.put("HybridFlag",atomised
.item(i
).getTextContent());
616 path
=atomised
.item(i
).getNodeName();
617 getHierarchie(atomised
.item(i
));
618 dataHolder
.knownABCDelements
.add(path
);
621 if(atomised
.item(i
).getNodeName().equals("AuthorTeamParenthesis")){
622 atomisedMap
.put("AuthorTeamParenthesis",atomised
.item(i
).getTextContent());
623 path
=atomised
.item(i
).getNodeName();
624 getHierarchie(atomised
.item(i
));
625 dataHolder
.knownABCDelements
.add(path
);
628 if(atomised
.item(i
).getNodeName().equals("AuthorTeam")){
629 atomisedMap
.put("AuthorTeam",atomised
.item(i
).getTextContent());
630 path
=atomised
.item(i
).getNodeName();
631 getHierarchie(atomised
.item(i
));
632 dataHolder
.knownABCDelements
.add(path
);
635 if(atomised
.item(i
).getNodeName().equals("CultivarGroupName")){
636 atomisedMap
.put("CultivarGroupName",atomised
.item(i
).getTextContent());
637 path
=atomised
.item(i
).getNodeName();
638 getHierarchie(atomised
.item(i
));
639 dataHolder
.knownABCDelements
.add(path
);
642 if(atomised
.item(i
).getNodeName().equals("CultivarName")){
643 atomisedMap
.put("CultivarName",atomised
.item(i
).getTextContent());
644 path
=atomised
.item(i
).getNodeName();
645 getHierarchie(atomised
.item(i
));
646 dataHolder
.knownABCDelements
.add(path
);
649 if(atomised
.item(i
).getNodeName().equals("TradeDesignationNames")){
650 atomisedMap
.put("Trade",atomised
.item(i
).getTextContent());
651 path
=atomised
.item(i
).getNodeName();
652 getHierarchie(atomised
.item(i
));
653 dataHolder
.knownABCDelements
.add(path
);
660 private HashMap
<String
,String
> getAtomisedBacterial(NodeList atomised
, Abcd206DataHolder dataHolder
){
661 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
662 for (int i
=0;i
<atomised
.getLength();i
++){
663 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
664 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
665 path
=atomised
.item(i
).getNodeName();
666 getHierarchie(atomised
.item(i
));
667 dataHolder
.knownABCDelements
.add(path
);
670 if(atomised
.item(i
).getNodeName().equals("Subgenus")){
671 atomisedMap
.put("SubGenus",atomised
.item(i
).getTextContent());
672 path
=atomised
.item(i
).getNodeName();
673 getHierarchie(atomised
.item(i
));
674 dataHolder
.knownABCDelements
.add(path
);
677 if(atomised
.item(i
).getNodeName().equals("SubgenusAuthorAndYear")){
678 atomisedMap
.put("SubgenusAuthorAndYear",atomised
.item(i
).getTextContent());
679 path
=atomised
.item(i
).getNodeName();
680 getHierarchie(atomised
.item(i
));
681 dataHolder
.knownABCDelements
.add(path
);
684 if(atomised
.item(i
).getNodeName().equals("SpeciesEpithet")){
685 atomisedMap
.put("SpeciesEpithet",atomised
.item(i
).getTextContent());
686 path
=atomised
.item(i
).getNodeName();
687 getHierarchie(atomised
.item(i
));
688 dataHolder
.knownABCDelements
.add(path
);
691 if(atomised
.item(i
).getNodeName().equals("SubspeciesEpithet")){
692 atomisedMap
.put("SubspeciesEpithet",atomised
.item(i
).getTextContent());
693 path
=atomised
.item(i
).getNodeName();
694 getHierarchie(atomised
.item(i
));
695 dataHolder
.knownABCDelements
.add(path
);
698 if(atomised
.item(i
).getNodeName().equals("ParentheticalAuthorTeamAndYear")){
699 atomisedMap
.put("ParentheticalAuthorTeamAndYear",atomised
.item(i
).getTextContent());
700 path
=atomised
.item(i
).getNodeName();
701 getHierarchie(atomised
.item(i
));
702 dataHolder
.knownABCDelements
.add(path
);
705 if(atomised
.item(i
).getNodeName().equals("AuthorTeamAndYear")){
706 atomisedMap
.put("AuthorTeamAndYear",atomised
.item(i
).getTextContent());
707 path
=atomised
.item(i
).getNodeName();
708 getHierarchie(atomised
.item(i
));
709 dataHolder
.knownABCDelements
.add(path
);
712 if(atomised
.item(i
).getNodeName().equals("NameApprobation")){
713 atomisedMap
.put("NameApprobation",atomised
.item(i
).getTextContent());
714 path
=atomised
.item(i
).getNodeName();
715 getHierarchie(atomised
.item(i
));
716 dataHolder
.knownABCDelements
.add(path
);
723 private void getIDs(Element root
, Abcd206DataHolder dataHolder
){
726 group
= root
.getElementsByTagName("SourceInstitutionID");
727 path
=group
.item(0).getNodeName();
728 getHierarchie(group
.item(0));
729 dataHolder
.knownABCDelements
.add(path
);
731 dataHolder
.institutionCode
= group
.item(0).getTextContent();
732 } catch (NullPointerException e
) {
733 dataHolder
.institutionCode
= "";
736 group
= root
.getElementsByTagName("SourceID");
737 path
=group
.item(0).getNodeName();
738 getHierarchie(group
.item(0));
739 dataHolder
.knownABCDelements
.add(path
);
741 dataHolder
.collectionCode
= group
.item(0).getTextContent();
742 } catch (NullPointerException e
) {
743 dataHolder
.collectionCode
= "";
746 group
= root
.getElementsByTagName("UnitID");
747 path
=group
.item(0).getNodeName();
748 getHierarchie(group
.item(0));
749 dataHolder
.knownABCDelements
.add(path
);
751 dataHolder
.unitID
= group
.item(0).getTextContent();
752 } catch (NullPointerException e
) {
753 dataHolder
.unitID
= "";
757 private void getRecordBasis(Element root
, Abcd206DataHolder dataHolder
){
760 group
= root
.getElementsByTagName("RecordBasis");
761 path
=group
.item(0).getNodeName();
762 getHierarchie(group
.item(0));
763 dataHolder
.knownABCDelements
.add(path
);
765 dataHolder
.recordBasis
= group
.item(0).getTextContent();
766 } catch (NullPointerException e
) {
767 dataHolder
.recordBasis
= "";
771 private void getMultimedia(Element root
, Abcd206DataHolder dataHolder
){
772 NodeList group
, multimedias
, multimedia
;
774 group
= root
.getElementsByTagName("MultiMediaObjects");
775 for(int i
=0;i
<group
.getLength();i
++){
776 multimedias
= group
.item(i
).getChildNodes();
777 for (int j
=0;j
<multimedias
.getLength();j
++){
778 if (multimedias
.item(j
).getNodeName().equals("MultiMediaObject")){
779 multimedia
= multimedias
.item(j
).getChildNodes();
780 for (int k
=0;k
<multimedia
.getLength();k
++){
781 if(multimedia
.item(k
).getNodeName().equals("FileURI")){
782 dataHolder
.multimediaObjects
.add(multimedia
.item(k
).getTextContent());
783 path
= multimedia
.item(k
).getNodeName();
784 getHierarchie(multimedia
.item(k
));
785 dataHolder
.knownABCDelements
.add(path
);
792 } catch (NullPointerException e
) {
797 private void getNumbers(Element root
, Abcd206DataHolder dataHolder
){
800 group
= root
.getElementsByTagName("AccessionNumber");
801 path
=group
.item(0).getNodeName();
802 getHierarchie(group
.item(0));
803 dataHolder
.knownABCDelements
.add(path
);
805 dataHolder
.accessionNumber
= group
.item(0).getTextContent();
806 } catch (NullPointerException e
) {
807 dataHolder
.accessionNumber
= "";
810 group
= root
.getElementsByTagName("CollectorsFieldNumber");
811 path
=group
.item(0).getNodeName();
812 getHierarchie(group
.item(0));
813 dataHolder
.knownABCDelements
.add(path
);
815 dataHolder
.fieldNumber
= group
.item(0).getTextContent();
816 } catch (NullPointerException e
) {
817 dataHolder
.fieldNumber
= "";
821 group
= root
.getElementsByTagName("CollectorsNumber");
822 path
=group
.item(0).getNodeName();
823 getHierarchie(group
.item(0));
824 dataHolder
.knownABCDelements
.add(path
);
826 dataHolder
.collectorsNumber
= group
.item(0).getTextContent();
827 } catch (NullPointerException e
) {
828 dataHolder
.collectorsNumber
= "";
832 group
= root
.getElementsByTagName("AccessionNumber");
833 path
=group
.item(0).getNodeName();
834 getHierarchie(group
.item(0));
835 dataHolder
.knownABCDelements
.add(path
);
837 dataHolder
.accessionNumber
= group
.item(0).getTextContent();
838 } catch (NullPointerException e
) {
839 dataHolder
.accessionNumber
= "";
843 private void getGeolocation(Element root
, Abcd206DataHolder dataHolder
){
844 NodeList group
, childs
;
846 group
= root
.getElementsByTagName("LocalityText");
847 path
=group
.item(0).getNodeName();
848 getHierarchie(group
.item(0));
849 dataHolder
.knownABCDelements
.add(path
);
851 dataHolder
.locality
= group
.item(0).getTextContent();
852 if (group
.item(0).hasAttributes())
853 if (group
.item(0).getAttributes().getNamedItem("lang") != null)
854 dataHolder
.languageIso
= group
.item(0).getAttributes().getNamedItem("lang").getTextContent();
855 } catch (NullPointerException e
) {
856 dataHolder
.locality
= "";
859 group
= root
.getElementsByTagName("LongitudeDecimal");
860 path
=group
.item(0).getNodeName();
861 getHierarchie(group
.item(0));
862 dataHolder
.knownABCDelements
.add(path
);
864 dataHolder
.longitude
= Double
.valueOf(group
.item(0).getTextContent());
865 } catch (NullPointerException e
) {
866 dataHolder
.longitude
=0.0;
869 group
= root
.getElementsByTagName("LatitudeDecimal");
870 path
=group
.item(0).getNodeName();
871 getHierarchie(group
.item(0));
872 dataHolder
.knownABCDelements
.add(path
);
874 dataHolder
.latitude
= Double
.valueOf(group
.item(0).getTextContent());
875 } catch (NullPointerException e
) {
876 dataHolder
.latitude
=0.0;
879 group
= root
.getElementsByTagName("Country");
880 childs
= group
.item(0).getChildNodes();
881 for (int i
=0;i
<childs
.getLength(); i
++){
882 if(childs
.item(i
).getNodeName() == "Name"){
883 path
=childs
.item(i
).getNodeName();
884 getHierarchie(childs
.item(i
));
885 dataHolder
.knownABCDelements
.add(path
);
887 dataHolder
.country
= childs
.item(i
).getTextContent();
890 } catch (NullPointerException e
) {
891 dataHolder
.country
= "";
894 group
= root
.getElementsByTagName("Country");
895 childs
= group
.item(0).getChildNodes();
896 for (int i
=0;i
<childs
.getLength(); i
++){
897 if(childs
.item(i
).getNodeName() == "ISO3166Code"){
898 path
=childs
.item(i
).getNodeName();
899 getHierarchie(childs
.item(i
));
900 dataHolder
.knownABCDelements
.add(path
);
902 dataHolder
.isocountry
= childs
.item(i
).getTextContent();
905 } catch (NullPointerException e
) {
906 dataHolder
.isocountry
= "";
909 group
= root
.getElementsByTagName("Altitude");
910 for (int i
=0;i
<group
.getLength();i
++){
911 childs
= group
.item(i
).getChildNodes();
912 for (int j
=0;j
<childs
.getLength();j
++){
913 if (childs
.item(j
).getNodeName().equals("MeasurementOrFactText")){
914 path
=childs
.item(j
).getNodeName();
915 getHierarchie(childs
.item(j
));
916 dataHolder
.knownABCDelements
.add(path
);
918 dataHolder
.altitude
= Integer
.valueOf(childs
.item(j
).getTextContent());
922 } catch (NullPointerException e
) {
923 dataHolder
.altitude
= -9999;
927 group
= root
.getElementsByTagName("Depth");
928 path
=group
.item(0).getNodeName();
929 getHierarchie(group
.item(0));
930 dataHolder
.knownABCDelements
.add(path
);
932 dataHolder
.depth
= Integer
.valueOf(group
.item(0).getTextContent());
933 } catch (NullPointerException e
) {
934 dataHolder
.depth
= -9999;
938 group
= root
.getElementsByTagName("NamedArea");
939 dataHolder
.namedAreaList
= new ArrayList
<String
>();
940 for (int i
=0;i
<group
.getLength();i
++){
941 childs
= group
.item(i
).getChildNodes();
942 for (int j
=0; j
<childs
.getLength();j
++){
943 if (childs
.item(j
).getNodeName().equals("AreaName")){
944 path
= childs
.item(j
).getNodeName();
945 getHierarchie(childs
.item(j
));
946 dataHolder
.knownABCDelements
.add(path
);
948 dataHolder
.namedAreaList
.add(childs
.item(j
).getTextContent());
952 }catch(NullPointerException e
){
953 dataHolder
.namedAreaList
= new ArrayList
<String
>();
957 private void getGatheringPeople(Element root
, Abcd206DataHolder dataHolder
){
958 NodeList group
, childs
, person
;
960 group
= root
.getElementsByTagName("GatheringAgent");
961 dataHolder
.gatheringAgentList
= new ArrayList
<String
>();
962 for (int i
=0; i
< group
.getLength(); i
++){
963 childs
= group
.item(i
).getChildNodes();
964 for (int j
=0; j
<childs
.getLength();j
++){
965 if (childs
.item(j
).getNodeName().equals("Person")){
966 person
= childs
.item(j
).getChildNodes();
967 for (int k
=0; k
<person
.getLength(); k
++){
968 if (person
.item(k
).getNodeName().equals("FullName")){
969 path
=person
.item(k
).getNodeName();
970 getHierarchie(person
.item(k
));
971 dataHolder
.knownABCDelements
.add(path
);
973 dataHolder
.gatheringAgentList
.add(person
.item(k
).getTextContent());
980 } catch (NullPointerException e
) {
981 dataHolder
.gatheringAgentList
= new ArrayList
<String
>();
985 private Institution
getInstitution(String institutionCode
, Abcd206ImportConfigurator config
, Abcd206DataHolder dataHolder
){
986 Institution institution
;
987 List
<Institution
> institutions
;
989 logger
.info(dataHolder
.institutionCode
);
990 institutions
= getAgentService().searchInstitutionByCode(dataHolder
.institutionCode
);
992 institutions
=new ArrayList
<Institution
>();
994 if (institutions
.size() ==0 || !config
.getReUseExistingMetadata()){
995 logger
.info("Institution (agent) unknown or not allowed to reuse existing metadata");
997 institution
= Institution
.NewInstance();
998 institution
.setCode(dataHolder
.institutionCode
);
1001 logger
.info("Institution (agent) already in the db");
1002 institution
= institutions
.get(0);
1008 * Look if the Collection does already exists
1009 * @param collectionCode: a string
1010 * @param institution: the current Institution
1012 * @return the Collection (existing or new)
1014 private Collection
getCollection(String collectionCode
, Institution institution
, Abcd206ImportConfigurator config
, Abcd206DataHolder dataHolder
){
1015 Collection collection
= Collection
.NewInstance();
1016 List
<Collection
> collections
;
1018 collections
= getCollectionService().searchByCode(dataHolder
.collectionCode
);
1019 }catch(Exception e
){
1020 collections
=new ArrayList
<Collection
>();
1022 if (collections
.size() ==0 || !config
.getReUseExistingMetadata()){
1023 logger
.info("Collection not found or do not reuse existing metadata " + dataHolder
.collectionCode
);
1024 //create new collection
1025 collection
.setCode(dataHolder
.collectionCode
);
1026 collection
.setCodeStandard("GBIF");
1027 collection
.setInstitute(institution
);
1030 boolean collectionFound
=false;
1031 for (int i
=0; i
<collections
.size(); i
++){
1032 collection
= collections
.get(i
);
1034 if (collection
.getInstitute().getCode().equalsIgnoreCase(institution
.getCode())){
1035 //found a collection with the same code and the same institution
1036 collectionFound
=true;
1038 } catch (NullPointerException e
) {}
1040 if (!collectionFound
){
1041 collection
.setCode(dataHolder
.collectionCode
);
1042 collection
.setCodeStandard("GBIF");
1043 collection
.setInstitute(institution
);
1053 * @param derivedThing
1056 private void handleIdentifications(Abcd206ImportConfigurator config
, DerivedUnitFacade facade
, ReferenceBase sec
, Abcd206DataHolder dataHolder
){
1057 NonViralName
<?
> taxonName
= null;
1058 String fullScientificNameString
;
1060 DeterminationEvent determinationEvent
= null;
1061 List
<TaxonBase
> names
= null;
1063 String scientificName
="";
1064 boolean preferredFlag
=false;
1066 for (int i
= 0; i
< dataHolder
.identificationList
.size(); i
++) {
1067 fullScientificNameString
= dataHolder
.identificationList
.get(i
);
1068 fullScientificNameString
= fullScientificNameString
.replaceAll(" et ", " & ");
1069 if (fullScientificNameString
.indexOf("_preferred_") != -1){
1070 scientificName
= fullScientificNameString
.split("_preferred_")[0];
1071 String pTmp
= fullScientificNameString
.split("_preferred_")[1].split("_code_")[0];
1072 if (pTmp
.equals("1") || pTmp
.toLowerCase().indexOf("true") != -1){
1075 preferredFlag
=false;
1079 scientificName
= fullScientificNameString
;
1081 logger
.info(fullScientificNameString
);
1082 if (fullScientificNameString
.indexOf("_code_") != -1){
1083 dataHolder
.nomenclatureCode
= fullScientificNameString
.split("_code_")[1];
1085 if (config
.getDoAutomaticParsing() || dataHolder
.atomisedIdentificationList
== null || dataHolder
.atomisedIdentificationList
.size()==0){
1086 taxonName
= this.parseScientificName(scientificName
, dataHolder
);
1088 if (dataHolder
.atomisedIdentificationList
!= null || dataHolder
.atomisedIdentificationList
.size()>0){
1089 taxonName
= this.setTaxonNameByType(dataHolder
.atomisedIdentificationList
.get(i
), scientificName
, dataHolder
);
1092 if(taxonName
== null){
1093 taxonName
= NonViralName
.NewInstance(null);
1094 taxonName
.setFullTitleCache(scientificName
);
1096 if (config
.getDoReUseTaxon()){
1098 names
= getTaxonService().searchTaxaByName(scientificName
, sec
);
1099 taxon
= (Taxon
)names
.get(0);
1100 } catch(Exception e
){
1104 // taxonName = NonViralName.NewInstance(null);
1105 // taxonName.setFullTitleCache(scientificName);
1107 if (!config
.getDoReUseTaxon() || taxon
== null){
1108 getNameService().save(taxonName
);
1109 taxon
= Taxon
.NewInstance(taxonName
, sec
); //TODO sec set null
1111 determinationEvent
= DeterminationEvent
.NewInstance();
1112 determinationEvent
.setTaxon(taxon
);
1113 determinationEvent
.setPreferredFlag(preferredFlag
);
1115 for (String strReference
: dataHolder
.referenceList
){
1117 ReferenceBase reference
= ReferenceFactory
.newGeneric();
1118 reference
.setTitleCache(strReference
, true);
1119 determinationEvent
.addReference(reference
);
1121 facade
.addDetermination(determinationEvent
);
1126 private NonViralName
<?
> parseScientificName(String scientificName
, Abcd206DataHolder dataHolder
){
1127 NonViralNameParserImpl nvnpi
= NonViralNameParserImpl
.NewInstance();
1128 NonViralName
<?
>taxonName
= null;
1129 boolean problem
=false;
1131 if (dataHolder
.nomenclatureCode
.toString().equals("Zoological")){
1132 taxonName
= (ZoologicalName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICZN
,null);
1133 if (taxonName
.hasProblem()){
1137 if (dataHolder
.nomenclatureCode
.toString().equals("Botanical")){
1138 taxonName
= (BotanicalName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICBN
,null);
1139 if (taxonName
.hasProblem()){
1143 if (dataHolder
.nomenclatureCode
.toString().equals("Bacterial")){
1144 taxonName
= (BacterialName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICNB
, null);
1145 if (taxonName
.hasProblem()){
1149 if (dataHolder
.nomenclatureCode
.toString().equals("Cultivar")){
1150 taxonName
= (CultivarPlantName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICNCP
, null);
1151 if (taxonName
.hasProblem()){
1155 // if (this.nomenclatureCode.toString().equals("Viral")){
1156 // ViralName taxonName = (ViralName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICVCN(), null);
1157 // if (taxonName.hasProblem())
1158 // logger.info("pb ICVCN");
1160 //TODO: parsing of ViralNames?
1162 taxonName
= NonViralName
.NewInstance(null);
1163 taxonName
.setTitleCache(scientificName
, true);
1169 private NonViralName
<?
> setTaxonNameByType(HashMap
<String
, String
> atomisedMap
,String fullName
, Abcd206DataHolder dataHolder
){
1170 if (dataHolder
.nomenclatureCode
.equals("Zoological")){
1171 NonViralName
<ZoologicalName
> taxonName
= ZoologicalName
.NewInstance(null);
1172 taxonName
.setFullTitleCache(fullName
, true);
1173 taxonName
.setGenusOrUninomial(getFromMap(atomisedMap
,"Genus"));
1174 taxonName
.setInfraGenericEpithet(getFromMap(atomisedMap
,"SubGenus"));
1175 taxonName
.setSpecificEpithet(getFromMap(atomisedMap
,"SpeciesEpithet"));
1176 taxonName
.setInfraSpecificEpithet(getFromMap(atomisedMap
,"SubspeciesEpithet"));
1178 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
1179 team
= Team
.NewInstance();
1180 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"), true);
1182 if (getFromMap(atomisedMap
,"AuthorTeamAndYear") != null){
1183 team
= Team
.NewInstance();
1184 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamAndYear"), true);
1188 taxonName
.setBasionymAuthorTeam(team
);
1190 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
1191 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"));
1192 } else if (getFromMap(atomisedMap
,"AuthorTeamAndYear") != null){
1193 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeamAndYear"));
1196 if(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear") != null){
1197 team
= Team
.NewInstance();
1198 team
.setTitleCache(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear"), true);
1199 taxonName
.setCombinationAuthorTeam(team
);
1201 if (taxonName
.hasProblem()){
1202 logger
.info("pb ICZN");
1207 if (dataHolder
.nomenclatureCode
.equals("Botanical")){
1208 NonViralName
<BotanicalName
> taxonName
= BotanicalName
.NewInstance(null);
1209 taxonName
.setFullTitleCache(fullName
, true);
1210 taxonName
.setGenusOrUninomial(getFromMap(atomisedMap
,"Genus"));
1211 taxonName
.setInfraGenericEpithet(getFromMap(atomisedMap
,"FirstEpithet"));
1212 taxonName
.setInfraSpecificEpithet(getFromMap(atomisedMap
,"InfraSpeEpithet"));
1213 try{taxonName
.setRank(Rank
.getRankByName(getFromMap(atomisedMap
,"Rank")));
1214 }catch(Exception e
){}
1216 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
1217 team
= Team
.NewInstance();
1218 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"), true);
1220 taxonName
.setBasionymAuthorTeam(team
);
1223 if (getFromMap(atomisedMap
,"AuthorTeam") != null){
1224 team
= Team
.NewInstance();
1225 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeam"), true);
1227 taxonName
.setCombinationAuthorTeam(team
);
1231 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
1232 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"));
1233 }else if (getFromMap(atomisedMap
,"AuthorTeam") != null){
1234 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeam"));
1237 if(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear") != null){
1238 team
= Team
.NewInstance();
1239 team
.setTitleCache(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear"), true);
1240 taxonName
.setCombinationAuthorTeam(team
);
1242 if (taxonName
.hasProblem()){
1243 logger
.info("pb ICBN");
1248 if (dataHolder
.nomenclatureCode
.equals("Bacterial")){
1249 NonViralName
<BacterialName
> taxonName
= BacterialName
.NewInstance(null);
1250 taxonName
.setFullTitleCache(fullName
, true);
1251 taxonName
.setGenusOrUninomial(getFromMap(atomisedMap
,"Genus"));
1252 taxonName
.setInfraGenericEpithet(getFromMap(atomisedMap
,"SubGenus"));
1253 taxonName
.setSpecificEpithet(getFromMap(atomisedMap
,"Species"));
1254 taxonName
.setInfraSpecificEpithet(getFromMap(atomisedMap
,"SubspeciesEpithet"));
1255 if(getFromMap(atomisedMap
,"AuthorTeamAndYear") != null){
1256 Team team
= Team
.NewInstance();
1257 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamAndYear"), true);
1258 taxonName
.setCombinationAuthorTeam(team
);
1260 if(getFromMap(atomisedMap
,"ParentheticalAuthorTeamAndYear") != null){
1261 Team team
= Team
.NewInstance();
1262 team
.setTitleCache(getFromMap(atomisedMap
,"ParentheticalAuthorTeamAndYear"), true);
1263 taxonName
.setBasionymAuthorTeam(team
);
1265 if (taxonName
.hasProblem()){
1266 logger
.info("pb ICNB");
1271 if (dataHolder
.nomenclatureCode
.equals("Cultivar")){
1272 CultivarPlantName taxonName
= CultivarPlantName
.NewInstance(null);
1274 if (taxonName
.hasProblem()){
1275 logger
.info("pb ICNCP");
1280 // if (this.nomenclatureCode.equals("Viral")){
1281 // ViralName taxonName = ViralName.NewInstance(null);
1282 // taxonName.setFullTitleCache(fullName, true);
1283 // taxonName.setAcronym(getFromMap(atomisedMap,"Acronym"));
1284 // if (taxonName.hasProblem())
1285 // logger.info("pb ICVCN");
1286 // else return taxonName;
1289 NonViralName
<?
>taxonName
= NonViralName
.NewInstance(null);
1290 taxonName
.setFullTitleCache(fullName
, true);
1294 private String
getFromMap(HashMap
<String
, String
> atomisedMap
, String key
){
1295 String value
= null;
1296 if (atomisedMap
.containsKey(key
)){
1297 value
= atomisedMap
.get(key
);
1300 if (value
!= null && key
.matches(".*Year.*")){
1302 if (value
.matches("[a-z A-Z ]*[0-9]{4}$")){
1303 String tmp
=value
.split("[0-9]{4}$")[0];
1304 int year
= Integer
.parseInt(value
.split(tmp
)[1]);
1314 }catch(Exception e
){value
=null;}
1319 private void compareABCDtoCDM(String urlFileName
, ArrayList
<String
> knownElts
, Abcd206DataHolder dataHolder
){
1322 DocumentBuilderFactory factory
= DocumentBuilderFactory
.newInstance();
1323 DocumentBuilder constructeur
= factory
.newDocumentBuilder();
1324 URL url
= new URL(urlFileName
);
1325 Object o
= url
.getContent();
1326 InputStream is
= (InputStream
)o
;
1327 Document document
= constructeur
.parse(is
);
1328 Element root
= document
.getDocumentElement();
1329 traverse(root
, dataHolder
);
1330 } catch (ParserConfigurationException e
) {
1331 e
.printStackTrace();
1332 } catch (SAXException e
) {
1333 e
.printStackTrace();
1334 } catch (IOException e
) {
1335 e
.printStackTrace();
1337 Set
<String
> elts
= dataHolder
.allABCDelements
.keySet();
1338 Iterator
< String
>it
= elts
.iterator();
1340 while (it
.hasNext()){
1342 if (knownElts
.indexOf(elt
) == -1){
1343 logger
.info("Unsaved ABCD element: " + elt
+ " - " + dataHolder
.allABCDelements
.get(elt
));
1351 * Traverses the tree for compareABCDtoCDM
1355 private void traverse(Node node
, Abcd206DataHolder dataHolder
){
1356 // Extract node info:
1357 String test
= node
.getTextContent();
1359 // Print and continue traversing.
1360 if(test
!= null && test
!= "#text" && node
.getNodeName() != "#text" && test
.split("\n").length
==1 && test
.length()>0){
1361 path
=node
.getNodeName();
1362 getHierarchie(node
);
1363 dataHolder
.allABCDelements
.put(path
,test
);
1366 // Now traverse the rest of the tree in depth-first order.
1367 if (node
.hasChildNodes()) {
1368 // Get the children in a list.
1369 NodeList nl
= node
.getChildNodes();
1370 // How many of them?
1371 int size
= nl
.getLength();
1372 for (int i
=0; i
<size
; i
++){
1373 // Recursively traverse each of the children.
1374 traverse (nl
.item(i
), dataHolder
);
1382 protected boolean isIgnore(Abcd206ImportState state
) {
1383 //return ! config.isDoNameFacts();